# HG changeset patch # User hamidouk # Date 1321287566 -3600 # Node ID 6008172a05927aa48f5d3408684ca38f1c0d3c23 # Parent 8f99b0df327810ef893f8870f8acd3c850de5d22 converted all the source files to use the require.js syntax. diff -r 8f99b0df3278 -r 6008172a0592 src/js/IriSP.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/js/IriSP.js Mon Nov 14 17:19:26 2011 +0100 @@ -0,0 +1,6 @@ +/* IriSP.js - the module every module depends on. */ + +if ( window.IriSP === undefined && window.__IriSP === undefined ) { + var IriSP = {}; + var __IriSP = IriSP; /* for backward compatibility */ +} \ No newline at end of file diff -r 8f99b0df3278 -r 6008172a0592 src/js/data.js --- a/src/js/data.js Mon Nov 14 16:12:13 2011 +0100 +++ b/src/js/data.js Mon Nov 14 17:19:26 2011 +0100 @@ -1,157 +1,158 @@ /* data.js - this file deals with how the players gets and sends data */ - -IriSP.DataLoader = function() { - this._cache = {}; -}; +define(["IriSP"], function() { + IriSP.DataLoader = function() { + this._cache = {}; + }; -IriSP.DataLoader.prototype.get = function(url, callback) { - if (this._cache.hasOwnProperty(url)) { - callback(this._cache[url]); - } else { - /* we need a closure because this gets lost when it's called back */ - IriSP.jQuery.get(url, callback); - /* - IriSP.jQuery.get(url, (function(obj) { - return function(data) { - obj._cache[url] = data; - callback(obj._cache[url]); - }; - })(this)); - */ - + IriSP.DataLoader.prototype.get = function(url, callback) { + if (this._cache.hasOwnProperty(url)) { + callback(this._cache[url]); + } else { + /* we need a closure because this gets lost when it's called back */ + IriSP.jQuery.get(url, callback); + /* + IriSP.jQuery.get(url, (function(obj) { + return function(data) { + obj._cache[url] = data; + callback(obj._cache[url]); + }; + })(this)); + */ + + } } -} -/* the base abstract "class" */ -IriSP.Serializer = function(DataLoader, url) { - this._DataLoader = DataLoader; - this._url = url; - this._data = []; -}; + /* the base abstract "class" */ + IriSP.Serializer = function(DataLoader, url) { + this._DataLoader = DataLoader; + this._url = url; + this._data = []; + }; -IriSP.Serializer.prototype.serialize = function(data) { }; -IriSP.Serializer.prototype.deserialize = function(data) {}; + IriSP.Serializer.prototype.serialize = function(data) { }; + IriSP.Serializer.prototype.deserialize = function(data) {}; -IriSP.Serializer.prototype.currentMedia = function() { -}; + IriSP.Serializer.prototype.currentMedia = function() { + }; -IriSP.Serializer.prototype.sync = function(callback) { - callback.call(this, this._data); -}; + IriSP.Serializer.prototype.sync = function(callback) { + callback.call(this, this._data); + }; -IriSP.SerializerFactory = function(DataLoader) { - this._dataloader = DataLoader; -}; + IriSP.SerializerFactory = function(DataLoader) { + this._dataloader = DataLoader; + }; -IriSP.SerializerFactory.prototype.getSerializer = function(metadataOptions) { - /* This function returns serializer set-up with the correct - configuration - takes a metadata struct describing the metadata source - */ - - if (metadataOptions === undefined) - /* return an empty serializer */ - return IriSP.Serializer("", ""); - - switch(metadataOptions.type) { - case "json": - return new IriSP.JSONSerializer(this._dataloader, metadataOptions.src); - break; + IriSP.SerializerFactory.prototype.getSerializer = function(metadataOptions) { + /* This function returns serializer set-up with the correct + configuration - takes a metadata struct describing the metadata source + */ - case "dummy": /* only used for unit testing - not defined in production */ - return new IriSP.MockSerializer(this._dataloader, metadataOptions.src); - break; - - case "empty": - return new IriSP.Serializer("", "empty"); - break; + if (metadataOptions === undefined) + /* return an empty serializer */ + return IriSP.Serializer("", ""); + + switch(metadataOptions.type) { + case "json": + return new IriSP.JSONSerializer(this._dataloader, metadataOptions.src); + break; - default: - return undefined; - } -}; + case "dummy": /* only used for unit testing - not defined in production */ + return new IriSP.MockSerializer(this._dataloader, metadataOptions.src); + break; + + case "empty": + return new IriSP.Serializer("", "empty"); + break; + + default: + return undefined; + } + }; -IriSP.getMetadata = function() { - - IriSP.jQuery.ajax({ - dataType: IriSP.config.metadata.load, - url:IriSP.config.metadata.src, - success : function( json ){ - - IriSP.trace( "ajax", "success" ); - - // START PARSING ----------------------- - if( json === "" ){ - alert( "Json load error" ); - } else { - // # CREATE MEDIA // - // # JUSTE ONE PLAYER FOR THE MOMENT // - //__IriSP.jQuery("
").appendTo("#output"); - var MyMedia = new __IriSP.Media( - json.medias[0].id, - json.medias[0].href, - json.medias[0]['meta']['dc:duration'], - json.medias[0]['dc:title'], - json.medias[0]['dc:description']); - - IriSP.trace( "__IriSP.MyApiPlayer", - IriSP.config.gui.width+" " - + IriSP.config.gui.height + " " - + json.medias[0].href + " " - + json.medias[0]['meta']['dc:duration'] + " " - + json.medias[0]['meta']['item']['value']); - - // Create APIplayer - IriSP.MyApiPlayer = new __IriSP.APIplayer ( - IriSP.config.gui.width, - IriSP.config.gui.height, - json.medias[0].href, - json.medias[0]['meta']['dc:duration'], - json.medias[0]['meta']['item']['value']); - - // # CREATE THE FIRST LINE // - IriSP.trace( "__IriSP.init.main","__IriSP.Ligne" ); - IriSP.MyLdt = new __IriSP.Ligne( - json['annotation-types'][0].id, - json['annotation-types'][0]['dc:title'], - json['annotation-types'][0]['dc:description'], - json.medias[0]['meta']['dc:duration']); - - // CREATE THE TAG CLOUD // - IriSP.trace( "__IriSP.init.main","__IriSP.Tags" ); - IriSP.MyTags = new __IriSP.Tags( json.tags ); - - // CREATE THE ANNOTATIONS // - // JUSTE FOR THE FIRST TYPE // - /* FIXME: make it support more than one ligne de temps */ - IriSP.jQuery.each( json.annotations, function(i,item) { - if (item.meta['id-ref'] == IriSP.MyLdt.id) { - //__IriSP.trace("__IriSP.init.main","__IriSP.MyLdt.addAnnotation"); - IriSP.MyLdt.addAnnotation( - item.id, - item.begin, - item.end, - item.media, - item.content.title, - item.content.description, - item.content.color, - item.tags); - } - //MyTags.addAnnotation(item); - } ); - IriSP.jQuery.each( json.lists, function(i,item) { - IriSP.trace("lists",""); - } ); - IriSP.jQuery.each( json.views, function(i,item) { - IriSP.trace("views",""); - } ); - } - // END PARSING ----------------------- // - - - }, error : function(data){ - alert("ERROR : "+data); - } - }); + IriSP.getMetadata = function() { + + IriSP.jQuery.ajax({ + dataType: IriSP.config.metadata.load, + url:IriSP.config.metadata.src, + success : function( json ){ + + IriSP.trace( "ajax", "success" ); + + // START PARSING ----------------------- + if( json === "" ){ + alert( "Json load error" ); + } else { + // # CREATE MEDIA // + // # JUSTE ONE PLAYER FOR THE MOMENT // + //__IriSP.jQuery("
").appendTo("#output"); + var MyMedia = new __IriSP.Media( + json.medias[0].id, + json.medias[0].href, + json.medias[0]['meta']['dc:duration'], + json.medias[0]['dc:title'], + json.medias[0]['dc:description']); + + IriSP.trace( "__IriSP.MyApiPlayer", + IriSP.config.gui.width+" " + + IriSP.config.gui.height + " " + + json.medias[0].href + " " + + json.medias[0]['meta']['dc:duration'] + " " + + json.medias[0]['meta']['item']['value']); + + // Create APIplayer + IriSP.MyApiPlayer = new __IriSP.APIplayer ( + IriSP.config.gui.width, + IriSP.config.gui.height, + json.medias[0].href, + json.medias[0]['meta']['dc:duration'], + json.medias[0]['meta']['item']['value']); + + // # CREATE THE FIRST LINE // + IriSP.trace( "__IriSP.init.main","__IriSP.Ligne" ); + IriSP.MyLdt = new __IriSP.Ligne( + json['annotation-types'][0].id, + json['annotation-types'][0]['dc:title'], + json['annotation-types'][0]['dc:description'], + json.medias[0]['meta']['dc:duration']); + + // CREATE THE TAG CLOUD // + IriSP.trace( "__IriSP.init.main","__IriSP.Tags" ); + IriSP.MyTags = new __IriSP.Tags( json.tags ); + + // CREATE THE ANNOTATIONS // + // JUSTE FOR THE FIRST TYPE // + /* FIXME: make it support more than one ligne de temps */ + IriSP.jQuery.each( json.annotations, function(i,item) { + if (item.meta['id-ref'] == IriSP.MyLdt.id) { + //__IriSP.trace("__IriSP.init.main","__IriSP.MyLdt.addAnnotation"); + IriSP.MyLdt.addAnnotation( + item.id, + item.begin, + item.end, + item.media, + item.content.title, + item.content.description, + item.content.color, + item.tags); + } + //MyTags.addAnnotation(item); + } ); + IriSP.jQuery.each( json.lists, function(i,item) { + IriSP.trace("lists",""); + } ); + IriSP.jQuery.each( json.views, function(i,item) { + IriSP.trace("views",""); + } ); + } + // END PARSING ----------------------- // + + + }, error : function(data){ + alert("ERROR : "+data); + } + }); -} \ No newline at end of file + } +}); \ No newline at end of file diff -r 8f99b0df3278 -r 6008172a0592 src/js/init.js --- a/src/js/init.js Mon Nov 14 16:12:13 2011 +0100 +++ b/src/js/init.js Mon Nov 14 17:19:26 2011 +0100 @@ -3,92 +3,94 @@ */ -IriSP.configurePopcorn = function (layoutManager, options) { - var pop; - var containerDiv = layoutManager.createDiv(); - - switch(options.type) { - /* - todo : dynamically create the div/video tag which - will contain the video. - */ - case "html5": - var tmpId = Popcorn.guid("video"); - IriSP.jQuery("#" + containerDiv).append(""); - pop = Popcorn("#" + tmpId).mediafragment({start : 0}); - break; - - case "jwplayer": - var opts = IriSP.jQuery.extend({}, options); - delete opts.container; - pop = Popcorn.jwplayer("#" + containerDiv, "", opts).mediafragment({start : 0}); - break; +define(["IriSP"], function() { + IriSP.configurePopcorn = function (layoutManager, options) { + var pop; + var containerDiv = layoutManager.createDiv(); - case "youtube": - var opts = IriSP.jQuery.extend({}, options); - delete opts.container; - opts.controls = 0; - opts.autostart = false; - templ = "width: {{width}}px; height: {{height}}px;"; - var str = Mustache.to_html(templ, {width: opts.width, height: opts.height}); - // Popcorn.youtube wants us to specify the size of the player in the style attribute of its container div. - IriSP.jQuery("#" + containerDiv).attr("style", str); + switch(options.type) { + /* + todo : dynamically create the div/video tag which + will contain the video. + */ + case "html5": + var tmpId = Popcorn.guid("video"); + IriSP.jQuery("#" + containerDiv).append(""); + pop = Popcorn("#" + tmpId).mediafragment({start : 0}); + break; - pop = Popcorn.youtube("#" + containerDiv, opts.video, opts).mediafragment({start : 0}); - break; + case "jwplayer": + var opts = IriSP.jQuery.extend({}, options); + delete opts.container; + pop = Popcorn.jwplayer("#" + containerDiv, "", opts).mediafragment({start : 0}); + break; - default: - pop = undefined; - }; - - return pop; -}; - -IriSP.configureWidgets = function (popcornInstance, layoutManager, guiOptions) { - - var dt = new IriSP.DataLoader(); - var serialFactory = new IriSP.SerializerFactory(dt); - - var params = {width: guiOptions.width, height: guiOptions.height}; - - var ret_widgets = []; - var index; - - for (index = 0; index < guiOptions.widgets.length; index++) { - var widgetConfig = guiOptions.widgets[index]; - var widget = IriSP.instantiateWidget(popcornInstance, serialFactory, layoutManager, widgetConfig); - ret_widgets.push(widget); - + case "youtube": + var opts = IriSP.jQuery.extend({}, options); + delete opts.container; + opts.controls = 0; + opts.autostart = false; + templ = "width: {{width}}px; height: {{height}}px;"; + var str = Mustache.to_html(templ, {width: opts.width, height: opts.height}); + // Popcorn.youtube wants us to specify the size of the player in the style attribute of its container div. + IriSP.jQuery("#" + containerDiv).attr("style", str); + + pop = Popcorn.youtube("#" + containerDiv, opts.video, opts).mediafragment({start : 0}); + break; + + default: + pop = undefined; + }; + + return pop; }; - return ret_widgets; -}; + IriSP.configureWidgets = function (popcornInstance, layoutManager, guiOptions) { -IriSP.instantiateWidget = function(popcornInstance, serialFactory, layoutManager, widgetConfig) { - var container = layoutManager.createDiv(); - var arr = IriSP.jQuery.extend({}, widgetConfig); - arr.container = container; + var dt = new IriSP.DataLoader(); + var serialFactory = new IriSP.SerializerFactory(dt); - var serializer = serialFactory.getSerializer(widgetConfig.metadata); - - if (typeof serializer == "undefined") - debugger; - - // instantiate the object passed as a string - var widget = new IriSP[widgetConfig.type](popcornInstance, arr, serializer); + var params = {width: guiOptions.width, height: guiOptions.height}; + + var ret_widgets = []; + var index; - if (widgetConfig.hasOwnProperty("requires")) { - // also create the widgets this one depends on. - // the dependency widget is available in the parent widget context as - // this.WidgetName (for instance, this.TipWidget); + for (index = 0; index < guiOptions.widgets.length; index++) { + var widgetConfig = guiOptions.widgets[index]; + var widget = IriSP.instantiateWidget(popcornInstance, serialFactory, layoutManager, widgetConfig); + ret_widgets.push(widget); + + }; + + return ret_widgets; + }; + + IriSP.instantiateWidget = function(popcornInstance, serialFactory, layoutManager, widgetConfig) { + var container = layoutManager.createDiv(); + var arr = IriSP.jQuery.extend({}, widgetConfig); + arr.container = container; + + var serializer = serialFactory.getSerializer(widgetConfig.metadata); + + if (typeof serializer == "undefined") + debugger; - var i = 0; - for(i = 0; i < widgetConfig.requires.length; i++) { - var widgetName = widgetConfig.requires[i]["type"]; - widget[widgetName] = IriSP.instantiateWidget(popcornInstance, serialFactory, layoutManager, widgetConfig.requires[i]); - } - } - - serializer.sync(IriSP.wrap(widget, function() { this.draw(); })); - return widget; -}; \ No newline at end of file + // instantiate the object passed as a string + var widget = new IriSP[widgetConfig.type](popcornInstance, arr, serializer); + + if (widgetConfig.hasOwnProperty("requires")) { + // also create the widgets this one depends on. + // the dependency widget is available in the parent widget context as + // this.WidgetName (for instance, this.TipWidget); + + var i = 0; + for(i = 0; i < widgetConfig.requires.length; i++) { + var widgetName = widgetConfig.requires[i]["type"]; + widget[widgetName] = IriSP.instantiateWidget(popcornInstance, serialFactory, layoutManager, widgetConfig.requires[i]); + } + } + + serializer.sync(IriSP.wrap(widget, function() { this.draw(); })); + return widget; + }; +}); \ No newline at end of file diff -r 8f99b0df3278 -r 6008172a0592 src/js/layout.js --- a/src/js/layout.js Mon Nov 14 16:12:13 2011 +0100 +++ b/src/js/layout.js Mon Nov 14 17:19:26 2011 +0100 @@ -1,59 +1,61 @@ /* layout.js - very basic layout management */ -/* - a layout manager manages a div and the layout of objects - inside it. -*/ +define(["IriSP"], function() { + /* + a layout manager manages a div and the layout of objects + inside it. + */ -IriSP.LayoutManager = function(options) { - this._Popcorn = null; - this._widgets = []; - - this._div = "LdtPlayer"; - this._width = 640; - - if (options === undefined) { - options = {}; - }; - - if (options.hasOwnProperty('container')) { - this._div = options.container; - } + IriSP.LayoutManager = function(options) { + this._Popcorn = null; + this._widgets = []; + + this._div = "LdtPlayer"; + this._width = 640; + + if (options === undefined) { + options = {}; + }; + + if (options.hasOwnProperty('container')) { + this._div = options.container; + } - if (options.hasOwnProperty('width')) { - this._width = options.width; - } - - if (options.hasOwnProperty('height')) { - this._height = options.height; - } - - /* this is a shortcut */ - this.selector = IriSP.jQuery("#" + this._div); - - this.selector.css("width", this._width); - - if (this._height !== undefined) - this.selector.css("height", this._height); -}; + if (options.hasOwnProperty('width')) { + this._width = options.width; + } + + if (options.hasOwnProperty('height')) { + this._height = options.height; + } + + /* this is a shortcut */ + this.selector = IriSP.jQuery("#" + this._div); + + this.selector.css("width", this._width); + + if (this._height !== undefined) + this.selector.css("height", this._height); + }; -/* we need this special setter because of a chicken and egg problem : - we want the manager to use popcorn but the popcorn div will be managed - by the manager. So we need a way to set the instance the manager uses -*/ - -IriSP.LayoutManager.prototype.setPopcornInstance = function(popcorn) { - this._Popcorn = popcorn; - /* FIXME - don't forget to add the popcorn messages handlers there */ -} + /* we need this special setter because of a chicken and egg problem : + we want the manager to use popcorn but the popcorn div will be managed + by the manager. So we need a way to set the instance the manager uses + */ + + IriSP.LayoutManager.prototype.setPopcornInstance = function(popcorn) { + this._Popcorn = popcorn; + /* FIXME - don't forget to add the popcorn messages handlers there */ + } -IriSP.LayoutManager.prototype.createDiv = function() { - var newDiv = Popcorn.guid(this._div + "_widget_"); - this._widgets.push(newDiv); + IriSP.LayoutManager.prototype.createDiv = function() { + var newDiv = Popcorn.guid(this._div + "_widget_"); + this._widgets.push(newDiv); - var templ = "
1) { - tweet_annot_type = view.annotation_types[1]; - } - - for(var i = 0; i < json.annotations.length; i++) { - var item = json.annotations[i]; - var MyTime = Math.floor(item.begin/duration*lineSize); - var Myframe = Math.floor(MyTime/lineSize*frameLength); + function loaded_callback (json) { - if (typeof(item.meta) !== "undefined" - && typeof(item.meta["id-ref"]) !== "undefined" - && item.meta["id-ref"] === tweet_annot_type) { - - var MyTJson = JSON.parse(item.meta['dc:source']['content']); + // get current view (the first ???) + view = json.views[0]; - if (item.content['polemics'] != undefined - && item.content['polemics'][0] != null) { - + // the tweets are by definition of the second annotation type FIXME ? + tweet_annot_type = null; + if(typeof(view.annotation_types) !== "undefined" && view.annotation_types.length > 1) { + tweet_annot_type = view.annotation_types[1]; + } + + for(var i = 0; i < json.annotations.length; i++) { + var item = json.annotations[i]; + var MyTime = Math.floor(item.begin/duration*lineSize); + var Myframe = Math.floor(MyTime/lineSize*frameLength); + + if (typeof(item.meta) !== "undefined" + && typeof(item.meta["id-ref"]) !== "undefined" + && item.meta["id-ref"] === tweet_annot_type) { + + var MyTJson = JSON.parse(item.meta['dc:source']['content']); - for(var j=0; j max) { - max = moy; - } - } - - var tweetDrawed = new Array(); - var TweetHeight = 5; - // DRAW TWEETS ============================================ - for(var i = 0; i < nbrframes; i++) { - var addEheight = 5; - if (frames[i] != undefined){ - // by type + // GROUPES TWEET ============================================ + // max of tweet by Frame + var max = 0; + for(var i = 0; i < nbrframes; i++) { + var moy = 0; + for (var j = 0; j < 6; j++) { + if (frames[i] != undefined) { + if (frames[i].qualifVol[j] != undefined) { + moy += frames[i].qualifVol[j]; + } + } + } - for (var j = 6; j > -1; j--) { - if (frames[i].qualifVol[j] != undefined) { - // show tweet by type - for (var k = 0; k < frames[i].mytweetsID.length; k++) { - - if (frames[i].mytweetsID[k].qualification == j) { - var x = i * frameSize; - var y = this.heightmax - addEheight; - - if (this.yMax > y) { - this.yMax = y; + if (moy > max) { + max = moy; + } + } + + var tweetDrawed = new Array(); + var TweetHeight = 5; + + // DRAW TWEETS ============================================ + for(var i = 0; i < nbrframes; i++) { + var addEheight = 5; + if (frames[i] != undefined){ + // by type + + for (var j = 6; j > -1; j--) { + if (frames[i].qualifVol[j] != undefined) { + // show tweet by type + for (var k = 0; k < frames[i].mytweetsID.length; k++) { + + if (frames[i].mytweetsID[k].qualification == j) { + var x = i * frameSize; + var y = this.heightmax - addEheight; + + if (this.yMax > y) { + this.yMax = y; + } + + var e = this.paper.rect(x, y, frameSize - margin, TweetHeight /* height */).attr({stroke:"#00","stroke-width":0.1, fill: colors[j]}); + this.svgElements.push(e); + + addEheight += TweetHeight; + + e.time= frames[i].mytweetsID[k].timeframe; + e.title= frames[i].mytweetsID[k].title; + + e.mouseover(function(element) { return function (event) { + // event.clientX and event.clientY are to raphael what event.pageX and pageY are to jquery. + self.TooltipWidget.show.call(self.TooltipWidget, element.title, element.attr("fill"), event.clientX - 106, event.clientY - 160); + element.displayed = true; + debugger; + }}(e)).mouseout(function(element) { return function () { + self.TooltipWidget.hide.call(self.TooltipWidget); + }}(e)).mousedown(function () { + self._Popcorn.currentTime(this.time/1000); + }); + + IriSP.jQuery(e.node).attr('id', 't' + k + ''); + IriSP.jQuery(e.node).attr('title', frames[i].mytweetsID[k].title); + IriSP.jQuery(e.node).attr('begin', frames[i].mytweetsID[k].timeframe); } - - var e = this.paper.rect(x, y, frameSize - margin, TweetHeight /* height */).attr({stroke:"#00","stroke-width":0.1, fill: colors[j]}); - this.svgElements.push(e); - - addEheight += TweetHeight; - - e.time= frames[i].mytweetsID[k].timeframe; - e.title= frames[i].mytweetsID[k].title; - - e.mouseover(function(element) { return function (event) { - // event.clientX and event.clientY are to raphael what event.pageX and pageY are to jquery. - self.TooltipWidget.show.call(self.TooltipWidget, element.title, element.attr("fill"), event.clientX - 106, event.clientY - 160); - element.displayed = true; - debugger; - }}(e)).mouseout(function(element) { return function () { - self.TooltipWidget.hide.call(self.TooltipWidget); - }}(e)).mousedown(function () { - self._Popcorn.currentTime(this.time/1000); - }); - - IriSP.jQuery(e.node).attr('id', 't' + k + ''); - IriSP.jQuery(e.node).attr('title', frames[i].mytweetsID[k].title); - IriSP.jQuery(e.node).attr('begin', frames[i].mytweetsID[k].timeframe); } } } } - } - } - // DRAW UI :: resize border and bgd - this.paperBackground = this.paper.rect(0, 0, this.width, this.heightmax).attr({fill:"#F8F8F8","stroke-width":0.1,opacity: 1}); - // var PaperBorder = this.paper.rect(0, this.yMax,this.width,1).attr({fill:"#fff",stroke: "none",opacity: 1}); - - this.paperSlider = this.paper.rect(0, 0, 0, this.heightmax).attr({fill:"#D4D5D5", stroke: "none", opacity: 1}); - - // the small white line displayed over the slider. - this.sliderTip = this.paper.rect(0, 0, 1, this.heightmax).attr({fill:"#fc00ff", stroke: "none", opacity: 1}); - - // decalage - // tweetSelection = this.paper.rect(-100,-100,5,5).attr({fill:"#fff",stroke: "none",opacity: 1}); - + } + // DRAW UI :: resize border and bgd + this.paperBackground = this.paper.rect(0, 0, this.width, this.heightmax).attr({fill:"#F8F8F8","stroke-width":0.1,opacity: 1}); + // var PaperBorder = this.paper.rect(0, this.yMax,this.width,1).attr({fill:"#fff",stroke: "none",opacity: 1}); + + this.paperSlider = this.paper.rect(0, 0, 0, this.heightmax).attr({fill:"#D4D5D5", stroke: "none", opacity: 1}); + + // the small white line displayed over the slider. + this.sliderTip = this.paper.rect(0, 0, 1, this.heightmax).attr({fill:"#fc00ff", stroke: "none", opacity: 1}); + + // decalage + // tweetSelection = this.paper.rect(-100,-100,5,5).attr({fill:"#fff",stroke: "none",opacity: 1}); + + + this.paperSlider.toBack(); + this.paperBackground.toBack(); + this.sliderTip.toFront(); + } - this.paperSlider.toBack(); - this.paperBackground.toBack(); - this.sliderTip.toFront(); - } - - this._Popcorn.listen("timeupdate", IriSP.wrap(this, this.sliderUpdater)); -} + this._Popcorn.listen("timeupdate", IriSP.wrap(this, this.sliderUpdater)); + } -IriSP.PolemicWidget.prototype.sliderUpdater = function() { + IriSP.PolemicWidget.prototype.sliderUpdater = function() { - var time = +this._Popcorn.currentTime(); - var duration = +this._serializer.currentMedia().meta["dc:duration"]; - - this.paperSlider.attr("width", time * (this.width / (duration / 1000))); - - this.sliderTip.attr("x", time * (this.width / (duration / 1000))); -}; - - \ No newline at end of file + var time = +this._Popcorn.currentTime(); + var duration = +this._serializer.currentMedia().meta["dc:duration"]; + + this.paperSlider.attr("width", time * (this.width / (duration / 1000))); + + this.sliderTip.attr("x", time * (this.width / (duration / 1000))); + }; +}); + \ No newline at end of file diff -r 8f99b0df3278 -r 6008172a0592 src/js/widgets/segmentsWidget.js --- a/src/js/widgets/segmentsWidget.js Mon Nov 14 16:12:13 2011 +0100 +++ b/src/js/widgets/segmentsWidget.js Mon Nov 14 17:19:26 2011 +0100 @@ -1,148 +1,150 @@ -IriSP.SegmentsWidget = function(Popcorn, config, Serializer) { +define(["IriSP", "widgets", "util", "tooltipWidget"], function() { + IriSP.SegmentsWidget = function(Popcorn, config, Serializer) { - var self = this; - IriSP.Widget.call(this, Popcorn, config, Serializer); - this.oldSearchMatches = []; + var self = this; + IriSP.Widget.call(this, Popcorn, config, Serializer); + this.oldSearchMatches = []; - // event handlers - this._Popcorn.listen("IriSP.search", function(searchString) { self.searchHandler.call(self, searchString); }); - this._Popcorn.listen("IriSP.search.closed", function() { self.searchFieldClosedHandler.call(self); }); - this._Popcorn.listen("IriSP.search.cleared", function() { self.searchFieldClearedHandler.call(self); }); -}; + // event handlers + this._Popcorn.listen("IriSP.search", function(searchString) { self.searchHandler.call(self, searchString); }); + this._Popcorn.listen("IriSP.search.closed", function() { self.searchFieldClosedHandler.call(self); }); + this._Popcorn.listen("IriSP.search.cleared", function() { self.searchFieldClearedHandler.call(self); }); + }; -IriSP.SegmentsWidget.prototype = new IriSP.Widget(); + IriSP.SegmentsWidget.prototype = new IriSP.Widget(); -IriSP.SegmentsWidget.prototype.draw = function() { + IriSP.SegmentsWidget.prototype.draw = function() { - var self = this; - var annotations = this._serializer._data.annotations; + var self = this; + var annotations = this._serializer._data.annotations; - this.selector.css("overflow", "auto"); // clear the floats - FIXME : to refactor ? - this.selector.append(Mustache.to_html(IriSP.overlay_marker_template)); - - this.positionMarker = this.selector.children(":first"); - - this._Popcorn.listen("timeupdate", IriSP.wrap(this, this.positionUpdater)); - - this.selector.after("
"); // we need to do this because the segments are floated - - var i = 0; - var totalWidth = this.selector.width(); - var onePxPercent = 100 / totalWidth; /* the value of a pixel, in percents */ - - for (i = 0; i < annotations.length; i++) { - var annotation = annotations[i]; + this.selector.css("overflow", "auto"); // clear the floats - FIXME : to refactor ? + this.selector.append(Mustache.to_html(IriSP.overlay_marker_template)); + + this.positionMarker = this.selector.children(":first"); + + this._Popcorn.listen("timeupdate", IriSP.wrap(this, this.positionUpdater)); + + this.selector.after("
"); // we need to do this because the segments are floated + + var i = 0; + var totalWidth = this.selector.width(); + var onePxPercent = 100 / totalWidth; /* the value of a pixel, in percents */ + + for (i = 0; i < annotations.length; i++) { + var annotation = annotations[i]; - var begin = Math.round((+ annotation.begin) / 1000); - var end = Math.round((+ annotation.end) / 1000); - var duration = this._serializer.currentMedia().meta["dc:duration"] / 1000; - var id = annotation.id; - var startPourcent = IriSP.timeToPourcent(begin, duration); - - /* some sort of collapsing occurs, so we only have to substract one pixel to each box instead of - two - */ - var endPourcent = IriSP.timeToPourcent(end, duration) - startPourcent - onePxPercent * 1; - - /* on the other hand, we have to substract one pixel from the first box because it's the only - one to have to effective 1px margins */ - if (i == 0) { + var begin = Math.round((+ annotation.begin) / 1000); + var end = Math.round((+ annotation.end) / 1000); + var duration = this._serializer.currentMedia().meta["dc:duration"] / 1000; + var id = annotation.id; + var startPourcent = IriSP.timeToPourcent(begin, duration); + + /* some sort of collapsing occurs, so we only have to substract one pixel to each box instead of + two + */ + var endPourcent = IriSP.timeToPourcent(end, duration) - startPourcent - onePxPercent * 1; + + /* on the other hand, we have to substract one pixel from the first box because it's the only + one to have to effective 1px margins */ + if (i == 0) { - endPourcent -= onePxPercent; - } - - var divTitle = annotation.content.title.substr(0,55); - var color = annotation.content.color + endPourcent -= onePxPercent; + } + + var divTitle = annotation.content.title.substr(0,55); + var color = annotation.content.color - var annotationTemplate = Mustache.to_html(IriSP.annotation_template, - {"divTitle" : divTitle, "id" : id, "startPourcent" : startPourcent, - "endPourcent" : endPourcent, "hexa_color" : IriSP.DEC_HEXA_COLOR(color), - "seekPlace" : Math.round(begin/1000)}); + var annotationTemplate = Mustache.to_html(IriSP.annotation_template, + {"divTitle" : divTitle, "id" : id, "startPourcent" : startPourcent, + "endPourcent" : endPourcent, "hexa_color" : IriSP.DEC_HEXA_COLOR(color), + "seekPlace" : Math.round(begin/1000)}); - var toolTipTemplate = Mustache.to_html(IriSP.tooltip_template, - {"title" : divTitle, "begin" : begin, "end" : end, - "description": annotation.content.description}); + var toolTipTemplate = Mustache.to_html(IriSP.tooltip_template, + {"title" : divTitle, "begin" : begin, "end" : end, + "description": annotation.content.description}); - this.selector.append(annotationTemplate); + this.selector.append(annotationTemplate); - IriSP.jQuery("#" + id).tooltip({ effect: 'slide'}); + IriSP.jQuery("#" + id).tooltip({ effect: 'slide'}); - IriSP.jQuery("#" + id).fadeTo(0, 0.3); + IriSP.jQuery("#" + id).fadeTo(0, 0.3); - IriSP.jQuery("#" + id).mouseover(function() { - IriSP.jQuery("#" + id).animate({opacity: 0.6}, 5); - }).mouseout(function(){ - IriSP.jQuery("#" + id).animate({opacity: 0.3}, 5); - }); + IriSP.jQuery("#" + id).mouseover(function() { + IriSP.jQuery("#" + id).animate({opacity: 0.6}, 5); + }).mouseout(function(){ + IriSP.jQuery("#" + id).animate({opacity: 0.3}, 5); + }); - IriSP.jQuery("#" + id).click(function(_this, annotation) { - return function() { _this.clickHandler(annotation)}; - }(this, annotation)); - } -}; + IriSP.jQuery("#" + id).click(function(_this, annotation) { + return function() { _this.clickHandler(annotation)}; + }(this, annotation)); + } + }; -/* restores the view after a search */ -IriSP.SegmentsWidget.prototype.clear = function() { - // reinit the fields - for (var id in this.oldSearchMatches) { + /* restores the view after a search */ + IriSP.SegmentsWidget.prototype.clear = function() { + // reinit the fields + for (var id in this.oldSearchMatches) { - IriSP.jQuery("#"+id).dequeue(); - IriSP.jQuery("#"+id).animate({height:0}, 100); - IriSP.jQuery("#"+id).css('border-color','lightgray'); - IriSP.jQuery("#"+id).animate({opacity:0.3}, 100); - } -}; + IriSP.jQuery("#"+id).dequeue(); + IriSP.jQuery("#"+id).animate({height:0}, 100); + IriSP.jQuery("#"+id).css('border-color','lightgray'); + IriSP.jQuery("#"+id).animate({opacity:0.3}, 100); + } + }; -IriSP.SegmentsWidget.prototype.clickHandler = function(annotation) { - var begin = Math.round((+ annotation.begin) / 1000); - this._Popcorn.currentTime(begin); -}; + IriSP.SegmentsWidget.prototype.clickHandler = function(annotation) { + var begin = Math.round((+ annotation.begin) / 1000); + this._Popcorn.currentTime(begin); + }; -IriSP.SegmentsWidget.prototype.searchHandler = function(searchString) { + IriSP.SegmentsWidget.prototype.searchHandler = function(searchString) { - if (searchString == "") - return; + if (searchString == "") + return; - var matches = this._serializer.searchOccurences(searchString); + var matches = this._serializer.searchOccurences(searchString); - for (var id in matches) { - var factor = matches[id] * 8; - this.selector.find("#"+id).dequeue(); - this.selector.find("#"+id).animate({height: factor}, 200); - this.selector.find("#"+id).css('border-color','red'); - this.selector.find("#"+id).animate({opacity:0.6}, 200); + for (var id in matches) { + var factor = matches[id] * 8; + this.selector.find("#"+id).dequeue(); + this.selector.find("#"+id).animate({height: factor}, 200); + this.selector.find("#"+id).css('border-color','red'); + this.selector.find("#"+id).animate({opacity:0.6}, 200); - IriSP.jQuery("#LdtSearchInput").css('background-color','#e1ffe1'); - } + IriSP.jQuery("#LdtSearchInput").css('background-color','#e1ffe1'); + } - // clean up the blocks that were in the previous search - // but who aren't in the current one. - for (var id in this.oldSearchMatches) { - if (!matches.hasOwnProperty(id)) { - IriSP.jQuery("#"+id).dequeue(); - IriSP.jQuery("#"+id).animate({height:0}, 250); - IriSP.jQuery("#"+id).animate({opacity:0.3}, 200); - this.selector.find("#"+id).css('border','solid 1px #aaaaaa'); + // clean up the blocks that were in the previous search + // but who aren't in the current one. + for (var id in this.oldSearchMatches) { + if (!matches.hasOwnProperty(id)) { + IriSP.jQuery("#"+id).dequeue(); + IriSP.jQuery("#"+id).animate({height:0}, 250); + IriSP.jQuery("#"+id).animate({opacity:0.3}, 200); + this.selector.find("#"+id).css('border','solid 1px #aaaaaa'); + } } - } - - this.oldSearchMatches = matches; -}; + + this.oldSearchMatches = matches; + }; -IriSP.SegmentsWidget.prototype.searchFieldClearedHandler = function() { - this.clear(); -}; + IriSP.SegmentsWidget.prototype.searchFieldClearedHandler = function() { + this.clear(); + }; -IriSP.SegmentsWidget.prototype.searchFieldClosedHandler = function() { - this.clear(); -}; + IriSP.SegmentsWidget.prototype.searchFieldClosedHandler = function() { + this.clear(); + }; -IriSP.SegmentsWidget.prototype.positionUpdater = function() { - var duration = this._serializer.currentMedia().meta["dc:duration"] / 1000; - var time = this._Popcorn.currentTime(); - var position = ((time / duration) * 100).toFixed(2); + IriSP.SegmentsWidget.prototype.positionUpdater = function() { + var duration = this._serializer.currentMedia().meta["dc:duration"] / 1000; + var time = this._Popcorn.currentTime(); + var position = ((time / duration) * 100).toFixed(2); - this.positionMarker.css("left", position + "%"); -}; \ No newline at end of file + this.positionMarker.css("left", position + "%"); + }; +}); \ No newline at end of file diff -r 8f99b0df3278 -r 6008172a0592 src/js/widgets/sliderWidget.js --- a/src/js/widgets/sliderWidget.js Mon Nov 14 16:12:13 2011 +0100 +++ b/src/js/widgets/sliderWidget.js Mon Nov 14 17:19:26 2011 +0100 @@ -1,52 +1,54 @@ -IriSP.SliderWidget = function(Popcorn, config, Serializer) { - IriSP.Widget.call(this, Popcorn, config, Serializer); -}; +define(["IriSP", "widgets", "util"], function() { + IriSP.SliderWidget = function(Popcorn, config, Serializer) { + IriSP.Widget.call(this, Popcorn, config, Serializer); + }; -IriSP.SliderWidget.prototype = new IriSP.Widget(); + IriSP.SliderWidget.prototype = new IriSP.Widget(); -IriSP.SliderWidget.prototype.draw = function() { - var self = this; - - this.selector.append("
"); - this.sliderBackground = this.selector.children(".sliderBackground"); - - this.selector.append("
"); - this.sliderForeground = this.selector.children(".sliderForeground"); - - this.selector.append(Mustache.to_html(IriSP.overlay_marker_template)); - this.positionMarker = this.selector.children(".positionMarker"); - - this.sliderBackground.click(function(event) { self.clickHandler.call(self, event); }); - - this._Popcorn.listen("timeupdate", IriSP.wrap(this, this.sliderUpdater)); -}; + IriSP.SliderWidget.prototype.draw = function() { + var self = this; + + this.selector.append("
"); + this.sliderBackground = this.selector.children(".sliderBackground"); + + this.selector.append("
"); + this.sliderForeground = this.selector.children(".sliderForeground"); + + this.selector.append(Mustache.to_html(IriSP.overlay_marker_template)); + this.positionMarker = this.selector.children(".positionMarker"); + + this.sliderBackground.click(function(event) { self.clickHandler.call(self, event); }); + + this._Popcorn.listen("timeupdate", IriSP.wrap(this, this.sliderUpdater)); + }; -/* updates the slider as time passes */ -IriSP.SliderWidget.prototype.sliderUpdater = function() { - var time = this._Popcorn.currentTime(); - - var duration = this._serializer.currentMedia().meta["dc:duration"] / 1000; - var percent = ((time / duration) * 100).toFixed(2); - this.sliderForeground.css("width", percent + "%"); - this.positionMarker.css("left", percent + "%"); - -}; + /* updates the slider as time passes */ + IriSP.SliderWidget.prototype.sliderUpdater = function() { + var time = this._Popcorn.currentTime(); + + var duration = this._serializer.currentMedia().meta["dc:duration"] / 1000; + var percent = ((time / duration) * 100).toFixed(2); + this.sliderForeground.css("width", percent + "%"); + this.positionMarker.css("left", percent + "%"); + + }; -IriSP.SliderWidget.prototype.clickHandler = function(event) { - /* this piece of code is a little bit convoluted - here's how it works : - we want to handle clicks on the progress bar and convert those to seeks in the media. - However, jquery only gives us a global position, and we want a number of pixels relative - to our container div, so we get the parent position, and compute an offset to this position, - and finally compute the progress ratio in the media. - Finally we multiply this ratio with the duration to get the correct time - */ - - var parentOffset = this.sliderBackground.parent().offset(); - var width = this.sliderBackground.width(); - var relX = event.pageX - parentOffset.left; - - var duration = this._serializer.currentMedia().meta["dc:duration"] / 1000; - var newTime = ((relX / width) * duration).toFixed(2); - - this._Popcorn.currentTime(newTime); -}; \ No newline at end of file + IriSP.SliderWidget.prototype.clickHandler = function(event) { + /* this piece of code is a little bit convoluted - here's how it works : + we want to handle clicks on the progress bar and convert those to seeks in the media. + However, jquery only gives us a global position, and we want a number of pixels relative + to our container div, so we get the parent position, and compute an offset to this position, + and finally compute the progress ratio in the media. + Finally we multiply this ratio with the duration to get the correct time + */ + + var parentOffset = this.sliderBackground.parent().offset(); + var width = this.sliderBackground.width(); + var relX = event.pageX - parentOffset.left; + + var duration = this._serializer.currentMedia().meta["dc:duration"] / 1000; + var newTime = ((relX / width) * duration).toFixed(2); + + this._Popcorn.currentTime(newTime); + }; +}); \ No newline at end of file diff -r 8f99b0df3278 -r 6008172a0592 src/js/widgets/tooltipWidget.js --- a/src/js/widgets/tooltipWidget.js Mon Nov 14 16:12:13 2011 +0100 +++ b/src/js/widgets/tooltipWidget.js Mon Nov 14 17:19:26 2011 +0100 @@ -1,28 +1,30 @@ /* this widget displays a small tooltip */ -IriSP.TooltipWidget = function(Popcorn, config, Serializer) { - IriSP.Widget.call(this, Popcorn, config, Serializer); -}; +define(["IriSP", "widgets", "util"], function() { + IriSP.TooltipWidget = function(Popcorn, config, Serializer) { + IriSP.Widget.call(this, Popcorn, config, Serializer); + }; -IriSP.TooltipWidget.prototype = new IriSP.Widget(); + IriSP.TooltipWidget.prototype = new IriSP.Widget(); -IriSP.TooltipWidget.prototype.draw = function() { - var templ = Mustache.to_html(IriSP.tooltipWidget_template); + IriSP.TooltipWidget.prototype.draw = function() { + var templ = Mustache.to_html(IriSP.tooltipWidget_template); + + this.selector.append(templ); + this.hide(); - this.selector.append(templ); - this.hide(); - -}; + }; -IriSP.TooltipWidget.prototype.show = function(text, color, x, y) { - if (this.selector.find(".tiptext").text() == text) - return; - - this.selector.find(".tipcolor").css("background-color", color); - this.selector.find(".tiptext").text(text); - this.selector.find(".tip").css("left", x).css("top", y); -}; + IriSP.TooltipWidget.prototype.show = function(text, color, x, y) { + if (this.selector.find(".tiptext").text() == text) + return; + + this.selector.find(".tipcolor").css("background-color", color); + this.selector.find(".tiptext").text(text); + this.selector.find(".tip").css("left", x).css("top", y); + }; -IriSP.TooltipWidget.prototype.hide = function() { - this.selector.find(".tip").css("left", -10000).css("top", -100000); -}; \ No newline at end of file + IriSP.TooltipWidget.prototype.hide = function() { + this.selector.find(".tip").css("left", -10000).css("top", -100000); + }; +}); \ No newline at end of file