-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
40 changed files
with
2,223 additions
and
1,858 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
/* ConfigCache.js | ||
* | ||
* copyright (c) 2010-2016, Christian Mayer and the CometVisu contributers. | ||
* | ||
* This program is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License as published by the Free | ||
* Software Foundation; either version 3 of the License, or (at your option) | ||
* any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
* more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along | ||
* with this program; if not, write to the Free Software Foundation, Inc., | ||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA | ||
*/ | ||
|
||
/** | ||
* Handles caches for cometvisu configs | ||
* | ||
* @author Tobias Bräutigam | ||
* @since 0.10.0 | ||
*/ | ||
|
||
/* TODO: | ||
- cache icons | ||
*/ | ||
define([], function() { | ||
var instance; | ||
|
||
function ConfigCache() { | ||
this._cacheKey = "data"; | ||
this._parseCacheData = null; | ||
this._valid = null; | ||
|
||
this.dump = function(xml) { | ||
this.save(this._cacheKey, { | ||
hash: this.toHash(xml), | ||
data: templateEngine.widgetData, | ||
addresses: templateEngine.ga_list, | ||
configSettings: templateEngine.configSettings | ||
}); | ||
localStorage.setItem(templateEngine.configSuffix+".body", $('body').html()); | ||
}; | ||
|
||
this.save = function(key, data) { | ||
localStorage.setItem(templateEngine.configSuffix+"."+key, JSON.stringify(data)); | ||
}; | ||
|
||
this.getBody = function() { | ||
return localStorage.getItem(templateEngine.configSuffix + ".body"); | ||
}; | ||
|
||
this.getData = function(key) { | ||
if (!this._parseCacheData) { | ||
this._parseCacheData = JSON.parse(localStorage.getItem(templateEngine.configSuffix + "." + this._cacheKey)); | ||
} | ||
if (!this._parseCacheData) { | ||
return null; | ||
} | ||
if (key) { | ||
return this._parseCacheData[key]; | ||
} else { | ||
return this._parseCacheData; | ||
} | ||
}; | ||
|
||
/** | ||
* Returns true if there is an existing cache for the current config file | ||
*/ | ||
this.isCached = function() { | ||
return localStorage.getItem(templateEngine.configSuffix + "." + this._cacheKey) !== null; | ||
}; | ||
|
||
this.isValid = function(xml) { | ||
// cache the result, as the config stays the same until next reload | ||
if (this._valid === null) { | ||
var hash = this.toHash(xml); | ||
// TODO: remove before release | ||
console.log("Current hash: '%s', cached hash: '%s'", hash, this.getData("hash")); | ||
this._valid = hash == this.getData("hash"); | ||
} | ||
return this._valid; | ||
}; | ||
|
||
this.toHash = function(xml) { | ||
return this.hashCode((new XMLSerializer()).serializeToString(xml)); | ||
}; | ||
|
||
this.clear = function(configSuffix) { | ||
configSuffix = configSuffix || templateEngine.configSuffix; | ||
localStorage.removeItem(configSuffix+"."+this._cacheKey); | ||
localStorage.removeItem(configSuffix+".body"); | ||
}; | ||
|
||
/** | ||
* @see http://stackoverflow.com/q/7616461/940217 | ||
* @return {number} | ||
*/ | ||
this.hashCode = function(string){ | ||
if (Array.prototype.reduce){ | ||
return string.split("").reduce(function(a,b){a=((a<<5)-a)+b.charCodeAt(0);return a&a},0); | ||
} | ||
var hash = 0; | ||
if (string.length === 0) return hash; | ||
for (var i = 0, l = string.length; i < l; i++) { | ||
var character = string.charCodeAt(i); | ||
hash = ((hash<<5)-hash)+character; | ||
hash = hash & hash; // Convert to 32bit integer | ||
} | ||
return hash; | ||
} | ||
} | ||
return { | ||
// simulate a singleton | ||
getInstance : function() { | ||
if (!instance) { | ||
instance = new ConfigCache(); | ||
} | ||
return instance; | ||
} | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* MessageBroker.js | ||
* | ||
* copyright (c) 2010-2016, Christian Mayer and the CometVisu contributers. | ||
* | ||
* This program is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License as published by the Free | ||
* Software Foundation; either version 3 of the License, or (at your option) | ||
* any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
* more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along | ||
* with this program; if not, write to the Free Software Foundation, Inc., | ||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA | ||
*/ | ||
|
||
/** | ||
* Global MessageBroker for publishing/subscribing messages on defined topics | ||
* | ||
* @author Tobias Bräutigam | ||
* @since 0.10.0 | ||
*/ | ||
define([], function() { | ||
var instance; | ||
|
||
function MessageBroker() { | ||
|
||
this.__registry = {}; | ||
// topics only fired once | ||
this.__singleEventTopics = ["setup.dom.finished"]; | ||
|
||
this.enableTestMode = function() { | ||
this.__singleEventTopics = []; | ||
}; | ||
|
||
this.subscribeOnce = function (topic, callback, context, priority) { | ||
this.subscribe(topic, callback, context, priority, true); | ||
}; | ||
|
||
this.subscribe = function (topic, callback, context, priority, once) { | ||
if (!this.__registry[topic]) { | ||
this.__registry[topic] = []; | ||
} | ||
var registry = this.__registry[topic]; | ||
registry.push([callback || this, context, priority || 0, once || false]); | ||
// sort by priority | ||
registry.sort(function(a, b) { | ||
return b[2] - a[2]; | ||
}) | ||
}; | ||
|
||
this.publish = function (topic) { | ||
var registry = this.__registry[topic]; | ||
if (registry) { | ||
var remove = []; | ||
registry.forEach(function(entry, index) { | ||
entry[0].apply(entry[1], Array.prototype.slice.call(arguments, 1)); | ||
if (entry[3] === true) { | ||
remove.push(index); | ||
} | ||
}); | ||
if (this.__singleEventTopics.indexOf(topic) >= 0) { | ||
// this is a single-fire event and can only be fired once -> delete listeners | ||
delete this.__registry[topic]; | ||
} | ||
else { | ||
remove.forEach(function (index) { | ||
registry.splice(index, 1); | ||
}, this); | ||
} | ||
} | ||
}; | ||
|
||
this.clear = function() { | ||
this.__registry = {}; | ||
} | ||
} | ||
return { | ||
// simulate a singleton | ||
getInstance : function() { | ||
if (!instance) { | ||
instance = new MessageBroker(); | ||
} | ||
return instance; | ||
} | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.