1 IriSP.Widgets.Tagcloud = function(player, config) { |
1 IriSP.Widgets.Tagcloud = function(player, config) { |
2 IriSP.Widgets.Widget.call(this, player, config); |
2 IriSP.Widgets.Widget.call(this, player, config); |
3 this.stopwords = IriSP._.uniq([].concat(this.custom_stopwords).concat(this.stopword_lists[this.stopword_language])); |
3 this.stopwords = IriSP._.uniq([].concat(this.custom_stopwords).concat(this.stopword_lists[this.stopword_language])); |
4 } |
4 }; |
5 |
5 |
6 IriSP.Widgets.Tagcloud.prototype = new IriSP.Widgets.Widget(); |
6 IriSP.Widgets.Tagcloud.prototype = new IriSP.Widgets.Widget(); |
7 |
7 |
8 IriSP.Widgets.Tagcloud.prototype.template = |
8 IriSP.Widgets.Tagcloud.prototype.template = |
9 '<div class="Ldt-Tagcloud-Container"><ul class="Ldt-Tagcloud-List">' |
9 '<div class="Ldt-Tagcloud-Container"><ul class="Ldt-Tagcloud-List">' |
20 exclude_pattern: false, |
20 exclude_pattern: false, |
21 annotation_type: false, |
21 annotation_type: false, |
22 segment_annotation_type: false, |
22 segment_annotation_type: false, |
23 min_font_size: 10, |
23 min_font_size: 10, |
24 max_font_size: 26 |
24 max_font_size: 26 |
25 } |
25 }; |
26 |
26 |
27 IriSP.Widgets.Tagcloud.prototype.stopword_lists = { |
27 IriSP.Widgets.Tagcloud.prototype.stopword_lists = { |
28 "fr" : [ |
28 "fr" : [ |
29 'aussi', 'avec', 'aux', 'bien', 'car', 'cette', 'comme', 'dans', 'des', 'donc', 'dont', 'elle', 'encore', 'entre', 'est', |
29 'aussi', 'avec', 'aux', 'bien', 'car', 'cette', 'comme', 'dans', 'des', 'donc', 'dont', 'elle', 'encore', 'entre', 'est', |
30 'être', 'eux', 'faire', 'fait', 'http', 'ici', 'ils', 'les', 'leur', 'leurs', 'mais', 'mes', 'même', 'mon', 'notre', |
30 'être', 'eux', 'faire', 'fait', 'http', 'ici', 'ils', 'les', 'leur', 'leurs', 'mais', 'mes', 'même', 'mon', 'notre', |
34 "en" : [ |
34 "en" : [ |
35 'about', 'again', 'are', 'and', 'because', 'being', 'but', 'can', 'done', 'have', 'for', 'from', |
35 'about', 'again', 'are', 'and', 'because', 'being', 'but', 'can', 'done', 'have', 'for', 'from', |
36 'get', 'here', 'http', 'like', 'more', 'one', 'our', 'she', 'that', 'the', 'their', 'then', 'there', |
36 'get', 'here', 'http', 'like', 'more', 'one', 'our', 'she', 'that', 'the', 'their', 'then', 'there', |
37 'they', 'this', 'very', 'what', 'when', 'where', 'who', 'why', 'will', 'with', 'www', 'you', 'your' |
37 'they', 'this', 'very', 'what', 'when', 'where', 'who', 'why', 'will', 'with', 'www', 'you', 'your' |
38 ] |
38 ] |
39 } |
39 }; |
40 |
40 |
41 IriSP.Widgets.Tagcloud.prototype.draw = function() { |
41 IriSP.Widgets.Tagcloud.prototype.draw = function() { |
42 |
42 |
43 if (this.segment_annotation_type) { |
43 if (this.segment_annotation_type) { |
44 var _this = this; |
44 var _this = this; |
45 this.source.getAnnotationsByTypeTitle(this.segment_annotation_type).forEach(function(_a) { |
45 this.source.getAnnotationsByTypeTitle(this.segment_annotation_type).forEach(function(_a) { |
46 _a.on("enter", function() { |
46 _a.on("enter", function() { |
47 _this.redraw(_a.begin, _a.end); |
47 _this.redraw(_a.begin, _a.end); |
48 }) |
48 }); |
49 }); |
49 }); |
50 } else { |
50 } else { |
51 this.redraw(); |
51 this.redraw(); |
52 } |
52 } |
53 } |
53 }; |
54 |
54 |
55 IriSP.Widgets.Tagcloud.prototype.redraw = function(_from, _to) { |
55 IriSP.Widgets.Tagcloud.prototype.redraw = function(_from, _to) { |
56 var _urlRegExp = /https?:\/\/[0-9a-zA-Z\.%\/-_]+/g, |
56 var _urlRegExp = /https?:\/\/[0-9a-zA-Z\.%\/-_]+/g, |
57 _regexpword = /[^\s\.&;,'"!\?\d\(\)\+\[\]\\\…\-«»:\/]{3,}/g, |
57 _regexpword = /[^\s\.&;,'"!\?\d\(\)\+\[\]\\\…\-«»:\/]{3,}/g, |
58 _words = {}, |
58 _words = {}, |
60 _annotations = this.getWidgetAnnotations(); |
60 _annotations = this.getWidgetAnnotations(); |
61 |
61 |
62 if (typeof _from !== "undefined" && typeof _to !== "undefined") { |
62 if (typeof _from !== "undefined" && typeof _to !== "undefined") { |
63 _annotations = _annotations.filter(function(_annotation) { |
63 _annotations = _annotations.filter(function(_annotation) { |
64 return _annotation.begin >= _from && _annotation.end <= _to; |
64 return _annotation.begin >= _from && _annotation.end <= _to; |
65 }) |
65 }); |
66 } |
66 } |
67 |
67 |
68 _annotations.forEach(function(_annotation) { |
68 _annotations.forEach(function(_annotation) { |
69 var _txt = |
69 var _txt = |
70 (_this.include_titles ? _annotation.title : '') |
70 (_this.include_titles ? _annotation.title : '') |
74 + (_this.include_tag_texts ? _annotation.getTagTexts() : ''); |
74 + (_this.include_tag_texts ? _annotation.getTagTexts() : ''); |
75 IriSP._(_txt.toLowerCase().replace(_urlRegExp, '').match(_regexpword)).each(function(_word) { |
75 IriSP._(_txt.toLowerCase().replace(_urlRegExp, '').match(_regexpword)).each(function(_word) { |
76 if (IriSP._(_this.stopwords).indexOf(_word) == -1 && (!_this.exclude_pattern || !_this.exclude_pattern.test(_word))) { |
76 if (IriSP._(_this.stopwords).indexOf(_word) == -1 && (!_this.exclude_pattern || !_this.exclude_pattern.test(_word))) { |
77 _words[_word] = 1 + (_words[_word] || 0); |
77 _words[_word] = 1 + (_words[_word] || 0); |
78 } |
78 } |
79 }) |
79 }); |
80 }); |
80 }); |
81 _words = IriSP._(_words) |
81 _words = IriSP._(_words) |
82 .chain() |
82 .chain() |
83 .map(function(_v, _k) { |
83 .map(function(_v, _k) { |
84 return { |
84 return { |
85 "word" : _k, |
85 "word" : _k, |
86 "count" : _v |
86 "count" : _v |
87 } |
87 }; |
88 }) |
88 }) |
89 .filter(function(_v) { |
89 .filter(function(_v) { |
90 return _v.count > 2; |
90 return _v.count > 2; |
91 }) |
91 }) |
92 .sortBy(function(_v) { |
92 .sortBy(function(_v) { |
107 var _txt = IriSP.jQuery(this).attr("content"); |
107 var _txt = IriSP.jQuery(this).attr("content"); |
108 _this.source.getAnnotations().search(_txt); |
108 _this.source.getAnnotations().search(_txt); |
109 }); |
109 }); |
110 this.source.getAnnotations().on("search", this.functionWrapper("onSearch")); |
110 this.source.getAnnotations().on("search", this.functionWrapper("onSearch")); |
111 this.source.getAnnotations().on("search-cleared", this.functionWrapper("onSearch")); |
111 this.source.getAnnotations().on("search-cleared", this.functionWrapper("onSearch")); |
112 } |
112 }; |
113 |
113 |
114 IriSP.Widgets.Tagcloud.prototype.onSearch = function(searchString) { |
114 IriSP.Widgets.Tagcloud.prototype.onSearch = function(searchString) { |
115 searchString = typeof searchString !== "undefined" ? searchString : ''; |
115 searchString = typeof searchString !== "undefined" ? searchString : ''; |
116 if (searchString) { |
116 if (searchString) { |
117 var _rgxp = IriSP.Model.regexpFromTextOrArray(searchString); |
117 var _rgxp = IriSP.Model.regexpFromTextOrArray(searchString); |