# HG changeset patch # User hamidouk # Date 1326724926 -3600 # Node ID db8697ff4594d7b7df8ca03e073671591d4d5a5b # Parent bfea870f9eb9dad1c7f7c6536c9089c6f6427c64# Parent 47735d0bedb58f9773eecefd700afa2d27d059f7 Merge with upstream diff -r 47735d0bedb5 -r db8697ff4594 src/ldt/ldt/static/ldt/js/LdtPlayer-release.js --- a/src/ldt/ldt/static/ldt/js/LdtPlayer-release.js Mon Jan 16 15:39:17 2012 +0100 +++ b/src/ldt/ldt/static/ldt/js/LdtPlayer-release.js Mon Jan 16 15:42:06 2012 +0100 @@ -1404,16 +1404,14 @@ // conversion de couleur Decimal vers HexaDecimal || 000 si fff IriSP.DEC_HEXA_COLOR = function (dec) { - var hexa='0123456789ABCDEF'; - var hex=''; - var tmp; - while (dec>15){ - tmp = dec-(Math.floor(dec/16))*16; - hex = hexa.charAt(tmp)+hex; - dec = Math.floor(dec/16); - } - hex = hexa.charAt(dec)+hex; - return(hex); + var val = +dec; + var str = val.toString(16); + var zeroes = ""; + if (str.length < 6) { + for (var i = 0; i < 6 - str.length; i++) + zeroes += "0"; + } + return zeroes + str; }; /* shortcut to have global variables in templates */ @@ -1451,6 +1449,10 @@ return ""; }; +/** test if a value is null or undefined */ +IriSP.null_or_undefined = function(val) { + return (typeof(val) === "undefined" || val === null); +} /* for ie compatibility if (Object.prototype.__defineGetter__&&!Object.defineProperty) { Object.defineProperty=function(obj,prop,desc) { @@ -1984,19 +1986,18 @@ opts.streamer = ""; var fullPath = IriSP.__jsonMetadata["medias"][0]["href"]; var pathSplit = fullPath.split('/'); - console.log(pathSplit); for (var i = 0; i < pathSplit.length; i++) { if (i < 4) { opts.streamer += pathSplit[i] + "/"; } else { opts.file += pathSplit[i]; + /* omit the last slash if we're on the last element */ if (i < pathSplit.length - 1) opts.file += "/"; } } - - console.log(opts.file); + } else { /* other providers type, video for instance - pass everything as is */ @@ -3534,9 +3535,9 @@ this.selector.append(Mustache.to_html(IriSP.overlay_marker_template)); var view_type = this._serializer.getChapitrage(); - if (typeof(view_type) === "undefined") - view_type = this._serializer.getNonTweetIds()[0]; - + if (typeof(view_type) === "undefined") { + view_type = this._serializer.getNonTweetIds()[0]; + } this.positionMarker = this.selector.children(":first"); this._Popcorn.listen("timeupdate", IriSP.wrap(this, this.positionUpdater)); @@ -3588,8 +3589,10 @@ var hexa_color = IriSP.DEC_HEXA_COLOR(color); + /* if (hexa_color === "FFCC00") hexa_color = "333"; + */ if (hexa_color.length == 4) hexa_color = hexa_color + '00'; @@ -4530,36 +4533,89 @@ /** returns a list of ids of tweet lines (aka: groups in cinelab) */ IriSP.JSONSerializer.prototype.getTweetIds = function() { - if (typeof(this._data.lists) === "undefined" || this._data.lists === null) + if (IriSP.null_or_undefined(this._data.lists) || IriSP.null_or_undefined(this._data.lists) || + IriSP.null_or_undefined(this._data.views) || IriSP.null_or_undefined(this._data.views[0])) return []; - var tweetsId = []; - /* first get the list containing the tweets */ - var tweets = IriSP.underscore.filter(this._data.lists, function(entry) { return entry.id.indexOf("tweet") !== -1 }); + /* Get the displayable types + We've got to jump through a few hoops because the json sometimes defines + fields with underscores and sometimes with dashes + */ + var annotation_types = this._data.views[0]["annotation_types"]; + if (IriSP.null_or_undefined(annotation_types)) { + annotation_types = this._data.views[0]["annotation-types"]; + if (IriSP.null_or_undefined(annotation_types)) { + console.log("neither view.annotation_types nor view.annotation-types are defined"); + return; + } + } + + var available_types = this._data["annotation_types"]; + if (IriSP.null_or_undefined(available_types)) { + available_types = this._data["annotation-types"]; + if (IriSP.null_or_undefined(available_types)) { + console.log("neither annotation_types nor annotation-types are defined"); + return; + } + } - if (tweets.length === 0) - return []; + var potential_types = []; - // FIXME: collect tweets from multiple sources ? - tweetsId = IriSP.underscore.pluck(tweets[0].items, "id-ref"); - + // Get the list of types which contain "Tw" in their content + for (var i = 0; i < available_types.length; i++) { + if (/Tw/i.test(available_types[i]["dc:title"])) { + potential_types.push(available_types[i].id); + } + } + + // Get the intersection of both. + var tweetsId = IriSP.underscore.intersection(annotation_types, potential_types); + return tweetsId; }; /** this function returns a list of lines which are not tweet lines */ IriSP.JSONSerializer.prototype.getNonTweetIds = function() { - if (typeof(this._data.lists) === "undefined" || this._data.lists === null) + if (IriSP.null_or_undefined(this._data.lists) || IriSP.null_or_undefined(this._data.lists) || + IriSP.null_or_undefined(this._data.views) || IriSP.null_or_undefined(this._data.views[0])) return []; - - /* complicated : for each list in this._data.lists, get the id-ref. - flatten the returned array because pluck returns a string afterwards. + + /* Get the displayable types + We've got to jump through a few hoops because the json sometimes defines + fields with underscores and sometimes with dashes */ - var ids = IriSP.underscore.flatten(IriSP.underscore.map(this._data.lists, function(entry) { - return IriSP.underscore.pluck(entry.items, "id-ref"); })); - - var illegal_values = this.getTweetIds(); - return IriSP.underscore.difference(ids, illegal_values); + var annotation_types = this._data.views[0]["annotation_types"]; + if (IriSP.null_or_undefined(annotation_types)) { + annotation_types = this._data.views[0]["annotation-types"]; + if (IriSP.null_or_undefined(annotation_types)) { + console.log("neither view.annotation_types nor view.annotation-types are defined"); + return; + } + } + + var available_types = this._data["annotation_types"]; + if (IriSP.null_or_undefined(available_types)) { + available_types = this._data["annotation-types"]; + if (IriSP.null_or_undefined(available_types)) { + console.log("neither annotation_types nor annotation-types are defined"); + return; + } + } + + var potential_types = []; + + // Get the list of types which do not contain "Tw" in their content + for (var i = 0; i < available_types.length; i++) { + if (!(/Tw/i.test(available_types[i]["dc:title"]))) { + potential_types.push(available_types[i].id); + } + } + + // Get the intersection of both. + var nonTweetsId = IriSP.underscore.intersection(annotation_types, potential_types); + + return nonTweetsId; }; @@ -4585,7 +4641,15 @@ /** return the id of the ligne de temps named "Chapitrage" */ IriSP.JSONSerializer.prototype.getChapitrage = function() { - return this.getId("Chapitrage"); + var val = this.getId("Chapitrage"); + if (typeof(val) === "undefined") + val = this.getId("Chapter"); + if (typeof(val) === "undefined") + val = this.getId("Chapit"); + if (typeof(val) === "undefined") + val = this.getId("Chap"); + + return val; }; /** return the id of the ligne de temps named "Tweets" */ @@ -4605,5 +4669,13 @@ /** return the id of the ligne de temps named "Contributions" */ IriSP.JSONSerializer.prototype.getContributions = function() { - return this.getId("Contributions"); + var val = this.getId("Contribution"); + if (typeof(val) === "undefined") + val = this.getId("Particip"); + if (typeof(val) === "undefined") + val = this.getId("Contr"); + if (typeof(val) === "undefined") + val = this.getId("Publ"); + + return val; }; \ No newline at end of file