diff -r c9c502117eb6 -r ff4b567d51f2 web/res/metadataplayer/LdtPlayer-core.js --- a/web/res/metadataplayer/LdtPlayer-core.js Fri Feb 13 13:14:15 2015 +0100 +++ b/web/res/metadataplayer/LdtPlayer-core.js Sun Feb 15 00:43:16 2015 +0100 @@ -32,12 +32,16 @@ if (typeof window.IriSP === "undefined") { window.IriSP = { - VERSION: "0.3.1" + VERSION: "0.3.2" }; } -if (typeof IriSP.jQuery === "undefined" && typeof window.jQuery !== "undefined" && parseFloat(window.jQuery().jquery) >= 1.7) { - IriSP.jQuery = window.jQuery; +if (typeof IriSP.jQuery === "undefined" && typeof window.jQuery !== "undefined") { + var jvp = window.jQuery().jquery.split("."), + jv = 100 * parseInt(jvp[0]) + parseInt(jvp[1]); + if (jv > 170) { + IriSP.jQuery = window.jQuery; + } } if (typeof IriSP._ === "undefined" && typeof window._ !== "undefined" && parseFloat(window._.VERSION) >= 1.4) { @@ -453,6 +457,26 @@ return res; }; +List.prototype.searchByTags = function(_text) { + if (!_text) { + this.trigger("clear-search"); + return this; + } + this.searching = true; + this.trigger("search", _text); + var rxsource = fullTextRegexps(_text), + rgxp = new RegExp(rxsource,"im"); + this.regexp = new RegExp(rxsource,"gim"); + var res = this.filter(function(_element, _k) { + var _isfound = rgxp.test(_element.getTagTexts()); + _element.found = _isfound; + _element.trigger(_isfound ? "found" : "not-found"); + return _isfound; + }); + this.trigger(res.length ? "found" : "not-found",res); + return res; +}; + List.prototype.getTitles = function() { return this.map(function(_el) { return _el.title; @@ -1633,7 +1657,7 @@ "dc:created" : IriSP.Model.dateToIso(_data.created || _source.created), "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, + "dc:contributor" : _data.contributor || _source.contributor || _data.creator || _source.creator } }; _dest.tags.push(_res); @@ -1655,7 +1679,7 @@ "dc:created" : IriSP.Model.dateToIso(_data.created || _source.created), "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, + "dc:contributor" : _data.contributor || _source.contributor || _data.creator || _source.creator }; _dest["annotation-types"].push(_res); _dest.views[0].annotation_types.push(_data.id); @@ -1724,7 +1748,7 @@ "dc:created" : IriSP.Model.dateToIso(_data.created || _source.created), "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, + "dc:contributor" : _data.contributor || _source.contributor || _data.creator || _source.creator // project : _source.projectId } }; @@ -1871,7 +1895,8 @@ } }; -/* End of LDT Platform Serializer *//* ldt_annotate serializer: Used when Putting annotations on the platform */ +/* End of LDT Platform Serializer */ +/* ldt_annotate serializer: Used when Putting annotations on the platform */ if (typeof IriSP.serializers === "undefined") { IriSP.serializers = {}; @@ -1947,7 +1972,86 @@ } }; -/* End ldt_annotate serializer *//* START segmentapi-serializer.js */ +/* End ldt_annotate serializer *//* ldt_localstorage serializer: Used to store personal annotations in local storage */ + +if (typeof IriSP.serializers === "undefined") { + IriSP.serializers = {}; +} + +IriSP.serializers.ldt_localstorage = { + serializeAnnotation : function(_data, _source) { + var _annType = _data.getAnnotationType(); + return { + begin: _data.begin.milliseconds, + end: _data.end.milliseconds, + content: { + description: _data.description, + title: _data.title, + audio: _data.audio + }, + tags: _data.getTagTexts(), + media: _data.getMedia().id, + type_title: _annType.title, + type: ( typeof _annType.dont_send_id !== "undefined" && _annType.dont_send_id ? "" : _annType.id ), + meta: { + created: _data.created, + creator: _data.creator + } + }; + }, + deserializeAnnotation : function(_anndata, _source) { + var _ann = new IriSP.Model.Annotation(_anndata.id, _source); + _ann.description = _anndata.content.description || ""; + _ann.title = _anndata.content.title || ""; + _ann.creator = _anndata.meta.creator || ""; + _ann.created = new Date(_anndata.meta.created); + _ann.setMedia(_anndata.media, _source); + var _anntype = _source.getElement(_anndata.type); + if (!_anntype) { + _anntype = new IriSP.Model.AnnotationType(_anndata.type, _source); + _anntype.title = _anndata.type_title; + _source.getAnnotationTypes().push(_anntype); + } + _ann.setAnnotationType(_anntype.id); + var _tagIds = IriSP._(_anndata.tags).map(function(_title) { + var _tags = _source.getTags(true).searchByTitle(_title, true); + if (_tags.length) { + var _tag = _tags[0]; + } + else { + _tag = new IriSP.Model.Tag(_title.replace(/\W/g,'_'),_source); + _tag.title = _title; + _source.getTags().push(_tag); + } + return _tag.id; + }); + _ann.setTags(_tagIds); + _ann.setBegin(_anndata.begin); + _ann.setEnd(_anndata.end); + if (typeof _anndata.content.audio !== "undefined" && _anndata.content.audio.href) { + _ann.audio = _anndata.content.audio; + } + _source.getAnnotations().push(_ann); + }, + serialize : function(_source) { + var _this = this; + return JSON.stringify(_source.getAnnotations().map(function (a) { return _this.serializeAnnotation(a, _source); })); + }, + deSerialize : function(_data, _source) { + var _this = this; + if (typeof _data == "string") { + _data = JSON.parse(_data); + } + + _source.addList('tag', new IriSP.Model.List(_source.directory)); + _source.addList('annotationType', new IriSP.Model.List(_source.directory)); + _source.addList('annotation', new IriSP.Model.List(_source.directory)); + _data.map( function (a) { _this.deserializeAnnotation(a, _source); }); + } +}; + +/* End ldt_localstorage serializer */ +/* START segmentapi-serializer.js */ if (typeof IriSP.serializers === "undefined") { IriSP.serializers = {}; @@ -1968,7 +2072,7 @@ } _ann.setMedia(_s.iri_id); _ann.title = _s.title; - _ann.description = _s.abstract; + _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(",") : []); @@ -2011,9 +2115,13 @@ backboneRelational: "backbone-relational.js", paper: "paper.js", jqueryMousewheel: "jquery.mousewheel.min.js", + splitter: "jquery.splitter.js", + cssSplitter: "jquery.splitter.css", renkanPublish: "renkan.js", processing: "processing-1.3.6.min.js", - recordMicSwf: "record_mic.swf" + recordMicSwf: "record_mic.swf", + mousetrap: "mousetrap.min.js", + mousetrapGlobal: "mousetrap-global-bind.js" }, locations : { // use to define locations outside default_dir @@ -2088,6 +2196,12 @@ }, MultiSegments: { noCss: true + }, + SlideVideoPlayer: { + requires: [ "jQuery", "jQueryUI", "splitter" ] + }, + Shortcuts: { + requires: [ "mousetrap", "mousetrapGlobal" ] } }; @@ -2461,13 +2575,19 @@ }; IriSP.Widgets.Widget.prototype.getWidgetAnnotations = function() { + var result = null; if (typeof this.annotation_type === "undefined") { - return this.media.getAnnotations(); + result = this.media.getAnnotations(); + } else if (this.annotation_type.elementType === "annotationType") { + result = this.annotation_type.getAnnotations(); + } else { + result = this.media.getAnnotationsByTypeTitle(this.annotation_type); } - if (this.annotation_type.elementType === "annotationType") { - return this.annotation_type.getAnnotations(); + if (typeof this.annotation_filter !== "undefined") { + return this.annotation_filter(result); + } else { + return result; } - return this.media.getAnnotationsByTypeTitle(this.annotation_type); }; IriSP.Widgets.Widget.prototype.getWidgetAnnotationsAtTime = function() { @@ -2511,9 +2631,32 @@ }); }; +/* + * Position the player to the next/previous annotations based on current player position + * + * Parameter: offset: -1 for previous annotation, +1 for next annotation + */ +IriSP.Widgets.Widget.prototype.navigate = function(offset) { + // offset is normally either -1 (previous slide) or +1 (next slide) + var _this = this; + var currentTime = _this.media.getCurrentTime(); + var annotations = _this.source.getAnnotations().sortBy(function(_annotation) { + return _annotation.begin; + }); + for (var i = 0; i < annotations.length; i++) { + if (annotations[i].begin <= currentTime && currentTime < annotations[i].end) { + // Found a current annotation - clamp i+offset value to [0, length - 1] + i = Math.min(annotations.length - 1, Math.max(0, i + offset)); + _this.media.setCurrentTime(annotations[i].begin); + break; + } + }; +}; + + /** * This method responsible of drawing a widget on screen. */ IriSP.Widgets.Widget.prototype.draw = function() { /* implemented by "sub-classes" */ -}; \ No newline at end of file +};