web-atoms-core
Version:
149 lines • 4.8 kB
JavaScript
(function (factory) {
if (typeof module === "object" && typeof module.exports === "object") {
var v = factory(require, exports);
if (v !== undefined) module.exports = v;
}
else if (typeof define === "function" && define.amd) {
define(["require", "exports"], factory);
}
})(function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// refer http://youmightnotneedjquery.com/
var ChildEnumerator = /** @class */ (function () {
function ChildEnumerator(e) {
this.e = e;
}
Object.defineProperty(ChildEnumerator.prototype, "current", {
get: function () {
return this.item;
},
enumerable: true,
configurable: true
});
ChildEnumerator.prototype.next = function () {
if (!this.item) {
this.item = this.e.firstElementChild;
}
else {
this.item = this.item.nextElementSibling;
}
return this.item ? true : false;
};
return ChildEnumerator;
}());
exports.ChildEnumerator = ChildEnumerator;
var AtomUI = /** @class */ (function () {
function AtomUI() {
}
AtomUI.outerHeight = function (el, margin) {
if (margin === void 0) { margin = false; }
var height = el.offsetHeight;
if (!margin) {
return height;
}
var style = getComputedStyle(el);
height += parseInt(style.marginTop, 10) + parseInt(style.marginBottom, 10);
return height;
};
AtomUI.outerWidth = function (el, margin) {
if (margin === void 0) { margin = false; }
var width = el.offsetWidth;
if (!margin) {
return width;
}
var style = getComputedStyle(el);
width += parseInt(style.marginLeft, 10) + parseInt(style.marginRight, 10);
return width;
};
AtomUI.innerWidth = function (el) {
return el.clientWidth;
};
AtomUI.innerHeight = function (el) {
return el.clientHeight;
};
AtomUI.scrollTop = function (el, y) {
el.scrollTo(0, y);
};
AtomUI.screenOffset = function (e) {
var r = {
x: e.offsetLeft,
y: e.offsetTop,
width: e.offsetWidth,
height: e.offsetHeight
};
if (e.offsetParent) {
var p = this.screenOffset(e.offsetParent);
r.x += p.x;
r.y += p.y;
}
return r;
};
AtomUI.parseUrl = function (url) {
var r = {};
var plist = url.split("&");
for (var _i = 0, plist_1 = plist; _i < plist_1.length; _i++) {
var item = plist_1[_i];
var p = item.split("=");
var key = decodeURIComponent(p[0]);
if (!key) {
continue;
}
var val = p[1];
if (val) {
val = decodeURIComponent(val);
}
// val = AtomUI.parseValue(val);
r[key] = this.parseValue(val);
}
return r;
};
AtomUI.parseValue = function (val) {
var n;
if (/^[0-9]+$/.test(val)) {
n = parseInt(val, 10);
if (!isNaN(n)) {
return n;
}
return val;
}
if (/^[0-9]+\.[0-9]+/gi.test(val)) {
n = parseFloat(val);
if (!isNaN(n)) {
return n;
}
return val;
}
if (val === "true") {
return true;
}
if (val === "false") {
return false;
}
return val;
};
AtomUI.assignID = function (element) {
if (!element.id) {
element.id = "__waID" + AtomUI.getNewIndex();
}
return element.id;
};
AtomUI.toNumber = function (text) {
if (!text) {
return 0;
}
if (text.constructor === String) {
return parseFloat(text);
}
return 0;
};
AtomUI.getNewIndex = function () {
AtomUI.index = AtomUI.index + 1;
return AtomUI.index;
};
AtomUI.index = 1001;
return AtomUI;
}());
exports.AtomUI = AtomUI;
});
//# sourceMappingURL=AtomUI.js.map