# HG changeset patch # User veltr # Date 1336989425 -7200 # Node ID 12b2cd7e91591979c62d8ee6e72b17898482b9c3 # Parent 445631dffdf8b3721e20791a077d90392fe3c4d5 Compatibility for tracemanager diff -r 445631dffdf8 -r 12b2cd7e9159 src/js/libs/tracemanager.js --- a/src/js/libs/tracemanager.js Fri May 11 16:07:52 2012 +0200 +++ b/src/js/libs/tracemanager.js Mon May 14 11:57:05 2012 +0200 @@ -1,7 +1,24 @@ /* * Modelled Trace API + * + * This file is part of ktbs4js. + * + * ktbs4js is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * ktbs4js 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with ktbs4js. If not, see . + * */ -IriSP.TraceManager = function($) { +/* FIXME: properly use require.js feature. This will do for debugging in the meantime */ +window.tracemanager = (function($) { // If there are more than MAX_FAILURE_COUNT synchronisation // failures, then disable synchronisation MAX_FAILURE_COUNT = 20; @@ -12,8 +29,8 @@ var BufferedService_prototype = { /* -* Buffered service for traces -*/ + * Buffered service for traces + */ // url: "", // buffer: [], // isReady: false, @@ -72,8 +89,8 @@ }, /* Sync mode: delayed, sync (immediate sync), none (no -* synchronisation with server, the trace has to be explicitly saved -* if needed */ + * synchronisation with server, the trace has to be explicitly saved + * if needed */ set_sync_mode: function(mode, default_subject) { this.sync_mode = mode; if (! this.isReady && mode !== "none") @@ -118,8 +135,8 @@ }, /* -* Initialize the sync service -*/ + * Initialize the sync service + */ init: function(default_subject) { var self = this; if (this.isReady) @@ -170,20 +187,20 @@ var Trace_prototype = { /* FIXME: We could/should use a sorted list such as -http://closure-library.googlecode.com/svn/docs/class_goog_structs_AvlTree.html -to speed up queries based on time */ + http://closure-library.googlecode.com/svn/docs/class_goog_structs_AvlTree.html + to speed up queries based on time */ obsels: [], /* Trace URI */ uri: "", default_subject: "", /* baseuri is used as the base URI to resolve relative -* attribute-type names in obsels. Strictly speaking, this -* should rather be expressed as a reference to model, or -* more generically, as a qname/URI dict */ + * attribute-type names in obsels. Strictly speaking, this + * should rather be expressed as a reference to model, or + * more generically, as a qname/URI dict */ baseuri: "", /* Mapping of obsel type or property name to a compact -* representation (shorthands). -*/ + * representation (shorthands). + */ shorthands: null, syncservice: null, @@ -193,8 +210,8 @@ }, /* Sync mode: delayed, sync (immediate sync), none (no -* synchronisation with server, the trace has to be explicitly saved -* if needed */ + * synchronisation with server, the trace has to be explicitly saved + * if needed */ set_sync_mode: function(mode) { if (this.syncservice !== null) { this.syncservice.set_sync_mode(mode, this.default_subject); @@ -202,14 +219,14 @@ }, /* -* Return a list of the obsels of this trace matching the parameters -*/ + * Return a list of the obsels of this trace matching the parameters + */ list_obsels: function(_begin, _end, _reverse) { var res; if (typeof _begin !== 'undefined' || typeof _end !== 'undefined') { /* -* Not optimized yet. -*/ + * Not optimized yet. + */ res = []; var l = this.obsels.length; for (var i = 0; i < l; i++) { @@ -237,8 +254,8 @@ }, /* -* Return the obsel of this trace identified by the URI, or undefined -*/ + * Return the obsel of this trace identified by the URI, or undefined + */ get_obsel: function(id) { for (var i = 0; i < this.obsels.length; i++) { /* FIXME: should check against variations of id/uri, take this.baseuri into account */ @@ -296,8 +313,8 @@ var Trace = function(uri, requestmode) { /* FIXME: We could/should use a sorted list such as -http://closure-library.googlecode.com/svn/docs/class_goog_structs_AvlTree.html -to speed up queries based on time */ + http://closure-library.googlecode.com/svn/docs/class_goog_structs_AvlTree.html + to speed up queries based on time */ this.obsels = []; /* Trace URI */ if (uri === undefined) @@ -321,8 +338,8 @@ var Obsel_prototype = { /* The following attributes are here for documentation -* purposes. They MUST be defined in the constructor -* function. */ + * purposes. They MUST be defined in the constructor + * function. */ trace: undefined, type: undefined, begin: undefined, @@ -373,8 +390,8 @@ /* FIXME: not implemented yet */ }, /* -* Return the value of the given attribute type for this obsel -*/ + * Return the value of the given attribute type for this obsel + */ get_attribute_value: function(at) { if (typeof at === "string") /* It is a URI */ @@ -414,8 +431,8 @@ }, /* -* Return a JSON representation of the obsel -*/ + * Return a JSON representation of the obsel + */ toJSON: function() { var r = { "@id": this.id, @@ -432,9 +449,9 @@ }, /* -* Return a compact JSON representation of the obsel. -* Use predefined + custom shorthands for types/properties -*/ + * Return a compact JSON representation of the obsel. + * Use predefined + custom shorthands for types/properties + */ toCompactJSON: function() { var r = { "@t": (this.trace.shorthands.hasOwnProperty(this.type) ? this.trace.shorthands[this.type] : this.type), @@ -485,19 +502,19 @@ var TraceManager_prototype = { traces: [], /* -* Return the trace with id name -* If it was not registered, return undefined. -*/ + * Return the trace with id name + * If it was not registered, return undefined. + */ get_trace: function(name) { return this.traces[name]; }, /* -* Explicitly create and initialize a new trace with the given name. -* The optional uri parameter allows to initialize the trace URI. -* -* If another existed with the same name before, then it is replaced by a new one. -*/ + * Explicitly create and initialize a new trace with the given name. + * The optional uri parameter allows to initialize the trace URI. + * + * If another existed with the same name before, then it is replaced by a new one. + */ init_trace: function(name, params) { if (window.console) window.console.log("init_trace", params); @@ -518,6 +535,6 @@ }; TraceManager.prototype = TraceManager_prototype; - var tracemanager = new TraceManager(); + var tracemanager = new TraceManager(); return tracemanager; - }; + })(jQuery); diff -r 445631dffdf8 -r 12b2cd7e9159 src/js/main.js --- a/src/js/main.js Fri May 11 16:07:52 2012 +0200 +++ b/src/js/main.js Mon May 14 11:57:05 2012 +0200 @@ -35,9 +35,20 @@ ) } +IriSP._cssCache = []; + +IriSP.loadCss = function(_cssFile) { + if (typeof _cssFile === "string" && _cssFile && IriSP._(IriSP._cssCache).indexOf(_cssFile) === -1) { + IriSP.jQuery("", { + rel : "stylesheet", + type : "text/css", + href : _cssFile + }).appendTo('head'); + IriSP._cssCache.push(_cssFile); + } +} + IriSP.loadLibs = function( config, metadata_url, callback ) { - // Localize jQuery variable - IriSP.jQuery = null; var $L = $LAB.script(IriSP.getLib("jQuery")).script(IriSP.getLib("swfObject")).wait() .script(IriSP.getLib("jQueryUI")); @@ -63,9 +74,6 @@ config.gui.widgets[idx].type === "SparklineWidget") { $L.script(IriSP.getLib("raphael")); } - if (config.gui.widgets[idx].type === "TraceWidget") { - $L.script(IriSP.getLib("tracemanager")) - } } // same for modules @@ -75,25 +83,12 @@ $L.script(IriSP.getLib("raphaelJs")); } */ - $L.wait(function() { - IriSP.jQuery = window.jQuery.noConflict( true ); - - var css_link_jquery = IriSP.jQuery( "", { - rel: "stylesheet", - type: "text/css", - href: IriSP.getLib("cssjQueryUI"), - 'class': "dynamic_css" - } ); - var css_link_custom = IriSP.jQuery( "", { - rel: "stylesheet", - type: "text/css", - href: config.gui.css, - 'class': "dynamic_css" - } ); - - css_link_jquery.appendTo('head'); - css_link_custom.appendTo('head'); + if (typeof IriSP.jQuery === "undefined" && typeof window.jQuery !== "undefined") { + IriSP.jQuery = window.jQuery.noConflict(); + } + IriSP.loadCss(IriSP.getLib("cssjQueryUI")); + IriSP.loadCss(config.gui.css); IriSP.setupDataLoader(); IriSP.__dataloader.get(metadata_url, diff -r 445631dffdf8 -r 12b2cd7e9159 src/js/widgets/traceWidget.js --- a/src/js/widgets/traceWidget.js Fri May 11 16:07:52 2012 +0200 +++ b/src/js/widgets/traceWidget.js Mon May 14 11:57:05 2012 +0200 @@ -29,17 +29,24 @@ } _this._Popcorn.listen(_listener, _f); }); - this._Popcorn.listen("timeupdate", IriSP.underscore.throttle(function(_arg) { - _this.eventHandler(_listener, _arg); - })); - this.tracer = IriSP.TraceManager(IriSP.jQuery).init_trace("test", this._config); - this.tracer.trace("StartTracing", { "hello": "world" }); + if (typeof window.tracemanager === "undefined") { + $LAB.script(IriSP.getLib("tracemanager")).wait(function() { + _this.onTmLoaded(); + }); + } else { + this.onTmLoaded(); + } } IriSP.TraceWidget.prototype = new IriSP.Widget(); +IriSP.TraceWidget.prototype.onTmLoaded = function() { + this.tracer = window.tracemanager.init_trace("test", this._config); + this.tracer.trace("StartTracing", { "hello": "world" }); +} + IriSP.TraceWidget.prototype.draw = function() { this.mouseLocation = ''; var _this = this; diff -r 445631dffdf8 -r 12b2cd7e9159 test/integration/allocine_dossier_independant/js/LdtPlayer-release.js --- a/test/integration/allocine_dossier_independant/js/LdtPlayer-release.js Fri May 11 16:07:52 2012 +0200 +++ b/test/integration/allocine_dossier_independant/js/LdtPlayer-release.js Mon May 14 11:57:05 2012 +0200 @@ -1032,9 +1032,20 @@ ) } +IriSP._cssCache = []; + +IriSP.loadCss = function(_cssFile) { + if (typeof _cssFile === "string" && _cssFile && IriSP._(IriSP._cssCache).indexOf(_cssFile) === -1) { + IriSP.jQuery("", { + rel : "stylesheet", + type : "text/css", + href : _cssFile + }).appendTo('head'); + IriSP._cssCache.push(_cssFile); + } +} + IriSP.loadLibs = function( config, metadata_url, callback ) { - // Localize jQuery variable - IriSP.jQuery = null; var $L = $LAB.script(IriSP.getLib("jQuery")).script(IriSP.getLib("swfObject")).wait() .script(IriSP.getLib("jQueryUI")); @@ -1060,9 +1071,6 @@ config.gui.widgets[idx].type === "SparklineWidget") { $L.script(IriSP.getLib("raphael")); } - if (config.gui.widgets[idx].type === "TraceWidget") { - $L.script(IriSP.getLib("tracemanager")) - } } // same for modules @@ -1072,25 +1080,12 @@ $L.script(IriSP.getLib("raphaelJs")); } */ - $L.wait(function() { - IriSP.jQuery = window.jQuery.noConflict( true ); - - var css_link_jquery = IriSP.jQuery( "", { - rel: "stylesheet", - type: "text/css", - href: IriSP.getLib("cssjQueryUI"), - 'class': "dynamic_css" - } ); - var css_link_custom = IriSP.jQuery( "", { - rel: "stylesheet", - type: "text/css", - href: config.gui.css, - 'class': "dynamic_css" - } ); - - css_link_jquery.appendTo('head'); - css_link_custom.appendTo('head'); + if (typeof IriSP.jQuery === "undefined" && typeof window.jQuery !== "undefined") { + IriSP.jQuery = window.jQuery.noConflict(); + } + IriSP.loadCss(IriSP.getLib("cssjQueryUI")); + IriSP.loadCss(config.gui.css); IriSP.setupDataLoader(); IriSP.__dataloader.get(metadata_url, @@ -5784,17 +5779,24 @@ } _this._Popcorn.listen(_listener, _f); }); - this._Popcorn.listen("timeupdate", IriSP.underscore.throttle(function(_arg) { - _this.eventHandler(_listener, _arg); - })); - this.tracer = IriSP.TraceManager(IriSP.jQuery).init_trace("test", this._config); - this.tracer.trace("StartTracing", { "hello": "world" }); + if (typeof window.tracemanager === "undefined") { + $LAB.script(IriSP.getLib("tracemanager")).wait(function() { + _this.onTmLoaded(); + }); + } else { + this.onTmLoaded(); + } } IriSP.TraceWidget.prototype = new IriSP.Widget(); +IriSP.TraceWidget.prototype.onTmLoaded = function() { + this.tracer = window.tracemanager.init_trace("test", this._config); + this.tracer.trace("StartTracing", { "hello": "world" }); +} + IriSP.TraceWidget.prototype.draw = function() { this.mouseLocation = ''; var _this = this; diff -r 445631dffdf8 -r 12b2cd7e9159 test/integration/allocine_dossier_independant/js/libs/tracemanager.js --- a/test/integration/allocine_dossier_independant/js/libs/tracemanager.js Fri May 11 16:07:52 2012 +0200 +++ b/test/integration/allocine_dossier_independant/js/libs/tracemanager.js Mon May 14 11:57:05 2012 +0200 @@ -1,7 +1,24 @@ /* * Modelled Trace API + * + * This file is part of ktbs4js. + * + * ktbs4js is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * ktbs4js 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with ktbs4js. If not, see . + * */ -IriSP.TraceManager = function($) { +/* FIXME: properly use require.js feature. This will do for debugging in the meantime */ +window.tracemanager = (function($) { // If there are more than MAX_FAILURE_COUNT synchronisation // failures, then disable synchronisation MAX_FAILURE_COUNT = 20; @@ -12,8 +29,8 @@ var BufferedService_prototype = { /* -* Buffered service for traces -*/ + * Buffered service for traces + */ // url: "", // buffer: [], // isReady: false, @@ -72,8 +89,8 @@ }, /* Sync mode: delayed, sync (immediate sync), none (no -* synchronisation with server, the trace has to be explicitly saved -* if needed */ + * synchronisation with server, the trace has to be explicitly saved + * if needed */ set_sync_mode: function(mode, default_subject) { this.sync_mode = mode; if (! this.isReady && mode !== "none") @@ -118,8 +135,8 @@ }, /* -* Initialize the sync service -*/ + * Initialize the sync service + */ init: function(default_subject) { var self = this; if (this.isReady) @@ -170,20 +187,20 @@ var Trace_prototype = { /* FIXME: We could/should use a sorted list such as -http://closure-library.googlecode.com/svn/docs/class_goog_structs_AvlTree.html -to speed up queries based on time */ + http://closure-library.googlecode.com/svn/docs/class_goog_structs_AvlTree.html + to speed up queries based on time */ obsels: [], /* Trace URI */ uri: "", default_subject: "", /* baseuri is used as the base URI to resolve relative -* attribute-type names in obsels. Strictly speaking, this -* should rather be expressed as a reference to model, or -* more generically, as a qname/URI dict */ + * attribute-type names in obsels. Strictly speaking, this + * should rather be expressed as a reference to model, or + * more generically, as a qname/URI dict */ baseuri: "", /* Mapping of obsel type or property name to a compact -* representation (shorthands). -*/ + * representation (shorthands). + */ shorthands: null, syncservice: null, @@ -193,8 +210,8 @@ }, /* Sync mode: delayed, sync (immediate sync), none (no -* synchronisation with server, the trace has to be explicitly saved -* if needed */ + * synchronisation with server, the trace has to be explicitly saved + * if needed */ set_sync_mode: function(mode) { if (this.syncservice !== null) { this.syncservice.set_sync_mode(mode, this.default_subject); @@ -202,14 +219,14 @@ }, /* -* Return a list of the obsels of this trace matching the parameters -*/ + * Return a list of the obsels of this trace matching the parameters + */ list_obsels: function(_begin, _end, _reverse) { var res; if (typeof _begin !== 'undefined' || typeof _end !== 'undefined') { /* -* Not optimized yet. -*/ + * Not optimized yet. + */ res = []; var l = this.obsels.length; for (var i = 0; i < l; i++) { @@ -237,8 +254,8 @@ }, /* -* Return the obsel of this trace identified by the URI, or undefined -*/ + * Return the obsel of this trace identified by the URI, or undefined + */ get_obsel: function(id) { for (var i = 0; i < this.obsels.length; i++) { /* FIXME: should check against variations of id/uri, take this.baseuri into account */ @@ -296,8 +313,8 @@ var Trace = function(uri, requestmode) { /* FIXME: We could/should use a sorted list such as -http://closure-library.googlecode.com/svn/docs/class_goog_structs_AvlTree.html -to speed up queries based on time */ + http://closure-library.googlecode.com/svn/docs/class_goog_structs_AvlTree.html + to speed up queries based on time */ this.obsels = []; /* Trace URI */ if (uri === undefined) @@ -321,8 +338,8 @@ var Obsel_prototype = { /* The following attributes are here for documentation -* purposes. They MUST be defined in the constructor -* function. */ + * purposes. They MUST be defined in the constructor + * function. */ trace: undefined, type: undefined, begin: undefined, @@ -373,8 +390,8 @@ /* FIXME: not implemented yet */ }, /* -* Return the value of the given attribute type for this obsel -*/ + * Return the value of the given attribute type for this obsel + */ get_attribute_value: function(at) { if (typeof at === "string") /* It is a URI */ @@ -414,8 +431,8 @@ }, /* -* Return a JSON representation of the obsel -*/ + * Return a JSON representation of the obsel + */ toJSON: function() { var r = { "@id": this.id, @@ -432,9 +449,9 @@ }, /* -* Return a compact JSON representation of the obsel. -* Use predefined + custom shorthands for types/properties -*/ + * Return a compact JSON representation of the obsel. + * Use predefined + custom shorthands for types/properties + */ toCompactJSON: function() { var r = { "@t": (this.trace.shorthands.hasOwnProperty(this.type) ? this.trace.shorthands[this.type] : this.type), @@ -485,19 +502,19 @@ var TraceManager_prototype = { traces: [], /* -* Return the trace with id name -* If it was not registered, return undefined. -*/ + * Return the trace with id name + * If it was not registered, return undefined. + */ get_trace: function(name) { return this.traces[name]; }, /* -* Explicitly create and initialize a new trace with the given name. -* The optional uri parameter allows to initialize the trace URI. -* -* If another existed with the same name before, then it is replaced by a new one. -*/ + * Explicitly create and initialize a new trace with the given name. + * The optional uri parameter allows to initialize the trace URI. + * + * If another existed with the same name before, then it is replaced by a new one. + */ init_trace: function(name, params) { if (window.console) window.console.log("init_trace", params); @@ -518,6 +535,6 @@ }; TraceManager.prototype = TraceManager_prototype; - var tracemanager = new TraceManager(); + var tracemanager = new TraceManager(); return tracemanager; - }; + })(jQuery); diff -r 445631dffdf8 -r 12b2cd7e9159 test/integration/allocine_dossier_independant/test-allocine.htm --- a/test/integration/allocine_dossier_independant/test-allocine.htm Fri May 11 16:07:52 2012 +0200 +++ b/test/integration/allocine_dossier_independant/test-allocine.htm Mon May 14 11:57:05 2012 +0200 @@ -69,7 +69,7 @@ api_method : 'POST' }, { type: "TraceWidget", - // js_console : true, + js_console : true, url: "http://traces.advene.org:5000/", requestmode: 'GET', syncmode: "sync"