diff -r fba78a21c109 -r 7607516bd9f1 web/res/js/LdtPlayer-release.js --- a/web/res/js/LdtPlayer-release.js Thu Apr 12 16:22:41 2012 +0200 +++ b/web/res/js/LdtPlayer-release.js Thu Apr 12 17:24:24 2012 +0200 @@ -996,7 +996,7 @@ "'")+",'"}).replace(d.evaluate||null,function(a,b){return"');"+b.replace(/\\'/g,"'").replace(/[\r\n\t]/g," ")+";__p.push('"}).replace(/\r/g,"\\r").replace(/\n/g,"\\n").replace(/\t/g,"\\t")+"');}return __p.join('');",e=new Function("obj","_",d);return c?e(c,b):function(a){return e.call(this,a,b)}};var n=function(a){this._wrapped=a};b.prototype=n.prototype;var u=function(a,c){return c?b(a).chain():a},J=function(a,c){n.prototype[a]=function(){var a=i.call(arguments);H.call(a,this._wrapped);return u(c.apply(b, a),this._chain)}};b.mixin(b);j("pop,push,reverse,shift,sort,splice,unshift".split(","),function(a){var b=k[a];n.prototype[a]=function(){b.apply(this._wrapped,arguments);return u(this._wrapped,this._chain)}});j(["concat","join","slice"],function(a){var b=k[a];n.prototype[a]=function(){return u(b.apply(this._wrapped,arguments),this._chain)}});n.prototype.chain=function(){this._chain=true;return this};n.prototype.value=function(){return this._wrapped}}).call(this); /* main file */ - +// Why is it called main ? It only loads the libs ! if ( window.IriSP === undefined && window.__IriSP === undefined ) { /** @@ -1016,23 +1016,39 @@ IriSP._ = window._.noConflict(); IriSP.underscore = IriSP._; -IriSP.loadLibs = function( libs, config, metadata_url, callback ) { +IriSP.getLib = function(lib) { + return ( + IriSP.libFiles.useCdn && typeof IriSP.libFiles.cdn[lib] == "string" + ? IriSP.libFiles.cdn[lib] + : ( + typeof IriSP.libFiles.locations[lib] == "string" + ? IriSP.libFiles.locations[lib] + : ( + typeof IriSP.libFiles.inDefaultDir[lib] == "string" + ? IriSP.libFiles.defaultDir + IriSP.libFiles.inDefaultDir[lib] + : null + ) + ) + ) +} + +IriSP.loadLibs = function( config, metadata_url, callback ) { // Localize jQuery variable IriSP.jQuery = null; - var $L = $LAB.script(libs.jQuery).script(libs.swfObject).wait() - .script(libs.jQueryUI); + var $L = $LAB.script(IriSP.getLib("jQuery")).script(IriSP.getLib("swfObject")).wait() + .script(IriSP.getLib("jQueryUI")); if (config.player.type === "jwplayer" || config.player.type === "allocine") { // load our popcorn.js lookalike - $L.script(libs.jwplayer); + $L.script(IriSP.getLib("jwplayer")); } else { // load the real popcorn - $L.script(libs.popcorn).script(libs["popcorn.code"]); + $L.script(IriSP.getLib("popcorn")).script(IriSP.getLib("popcorn.code")); if (config.player.type === "youtube") { - $L.script(libs["popcorn.youtube"]); + $L.script(IriSP.getLib("popcorn.youtube")); } if (config.player.type === "vimeo") - $L.script(libs["popcorn.vimeo"]); + $L.script(IriSP.getLib("popcorn.vimeo")); /* do nothing for html5 */ } @@ -1042,10 +1058,10 @@ if (config.gui.widgets[idx].type === "PolemicWidget" || config.gui.widgets[idx].type === "StackGraphWidget" || config.gui.widgets[idx].type === "SparklineWidget") { - $L.script(libs.raphael); + $L.script(IriSP.getLib("raphael")); } if (config.gui.widgets[idx].type === "TraceWidget") { - $L.script(libs.tracemanager) + $L.script(IriSP.getLib("tracemanager")) } } @@ -1053,7 +1069,7 @@ /* for (var idx in config.modules) { if (config.modules[idx].type === "PolemicWidget") - $L.script(libs.raphaelJs); + $L.script(IriSP.getLib("raphaelJs")); } */ @@ -1063,7 +1079,7 @@ var css_link_jquery = IriSP.jQuery( "", { rel: "stylesheet", type: "text/css", - href: libs.cssjQueryUI, + href: IriSP.getLib("cssjQueryUI"), 'class': "dynamic_css" } ); var css_link_custom = IriSP.jQuery( "", { @@ -1089,9 +1105,9 @@ IriSP.annotation_template = "{{! template for an annotation displayed in a segmentWidget }}
"; IriSP.annotationWidget_template = "{{! template for the annotation widget }}
"; IriSP.annotation_loading_template = "{{! template shown while the annotation widget is loading }}
 
Chargement...
"; -IriSP.annotationsListWidget_template = "{{! template for the annotation list widget }}
"; +IriSP.annotationsListWidget_template = "{{! template for the annotation list widget }}
"; IriSP.arrowWidget_template = "
"; -IriSP.createAnnotationWidget_template = "{{! template for the annotation creation widget }}
{{^cinecast_version}}
{{/cinecast_version}}
{{#show_from_field}} {{/show_from_field}}
{{^user_avatar}} {{/user_avatar}} {{#user_avatar}} {{/user_avatar}}
{{#keywords.length}}
    {{#keywords}}
  • {{/keywords}}
{{/keywords.length}} {{#polemic_mode}} {{#polemics.length}}
    {{#polemics}}
  • {{/polemics}}
{{/polemics.length}} {{/polemic_mode}}
"; +IriSP.createAnnotationWidget_template = "{{! template for the annotation creation widget }}
{{^cinecast_version}}
{{/cinecast_version}}
{{#show_from_field}} {{/show_from_field}}
{{^user_avatar}} {{/user_avatar}} {{#user_avatar}} {{/user_avatar}}
{{#tags.length}}
    {{#tags}}
  • {{/tags}}
{{#random_tags}} {{/random_tags}} {{/tags.length}} {{#polemic_mode}} {{#polemics.length}}
    {{#polemics}}
  • {{/polemics}}
{{/polemics.length}} {{/polemic_mode}}
"; IriSP.createAnnotation_errorMessage_template = "

{{l10n.empty_annotation}}

"; IriSP.loading_template = "
{{l10n.loading_wait}}
"; IriSP.overlay_marker_template = "{{! the template for the small bars which is z-indexed over our segment widget }}
"; @@ -1286,10 +1302,7 @@ /** issue a call to an url shortener and return the shortened url */ IriSP.shorten_url = function(url) { - if (IriSP.config.shortener.hasOwnProperty("shortening_function")) - return IriSP.config.shortener.shortening_function(url); - - return url; + return encodeURIComponent(url); }; @@ -1424,11 +1437,11 @@ }; IriSP.PopcornReplacement.player.prototype.pause = function() { - if ( !this.media.paused ) { +// if ( !this.media.paused ) { this.media.paused = true; this.trigger( "pause" ); this.playerFns.pause(); - } +// } }; IriSP.PopcornReplacement.player.prototype.muted = function(val) { @@ -1556,15 +1569,16 @@ this._callbacks = {}; }; -IriSP.DataLoader.prototype.get = function(url, callback) { - - var base_url = url.split("&")[0] +IriSP.DataLoader.prototype.get = function(url, callback, force_reload) { + var base_url = url.split("&")[0]; + if (typeof force_reload != "undefined" && force_reload && this._cache.hasOwnProperty(base_url)) { + delete this._cache[base_url] + } if (this._cache.hasOwnProperty(base_url)) { callback(this._cache[base_url]); } else { if (!this._callbacks.hasOwnProperty(base_url)) { - this._callbacks[base_url] = []; - this._callbacks[base_url].push(callback); + this._callbacks[base_url] = [callback]; /* we need a closure because this gets lost when it's called back */ // uncomment you don't want to use caching. @@ -1577,6 +1591,7 @@ for (i = 0; i < this._callbacks[base_url].length; i++) { this._callbacks[base_url][i](this._cache[base_url]); } + delete this._callbacks[base_url]; }; /* automagically choose between json and jsonp */ @@ -1614,8 +1629,11 @@ IriSP.Serializer.prototype.currentMedia = function() { }; -IriSP.Serializer.prototype.sync = function(callback) { - callback.call(this, this._data); +IriSP.Serializer.prototype.getDuration = function() { +}; + +IriSP.Serializer.prototype.sync = function(callback) { + callback.call(this, this._data); }; IriSP.SerializerFactory = function(DataLoader) { @@ -1626,7 +1644,6 @@ /* This function returns serializer set-up with the correct configuration - takes a metadata struct describing the metadata source */ - if (metadataOptions === undefined) /* return an empty serializer */ return IriSP.Serializer("", ""); @@ -1648,157 +1665,147 @@ return undefined; } }; -/* site.js - all our site-dependent config : player chrome, cdn locations, etc...*/ - -IriSP.defaults = {}; - -/* these objects are filled by configureDefaults. The function doesn't overwrite - defaults that were originally defined by the user. -*/ -IriSP.lib = {}; - -/* We need to define those so that the individual settings can be overwritten */ -IriSP.widgetsDefaults = {}; - -IriSP.paths = {}; - -IriSP.libdir = "/metadataplayer/src/js/libs/"; -IriSP.jwplayer_swf_path = "../test/libs/player.swf"; -IriSP.platform_url = "http://192.168.56.101/pf"; -IriSP.default_templates_vars = { }; - -IriSP.language = 'fr'; - -/** ugly ugly ugly ugly - returns an object defining - the paths to the libs - We need it that way cause it's called at runtime by - IriSP.configureDefaults. -*/ -IriSP.defaults.lib = function(libdir) { - if (IriSP.null_or_undefined(libdir)) - libdir = IriSP.libdir; - - return { -// jQuery : "http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.js", - jQuery : libdir + "jquery.min.js", -// jQueryUI : "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.17/jquery-ui.js", - jQueryUI : libdir + "jquery-ui.min.js", -// jQueryToolTip : "http://cdn.jquerytools.org/1.2.4/all/jquery.tools.min.js", - jQueryToolTip : libdir + "jquery.tools.min.js", -// swfObject : "http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js", - swfObject : libdir + "swfobject.js", -// cssjQueryUI : "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.4/themes/base/jquery-ui.css", - cssjQueryUI : libdir + "jquery-ui.css", - popcorn : libdir + "popcorn.js", - jwplayer : libdir + "jwplayer.js", - popcornReplacement: libdir + "pop.js", - raphael: libdir + "raphael.js", - jquery_sparkline: libdir + "jquery.sparkline.js", - "popcorn.mediafragment" : libdir + "popcorn.mediafragment.js", - "popcorn.code" : libdir + "popcorn.code.js", - "popcorn.jwplayer": libdir + "popcorn.jwplayer.js", - "popcorn.youtube": libdir + "popcorn.youtube.js", - "tracemanager": libdir + "tracemanager.js" - }; -}; - -//Configuration for the player and utility functions. -// No need to have them configured at runtime -IriSP.config = {}; - -IriSP.config.shortener = { - // function to call to shorten an url. - //shortening_function : IriSP.platform_shorten_url -}; - -IriSP.defaults.widgetsDefaults = function(platform_url) { - if (IriSP.null_or_undefined(platform_url)) - platform_url = IriSP.platform_url; - - return { - "LayoutManager" : {spacer_div_height : "0px" }, - "PlayerWidget" : {}, - "AnnotationsWidget": { - "share_text" : "I'm watching ", - "fb_link" : "http://www.facebook.com/share.php?u=", - "tw_link" : "http://twitter.com/home?status=", - "gplus_link" : "" - }, - +IriSP.language = 'en'; + +IriSP.libFiles = { + defaultDir : "js/libs/", + inDefaultDir : { + jQuery : "jquery.min.js", + jQueryUI : "jquery-ui.min.js", + jQueryToolTip : "jquery.tools.min.js", + swfObject : "swfobject.js", + cssjQueryUI : "jquery-ui.css", + popcorn : "popcorn.js", + jwplayer : "jwplayer.js", + raphael : "raphael.js", + "popcorn.mediafragment" : "popcorn.mediafragment.js", + "popcorn.code" : "popcorn.code.js", + "popcorn.jwplayer" : "popcorn.jwplayer.js", + "popcorn.youtube" : "popcorn.youtube.js", + "tracemanager" : "tracemanager.js" + }, + locations : { + // use to define locations outside defautl_dir + }, + cdn : { + jQueryUI : "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.17/jquery-ui.js", + jQueryToolTip : "http://cdn.jquerytools.org/1.2.4/all/jquery.tools.min.js", + swfObject : "http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js", + cssjQueryUI : "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.4/themes/base/jquery-ui.css" + }, + useCdn : false +} + +IriSP.widgetsDefaults = { + "LayoutManager" : { + spacer_div_height : 0 + }, + "PlayerWidget" : { + + }, + "AnnotationsWidget" : { + "share_text" : "I'm watching " + }, "TweetsWidget" : { default_profile_picture : "https://si0.twimg.com/sticky/default_profile_images/default_profile_1_normal.png", - tweet_display_period: 10000 // how long do we show a tweet ? - + tweet_display_period : 10000 // how long do we show a tweet ? }, "SliderWidget" : { - minimize_period: 850 // how long does the slider stays maximized after the user leaves the zone ? + minimize_period : 850 // how long does the slider stays maximized after the user leaves the zone ? + }, + "SegmentsWidget" : { + cinecast_version : false }, "createAnnotationWidget" : { - keywords: ["#amateur", "#digital-studies"], - polemic_mode: true, /* enable polemics ? */ - /* polemics - the corresponding class names defined in the css should be for instance : - Ldt-createAnnotation-polemic-positive for positive - Ldt-createAnnotation-polemic-equalequal for equalequal, etc. - */ - polemics: [ { "className" : "positive", "keyword" : "++" }, { "className" : "negative", "keyword" : "--" }, { "className" : "reference", "keyword" : "==" }, { "className" : "question", "keyword" : "??" } ], - cinecast_version: false, /* put to false to enable the platform version, true for the festival cinecast one. */ - + tags : [ + { + "id" : "digitalstudies", + "meta" : { + "description" : "#digital-studies" + } + }, + { + "id" : "amateur", + "meta" : { + "description" : "#amateur" + }, + } + ], + remote_tags : false, + random_tags : false, + show_from_field : false, + disable_share : false, + polemic_mode : true, /* enable polemics ? */ + polemics : [{ + "className" : "positive", + "keyword" : "++" + }, { + "className" : "negative", + "keyword" : "--" + }, { + "className" : "reference", + "keyword" : "==" + }, { + "className" : "question", + "keyword" : "??" + }], + cinecast_version : false, /* 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_method: "PUT" + by the widget. + */ + 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. - }, - "Main" : { - autoplay: true + lineColor : "#7492b4", + fillColor : "#aeaeb8", + lineWidth : 2, + cinecast_version : false }, "AnnotationsListWidget" : { - ajax_mode: true, /* use ajax to get information about the annotations. - if set to false, only search in the annotations for the - current project. */ + ajax_mode : true, /* use ajax to get information about the annotations. + if set to false, only search in the annotations for the + current project. */ /* the platform generates some funky urls. We replace them afterwards to point to the - correct place - this setting will probably be overwritten by the platform - implementers. - Note that the player has to replace the variables between {{ and }} by its own values. - */ - ajax_url: platform_url + "/ldtplatform/api/ldt/segments/{media}/{begin}/{end}", - - ajax_granularity: 10000, /* how much ms should we look before and after the - current timecode */ - - default_thumbnail: "/metadataplayer/src/css/imgs/video_sequence.png", - - project_url: platform_url + "/ldtplatform/ldt/front/player/" /* the beginning - of a link to the - new front */ - } - }; -}; - -/* -Override this if you want to change the info the player receives about the user. -It's typically overrided in server-side templates with user-specific data. -*/ -IriSP.defaults.user = function() { return { - "name" : "Anonymous user", - "avatar" : IriSP.paths.imgs + "/user_default_icon.png" + correct place - this setting will probably be overwritten by the platform + implementers. + Note that the player has to replace the variables between {{ and }} by its own values. + */ + ajax_url : "", //platform_url + "/ldtplatform/api/ldt/segments/{{media}}/{{begin}}/{{end}}", + ajax_granularity : 10000, /* how much ms should we look before and after the current timecode */ + default_thumbnail : "http://ldt.iri.centrepompidou.fr/static/site/ldt/css/imgs/video_sequence.png", + project_url : "", //platform_url + "/ldtplatform/ldt/front/player/" + /* the beginning of a link to the new front */ + cinecast_version : false, + refresh_interval : 10000 + }, + "StackGraphWidget" : { + defaultcolor : "#585858", + tags : [ + { + "keywords" : [ "++" ], + "description" : "positif", + "color" : "#1D973D" + }, + { + "keywords" : [ "--" ], + "description" : "negatif", + "color" : "#CE0A15" + }, + { + "keywords" : [ "==" ], + "description" : "reference", + "color" : "#C5A62D" + }, + { + "keywords" : [ "??" ], + "description" : "question", + "color" : "#036AAE" + } + ], + streamgraph : false } -}; - - -IriSP.defaults.paths = { -// "imgs": "/tweetlive/res/metadataplayer/src/css/imgs" - "imgs": "/metadataplayer/src/css/imgs" -}; - - -IriSP.defaults.default_templates_vars = function() { - return { - "img_dir" : IriSP.paths.imgs - }; }/* the widget classes and definitions */ /** @@ -1858,24 +1865,28 @@ this.selector.attr("widget-type", this._config.type); } -}; - -// 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 - ) - ) - ) + // Parsing Widget Defaults + var _this = this; + + if (typeof config.type == "string" && typeof IriSP.widgetsDefaults[config.type] == "object") { + IriSP._(IriSP.widgetsDefaults[config.type]).each(function(_v, _k) { + if (typeof config[_k] != "undefined") { + _this[_k] = config[_k]; + } else { + _this[_k] = _v; + } + }); + } + +}; + + +IriSP.Widget.prototype.currentMedia = function() { + return this._serializer.currentMedia(); +} + +IriSP.Widget.prototype.getDuration = function() { + return this._serializer.getDuration(); } /** @@ -1935,7 +1946,10 @@ /* this is a shortcut */ this.selector = IriSP.jQuery("#" + this._div); - this.selector.css("width", this._width); + this.selector.css({ + "width": this._width, + "clear": "both" + }); if (this._height !== undefined) this.selector.css("height", this._height); @@ -1965,8 +1979,8 @@ var spacerDiv = IriSP.guid("LdtPlayer_spacer_"); this._widgets.push([widgetName, newDiv]); - var divTempl = "
$1')) + _$.html(_$.text().trim().replace(_this.searchRe, '$1')) }) } }; IriSP.AnnotationsListWidget.prototype.transformAnnotation = function(a) { - var _this = this + var _this = this; return { "id" : a.id, "title": this.cinecast_version ? IriSP.get_aliased(a.meta, ['creator_name', 'creator']) : a.content.title, @@ -2850,6 +2829,7 @@ "end" : IriSP.msToTime(a.end), "thumbnail" : (typeof a.meta == "object" && typeof a.meta.thumbnail == "string") ? a.meta.thumbnail : this.default_thumbnail, "url" : (typeof a.meta == "object" && typeof a.meta.url == "string") ? a.meta.url : null, + "created_at" :(typeof a.meta == "object" && typeof a.meta.created == "string") ? Date.parse(a.meta.created.replace(/^(\d{4})-(\d{2})-(\d{2})T(\d{2}\:\d{2}\:\d{2}).*$/,"$2/$3/$1 $4 UTC+0000")) : null, "tags": typeof a.tags == "object" ? IriSP.underscore(a.tags) .chain() @@ -2908,7 +2888,6 @@ this._Popcorn.trigger("IriSP.search.noMatchFound"); } } - list = IriSP.underscore(list) .chain() .sortBy(function(_o) { @@ -2916,16 +2895,15 @@ }) .first(10) .sortBy(function(_o) { - return _o.iterator; + return (_this.cinecast_version ? - _o.created_at : _o.iterator); }) .value(); - var idList = IriSP.underscore.pluck(list, "id").sort(); - - if (!IriSP.underscore.isEqual(this.__oldList, idList) || typeof(force_redraw) !== "undefined") { + if (!IriSP.underscore.isEqual(this.__oldList, idList) || this.lastSearch !== this.searchRe || typeof(force_redraw) !== "undefined") { this.do_redraw(list); this.__oldList = idList; + this.lastSearch = this.searchRe; } /* save for next call */ @@ -2944,15 +2922,13 @@ } - /* the platform gives us a special url - of the type : http://path/{media}/{begin}/{end} + /* the platform gives us a special url - of the type : http://path/{{media}}/{{begin}}/{{end}} we double the braces using regexps and we feed it to mustache to build the correct url we have to do that because the platform only knows at run time what view it's displaying. */ - var platf_url = IriSP.widgetsDefaults.AnnotationsListWidget.ajax_url - .replace(/\{/g, '{{').replace(/\}/g, '}}'); - var media_id = this._serializer.currentMedia()["id"]; - var duration = this._serializer.getDuration(); + var media_id = this.currentMedia()["id"]; + var duration = this.getDuration(); var begin_timecode = (Math.floor(tcode) - 300) * 1000; if (begin_timecode < 0) @@ -2962,7 +2938,7 @@ if (end_timecode > duration) end_timecode = duration; - var templ = Mustache.to_html(platf_url, {media: media_id, begin: begin_timecode, + var templ = Mustache.to_html(this.ajax_url, {media: media_id, begin: begin_timecode, end: end_timecode}); /* we create on the fly a serializer to get the ajax */ @@ -2983,7 +2959,7 @@ */ var l = []; - var media = this._serializer.currentMedia()["id"]; + var media = this.currentMedia()["id"]; for (i = 0; i < annotations.length; i++) { var obj = this.transformAnnotation(annotations[i]) @@ -3016,13 +2992,33 @@ var _this = this; - if (!this.ajax_mode) { + if (!this.ajax_mode || this.cinecast_version) { var _throttled = IriSP.underscore.throttle(function() { _this.drawList(); }, 1500); _throttled(); this._Popcorn.listen("IriSP.createAnnotationWidget.addedAnnotation", _throttled); this._Popcorn.listen("timeupdate", _throttled); + if (this.cinecast_version) { + window.setInterval(function() { + var _tmpSerializer = new IriSP.JSONSerializer(IriSP.__dataloader, _this._config.metadata.src, true); + _tmpSerializer.sync(function(json) { + _this.annotations_ids = IriSP.underscore(_this._serializer._data.annotations).map(function(_a) { + return _a.id.toLowerCase(); + }); + IriSP.underscore(json.annotations).each(function(_a) { + var _j = _this.annotations_ids.indexOf(_a.id); + if (_j == -1) { + _this._serializer._data.annotations.push(_a); + _this.annotations_ids.push(_a.id); + } else { + _this._serializer._data.annotations[_j] = _a; + } + _throttled(); + }); + }, true); // true is for force_refresh + },this.refresh_interval); + } } else { /* update the widget when the video has finished loading and when it's seeked and paused */ this._Popcorn.listen("seeked", IriSP.wrap(this, this.ajaxRedraw)); @@ -3066,7 +3062,7 @@ var keywords = ""; var begin = +annotation.begin / 1000; var end = +annotation.end / 1000; - var duration = this._serializer.getDuration(); + var duration = this.getDuration(); var tags = ""; var title_templ = "{{title}} - ( {{begin}} - {{end}} )"; @@ -3098,15 +3094,10 @@ this.selector.find(".Ldt-SaKeywords").text(tags); // update sharing buttons - var defaults = IriSP.widgetsDefaults.AnnotationsWidget; - var text = defaults.share_text; - var fb_link = defaults.fb_link; - var tw_link = defaults.tw_link; - var gplus_link = defaults.gplus_link; var url = document.location.href + "#id=" + annotation.id; - this.selector.find(".Ldt-fbShare").attr("href", IriSP.mkFbUrl(url, text)); - this.selector.find(".Ldt-TwShare").attr("href", IriSP.mkTweetUrl(url, text)); - this.selector.find(".Ldt-GplusShare").attr("href", IriSP.mkGplusUrl(url, text)); + this.selector.find(".Ldt-fbShare").attr("href", IriSP.mkFbUrl(url, this.share_text)); + this.selector.find(".Ldt-TwShare").attr("href", IriSP.mkTweetUrl(url, this.share_text)); + this.selector.find(".Ldt-GplusShare").attr("href", IriSP.mkGplusUrl(url, this.share_text)); }; IriSP.AnnotationsWidget.prototype.clearWidget = function() { @@ -3220,7 +3211,7 @@ var begin = (+ currentAnnotation.begin) / 1000; var end = (+ currentAnnotation.end) / 1000; - var duration = this._serializer.getDuration() / 1000; + var duration = this.getDuration() / 1000; var middle_time = (begin + end) / 2; var percents = middle_time / duration; @@ -3281,7 +3272,8 @@ "empty_annotation": "Your annotation is empty. Please write something before submitting.", "annotation_saved": "Thank you, your annotation has been saved.", "share_annotation": "Would you like to share it on social networks ?", - "share_on": "Share on" + "share_on": "Share on", + "more_tags": "More tags" }, "fr": { "submit": "Envoyer", @@ -3294,7 +3286,8 @@ "empty_annotation": "Votre annotation est vide. Merci de rédiger un texte avant de l'envoyer.", "annotation_saved": "Merci, votre annotation a été enregistrée.", "share_annotation": "Souhaitez-vous la partager sur les réseaux sociaux ?", - "share_on": "Partager sur" + "share_on": "Partager sur", + "more_tags": "Plus de mots-clés" } } ); @@ -3302,14 +3295,6 @@ IriSP.createAnnotationWidget = function(Popcorn, config, Serializer) { IriSP.Widget.call(this, Popcorn, config, Serializer); this._hidden = true; - - 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)) { @@ -3337,6 +3322,18 @@ }; IriSP.createAnnotationWidget.prototype.draw = function() { + var _this = this; + if (typeof this.remote_tags == "object") { + IriSP.jQuery.getJSON((typeof this.remote_tags.alias == "string" ? this.remote_tags.alias : this.remote_tags.url), function(_json) { + _this.tags = _json.tags; + _this.drawCallback(); + }); + } else { + this.drawCallback(); + } +} + +IriSP.createAnnotationWidget.prototype.drawCallback = function() { var _this = this; var annotationMarkup = IriSP.templToHTML(IriSP.createAnnotationWidget_template, @@ -3349,17 +3346,25 @@ else { this.showStartScreen(); } - + + if (this.random_tags) { + this.selector.find(".Ldt-createAnnotation-keywords li").hide(); + this.showMoreTags(); + this.selector.find('.Ldt-createAnnotation-moar-keywordz').click(function() { + _this.showMoreTags(); + }) + } // Add onclick event to both polemic and keywords buttons - this.selector.find(".Ldt-createAnnotation-btnblock button").click(function() { + this.selector.find(".Ldt-createAnnotation-keyword-button, .Ldt-createAnnotation-polemic-button").click(function() { _this.addKeyword(IriSP.jQuery(this).text()); + return false; }); // js_mod is a custom event because there's no simple way to test for a js // change in a textfield. this.selector.find(".Ldt-createAnnotation-Description") - .bind("propertychange keyup input paste js_mod", IriSP.wrap(this, this.handleTextChanges)); + .bind("propertychange keyup input paste click js_mod", IriSP.wrap(this, this.handleTextChanges)); /* the cinecast version of the player is supposed to pause when the user clicks on the button */ @@ -3420,6 +3425,21 @@ } }; +IriSP.createAnnotationWidget.prototype.showMoreTags = function() { + for (var j=0; j < this.random_tags; j++) { + var _jq = this.selector.find(".Ldt-createAnnotation-keywords li:hidden"); + if (_jq.length > 1) { + IriSP.jQuery(_jq[Math.floor(_jq.length*Math.random())]).show(); + } else { + _jq.show(); + break; + } + } + if (this.selector.find(".Ldt-createAnnotation-keywords li:hidden").length == 0) { + this.selector.find('.Ldt-createAnnotation-moar-keywordz').hide(); + } +} + /* Handles adding keywords and polemics */ IriSP.createAnnotationWidget.prototype.addKeyword = function(_keyword) { var _field = this.selector.find(".Ldt-createAnnotation-Description"), @@ -3429,8 +3449,7 @@ ? _contents.replace(_rx,"").replace(" "," ").trim() : _contents.trim() + " " + _keyword ); - _field.val(_contents); - _field.trigger("js_mod"); + _field.val(_contents.trim()).trigger("js_mod"); } /** handles clicks on the annotate button. Works only for the non-cinecast version */ @@ -3455,7 +3474,7 @@ // block the arrow. this._Popcorn.trigger("IriSP.ArrowWidget.blockArrow"); - var duration = this._serializer.getDuration(); + var duration = this.getDuration(); var currentChapter = this._serializer.currentChapitre(currentTime); @@ -3491,7 +3510,7 @@ /** watch for changes in the textfield and change the buttons accordingly */ IriSP.createAnnotationWidget.prototype.handleTextChanges = function(event) { var contents = this.selector.find(".Ldt-createAnnotation-Description").val(); - if (this.cinecast_version && !this._Popcorn.media.paused) { + if (this.cinecast_version) { this._Popcorn.pause(); } this.selector.find(".Ldt-createAnnotation-btnblock button").each(function() { @@ -3614,23 +3633,28 @@ IriSP.createAnnotationWidget.prototype.sendLdtData = function(contents, callback) { var _this = this; - var apiJson = {annotations : [{}], meta: {}}; + var apiJson = { + format : "http://advene.org/ns/cinelab/", + annotations : [ + {} + ], + meta: {}}; var annotation = apiJson.annotations[0]; - annotation.media = this._serializer.currentMedia()["id"]; + annotation.media = this.currentMedia()["id"]; if (this.cinecast_version) { annotation.begin = Math.round(this._Popcorn.currentTime() * 1000); annotation.end = annotation.begin; } else { - var duration = this._serializer.getDuration(); + var duration = this.getDuration(); annotation.begin = +((duration * (this.sliceLeft / 100)).toFixed(0)); annotation.end = +((duration * ((this.sliceWidth + this.sliceLeft) / 100)).toFixed(0)); } // boundary checks annotation.begin = Math.max(0, annotation.begin); - annotation.end = Math.min(this._serializer.getDuration(), annotation.end); + annotation.end = Math.min(this.getDuration(), annotation.end); annotation.type = ( this.cinecast_version ? "cinecast:UserAnnotation" : ( this._serializer.getContributions() || "" )); if (typeof(annotation.type) === "undefined") @@ -3665,8 +3689,27 @@ meta.created = Date().toString(); - // All #hashtags are added to tags - annotation.tags = contents.match(/#[^#\s]+\b/gim) || []; + var _tags = []; + IriSP._(this.tags).each(function(_v) { + var _rx = IriSP.regexpFromText(_v.meta.description); + if (_rx.test(contents)) { + _tags.push(_v.id); + } + }); + + if (typeof this.remote_tags == "object") { + _tags = IriSP._(_tags).map(function(_t) { + return _this.remote_tags.id + ':' + _t + }); + if (typeof apiJson.imports == "undefined") { + apiJson.imports = []; + } + apiJson.imports.push({ + "id" : this.remote_tags.id, + "url" : this.remote_tags.url + }) + } + annotation.tags = IriSP.underscore.uniq(_tags); var jsonString = JSON.stringify(apiJson); var project_id = this._serializer._data.meta.id; @@ -3683,9 +3726,9 @@ //dataType: 'json', success: IriSP.wrap(this, function(json, textStatus, XMLHttpRequest) { /* add the annotation to the annotation and tell the world */ - if (this.cinecast_version) { - var annotation = json.annotations[0]; - } else { + var annotation = json.annotations[0]; + + if (!this.cinecast_version) { /* if the media doesn't have a contributions line, we need to add one */ if (typeof(this._serializer.getContributions()) === "undefined") { /* set up a basic view */ @@ -3704,12 +3747,19 @@ annotation.meta = meta; annotation.meta["id-ref"] = json.annotations[0]["type"]; + } else { + annotation.type = "cinecast:UserAnnotation"; } - // everything is shared so there's no need to propagate the change - _this._serializer._data.annotations.push(annotation); - + var _an_ids = IriSP.underscore(this._serializer._data.annotations).map(function(_a) { + return _a.id.toLowerCase(); + }); + if (_an_ids.indexOf(annotation.id.toLowerCase()) == -1) { + _this._serializer._data.annotations.push(annotation); + } + _this._Popcorn.trigger("IriSP.createAnnotationWidget.addedAnnotation", annotation); + this.selector.find(".Ldt-createAnnotation-Description").val("").trigger("js_mod"); callback(annotation); }), error: @@ -3863,7 +3913,7 @@ } // we get it at each call because it may change. - var duration = this._serializer.getDuration() / 1000; + var duration = this.getDuration() / 1000; var totalTime = IriSP.secondsToTime(duration); var elapsedTime = IriSP.secondsToTime(this._Popcorn.currentTime()); @@ -4071,7 +4121,7 @@ var lineSize = this.width; // timeline pixel width var nbrframes = lineSize/frameSize; // frame numbers var numberOfTweet = 0; // number of tweet overide later - var duration = this._serializer.getDuration(); // timescale width + var duration = this.getDuration(); // timescale width var frameLength = lineSize / frameSize; // frame timescale var timeline; var colors = new Array("","#1D973D","#036AAE","#CE0A15","#C5A62D","#585858"); @@ -4405,7 +4455,7 @@ IriSP.PolemicWidget.prototype.sliderUpdater = function() { var time = +this._Popcorn.currentTime(); - var duration = this._serializer.getDuration(); + var duration = this.getDuration(); this.paperSlider.attr("width", time * (this.width / (duration / 1000))); @@ -4477,7 +4527,6 @@ this._Popcorn.listen("IriSP.search.closed", function() { self.searchFieldClosedHandler.call(self); }); this._Popcorn.listen("IriSP.search.cleared", function() { self.searchFieldClearedHandler.call(self); }); - this.checkOption("cinecast_version"); this.defaultColors = ["#1f77b4","#aec7e8","#ff7f0e","#ffbb78","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5","#8c564b","#c49c94","#e377c2","#f7b6d2","#7f7f7f","#c7c7c7","#bcbd22","#dbdb8d","#17becf","#9edae5"] }; @@ -4494,7 +4543,7 @@ this.positionMarker = this.selector.find(".Ldt-SegmentPositionMarker"); this._Popcorn.listen("timeupdate", IriSP.wrap(this, this.positionUpdater)); - var duration = this._serializer.getDuration(); + var duration = this.getDuration(); if (this.cinecast_version) { var segments_annotations = IriSP.underscore.filter( @@ -4661,7 +4710,7 @@ }; IriSP.SegmentsWidget.prototype.positionUpdater = function() { - var duration = this._serializer.getDuration() / 1000; + var duration = this.getDuration() / 1000; var time = this._Popcorn.currentTime(); //var position = ((time / duration) * 100).toFixed(2); var position = ((time / duration) * 100).toFixed(2); @@ -4888,7 +4937,7 @@ var time = this._Popcorn.currentTime(); - var duration = this._serializer.getDuration() / 1000; + var duration = this.getDuration() / 1000; var percents = time / duration; /* we do these complicated calculations to center exactly @@ -4928,7 +4977,7 @@ var width = this.sliderBackground.width(); var relX = event.pageX - parentOffset.left; - var duration = this._serializer.getDuration() / 1000; + var duration = this.getDuration() / 1000; var newTime = ((relX / width) * duration).toFixed(2); this._Popcorn.currentTime(newTime); @@ -4941,7 +4990,7 @@ var width = this.sliderBackground.width(); var relX = event.pageX - parentOffset.left; - var duration = this._serializer.getDuration() / 1000; + var duration = this.getDuration() / 1000; var newTime = ((relX / width) * duration).toFixed(2); this._Popcorn.currentTime(newTime); @@ -4969,7 +5018,7 @@ IriSP.SliderWidget.prototype.mouseOutHandler = function(event) { this.timeOutId = window.setTimeout(IriSP.wrap(this, this.minimizeOnTimeout), - IriSP.widgetsDefaults.SliderWidget.minimize_period); + this.minimize_period); }; IriSP.SliderWidget.prototype.minimizeOnTimeout = function(event) { @@ -4998,7 +5047,7 @@ var width = this.sliderBackground.width(); var relX = event.originalEvent.pageX - parentOffset.left; - var duration = this._serializer.getDuration() / 1000; + var duration = this.getDuration() / 1000; var newTime = ((relX / width) * duration).toFixed(2); this._Popcorn.currentTime(newTime); @@ -5012,9 +5061,6 @@ this._oldAnnotation = null; this._results = []; - this.lineColor = this._config.lineColor || "#7492b4"; - this.fillColor = this._config.fillColor || "#aeaeb8"; - this.lineWidth = this._config.lineWidth || 2; this.slices = this._config.slices || Math.floor(this.width/20); if (!this.width) { this.width = this.selector.width(); @@ -5026,7 +5072,6 @@ if (this._config.background) { this.selector.css("background", this._config.background); } - this.checkOption('cinecast_version'); }; @@ -5038,7 +5083,7 @@ /** draw the sparkline using jquery sparkline */ IriSP.SparklineWidget.prototype.draw = function() { - this.duration = this._serializer.getDuration(); + this.duration = this.getDuration(); this.paper = new Raphael(this.selector[0], this.width, this.height); var _this = this; @@ -5061,11 +5106,16 @@ //console.log("sparklinewidget : using stats embedded in the json"); var _results = stat_view.meta.stat.split(","); } else { - var _annotations = this._serializer._data.annotations, - _sliceDuration = Math.floor( this.duration / this.slices), + var _annotations = this._serializer._data.annotations; + if (this.cinecast_version) { + _annotations = _(_annotations).filter(function(_a) { + return _a.type !== "cinecast:MovieExtract"; + }); + } + var _sliceDuration = Math.floor( this.duration / this.slices), _results = _(_.range(this.slices)).map(function(_i) { return _(_annotations).filter(function(_a){ - return (_a.begin <= (1 + _i) * _sliceDuration) && (_a.end >= _i * _sliceDuration) && (!_this.cinecast_version || _a.type == "cinecast:UserAnnotation") + return (_a.begin <= (1 + _i) * _sliceDuration) && (_a.end >= _i * _sliceDuration) }).length; }); } @@ -5158,53 +5208,23 @@ IriSP.StackGraphWidget.prototype = new IriSP.Widget(); IriSP.StackGraphWidget.prototype.draw = function() { - var _ = IriSP._, - _defaultTags = [ - { - "keywords" : [ "++" ], - "description" : "positif", - "color" : "#1D973D" - }, - { - "keywords" : [ "--" ], - "description" : "negatif", - "color" : "#CE0A15" - }, - { - "keywords" : [ "==" ], - "description" : "reference", - "color" : "#C5A62D" - }, - { - "keywords" : [ "??" ], - "description" : "question", - "color" : "#036AAE" - } - ], - _defaultDefColor = "#585858"; + var _ = IriSP._; this.height = this._config.height || 50; this.width = this.selector.width(); - this.isStreamGraph = this._config.streamgraph || false; - this.sliceCount = this._config.slices || ~~(this.width/(this.isStreamGraph ? 20 : 5)); - this.tagconf = (this._config.tags - ? this._config.tags - : _defaultTags); - IriSP._(this.tagconf).each(function(_a) { + this.slices = this._config.slices || ~~(this.width/(this.streamgraph ? 20 : 5)); + _(this.tags).each(function(_a) { _a.regexp = new RegExp(_(_a.keywords).map(function(_k) { return _k.replace(/([\W])/gm,'\\$1'); }).join("|"),"im") }); - this.defaultcolorconf = (this._config.defaultcolor - ? this._config.defaultcolor - : _defaultDefColor); this.paper = new Raphael(this.selector[0], this.width, this.height); this.groups = []; - this.duration = this._serializer.getDuration(); + this.duration = this.getDuration(); var _annotationType = this._serializer.getTweets(), - _sliceDuration = ~~ ( this.duration / this.sliceCount), + _sliceDuration = ~~ ( this.duration / this.slices), _annotations = this._serializer._data.annotations, - _groupedAnnotations = _(_.range(this.sliceCount)).map(function(_i) { + _groupedAnnotations = _(_.range(this.slices)).map(function(_i) { return _(_annotations).filter(function(_a){ return (_a.begin <= (1 + _i) * _sliceDuration) && (_a.end >= _i * _sliceDuration) }); @@ -5213,25 +5233,25 @@ return _g.length }).length, _scale = this.height / _max, - _width = this.width / this.sliceCount, + _width = this.width / this.slices, _showTitle = !this._config.excludeTitle, _showDescription = !this._config.excludeDescription; - var _paths = _(this.tagconf).map(function() { + var _paths = _(this.tags).map(function() { return []; }); _paths.push([]); - for (var i = 0; i < this.sliceCount; i++) { + for (var i = 0; i < this.slices; i++) { var _group = _groupedAnnotations[i]; if (_group) { - var _vol = _(this.tagconf).map(function() { + var _vol = _(this.tags).map(function() { return 0; }); for (var j = 0; j < _group.length; j++){ var _txt = (_showTitle ? _group[j].content.title : '') + ' ' + (_showDescription ? _group[j].content.description : '') - var _tags = _(this.tagconf).map(function(_tag) { + var _tags = _(this.tags).map(function(_tag) { return (_txt.search(_tag.regexp) == -1 ? 0 : 1) }), _nbtags = _(_tags).reduce(function(_a,_b) { @@ -5249,20 +5269,20 @@ _nbneutre = _group.length - _nbtags, _h = _nbneutre * _scale, _base = this.height - _h; - if (!this.isStreamGraph) { + if (!this.streamgraph) { this.paper.rect(i * _width, _base, _width - 1, _h ).attr({ "stroke" : "none", - "fill" : this.defaultcolorconf + "fill" : this.defaultcolor }); } _paths[0].push(_base); - for (var j = 0; j < this.tagconf.length; j++) { + for (var j = 0; j < this.tags.length; j++) { _h = _vol[j] * _scale; _base = _base - _h; - if (!this.isStreamGraph) { + if (!this.streamgraph) { this.paper.rect(i * _width, _base, _width - 1, _h ).attr({ "stroke" : "none", - "fill" : this.tagconf[j].color + "fill" : this.tags[j].color }); } _paths[j+1].push(_base); @@ -5274,13 +5294,13 @@ for (var j = 0; j < _paths.length; j++) { _paths[j].push(this.height); } - this.groups.push(_(this.tagconf).map(function() { + this.groups.push(_(this.tags).map(function() { return 0; })); } } - if (this.isStreamGraph) { + if (this.streamgraph) { for (var j = _paths.length - 1; j >= 0; j--) { var _d = _(_paths[j]).reduce(function(_memo, _v, _k) { return _memo + ( _k @@ -5289,7 +5309,7 @@ },'') + 'L' + this.width + ' ' + _paths[j][_paths[j].length - 1] + 'L' + this.width + ' ' + this.height + 'L0 ' + this.height; this.paper.path(_d).attr({ "stroke" : "none", - "fill" : (j ? this.tagconf[j-1].color : this.defaultcolorconf) + "fill" : (j ? this.tags[j-1].color : this.defaultcolor) }); } } @@ -5315,7 +5335,7 @@ _this.updateTooltip(_e); // Trace var relX = _e.pageX - _this.selector.offset().left; - var _duration = _this._serializer.getDuration(); + var _duration = _this.getDuration(); var _time = parseInt((relX / _this.width) * _duration); _this._Popcorn.trigger("IriSP.TraceWidget.MouseEvents", { "widget" : "StackGraphWidget", @@ -5356,10 +5376,10 @@ }; IriSP.StackGraphWidget.prototype.updateTooltip = function(event) { - var _segment = Math.max(0,Math.min(this.groups.length - 1, 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.slices * (event.pageX - this.selector.offset().left)/this.width))), _valeurs = this.groups[_segment], - _width = this.width / this.sliceCount, - _html = '