...
 
/*
* KSS-RPC v0.22-beta
* KSS-RPC v0.23-beta
*
* Copyright (c) 2017, joonis new media
* Author: Thimo Kraemer <thimo.kraemer@joonis.de>
......@@ -61,7 +61,7 @@
******************************************************************************************/
var kss = {
version: '0.22-beta',
version: '0.23-beta',
_initialized: false,
_ruleSheets: {},
_nodeRegister: {},
......@@ -238,39 +238,40 @@ kss._observe = function(records, observer) {
kss._cleanNode = function(node, deep) {
var count = 0;
if (deep) {
count += kss._cleanChildNodes(node);
}
node.removeAttribute('data-has-kss');
var kssId = node._kssId;
if (!kssId)
return count;
kss.each(node._kssEvtHandlers, function(hnd) {
node.removeEventListener(hnd.eventname, hnd);
hnd.node = null;
});
kss.each(node._kssEvtBinders, function(bnd) {
if (bnd.destroy) {
try { bnd.destroy(); }
catch (err) { kss.error(err); }
}
});
delete node._kssEvtHandlers;
delete node._kssEvtBinders;
delete node._kssRules;
delete node._kssId;
delete kss._nodeRegister[kssId];
count++;
deep && kss.log('Cleand up ' + count + ' node(s)');
if (kssId) {
kss.each(node._kssEvtHandlers, function(hnd) {
node.removeEventListener(hnd.eventname, hnd);
hnd.node = null;
});
kss.each(node._kssEvtBinders, function(bnd) {
if (bnd.destroy) {
try { bnd.destroy(); }
catch (err) { kss.error(err); }
}
});
delete node._kssEvtHandlers;
delete node._kssEvtBinders;
delete node._kssRules;
delete node._kssId;
delete kss._nodeRegister[kssId];
count = 1;
}
if (deep) {
count = kss._cleanChildNodes(node, count);
}
return count;
};
kss._cleanChildNodes = function(node) {
kss._cleanChildNodes = function(node, _count) {
_count = _count || 0;
var nodes = kss.cssQuery('*[data-has-kss]', node);
kss.each(nodes, function(node) {
kss._cleanNode(node);
_count += kss._cleanNode(node);
});
return nodes.length;
_count && kss.log('Cleaned up ' + _count + ' node(s)');
return _count;
};
kss._cleanUp = function(purgeAll) {
......@@ -282,7 +283,7 @@ kss._cleanUp = function(purgeAll) {
count++;
}
});
count && kss.log('Cleand up ' + count + ' node(s)');
count && kss.log('Cleaned up ' + count + ' node(s)');
};
kss._register = function(name, func, what, many) {
......@@ -722,7 +723,7 @@ kss._EventHandler = function(node, eventname, rule, initial) {
kss.each(kss._eventBinders[eventname], function(binder) {
try {
var bnd = new binder(this);
node._kssEvtBinders.push(bnd);
bnd && node._kssEvtBinders.push(bnd);
}
catch (err) {
this.error(err);
......@@ -2728,12 +2729,6 @@ kss._TimeoutEventBinder = function(handler) {
delay: null,
repeat: true
});
this.hasServerActions = kss.each(handler.rule.actions,
function(action) {
if (action.type == 'server') {
return true;
}
}) || false;
this.setTimeout();
};
......@@ -2746,16 +2741,12 @@ kss._TimeoutEventBinder.prototype = {
+ 'timeout-delay: "' + delay + '"');
return;
}
if (this.hasServerActions && delay < 1000) {
this.eventHandler.warn('Delay of timeout event must be '
+ 'at least 1000 for rules containing server actions');
delay = 1000;
}
var self = this;
setTimeout(function() {self.timeout();}, delay);
this.timer = setTimeout(function() {self.timeout();}, delay);
},
timeout: function() {
this.timer = null;
var node = this.eventHandler.node;
if (!document.documentElement.contains(node)) {
return;
......@@ -2764,6 +2755,11 @@ kss._TimeoutEventBinder.prototype = {
if (this.props('repeat')) {
this.setTimeout();
}
},
destroy: function() {
this.timer && clearTimeout(this.timer);
this.timer = null;
}
};
......