diff -r 919e362b9db1 -r 3ab36f402b0c src/widgets/Tagcloud.js --- a/src/widgets/Tagcloud.js Thu Aug 30 14:45:23 2012 +0200 +++ b/src/widgets/Tagcloud.js Thu Jan 02 16:40:25 2014 +0100 @@ -1,7 +1,7 @@ IriSP.Widgets.Tagcloud = function(player, config) { IriSP.Widgets.Widget.call(this, player, config); this.stopwords = IriSP._.uniq([].concat(this.custom_stopwords).concat(this.stopword_lists[this.stopword_language])); -} +}; IriSP.Widgets.Tagcloud.prototype = new IriSP.Widgets.Widget(); @@ -22,7 +22,7 @@ segment_annotation_type: false, min_font_size: 10, max_font_size: 26 -} +}; IriSP.Widgets.Tagcloud.prototype.stopword_lists = { "fr" : [ @@ -36,45 +36,33 @@ 'get', 'here', 'http', 'like', 'more', 'one', 'our', 'she', 'that', 'the', 'their', 'then', 'there', 'they', 'this', 'very', 'what', 'when', 'where', 'who', 'why', 'will', 'with', 'www', 'you', 'your' ] -} +}; IriSP.Widgets.Tagcloud.prototype.draw = function() { - this.bindPopcorn("IriSP.search", "onSearch"); - this.bindPopcorn("IriSP.search.closed", "onSearch"); - this.bindPopcorn("IriSP.search.cleared", "onSearch"); if (this.segment_annotation_type) { - this.bindPopcorn("timeupdate","onTimeupdate"); + var _this = this; + this.source.getAnnotationsByTypeTitle(this.segment_annotation_type).forEach(function(_a) { + _a.on("enter", function() { + _this.redraw(_a.begin, _a.end); + }); + }); } else { this.redraw(); } -} +}; -IriSP.Widgets.Tagcloud.prototype.onTimeupdate = function() { - var _time = Math.floor(this.player.popcorn.currentTime() * 1000), - _list = this.source.getAnnotationsByTypeTitle(this.segment_annotation_type).filter(function(_annotation) { - return _annotation.begin <= _time && _annotation.end > _time; - }); - if (_list.length) { - if (_list[0].begin !== this.begin_time || _list[0].end !== this.end_time) { - this.begin_time = _list[0].begin; - this.end_time = _list[0].end; - this.redraw(); - } - } -} - -IriSP.Widgets.Tagcloud.prototype.redraw = function() { +IriSP.Widgets.Tagcloud.prototype.redraw = function(_from, _to) { var _urlRegExp = /https?:\/\/[0-9a-zA-Z\.%\/-_]+/g, _regexpword = /[^\s\.&;,'"!\?\d\(\)\+\[\]\\\…\-«»:\/]{3,}/g, _words = {}, _this = this, _annotations = this.getWidgetAnnotations(); - if (typeof this.begin_time !== "undefined" && typeof this.end_time !== "undefined") { + if (typeof _from !== "undefined" && typeof _to !== "undefined") { _annotations = _annotations.filter(function(_annotation) { - return _annotation.begin >= _this.begin_time && _annotation.end <= _this.end_time; - }) + return _annotation.begin >= _from && _annotation.end <= _to; + }); } _annotations.forEach(function(_annotation) { @@ -88,7 +76,7 @@ if (IriSP._(_this.stopwords).indexOf(_word) == -1 && (!_this.exclude_pattern || !_this.exclude_pattern.test(_word))) { _words[_word] = 1 + (_words[_word] || 0); } - }) + }); }); _words = IriSP._(_words) .chain() @@ -96,7 +84,7 @@ return { "word" : _k, "count" : _v - } + }; }) .filter(function(_v) { return _v.count > 2; @@ -117,10 +105,11 @@ this.$.html(Mustache.to_html(this.template, {words: _words })); this.$.find(".Ldt-Tagcloud-item").click(function() { var _txt = IriSP.jQuery(this).attr("content"); - _this.player.popcorn.trigger("IriSP.search.triggeredSearch", _txt); + _this.source.getAnnotations().search(_txt); }); - -} + this.source.getAnnotations().on("search", this.functionWrapper("onSearch")); + this.source.getAnnotations().on("search-cleared", this.functionWrapper("onSearch")); +}; IriSP.Widgets.Tagcloud.prototype.onSearch = function(searchString) { searchString = typeof searchString !== "undefined" ? searchString : ''; @@ -136,4 +125,4 @@ _el.html(_txt); } }); -} +};