Skip to content

Commit

Permalink
Merge 75dcfc4 into 062337c
Browse files Browse the repository at this point in the history
  • Loading branch information
peuter committed Nov 13, 2016
2 parents 062337c + 75dcfc4 commit c99abc9
Show file tree
Hide file tree
Showing 40 changed files with 2,223 additions and 1,858 deletions.
5 changes: 4 additions & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,10 @@ module.exports = function(grunt) {
configFile: 'karma.conf.js',
singleRun: true,
browsers: ['PhantomJS'],
reporters: ['progress']
reporters: ['progress'],
client: {
captureConsole: true
}
}
},

Expand Down
17 changes: 17 additions & 0 deletions doc/manual/de/config/url-params.rst
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,20 @@ funktionieren.
Default: 0 (testMode=0)
Options: 0 (testMode=0), 1 (testMode=1)
*enableCache* - Caching aktivieren
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Durch den Parameter ``enableCache`` kann das Caching konfiguriert werden. Dieses bewirkt, dass eine Config
nicht bei jeden Laden komplett neu eingelesen wird und daraus eine HTML-Seite generiert wird, sondern dass
die gerenderte HTML-Struktur inkl. aller weiterer benötigter Daten lokal im Browser gespeichert werden
(im LocalStore). Bei jedem weiteren Laden der Config werden die Daten also aus dem Cache gelesen, was
das Laden der Visu auf leistungsschwachen Geräten wie z.B. Smartphones beschleunigt.

Der Cache kann über diesen Parameter aktiviert (=true), deaktivert (=false) oder gelöscht werden (=invalid).
Das Löschen bewirkt, dass alle Werte aus dem Cache gelöscht werden und neu angelegt werden.

.. code::
Default: true (enableCache=true)
Options: false (enableCache=false), true (enableCache=true), invalid (enableCache=invalid)
3 changes: 2 additions & 1 deletion src/cometvisu.appcache
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
CACHE MANIFEST
# Version GIT:20160528-2208
# Version GIT:20161114-1409

CACHE:
index.html
Expand Down Expand Up @@ -30,6 +30,7 @@ lib/IconHandler.js
lib/IconTools.js
lib/Compatibility.js
lib/CometVisuClient.js
lib/ConfigCache.js
lib/PageHandler.js
lib/PagePartsHandler.js
lib/TrickOMatic.js
Expand Down
2 changes: 1 addition & 1 deletion src/designs/metal/design_setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ $(window).bind('scrolltopage',function() {
}
});

templateEngine.bindActionForLoadingFinished(function() {
templateEngine.messageBroker.subscribe("loading.done", function() {
$('#navbarLeft .navbar .widget .label,#navbarRight .navbar .widget .label').each(function(i) {
var label = $(this);
if (label.text().trim()!="") {
Expand Down
125 changes: 125 additions & 0 deletions src/lib/ConfigCache.js
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;
}
};
});
90 changes: 90 additions & 0 deletions src/lib/MessageBroker.js
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;
}
};
});
33 changes: 12 additions & 21 deletions src/lib/PageHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
// FIXME and TODO: This class is currently just a quick hack to get rid
// of the jQuery-Tools Scrollable. It should be enhanced to allow different
// page transition animations like blending, etc. pp.
define([ 'jquery' ], function( $ ) {
define([ 'jquery', 'MessageBroker' ], function( $, MessageBroker ) {
"use strict";

var
Expand All @@ -39,31 +39,24 @@ define([ 'jquery' ], function( $ ) {

this.seekTo = function( target, speed )
{
currentPath !== '' && templateEngine.callbacks[currentPath].exitingPageChange.forEach( function( callback ){
callback( currentPath, target );
});

var
page = $('#' + target),
callbacks = templateEngine.callbacks[target];


currentPath !== '' && MessageBroker.getInstance().publish("path."+currentPath+".exitingPageChange", currentPath, target);

var page = $('#' + target);

if( 0 === page.length ) // check if page does exist
return;

callbacks.beforePageChange.forEach( function( callback ){
callback( target );
});

MessageBroker.getInstance().publish("path."+target+".beforePageChange", target);

templateEngine.resetPageValues();

templateEngine.currentPage = page;

page.addClass('pageActive activePage');// show new page

callbacks.duringPageChange.forEach( function( callback ){
callback( target );
});


MessageBroker.getInstance().publish("path."+target+".duringPageChange", target);

// update visibility of navbars, top-navigation, footer
templateEngine.pagePartsHandler.updatePageParts( page, speed );

Expand All @@ -87,9 +80,7 @@ define([ 'jquery' ], function( $ ) {
$('.pageActive', '#pages').removeClass('pageActive');
templateEngine.currentPage.addClass('pageActive activePage');// show new page
$('#pages').css('left', 0 );
currentPath !== '' && templateEngine.callbacks[currentPath].afterPageChange.forEach( function( callback ){
callback( currentPath );
});
currentPath !== '' && MessageBroker.getInstance().publish("path."+currentPath+".afterPageChange", currentPath);
});
};

Expand Down

0 comments on commit c99abc9

Please sign in to comment.