diff -r 76efa2333f31 -r 3ec2343f2b85 integration/js/model.js --- a/integration/js/model.js Tue Nov 06 18:49:13 2012 +0100 +++ b/integration/js/model.js Thu Nov 08 18:24:47 2012 +0100 @@ -2,32 +2,28 @@ /* model.js is where data is stored in a standard form, whatever the serializer */ IriSP.Model = (function (ns) { + + function pad(n, x, b) { + b = b || 10; + var s = (x).toString(b); + while (s.length < n) { + s = "0" + s; + } + return s; + } + + function rand16(n) { + return pad(n, Math.floor(Math.random()*Math.pow(16,n)), 16); + } + + var uidbase = rand16(8) + "-" + rand16(4) + "-", uidincrement = Math.floor(Math.random()*0x10000); var 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 _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 + }).forEach(function(_a) { + _a.playing = true; + _a.trigger("enter"); + _this.trigger("enter-annotation",_a); + }); }); } @@ -541,22 +543,7 @@ this.elementType = 'media'; this.duration = new Model.Time(); this.video = ''; - var _this = this; - this.on("timeupdate", function(_time) { - _this.getAnnotations().filter(function(_a) { - return (_a.end <= _time || _a.begin > _time) && _a.playing - }).forEach(function(_a) { - _a.playing = false; - _a.trigger("leave"); - }); - _this.getAnnotations().filter(function(_a) { - return _a.begin <= _time && _a.end > _time && !_a.playing - }).forEach(function(_a) { - _a.playing = true; - _a.trigger("enter"); - }); - }); } Model.Media.prototype = new Model.Playable(); @@ -737,30 +724,7 @@ this.duration = new Model.Time(); this.segments = new Model.List(_source.directory); this.loaded = false; - var _currentMedia = null; var _this = this; - this.on("timeupdate", function(_time) { - _this.getSegments().filter(function(_a) { - return (_a.end <= _time || _a.begin > _time) && _a.playing - }).forEach(function(_a) { - _a.playing = false; - _a.trigger("leave"); - }); - _this.getSegments().filter(function(_a) { - return _a.begin <= _time && _a.end > _time && !_a.playing - }).forEach(function(_a) { - _a.playing = true; - _a.trigger("enter"); - var _m = _a.getMedia(); - if (_m !== _currentMedia) { - if (_currentMedia) { - _currentMedia.trigger("leave"); - } - _m.trigger("enter"); - _currentMedia = _m; - } - }); - }); this._updateTimes = function() { _this.updateTimes(); _this.trigger("change"); @@ -880,7 +844,7 @@ }); } -Model.Mashup.prototype.getSegments = function() { +Model.Mashup.prototype.getAnnotations = function() { return this.segments; }