# HG changeset patch # User veltr # Date 1335547101 -7200 # Node ID f11b234497f7f57ebd388edac2ed93c4d6d58a6f # Parent 4c7b33bf2795de530c015781fdcbc79b67f282dc Finished Mediafragment diff -r 4c7b33bf2795 -r f11b234497f7 src/js/init.js --- a/src/js/init.js Thu Apr 26 19:18:57 2012 +0200 +++ b/src/js/init.js Fri Apr 27 19:18:21 2012 +0200 @@ -44,7 +44,7 @@ /* widget specific requirements */ for(var _i = 0; _i < this.config.gui.widgets.length; _i++) { - if(this.config.gui.widgets[_i].type === "Sparkline") { + if(this.config.gui.widgets[_i].type === "Sparkline" || this.config.gui.widgets[_i].type === "Arrow") { $L.script(IriSP.getLib("raphael")); } if(this.config.gui.widgets[_i].type === "TraceWidget") { diff -r 4c7b33bf2795 -r f11b234497f7 src/js/model.js --- a/src/js/model.js Thu Apr 26 19:18:57 2012 +0200 +++ b/src/js/model.js Fri Apr 27 19:18:21 2012 +0200 @@ -73,9 +73,14 @@ IriSP.Model.List.prototype = new Array(); IriSP.Model.List.prototype.getElement = function(_id) { - var _index = (IriSP._(this.idIndex).indexOf(this.source.getNamespaced(_id).fullName)); + var _index = IriSP._(this.idIndex).indexOf(_id); if (_index !== -1) { return this[_index]; + } else { + var _un = _id.replace(/.*:/); + return IriSP._(this.idIndex).find(function(_i) { + return _i.replace(/.*:/) === _un; + }); } } @@ -538,7 +543,7 @@ } IriSP.Model.Source.prototype.getElement = function(_elId) { - return this.directory.getElement(_this.getNamespaced(_elId).fullname); + return this.directory.getElement(this.getNamespaced(_elId).fullname); } IriSP.Model.Source.prototype.setCurrentMediaId = function(_idRef) { @@ -680,7 +685,18 @@ } IriSP.Model.Directory.prototype.getElement = function(_id) { - return this.elements[_id]; + var _res = this.elements[_id]; + if (typeof _res === "undefined") { + var _un = _id.replace(/.*:/), + _keys = IriSP._(this.elements).keys(); + _key = IriSP._(_keys).find(function(_i) { + return _i.replace(/.*:/) === _un; + }); + if (typeof _key !== "undefined") { + _res = this.elements[_key]; + } + } + return _res; } IriSP.Model.Directory.prototype.addElement = function(_element) { diff -r 4c7b33bf2795 -r f11b234497f7 src/js/modules/mediafragment.js --- a/src/js/modules/mediafragment.js Thu Apr 26 19:18:57 2012 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,121 +0,0 @@ -/* mediafragment module */ - -IriSP.MediaFragment = function(Popcorn, config, Serializer) { - IriSP.Module.call(this, Popcorn, config, Serializer); - - this.mutex = false; /* a mutex because we access the url from two different functions */ - - this._Popcorn.listen( "loadedmetadata", IriSP.wrap(this,this.advanceTime)); - this._Popcorn.listen( "pause", IriSP.wrap(this,this.updateTime)); - this._Popcorn.listen( "seeked", IriSP.wrap(this,this.updateTime)); - this._Popcorn.listen( "IriSP.PolemicTweet.click", IriSP.wrap(this,this.updateAnnotation)); - this._Popcorn.listen( "IriSP.SegmentsWidget.click", IriSP.wrap(this,this.updateAnnotation)); - - window.onhashchange = IriSP.wrap(this, this.advanceTime); -}; - -IriSP.MediaFragment.prototype = new IriSP.Module(); - -IriSP.MediaFragment.prototype.advanceTime = function() { - var url = window.location.href; - - if ( url.split( "#" )[ 1 ] != null ) { - pageoffset = url.split( "#" )[1]; - - if ( pageoffset.substring(0, 2) === "t=") { - // timecode - if ( pageoffset.substring( 2 ) != null ) { - var offsettime = pageoffset.substring( 2 ); - this._Popcorn.currentTime( parseFloat(offsettime) ); - - /* we have to trigger this signal manually because of a - bug in the jwplayer */ - this._Popcorn.trigger("seeked", parseFloat(offsettime)); - } - } else if ( pageoffset.substring(0, 3) === "id=") { - // annotation - var annotationId = pageoffset.substring( 3 ); - // there's no better way than that because - // of possible race conditions - this._serializer.sync(IriSP.wrap(this, function() { - this.lookupAnnotation.call(this, annotationId); - })); - } - } -}; - -/** handler for the seeked signal. It may have or may have not an argument. - @param time if not undefined, the time we're seeking to -*/ -IriSP.MediaFragment.prototype.updateTime = function(time) { - if (this.mutex === true) { - return; - } - - var history = window.history; - if ( !history.pushState ) { - return false; - } - - if (IriSP.null_or_undefined(time) || typeof(time) != "number") { - var ntime = this._Popcorn.currentTime().toFixed(2) - } else { - var ntime = time.toFixed(2); - } - - // used to relay the new hash to the embedder - this._Popcorn.trigger("IriSP.Mediafragment.hashchange", "#t=" + ntime); - - splitArr = window.location.href.split( "#" ) - history.replaceState( {}, "", splitArr[0] + "#t=" + ntime ); -}; - - -IriSP.MediaFragment.prototype.updateAnnotation = function(annotationId) { - var _this = this; - this.mutex = true; - - var history = window.history; - if ( !history.pushState ) { - return false; - } - - - // used to relay the new hash to the embedder - this._Popcorn.trigger("IriSP.Mediafragment.hashchange", "#id=" + annotationId); - - splitArr = window.location.href.split( "#" ) - history.replaceState( {}, "", splitArr[0] + "#id=" + annotationId); - - - // reset the mutex afterwards to prevent the module from reacting to his own changes. - window.setTimeout(function() { _this.mutex = false }, 50); -}; - -// lookup and seek to the beginning of an annotation -IriSP.MediaFragment.prototype.lookupAnnotation = function(annotationId) { - var _this = this; - this.mutex = true; - - var annotation = undefined; - var annotations = this._serializer._data.annotations; - - var i; - for (i = 0; i < annotations.length; i++) { - if (annotations[i].id === annotationId) { - annotation = annotations[i]; - break; - } - } - - if (typeof(annotation) !== "undefined") { - this._Popcorn.currentTime(annotation.begin / 1000); - - /* we have to trigger this signal manually because of a - bug in the jwplayer */ - this._Popcorn.trigger("seeked", annotation.begin / 1000); - this._Popcorn.trigger("IriSP.Mediafragment.showAnnotation", annotationId); - } - - window.setTimeout(function() { _this.mutex = false }, 50); -}; diff -r 4c7b33bf2795 -r f11b234497f7 src/js/widgets/sliceWidget.js --- a/src/js/widgets/sliceWidget.js Thu Apr 26 19:18:57 2012 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,163 +0,0 @@ -/** A widget to create a new segment */ -IriSP.SliceWidget = function(Popcorn, config, Serializer) { - IriSP.Widget.call(this, Popcorn, config, Serializer); - -}; - -IriSP.SliceWidget.prototype = new IriSP.Widget(); - -IriSP.SliceWidget.prototype.draw = function() { - var templ = Mustache.to_html(IriSP.sliceWidget_template); - this.selector.append(templ); - - this.sliceZone = this.selector.find(".Ldt-sliceZone"); - - /* global variables used to keep the position and width - of the zone. - */ - this.zoneLeft = 0; - this.zoneWidth = 0; - - this.leftHandle = this.selector.find(".Ldt-sliceLeftHandle"); - this.rightHandle = this.selector.find(".Ldt-sliceRightHandle"); - - var left = this.selector.offset().left; - var top = this.selector.offset().top; - - // a bug in firefox makes it use the wrong format - if (!IriSP.jQuery.browser.mozilla) { - // contain the handles correctly - we cannot set - // containment: parent because it wouldn't allow to select the - // whole slice, so we have to compute a box in which the slice is - // allowed to move. - var containment = [left - 8, top, this.selector.width() + left, top]; - - // var containment = [left - 16, top, this.selector.width() + left - 8, top]; - this.leftHandle.draggable({axis: "x", - drag: IriSP.wrap(this, this.leftHandleDragged), - containment: containment - }); - - containment = [left, top, this.selector.width() + left, top]; - // containment = [left, top, this.selector.width() + left - 8, top]; - this.rightHandle.draggable({axis: "x", - drag: IriSP.wrap(this, this.rightHandleDragged), - containment: containment - }); - - } else { // firefox - // we need to define a containment specific to firefox. - - var containment = [left - 16, top, this.selector.width() + left - 8, top]; - this.leftHandle.draggable({axis: "x", - drag: IriSP.wrap(this, this.leftHandleDragged), - containment: containment - }); - - containment = [left, top, this.selector.width() + left - 8, top]; - this.rightHandle.draggable({axis: "x", - drag: IriSP.wrap(this, this.rightHandleDragged), - containment: containment - }); - } - - this.leftHandle.css("position", "absolute"); - this.rightHandle.css("position", "absolute"); - - this._Popcorn.listen("IriSP.SliceWidget.position", - IriSP.wrap(this, this.positionSliceHandler)); - - this._Popcorn.listen("IriSP.SliceWidget.show", IriSP.wrap(this, this.show)); - this._Popcorn.listen("IriSP.SliceWidget.hide", IriSP.wrap(this, this.hide)); - this.selector.hide(); -}; - -/** responds to an "IriSP.SliceWidget.position" message - @param params an array with the first element being the left distance in - percents and the second element the width of the slice in pixels -*/ -IriSP.SliceWidget.prototype.positionSliceHandler = function(params) { - left = params[0]; - width = params[1]; - - this.zoneLeft = left; - this.zoneWidth = width; - this.sliceZone.css("left", left + "px"); - this.sliceZone.css("width", width + "px"); - this.leftHandle.css("left", (left - 7) + "px"); - this.rightHandle.css("left", left + width + "px"); - - this._leftHandleOldLeft = left - 7; - this._rightHandleOldLeft = left + width; -}; - -/** handle a dragging of the left handle */ -IriSP.SliceWidget.prototype.leftHandleDragged = function(event, ui) { - /* we have a special variable, this._leftHandleOldLeft, to keep the - previous position of the handle. We do that to know in what direction - is the handle being dragged - */ - - var currentX = this.leftHandle.offset().left; - var rightHandleX = Math.floor(this.rightHandle.position()["left"]); - - var container_offset = this.selector.offset().left; - - if (Math.floor(ui.position.left) >= rightHandleX - 7) { - /* prevent the handle from moving past the right handle */ - ui.position.left = rightHandleX - 7; - } - - this.zoneWidth = rightHandleX - Math.floor(ui.position.left) - 7; - this.zoneLeft = Math.floor(ui.position.left) + 8; - - this.sliceZone.css("width", this.zoneWidth); - this.sliceZone.css("left", this.zoneLeft + "px"); - - this._leftHandleOldLeft = ui.position.left; - this.broadcastChanges(); - -}; - -/** handle a dragging of the right handle */ -IriSP.SliceWidget.prototype.rightHandleDragged = function(event, ui) { - /* we have a special variable, this._leftHandleOldLeft, to keep the - previous position of the handle. We do that to know in what direction - is the handle being dragged - */ - - var currentX = this.leftHandle.position()["left"]; - var leftHandleX = Math.floor(this.leftHandle.position()["left"]); - - var container_offset = this.selector.offset().left + this.selector.width(); - - if (Math.floor(ui.position.left) < leftHandleX + 7) { - /* prevent the handle from moving past the left handle */ - ui.position.left = leftHandleX + 7; - } - - this.zoneWidth = Math.floor(ui.position.left) - (leftHandleX + 7); - - this.sliceZone.css("width", this.zoneWidth); - //this.sliceZone.css("left", this.zoneLeft + "px"); - this._rightHandleOldLeft = Math.floor(this._rightHandleOldLeft); - this.broadcastChanges(); -}; - -/** tell to the world that the coordinates of the slice have - changed -*/ -IriSP.SliceWidget.prototype.broadcastChanges = function() { - var leftPercent = (this.zoneLeft / this.selector.width()) * 100; - var zonePercent = (this.zoneWidth / this.selector.width()) * 100; - - this._Popcorn.trigger("IriSP.SliceWidget.zoneChange", [leftPercent, zonePercent]); -}; - -IriSP.SliceWidget.prototype.show = function() { - this.selector.show(); -}; - -IriSP.SliceWidget.prototype.hide = function() { - this.selector.hide(); -}; \ No newline at end of file diff -r 4c7b33bf2795 -r f11b234497f7 src/js/widgets/tagCloudWidget.js --- a/src/js/widgets/tagCloudWidget.js Thu Apr 26 19:18:57 2012 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,96 +0,0 @@ -IriSP.TagCloudWidget = function(Popcorn, config, Serializer) { - IriSP.Widget.call(this, Popcorn, config, Serializer); -} - -IriSP.TagCloudWidget.prototype = new IriSP.Widget(); - -IriSP.TagCloudWidget.prototype.draw = function() { - - var _urlRegExp = /https?:\/\/[0-9a-zA-Z\.%\/-_]+/g, - _stopWords = [ - 'aussi', 'and', 'avec', 'aux', 'bien', 'car', 'cette', 'comme', 'dans', 'donc', 'des', 'elle', 'encore', 'entre', 'est', - 'être', 'eux', 'faire', 'fait', 'http', 'ici', 'ils', 'les', 'leur', 'leurs', 'mais', 'mes', 'même', 'mon', 'notre', - 'non', 'nos', 'nous', 'ont', 'par', 'pas', 'peu', 'peut', 'plus', 'pour', 'que', 'qui', 'sans', 'ses' ,'son', 'sont', 'sur', - 'tes', 'très', 'the', 'ton', 'tous', 'tout', 'une', 'votre', 'vos', 'vous' ], - _regexpword = /[^\s\.&;,'"!\?\d\(\)\+\[\]\\\…\-«»:\/]{3,}/g, - _words = {}, - _showTitle = !this._config.excludeTitle, - _showDescription = !this._config.excludeDescription, - _excludePattern = this._config.excludePattern || null, - _tagCount = this._config.tagCount || 30; - if (typeof this._config.excludeWords !== "undefined" && this._config.excludeWords.length) { - IriSP._(this._config.excludeWords).each(function(_w) { - _stopWords.push(_w.toLowerCase()); - }); - } - - IriSP._(this._serializer._data.annotations).each(function(_annotation) { - if (_annotation.content && _annotation.content.description) { - var _txt = (_showTitle ? _annotation.content.title : '') + ' ' + (_showDescription ? _annotation.content.description : '') - IriSP._(_txt.toLowerCase().replace(_urlRegExp, '').match(_regexpword)).each(function(_mot) { - if (_stopWords.indexOf(_mot) == -1 && (_excludePattern == null || !_excludePattern.test(_mot))) { - _words[_mot] = 1 + (_words[_mot] || 0); - } - }) - } - }); - - _words = IriSP._(_words) - .chain() - .map(function(_v, _k) { - return { - "word" : _k, - "count" : _v - } - }) - .filter(function(_v) { - return _v.count > 2; - }) - .sortBy(function(_v) { - return - _v.count; - }) - .first(_tagCount) - .value(); - var _max = _words[0].count, - _min = Math.min(_words[_words.length - 1].count, _max - 1), - _scale = 16 / Math.sqrt(_max - _min), - _this = this, - _html = '