client/js/ldtjson-bin.js
changeset 196 2a2fcec209d0
parent 195 15e048e00002
child 211 d87f6bdee43d
--- a/client/js/ldtjson-bin.js	Wed Jul 03 13:42:59 2013 +0200
+++ b/client/js/ldtjson-bin.js	Thu Jul 04 12:43:30 2013 +0200
@@ -1,5 +1,7 @@
 (function(Rkns) {
-"use strict"
+"use strict";
+
+var _ = Rkns._;
 
 var Ldt = Rkns.Ldt = {};
 
@@ -15,12 +17,12 @@
 
 var ProjectBin = Ldt.ProjectBin = Rkns.Utils.inherit(Rkns._BaseBin);
 
-ProjectBin.prototype.tagTemplate = Rkns._.template(
+ProjectBin.prototype.tagTemplate = _.template(
     '<li class="Rk-Bin-Item" draggable="true" data-image="<%- Rkns.Utils.getFullURL(static_url+\'img/ldt-tag.png\') %>" data-uri="<%=ldt_platform%>ldtplatform/ldt/front/search/?search=<%=encodedtitle%>&field=all" data-title="<%-title%>" data-description="Tag \'<%-title%>\'">'
     + '<img class="Rk-Ldt-Tag-Icon" src="<%-static_url%>img/ldt-tag.png" /><h4><%=htitle%></h4><div class="Rk-Clear"></div></li>'
 );
 
-ProjectBin.prototype.annotationTemplate = Rkns._.template(
+ProjectBin.prototype.annotationTemplate = _.template(
     '<li class="Rk-Bin-Item" draggable="true" data-image="<%- Rkns.Utils.getFullURL(image) %>" data-uri="<%=ldt_platform%>ldtplatform/ldt/front/player/<%=mediaid%>/#id=<%=annotationid%>" data-title="<%-title%>" data-description="<%-description%>">'
     + '<img class="Rk-Ldt-Annotation-Icon" src="<%=image%>"/><h4><%=htitle%></h4><p><%=hdescription%></p><p>Start: <%=start%>, End: <%=end%>, Duration: <%=duration%></p><div class="Rk-Clear"></div></li>'
 );
@@ -34,14 +36,11 @@
     this.refresh();
 };
 
-ProjectBin.prototype.render = function(searchstr) {
-    if (searchstr) {
-        var rxbase = searchstr.replace(/(\W)/g,'\\$1'),
-            _rgxp = new RegExp('('+rxbase+')','gi'),
-            rxtest = new RegExp(rxbase,'i');
-    }
+ProjectBin.prototype.render = function(searchbase) {
+    var search = searchbase || Rkns.Utils.regexpFromTextOrArray();
     function highlight(_text) {
-        return searchstr ? _text.replace(_rgxp, "<span class='searchmatch'>$1</span>") : _text;
+        var _e = _(_text).escape();
+        return search.isempty ? _e : search.replace(_e, "<span class='searchmatch'>$1</span>");
     }
     function convertTC(_ms) {
         function pad(_n) {
@@ -68,9 +67,9 @@
         _this = this,
         count = 0;
     _this.title_$.text('LDT Project: "' + _projtitle + '"');
-    Rkns._(_this.data.tags).map(function(_tag) {
+    _(_this.data.tags).map(function(_tag) {
         var _title = _tag.meta["dc:title"];
-        if (searchstr && !rxtest.test(_title)) {
+        if (!search.isempty && !search.test(_title)) {
             return;
         }
         count++;
@@ -83,10 +82,10 @@
         });
     });
     _html += '<li><h3>Annotations</h3></li>';
-    Rkns._(_this.data.annotations).map(function(_annotation) {
+    _(_this.data.annotations).map(function(_annotation) {
         var _description = _annotation.content.description,
             _title = _annotation.content.title.replace(_description,"");
-        if (searchstr && !rxtest.test(_title) && !rxtest.test(_description)) {
+        if (!search.isempty && !search.test(_title) && !search.test(_description)) {
             return;
         }
         count++;
@@ -113,12 +112,12 @@
     });
     
     this.main_$.html(_html);
-    if (searchstr && count) {
+    if (!search.isempty && count) {
         this.count_$.text(count).show();
     } else {
         this.count_$.hide();
     }
-    if (searchstr && !count) {
+    if (!search.isempty && !count) {
         this.$.hide();
     } else {
         this.$.show();
@@ -161,7 +160,7 @@
 
 var ResultsBin = Ldt.ResultsBin = Rkns.Utils.inherit(Rkns._BaseBin);
 
-ResultsBin.prototype.segmentTemplate = Rkns._.template(
+ResultsBin.prototype.segmentTemplate = _.template(
     '<li class="Rk-Bin-Item" draggable="true" data-image="<%- Rkns.Utils.getFullURL(image) %>" data-uri="<%=ldt_platform%>ldtplatform/ldt/front/player/<%=mediaid%>/#id=<%=annotationid%>" data-title="<%-title%>" data-description="<%-description%>">'
     + '<img class="Rk-Ldt-Annotation-Icon" src="<%=image%>"/><h4><%=htitle%></h4><p><%=hdescription%></p><p>Start: <%=start%>, End: <%=end%>, Duration: <%=duration%></p><div class="Rk-Clear"></div></li>'
 );
@@ -176,17 +175,14 @@
     this.refresh();
 };
 
-ResultsBin.prototype.render = function(searchstr) {
-    if (searchstr) {
-        var rxbase = searchstr.replace(/(\W)/g,'\\$1'),
-            _rgxp = new RegExp('('+rxbase+')','gi'),
-            rxtest = new RegExp(rxbase,'i');
-    } else {
-        var rxbase = this.search.replace(/(\W)/g,'\\$1'),
-            _rgxp = new RegExp('('+rxbase+')','gi');
+ResultsBin.prototype.render = function(searchbase) {
+    if (!this.data) {
+        return;
     }
+    var search = searchbase || Rkns.Utils.regexpFromTextOrArray();
+    var highlightrx = (search.isempty ? Rkns.Utils.regexpFromTextOrArray(this.search) : search);
     function highlight(_text) {
-        return _text.replace(_rgxp, "<span class='searchmatch'>$1</span>");
+        return highlightrx.replace(_(_text).escape(), "<span class='searchmatch'>$1</span>");
     }
     function convertTC(_ms) {
         function pad(_n) {
@@ -211,10 +207,10 @@
     var _html = '',
         _this = this,
         count = 0;
-    Rkns._(_this.data.objects).each(function(_segment) {
+    _(this.data.objects).each(function(_segment) {
         var _description = _segment.abstract,
             _title = _segment.title;
-        if (searchstr && !rxtest.test(_title) && !rxtest.test(_description)) {
+        if (!search.isempty && !search.test(_title) && !search.test(_description)) {
             return;
         }
         count++;
@@ -244,12 +240,12 @@
     });
     
     this.main_$.html(_html);
-    if (searchstr && count) {
+    if (!search.isempty && count) {
         this.count_$.text(count).show();
     } else {
         this.count_$.hide();
     }
-    if (searchstr && !count) {
+    if (!search.isempty && !count) {
         this.$.hide();
     } else {
         this.$.show();