...
 
/*
* KSS-RPC v0.19-beta
* KSS-RPC v0.20-beta
*
* Copyright (c) 2017, joonis new media
* Author: Thimo Kraemer <thimo.kraemer@joonis.de>
......@@ -61,7 +61,7 @@
******************************************************************************************/
var kss = {
version: '0.19-beta',
version: '0.20-beta',
_initialized: false,
_ruleSheets: {},
_eventBinders: {},
......@@ -672,10 +672,11 @@ kss._EventHandler = function(node, eventname, rule, initial) {
this.eventname = eventname;
this.event = {};
this.rule = rule;
this._queuedActions = {};
// Get kss- properties
this.kssProps = this.propertyGetter({
selector: '@samenode',
precondition: true,
precondition: true
}, rule.props);
// Get evt- properties
this.evtProps = this.propertyGetter({
......@@ -805,26 +806,26 @@ kss._EventHandler.prototype = {
}, this);
},
_execClientAction: function(action, params, selector) {
if (!kss._actionProviders[action]) {
this.error('Skipping non-existent client action "' + action + '"');
_execClientAction: function(name, params, selector) {
if (!kss._actionProviders[name]) {
this.error('Skipping non-existent client action "' + name + '"');
return;
}
var _params = {};
kss.each(params, function(value, key) {
_params[kss.camelCase(key)] = value;
});
action = {name: action, type: 'client'};
var action = {name: name, type: 'client', params: _params};
this._callBinders('onstart', action);
var error;
try {
selector = selector || this.kssProps('selector');
var nodes = kss.cssQuery(selector, this.node, true);
this.log('Execute client action "' + action.name + '" for '
this.log('Execute client action "' + name + '" for '
+ nodes.length + ' node(s) (selector "' + selector + '")');
this.debug('Parameters:', _params);
kss.each(nodes, function(node) {
kss._actionProviders[action.name].call(this, node, _params);
kss._actionProviders[name].call(this, node, _params);
}, this);
}
catch (err) {
......@@ -834,26 +835,42 @@ kss._EventHandler.prototype = {
this._callBinders('oncomplete', action, error);
},
_execServerAction: function(action, params, timeout) {
// Prevent server actions for mouse moves
if (['mousemove','drag','dragover'].indexOf(this.eventname) > -1) {
_execServerAction: function(name, params, timeout) {
// Action queue
if (name in this._queuedActions) {
this.debug('Queued server action "'
+ name + '" and dropped previous');
this._queuedActions[name] = [params, timeout];
return;
}
this._queuedActions[name] = null;
var config = Object.create(this.rule.config);
if (timeout) {
config.timeout = timeout;
}
var action = {name: name, type: 'server', params: params};
if (params && (config.protocol == 'xml-rpc' ||
config.protocol == 'json-rpc-v1')) {
params = [params];
}
action = {name: action, type: 'server'};
this._callBinders('onstart', action);
var self = this;
function completed(error) {
if (error)
self.error(error);
self._callBinders('oncomplete', action, error);
var args = self._queuedActions[name];
delete self._queuedActions[name];
if (args) {
self._execServerAction(name, args[0], args[1]);
}
}
try {
var msg = this.time('Execute server action "' + action.name + '"');
var msg = this.time('Execute server action "' + name + '"');
var rpc = new kss.RPC(config.endpoint, config);
var self = this;
rpc.invoke(action.name, params,
rpc.invoke(name, params,
function(result) {
var error;
try {
......@@ -873,20 +890,15 @@ kss._EventHandler.prototype = {
});
}
catch (err) {
self.error(err);
error = err;
}
self._callBinders('oncomplete', action, error);
completed(error);
},
function(err) {
self.error(err);
self._callBinders('oncomplete', action, err);
}
completed
);
}
catch (err) {
this.error(err);
this._callBinders('oncomplete', action, err);
completed(err);
}
},
......