src/js/widgets/tagCloudWidget.js
branchpopcorn-port
changeset 728 9ee6badcb160
parent 725 067002a5131d
child 736 eff5206f6877
equal deleted inserted replaced
727:70795f940a6c 728:9ee6badcb160
    46         .first(_tagCount)
    46         .first(_tagCount)
    47         .value();
    47         .value();
    48     var _max = _words[0].count,
    48     var _max = _words[0].count,
    49         _min = Math.min(_words[_words.length - 1].count, _max - 1),
    49         _min = Math.min(_words[_words.length - 1].count, _max - 1),
    50         _scale = 16 / Math.sqrt(_max - _min),
    50         _scale = 16 / Math.sqrt(_max - _min),
       
    51         _this = this,
    51         _html = '<ul>'
    52         _html = '<ul>'
    52             + IriSP._(_words)
    53             + IriSP._(_words)
    53                 .chain()
    54                 .chain()
    54                 .shuffle()
    55                 .shuffle()
    55                 .map(function(_word) {
    56                 .map(function(_word) {
    64                 .join("")
    65                 .join("")
    65             + '</ul>';
    66             + '</ul>';
    66     this.selector
    67     this.selector
    67         .addClass("Ldt-TagCloud")
    68         .addClass("Ldt-TagCloud")
    68         .html(_html);
    69         .html(_html);
    69     
    70     this.selector.find("li").click(function() {
       
    71         var _txt = this.textContent.replace(/(^[\s]+|[\s]+$)/g,'');
       
    72         _this._Popcorn.trigger("IriSP.search", _txt);
       
    73     });
       
    74     this._Popcorn.listen("IriSP.search", IriSP.wrap(this, function(searchString) {
       
    75         var _rgxp = new RegExp("(" + searchString.replace(/(\W)/g,'\\$1') + ")","gi");
       
    76         this.selector.find("li").each(function(_i, _e) {
       
    77             _e.innerHTML = searchString.length ?
       
    78                 _e.textContent.replace(_rgxp,'<span class="Ldt-TagCloud-actif">$1</span>')
       
    79                 : _e.textContent;
       
    80         });
       
    81     }));
       
    82     this._Popcorn.listen("IriSP.search.closed", IriSP.wrap(this, this.searchFieldClosedHandler));
       
    83     this._Popcorn.listen("IriSP.search.cleared", IriSP.wrap(this, this.searchFieldClearedHandler));
    70 }
    84 }
       
    85 
       
    86 IriSP.TagCloudWidget.prototype.endsearch = function() {
       
    87     this.selector.find("li").each(function(_i, _e) {
       
    88         _e.innerHTML = _e.textContent;
       
    89     });
       
    90 }