1259 /** test if a value is null or undefined */ |
1259 /** test if a value is null or undefined */ |
1260 IriSP.null_or_undefined = function(val) { |
1260 IriSP.null_or_undefined = function(val) { |
1261 return (typeof(val) === "undefined" || val === null); |
1261 return (typeof(val) === "undefined" || val === null); |
1262 }; |
1262 }; |
1263 |
1263 |
|
1264 /** get a property that can have multiple names **/ |
|
1265 |
|
1266 IriSP.get_aliased = function(_obj, _aliases) { |
|
1267 for (var _i = 0; _i < _aliases.length; _i++) { |
|
1268 if (typeof _obj[_aliases[_i]] !== "undefined") { |
|
1269 return _obj[_aliases[_i]]; |
|
1270 } |
|
1271 } |
|
1272 return null; |
|
1273 } |
|
1274 |
1264 /** issue a call to an url shortener and return the shortened url */ |
1275 /** issue a call to an url shortener and return the shortened url */ |
1265 IriSP.shorten_url = function(url) { |
1276 IriSP.shorten_url = function(url) { |
1266 if (IriSP.config.shortener.hasOwnProperty("shortening_function")) |
1277 if (IriSP.config.shortener.hasOwnProperty("shortening_function")) |
1267 return IriSP.config.shortener.shortening_function(url); |
1278 return IriSP.config.shortener.shortening_function(url); |
1268 |
1279 |
1623 /* We need to define those so that the individual settings can be overwritten */ |
1634 /* We need to define those so that the individual settings can be overwritten */ |
1624 IriSP.widgetsDefaults = {}; |
1635 IriSP.widgetsDefaults = {}; |
1625 |
1636 |
1626 IriSP.paths = {}; |
1637 IriSP.paths = {}; |
1627 |
1638 |
1628 IriSP.libdir = "/metadataplayer/src/js/libs/"; |
1639 IriSP.libdir = "js/libs/"; |
1629 IriSP.jwplayer_swf_path = "/metadataplayer/test/libs/player.swf"; |
1640 IriSP.jwplayer_swf_path = "../test/libs/player.swf"; |
1630 IriSP.platform_url = "http://localhost/pf"; |
1641 IriSP.platform_url = "http://192.168.56.101/pf"; |
1631 IriSP.default_templates_vars = { }; |
1642 IriSP.default_templates_vars = { }; |
1632 |
1643 |
1633 /** ugly ugly ugly ugly - returns an object defining |
1644 /** ugly ugly ugly ugly - returns an object defining |
1634 the paths to the libs |
1645 the paths to the libs |
1635 We need it that way cause it's called at runtime by |
1646 We need it that way cause it's called at runtime by |
1694 /* polemics - the corresponding class names defined in the css should be for instance : |
1705 /* polemics - the corresponding class names defined in the css should be for instance : |
1695 Ldt-createAnnotation-polemic-plusplus for plusplus |
1706 Ldt-createAnnotation-polemic-plusplus for plusplus |
1696 Ldt-createAnnotation-polemic-equalequal for equalequal, etc. |
1707 Ldt-createAnnotation-polemic-equalequal for equalequal, etc. |
1697 */ |
1708 */ |
1698 polemics: {"++" : "positive", "--" : "negative", "==" : "reference", "??" : "question"}, |
1709 polemics: {"++" : "positive", "--" : "negative", "==" : "reference", "??" : "question"}, |
1699 cinecast_version: true /* put to false to enable the platform version, true for the festival cinecast one. */ |
1710 cinecast_version: true, /* put to false to enable the platform version, true for the festival cinecast one. */ |
|
1711 |
|
1712 /* where does the widget PUT the annotations - this is a mustache template. id refers to the id of the media ans is filled |
|
1713 by the widget. |
|
1714 */ |
|
1715 api_endpoint_template: platform_url + "/ldtplatform/api/ldt/annotations/{{id}}.json" |
1700 }, |
1716 }, |
1701 "SparklineWidget" : { |
1717 "SparklineWidget" : { |
1702 column_width: 10 // the width of a column in pixels. |
1718 column_width: 10 // the width of a column in pixels. |
1703 }, |
1719 }, |
1704 "Main" : { |
1720 "Main" : { |
1726 }; |
1742 }; |
1727 |
1743 |
1728 /* |
1744 /* |
1729 Override this if you want to change the info the player receives about the user. |
1745 Override this if you want to change the info the player receives about the user. |
1730 It's typically overrided in server-side templates with user-specific data. |
1746 It's typically overrided in server-side templates with user-specific data. |
1731 |
|
1732 IriSP.user = { |
|
1733 "name" : "loic", |
|
1734 "avatar" : "http://a1.twimg.com/profile_images/39270812/loicempuria_normal.jpg" |
|
1735 }; |
|
1736 */ |
1747 */ |
|
1748 IriSP.defaults.user = function() { return { |
|
1749 "name" : "Anonymous user", |
|
1750 "avatar" : IriSP.paths.imgs + "/user_default_icon.png" |
|
1751 } |
|
1752 }; |
|
1753 |
1737 |
1754 |
1738 IriSP.defaults.paths = { |
1755 IriSP.defaults.paths = { |
1739 // "imgs": "/tweetlive/res/metadataplayer/src/css/imgs" |
1756 // "imgs": "/tweetlive/res/metadataplayer/src/css/imgs" |
1740 "imgs": "/metadataplayer/src/css/imgs" |
1757 "imgs": "/metadataplayer/src/css/imgs" |
1741 }; |
1758 }; |
1977 as a streamer is of the form rtmp://domain/path/ and the media is |
1994 as a streamer is of the form rtmp://domain/path/ and the media is |
1978 the rest, we uglily do this : |
1995 the rest, we uglily do this : |
1979 */ |
1996 */ |
1980 opts.file = ""; |
1997 opts.file = ""; |
1981 opts.streamer = ""; |
1998 opts.streamer = ""; |
1982 var fullPath = IriSP.__jsonMetadata["medias"][0]["href"]; |
1999 var fullPath = IriSP.get_aliased(IriSP.__jsonMetadata["medias"][0], ["href","url"]); |
1983 |
2000 |
1984 /* files can either use href or url to refer to the stream */ |
2001 if (fullPath === null) { |
1985 if (IriSP.null_or_undefined(fullPath)) { |
|
1986 fullPath = IriSP.__jsonMetadata["medias"][0]["url"]; |
|
1987 } |
|
1988 |
|
1989 if (IriSP.null_or_undefined(fullPath)) { |
|
1990 console.log("no url or href field defined in the metadata."); |
2002 console.log("no url or href field defined in the metadata."); |
1991 } |
2003 } |
1992 |
2004 |
1993 var pathSplit = fullPath.split('/'); |
2005 var pathSplit = fullPath.split('/'); |
1994 |
2006 |
2193 };/* To wrap a player the develop should create a new class derived from |
2205 };/* To wrap a player the develop should create a new class derived from |
2194 the IriSP.PopcornReplacement.player and defining the correct functions */ |
2206 the IriSP.PopcornReplacement.player and defining the correct functions */ |
2195 |
2207 |
2196 /** allocine player wrapper */ |
2208 /** allocine player wrapper */ |
2197 IriSP.PopcornReplacement.allocine = function(container, options) { |
2209 IriSP.PopcornReplacement.allocine = function(container, options) { |
2198 console.log("Calling allocine player"); |
2210 // console.log("Calling allocine player"); |
2199 /* appel du parent pour initialiser les structures communes à tous les players */ |
2211 /* appel du parent pour initialiser les structures communes à tous les players */ |
2200 IriSP.PopcornReplacement.player.call(this, container, options); |
2212 IriSP.PopcornReplacement.player.call(this, container, options); |
2201 |
2213 |
2202 var _this = this; |
2214 var _this = this; |
2203 |
2215 |
2204 /* Définition des fonctions de l'API - */ |
2216 /* Définition des fonctions de l'API - */ |
2205 |
2217 |
2206 this.playerFns = { |
2218 this.playerFns = { |
2207 play : function() { |
2219 play : function() { |
2208 if (_this.player) { |
2220 if (_this.player) { |
2209 console.log("ask play _this.player = " + _this.player); |
2221 // console.log("ask play _this.player = " + _this.player); |
2210 return _this.player.sendToActionScript("play"); |
2222 return _this.player.sendToActionScript("play"); |
2211 } else { |
2223 } else { |
2212 return false; |
2224 return false; |
2213 } |
2225 } |
2214 }, |
2226 }, |
2215 pause : function() { |
2227 pause : function() { |
2216 if (_this.player) { |
2228 if (_this.player) { |
2217 console.log("ask pause _this.player = " + _this.player); |
2229 // console.log("ask pause _this.player = " + _this.player); |
2218 return _this.player.sendToActionScript("pause"); |
2230 return _this.player.sendToActionScript("pause"); |
2219 } else { |
2231 } else { |
2220 return false; |
2232 return false; |
2221 } |
2233 } |
2222 }, |
2234 }, |
2253 |
2265 |
2254 window.onReady = IriSP.wrap(this, this.ready); |
2266 window.onReady = IriSP.wrap(this, this.ready); |
2255 //NOT CALLED window.onAllocineStateChange = IriSP.wrap(this, this.stateHandler); |
2267 //NOT CALLED window.onAllocineStateChange = IriSP.wrap(this, this.stateHandler); |
2256 window.onTime = IriSP.wrap(this, this.progressHandler); |
2268 window.onTime = IriSP.wrap(this, this.progressHandler); |
2257 |
2269 |
2258 var fv = "adVast=false&lg=fr_cinecast&autoPlay="+options.autoPlay+"&directVideoTitle= &urlAcData="+options.urlAcData+"&directVideoPath="+options.directVideoPath+"&host=http://allocine.fr"; |
2270 var _videoUrl = ( |
2259 console.log("fv = " + fv); |
2271 typeof options.directVideoPath == "string" |
|
2272 ? options.directVideoPath |
|
2273 : IriSP.get_aliased(IriSP.__jsonMetadata["medias"][0], ["href","url"]) |
|
2274 ); |
|
2275 |
|
2276 var fv = "streamFMS=true&adVast=false&lg=fr_cinecast&autoPlay=" + options.autoPlay + "&directVideoTitle=&urlAcData=" + options.urlAcData + "&directVideoPath=" + _videoUrl + "&host=http://allocine.fr"; |
|
2277 // console.log("fv = " + fv); |
2260 |
2278 |
2261 var params = { |
2279 var params = { |
2262 "allowScriptAccess" : "always", |
2280 "allowScriptAccess" : "always", |
2263 "wmode": "opaque", |
2281 "wmode": "opaque", |
2264 "flashvars" : fv |
2282 "flashvars" : fv |
2706 */ |
2724 */ |
2707 |
2725 |
2708 var platf_url = IriSP.widgetsDefaults["AnnotationsListWidget"].ajax_url |
2726 var platf_url = IriSP.widgetsDefaults["AnnotationsListWidget"].ajax_url |
2709 .replace(/\{/g, '{{').replace(/\}/g, '}}'); |
2727 .replace(/\{/g, '{{').replace(/\}/g, '}}'); |
2710 var media_id = this._serializer.currentMedia()["id"]; |
2728 var media_id = this._serializer.currentMedia()["id"]; |
2711 var duration = +this._serializer.currentMedia().meta["dc:duration"]; |
2729 var duration = this._serializer.getDuration(); |
2712 |
2730 |
2713 var begin_timecode = (Math.floor(tcode) - 300) * 1000; |
2731 var begin_timecode = (Math.floor(tcode) - 300) * 1000; |
2714 if (begin_timecode < 0) |
2732 if (begin_timecode < 0) |
2715 begin_timecode = 0; |
2733 begin_timecode = 0; |
2716 |
2734 |
2827 var title = annotation.content.title; |
2845 var title = annotation.content.title; |
2828 var description = annotation.content.description; |
2846 var description = annotation.content.description; |
2829 var keywords = ""; |
2847 var keywords = ""; |
2830 var begin = +annotation.begin / 1000; |
2848 var begin = +annotation.begin / 1000; |
2831 var end = +annotation.end / 1000; |
2849 var end = +annotation.end / 1000; |
2832 var duration = +this._serializer.currentMedia().meta["dc:duration"]; |
2850 var duration = this._serializer.getDuration(); |
2833 var tags = ""; |
2851 var tags = ""; |
2834 |
2852 |
2835 var title_templ = "{{title}} - ( {{begin}} - {{end}} )"; |
2853 var title_templ = "{{title}} - ( {{begin}} - {{end}} )"; |
2836 var endstr = Mustache.to_html(title_templ, {title: title, begin: IriSP.secondsToTime(begin), end: IriSP.secondsToTime(end)}); |
2854 var endstr = Mustache.to_html(title_templ, {title: title, begin: IriSP.secondsToTime(begin), end: IriSP.secondsToTime(end)}); |
2837 |
2855 |
2842 if (!IriSP.null_or_undefined(annotation.tags) && !IriSP.null_or_undefined(this._serializer._data.tags)) { |
2860 if (!IriSP.null_or_undefined(annotation.tags) && !IriSP.null_or_undefined(this._serializer._data.tags)) { |
2843 /* save the tag id and keywords in a unique structure */ |
2861 /* save the tag id and keywords in a unique structure */ |
2844 var tag_list = {}; |
2862 var tag_list = {}; |
2845 for (var i = 0; i < this._serializer._data.tags.length; i++) { |
2863 for (var i = 0; i < this._serializer._data.tags.length; i++) { |
2846 var id = this._serializer._data.tags[i]["id"]; |
2864 var id = this._serializer._data.tags[i]["id"]; |
2847 var keyword = this._serializer._data.tags[i]["meta"]["dc:title"]; |
2865 var keyword = IriSP.get_aliased(this._serializer._data.tags[i]["meta"], ["dc:title", "title"]); |
2848 |
2866 |
2849 tag_list[id] = keyword; |
2867 tag_list[id] = keyword; |
2850 } |
2868 } |
2851 |
2869 |
2852 /* then browse the list of defined tags for the current annotation */ |
2870 /* then browse the list of defined tags for the current annotation */ |
2981 /* move the arrow only if the current annotation changes */ |
2999 /* move the arrow only if the current annotation changes */ |
2982 if (currentAnnotation != this._oldAnnotation) { |
3000 if (currentAnnotation != this._oldAnnotation) { |
2983 var begin = (+ currentAnnotation.begin) / 1000; |
3001 var begin = (+ currentAnnotation.begin) / 1000; |
2984 var end = (+ currentAnnotation.end) / 1000; |
3002 var end = (+ currentAnnotation.end) / 1000; |
2985 |
3003 |
2986 var duration = +this._serializer.currentMedia().meta["dc:duration"] / 1000; |
3004 var duration = this._serializer.getDuration() / 1000; |
2987 var middle_time = (begin + end) / 2; |
3005 var middle_time = (begin + end) / 2; |
2988 var percents = middle_time / duration; |
3006 var percents = middle_time / duration; |
2989 |
3007 |
2990 // we need to apply a fix because the arrow has a certain length |
3008 // we need to apply a fix because the arrow has a certain length |
2991 // it's half the length of the arrow (27 / 2). We need to convert |
3009 // it's half the length of the arrow (27 / 2). We need to convert |
3229 var currentTime = this._Popcorn.currentTime(); |
3247 var currentTime = this._Popcorn.currentTime(); |
3230 |
3248 |
3231 // block the arrow. |
3249 // block the arrow. |
3232 this._Popcorn.trigger("IriSP.ArrowWidget.blockArrow"); |
3250 this._Popcorn.trigger("IriSP.ArrowWidget.blockArrow"); |
3233 |
3251 |
3234 var duration = +this._serializer.currentMedia().meta["dc:duration"]; |
3252 var duration = this._serializer.getDuration(); |
3235 |
3253 |
3236 var currentChapter = this._serializer.currentChapitre(currentTime); |
3254 var currentChapter = this._serializer.currentChapitre(currentTime); |
3237 |
3255 |
3238 if (IriSP.null_or_undefined(currentChapter)) { |
3256 if (IriSP.null_or_undefined(currentChapter)) { |
3239 var left = this.selector.width() / 2; |
3257 var left = this.selector.width() / 2; |
3408 var _this = this; |
3426 var _this = this; |
3409 var apiJson = {annotations : [{}], meta: {}}; |
3427 var apiJson = {annotations : [{}], meta: {}}; |
3410 var annotation = apiJson["annotations"][0]; |
3428 var annotation = apiJson["annotations"][0]; |
3411 |
3429 |
3412 annotation["media"] = this._serializer.currentMedia()["id"]; |
3430 annotation["media"] = this._serializer.currentMedia()["id"]; |
3413 var duration_part = Math.round(this._serializer.currentMedia().meta["dc:duration"] / 20); |
3431 var duration_part = Math.round(this._serializer.getDuration() / 20); |
3414 |
3432 |
3415 if (this.cinecast_version) { |
3433 if (this.cinecast_version) { |
3416 annotation["begin"] = Math.round(this._Popcorn.currentTime() * 1000 - duration_part); |
3434 annotation["begin"] = Math.round(this._Popcorn.currentTime() * 1000 - duration_part); |
3417 annotation["end"] = Math.round(this._Popcorn.currentTime() * 1000 + duration_part); |
3435 annotation["end"] = Math.round(this._Popcorn.currentTime() * 1000 + duration_part); |
3418 } else { |
3436 } else { |
3419 var duration = +this._serializer.currentMedia().meta["dc:duration"]; |
3437 var duration = this._serializer.getDuration(); |
3420 annotation["begin"] = +((duration * (this.sliceLeft / 100)).toFixed(0)); |
3438 annotation["begin"] = +((duration * (this.sliceLeft / 100)).toFixed(0)); |
3421 annotation["end"] = +((duration * ((this.sliceWidth + this.sliceLeft) / 100)).toFixed(0)); |
3439 annotation["end"] = +((duration * ((this.sliceWidth + this.sliceLeft) / 100)).toFixed(0)); |
3422 } |
3440 } |
3423 |
3441 |
3424 // boundary checks |
3442 // boundary checks |
3425 if (annotation["begin"] < 0) |
3443 if (annotation["begin"] < 0) |
3426 annotation["begin"] = 0; |
3444 annotation["begin"] = 0; |
3427 |
3445 |
3428 if (annotation["end"] > this._serializer.currentMedia().meta["dc:duration"]) |
3446 if (annotation["end"] > this._serializer.getDuration()) |
3429 annotation["end"] = this._serializer.currentMedia().meta["dc:duration"]; |
3447 annotation["end"] = this._serializer.getDuration(); |
3430 |
3448 |
3431 |
3449 |
3432 annotation["type"] = this._serializer.getContributions(); |
3450 annotation["type"] = this._serializer.getContributions(); |
3433 if (typeof(annotation["type"]) === "undefined") |
3451 if (typeof(annotation["type"]) === "undefined") |
3434 annotation["type"] = ""; |
3452 annotation["type"] = ""; |
3473 if (typeof(this._serializer.getContributions()) === "undefined") { |
3491 if (typeof(this._serializer.getContributions()) === "undefined") { |
3474 /* set up a basic view */ |
3492 /* set up a basic view */ |
3475 var tmp_view = {"dc:contributor": "perso", "dc:creator": "perso", "dc:title": "Contributions", |
3493 var tmp_view = {"dc:contributor": "perso", "dc:creator": "perso", "dc:title": "Contributions", |
3476 "id": json.annotations[0].type} |
3494 "id": json.annotations[0].type} |
3477 |
3495 |
3478 this._serializer._data["annotation-types"].push(tmp_view); |
3496 |
|
3497 IriSP.get_aliased(this._serializer._data, ["annotation_types", "annotation-types"]).push(tmp_view); |
3479 } |
3498 } |
3480 |
3499 |
3481 delete annotation.tags; |
3500 delete annotation.tags; |
3482 annotation.content.description = annotation.content.data; |
3501 annotation.content.description = annotation.content.data; |
3483 annotation.content.title = ""; |
3502 annotation.content.title = ""; |
3584 return; |
3603 return; |
3585 |
3604 |
3586 } |
3605 } |
3587 |
3606 |
3588 // we get it at each call because it may change. |
3607 // we get it at each call because it may change. |
3589 var duration = +this._serializer.currentMedia().meta["dc:duration"] / 1000; |
3608 var duration = this._serializer.getDuration() / 1000; |
3590 var totalTime = IriSP.secondsToTime(duration); |
3609 var totalTime = IriSP.secondsToTime(duration); |
3591 var elapsedTime = IriSP.secondsToTime(this._Popcorn.currentTime()); |
3610 var elapsedTime = IriSP.secondsToTime(this._Popcorn.currentTime()); |
3592 |
3611 |
3593 this.selector.find(".Ldt-ElapsedTime").html(elapsedTime.toString()); |
3612 this.selector.find(".Ldt-ElapsedTime").html(elapsedTime.toString()); |
3594 this.selector.find(".Ldt-TotalTime").html(totalTime.toString()); |
3613 this.selector.find(".Ldt-TotalTime").html(totalTime.toString()); |
3789 var frameSize = 5; // frame size |
3808 var frameSize = 5; // frame size |
3790 var margin = 1; // marge between frame |
3809 var margin = 1; // marge between frame |
3791 var lineSize = this.width; // timeline pixel width |
3810 var lineSize = this.width; // timeline pixel width |
3792 var nbrframes = lineSize/frameSize; // frame numbers |
3811 var nbrframes = lineSize/frameSize; // frame numbers |
3793 var numberOfTweet = 0; // number of tweet overide later |
3812 var numberOfTweet = 0; // number of tweet overide later |
3794 var duration = +this._serializer.currentMedia().meta["dc:duration"]; // timescale width |
3813 var duration = this._serializer.getDuration(); // timescale width |
3795 var frameLength = lineSize / frameSize; // frame timescale |
3814 var frameLength = lineSize / frameSize; // frame timescale |
3796 var timeline; |
3815 var timeline; |
3797 var colors = new Array("","#1D973D","#C5A62D","#CE0A15","#036AAE","#585858"); |
3816 var colors = new Array("","#1D973D","#C5A62D","#CE0A15","#036AAE","#585858"); |
3798 |
3817 |
3799 // array |
3818 // array |
3909 |
3928 |
3910 if (typeof(item.meta) !== "undefined" |
3929 if (typeof(item.meta) !== "undefined" |
3911 && typeof(item.meta["id-ref"]) !== "undefined" |
3930 && typeof(item.meta["id-ref"]) !== "undefined" |
3912 && item.meta["id-ref"] === view_type) { |
3931 && item.meta["id-ref"] === view_type) { |
3913 |
3932 |
3914 var MyTJson = {}; |
3933 var MyTJson = {}, |
3915 if (typeof(item.meta['dc:source']) !== "undefined") { |
3934 _source = IriSP.get_aliased(item.meta, ['dc:source', 'source']); |
3916 var MyTJson = JSON.parse(item.meta['dc:source']['content']); |
3935 if (_source !== null) { |
|
3936 var MyTJson = JSON.parse(_source['content']); |
3917 } |
3937 } |
3918 |
3938 |
3919 if (item.content['polemics'] != undefined |
3939 if (item.content['polemics'] != undefined |
3920 && item.content['polemics'][0] != null) { |
3940 && item.content['polemics'][0] != null) { |
3921 |
3941 |
4119 |
4139 |
4120 /** update the positionMarker as time passes */ |
4140 /** update the positionMarker as time passes */ |
4121 IriSP.PolemicWidget.prototype.sliderUpdater = function() { |
4141 IriSP.PolemicWidget.prototype.sliderUpdater = function() { |
4122 |
4142 |
4123 var time = +this._Popcorn.currentTime(); |
4143 var time = +this._Popcorn.currentTime(); |
4124 var duration = +this._serializer.currentMedia().meta["dc:duration"]; |
4144 var duration = this._serializer.getDuration(); |
4125 |
4145 |
4126 this.paperSlider.attr("width", time * (this.width / (duration / 1000))); |
4146 this.paperSlider.attr("width", time * (this.width / (duration / 1000))); |
4127 |
4147 |
4128 this.sliderTip.attr("x", time * (this.width / (duration / 1000))); |
4148 this.sliderTip.attr("x", time * (this.width / (duration / 1000))); |
4129 }; |
4149 }; |
4198 |
4218 |
4199 /* Get the width of a segment, in pixels. */ |
4219 /* Get the width of a segment, in pixels. */ |
4200 IriSP.SegmentsWidget.prototype.segmentToPixel = function(annotation) { |
4220 IriSP.SegmentsWidget.prototype.segmentToPixel = function(annotation) { |
4201 var begin = Math.round((+ annotation.begin) / 1000); |
4221 var begin = Math.round((+ annotation.begin) / 1000); |
4202 var end = Math.round((+ annotation.end) / 1000); |
4222 var end = Math.round((+ annotation.end) / 1000); |
4203 var duration = this._serializer.currentMedia().meta["dc:duration"] / 1000; |
4223 var duration = this._serializer.getDuration() / 1000; |
4204 |
4224 |
4205 var startPourcent = IriSP.timeToPourcent(begin, duration); |
4225 var startPourcent = IriSP.timeToPourcent(begin, duration); |
4206 var startPixel = Math.floor(this.selector.parent().width() * (startPourcent / 100)); |
4226 var startPixel = Math.floor(this.selector.parent().width() * (startPourcent / 100)); |
4207 |
4227 |
4208 var endPourcent = Math.floor(IriSP.timeToPourcent(end, duration) - startPourcent); |
4228 var endPourcent = Math.floor(IriSP.timeToPourcent(end, duration) - startPourcent); |
4261 for (i = 0; i < segments_annotations.length; i++) { |
4281 for (i = 0; i < segments_annotations.length; i++) { |
4262 |
4282 |
4263 var annotation = segments_annotations[i]; |
4283 var annotation = segments_annotations[i]; |
4264 var begin = (+ annotation.begin); |
4284 var begin = (+ annotation.begin); |
4265 var end = (+ annotation.end); |
4285 var end = (+ annotation.end); |
4266 var duration = this._serializer.currentMedia().meta["dc:duration"]; |
4286 var duration = this._serializer.getDuration(); |
4267 var id = annotation.id; |
4287 var id = annotation.id; |
4268 |
4288 |
4269 var startPixel = Math.floor(this.selector.parent().width() * (begin / duration)); |
4289 var startPixel = Math.floor(this.selector.parent().width() * (begin / duration)); |
4270 |
4290 |
4271 var endPixel = Math.floor(this.selector.parent().width() * (end / duration)); |
4291 var endPixel = Math.floor(this.selector.parent().width() * (end / duration)); |
4406 IriSP.SegmentsWidget.prototype.searchFieldClosedHandler = function() { |
4426 IriSP.SegmentsWidget.prototype.searchFieldClosedHandler = function() { |
4407 this.clear(); |
4427 this.clear(); |
4408 }; |
4428 }; |
4409 |
4429 |
4410 IriSP.SegmentsWidget.prototype.positionUpdater = function() { |
4430 IriSP.SegmentsWidget.prototype.positionUpdater = function() { |
4411 var duration = this._serializer.currentMedia().meta["dc:duration"] / 1000; |
4431 var duration = this._serializer.getDuration() / 1000; |
4412 var time = this._Popcorn.currentTime(); |
4432 var time = this._Popcorn.currentTime(); |
4413 //var position = ((time / duration) * 100).toFixed(2); |
4433 //var position = ((time / duration) * 100).toFixed(2); |
4414 var position = ((time / duration) * 100).toFixed(2); |
4434 var position = ((time / duration) * 100).toFixed(2); |
4415 |
4435 |
4416 this.positionMarker.css("left", position + "%"); |
4436 this.positionMarker.css("left", position + "%"); |
4633 if(this.draggingOngoing || this._disableUpdate) |
4653 if(this.draggingOngoing || this._disableUpdate) |
4634 return; |
4654 return; |
4635 |
4655 |
4636 var time = this._Popcorn.currentTime(); |
4656 var time = this._Popcorn.currentTime(); |
4637 |
4657 |
4638 var duration = this._serializer.currentMedia().meta["dc:duration"] / 1000; |
4658 var duration = this._serializer.getDuration() / 1000; |
4639 var percents = time / duration; |
4659 var percents = time / duration; |
4640 |
4660 |
4641 /* we do these complicated calculations to center exactly |
4661 /* we do these complicated calculations to center exactly |
4642 the position Marker */ |
4662 the position Marker */ |
4643 |
4663 |
4673 |
4693 |
4674 var parentOffset = this.sliderBackground.parent().offset(); |
4694 var parentOffset = this.sliderBackground.parent().offset(); |
4675 var width = this.sliderBackground.width(); |
4695 var width = this.sliderBackground.width(); |
4676 var relX = event.pageX - parentOffset.left; |
4696 var relX = event.pageX - parentOffset.left; |
4677 |
4697 |
4678 var duration = this._serializer.currentMedia().meta["dc:duration"] / 1000; |
4698 var duration = this._serializer.getDuration() / 1000; |
4679 var newTime = ((relX / width) * duration).toFixed(2); |
4699 var newTime = ((relX / width) * duration).toFixed(2); |
4680 |
4700 |
4681 this._Popcorn.currentTime(newTime); |
4701 this._Popcorn.currentTime(newTime); |
4682 }; |
4702 }; |
4683 |
4703 |
4686 IriSP.SliderWidget.prototype.foregroundClickHandler = function(event) { |
4706 IriSP.SliderWidget.prototype.foregroundClickHandler = function(event) { |
4687 var parentOffset = this.sliderForeground.parent().offset(); |
4707 var parentOffset = this.sliderForeground.parent().offset(); |
4688 var width = this.sliderBackground.width(); |
4708 var width = this.sliderBackground.width(); |
4689 var relX = event.pageX - parentOffset.left; |
4709 var relX = event.pageX - parentOffset.left; |
4690 |
4710 |
4691 var duration = this._serializer.currentMedia().meta["dc:duration"] / 1000; |
4711 var duration = this._serializer.getDuration() / 1000; |
4692 var newTime = ((relX / width) * duration).toFixed(2); |
4712 var newTime = ((relX / width) * duration).toFixed(2); |
4693 |
4713 |
4694 this._Popcorn.currentTime(newTime); |
4714 this._Popcorn.currentTime(newTime); |
4695 }; |
4715 }; |
4696 |
4716 |
4742 |
4762 |
4743 var parentOffset = this.sliderForeground.parent().offset(); |
4763 var parentOffset = this.sliderForeground.parent().offset(); |
4744 var width = this.sliderBackground.width(); |
4764 var width = this.sliderBackground.width(); |
4745 var relX = event.pageX - parentOffset.left; |
4765 var relX = event.pageX - parentOffset.left; |
4746 |
4766 |
4747 var duration = this._serializer.currentMedia().meta["dc:duration"] / 1000; |
4767 var duration = this._serializer.getDuration() / 1000; |
4748 var newTime = ((relX / width) * duration).toFixed(2); |
4768 var newTime = ((relX / width) * duration).toFixed(2); |
4749 |
4769 |
4750 this._Popcorn.currentTime(newTime); |
4770 this._Popcorn.currentTime(newTime); |
4751 |
4771 |
4752 this.draggingOngoing = false; |
4772 this.draggingOngoing = false; |
4796 console.log("sparklinewidget : using stats embedded in the json"); |
4816 console.log("sparklinewidget : using stats embedded in the json"); |
4797 var results = stat_view.meta.stat.split(","); |
4817 var results = stat_view.meta.stat.split(","); |
4798 } else { |
4818 } else { |
4799 console.log("sparklinewidget : computing stats ourselves"); |
4819 console.log("sparklinewidget : computing stats ourselves"); |
4800 var num_columns = (this.selector.width()) / IriSP.widgetsDefaults["SparklineWidget"].column_width; |
4820 var num_columns = (this.selector.width()) / IriSP.widgetsDefaults["SparklineWidget"].column_width; |
4801 var duration = +this._serializer.currentMedia().meta["dc:duration"]; |
4821 var duration = this._serializer.getDuration(); |
4802 var time_step = duration / num_columns; /* the time interval between two columns */ |
4822 var time_step = duration / num_columns; /* the time interval between two columns */ |
4803 var results = []; |
4823 var results = []; |
4804 var i = 0; /* the index in the loop */ |
4824 var i = 0; /* the index in the loop */ |
4805 |
4825 |
4806 /* this algorithm makes one assumption : that the array is sorted |
4826 /* this algorithm makes one assumption : that the array is sorted |
4843 }; |
4863 }; |
4844 |
4864 |
4845 /** react to a timeupdate event */ |
4865 /** react to a timeupdate event */ |
4846 IriSP.SparklineWidget.prototype.timeUpdateHandler = function() { |
4866 IriSP.SparklineWidget.prototype.timeUpdateHandler = function() { |
4847 var currentTime = this._Popcorn.currentTime(); |
4867 var currentTime = this._Popcorn.currentTime(); |
4848 var duration = +this._serializer.currentMedia().meta["dc:duration"] / 1000; |
4868 var duration = this._serializer.getDuration() / 1000; |
4849 var proportion = ((currentTime / duration) * 100).toFixed(4); |
4869 var proportion = ((currentTime / duration) * 100).toFixed(4); |
4850 |
4870 |
4851 IriSP.jQuery(".Ldt-sparkLinePositionMarker").css("width", proportion + "%"); |
4871 IriSP.jQuery(".Ldt-sparkLinePositionMarker").css("width", proportion + "%"); |
4852 } |
4872 } |
4853 |
4873 |
4863 |
4883 |
4864 var parentOffset = this.selector.offset(); |
4884 var parentOffset = this.selector.offset(); |
4865 var width = this.selector.width(); |
4885 var width = this.selector.width(); |
4866 var relX = event.pageX - parentOffset.left; |
4886 var relX = event.pageX - parentOffset.left; |
4867 |
4887 |
4868 var duration = this._serializer.currentMedia().meta["dc:duration"] / 1000; |
4888 var duration = this._serializer.getDuration() / 1000; |
4869 var newTime = ((relX / width) * duration).toFixed(2); |
4889 var newTime = ((relX / width) * duration).toFixed(2); |
4870 |
4890 |
4871 this._Popcorn.trigger("IriSP.SparklineWidget.clicked", newTime); |
4891 this._Popcorn.trigger("IriSP.SparklineWidget.clicked", newTime); |
4872 this._Popcorn.currentTime(newTime); |
4892 this._Popcorn.currentTime(newTime); |
4873 }; |
4893 }; |
4874 |
4894 |
4875 /** react when a new annotation is added */ |
4895 /** react when a new annotation is added */ |
4876 IriSP.SparklineWidget.prototype.handleNewAnnotation = function(annotation) { |
4896 IriSP.SparklineWidget.prototype.handleNewAnnotation = function(annotation) { |
4877 var num_columns = this._results.length; |
4897 var num_columns = this._results.length; |
4878 var duration = +this._serializer.currentMedia().meta["dc:duration"]; |
4898 var duration = this._serializer.getDuration(); |
4879 var time_step = Math.round(duration / num_columns); /* the time interval between two columns */ |
4899 var time_step = Math.round(duration / num_columns); /* the time interval between two columns */ |
4880 var begin = +annotation.begin; |
4900 var begin = +annotation.begin; |
4881 var end = +annotation.end; |
4901 var end = +annotation.end; |
4882 |
4902 |
4883 /* increment all the values between the beginning and the end of the annotation */ |
4903 /* increment all the values between the beginning and the end of the annotation */ |
4896 } |
4916 } |
4897 |
4917 |
4898 IriSP.StackGraphWidget.prototype = new IriSP.Widget(); |
4918 IriSP.StackGraphWidget.prototype = new IriSP.Widget(); |
4899 |
4919 |
4900 IriSP.StackGraphWidget.prototype.draw = function() { |
4920 IriSP.StackGraphWidget.prototype.draw = function() { |
4901 var _defaultTags = [ |
4921 var _ = IriSP._, |
|
4922 _defaultTags = [ |
4902 { |
4923 { |
4903 "keywords" : [ "++" ], |
4924 "keywords" : [ "++" ], |
4904 "description" : "positif", |
4925 "description" : "positif", |
4905 "color" : "#1D973D" |
4926 "color" : "#1D973D" |
4906 }, |
4927 }, |
4927 this.sliceCount = this._config.slices || ~~(this.width/(this.isStreamGraph ? 20 : 5)); |
4948 this.sliceCount = this._config.slices || ~~(this.width/(this.isStreamGraph ? 20 : 5)); |
4928 this.tagconf = (this._config.tags |
4949 this.tagconf = (this._config.tags |
4929 ? this._config.tags |
4950 ? this._config.tags |
4930 : _defaultTags); |
4951 : _defaultTags); |
4931 IriSP._(this.tagconf).each(function(_a) { |
4952 IriSP._(this.tagconf).each(function(_a) { |
4932 _a.regexp = new RegExp(_a.keywords.map(function(_k) { |
4953 _a.regexp = new RegExp(_(_a.keywords).map(function(_k) { |
4933 return _k.replace(/([\W])/gm,'\\$1'); |
4954 return _k.replace(/([\W])/gm,'\\$1'); |
4934 }).join("|"),"im") |
4955 }).join("|"),"im") |
4935 }); |
4956 }); |
4936 this.defaultcolorconf = (this._config.defaultcolor |
4957 this.defaultcolorconf = (this._config.defaultcolor |
4937 ? this._config.defaultcolor |
4958 ? this._config.defaultcolor |
4938 : _defaultDefColor); |
4959 : _defaultDefColor); |
4939 this.paper = new Raphael(this.selector[0], this.width, this.height); |
4960 this.paper = new Raphael(this.selector[0], this.width, this.height); |
4940 this.groups = []; |
4961 this.groups = []; |
4941 this.duration = this._serializer.currentMedia().meta["dc:duration"]; |
4962 this.duration = this._serializer.getDuration(); |
4942 |
4963 |
4943 var _annotationType = this._serializer.getTweets(), |
4964 var _annotationType = this._serializer.getTweets(), |
4944 _sliceDuration = ~~ ( this.duration / this.sliceCount), |
4965 _sliceDuration = ~~ ( this.duration / this.sliceCount), |
4945 _annotations = this._serializer._data.annotations, |
4966 _annotations = this._serializer._data.annotations, |
4946 _groupedAnnotations = IriSP._.range(this.sliceCount).map(function(_i) { |
4967 _groupedAnnotations = _(_.range(this.sliceCount)).map(function(_i) { |
4947 return _annotations.filter(function(_a){ |
4968 return _(_annotations).filter(function(_a){ |
4948 return (_a.begin <= (1 + _i) * _sliceDuration) && (_a.end >= _i * _sliceDuration) |
4969 return (_a.begin <= (1 + _i) * _sliceDuration) && (_a.end >= _i * _sliceDuration) |
4949 }); |
4970 }); |
4950 }), |
4971 }), |
4951 _max = IriSP._(_groupedAnnotations).max(function(_g) { |
4972 _max = IriSP._(_groupedAnnotations).max(function(_g) { |
4952 return _g.length |
4973 return _g.length |
4955 _width = this.width / this.sliceCount |
4976 _width = this.width / this.sliceCount |
4956 _showTitle = !this._config.excludeTitle, |
4977 _showTitle = !this._config.excludeTitle, |
4957 _showDescription = !this._config.excludeDescription; |
4978 _showDescription = !this._config.excludeDescription; |
4958 |
4979 |
4959 |
4980 |
4960 var _paths = this.tagconf.map(function() { |
4981 var _paths = _(this.tagconf).map(function() { |
4961 return []; |
4982 return []; |
4962 }); |
4983 }); |
4963 _paths.push([]); |
4984 _paths.push([]); |
4964 |
4985 |
4965 for (var i = 0; i < this.sliceCount; i++) { |
4986 for (var i = 0; i < this.sliceCount; i++) { |
4966 var _group = _groupedAnnotations[i]; |
4987 var _group = _groupedAnnotations[i]; |
4967 if (_group) { |
4988 if (_group) { |
4968 var _vol = this.tagconf.map(function() { |
4989 var _vol = _(this.tagconf).map(function() { |
4969 return 0; |
4990 return 0; |
4970 }); |
4991 }); |
4971 for (var j = 0; j < _group.length; j++){ |
4992 for (var j = 0; j < _group.length; j++){ |
4972 var _txt = (_showTitle ? _group[j].content.title : '') + ' ' + (_showDescription ? _group[j].content.description : '') |
4993 var _txt = (_showTitle ? _group[j].content.title : '') + ' ' + (_showDescription ? _group[j].content.description : '') |
4973 var _tags = this.tagconf.map(function(_tag) { |
4994 var _tags = _(this.tagconf).map(function(_tag) { |
4974 return (_txt.search(_tag.regexp) == -1 ? 0 : 1) |
4995 return (_txt.search(_tag.regexp) == -1 ? 0 : 1) |
4975 }), |
4996 }), |
4976 _nbtags = _tags.reduce(function(_a,_b) { |
4997 _nbtags = _(_tags).reduce(function(_a,_b) { |
4977 return _a + _b; |
4998 return _a + _b; |
4978 }, 0); |
4999 }, 0); |
4979 if (_nbtags) { |
5000 if (_nbtags) { |
4980 IriSP._(_tags).each(function(_v, _k) { |
5001 IriSP._(_tags).each(function(_v, _k) { |
4981 _vol[_k] += (_v / _nbtags); |
5002 _vol[_k] += (_v / _nbtags); |
4982 }); |
5003 }); |
4983 } |
5004 } |
4984 } |
5005 } |
4985 var _nbtags = _vol.reduce(function(_a,_b) { |
5006 var _nbtags = _(_vol).reduce(function(_a,_b) { |
4986 return _a + _b; |
5007 return _a + _b; |
4987 }, 0), |
5008 }, 0), |
4988 _nbneutre = _group.length - _nbtags, |
5009 _nbneutre = _group.length - _nbtags, |
4989 _h = _nbneutre * _scale, |
5010 _h = _nbneutre * _scale, |
4990 _base = this.height - _h; |
5011 _base = this.height - _h; |
5004 "fill" : this.tagconf[j].color |
5025 "fill" : this.tagconf[j].color |
5005 }); |
5026 }); |
5006 } |
5027 } |
5007 _paths[j+1].push(_base); |
5028 _paths[j+1].push(_base); |
5008 } |
5029 } |
5009 this.groups.push(_vol.map(function(_v) { |
5030 this.groups.push(_(_vol).map(function(_v) { |
5010 return _v / _group.length; |
5031 return _v / _group.length; |
5011 })) |
5032 })) |
5012 } else { |
5033 } else { |
5013 for (var j = 0; j < _paths.length; j++) { |
5034 for (var j = 0; j < _paths.length; j++) { |
5014 _paths[j].push(this.height); |
5035 _paths[j].push(this.height); |
5015 } |
5036 } |
5016 this.groups.push(this.tagconf.map(function() { |
5037 this.groups.push(_(this.tagconf).map(function() { |
5017 return 0; |
5038 return 0; |
5018 })); |
5039 })); |
5019 } |
5040 } |
5020 } |
5041 } |
5021 |
5042 |
5022 if (this.isStreamGraph) { |
5043 if (this.isStreamGraph) { |
5023 for (var j = _paths.length - 1; j >= 0; j--) { |
5044 for (var j = _paths.length - 1; j >= 0; j--) { |
5024 var _d = _paths[j].reduce(function(_memo, _v, _k) { |
5045 var _d = _(_paths[j]).reduce(function(_memo, _v, _k) { |
5025 return _memo + ( _k |
5046 return _memo + ( _k |
5026 ? 'C' + (_k * _width) + ' ' + _paths[j][_k - 1] + ' ' + (_k * _width) + ' ' + _v + ' ' + ((_k + .5) * _width) + ' ' + _v |
5047 ? 'C' + (_k * _width) + ' ' + _paths[j][_k - 1] + ' ' + (_k * _width) + ' ' + _v + ' ' + ((_k + .5) * _width) + ' ' + _v |
5027 : 'M0 ' + _v + 'L' + (.5*_width) + ' ' + _v ) |
5048 : 'M0 ' + _v + 'L' + (.5*_width) + ' ' + _v ) |
5028 },'') + 'L' + this.width + ' ' + _paths[j][_paths[j].length - 1] + 'L' + this.width + ' ' + this.height + 'L0 ' + this.height; |
5049 },'') + 'L' + this.width + ' ' + _paths[j][_paths[j].length - 1] + 'L' + this.width + ' ' + this.height + 'L0 ' + this.height; |
5029 this.paper.path(_d).attr({ |
5050 this.paper.path(_d).attr({ |
5053 .mousemove(function(event) { |
5074 .mousemove(function(event) { |
5054 _this.updateTooltip(event); |
5075 _this.updateTooltip(event); |
5055 |
5076 |
5056 // Also tell the world where the mouse is hovering. |
5077 // Also tell the world where the mouse is hovering. |
5057 var relX = event.pageX - _this.selector.offset().left; |
5078 var relX = event.pageX - _this.selector.offset().left; |
5058 var duration = _this._serializer.currentMedia().meta["dc:duration"]; |
5079 var duration = _this._serializer.getDuration(); |
5059 var Time = ((relX / _this.width) * duration).toFixed(2); |
5080 var Time = ((relX / _this.width) * duration).toFixed(2); |
5060 _this._Popcorn.trigger("IriSP.StackGraphWidget.mouseOver", Time); |
5081 _this._Popcorn.trigger("IriSP.StackGraphWidget.mouseOver", Time); |
5061 |
5082 |
5062 }) |
5083 }) |
5063 .mouseout(function() { |
5084 .mouseout(function() { |
5091 |
5112 |
5092 IriSP.StackGraphWidget.prototype.updateTooltip = function(event) { |
5113 IriSP.StackGraphWidget.prototype.updateTooltip = function(event) { |
5093 var _segment = ~~(this.sliceCount * (event.pageX - this.selector.offset().left)/this.width), |
5114 var _segment = ~~(this.sliceCount * (event.pageX - this.selector.offset().left)/this.width), |
5094 _valeurs = this.groups[_segment], |
5115 _valeurs = this.groups[_segment], |
5095 _width = this.width / this.sliceCount, |
5116 _width = this.width / this.sliceCount, |
5096 _html = '<ul style="list-style: none; margin: 0; padding: 0;">' + this.tagconf.map(function(_tag, _i) { |
5117 _html = '<ul style="list-style: none; margin: 0; padding: 0;">' + IriSP._(this.tagconf).map(function(_tag, _i) { |
5097 return '<li style="clear: both;"><span style="float: left; width: 10px; height: 10px; margin: 2px; background: ' |
5118 return '<li style="clear: both;"><span style="float: left; width: 10px; height: 10px; margin: 2px; background: ' |
5098 + _tag.color |
5119 + _tag.color |
5099 + ';"></span>' |
5120 + ';"></span>' |
5100 + ~~(100 * _valeurs[_i]) |
5121 + ~~(100 * _valeurs[_i]) |
5101 + '% de ' |
5122 + '% de ' |
5272 } |
5293 } |
5273 |
5294 |
5274 var imageMarkup = IriSP.templToHTML("<img src='{{src}}' alt='user image'></img>", |
5295 var imageMarkup = IriSP.templToHTML("<img src='{{src}}' alt='user image'></img>", |
5275 {src : img}); |
5296 {src : img}); |
5276 |
5297 |
5277 if (typeof(annotation.meta["dc:source"].content) !== "undefined") { |
5298 if (typeof(IriSP.get_aliased(annotation.meta, ["dc:source", "source"]).content) !== "undefined") { |
5278 var tweetContents = JSON.parse(annotation.meta["dc:source"].content); |
5299 var tweetContents = JSON.parse(IriSP.get_aliased(annotation.meta, ["dc:source", "source"]).content); |
5279 var creator = tweetContents.user.screen_name; |
5300 var creator = tweetContents.user.screen_name; |
5280 var real_name = tweetContents.user.name; |
5301 var real_name = tweetContents.user.name; |
5281 |
5302 |
5282 imageMarkup = IriSP.templToHTML("<a href='http://twitter.com/{{creator}}'><img src='{{src}}' alt='user image'></img></a>", |
5303 imageMarkup = IriSP.templToHTML("<a href='http://twitter.com/{{creator}}'><img src='{{src}}' alt='user image'></img></a>", |
5283 {src : img, creator: creator}); |
5304 {src : img, creator: creator}); |
5674 |
5695 |
5675 /* Get the displayable types |
5696 /* Get the displayable types |
5676 We've got to jump through a few hoops because the json sometimes defines |
5697 We've got to jump through a few hoops because the json sometimes defines |
5677 fields with underscores and sometimes with dashes |
5698 fields with underscores and sometimes with dashes |
5678 */ |
5699 */ |
5679 var annotation_types = this._data.views[0]["annotation_types"]; |
5700 var annotation_types = IriSP.get_aliased(this._data.views[0], ["annotation_types", "annotation-types"]); |
5680 if (IriSP.null_or_undefined(annotation_types)) { |
5701 if (annotation_types === null) { |
5681 annotation_types = this._data.views[0]["annotation-types"]; |
|
5682 if (IriSP.null_or_undefined(annotation_types)) { |
|
5683 console.log("neither view.annotation_types nor view.annotation-types are defined"); |
5702 console.log("neither view.annotation_types nor view.annotation-types are defined"); |
5684 return; |
5703 return; |
5685 } |
5704 } |
5686 } |
5705 |
5687 |
5706 var available_types = IriSP.get_aliased(this._data, ["annotation_types", "annotation-types"]); |
5688 var available_types = this._data["annotation_types"]; |
5707 if (available_types === null) { |
5689 if (IriSP.null_or_undefined(available_types)) { |
5708 console.log("neither view.annotation_types nor view.annotation-types are defined"); |
5690 available_types = this._data["annotation-types"]; |
|
5691 if (IriSP.null_or_undefined(available_types)) { |
|
5692 console.log("neither annotation_types nor annotation-types are defined"); |
|
5693 return; |
5709 return; |
5694 } |
|
5695 } |
5710 } |
5696 |
5711 |
5697 var potential_types = []; |
5712 var potential_types = []; |
5698 |
5713 |
5699 // Get the list of types which contain "Tw" in their content |
5714 // Get the list of types which contain "Tw" in their content |
5700 for (var i = 0; i < available_types.length; i++) { |
5715 for (var i = 0; i < available_types.length; i++) { |
5701 if (/Tw/i.test(available_types[i]["dc:title"])) { |
5716 if (/Tw/i.test(IriSP.get_aliased(available_types[i], ['dc:title', 'title']))) { |
5702 potential_types.push(available_types[i].id); |
5717 potential_types.push(available_types[i].id); |
5703 } |
5718 } |
5704 } |
5719 } |
5705 |
5720 |
5706 // Get the intersection of both. |
5721 // Get the intersection of both. |
5717 |
5732 |
5718 /* Get the displayable types |
5733 /* Get the displayable types |
5719 We've got to jump through a few hoops because the json sometimes defines |
5734 We've got to jump through a few hoops because the json sometimes defines |
5720 fields with underscores and sometimes with dashes |
5735 fields with underscores and sometimes with dashes |
5721 */ |
5736 */ |
5722 var annotation_types = this._data.views[0]["annotation_types"]; |
5737 var annotation_types = IriSP.get_aliased(this._data.views[0], ["annotation_types", "annotation-types"]); |
5723 if (IriSP.null_or_undefined(annotation_types)) { |
5738 if (annotation_types === null) { |
5724 annotation_types = this._data.views[0]["annotation-types"]; |
|
5725 if (IriSP.null_or_undefined(annotation_types)) { |
|
5726 console.log("neither view.annotation_types nor view.annotation-types are defined"); |
5739 console.log("neither view.annotation_types nor view.annotation-types are defined"); |
5727 return; |
5740 return; |
5728 } |
5741 } |
5729 } |
5742 |
5730 |
5743 var available_types = IriSP.get_aliased(this._data, ["annotation_types", "annotation-types"]); |
5731 var available_types = this._data["annotation_types"]; |
5744 if (available_types === null) { |
5732 if (IriSP.null_or_undefined(available_types)) { |
5745 console.log("neither view.annotation_types nor view.annotation-types are defined"); |
5733 available_types = this._data["annotation-types"]; |
|
5734 if (IriSP.null_or_undefined(available_types)) { |
|
5735 console.log("neither annotation_types nor annotation-types are defined"); |
|
5736 return; |
5746 return; |
5737 } |
|
5738 } |
5747 } |
5739 |
5748 |
5740 var potential_types = []; |
5749 var potential_types = []; |
5741 |
5750 |
5742 // Get the list of types which do not contain "Tw" in their content |
5751 // Get the list of types which do not contain "Tw" in their content |
5743 for (var i = 0; i < available_types.length; i++) { |
5752 for (var i = 0; i < available_types.length; i++) { |
5744 if (!(/Tw/i.test(available_types[i]["dc:title"]))) { |
5753 if (!(/Tw/i.test(IriSP.get_aliased(available_types[i], ['dc:title', 'title'])))) { |
5745 potential_types.push(available_types[i].id); |
5754 potential_types.push(available_types[i].id); |
5746 } |
5755 } |
5747 } |
5756 } |
5748 |
5757 |
5749 // Get the intersection of both. |
5758 // Get the intersection of both. |
5755 |
5764 |
5756 /** return the id of the ligne de temps which contains name |
5765 /** return the id of the ligne de temps which contains name |
5757 @param name of the ligne de temps |
5766 @param name of the ligne de temps |
5758 */ |
5767 */ |
5759 IriSP.JSONSerializer.prototype.getId = function(name) { |
5768 IriSP.JSONSerializer.prototype.getId = function(name) { |
5760 if (IriSP.null_or_undefined(this._data["annotation-types"])) |
5769 var available_types = IriSP.get_aliased(this._data, ["annotation_types", "annotation-types"]); |
|
5770 |
|
5771 if (available_types == null) |
5761 return; |
5772 return; |
5762 |
5773 |
5763 name = name.toUpperCase(); |
5774 name = name.toUpperCase(); |
5764 var e; |
5775 var e; |
5765 e = IriSP.underscore.find(this._data["annotation-types"], |
5776 e = IriSP.underscore.find(available_types, |
5766 function(entry) { |
5777 function(entry) { |
5767 if (IriSP.null_or_undefined(entry["dc:title"])) |
5778 if (IriSP.get_aliased(entry, ['dc:title', 'title']) === null) |
5768 return false; |
5779 return false; |
5769 |
5780 return (entry["dc:title"].toUpperCase().indexOf(name) !== -1); |
5770 return (entry["dc:title"].toUpperCase().indexOf(name) !== -1) }); |
5781 }); |
5771 |
5782 |
5772 if (typeof(e) === "undefined") |
5783 if (typeof(e) === "undefined") |
5773 return; |
5784 return; |
5774 |
5785 |
5775 var id = e.id; |
5786 var id = e.id; |
5779 |
5790 |
5780 /** return the list of id's of the ligne de temps which contains name |
5791 /** return the list of id's of the ligne de temps which contains name |
5781 @param name of the ligne de temps |
5792 @param name of the ligne de temps |
5782 */ |
5793 */ |
5783 IriSP.JSONSerializer.prototype.getIds = function(name) { |
5794 IriSP.JSONSerializer.prototype.getIds = function(name) { |
5784 if (IriSP.null_or_undefined(this._data["annotation-types"])) |
5795 var available_types = IriSP.get_aliased(this._data, ["annotation_types", "annotation-types"]); |
|
5796 |
|
5797 if (available_types == null) |
5785 return; |
5798 return; |
5786 |
5799 |
5787 name = name.toUpperCase(); |
5800 name = name.toUpperCase(); |
5788 var e = []; |
5801 var e = []; |
5789 e = IriSP.underscore.filter(this._data["annotation-types"], |
5802 e = IriSP.underscore.filter(available_types, |
5790 function(entry) { return (entry["dc:title"].toUpperCase().indexOf(name) !== -1) }); |
5803 function(entry) { return (IriSP.get_aliased(entry, ['dc:title', 'title']).toUpperCase().indexOf(name) !== -1) }); |
5791 return IriSP.underscore.pluck(e, "id"); |
5804 return IriSP.underscore.pluck(e, "id"); |
5792 }; |
5805 }; |
5793 |
5806 |
5794 /** return the id of the ligne de temps named "Chapitrage" */ |
5807 /** return the id of the ligne de temps named "Chapitrage" */ |
5795 IriSP.JSONSerializer.prototype.getChapitrage = function() { |
5808 IriSP.JSONSerializer.prototype.getChapitrage = function() { |