# HG changeset patch # User veltr # Date 1331228326 -3600 # Node ID 18ca612e9ff0ebc472c902242b4f06710d86613f # Parent ae16691d183d3dd438f210e1a2b2021f55c21767 Lots of changes diff -r ae16691d183d -r 18ca612e9ff0 src/js/header.js --- a/src/js/header.js Tue Mar 06 13:26:51 2012 +0100 +++ b/src/js/header.js Thu Mar 08 18:38:46 2012 +0100 @@ -1,7 +1,7 @@ /* * * Copyright 2010-2012 Institut de recherche et d'innovation - * contributor(s) : Karim Hamidou, Samuel Huron + * contributor(s) : Karim Hamidou, Samuel Huron, Raphael Velt, Thibaut Cavalie * * contact@iri.centrepompidou.fr * http://www.iri.centrepompidou.fr diff -r ae16691d183d -r 18ca612e9ff0 src/js/site.js.templ --- a/src/js/site.js.templ Tue Mar 06 13:26:51 2012 +0100 +++ b/src/js/site.js.templ Thu Mar 08 18:38:46 2012 +0100 @@ -82,13 +82,14 @@ Ldt-createAnnotation-polemic-plusplus for plusplus Ldt-createAnnotation-polemic-equalequal for equalequal, etc. */ - polemics: {"++" : "positive", "--" : "negative", "==" : "reference", "??" : "question"}, + polemics: [ { "className" : "positive", "keyword" : "++" }, { "className" : "negative", "keyword" : "--" }, { "className" : "reference", "keyword" : "==" }, { "className" : "question", "keyword" : "??" } ], cinecast_version: true, /* put to false to enable the platform version, true for the festival cinecast one. */ /* where does the widget PUT the annotations - this is a mustache template. id refers to the id of the media ans is filled by the widget. */ - api_endpoint_template: platform_url + "/ldtplatform/api/ldt/annotations/{{id}}.json" + api_endpoint_template: platform_url + "/ldtplatform/api/ldt/annotations/{{id}}.json", + api_method: "PUT" }, "SparklineWidget" : { column_width: 10 // the width of a column in pixels. diff -r ae16691d183d -r 18ca612e9ff0 src/js/utils.js --- a/src/js/utils.js Tue Mar 06 13:26:51 2012 +0100 +++ b/src/js/utils.js Thu Mar 08 18:38:46 2012 +0100 @@ -192,3 +192,8 @@ } } */ + +/* Creates regexps from text */ +IriSP.regexpFromText = function(_text) { + return new RegExp('(' + _text.replace(/(\W)/gim,'\\$1') + ')','gim'); +} diff -r ae16691d183d -r 18ca612e9ff0 src/js/widgets.js --- a/src/js/widgets.js Tue Mar 06 13:26:51 2012 +0100 +++ b/src/js/widgets.js Thu Mar 08 18:38:46 2012 +0100 @@ -50,29 +50,32 @@ } if (config.hasOwnProperty("layoutManager")) { - this.layoutManager = config.layoutManager; + this.layoutManager = config.layoutManager; } - if (typeof this.selector != "undefined" && typeof Popcorn != "undefined") { - var _id = this._id; - this.selector.bind("click mouseover mouseout dragstart dragstop", function(_e) { - var _data = { - "type": _e.type, - "x": _e.clientX, - "y": _e.clientY, - "widget": _id, - "target_name": _e.target.localName, - "target_id": _e.target.id, - "target_class": _e.target.className, - "text": _e.target.textContent.trim(), - "title": _e.target.title, - "value": _e.target.value - }; - Popcorn.trigger('IriSP.Widget.MouseEvents', _data); - }) + if (typeof this.selector != "undefined") { + this.selector.addClass("Ldt-TraceMe").addClass("Ldt-Widget"); } }; +// This functions checks for configuration options + +IriSP.Widget.prototype.checkOption = function(_name, _default) { + this[_name] = ( + typeof this._config[_name] != "undefined" + ? this._config[_name] + : ( + (typeof IriSP.widgetsDefaults[this._config.type] != "undefined" && IriSP.widgetsDefaults[this._config.type][_name] != "undefined") + ? IriSP.widgetsDefaults[this._config.type][_name] + : ( + typeof _default != "undefined" + ? _default + : null + ) + ) + ) +} + /** * This method responsible of drawing a widget on screen. */ diff -r ae16691d183d -r 18ca612e9ff0 src/js/widgets/createAnnotationWidget.js --- a/src/js/widgets/createAnnotationWidget.js Tue Mar 06 13:26:51 2012 +0100 +++ b/src/js/widgets/createAnnotationWidget.js Thu Mar 08 18:38:46 2012 +0100 @@ -1,15 +1,23 @@ IriSP.createAnnotationWidget = function(Popcorn, config, Serializer) { IriSP.Widget.call(this, Popcorn, config, Serializer); this._hidden = true; - this.keywords = IriSP.widgetsDefaults["createAnnotationWidget"].keywords; - this.polemic_mode = IriSP.widgetsDefaults["createAnnotationWidget"].polemic_mode; - this.polemics = IriSP.widgetsDefaults["createAnnotationWidget"].polemics; - - this.cinecast_version = IriSP.widgetsDefaults["createAnnotationWidget"].cinecast_version; - this.api_endpoint_template = IriSP.widgetsDefaults["createAnnotationWidget"].api_endpoint_template; - - this.ids = {}; /* a dictionnary linking buttons ids to keywords */ + this.checkOption("keywords"); + this.checkOption("polemic_mode", true); + this.checkOption("polemics"); + this.checkOption("cinecast_version", false); + this.checkOption("api_endpoint_template"); + this.checkOption("show_from_field", true); + this.checkOption("api_method"); + + if (!IriSP.null_or_undefined(IriSP.user)) { + if (!IriSP.null_or_undefined(IriSP.user.avatar)) { + this.user_avatar = IriSP.user.avatar; + } + if (!IriSP.null_or_undefined(IriSP.user.name)) { + this.user_name = IriSP.user.name; + } + } /* variables to save the current position of the slicer */ if (this.cinecast_version) { @@ -29,14 +37,9 @@ IriSP.createAnnotationWidget.prototype.draw = function() { var _this = this; - var template_params = {cinecast_version: this.cinecast_version, - polemic_mode: this.polemic_mode}; - - if (!IriSP.null_or_undefined(IriSP.user) && !IriSP.null_or_undefined(IriSP.user.avatar)) - template_params["user_avatar"] = IriSP.user.avatar; var annotationMarkup = IriSP.templToHTML(IriSP.createAnnotationWidget_template, - template_params); + this); this.selector.append(annotationMarkup); @@ -45,70 +48,12 @@ else { this.showStartScreen(); } + + // Add onclick event to both polemic and keywords buttons - // add the keywords. - for (var i = 0; i < this.keywords.length; i++) { - var keyword = this.keywords[i]; - var id = IriSP.guid("button_"); - var templ = IriSP.templToHTML("", - {keyword: keyword, id: id}); - - this.ids[keyword] = id; // save it for the function that handle textarea changes. - - this.selector.find(".Ldt-createAnnotation-keywords").append(templ); - this.selector.find("#" + id).click(function(keyword) { return function() { - var contents = _this.selector.find(".Ldt-createAnnotation-Description").val(); - if (contents.indexOf(keyword) != -1) { - var newVal = contents.replace(" " + keyword, ""); - if (newVal == contents) - newVal = contents.replace(keyword, ""); - } else { - if (contents === "") - var newVal = keyword; - else - var newVal = contents + " " + keyword; - } - - _this.selector.find(".Ldt-createAnnotation-Description").val(newVal); - // we use a custom event because there's no simple way to test for a js - // change in a textfield. - _this.selector.find(".Ldt-createAnnotation-Description").trigger("js_mod"); - // also call our update function. - //_this.handleTextChanges(); - } - }(keyword)); - } - - // add the polemic buttons. - if(this.polemic_mode) - for (var polemic in this.polemics) { - - var classname = IriSP.templToHTML("Ldt-createAnnotation-polemic-{{classname}}", {classname : this.polemics[polemic]}); - - var templ = IriSP.templToHTML("", - {classname: classname, polemic: polemic}); - - this.selector.find(".Ldt-createAnnotation-polemics").append(templ); - this.selector.find("." + classname).click(function(polemic) { return function() { - var contents = _this.selector.find(".Ldt-createAnnotation-Description").val(); - if (contents.indexOf(polemic) != -1) { - var newVal = contents.replace(" " + polemic, ""); - if (newVal == contents) - newVal = contents.replace(polemic, ""); - } else { - if (contents === "") - var newVal = polemic; - else - var newVal = contents + " " + polemic; - } - - _this.selector.find(".Ldt-createAnnotation-Description").val(newVal); - - // also call our update function. - _this.handleTextChanges(); - } - }(polemic)); - } + this.selector.find(".Ldt-createAnnotation-keywords button, .Ldt-createAnnotation-polemics button").click(function() { + _this.addKeyword(IriSP.jQuery(this).text()); + }); // js_mod is a custom event because there's no simple way to test for a js // change in a textfield. @@ -178,6 +123,19 @@ } }; +/* Handles adding keywords and polemics */ +IriSP.createAnnotationWidget.prototype.addKeyword = function(_keyword) { + var _field = this.selector.find(".Ldt-createAnnotation-Description"), + _rx = IriSP.regexpFromText(_keyword), + _contents = _field.val(); + _contents = ( _rx.test(_contents) + ? _contents.replace(_rx,"").replace(" "," ").trim() + : _contents.trim() + " " + _keyword + ); + _field.val(_contents); + _field.trigger("js_mod"); +} + /** handles clicks on the annotate button. Works only for the non-cinecast version */ IriSP.createAnnotationWidget.prototype.handleAnnotateSignal = function() { @@ -237,24 +195,25 @@ IriSP.createAnnotationWidget.prototype.handleTextChanges = function(event) { var contents = this.selector.find(".Ldt-createAnnotation-Description").val(); - for(var keyword in this.ids) { - - var id = this.ids[keyword]; + this.selector.find(".Ldt-createAnnotation-keywords button").each(function() { + var _rx = IriSP.regexpFromText(IriSP.jQuery(this).text()); + if (_rx.test(contents)) { + IriSP.jQuery(this).removeClass("Ldt-createAnnotation-absent-keyword") + .addClass("Ldt-createAnnotation-present-keyword"); + } else { + IriSP.jQuery(this).addClass("Ldt-createAnnotation-absent-keyword") + .removeClass("Ldt-createAnnotation-present-keyword"); + } + }); - if (contents.indexOf(keyword) != -1) { - /* the word is present in the textarea but the button is not toggled */ - if (this.selector.find("#" + id).hasClass("Ldt-createAnnotation-absent-keyword")) - this.selector.find("#" + id).removeClass("Ldt-createAnnotation-absent-keyword") - .addClass("Ldt-createAnnotation-present-keyword"); - } else { - /* the word is absent from the textarea but the button is toggled */ - if (this.selector.find("#" + id).hasClass("Ldt-createAnnotation-present-keyword")) { - this.selector.find("#" + id).removeClass("Ldt-createAnnotation-present-keyword") - .addClass("Ldt-createAnnotation-absent-keyword"); + this.selector.find(".Ldt-createAnnotation-polemics button").each(function() { + var _rx = IriSP.regexpFromText(IriSP.jQuery(this).text()); + if (_rx.test(contents)) { + IriSP.jQuery(this).addClass("Ldt-createAnnotation-polemic-active"); + } else { + IriSP.jQuery(this).removeClass("Ldt-createAnnotation-polemic-active"); } - } - } - + }); if (this.polemic_mode) { /* Also go through the polemics to highlight the buttons */ for (var polemic in this.polemics) { @@ -327,7 +286,7 @@ var _this = this; var textfield = this.selector.find(".Ldt-createAnnotation-Description"); var contents = textfield.val(); - + if (contents === "") { if (this.selector.find(".Ldt-createAnnotation-errorMessage").length === 0) { this.selector.find(".Ldt-createAnnotation-Container") @@ -407,20 +366,23 @@ annotation.content["data"] = contents; var meta = apiJson["meta"]; - if (!IriSP.null_or_undefined(IriSP.user) && !IriSP.null_or_undefined(IriSP.user.name)) - meta.creator = IriSP.user.name; - else - meta.creator = "An User"; + + + var _username = this.selector.find(".Ldt-createAnnotation-userName").val(); + meta.creator = ( + (_username && _username.length) + ? _username + : ( + (!IriSP.null_or_undefined(IriSP.user) && !IriSP.null_or_undefined(IriSP.user.name)) + ? IriSP.user.name + : "Anonymous user" + ) + ); meta.created = Date().toString(); - annotation["tags"] = []; - - for (var i = 0; i < this.keywords.length; i++) { - var keyword = this.keywords[i]; - if (contents.indexOf(keyword) != -1) - annotation["tags"].push(keyword); - } + // All #hashtags are added to tags + annotation.tags = contents.match(/(#[\S]*)/g); var jsonString = JSON.stringify(apiJson); var project_id = this._serializer._data.meta.id; @@ -431,7 +393,7 @@ IriSP.jQuery.ajax({ url: url, - type: 'PUT', + type: this.api_method, contentType: 'application/json', data: jsonString, //dataType: 'json', diff -r ae16691d183d -r 18ca612e9ff0 src/js/widgets/playerWidget.js --- a/src/js/widgets/playerWidget.js Tue Mar 06 13:26:51 2012 +0100 +++ b/src/js/widgets/playerWidget.js Thu Mar 08 18:38:46 2012 +0100 @@ -58,9 +58,9 @@ /* Update the elasped time div */ IriSP.PlayerWidget.prototype.timeDisplayUpdater = function() { - if (this._previousSecond === undefined) + if (this._previousSecond === undefined) { this._previousSecond = this._Popcorn.roundTime(); - + } else { /* we're still in the same second, so it's not necessary to update time */ if (this._Popcorn.roundTime() == this._previousSecond) diff -r ae16691d183d -r 18ca612e9ff0 src/js/widgets/polemicWidget.js --- a/src/js/widgets/polemicWidget.js Tue Mar 06 13:26:51 2012 +0100 +++ b/src/js/widgets/polemicWidget.js Thu Mar 08 18:38:46 2012 +0100 @@ -54,7 +54,7 @@ var duration = this._serializer.getDuration(); // timescale width var frameLength = lineSize / frameSize; // frame timescale var timeline; - var colors = new Array("","#1D973D","#C5A62D","#CE0A15","#036AAE","#585858"); + var colors = new Array("","#1D973D","#036AAE","#CE0A15","#C5A62D","#585858"); // array //var tweets = new Array(); @@ -322,9 +322,16 @@ e.id = frames[i].mytweetsID[k].cinecast_id; this.svgElements[e.id] = e; - IriSP.jQuery(e.node).mouseenter(function(element) { return function () { + IriSP.jQuery(e.node).mouseenter(function(element) { return function (_e) { self.TooltipWidget.show.call(self.TooltipWidget, element.title, element.attr("fill"), element.attrs.x + element.attrs.width / 2, element.attrs.y - 2); element.displayed = true; + self._Popcorn.trigger("IriSP.TraceWidget.MouseEvents", { + "widget" : "StackGraphWidget", + "type": "mousemove", + "x": _e.pageX, + "y": _e.pageY, + "annotation_id": element.id + }); }}(e)).mousedown(function(element) { return function () { self._Popcorn.currentTime(element.time/1000); self._Popcorn.trigger("IriSP.PolemicTweet.click", element.id); diff -r ae16691d183d -r 18ca612e9ff0 src/js/widgets/stackGraphWidget.js --- a/src/js/widgets/stackGraphWidget.js Tue Mar 06 13:26:51 2012 +0100 +++ b/src/js/widgets/stackGraphWidget.js Thu Mar 08 18:38:46 2012 +0100 @@ -158,14 +158,19 @@ var _this = this; this.selector .click(IriSP.wrap(this, this.clickHandler)) - .mousemove(function(event) { - _this.updateTooltip(event); - - // Also tell the world where the mouse is hovering. - var relX = event.pageX - _this.selector.offset().left; - var duration = _this._serializer.getDuration(); - var Time = ((relX / _this.width) * duration).toFixed(2); - _this._Popcorn.trigger("IriSP.StackGraphWidget.mouseOver", Time); + .mousemove(function(_e) { + _this.updateTooltip(_e); + // Trace + var relX = _e.pageX - _this.selector.offset().left; + var _duration = _this._serializer.getDuration(); + var _time = parseInt((relX / _this.width) * _duration); + _this._Popcorn.trigger("IriSP.TraceWidget.MouseEvents", { + "widget" : "StackGraphWidget", + "type": "mousemove", + "x": _e.pageX, + "y": _e.pageY, + "time": _time + }); }) .mouseout(function() { @@ -198,7 +203,7 @@ }; IriSP.StackGraphWidget.prototype.updateTooltip = function(event) { - var _segment = Math.floor(this.sliceCount * (event.pageX - this.selector.offset().left)/this.width), + var _segment = Math.max(0,Math.min(this.groups.length - 1, Math.floor(this.sliceCount * (event.pageX - this.selector.offset().left)/this.width))), _valeurs = this.groups[_segment], _width = this.width / this.sliceCount, _html = '
- {{/user_avatar}}
- {{#user_avatar}}
-
+ {{/user_avatar}}
+ {{#user_avatar}}