diff -r 15e048e00002 -r 2a2fcec209d0 client/js/ldtjson-bin.js --- 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( '
  • ' + '

    <%=htitle%>

  • ' ); -ProjectBin.prototype.annotationTemplate = Rkns._.template( +ProjectBin.prototype.annotationTemplate = _.template( '
  • ' + '

    <%=htitle%>

    <%=hdescription%>

    Start: <%=start%>, End: <%=end%>, Duration: <%=duration%>

  • ' ); @@ -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, "$1") : _text; + var _e = _(_text).escape(); + return search.isempty ? _e : search.replace(_e, "$1"); } 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 += '
  • Annotations

  • '; - 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( '
  • ' + '

    <%=htitle%>

    <%=hdescription%>

    Start: <%=start%>, End: <%=end%>, Duration: <%=duration%>

  • ' ); @@ -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, "$1"); + return highlightrx.replace(_(_text).escape(), "$1"); } 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();