--- a/src/js/model.js Fri Jun 08 19:03:03 2012 +0200
+++ b/src/js/model.js Tue Jun 12 19:44:20 2012 +0200
@@ -336,14 +336,11 @@
IriSP.Model.Reference = function(_source, _idRef) {
this.source = _source;
+ this.id = _idRef;
if (typeof _idRef === "object") {
this.isList = true;
- this.id = IriSP._(_idRef).map(function(_id) {
- return _source.getNamespaced(_id).fullname;
- });
} else {
this.isList = false;
- this.id = _source.getNamespaced(_idRef).fullname;
}
this.refresh();
}
@@ -384,8 +381,7 @@
_id = IriSP.Model.getUID();
}
this.source = _source;
- this.namespacedId = _source.getNamespaced(_id)
- this.id = this.namespacedId.fullname;
+ this.id = _id;
this.title = "";
this.description = "";
this.source.directory.addElement(this);
@@ -525,7 +521,7 @@
/* */
IriSP.Model.MashedAnnotation = function(_mashup, _annotation) {
- IriSP.Model.Element.call(this, _mashup.namespacedId.name + "_" + _annotation.namespacedId.name, _annotation.source);
+ IriSP.Model.Element.call(this, _mashup.id + "_" + _annotation.id, _annotation.source);
this.elementType = 'mashedAnnotation';
this.annotation = _annotation;
this.begin = new IriSP.Model.Time(_mashup.duration);
@@ -629,54 +625,10 @@
})
this.callbackQueue = [];
this.contents = {};
- if (typeof this.namespace === "undefined") {
- this.namespace = "metadataplayer";
- } else {
- if (typeof this.namespaceUrl === "undefined" && typeof this.url !== "undefined") {
- var _matches = this.url.match(/(^[^?&]+|[^?&][a-zA-Z0-9_%=?]+)/g),
- _url = _matches[0];
- if (_matches.length > 1) {
- _matches = IriSP._(_matches.slice(1)).reject(function(_txt) {
- return /\?$/.test(_txt);
- });
- }
- if (_matches.length > 0) {
- _url += '?' + _matches.join('&');
- }
- this.namespaceUrl = _url;
- }
- }
- if (typeof this.namespaceUrl === "undefined") {
- this.namespaceUrl = "http://ldt.iri.centrepompidou.fr/";
- }
- this.directory.addNamespace(this.namespace, this.namespaceUrl);
this.get();
}
}
-IriSP.Model.Source.prototype.getNamespaced = function(_id) {
- var _tab = _id.split(':');
- if (_tab.length > 1) {
- return {
- namespace : _tab[0],
- name : _tab[1],
- fullname : _id
- }
- } else {
- return {
- namespace : this.namespace,
- name : _id,
- fullname : this.namespace + ':' + _id
- }
- }
-}
-
-IriSP.Model.Source.prototype.unNamespace = function(_id) {
- if (typeof _id !== "undefined") {
- return _id.replace(this.namespace + ':', '');
- }
-}
-
IriSP.Model.Source.prototype.addList = function(_listId, _contents) {
if (typeof this.contents[_listId] === "undefined") {
this.contents[_listId] = new IriSP.Model.List(this.directory);
@@ -703,7 +655,7 @@
}
IriSP.Model.Source.prototype.getElement = function(_elId) {
- return this.directory.getElement(this.getNamespaced(_elId).fullname);
+ return this.directory.getElement(_elId);
}
IriSP.Model.Source.prototype.setCurrentMediaId = function(_idRef) {
@@ -718,21 +670,6 @@
}
}
-IriSP.Model.Source.prototype.listNamespaces = function(_excludeSelf) {
- var _this = this,
- _nsls = [],
- _excludeSelf = (typeof _excludeSelf !== "undefined" && _excludeSelf);
- this.forEach(function(_list) {
- IriSP._(_list).forEach(function(_el) {
- var _ns = _el.id.replace(/:.*$/,'');
- if (IriSP._(_nsls).indexOf(_ns) === -1 && (!_excludeSelf || _ns !== _this.namespace)) {
- _nsls.push(_ns);
- }
- })
- });
- return _nsls;
-}
-
IriSP.Model.Source.prototype.get = function() {
this.status = IriSP.Model._SOURCE_STATUS_WAITING;
this.handleCallbacks();
@@ -839,11 +776,6 @@
IriSP.Model.Directory = function() {
this.remoteSources = {};
this.elements = {};
- this.namespaces = {};
-}
-
-IriSP.Model.Directory.prototype.addNamespace = function(_namespace, _url) {
- this.namespaces[_namespace] = _url;
}
IriSP.Model.Directory.prototype.remoteSource = function(_properties) {
--- a/src/js/serializers/ldt.js Fri Jun 08 19:03:03 2012 +0200
+++ b/src/js/serializers/ldt.js Tue Jun 12 19:44:20 2012 +0200
@@ -29,7 +29,7 @@
},
serializer : function(_data, _source) {
return {
- id : _source.unNamespace(_data.id),
+ id : _data.id,
url : _data.video,
meta : {
"dc:title" : _data.title,
@@ -49,7 +49,7 @@
},
serializer : function(_data, _source) {
return {
- id : _source.unNamespace(_data.id),
+ id : _data.id,
meta : {
"dc:title" : _data.title
}
@@ -66,7 +66,7 @@
},
serializer : function(_data, _source) {
return {
- id : _source.unNamespace(_data.id),
+ id : _data.id,
"dc:title" : _data.title,
"dc:description" : _data.description
}
@@ -106,7 +106,7 @@
},
serializer : function(_data, _source) {
return {
- id : _source.unNamespace(_data.id),
+ id : _data.id,
begin : _data.begin.milliseconds,
end : _data.end.milliseconds,
content : {
@@ -114,16 +114,16 @@
description : _data.description,
audio : _data.audio
},
- media : _source.unNamespace(_data.media.id),
+ media : _data.media.id,
meta : {
- "id-ref" : _source.unNamespace(_data.annotationType.id),
+ "id-ref" : _data.annotationType.id,
"dc:created" : IriSP.Model.dateToIso(_data.created),
"dc:creator" : _data.creator,
project : _source.projectId
},
tags : IriSP._(_data.tag.id).map(function(_id) {
return {
- "id-ref" : _source.unNamespace(_id)
+ "id-ref" : _id
}
})
}
@@ -145,7 +145,7 @@
"dc:title": _data.title,
"dc:description": _data.description,
segments: _data.segments.map(function(_annotation) {
- return _source.unNamespace(_id);
+ return _id;
})
}
}
@@ -171,9 +171,9 @@
return;
}
IriSP._(this.types).forEach(function(_type, _typename) {
- var _listdata = _data[_type.serialized_name];
+ var _listdata = _data[_type.serialized_name],
+ _list = new IriSP.Model.List(_source.directory);
if (typeof _listdata !== "undefined" && _listdata !== null) {
- var _list = new IriSP.Model.List(_source.directory);
if (_listdata.hasOwnProperty("length")) {
var _l = _listdata.length;
for (var _i = 0; _i < _l; _i++) {
@@ -182,8 +182,8 @@
} else {
_list.push(_type.deserializer(_listdata, _source));
}
- _source.addList(_typename, _list);
}
+ _source.addList(_typename, _list);
});
if (typeof _data.meta !== "undefined") {
--- a/src/js/serializers/ldt_annotate.js Fri Jun 08 19:03:03 2012 +0200
+++ b/src/js/serializers/ldt_annotate.js Tue Jun 12 19:44:20 2012 +0200
@@ -9,6 +9,7 @@
annotation : {
serialized_name : "annotations",
serializer : function(_data, _source) {
+ var _annType = _data.getAnnotationType();
return {
begin: _data.begin.milliseconds,
end: _data.end.milliseconds,
@@ -17,10 +18,10 @@
audio: _data.audio
},
tags: _data.getTagTexts(),
- media: _source.unNamespace(_data.getMedia().id),
+ media: _data.getMedia().id,
title: _data.title,
- type_title: _data.getAnnotationType().title,
- type: ( typeof _data.getAnnotationType().dont_send_id !== "undefined" && _data.getAnnotationType().dont_send_id ? "" : _source.unNamespace(_data.getAnnotationType().id) )
+ type_title: _annType.title,
+ type: ( typeof _annType.dont_send_id !== "undefined" && _annType.dont_send_id ? "" : _annType.id )
}
}
}
--- a/src/js/widgets.js Fri Jun 08 19:03:03 2012 +0200
+++ b/src/js/widgets.js Tue Jun 12 19:44:20 2012 +0200
@@ -66,7 +66,15 @@
}
}
- this.l10n = (typeof this.messages[IriSP.language] !== "undefined" ? this.messages[IriSP.language] : this.messages["en"]);
+ this.l10n = (
+ typeof this.messages[IriSP.language] !== "undefined"
+ ? this.messages[IriSP.language]
+ : (
+ IriSP.language.length > 2 && typeof this.messages[IriSP.language.substr(0,2)] !== "undefined"
+ ? this.messages[IriSP.language.substr(0,2)]
+ : this.messages["en"]
+ )
+ );
};
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/obsolete-files/model-namespaced.js Tue Jun 12 19:44:20 2012 +0200
@@ -0,0 +1,877 @@
+/* model.js is where data is stored in a standard form, whatever the serializer */
+
+IriSP.Model = {
+ _SOURCE_STATUS_EMPTY : 0,
+ _SOURCE_STATUS_WAITING : 1,
+ _SOURCE_STATUS_READY : 2,
+ _ID_AUTO_INCREMENT : 0,
+ _ID_BASE : (function(_d) {
+ function pad(n){return n<10 ? '0'+n : n}
+ function fillrand(n) {
+ var _res = ''
+ for (var i=0; i<n; i++) {
+ _res += Math.floor(16*Math.random()).toString(16);
+ }
+ return _res;
+ }
+ return _d.getUTCFullYear() + '-'
+ + pad(_d.getUTCMonth()+1) + '-'
+ + pad(_d.getUTCDate()) + '-'
+ + fillrand(16);
+ })(new Date()),
+ getUID : function() {
+ var _n = (++this._ID_AUTO_INCREMENT).toString();
+ while (_n.length < 4) {
+ _n = '0' + _n
+ }
+ return "autoid-" + this._ID_BASE + '-' + _n;
+ },
+ regexpFromTextOrArray : function(_textOrArray) {
+ function escapeText(_text) {
+ return _text.replace(/([\\\*\+\?\|\{\[\}\]\(\)\^\$\.\#\/])/gm, '\\$1');
+ }
+ return new RegExp( '('
+ + (
+ typeof _textOrArray === "string"
+ ? escapeText(_textOrArray)
+ : IriSP._(_textOrArray).map(escapeText).join("|")
+ )
+ + ')',
+ 'gim'
+ );
+ },
+ isoToDate : function(_str) {
+ // http://delete.me.uk/2005/03/iso8601.html
+ var regexp = "([0-9]{4})(-([0-9]{2})(-([0-9]{2})(T([0-9]{2}):([0-9]{2})(:([0-9]{2})(\.([0-9]+))?)?(Z|(([-+])([0-9]{2}):([0-9]{2})))?)?)?)?";
+ var d = _str.match(new RegExp(regexp));
+
+ var offset = 0;
+ var date = new Date(d[1], 0, 1);
+
+ if (d[3]) { date.setMonth(d[3] - 1); }
+ if (d[5]) { date.setDate(d[5]); }
+ if (d[7]) { date.setHours(d[7]); }
+ if (d[8]) { date.setMinutes(d[8]); }
+ if (d[10]) { date.setSeconds(d[10]); }
+ if (d[12]) { date.setMilliseconds(Number("0." + d[12]) * 1000); }
+ if (d[14]) {
+ offset = (Number(d[16]) * 60) + Number(d[17]);
+ offset *= ((d[15] == '-') ? 1 : -1);
+ }
+
+ offset -= date.getTimezoneOffset();
+ time = (Number(date) + (offset * 60 * 1000));
+ var _res = new Date();
+ _res.setTime(Number(time));
+ return _res;
+ },
+ dateToIso : function(d) {
+ function pad(n){return n<10 ? '0'+n : n}
+ return d.getUTCFullYear()+'-'
+ + pad(d.getUTCMonth()+1)+'-'
+ + pad(d.getUTCDate())+'T'
+ + pad(d.getUTCHours())+':'
+ + pad(d.getUTCMinutes())+':'
+ + pad(d.getUTCSeconds())+'Z'
+ }
+}
+
+/*
+ * IriSP.Model.List is a class for a list of elements (e.g. annotations, medias, etc. that each have a distinct ID)
+ */
+IriSP.Model.List = function(_directory) {
+ Array.call(this);
+ this.directory = _directory;
+ this.idIndex = [];
+ if (typeof _directory == "undefined") {
+ console.trace();
+ throw "Error : new IriSP.Model.List(directory): directory is undefined";
+ }
+}
+
+IriSP.Model.List.prototype = new Array();
+
+IriSP.Model.List.prototype.getElement = function(_id) {
+ return this[_id];
+}
+
+IriSP.Model.List.prototype.hasId = function(_id) {
+ return (IriSP._(this.idIndex).indexOf(_id) !== -1);
+}
+
+/* On recent browsers, forEach and map are defined and do what we want.
+ * Otherwise, we'll use the Underscore.js functions
+ */
+if (typeof Array.prototype.forEach === "undefined") {
+ IriSP.Model.List.prototype.forEach = function(_callback) {
+ var _this = this;
+ IriSP._(this).forEach(function(_value, _key) {
+ _callback(_value, _key, _this);
+ });
+ }
+}
+
+if (typeof Array.prototype.map === "undefined") {
+ IriSP.Model.List.prototype.map = function(_callback) {
+ var _this = this;
+ return IriSP._(this).map(function(_value, _key) {
+ return _callback(_value, _key, _this);
+ });
+ }
+}
+
+IriSP.Model.List.prototype.pluck = function(_key) {
+ return this.map(function(_value) {
+ return _value[_key];
+ });
+}
+
+/* We override Array's filter function because it doesn't return an IriSP.Model.List
+ */
+IriSP.Model.List.prototype.filter = function(_callback) {
+ var _this = this,
+ _res = new IriSP.Model.List(this.directory);
+ _res.addElements(IriSP._(this).filter(function(_value, _key) {
+ return _callback(_value, _key, _this);
+ }));
+ return _res;
+}
+
+IriSP.Model.List.prototype.slice = function(_start, _end) {
+ var _res = new IriSP.Model.List(this.directory);
+ _res.addElements(Array.prototype.slice.call(this, _start, _end));
+ return _res;
+}
+
+IriSP.Model.List.prototype.splice = function(_start, _end) {
+ var _res = new IriSP.Model.List(this.directory);
+ _res.addElements(Array.prototype.splice.call(this, _start, _end));
+ this.idIndex.splice(_start, _end);
+ return _res;
+}
+
+/* Array has a sort function, but it's not as interesting as Underscore.js's sortBy
+ * and won't return a new IriSP.Model.List
+ */
+IriSP.Model.List.prototype.sortBy = function(_callback) {
+ var _this = this,
+ _res = new IriSP.Model.List(this.directory);
+ _res.addElements(IriSP._(this).sortBy(function(_value, _key) {
+ return _callback(_value, _key, _this);
+ }));
+ return _res;
+}
+
+/* Title and Description are basic information for (almost) all element types,
+ * here we can search by these criteria
+ */
+IriSP.Model.List.prototype.searchByTitle = function(_text) {
+ var _rgxp = IriSP.Model.regexpFromTextOrArray(_text);
+ return this.filter(function(_element) {
+ return _rgxp.test(_element.title);
+ });
+}
+
+IriSP.Model.List.prototype.searchByDescription = function(_text) {
+ var _rgxp = IriSP.Model.regexpFromTextOrArray(_text);
+ return this.filter(function(_element) {
+ return _rgxp.test(_element.description);
+ });
+}
+
+IriSP.Model.List.prototype.searchByTextFields = function(_text) {
+ var _rgxp = IriSP.Model.regexpFromTextOrArray(_text);
+ return this.filter(function(_element) {
+ return _rgxp.test(_element.description) || _rgxp.test(_element.title);
+ });
+}
+
+IriSP.Model.List.prototype.getTitles = function() {
+ return this.map(function(_el) {
+ return _el.title;
+ });
+}
+
+IriSP.Model.List.prototype.addId = function(_id) {
+ var _el = this.directory.getElement(_id)
+ if (!this.hasId(_id) && typeof _el !== "undefined") {
+ this.idIndex.push(_id);
+ Array.prototype.push.call(this, _el);
+ }
+}
+
+IriSP.Model.List.prototype.push = function(_el) {
+ if (typeof _el === "undefined") {
+ return;
+ }
+ var _index = (IriSP._(this.idIndex).indexOf(_el.id));
+ if (_index === -1) {
+ this.idIndex.push(_el.id);
+ Array.prototype.push.call(this, _el);
+ } else {
+ this[_index] = _el;
+ }
+}
+
+IriSP.Model.List.prototype.addIds = function(_array) {
+ var _l = _array.length,
+ _this = this;
+ IriSP._(_array).forEach(function(_id) {
+ _this.addId(_id);
+ });
+}
+
+IriSP.Model.List.prototype.addElements = function(_array) {
+ var _this = this;
+ IriSP._(_array).forEach(function(_el) {
+ _this.push(_el);
+ });
+}
+
+IriSP.Model.List.prototype.removeId = function(_id, _deleteFromDirectory) {
+ var _deleteFromDirectory = _deleteFromDirectory || false,
+ _index = (IriSP._(this.idIndex).indexOf(_id));
+ if (_index !== -1) {
+ this.splice(_index,1);
+ }
+ if (_deleteFromDirectory) {
+ delete this.directory.elements[_id];
+ }
+}
+
+IriSP.Model.List.prototype.removeElement = function(_el, _deleteFromDirectory) {
+ var _deleteFromDirectory = _deleteFromDirectory || false;
+ this.removeId(_el.id);
+}
+
+IriSP.Model.List.prototype.removeIds = function(_list, _deleteFromDirectory) {
+ var _deleteFromDirectory = _deleteFromDirectory || false,
+ _this = this;
+ IriSP._(_list).forEach(function(_id) {
+ _this.removeId(_id);
+ });
+}
+
+IriSP.Model.List.prototype.removeElements = function(_list, _deleteFromDirectory) {
+ var _deleteFromDirectory = _deleteFromDirectory || false,
+ _this = this;
+ IriSP._(_list).forEach(function(_el) {
+ _this.removeElement(_el);
+ });
+}
+
+/* A simple time management object, that helps converting millisecs to seconds and strings,
+ * without the clumsiness of the original Date object.
+ */
+
+IriSP.Model.Time = function(_milliseconds) {
+ this.milliseconds = 0;
+ this.setMilliseconds(_milliseconds);
+}
+
+IriSP.Model.Time.prototype.setMilliseconds = function(_milliseconds) {
+ var _ante = _milliseconds;
+ switch(typeof _milliseconds) {
+ case "string":
+ this.milliseconds = parseFloat(_milliseconds);
+ break;
+ case "number":
+ this.milliseconds = _milliseconds;
+ break;
+ case "object":
+ this.milliseconds = parseFloat(_milliseconds.valueOf());
+ break;
+ default:
+ this.milliseconds = 0;
+ }
+ if (this.milliseconds === NaN) {
+ this.milliseconds = _ante;
+ }
+}
+
+IriSP.Model.Time.prototype.setSeconds = function(_seconds) {
+ this.milliseconds = 1000 * _seconds;
+}
+
+IriSP.Model.Time.prototype.getSeconds = function() {
+ return Math.floor(this.milliseconds / 1000);
+}
+
+IriSP.Model.Time.prototype.getHMS = function() {
+ var _totalSeconds = Math.abs(this.getSeconds());
+ return {
+ hours : Math.floor(_totalSeconds / 3600),
+ minutes : (Math.floor(_totalSeconds / 60) % 60),
+ seconds : _totalSeconds % 60
+ }
+}
+
+IriSP.Model.Time.prototype.add = function(_milliseconds) {
+ this.milliseconds += new IriSP.Model.Time(_milliseconds).milliseconds;
+}
+
+IriSP.Model.Time.prototype.valueOf = function() {
+ return this.milliseconds;
+}
+
+IriSP.Model.Time.prototype.toString = function() {
+ function pad(_n) {
+ var _res = _n.toString();
+ while (_res.length < 2) {
+ _res = '0' + _res;
+ }
+ return _res;
+ }
+ var _hms = this.getHMS(),
+ _res = '';
+ if (_hms.hours) {
+ _res += pad(_hms.hours) + ':'
+ }
+ _res += pad(_hms.minutes) + ':' + pad(_hms.seconds);
+ return _res;
+}
+
+/* IriSP.Model.Reference handles references between elements
+ */
+
+IriSP.Model.Reference = function(_source, _idRef) {
+ this.source = _source;
+ if (typeof _idRef === "object") {
+ this.isList = true;
+ this.id = IriSP._(_idRef).map(function(_id) {
+ return _source.getNamespaced(_id).fullname;
+ });
+ } else {
+ this.isList = false;
+ this.id = _source.getNamespaced(_idRef).fullname;
+ }
+ this.refresh();
+}
+
+IriSP.Model.Reference.prototype.refresh = function() {
+ if (this.isList) {
+ this.contents = new IriSP.Model.List(this.source.directory);
+ this.contents.addIds(this.id);
+ } else {
+ this.contents = this.source.directory.getElement(this.id);
+ }
+
+}
+
+IriSP.Model.Reference.prototype.getContents = function() {
+ if (typeof this.contents === "undefined" || (this.isList && this.contents.length != this.id.length)) {
+ this.refresh();
+ }
+ return this.contents;
+}
+
+IriSP.Model.Reference.prototype.isOrHasId = function(_idRef) {
+ if (this.isList) {
+ return (IriSP._(this.id).indexOf(_idRef) !== -1)
+ } else {
+ return (this.id == _idRef);
+ }
+}
+
+/* */
+
+IriSP.Model.Element = function(_id, _source) {
+ this.elementType = 'element';
+ if (typeof _source === "undefined") {
+ return;
+ }
+ if (typeof _id === "undefined" || !_id) {
+ _id = IriSP.Model.getUID();
+ }
+ this.source = _source;
+ this.namespacedId = _source.getNamespaced(_id)
+ this.id = this.namespacedId.fullname;
+ this.title = "";
+ this.description = "";
+ this.source.directory.addElement(this);
+}
+
+IriSP.Model.Element.prototype.toString = function() {
+ return this.elementType + (this.elementType !== 'element' ? ', id=' + this.id + ', title="' + this.title + '"' : '');
+}
+
+IriSP.Model.Element.prototype.setReference = function(_elementType, _idRef) {
+ this[_elementType] = new IriSP.Model.Reference(this.source, _idRef);
+}
+
+IriSP.Model.Element.prototype.getReference = function(_elementType) {
+ if (typeof this[_elementType] !== "undefined") {
+ return this[_elementType].getContents();
+ }
+}
+
+IriSP.Model.Element.prototype.getRelated = function(_elementType, _global) {
+ _global = (typeof _global !== "undefined" && _global);
+ var _this = this;
+ return this.source.getList(_elementType, _global).filter(function(_el) {
+ var _ref = _el[_this.elementType];
+ return _ref.isOrHasId(_this.id);
+ });
+}
+
+/* */
+
+IriSP.Model.Media = function(_id, _source) {
+ IriSP.Model.Element.call(this, _id, _source);
+ this.elementType = 'media';
+ this.duration = new IriSP.Model.Time();
+ this.video = '';
+}
+
+IriSP.Model.Media.prototype = new IriSP.Model.Element();
+
+IriSP.Model.Media.prototype.setDuration = function(_durationMs) {
+ this.duration.setMilliseconds(_durationMs);
+}
+
+IriSP.Model.Media.prototype.getAnnotations = function() {
+ return this.getRelated("annotation");
+}
+
+IriSP.Model.Media.prototype.getAnnotationsByTypeTitle = function(_title) {
+ var _annTypes = this.source.getAnnotationTypes().searchByTitle(_title).pluck("id");
+ if (_annTypes.length) {
+ return this.getAnnotations().filter(function(_annotation) {
+ return IriSP._(_annTypes).indexOf(_annotation.getAnnotationType().id) !== -1;
+ });
+ } else {
+ return new IriSP.Model.List(this.source.directory)
+ }
+}
+
+/* */
+
+IriSP.Model.Tag = function(_id, _source) {
+ IriSP.Model.Element.call(this, _id, _source);
+ this.elementType = 'tag';
+}
+
+IriSP.Model.Tag.prototype = new IriSP.Model.Element();
+
+IriSP.Model.Tag.prototype.getAnnotations = function() {
+ return this.getRelated("annotation");
+}
+
+/* */
+
+IriSP.Model.AnnotationType = function(_id, _source) {
+ IriSP.Model.Element.call(this, _id, _source);
+ this.elementType = 'annotationType';
+}
+
+IriSP.Model.AnnotationType.prototype = new IriSP.Model.Element();
+
+IriSP.Model.AnnotationType.prototype.getAnnotations = function() {
+ return this.getRelated("annotation");
+}
+
+/* Annotation
+ * */
+
+IriSP.Model.Annotation = function(_id, _source) {
+ IriSP.Model.Element.call(this, _id, _source);
+ this.elementType = 'annotation';
+ this.begin = new IriSP.Model.Time();
+ this.end = new IriSP.Model.Time();
+}
+
+IriSP.Model.Annotation.prototype = new IriSP.Model.Element(null);
+
+IriSP.Model.Annotation.prototype.setBegin = function(_beginMs) {
+ this.begin.setMilliseconds(_beginMs);
+}
+
+IriSP.Model.Annotation.prototype.setEnd = function(_beginMs) {
+ this.end.setMilliseconds(_beginMs);
+}
+
+IriSP.Model.Annotation.prototype.setMedia = function(_idRef) {
+ this.setReference("media", _idRef);
+}
+
+IriSP.Model.Annotation.prototype.getMedia = function() {
+ return this.getReference("media");
+}
+
+IriSP.Model.Annotation.prototype.setAnnotationType = function(_idRef) {
+ this.setReference("annotationType", _idRef);
+}
+
+IriSP.Model.Annotation.prototype.getAnnotationType = function() {
+ return this.getReference("annotationType");
+}
+
+IriSP.Model.Annotation.prototype.setTags = function(_idRefs) {
+ this.setReference("tag", _idRefs);
+}
+
+IriSP.Model.Annotation.prototype.getTags = function() {
+ return this.getReference("tag");
+}
+
+IriSP.Model.Annotation.prototype.getTagTexts = function() {
+ return this.getTags().getTitles();
+}
+
+IriSP.Model.Annotation.prototype.getDuration = function() {
+ return new IriSP.Model.Time(this.end.milliseconds - this.begin.milliseconds)
+}
+
+/* */
+
+IriSP.Model.MashedAnnotation = function(_mashup, _annotation) {
+ IriSP.Model.Element.call(this, _mashup.namespacedId.name + "_" + _annotation.namespacedId.name, _annotation.source);
+ this.elementType = 'mashedAnnotation';
+ this.annotation = _annotation;
+ this.begin = new IriSP.Model.Time(_mashup.duration);
+ this.end = new IriSP.Model.Time(_mashup.duration + _annotation.getDuration());
+ this.title = this.annotation.title;
+ this.description = this.annotation.description;
+ this.color = this.annotation.color;
+}
+
+IriSP.Model.MashedAnnotation.prototype = new IriSP.Model.Element(null);
+
+IriSP.Model.MashedAnnotation.prototype.getMedia = function() {
+ return this.annotation.getReference("media");
+}
+
+IriSP.Model.MashedAnnotation.prototype.getAnnotationType = function() {
+ return this.annotation.getReference("annotationType");
+}
+
+IriSP.Model.MashedAnnotation.prototype.getTags = function() {
+ return this.annotation.getReference("tag");
+}
+
+IriSP.Model.MashedAnnotation.prototype.getTagTexts = function() {
+ return this.annotation.getTags().getTitles();
+}
+
+/* */
+
+IriSP.Model.Mashup = function(_id, _source) {
+ IriSP.Model.Element.call(this, _id, _source);
+ this.elementType = 'mashup';
+ this.duration = new IriSP.Model.Time();
+ this.segments = new IriSP.Model.List(_source.directory);
+ this.medias = new IriSP.Model.List(_source.directory);
+}
+
+IriSP.Model.Mashup.prototype = new IriSP.Model.Element();
+
+IriSP.Model.Mashup.prototype.addSegment = function(_annotation) {
+ var _mashedAnnotation = new IriSP.Model.MashedAnnotation(this, _annotation);
+ this.duration.setMilliseconds(_mashedAnnotation.end);
+ this.segments.push(_mashedAnnotation);
+ this.medias.push(_annotation.getMedia());
+}
+
+IriSP.Model.Mashup.prototype.addSegmentById = function(_elId) {
+ var _annotation = this.source.getElement(_elId);
+ if (typeof _annotation !== "undefined") {
+ this.addSegment(_annotation);
+ }
+}
+
+IriSP.Model.Mashup.prototype.getAnnotations = function() {
+ return this.segments;
+}
+
+IriSP.Model.Mashup.prototype.getMedias = function() {
+ return this.medias;
+}
+
+IriSP.Model.Mashup.prototype.getAnnotationsByTypeTitle = function(_title) {
+ var _annTypes = this.source.getAnnotationTypes().searchByTitle(_title).pluck("id");
+ if (_annTypes.length) {
+ return this.getAnnotations().filter(function(_annotation) {
+ return IriSP._(_annTypes).indexOf(_annotation.getAnnotationType().id) !== -1;
+ });
+ } else {
+ return new IriSP.Model.List(this.source.directory)
+ }
+}
+
+IriSP.Model.Mashup.prototype.getAnnotationAtTime = function(_time) {
+ var _list = this.segments.filter(function(_annotation) {
+ return _annotation.begin <= _time && _annotation.end > _time;
+ });
+ if (_list.length) {
+ return _list[0];
+ } else {
+ return undefined;
+ }
+}
+
+IriSP.Model.Mashup.prototype.getMediaAtTime = function(_time) {
+ var _annotation = this.getAnnotationAtTime(_time);
+ if (typeof _annotation !== "undefined") {
+ return _annotation.getMedia();
+ } else {
+ return undefined;
+ }
+}
+
+/* */
+
+IriSP.Model.Source = function(_config) {
+ this.status = IriSP.Model._SOURCE_STATUS_EMPTY;
+ if (typeof _config !== "undefined") {
+ var _this = this;
+ IriSP._(_config).forEach(function(_v, _k) {
+ _this[_k] = _v;
+ })
+ this.callbackQueue = [];
+ this.contents = {};
+ if (typeof this.namespace === "undefined") {
+ this.namespace = "metadataplayer";
+ } else {
+ if (typeof this.namespaceUrl === "undefined" && typeof this.url !== "undefined") {
+ var _matches = this.url.match(/(^[^?&]+|[^?&][a-zA-Z0-9_%=?]+)/g),
+ _url = _matches[0];
+ if (_matches.length > 1) {
+ _matches = IriSP._(_matches.slice(1)).reject(function(_txt) {
+ return /\?$/.test(_txt);
+ });
+ }
+ if (_matches.length > 0) {
+ _url += '?' + _matches.join('&');
+ }
+ this.namespaceUrl = _url;
+ }
+ }
+ if (typeof this.namespaceUrl === "undefined") {
+ this.namespaceUrl = "http://ldt.iri.centrepompidou.fr/";
+ }
+ this.directory.addNamespace(this.namespace, this.namespaceUrl);
+ this.get();
+ }
+}
+
+IriSP.Model.Source.prototype.getNamespaced = function(_id) {
+ var _tab = _id.split(':');
+ if (_tab.length > 1) {
+ return {
+ namespace : _tab[0],
+ name : _tab[1],
+ fullname : _id
+ }
+ } else {
+ return {
+ namespace : this.namespace,
+ name : _id,
+ fullname : this.namespace + ':' + _id
+ }
+ }
+}
+
+IriSP.Model.Source.prototype.unNamespace = function(_id) {
+ if (typeof _id !== "undefined") {
+ return _id.replace(this.namespace + ':', '');
+ }
+}
+
+IriSP.Model.Source.prototype.addList = function(_listId, _contents) {
+ if (typeof this.contents[_listId] === "undefined") {
+ this.contents[_listId] = new IriSP.Model.List(this.directory);
+ }
+ this.contents[_listId].addElements(_contents);
+}
+
+IriSP.Model.Source.prototype.getList = function(_listId, _global) {
+ _global = (typeof _global !== "undefined" && _global);
+ if (_global || typeof this.contents[_listId] === "undefined") {
+ return this.directory.getGlobalList().filter(function(_e) {
+ return (_e.elementType === _listId);
+ });
+ } else {
+ return this.contents[_listId];
+ }
+}
+
+IriSP.Model.Source.prototype.forEach = function(_callback) {
+ var _this = this;
+ IriSP._(this.contents).forEach(function(_value, _key) {
+ _callback.call(_this, _value, _key);
+ })
+}
+
+IriSP.Model.Source.prototype.getElement = function(_elId) {
+ return this.directory.getElement(this.getNamespaced(_elId).fullname);
+}
+
+IriSP.Model.Source.prototype.setCurrentMediaId = function(_idRef) {
+ if (typeof _idRef !== "undefined") {
+ this.currentMedia = this.getElement(_idRef);
+ }
+}
+
+IriSP.Model.Source.prototype.setDefaultCurrentMedia = function() {
+ if (typeof this.currentMedia === "undefined" && this.getMedias().length) {
+ this.currentMedia = this.getMedias()[0];
+ }
+}
+
+IriSP.Model.Source.prototype.listNamespaces = function(_excludeSelf) {
+ var _this = this,
+ _nsls = [],
+ _excludeSelf = (typeof _excludeSelf !== "undefined" && _excludeSelf);
+ this.forEach(function(_list) {
+ IriSP._(_list).forEach(function(_el) {
+ var _ns = _el.id.replace(/:.*$/,'');
+ if (IriSP._(_nsls).indexOf(_ns) === -1 && (!_excludeSelf || _ns !== _this.namespace)) {
+ _nsls.push(_ns);
+ }
+ })
+ });
+ return _nsls;
+}
+
+IriSP.Model.Source.prototype.get = function() {
+ this.status = IriSP.Model._SOURCE_STATUS_WAITING;
+ this.handleCallbacks();
+}
+
+/* We defer the callbacks calls so they execute after the queue is cleared */
+IriSP.Model.Source.prototype.deferCallback = function(_callback) {
+ var _this = this;
+ IriSP._.defer(function() {
+ _callback.call(_this);
+ });
+}
+
+IriSP.Model.Source.prototype.handleCallbacks = function() {
+ this.status = IriSP.Model._SOURCE_STATUS_READY;
+ while (this.callbackQueue.length) {
+ this.deferCallback(this.callbackQueue.splice(0,1)[0]);
+ }
+}
+IriSP.Model.Source.prototype.onLoad = function(_callback) {
+ if (this.status === IriSP.Model._SOURCE_STATUS_READY) {
+ this.deferCallback(_callback);
+ } else {
+ this.callbackQueue.push(_callback);
+ }
+}
+
+IriSP.Model.Source.prototype.serialize = function() {
+ return this.serializer.serialize(this);
+}
+
+IriSP.Model.Source.prototype.deSerialize = function(_data) {
+ this.serializer.deSerialize(_data, this);
+}
+
+IriSP.Model.Source.prototype.getAnnotations = function(_global) {
+ _global = (typeof _global !== "undefined" && _global);
+ return this.getList("annotation", _global);
+}
+
+IriSP.Model.Source.prototype.getMedias = function(_global) {
+ _global = (typeof _global !== "undefined" && _global);
+ return this.getList("media", _global);
+}
+
+IriSP.Model.Source.prototype.getTags = function(_global) {
+ _global = (typeof _global !== "undefined" && _global);
+ return this.getList("tag", _global);
+}
+
+IriSP.Model.Source.prototype.getMashups = function(_global) {
+ _global = (typeof _global !== "undefined" && _global);
+ return this.getList("mashup", _global);
+}
+
+IriSP.Model.Source.prototype.getAnnotationTypes = function(_global) {
+ _global = (typeof _global !== "undefined" && _global);
+ return this.getList("annotationType", _global);
+}
+
+IriSP.Model.Source.prototype.getAnnotationsByTypeTitle = function(_title, _global) {
+ _global = (typeof _global !== "undefined" && _global);
+ var _res = new IriSP.Model.List(this.directory),
+ _annTypes = this.getAnnotationTypes(_global).searchByTitle(_title);
+ _annTypes.forEach(function(_annType) {
+ _res.addElements(_annType.getAnnotations(_global));
+ })
+ return _res;
+}
+
+IriSP.Model.Source.prototype.getDuration = function() {
+ var _m = this.currentMedia;
+ if (typeof _m !== "undefined") {
+ return this.currentMedia.duration;
+ }
+}
+
+IriSP.Model.Source.prototype.merge = function(_source) {
+ var _this = this;
+ _source.forEach(function(_value, _key) {
+ _this.getList(_key).addElements(_value);
+ });
+}
+
+/* */
+
+IriSP.Model.RemoteSource = function(_config) {
+ IriSP.Model.Source.call(this, _config);
+}
+
+IriSP.Model.RemoteSource.prototype = new IriSP.Model.Source();
+
+IriSP.Model.RemoteSource.prototype.get = function() {
+ this.status = IriSP.Model._SOURCE_STATUS_WAITING;
+ var _this = this;
+ this.serializer.loadData(this.url, function(_result) {
+ _this.deSerialize(_result);
+ _this.handleCallbacks();
+ });
+}
+
+/* */
+
+IriSP.Model.Directory = function() {
+ this.remoteSources = {};
+ this.elements = {};
+ this.namespaces = {};
+}
+
+IriSP.Model.Directory.prototype.addNamespace = function(_namespace, _url) {
+ this.namespaces[_namespace] = _url;
+}
+
+IriSP.Model.Directory.prototype.remoteSource = function(_properties) {
+ var _config = IriSP._({ directory: this }).extend(_properties);
+ if (typeof this.remoteSources[_properties.url] === "undefined") {
+ this.remoteSources[_properties.url] = new IriSP.Model.RemoteSource(_config);
+ }
+ return this.remoteSources[_properties.url];
+}
+
+IriSP.Model.Directory.prototype.newLocalSource = function(_properties) {
+ var _config = IriSP._({ directory: this }).extend(_properties),
+ _res = new IriSP.Model.Source(_config);
+ return _res;
+}
+
+IriSP.Model.Directory.prototype.getElement = function(_id) {
+ return this.elements[_id];
+}
+
+IriSP.Model.Directory.prototype.addElement = function(_element) {
+ this.elements[_element.id] = _element;
+}
+
+IriSP.Model.Directory.prototype.getGlobalList = function() {
+ var _res = new IriSP.Model.List(this);
+ _res.addIds(IriSP._(this.elements).keys());
+ return _res;
+}
+
+/* */
--- a/src/widgets/Annotation.js Fri Jun 08 19:03:03 2012 +0200
+++ b/src/widgets/Annotation.js Tue Jun 12 19:44:20 2012 +0200
@@ -77,7 +77,7 @@
this.lastAnnotation = _annotation.id;
var _url = (typeof _annotation.url !== "undefined"
? _annotation.url
- : (document.location.href.replace(/#.*$/,'') + '#id=' + _annotation.namespacedId.name));
+ : (document.location.href.replace(/#.*$/,'') + '#id=' + _annotation.id));
var _text = this.l10n.watching + _annotation.title + (this.site_name ? this.l10n.on_site + this.site_name : '');
var _tags = _annotation.getTagTexts();
if (_tags.length) {
--- a/src/widgets/AnnotationsList.js Fri Jun 08 19:03:03 2012 +0200
+++ b/src/widgets/AnnotationsList.js Tue Jun 12 19:44:20 2012 +0200
@@ -84,7 +84,7 @@
this.lastAjaxQuery = _currentTime;
_currentTime = Math.floor(1000 * _currentTime);
var _url = Mustache.to_html(this.ajax_url, {
- media : this.source.currentMedia.namespacedId.name,
+ media : this.source.currentMedia.id,
begin : Math.max(0, _currentTime - this.ajax_granularity),
end : Math.min(_duration.milliseconds, _currentTime + this.ajax_granularity)
});
@@ -99,11 +99,11 @@
_currentTime = 0;
}
var _currentAnnotation = this.source.currentMedia.getAnnotationAtTime(_currentTime * 1000);
- if (typeof _currentAnnotation !== "undefined" && _currentAnnotation.namespacedId.name !== this.lastMashupAnnotation) {
- this.lastMashupAnnotation = _currentAnnotation.namespacedId.name;
+ if (typeof _currentAnnotation !== "undefined" && _currentAnnotation.id !== this.lastMashupAnnotation) {
+ this.lastMashupAnnotation = _currentAnnotation.id;
var _currentMedia = _currentAnnotation.getMedia(),
_url = Mustache.to_html(this.ajax_url, {
- media : _currentMedia.namespacedId.name,
+ media : _currentMedia.id,
begin : Math.max(0, _currentAnnotation.annotation.begin.milliseconds - this.ajax_granularity),
end : Math.min(_currentMedia.duration.milliseconds, _currentAnnotation.annotation.end.milliseconds + this.ajax_granularity)
});
@@ -129,9 +129,9 @@
var _currentAnnotation = this.source.currentMedia.getAnnotationAtTime(_currentTime * 1000);
if (typeof _currentAnnotation !== "undefined") {
_currentTime = _currentTime - _currentAnnotation.begin.getSeconds() + _currentAnnotation.annotation.begin.getSeconds();
- var _mediaId = _currentAnnotation.getMedia().namespacedId.name;
+ var _mediaId = _currentAnnotation.getMedia().id;
_list = _list.filter(function(_annotation) {
- return _annotation.getMedia().namespacedId.name === _mediaId;
+ return _annotation.getMedia().id === _mediaId;
});
}
}
@@ -169,15 +169,15 @@
{
project : _annotation.project,
media : _annotation.media.id.replace(/^.*:/,''),
- annotation : _annotation.namespacedId.name,
+ annotation : _annotation.id,
annotationType : _annotation.annotationType.id.replace(/^.*:/,'')
}
)
- : '#id=' + _annotation.namespacedId.name
+ : '#id=' + _annotation.id
)
);
var _res = {
- id : _annotation.namespacedId.name,
+ id : _annotation.id,
title : _annotation.title.replace(_annotation.description,''),
description : _annotation.description,
begin : _annotation.begin.toString(),
--- a/src/widgets/CreateAnnotation.js Fri Jun 08 19:03:03 2012 +0200
+++ b/src/widgets/CreateAnnotation.js Tue Jun 12 19:44:20 2012 +0200
@@ -259,6 +259,7 @@
},
error: function(_xhr, _error, _thrown) {
IriSP.log("Error when sending annotation", _thrown);
+ _export.getAnnotations().removeElement(_annotation, true);
_this.showScreen('Error');
window.setTimeout(function(){
_this.showScreen("Main")
--- a/src/widgets/MediaList.js Fri Jun 08 19:03:03 2012 +0200
+++ b/src/widgets/MediaList.js Tue Jun 12 19:44:20 2012 +0200
@@ -66,7 +66,7 @@
this.$.find('.Ldt-MediaList-Now-Description').html(_media.description);
var _url = _media.url || Mustache.to_html(
this.media_url_template, {
- media: _media.namespacedId.name
+ media: _media.id
});
this.$.find('.Ldt-MediaList-NowContainer a').attr("href", _url);
} else {
@@ -84,7 +84,7 @@
thumbnail: _media.thumbnail || _this.default_thumbnail,
url: _media.url || Mustache.to_html(
_this.media_url_template, {
- media: _media.namespacedId.name
+ media: _media.id
}),
title: _media.title,
description: _media.description
--- a/src/widgets/Mediafragment.js Fri Jun 08 19:03:03 2012 +0200
+++ b/src/widgets/Mediafragment.js Tue Jun 12 19:44:20 2012 +0200
@@ -65,7 +65,7 @@
}
IriSP.Widgets.Mediafragment.prototype.setHashToAnnotation = function(_annotationId) {
- this.setHash( 'id', this.source.unNamespace(_annotationId) );
+ this.setHash( 'id', _annotationId );
}
IriSP.Widgets.Mediafragment.prototype.setHashToTime = function(_time) {
--- a/src/widgets/Polemic.js Fri Jun 08 19:03:03 2012 +0200
+++ b/src/widgets/Polemic.js Tue Jun 12 19:44:20 2012 +0200
@@ -169,13 +169,13 @@
var _y = _this.height;
_slice.annotations.forEach(function(_annotation) {
_y -= _this.element_height;
- displayElement(_x, _y, _this.defaultcolor, _annotation.namespacedId.name, _annotation.title);
+ displayElement(_x, _y, _this.defaultcolor, _annotation.id, _annotation.title);
});
IriSP._(_slice.polemicStacks).forEach(function(_annotations, _j) {
var _color = _this.polemics[_j].color;
_annotations.forEach(function(_annotation) {
_y -= _this.element_height;
- displayElement(_x, _y, _color, _annotation.namespacedId.name, _annotation.title);
+ displayElement(_x, _y, _color, _annotation.id, _annotation.title);
});
});
_x += _this.element_width;
--- a/src/widgets/Segments.js Fri Jun 08 19:03:03 2012 +0200
+++ b/src/widgets/Segments.js Tue Jun 12 19:44:20 2012 +0200
@@ -51,7 +51,7 @@
left : Math.floor( _left ),
width : Math.floor( _width ),
center : Math.floor( _center ),
- id : _annotation.namespacedId.name
+ id : _annotation.id
}
})
}));
--- a/test/jwplayer.htm Fri Jun 08 19:03:03 2012 +0200
+++ b/test/jwplayer.htm Tue Jun 12 19:44:20 2012 +0200
@@ -17,6 +17,7 @@
<script type="text/javascript">
IriSP.libFiles.locations.jwPlayerSWF = "player.swf";
IriSP.libFiles.defaultDir = "libs/";
+ IriSP.language = 'fr';
IriSP.widgetsDir = "metadataplayer";
var _metadata = {
url: 'json/ldt-jwplayer.json',
@@ -31,7 +32,6 @@
},
css : 'metadataplayer/LdtPlayer-core.css',
widgets: [
- { type: "Sparkline" },
{ type: "Slider" },
{ type: "Controller" },
{ type: "Polemic" },
@@ -39,15 +39,14 @@
{ type: "Slice" },
{ type: "Arrow" },
{ type: "Annotation" },
-/* {
+ {
type: "CreateAnnotation",
api_endpoint_template: "http://192.168.56.101/pf/ldtplatform/api/ldt/annotations/{{id}}.json",
creator_name: "Metadataplayer"
- }, */
+ },
{ type: "Tweet" },
{
- type: "Tagcloud",
- segment_annotation_type: "chap"
+ type: "Tagcloud"
},
{
type: "AnnotationsList",