check jQuery and Underscore versions
authorveltr
Wed, 15 May 2013 16:22:37 +0200
changeset 1000 91023037f841
parent 999 7130fcc8ce9c
child 1001 3210bf928a11
check jQuery and Underscore versions
src/js/init.js
src/js/widgets-container/defaults.js
src/js/widgets-container/metadataplayer.js
--- a/src/js/init.js	Wed May 15 15:43:19 2013 +0200
+++ b/src/js/init.js	Wed May 15 16:22:37 2013 +0200
@@ -4,10 +4,10 @@
     window.IriSP = {};
 }
 
-if (typeof IriSP.jQuery === "undefined" && typeof window.jQuery !== "undefined") {
+if (typeof IriSP.jQuery === "undefined" && typeof window.jQuery !== "undefined" && parseFloat(window.jQuery().jquery) >= 1.7) {
     IriSP.jQuery = window.jQuery;
 }
 
-if (typeof IriSP._ === "undefined" && typeof window._ !== "undefined") {
+if (typeof IriSP._ === "undefined" && typeof window._ !== "undefined" && parseFloat(window._.VERSION) >= 1.4) {
     IriSP._ = window._;
 }
--- a/src/js/widgets-container/defaults.js	Wed May 15 15:43:19 2013 +0200
+++ b/src/js/widgets-container/defaults.js	Wed May 15 16:22:37 2013 +0200
@@ -1,3 +1,5 @@
+/* Start of defaults.js */
+
 IriSP.language = 'en';
 
 IriSP.libFiles = {
@@ -40,7 +42,7 @@
         popcorn: "http://cdn.popcornjs.org/code/dist/popcorn-complete.min.js"
     },
     useCdn : false
-}
+};
 
 IriSP.widgetsDir = 'widgets';
 
@@ -99,10 +101,12 @@
     MultiSegments: {
         noCss: true
     }
-}
+};
 
 IriSP.guiDefaults = {
     width : 640,            
     container : 'LdtPlayer',
     spacer_div_height : 0
-}
+};
+
+/* End of defaults.js */
--- a/src/js/widgets-container/metadataplayer.js	Wed May 15 15:43:19 2013 +0200
+++ b/src/js/widgets-container/metadataplayer.js	Wed May 15 16:22:37 2013 +0200
@@ -3,59 +3,73 @@
 
 /* The Metadataplayer Object, single point of entry, replaces IriSP.init_player */
 
-IriSP.Metadataplayer = function(config) {
-    IriSP.log("IriSP.Metadataplayer constructor");
-    for (var key in IriSP.guiDefaults) {
-        if (IriSP.guiDefaults.hasOwnProperty(key) && !config.hasOwnProperty(key)) {
-            config[key] = IriSP.guiDefaults[key]
+(function(ns) {
+
+var formerJQuery, formerUnderscore, former$;
+
+var Metadataplayer = ns.Metadataplayer = function(config) {
+    ns.log("IriSP.Metadataplayer constructor");
+    for (var key in ns.guiDefaults) {
+        if (ns.guiDefaults.hasOwnProperty(key) && !config.hasOwnProperty(key)) {
+            config[key] = ns.guiDefaults[key]
         }
     }
     var _container = document.getElementById(config.container);
     _container.innerHTML = '<h3 class="Ldt-Loader">Loading... Chargement...</h3>';
-    this.sourceManager = new IriSP.Model.Directory();
+    this.sourceManager = new ns.Model.Directory();
     this.config = config;
     this.__events = {};
     this.loadLibs();
 };
 
-IriSP.Metadataplayer.prototype.toString = function() {
+Metadataplayer.prototype.toString = function() {
     return 'Metadataplayer in #' + this.config.container;
 };
 
-IriSP.Metadataplayer.prototype.on = function(_event, _callback) {
+Metadataplayer.prototype.on = function(_event, _callback) {
     if (typeof this.__events[_event] === "undefined") {
         this.__events[_event] = [];
     }
     this.__events[_event].push(_callback);
 };
 
-IriSP.Metadataplayer.prototype.trigger = function(_event, _data) {
+Metadataplayer.prototype.trigger = function(_event, _data) {
     var _element = this;
-    IriSP._(this.__events[_event]).each(function(_callback) {
+    ns._(this.__events[_event]).each(function(_callback) {
         _callback.call(_element, _data);
     });
 };
 
-IriSP.Metadataplayer.prototype.loadLibs = function() {
-    IriSP.log("IriSP.Metadataplayer.prototype.loadLibs");
+Metadataplayer.prototype.loadLibs = function() {
+    ns.log("IriSP.Metadataplayer.prototype.loadLibs");
     var $L = $LAB
-        .script(IriSP.getLib("underscore"))
-        .script(IriSP.getLib("Mustache"))
-        .script(IriSP.getLib("jQuery"));
+        .script(ns.getLib("Mustache"));
+    
+    formerJQuery = !!window.jQuery;
+    former$ = !!window.$;
+    formerUnderscore = !!window._;
     
-    if (typeof JSON == "undefined") {
-        $L.script(IriSP.getLib("json"));
+    if (typeof ns.jQuery === "undefined") {
+        $L.script(ns.getLib("jQuery"));
+    }
+    
+    if (typeof ns._ === "undefined") {
+        $L.script(ns.getLib("underscore"));
+    }
+    
+    if (typeof window.JSON == "undefined") {
+        $L.script(ns.getLib("json"));
     }
     
     $L.wait()
-        .script(IriSP.getLib("jQueryUI"));
+        .script(ns.getLib("jQueryUI"));
 
     /* widget specific requirements */
     for(var _i = 0; _i < this.config.widgets.length; _i++) {
         var _t = this.config.widgets[_i].type;
-        if (typeof IriSP.widgetsRequirements[_t] !== "undefined" && typeof IriSP.widgetsRequirements[_t].requires !== "undefined" ) {
-            for (var _j = 0; _j < IriSP.widgetsRequirements[_t].requires.length; _j++) {
-                $L.script(IriSP.getLib(IriSP.widgetsRequirements[_t].requires[_j]));
+        if (typeof ns.widgetsRequirements[_t] !== "undefined" && typeof ns.widgetsRequirements[_t].requires !== "undefined" ) {
+            for (var _j = 0; _j < ns.widgetsRequirements[_t].requires.length; _j++) {
+                $L.script(ns.getLib(ns.widgetsRequirements[_t].requires[_j]));
             }
         }
     }
@@ -67,18 +81,24 @@
     });
 };
 
-IriSP.Metadataplayer.prototype.onLibsLoaded = function() {
-    IriSP.log("IriSP.Metadataplayer.prototype.onLibsLoaded");
-    if (typeof IriSP.jQuery === "undefined" && typeof window.jQuery !== "undefined") {
-        IriSP.jQuery = window.jQuery;
+Metadataplayer.prototype.onLibsLoaded = function() {
+    ns.log("IriSP.Metadataplayer.prototype.onLibsLoaded");
+    if (typeof ns.jQuery === "undefined" && typeof window.jQuery !== "undefined") {
+        ns.jQuery = window.jQuery;
+        if (former$ || formerJQuery) {
+            window.jQuery.noConflict(formerJQuery);
+        }
     }
-    if (typeof IriSP._ === "undefined" && typeof window._ !== "undefined") {
-        IriSP._ = window._;
+    if (typeof ns._ === "undefined" && typeof window._ !== "undefined") {
+        ns._ = window._;
+        if (formerUnderscore) {
+            _.noConflict();
+        }
     }
-    IriSP.loadCss(IriSP.getLib("cssjQueryUI"));
-    IriSP.loadCss(this.config.css);
+    ns.loadCss(ns.getLib("cssjQueryUI"));
+    ns.loadCss(this.config.css);
     
-    this.$ = IriSP.jQuery('#' + this.config.container);
+    this.$ = ns.jQuery('#' + this.config.container);
     this.$.css({
         "width": this.config.width,
         "clear": "both"
@@ -89,7 +109,7 @@
       
     this.widgets = [];
     var _this = this;
-    IriSP._(this.config.widgets).each(function(widgetconf, key) {
+    ns._(this.config.widgets).each(function(widgetconf, key) {
         _this.widgets.push(null);
         _this.loadWidget(widgetconf, function(widget) {
             _this.widgets[key] = widget;
@@ -106,7 +126,7 @@
         if (_this.widgetsLoaded) {
             return;
         }
-        var isloaded = !IriSP._(_this.widgets).any(function(w) {
+        var isloaded = !ns._(_this.widgets).any(function(w) {
             return !(w && w.isLoaded())
         });
         if (isloaded) {
@@ -116,12 +136,12 @@
     });   
 };
 
-IriSP.Metadataplayer.prototype.loadMetadata = function(_metadataInfo) {
+Metadataplayer.prototype.loadMetadata = function(_metadataInfo) {
     if (_metadataInfo.elementType === "source") {
         return _metadataInfo;
     }
     if (typeof _metadataInfo.serializer === "undefined" && typeof _metadataInfo.format !== "undefined") {
-        _metadataInfo.serializer = IriSP.serializers[_metadataInfo.format];
+        _metadataInfo.serializer = ns.serializers[_metadataInfo.format];
     }
     if (typeof _metadataInfo.url !== "undefined" && typeof _metadataInfo.serializer !== "undefined") {
         return this.sourceManager.remoteSource(_metadataInfo);
@@ -130,7 +150,7 @@
     }
 };
 
-IriSP.Metadataplayer.prototype.loadWidget = function(_widgetConfig, _callback) {
+Metadataplayer.prototype.loadWidget = function(_widgetConfig, _callback) {
     /* Creating containers if needed */
     if (typeof _widgetConfig.container === "undefined") {
         var _divs = this.layoutDivs(_widgetConfig.type);
@@ -139,18 +159,18 @@
     
     var _this = this;
     
-    if (typeof IriSP.Widgets[_widgetConfig.type] !== "undefined") {
-        IriSP._.defer(function() {
-            _callback(new IriSP.Widgets[_widgetConfig.type](_this, _widgetConfig));
+    if (typeof ns.Widgets[_widgetConfig.type] !== "undefined") {
+        ns._.defer(function() {
+            _callback(new ns.Widgets[_widgetConfig.type](_this, _widgetConfig));
         });
     } else {
         /* Loading Widget CSS */
-        if (typeof IriSP.widgetsRequirements[_widgetConfig.type] === "undefined" || typeof IriSP.widgetsRequirements[_widgetConfig.type].noCss === "undefined" || !IriSP.widgetsRequirements[_widgetConfig.type].noCss) {
-            IriSP.loadCss(IriSP.widgetsDir + '/' + _widgetConfig.type + '.css');
+        if (typeof ns.widgetsRequirements[_widgetConfig.type] === "undefined" || typeof ns.widgetsRequirements[_widgetConfig.type].noCss === "undefined" || !ns.widgetsRequirements[_widgetConfig.type].noCss) {
+            ns.loadCss(ns.widgetsDir + '/' + _widgetConfig.type + '.css');
         }
         /* Loading Widget JS    */
-        $LAB.script(IriSP.widgetsDir + '/' + _widgetConfig.type + '.js').wait(function() {
-            _callback(new IriSP.Widgets[_widgetConfig.type](_this, _widgetConfig));
+        $LAB.script(ns.widgetsDir + '/' + _widgetConfig.type + '.js').wait(function() {
+            _callback(new ns.Widgets[_widgetConfig.type](_this, _widgetConfig));
         });
     }
 };
@@ -159,20 +179,20 @@
     @param widgetName the name of the widget.
     @return an array of the form [createdivId, spacerdivId].
 */
-IriSP.Metadataplayer.prototype.layoutDivs = function(_name, _height) {
+Metadataplayer.prototype.layoutDivs = function(_name, _height) {
     if (typeof(_name) === "undefined") {
        _name = "";
     }
-    var newDiv = IriSP._.uniqueId(this.config.container + "_widget_" + _name + "_"),
-        spacerDiv = IriSP._.uniqueId("LdtPlayer_spacer_"),
-        divHtml = IriSP.jQuery('<div>')
+    var newDiv = ns._.uniqueId(this.config.container + "_widget_" + _name + "_"),
+        spacerDiv = ns._.uniqueId("LdtPlayer_spacer_"),
+        divHtml = ns.jQuery('<div>')
             .attr("id",newDiv)
             .css({
                 width: this.config.width + "px",
                 position: "relative",
                 clear: "both"
             }),
-        spacerHtml = IriSP.jQuery('<div>')
+        spacerHtml = ns.jQuery('<div>')
             .attr("id",spacerDiv)
             .css({
                 width: this.config.width + "px",
@@ -190,4 +210,6 @@
     return [newDiv, spacerDiv];
 };
 
+})(IriSP);
+
 /* End of widgets-container/metadataplayer.js */
\ No newline at end of file