src/ldt/ldt/static/ldt/metadataplayer/LdtPlayer-core.js
changeset 1121 d56201bf1446
parent 1034 967a0a591acd
child 1122 3bda04d364dd
--- a/src/ldt/ldt/static/ldt/metadataplayer/LdtPlayer-core.js	Wed Jan 16 05:34:21 2013 +0100
+++ b/src/ldt/ldt/static/ldt/metadataplayer/LdtPlayer-core.js	Fri Mar 01 18:05:02 2013 +0100
@@ -126,17 +126,17 @@
     });
     this.$.find('.Ldt-Loader').detach();
     
-    var endload = false;
+    this.widgetsLoaded = false;
     
     this.on("widget-loaded", function() {
-        if (endload) {
+        if (_this.widgetsLoaded) {
             return;
         }
         var isloaded = !IriSP._(_this.widgets).any(function(w) {
             return !(w && w.isLoaded())
         });
         if (isloaded) {
-            endload = true;
+            _this.widgetsLoaded = true;
             _this.trigger("widgets-loaded");
         }
     });   
@@ -246,6 +246,79 @@
     }
 }
 
+IriSP.textFieldHtml = function(_text, _regexp, _extend) {
+    var list = [],
+        positions = [],
+        text = _text.replace(/(^\s+|\s+$)/g,'');
+    
+    function addToList(_rx, _startHtml, _endHtml) {
+        while(true) {
+            var result = _rx.exec(text);
+            if (!result) {
+                break;
+            }
+            var end = _rx.lastIndex,
+                start = result.index;
+            list.push({
+                start: start,
+                end: end,
+                startHtml: (typeof _startHtml === "function" ? _startHtml(result) : _startHtml),
+                endHtml: (typeof _endHtml === "function" ? _endHtml(result) : _endHtml)
+            });
+            positions.push(start);
+            positions.push(end);
+        }
+    }
+    
+    if (_regexp) {
+        addToList(_regexp, '<span class="Ldt-Highlight">', '</span>');
+    }
+    
+    addToList(/(https?:\/\/)?\w+\.\w+\S+/gm, function(matches) {
+        return '<a href="' + (matches[1] ? '' : 'http://') + matches[0] + '" target="_blank">'
+    }, '</a>');
+    addToList(/@([\d\w]{1,15})/gm, function(matches) {
+        return '<a href="http://twitter.com/' + matches[1] + '" target="_blank">'
+    }, '</a>');
+    addToList(/\*[^*]+\*/gm, '<b>', '</b>');
+    addToList(/[\n\r]+/gm, '', '<br />');
+    
+    IriSP._(_extend).each(function(x) {
+        addToList.apply(null, x);
+    });
+    
+    positions = IriSP._(positions)
+        .chain()
+        .uniq()
+        .sortBy(function(p) { return parseInt(p) })
+        .value();
+    
+    var res = "", lastIndex = 0;
+    
+    for (var i = 0; i < positions.length; i++) {
+        var pos = positions[i];
+        res += text.substring(lastIndex, pos);
+        for (var j = list.length - 1; j >= 0; j--) {
+            var item = list[j];
+            if (item.start < pos && item.end >= pos) {
+                res += item.endHtml;
+            }
+        }
+        for (var j = 0; j < list.length; j++) {
+            var item = list[j];
+            if (item.start <= pos && item.end > pos) {
+                res += item.startHtml;
+            }
+        }
+        lastIndex = pos;
+    }
+    
+    res += text.substring(lastIndex);
+    
+    return res;
+    
+}
+
 IriSP.log = function() {
     if (typeof console !== "undefined" && typeof IriSP.logging !== "undefined" && IriSP.logging) {
         console.log.apply(console, arguments);
@@ -272,11 +345,12 @@
     var uidbase = rand16(8) + "-" + rand16(4) + "-", uidincrement = Math.floor(Math.random()*0x10000);
     
     var charsub = [
-        [ 'a', 'á', 'à', 'â', 'ä' ],
-        [ 'c', 'ç' ],
-        [ 'e', 'é', 'è', 'ê', 'ë' ],
-        [ 'i', 'í', 'ì', 'î', 'ï' ],
-        [ 'o', 'ó', 'ò', 'ô', 'ö' ]
+        '[aáàâä]',
+        '[cç]',
+        '[eéèêë]',
+        '[iíìîï]',
+        '[oóòôö]',
+        '[uùûü]'
     ];
     
     var removeChars = [
@@ -324,10 +398,7 @@
             remrx = new RegExp(remsrc,"gm"),
             txt = _text.toLowerCase().replace(remrx,"")
             res = [],
-            charsrc = ns._(charsub).map(function(c) {
-                return "(" + c.join("|") + ")";
-            }),
-            charsrx = ns._(charsrc).map(function(c) {
+            charsrx = ns._(charsub).map(function(c) {
                 return new RegExp(c);
             }),
             src = "";
@@ -336,7 +407,7 @@
                 src += remsrc + "*";
             }
             var l = txt[j];
-            ns._(charsrc).each(function(v, k) {
+            ns._(charsub).each(function(v, k) {
                 l = l.replace(charsrx[k], v);
             });
             src += l;
@@ -476,7 +547,7 @@
  */
 Model.List.prototype.searchByTitle = function(_text, _iexact) {
     var _iexact = _iexact || false,
-        _rgxp = Model.regexpFromTextOrArray(_text, true);
+        _rgxp = Model.regexpFromTextOrArray(_text, true, _iexact);
     return this.filter(function(_element) {
         return _rgxp.test(_element.title);
     });
@@ -484,7 +555,7 @@
 
 Model.List.prototype.searchByDescription = function(_text, _iexact) {
     var _iexact = _iexact || false,
-        _rgxp = Model.regexpFromTextOrArray(_text, true);
+        _rgxp = Model.regexpFromTextOrArray(_text, true, _iexact);
     return this.filter(function(_element) {
         return _rgxp.test(_element.description);
     });
@@ -492,7 +563,7 @@
 
 Model.List.prototype.searchByTextFields = function(_text, _iexact) {
     var _iexact = _iexact || false,
-        _rgxp =  Model.regexpFromTextOrArray(_text, true);
+        _rgxp =  Model.regexpFromTextOrArray(_text, true, _iexact);
     return this.filter(function(_element) {
         var keywords = (_element.keywords || _element.getTagTexts() || []).join(", ");
         return _rgxp.test(_element.description) || _rgxp.test(_element.title) || _rgxp.test(keywords);
@@ -801,6 +872,7 @@
     this.volume = .5;
     this.paused = true;
     this.muted = false;
+    this.loadedMetadata = false;
     var _this = this;
     this.on("play", function() {
         _this.paused = false;
@@ -825,6 +897,9 @@
             _this.trigger("enter-annotation",_a);
         });
     });
+    this.on("loadedmetadata", function() {
+        _this.loadedMetadata = true;
+    })
 }
 
 Model.Playable.prototype = new Model.Element();
@@ -1068,17 +1143,6 @@
 
 Model.Mashup.prototype = new Model.Playable();
 
-Model.Mashup.prototype.checkLoaded = function() {
-    var loaded = !!this.segments.length;
-    this.getMedias().forEach(function(_m) {
-        loaded = loaded && _m.loaded;
-    });
-    this.loaded = loaded;
-    if (loaded) {
-        this.trigger("loadedmetadata");
-    }
-}
-
 Model.Mashup.prototype.updateTimes = function() {
     var _time = 0;
     this.segments.forEach(function(_segment) {
@@ -1446,6 +1510,9 @@
 return Model;
 
 })(IriSP);
+
+/* END model.js */
+
 IriSP.language = 'en';
 
 IriSP.libFiles = {
@@ -1591,8 +1658,16 @@
        _this[_key] = _value;
     });
     
+    this.$ = IriSP.jQuery('#' + this.container);
+    
     if (typeof this.width === "undefined") {
-        this.width = player.config.width;
+        this.width = this.$.width();
+    } else {
+        this.$.css("width", this.width);
+    }
+    
+    if (typeof this.height !== "undefined") {
+        this.$.css("height", this.height);
     }
     
     /* Setting this.player at the end in case it's been overriden
@@ -1601,7 +1676,6 @@
     this.player = player;
     
     /* Adding classes and html attributes */
-    this.$ = IriSP.jQuery('#' + this.container);
     this.$.addClass("Ldt-TraceMe Ldt-Widget").attr("widget-type", _type);
     
     this.l10n = (