|
From: <ma...@us...> - 2013-02-09 18:30:48
|
Revision: 1451
http://openautomation.svn.sourceforge.net/openautomation/?rev=1451&view=rev
Author: mayerch
Date: 2013-02-09 18:30:36 +0000 (Sat, 09 Feb 2013)
Log Message:
-----------
New try at handling the script includes
Modified Paths:
--------------
CometVisu/trunk/visu/index.html
CometVisu/trunk/visu/lib/compatibility.js
CometVisu/trunk/visu/lib/templateengine.js
CometVisu/trunk/visu/plugins/clock/structure_plugin.js
CometVisu/trunk/visu/plugins/colorchooser/structure_plugin.js
CometVisu/trunk/visu/plugins/diagram/structure_plugin.js
CometVisu/trunk/visu/plugins/rsslog/structure_plugin.js
CometVisu/trunk/visu/plugins/strftime/structure_plugin.js
CometVisu/trunk/visu/plugins/svg/structure_plugin.js
CometVisu/trunk/visu/plugins/upnpcontroller/structure_plugin.js
Modified: CometVisu/trunk/visu/index.html
===================================================================
--- CometVisu/trunk/visu/index.html 2013-02-09 18:01:44 UTC (rev 1450)
+++ CometVisu/trunk/visu/index.html 2013-02-09 18:30:36 UTC (rev 1451)
@@ -17,7 +17,7 @@
<script src="lib/compatibility.js" type="text/javascript"></script>
<script type="text/javascript">
$.ajaxSetup({ crossDomain: true, cache: 'true' != $.getUrlVar('forceReload') }); // make scripts debugable
- $.getOrderedScripts([
+ $.includeScripts([
"dependencies/jquery-ui.js",
"dependencies/strftime.js",
"dependencies/scrollable.js",
Modified: CometVisu/trunk/visu/lib/compatibility.js
===================================================================
--- CometVisu/trunk/visu/lib/compatibility.js 2013-02-09 18:01:44 UTC (rev 1450)
+++ CometVisu/trunk/visu/lib/compatibility.js 2013-02-09 18:30:36 UTC (rev 1451)
@@ -177,25 +177,16 @@
getUrlVar: function(name){
return $.getUrlVars()[name];
},
- getScriptSync: function( url ) {
- $.ajax({
- url: url,
- dataType: 'script',
- async: false
- });
- },
- // heavily inspired by: http://stackoverflow.com/questions/13066712/how-to-load-a-list-of-javascript-files-and-call-a-callback-after-all-of-them-are
+ /**
+ * heavily inspired by: http://stackoverflow.com/questions/13066712/how-to-load-a-list-of-javascript-files-and-call-a-callback-after-all-of-them-are
+ */
getOrderedScripts: function(files, callback) {
if( 'object' === typeof files && 0 == files.length && callback )
+ {
callback();
- else
- /*
- $.getScript( files.shift(), files.length
- ? function(){ $.getOrderedScripts(files, callback);}
- : callback
- );
- */
- // temporary fix till a better solution could be implemented:
+ } else {
+ if( 'string' === typeof files )
+ files = [ files ];
$.ajax({
url: files.shift(),
dataType: 'script',
@@ -204,7 +195,15 @@
? function(){ $.getOrderedScripts(files, callback);}
: callback
});
+ }
},
+ /**
+ * Include files on this place. This will be replaced by the content of the
+ * script during packaging
+ */
+ includeScripts: function(files, callback) {
+ this.getOrderedScripts(files, callback);
+ },
// inspired by http://stackoverflow.com/questions/2685614/load-external-css-file-like-scripts-in-jquery-which-is-compatible-in-ie-also
getCSS: function( url, parameters ) {
var cssLink = $( '<link/>' );
Modified: CometVisu/trunk/visu/lib/templateengine.js
===================================================================
--- CometVisu/trunk/visu/lib/templateengine.js 2013-02-09 18:01:44 UTC (rev 1450)
+++ CometVisu/trunk/visu/lib/templateengine.js 2013-02-09 18:30:36 UTC (rev 1451)
@@ -373,7 +373,10 @@
return className;
};
- this.parseXML = function(xml) {
+ var pluginsToLoadCount = 0;
+ var xml;
+ this.parseXML = function(loaded_xml) {
+ xml = loaded_xml;
// erst mal den Cache für AJAX-Requests wieder aktivieren
/*
$.ajaxSetup({
@@ -436,22 +439,19 @@
{media: 'only screen and (max-width: '
+ thisTemplateEngine.maxMobileScreenWidth + 'px)'} );
$.getCSS( 'designs/' + thisTemplateEngine.clientDesign + '/custom.css' );
- $.getScript( 'designs/' + thisTemplateEngine.clientDesign + '/design_setup.js',
+ $.getOrderedScripts( ['designs/' + thisTemplateEngine.clientDesign + '/design_setup.js'],
function(){
thisTemplateEngine.designReady = true;
- thisTemplateEngine.setup_page(xml);
+ thisTemplateEngine.setup_page();
}
);
// start with the plugins
var pluginsToLoad = [];
$('meta > plugins plugin', xml).each(function(i) {
- pluginsToLoad.push( 'plugins/' + $(this).attr('name') + '/structure_plugin.js' );
+ pluginsToLoadCount++;
+ $.getOrderedScripts( ['plugins/' + $(this).attr('name') + '/structure_plugin.js'] );
});
- $.getOrderedScripts( pluginsToLoad, function(){
- thisTemplateEngine.pluginsReady = true;
- thisTemplateEngine.setup_page(xml);
- });
// then the icons
$('meta > icons icon-definition', xml).each(function(i) {
@@ -555,7 +555,7 @@
});
thisTemplateEngine.pageReady = true;
- thisTemplateEngine.setup_page(xml);
+ thisTemplateEngine.setup_page();
};
/**
@@ -594,7 +594,7 @@
};
- this.setup_page = function(xml) {
+ this.setup_page = function() {
// and now setup the pages
// check if the page and the plugins are ready now
@@ -651,7 +651,8 @@
$('embed').each(function() {
this.onload = function() {
var svg = this.getSVGDocument();
-
+ if( !svg ) return;
+
// Pipe-O-Matic:
var pipes = svg.getElementsByClassName('pipe_group');
$(pipes).each(function() {
@@ -779,6 +780,8 @@
thisTemplateEngine.visu.setInitialAddresses(Object.keys(startPageAddresses));
}
thisTemplateEngine.visu.subscribe(thisTemplateEngine.getAddresses());
+
+ delete xml; // not needed anymore - free the space
// $(window).trigger('resize');
$("#pages").triggerHandler("done");
};
@@ -1076,6 +1079,26 @@
}
}
};
+
+ /**
+ * Load a script and run it before page setup.
+ * This is needed for plugin that depend on an external library.
+ */
+ this.getPluginDependency = function( url ){
+ $.getScriptSync( url );
+ }
+
+ /**
+ * This has to be called by a plugin once it was loaded.
+ */
+ this.pluginLoaded = function(){
+ pluginsToLoadCount--;
+ if( 0 == pluginsToLoadCount )
+ {
+ thisTemplateEngine.pluginsReady = true;
+ thisTemplateEngine.setup_page();
+ }
+ }
}
function PagePartsHandler() {
Modified: CometVisu/trunk/visu/plugins/clock/structure_plugin.js
===================================================================
--- CometVisu/trunk/visu/plugins/clock/structure_plugin.js 2013-02-09 18:01:44 UTC (rev 1450)
+++ CometVisu/trunk/visu/plugins/clock/structure_plugin.js 2013-02-09 18:30:36 UTC (rev 1451)
@@ -124,4 +124,6 @@
templateEngine.visu.write( addr.substr(1), templateEngine.transformEncode( data.address[addr][0], data.value ) );
}
}
-});
\ No newline at end of file
+});
+
+templateEngine.pluginLoaded();
\ No newline at end of file
Modified: CometVisu/trunk/visu/plugins/colorchooser/structure_plugin.js
===================================================================
--- CometVisu/trunk/visu/plugins/colorchooser/structure_plugin.js 2013-02-09 18:01:44 UTC (rev 1450)
+++ CometVisu/trunk/visu/plugins/colorchooser/structure_plugin.js 2013-02-09 18:30:36 UTC (rev 1451)
@@ -162,6 +162,6 @@
/**
* Include the needed stuff
*/
-$.getScriptSync( 'plugins/colorchooser/farbtastic/farbtastic.js' );
$.getCSS( 'plugins/colorchooser/farbtastic/farbtastic.css' );
+$.includeScripts( 'plugins/colorchooser/farbtastic/farbtastic.js', templateEngine.pluginLoaded );
Modified: CometVisu/trunk/visu/plugins/diagram/structure_plugin.js
===================================================================
--- CometVisu/trunk/visu/plugins/diagram/structure_plugin.js 2013-02-09 18:01:44 UTC (rev 1450)
+++ CometVisu/trunk/visu/plugins/diagram/structure_plugin.js 2013-02-09 18:30:36 UTC (rev 1451)
@@ -52,10 +52,10 @@
*
*/
-$.getOrderedScripts([
+$.includeScripts([
'plugins/diagram/flot/jquery.flot.js',
'plugins/diagram/flot/jquery.flot.axislabels.js'
-]);
+], templateEngine.pluginLoaded );
function diagram_get_content( page ) {
Modified: CometVisu/trunk/visu/plugins/rsslog/structure_plugin.js
===================================================================
--- CometVisu/trunk/visu/plugins/rsslog/structure_plugin.js 2013-02-09 18:01:44 UTC (rev 1450)
+++ CometVisu/trunk/visu/plugins/rsslog/structure_plugin.js 2013-02-09 18:30:36 UTC (rev 1451)
@@ -15,9 +15,7 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
-$.get("plugins/rsslog/rsslog.css", function(css) {
- $("head").append("<style>"+css+"</style>");
-});
+$.getCSS( 'plugins/rsslog/rsslog.css' );
VisuDesign_Custom.prototype.addCreator("rsslog", {
create: function( page, path ) {
@@ -253,3 +251,4 @@
});
})(jQuery);
+templateEngine.pluginLoaded();
\ No newline at end of file
Modified: CometVisu/trunk/visu/plugins/strftime/structure_plugin.js
===================================================================
--- CometVisu/trunk/visu/plugins/strftime/structure_plugin.js 2013-02-09 18:01:44 UTC (rev 1450)
+++ CometVisu/trunk/visu/plugins/strftime/structure_plugin.js 2013-02-09 18:30:36 UTC (rev 1451)
@@ -22,7 +22,7 @@
* Thanks to Michael Markstaller for implementing the jqclock as reference.
*/
-$('head').append('<link rel="stylesheet" href="plugins/strftime/strftime.css" type="text/css" />');
+$.getCSS( 'plugins/strftime/strftime.css' );
VisuDesign_Custom.prototype.addCreator("strftime", {
create : function(page, path) {
@@ -84,3 +84,5 @@
return ret_val;
}
});
+
+templateEngine.pluginLoaded();
\ No newline at end of file
Modified: CometVisu/trunk/visu/plugins/svg/structure_plugin.js
===================================================================
--- CometVisu/trunk/visu/plugins/svg/structure_plugin.js 2013-02-09 18:01:44 UTC (rev 1450)
+++ CometVisu/trunk/visu/plugins/svg/structure_plugin.js 2013-02-09 18:30:36 UTC (rev 1451)
@@ -72,4 +72,6 @@
element.find('#line'+(i+1)).attr('y2',9);
}
}
-});
\ No newline at end of file
+});
+
+templateEngine.pluginLoaded();
\ No newline at end of file
Modified: CometVisu/trunk/visu/plugins/upnpcontroller/structure_plugin.js
===================================================================
--- CometVisu/trunk/visu/plugins/upnpcontroller/structure_plugin.js 2013-02-09 18:01:44 UTC (rev 1450)
+++ CometVisu/trunk/visu/plugins/upnpcontroller/structure_plugin.js 2013-02-09 18:30:36 UTC (rev 1451)
@@ -15,8 +15,7 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
-
-$( 'head' ).append( '<link rel="stylesheet" href="plugins/upnpcontroller/upnpcontroller.css" type="text/css" />' );
+$.getCSS( 'plugins/upnpcontroller/upnpcontroller.css' );
var upnpcontroller_uid;
var upnpcontroller_trace_flag;
@@ -393,3 +392,4 @@
}
}
+templateEngine.pluginLoaded();
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|