web/res/metadataplayer/LdtPlayer-core.js
changeset 955 5171f8825985
parent 940 843f96e4eebd
child 956 883d0724ffd0
--- a/web/res/metadataplayer/LdtPlayer-core.js	Thu Sep 26 14:46:53 2013 +0200
+++ b/web/res/metadataplayer/LdtPlayer-core.js	Tue Oct 01 16:33:47 2013 +0200
@@ -59,7 +59,7 @@
     if (typeof IriSP.libFiles.inDefaultDir[lib] == "string") {
         return IriSP.libFiles.defaultDir + '/' + IriSP.libFiles.inDefaultDir[lib];
     }
-}
+};
 
 IriSP._cssCache = [];
 
@@ -103,10 +103,10 @@
     }
     
     addToList(/(https?:\/\/)?[\w\d\-]+\.[\w\d\-]+\S+/gm, function(matches) {
-        return '<a href="' + (matches[1] ? '' : 'http://') + matches[0] + '" target="_blank">'
+        return '<a href="' + (matches[1] ? '' : 'http://') + matches[0] + '" target="_blank">';
     }, '</a>');
     addToList(/@([\d\w]{1,15})/gm, function(matches) {
-        return '<a href="http://twitter.com/' + matches[1] + '" target="_blank">'
+        return '<a href="http://twitter.com/' + matches[1] + '" target="_blank">';
     }, '</a>');
     addToList(/\*[^*]+\*/gm, '<b>', '</b>');
     addToList(/[\n\r]+/gm, '', '<br />');
@@ -118,7 +118,7 @@
     positions = IriSP._(positions)
         .chain()
         .uniq()
-        .sortBy(function(p) { return parseInt(p) })
+        .sortBy(function(p) { return parseInt(p); })
         .value();
     
     var res = "", lastIndex = 0;
@@ -172,9 +172,9 @@
     var _this = this,
         noop = (function() {});
     IriSP._(properties).each(function(p) {
-        _this[p] = noop
+        _this[p] = noop;
     });
-}
+};
 
 /* js is where data is stored in a standard form, whatever the serializer */
 
@@ -231,7 +231,7 @@
     isLocalURL = Model.isLocalURL = function(url) {
         var matches = url.match(/^(\w+:)\/\/([^/]+)/);
         if (matches) {
-            return(matches[1] === document.location.protocol && matches[2] === document.location.host)
+            return(matches[1] === document.location.protocol && matches[2] === document.location.host);
         }
         return true;
     },
@@ -258,7 +258,7 @@
     fullTextRegexps = Model.fullTextRegexps = function(_text) {
         var remsrc = "[\\" + removeChars.join("\\") + "]",
             remrx = new RegExp(remsrc,"gm"),
-            txt = _text.toLowerCase().replace(remrx,"")
+            txt = _text.toLowerCase().replace(remrx,""),
             res = [],
             charsrx = ns._(charsub).map(function(c) {
                 return new RegExp(c);
@@ -308,7 +308,7 @@
             + pad(2, d.getUTCDate())+'T'  
             + pad(2, d.getUTCHours())+':'  
             + pad(2, d.getUTCMinutes())+':'  
-            + pad(2, d.getUTCSeconds())+'Z'  
+            + pad(2, d.getUTCSeconds())+'Z'  ;
     };
 
 /*
@@ -331,7 +331,7 @@
             _element.found = undefined;
         });
         _this.trigger("search-cleared");
-    })
+    });
 };
 
 List.prototype = new Array();
@@ -349,7 +349,7 @@
         ns._(this).forEach(function(_value, _key) {
             _callback(_value, _key, _this);
         });
-    }
+    };
 };
 
 if (typeof Array.prototype.map === "undefined") {
@@ -358,7 +358,7 @@
         return ns._(this).map(function(_value, _key) {
             return _callback(_value, _key, _this);
         });
-    }
+    };
 };
 
 List.prototype.pluck = function(_key) {
@@ -438,9 +438,9 @@
     }
     this.searching = true;
     this.trigger("search", _text);
-    var rxsource = fullTextRegexps(_text)
-        rgxp = new RegExp(rxsource,"im"),
-        this.regexp = new RegExp(rxsource,"gim");
+    var rxsource = fullTextRegexps(_text),
+        rgxp = new RegExp(rxsource,"im");
+    this.regexp = new RegExp(rxsource,"gim");
     var res = this.filter(function(_element, _k) {
         var titlematch = rgxp.test(_element.title),
             descmatch = rgxp.test(_element.description),
@@ -460,7 +460,7 @@
 };
 
 List.prototype.addId = function(_id) {
-    var _el = this.directory.getElement(_id)
+    var _el = this.directory.getElement(_id);
     if (!this.hasId(_id) && typeof _el !== "undefined") {
         this.idIndex.push(_id);
         Array.prototype.push.call(this, _el);
@@ -593,7 +593,7 @@
         minutes : (Math.floor(_totalSeconds / 60) % 60),
         seconds : _totalSeconds % 60,
         milliseconds: this.milliseconds % 1000
-    } 
+    };
 };
 
 Time.prototype.add = function(_milliseconds) {
@@ -608,11 +608,11 @@
     var _hms = this.getHMS(),
         _res = '';
     if (_hms.hours) {
-        _res += _hms.hours + ':'
+        _res += _hms.hours + ':';
     }
     _res += pad(2, _hms.minutes) + ':' + pad(2, _hms.seconds);
     if (showCs) {
-        _res += "." + Math.floor(_hms.milliseconds / 100)
+        _res += "." + Math.floor(_hms.milliseconds / 100);
     }
     return _res;
 };
@@ -650,7 +650,7 @@
 
 Reference.prototype.isOrHasId = function(_idRef) {
     if (this.isList) {
-        return (ns._(this.id).indexOf(_idRef) !== -1)
+        return (ns._(this.id).indexOf(_idRef) !== -1);
     } else {
         return (this.id == _idRef);
     }
@@ -662,7 +662,7 @@
     this.elementType = 'element';
     this.title = "";
     this.description = "";
-    this.__events = {}
+    this.__events = {};
     if (typeof _source === "undefined") {
         return;
     }
@@ -744,14 +744,14 @@
     this.on("timeupdate", function(_time) {
         _this.currentTime = _time;
         _this.getAnnotations().filter(function(_a) {
-            return (_a.end <= _time || _a.begin > _time) && _a.playing
+            return (_a.end <= _time || _a.begin > _time) && _a.playing;
         }).forEach(function(_a) {
             _a.playing = false;
             _a.trigger("leave");
             _this.trigger("leave-annotation",_a);
         });
         _this.getAnnotations().filter(function(_a) {
-            return _a.begin <= _time && _a.end > _time && !_a.playing
+            return _a.begin <= _time && _a.end > _time && !_a.playing;
         }).forEach(function(_a) {
             _a.playing = true;
             _a.trigger("enter");
@@ -834,7 +834,7 @@
             return ns._(_annTypes).indexOf(_annotation.getAnnotationType().id) !== -1;
         });
     } else {
-        return new List(this.source.directory)
+        return new List(this.source.directory);
     }
 };
 
@@ -930,7 +930,7 @@
 };
 
 Annotation.prototype.getDuration = function() {
-    return new Time(this.end.milliseconds - this.begin.milliseconds)
+    return new Time(this.end.milliseconds - this.begin.milliseconds);
 };
 
 /* */
@@ -997,7 +997,7 @@
     this._updateTimes = function() {
         _this.updateTimes();
         _this.trigger("change");
-    }
+    };
     this.on("add", this._updateTimes);
     this.on("remove", this._updateTimes);
 };
@@ -1086,19 +1086,19 @@
 
 Mashup.prototype.hasAnnotation = function(_annotation) {
     return !!ns._(this.segments).find(function(_s) {
-        return _s.annotation === _annotation
+        return _s.annotation === _annotation;
     });
 };
 
 Mashup.prototype.getAnnotation = function(_annotation) {
     return ns._(this.segments).find(function(_s) {
-        return _s.annotation === _annotation
+        return _s.annotation === _annotation;
     });
 };
 
 Mashup.prototype.getAnnotationById = function(_id) {
     return ns._(this.segments).find(function(_s) {
-        return _s.annotation.id === _id
+        return _s.annotation.id === _id;
     });
 };
 
@@ -1117,8 +1117,8 @@
 Mashup.prototype.getMedias = function() {
     var medias = new List(this.source.directory);
     this.segments.forEach(function(_annotation) {
-        medias.push(_annotation.getMedia())
-    })
+        medias.push(_annotation.getMedia());
+    });
     return medias;
 };
 
@@ -1129,7 +1129,7 @@
             return ns._(_annTypes).indexOf(_annotation.getAnnotationType().id) !== -1;
         });
     } else {
-        return new List(this.source.directory)
+        return new List(this.source.directory);
     }
 };
 
@@ -1163,7 +1163,7 @@
         var _this = this;
         ns._(_config).forEach(function(_v, _k) {
             _this[_k] = _v;
-        })
+        });
         this.callbackQueue = [];
         this.contents = {};
         this.get();
@@ -1187,7 +1187,7 @@
         });
     } else {
         if (typeof this.contents[_listId] === "undefined") {
-            this.contents[_listId] = new IriSP.List(this.directory);
+            this.contents[_listId] = new List(this.directory);
         }
         return this.contents[_listId];
     }
@@ -1197,7 +1197,7 @@
     var _this = this;
     ns._(this.contents).forEach(function(_value, _key) {
         _callback.call(_this, _value, _key);
-    })
+    });
 };
 
 Source.prototype.getElement = function(_elId) {
@@ -1270,7 +1270,7 @@
         _annTypes = this.getAnnotationTypes(_global).searchByTitle(_title);
     _annTypes.forEach(function(_annType) {
         _res.addElements(_annType.getAnnotations(_global));
-    })
+    });
     return _res;
 };
 
@@ -1466,7 +1466,7 @@
         getVolume();
         media.trigger("loadedmetadata");
         media.trigger("volumechange");
-    })
+    });
     
     videoEl.on("timeupdate", function() {
         media.trigger("timeupdate", new IriSP.Model.Time(1000*mediaEl.currentTime));
@@ -1475,7 +1475,7 @@
     videoEl.on("volumechange", function() {
         getVolume();
         media.trigger("volumechange");
-    })
+    });
     
     videoEl.on("play", function() {
         media.trigger("play");
@@ -1495,6 +1495,33 @@
     
     
 };
+IriSP.serializers.content = {
+    deSerialize : function(_data, _source) {
+        var _medialist = new IriSP.Model.List(_source.directory);
+        
+        function deserializeObject(_m, i) {
+            var _media = new IriSP.Model.Media(_m.iri_id, _source);
+            _media.video = _m.media_url;
+            _media.title = _m.title;
+            _media.description = _m.description;
+            _media.setDuration(_m.duration);
+            _media.thumbnail = _m.image;
+            _media.color = IriSP.vizcolors[i % IriSP.vizcolors.length];
+            _media.keywords = _m.tags;
+            _medialist.push(_media);
+        }
+        
+        if (typeof _data.objects !== "undefined") {
+            IriSP._(_data.objects).each(deserializeObject);
+        } else {
+            deserializeObject(_data, 0);
+        }
+        
+        _source.addList("media", _medialist);
+    }
+};
+
+/* END contentapi-serializer.js */
 /* LDT Platform Serializer */
 
 if (typeof IriSP.serializers === "undefined") {
@@ -1541,7 +1568,7 @@
                         "dc:contributor" : _data.contributor || _source.contributor || _data.creator || _source.creator,
                         "dc:duration" : _data.duration.milliseconds
                     }
-                }
+                };
                 _dest.medias.push(_res);
                 var _list = {
                     id: IriSP.Model.getUID(),
@@ -1574,9 +1601,9 @@
                     }).map(function(_at) {
                         return {
                             "id-ref": _at.id
-                        }
+                        };
                     })
-                }
+                };
                 _dest.lists.push(_list);
                 _dest.views[0].contents.push(_data.id);
             }
@@ -1602,7 +1629,7 @@
                         "dc:creator" : _data.creator || _source.creator,
                         "dc:contributor" : _data.contributor || _source.contributor || _data.creator || _source.creator,
                     }
-                }
+                };
                 _dest.tags.push(_res);
             }
         },
@@ -1623,7 +1650,7 @@
                     "dc:modified" : IriSP.Model.dateToIso(_data.modified || _source.modified),
                     "dc:creator" : _data.creator || _source.creator,
                     "dc:contributor" : _data.contributor || _source.contributor || _data.creator || _source.creator,
-                }
+                };
                 _dest["annotation-types"].push(_res);
                 _dest.views[0].annotation_types.push(_data.id);
             }
@@ -1694,18 +1721,18 @@
                         "dc:contributor" : _data.contributor || _source.contributor || _data.creator || _source.creator,
 //                        project : _source.projectId
                     }
-                }
+                };
                 if (_source.regenerateTags) {
                     _res.tags = IriSP._(_data.keywords).map(function(_kw) {
                         return {
                             "id-ref": _source.__keywords[_kw.toLowerCase()].id
-                        } 
+                        };
                     });
                 } else {
                     _res.tags = IriSP._(_data.tag.id).map(function(_id) {
                        return {
                            "id-ref" : _id
-                       } 
+                       };
                     });
                 }
                 _res.content.title = _data.title || _res.content.title || "";
@@ -1740,7 +1767,7 @@
                         return _annotation.annotation.id;
                     }),
                     id: _data.id
-                }
+                };
                 _dest.lists.push(_res);
             }
         }
@@ -1780,13 +1807,13 @@
                             id: IriSP.Model.getUID(),
                             title: kw,
                             regenerated: true
-                        }
+                        };
                     }
                 });
             });
             IriSP._(_source.__keywords).each(function(kw) {
                 _this.types.tag.serializer(kw, _source, _res);
-            })
+            });
         }
         _source.forEach(function(_list, _typename) {
             if (typeof _this.types[_typename] !== "undefined") {
@@ -1863,7 +1890,7 @@
                 created: _data.created,
                 creator: _data.creator
             }
-        }
+        };
     },
     deserializeAnnotation : function(_anndata, _source) {
         var _ann = new IriSP.Model.Annotation(_anndata.id, _source);
@@ -1914,7 +1941,40 @@
     }
 };
 
-/* End ldt_annotate serializer *//* Start of defaults.js */
+/* End ldt_annotate serializer */IriSP.serializers.segmentapi = {
+    deSerialize : function(_data, _source) {
+        var _annotationlist = new IriSP.Model.List(_source.directory),
+            _medialist = new IriSP.Model.List(_source.directory);
+        _source.addList("media", _medialist);
+        
+        function deserializeObject(_s) {
+            var _ann = new IriSP.Model.Annotation(_s.element_id, _source),
+                _media = _source.getElement(_s.iri_id);
+            if (!_media) {
+                _media = new IriSP.Model.Media(_s.iri_id, _source);
+                _source.getMedias().push(_media);
+            }
+            _ann.setMedia(_s.iri_id);
+            _ann.title = _s.title;
+            _ann.description = _s.abstract;
+            _ann.begin = new IriSP.Model.Time(_s.start_ts);
+            _ann.end = new IriSP.Model.Time(_s.start_ts + _s.duration);
+            _ann.keywords = (_s.tags ? _s.tags.split(",") : []);
+            _ann.project_id = _s.project_id;
+            _annotationlist.push(_ann);
+        }
+        
+        if (typeof _data.objects !== "undefined") {
+            IriSP._(_data.objects).each(deserializeObject);
+        } else {
+            deserializeObject(_data);
+        }
+        _source.addList("annotation", _annotationlist);
+    }
+};
+
+/* END segmentapi-serializer.js */
+/* Start of defaults.js */
 
 IriSP.language = 'en';
 
@@ -2156,7 +2216,7 @@
             return;
         }
         var isloaded = !ns._(_this.widgets).any(function(w) {
-            return !(w && w.isLoaded())
+            return !(w && w.isLoaded());
         });
         if (isloaded) {
             _this.widgetsLoaded = true;
@@ -2316,7 +2376,7 @@
             } else {
                 var _mediaopts = {
                     is_mashup: _this.is_mashup || false
-                }
+                };
                 _this.media = _this.source.getCurrentMedia(_mediaopts);
             }
             
@@ -2363,9 +2423,9 @@
     if (typeof _function !== "undefined") {
         return function() {
             return _function.apply(_this, Array.prototype.slice.call(arguments, 0));
-        }
+        };
     } else {
-        console.log("Error, Unknown function IriSP.Widgets." + this.type + "." + _name)
+        console.log("Error, Unknown function IriSP.Widgets." + this.type + "." + _name);
     }
 };