11 "wait_while_processed": "Please wait while your request is being processed...", |
11 "wait_while_processed": "Please wait while your request is being processed...", |
12 "error_while_contacting": "An error happened while contacting the server. Your annotation has not been saved.", |
12 "error_while_contacting": "An error happened while contacting the server. Your annotation has not been saved.", |
13 "empty_annotation": "Your annotation is empty. Please write something before submitting.", |
13 "empty_annotation": "Your annotation is empty. Please write something before submitting.", |
14 "annotation_saved": "Thank you, your annotation has been saved.", |
14 "annotation_saved": "Thank you, your annotation has been saved.", |
15 "share_annotation": "Would you like to share it on social networks ?", |
15 "share_annotation": "Would you like to share it on social networks ?", |
16 "share_on": "Share on" |
16 "share_on": "Share on", |
|
17 "moar_tags": "More tags" |
17 }, |
18 }, |
18 "fr": { |
19 "fr": { |
19 "submit": "Envoyer", |
20 "submit": "Envoyer", |
20 "add_keywords": "Ajouter des mots-clés", |
21 "add_keywords": "Ajouter des mots-clés", |
21 "add_polemic_keywords": "Ajouter des mots-clés polémiques", |
22 "add_polemic_keywords": "Ajouter des mots-clés polémiques", |
24 "wait_while_processed": "Veuillez patienter pendant le traitement de votre requête...", |
25 "wait_while_processed": "Veuillez patienter pendant le traitement de votre requête...", |
25 "error_while_contacting": "Une erreur s'est produite en contactant le serveur. Votre annotation n'a pas été enregistrée", |
26 "error_while_contacting": "Une erreur s'est produite en contactant le serveur. Votre annotation n'a pas été enregistrée", |
26 "empty_annotation": "Votre annotation est vide. Merci de rédiger un texte avant de l'envoyer.", |
27 "empty_annotation": "Votre annotation est vide. Merci de rédiger un texte avant de l'envoyer.", |
27 "annotation_saved": "Merci, votre annotation a été enregistrée.", |
28 "annotation_saved": "Merci, votre annotation a été enregistrée.", |
28 "share_annotation": "Souhaitez-vous la partager sur les réseaux sociaux ?", |
29 "share_annotation": "Souhaitez-vous la partager sur les réseaux sociaux ?", |
29 "share_on": "Partager sur" |
30 "share_on": "Partager sur", |
|
31 "moar_tagz": "Plus de mots-clés" |
30 } |
32 } |
31 } |
33 } |
32 ); |
34 ); |
33 |
35 |
34 IriSP.createAnnotationWidget = function(Popcorn, config, Serializer) { |
36 IriSP.createAnnotationWidget = function(Popcorn, config, Serializer) { |
40 this.checkOption("polemics"); |
42 this.checkOption("polemics"); |
41 this.checkOption("cinecast_version", false); |
43 this.checkOption("cinecast_version", false); |
42 this.checkOption("api_endpoint_template"); |
44 this.checkOption("api_endpoint_template"); |
43 this.checkOption("show_from_field", true); |
45 this.checkOption("show_from_field", true); |
44 this.checkOption("api_method"); |
46 this.checkOption("api_method"); |
|
47 this.checkOption("random_keywords"); |
|
48 this.checkOption("disable_share", false); |
45 |
49 |
46 if (!IriSP.null_or_undefined(IriSP.user)) { |
50 if (!IriSP.null_or_undefined(IriSP.user)) { |
47 if (!IriSP.null_or_undefined(IriSP.user.avatar)) { |
51 if (!IriSP.null_or_undefined(IriSP.user.avatar)) { |
48 this.user_avatar = IriSP.user.avatar; |
52 this.user_avatar = IriSP.user.avatar; |
49 } |
53 } |
67 this.selector.find(".Ldt-SaDescription").text(""); |
71 this.selector.find(".Ldt-SaDescription").text(""); |
68 this.selector.find(".Ldt-SaKeywordText").text(""); |
72 this.selector.find(".Ldt-SaKeywordText").text(""); |
69 }; |
73 }; |
70 |
74 |
71 IriSP.createAnnotationWidget.prototype.draw = function() { |
75 IriSP.createAnnotationWidget.prototype.draw = function() { |
|
76 var _this = this; |
|
77 if (typeof this._config.remote_keywords != "undefined" && typeof this._config.remote_keywords) { |
|
78 IriSP.jQuery.getJSON(this._config.remote_keywords, function(_json) { |
|
79 _this.keywords = IriSP.underscore(_json.tags).map(function(_tag) { |
|
80 return _tag.meta.description; |
|
81 }); |
|
82 _this.drawCallback(); |
|
83 }); |
|
84 } else { |
|
85 this.drawCallback(); |
|
86 } |
|
87 } |
|
88 |
|
89 IriSP.createAnnotationWidget.prototype.drawCallback = function() { |
72 var _this = this; |
90 var _this = this; |
73 |
91 |
74 var annotationMarkup = IriSP.templToHTML(IriSP.createAnnotationWidget_template, |
92 var annotationMarkup = IriSP.templToHTML(IriSP.createAnnotationWidget_template, |
75 this); |
93 this); |
76 |
94 |
79 if (!this.cinecast_version) |
97 if (!this.cinecast_version) |
80 this.selector.hide(); |
98 this.selector.hide(); |
81 else { |
99 else { |
82 this.showStartScreen(); |
100 this.showStartScreen(); |
83 } |
101 } |
84 |
102 |
|
103 if (this.random_keywords) { |
|
104 this.selector.find(".Ldt-createAnnotation-keywords li").hide(); |
|
105 this.showMoarTagz(); |
|
106 this.selector.find('.Ldt-createAnnotation-moar-keywordz').click(function() { |
|
107 _this.showMoarTagz(); |
|
108 }) |
|
109 } |
85 // Add onclick event to both polemic and keywords buttons |
110 // Add onclick event to both polemic and keywords buttons |
86 |
111 |
87 this.selector.find(".Ldt-createAnnotation-btnblock button").click(function() { |
112 this.selector.find(".Ldt-createAnnotation-keyword-button, .Ldt-createAnnotation-polemic-button").click(function() { |
88 _this.addKeyword(IriSP.jQuery(this).text()); |
113 _this.addKeyword(IriSP.jQuery(this).text()); |
|
114 return false; |
89 }); |
115 }); |
90 |
116 |
91 // js_mod is a custom event because there's no simple way to test for a js |
117 // js_mod is a custom event because there's no simple way to test for a js |
92 // change in a textfield. |
118 // change in a textfield. |
93 this.selector.find(".Ldt-createAnnotation-Description") |
119 this.selector.find(".Ldt-createAnnotation-Description") |
94 .bind("propertychange keyup input paste js_mod", IriSP.wrap(this, this.handleTextChanges)); |
120 .bind("propertychange keyup input paste click js_mod", IriSP.wrap(this, this.handleTextChanges)); |
95 |
121 |
96 /* the cinecast version of the player is supposed to pause when the user clicks on the button */ |
122 /* the cinecast version of the player is supposed to pause when the user clicks on the button */ |
97 |
123 |
98 /* the cinecast version expects the user to comment on a defined segment. |
124 /* the cinecast version expects the user to comment on a defined segment. |
99 As the widget is always shown, we need a way to update it's content as |
125 As the widget is always shown, we need a way to update it's content as |
150 } |
176 } |
151 )); |
177 )); |
152 } |
178 } |
153 }; |
179 }; |
154 |
180 |
|
181 IriSP.createAnnotationWidget.prototype.showMoarTagz = function() { |
|
182 for (var j=0; j < this.random_keywords; j++) { |
|
183 var _jq = this.selector.find(".Ldt-createAnnotation-keywords li:hidden"); |
|
184 if (_jq.length > 1) { |
|
185 IriSP.jQuery(_jq[Math.floor(_jq.length*Math.random())]).show(); |
|
186 } else { |
|
187 _jq.show(); |
|
188 break; |
|
189 } |
|
190 } |
|
191 if (this.selector.find(".Ldt-createAnnotation-keywords li:hidden").length == 0) { |
|
192 this.selector.find('.Ldt-createAnnotation-moar-keywordz').hide(); |
|
193 } |
|
194 } |
|
195 |
155 /* Handles adding keywords and polemics */ |
196 /* Handles adding keywords and polemics */ |
156 IriSP.createAnnotationWidget.prototype.addKeyword = function(_keyword) { |
197 IriSP.createAnnotationWidget.prototype.addKeyword = function(_keyword) { |
157 var _field = this.selector.find(".Ldt-createAnnotation-Description"), |
198 var _field = this.selector.find(".Ldt-createAnnotation-Description"), |
158 _rx = IriSP.regexpFromText(_keyword), |
199 _rx = IriSP.regexpFromText(_keyword), |
159 _contents = _field.val(); |
200 _contents = _field.val(); |
160 _contents = ( _rx.test(_contents) |
201 _contents = ( _rx.test(_contents) |
161 ? _contents.replace(_rx,"").replace(" "," ").trim() |
202 ? _contents.replace(_rx,"").replace(" "," ").trim() |
162 : _contents.trim() + " " + _keyword |
203 : _contents.trim() + " " + _keyword |
163 ); |
204 ); |
164 _field.val(_contents); |
205 _field.val(_contents.trim()); |
165 _field.trigger("js_mod"); |
206 _field.trigger("js_mod"); |
166 } |
207 } |
167 |
208 |
168 /** handles clicks on the annotate button. Works only for the non-cinecast version */ |
209 /** handles clicks on the annotate button. Works only for the non-cinecast version */ |
169 IriSP.createAnnotationWidget.prototype.handleAnnotateSignal = function() { |
210 IriSP.createAnnotationWidget.prototype.handleAnnotateSignal = function() { |
221 |
262 |
222 |
263 |
223 /** watch for changes in the textfield and change the buttons accordingly */ |
264 /** watch for changes in the textfield and change the buttons accordingly */ |
224 IriSP.createAnnotationWidget.prototype.handleTextChanges = function(event) { |
265 IriSP.createAnnotationWidget.prototype.handleTextChanges = function(event) { |
225 var contents = this.selector.find(".Ldt-createAnnotation-Description").val(); |
266 var contents = this.selector.find(".Ldt-createAnnotation-Description").val(); |
226 if (this.cinecast_version && !this._Popcorn.media.paused) { |
267 if (this.cinecast_version) { |
227 this._Popcorn.pause(); |
268 this._Popcorn.pause(); |
228 } |
269 } |
229 this.selector.find(".Ldt-createAnnotation-btnblock button").each(function() { |
270 this.selector.find(".Ldt-createAnnotation-btnblock button").each(function() { |
230 var _rx = IriSP.regexpFromText(IriSP.jQuery(this).text()); |
271 var _rx = IriSP.regexpFromText(IriSP.jQuery(this).text()); |
231 if (_rx.test(contents)) { |
272 if (_rx.test(contents)) { |
396 ); |
437 ); |
397 |
438 |
398 meta.created = Date().toString(); |
439 meta.created = Date().toString(); |
399 |
440 |
400 // All #hashtags are added to tags |
441 // All #hashtags are added to tags |
401 annotation.tags = contents.match(/#[^#\s]+\b/gim) || []; |
442 var _tags = contents.toLowerCase().match(/#[^#\s]+\b/gim) || []; |
|
443 this.selector.find('.Ldt-createAnnotation-keyword-button').each(function() { |
|
444 var _tx = IriSP.jQuery(this).text(), |
|
445 _rx = IriSP.regexpFromText(_tx); |
|
446 if (_rx.test(contents)) { |
|
447 _tags.push(_tx.toLowerCase()) |
|
448 } |
|
449 }); |
|
450 |
|
451 annotation.tags = IriSP.underscore.uniq(_tags); |
|
452 |
402 |
453 |
403 var jsonString = JSON.stringify(apiJson); |
454 var jsonString = JSON.stringify(apiJson); |
404 var project_id = this._serializer._data.meta.id; |
455 var project_id = this._serializer._data.meta.id; |
405 |
456 |
406 //TODO: extract magic url |
457 //TODO: extract magic url |
434 delete annotation.content.data; |
485 delete annotation.content.data; |
435 annotation.id = json.annotations[0].id; |
486 annotation.id = json.annotations[0].id; |
436 |
487 |
437 annotation.meta = meta; |
488 annotation.meta = meta; |
438 annotation.meta["id-ref"] = json.annotations[0]["type"]; |
489 annotation.meta["id-ref"] = json.annotations[0]["type"]; |
|
490 } else { |
|
491 annotation.type = "cinecast:UserAnnotation"; |
439 } |
492 } |
440 |
493 annotation.is_new = true; |
441 // everything is shared so there's no need to propagate the change |
494 // everything is shared so there's no need to propagate the change |
442 _this._serializer._data.annotations.push(annotation); |
495 _this._serializer._data.annotations.push(annotation); |
443 |
496 |
444 _this._Popcorn.trigger("IriSP.createAnnotationWidget.addedAnnotation", annotation); |
497 _this._Popcorn.trigger("IriSP.createAnnotationWidget.addedAnnotation", annotation); |
445 callback(annotation); |
498 callback(annotation); |