| author | veltr |
| Wed, 29 Aug 2012 18:34:11 +0200 | |
| branch | new-model |
| changeset 937 | eb3c442cec50 |
| parent 908 | f56199193fad |
| child 957 | 4da0a5740b6c |
| child 1019 | 3ab36f402b0c |
| permissions | -rw-r--r-- |
| 880 | 1 |
IriSP.Widgets.Tagcloud = function(player, config) { |
2 |
IriSP.Widgets.Widget.call(this, player, config); |
|
| 882 | 3 |
this.stopwords = IriSP._.uniq([].concat(this.custom_stopwords).concat(this.stopword_lists[this.stopword_language])); |
| 880 | 4 |
} |
5 |
||
6 |
IriSP.Widgets.Tagcloud.prototype = new IriSP.Widgets.Widget(); |
|
7 |
||
8 |
IriSP.Widgets.Tagcloud.prototype.template = |
|
9 |
'<div class="Ldt-Tagcloud-Container"><ul class="Ldt-Tagcloud-List">' |
|
| 906 | 10 |
+ '{{#words}}<li class="Ldt-Tagcloud-item Ldt-TraceMe" trace-info="tag:{{word}}" content="{{word}}" style="font-size: {{size}}px">{{word}}</li>{{/words}}' |
| 880 | 11 |
+ '</ul></div>'; |
12 |
||
13 |
IriSP.Widgets.Tagcloud.prototype.defaults = { |
|
14 |
include_titles: true, |
|
15 |
include_descriptions: true, |
|
|
908
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
906
diff
changeset
|
16 |
include_tag_texts: true, |
| 880 | 17 |
tag_count: 30, |
18 |
stopword_language: "fr", |
|
19 |
custom_stopwords: [], |
|
20 |
exclude_pattern: false, |
|
21 |
annotation_type: false, |
|
|
908
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
906
diff
changeset
|
22 |
segment_annotation_type: false, |
| 880 | 23 |
min_font_size: 10, |
24 |
max_font_size: 26 |
|
25 |
} |
|
26 |
||
27 |
IriSP.Widgets.Tagcloud.prototype.stopword_lists = { |
|
28 |
"fr" : [ |
|
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', |
|
31 |
'non', 'nos', 'nous', 'ont', 'par', 'pas', 'peu', 'peut', 'plus', 'pour', 'quand', 'que', 'qui', 'quoi', 'sans', |
|
32 |
'ses' ,'son', 'sont', 'sur', 'tes', 'très', 'the', 'ton', 'tous', 'tout', 'une', 'votre', 'vos', 'vous' |
|
33 |
], |
|
34 |
"en" : [ |
|
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', |
|
37 |
'they', 'this', 'very', 'what', 'when', 'where', 'who', 'why', 'will', 'with', 'www', 'you', 'your' |
|
38 |
] |
|
39 |
} |
|
40 |
||
41 |
IriSP.Widgets.Tagcloud.prototype.draw = function() { |
|
|
908
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
906
diff
changeset
|
42 |
this.bindPopcorn("IriSP.search", "onSearch"); |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
906
diff
changeset
|
43 |
this.bindPopcorn("IriSP.search.closed", "onSearch"); |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
906
diff
changeset
|
44 |
this.bindPopcorn("IriSP.search.cleared", "onSearch"); |
| 880 | 45 |
|
|
908
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
906
diff
changeset
|
46 |
if (this.segment_annotation_type) { |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
906
diff
changeset
|
47 |
this.bindPopcorn("timeupdate","onTimeupdate"); |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
906
diff
changeset
|
48 |
} else { |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
906
diff
changeset
|
49 |
this.redraw(); |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
906
diff
changeset
|
50 |
} |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
906
diff
changeset
|
51 |
} |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
906
diff
changeset
|
52 |
|
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
906
diff
changeset
|
53 |
IriSP.Widgets.Tagcloud.prototype.onTimeupdate = function() { |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
906
diff
changeset
|
54 |
var _time = Math.floor(this.player.popcorn.currentTime() * 1000), |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
906
diff
changeset
|
55 |
_list = this.source.getAnnotationsByTypeTitle(this.segment_annotation_type).filter(function(_annotation) { |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
906
diff
changeset
|
56 |
return _annotation.begin <= _time && _annotation.end > _time; |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
906
diff
changeset
|
57 |
}); |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
906
diff
changeset
|
58 |
if (_list.length) { |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
906
diff
changeset
|
59 |
if (_list[0].begin !== this.begin_time || _list[0].end !== this.end_time) { |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
906
diff
changeset
|
60 |
this.begin_time = _list[0].begin; |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
906
diff
changeset
|
61 |
this.end_time = _list[0].end; |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
906
diff
changeset
|
62 |
this.redraw(); |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
906
diff
changeset
|
63 |
} |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
906
diff
changeset
|
64 |
} |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
906
diff
changeset
|
65 |
} |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
906
diff
changeset
|
66 |
|
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
906
diff
changeset
|
67 |
IriSP.Widgets.Tagcloud.prototype.redraw = function() { |
| 880 | 68 |
var _urlRegExp = /https?:\/\/[0-9a-zA-Z\.%\/-_]+/g, |
69 |
_regexpword = /[^\s\.&;,'"!\?\d\(\)\+\[\]\\\…\-«»:\/]{3,}/g, |
|
70 |
_words = {}, |
|
|
908
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
906
diff
changeset
|
71 |
_this = this, |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
906
diff
changeset
|
72 |
_annotations = this.getWidgetAnnotations(); |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
906
diff
changeset
|
73 |
|
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
906
diff
changeset
|
74 |
if (typeof this.begin_time !== "undefined" && typeof this.end_time !== "undefined") { |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
906
diff
changeset
|
75 |
_annotations = _annotations.filter(function(_annotation) { |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
906
diff
changeset
|
76 |
return _annotation.begin >= _this.begin_time && _annotation.end <= _this.end_time; |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
906
diff
changeset
|
77 |
}) |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
906
diff
changeset
|
78 |
} |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
906
diff
changeset
|
79 |
|
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
906
diff
changeset
|
80 |
_annotations.forEach(function(_annotation) { |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
906
diff
changeset
|
81 |
var _txt = |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
906
diff
changeset
|
82 |
(_this.include_titles ? _annotation.title : '') |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
906
diff
changeset
|
83 |
+ ' ' |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
906
diff
changeset
|
84 |
+ (_this.include_descriptions ? _annotation.description : '') |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
906
diff
changeset
|
85 |
+ ' ' |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
906
diff
changeset
|
86 |
+ (_this.include_tag_texts ? _annotation.getTagTexts() : ''); |
| 880 | 87 |
IriSP._(_txt.toLowerCase().replace(_urlRegExp, '').match(_regexpword)).each(function(_word) { |
88 |
if (IriSP._(_this.stopwords).indexOf(_word) == -1 && (!_this.exclude_pattern || !_this.exclude_pattern.test(_word))) { |
|
89 |
_words[_word] = 1 + (_words[_word] || 0); |
|
90 |
} |
|
91 |
}) |
|
92 |
}); |
|
93 |
_words = IriSP._(_words) |
|
94 |
.chain() |
|
95 |
.map(function(_v, _k) { |
|
96 |
return { |
|
97 |
"word" : _k, |
|
98 |
"count" : _v |
|
99 |
} |
|
100 |
}) |
|
101 |
.filter(function(_v) { |
|
102 |
return _v.count > 2; |
|
103 |
}) |
|
104 |
.sortBy(function(_v) { |
|
105 |
return - _v.count; |
|
106 |
}) |
|
107 |
.first(this.tag_count) |
|
108 |
.value(); |
|
|
908
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
906
diff
changeset
|
109 |
if (_words.length) { |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
906
diff
changeset
|
110 |
var _max = _words[0].count, |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
906
diff
changeset
|
111 |
_min = Math.min(_words[_words.length - 1].count, _max - 1), |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
906
diff
changeset
|
112 |
_scale = (this.max_font_size - this.min_font_size) / Math.sqrt(_max - _min); |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
906
diff
changeset
|
113 |
IriSP._(_words).each(function(_word) { |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
906
diff
changeset
|
114 |
_word.size = Math.floor( _this.min_font_size + _scale * Math.sqrt(_word.count - _min) ); |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
906
diff
changeset
|
115 |
}); |
| 883 | 116 |
} |
|
908
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
906
diff
changeset
|
117 |
this.$.html(Mustache.to_html(this.template, {words: _words })); |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
906
diff
changeset
|
118 |
this.$.find(".Ldt-Tagcloud-item").click(function() { |
| 880 | 119 |
var _txt = IriSP.jQuery(this).attr("content"); |
120 |
_this.player.popcorn.trigger("IriSP.search.triggeredSearch", _txt); |
|
121 |
}); |
|
|
908
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
906
diff
changeset
|
122 |
|
| 880 | 123 |
} |
124 |
||
125 |
IriSP.Widgets.Tagcloud.prototype.onSearch = function(searchString) { |
|
126 |
searchString = typeof searchString !== "undefined" ? searchString : ''; |
|
127 |
if (searchString) { |
|
128 |
var _rgxp = IriSP.Model.regexpFromTextOrArray(searchString); |
|
129 |
} |
|
|
908
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
906
diff
changeset
|
130 |
this.$.find(".Ldt-Tagcloud-item").each(function() { |
| 880 | 131 |
var _el = IriSP.jQuery(this), |
132 |
_txt = _el.attr("content"); |
|
133 |
if (searchString) { |
|
134 |
_el.html(_txt.replace(_rgxp, '<span class="Ldt-Tagcloud-active">$1</span>')); |
|
135 |
} else { |
|
136 |
_el.html(_txt); |
|
137 |
} |
|
138 |
}); |
|
139 |
} |