mirror of
https://bitbucket.org/bellord13/kit.git
synced 2026-11-13 19:06:11 +03:00
fix
This commit is contained in:
+73
-11
@@ -3,6 +3,7 @@ __PluginManager__.register('support', function(module, exports, require, global)
|
||||
|
||||
window.pre = console.log;
|
||||
|
||||
const KIT_DATA_PREFIX = 'kit';
|
||||
|
||||
var data = function(){
|
||||
function normalizeData(val) {
|
||||
@@ -30,6 +31,12 @@ __PluginManager__.register('support', function(module, exports, require, global)
|
||||
}
|
||||
|
||||
const manipulator = {
|
||||
/**
|
||||
* @param element {HTMLElement}
|
||||
* @param key
|
||||
* @param value
|
||||
* @param prefix
|
||||
*/
|
||||
set(element, key, value, prefix = 'kit') {
|
||||
if(prefix !== '') {
|
||||
prefix = '-' + prefix;
|
||||
@@ -78,10 +85,71 @@ __PluginManager__.register('support', function(module, exports, require, global)
|
||||
}();
|
||||
|
||||
|
||||
var num = {
|
||||
round,
|
||||
ceil,
|
||||
floor,
|
||||
};
|
||||
function round(num, decimals = 0) {
|
||||
num = toNumber(num);
|
||||
decimals = toNumber(decimals);
|
||||
var k = Math.pow(10, decimals);
|
||||
num = Math.round(k * num) / k;
|
||||
return num;
|
||||
}
|
||||
function ceil(num, decimals = 0) {
|
||||
num = toNumber(num);
|
||||
decimals = toNumber(decimals);
|
||||
var k = Math.pow(10, decimals);
|
||||
num = Math.ceil(k * num) / k;
|
||||
return num;
|
||||
}
|
||||
function floor(num, decimals = 0) {
|
||||
num = toNumber(num);
|
||||
decimals = toNumber(decimals);
|
||||
var k = Math.pow(10, decimals);
|
||||
num = Math.floor(k * num) / k;
|
||||
return num;
|
||||
}
|
||||
|
||||
var node = {
|
||||
isRelate: function (node, container = document) {
|
||||
return node === container || container.contains(node);
|
||||
}
|
||||
},
|
||||
/**
|
||||
* @param node {HTMLElement}
|
||||
* @return {[]}
|
||||
*/
|
||||
getChainOfParents: function getChainOfParents(node) {
|
||||
var chain = [];
|
||||
if(!isNode(node)){
|
||||
return chain;
|
||||
}
|
||||
node = node.parentNode;
|
||||
while(node){
|
||||
chain.push(node);
|
||||
node = node.parentNode;
|
||||
}
|
||||
return chain;
|
||||
},
|
||||
/**
|
||||
* @param node {HTMLElement}
|
||||
* @return {[]}
|
||||
*/
|
||||
getChainOfParentsWithNode: function getChainOfParentsWithNode(node) {
|
||||
var chain = [];
|
||||
if(!isNode(node)){
|
||||
return chain;
|
||||
}
|
||||
while(node){
|
||||
chain.push(node);
|
||||
node = node.parentNode;
|
||||
}
|
||||
return chain;
|
||||
},
|
||||
isInPage: function (node) {
|
||||
return (node === document.body) ? false : document.body.contains(node);
|
||||
},
|
||||
};
|
||||
var str = {
|
||||
ucFirst: function (str) {
|
||||
@@ -252,9 +320,7 @@ __PluginManager__.register('support', function(module, exports, require, global)
|
||||
return nodeWrap.childNodes;
|
||||
}
|
||||
function setNodeData(node, key, value) {
|
||||
if(!isElement(node)) return false;
|
||||
node.kit = node.kit || {};
|
||||
node.kit[key] = value;
|
||||
return setObjProp(node, [KIT_DATA_PREFIX, key], value);
|
||||
}
|
||||
function setObjProp(object, branch, value) {
|
||||
if(!Array.isArray(branch)) {
|
||||
@@ -279,15 +345,10 @@ __PluginManager__.register('support', function(module, exports, require, global)
|
||||
return result;
|
||||
}
|
||||
function getNodeData(node, key, def = null) {
|
||||
if(!Array.isArray(key)) {
|
||||
key = [key];
|
||||
}
|
||||
var branch = ['kit'].concat(key);
|
||||
return getObjProp(node, branch, def);
|
||||
return getObjProp(node, [KIT_DATA_PREFIX, key], def);
|
||||
}
|
||||
|
||||
function getObjProp(object, branch, def = null) {
|
||||
if(!Array.isArray(branch)) {
|
||||
if(!isArray(branch)) {
|
||||
branch = [branch];
|
||||
}
|
||||
if(!isObject(object)) return def;
|
||||
@@ -387,6 +448,7 @@ __PluginManager__.register('support', function(module, exports, require, global)
|
||||
node: node,
|
||||
str: str,
|
||||
arr: arr,
|
||||
num: num,
|
||||
uniqueId,
|
||||
valueEx,
|
||||
empty,
|
||||
|
||||
Reference in New Issue
Block a user