# HG changeset patch # User hamidouk # Date 1327937035 -3600 # Node ID 69a9969daa41861aac6182214465e350b2133bab # Parent 9925bc81b8a848a0d582ba2b1a86a1cb3eaec021 better defaults - paths are now computed at run-time. diff -r 9925bc81b8a8 -r 69a9969daa41 src/js/init.js --- a/src/js/init.js Fri Jan 27 17:27:48 2012 +0100 +++ b/src/js/init.js Mon Jan 30 16:23:55 2012 +0100 @@ -207,3 +207,48 @@ serializer.sync(IriSP.wrap(widget, function() { this.draw(); })); return widget; }; + +/** Go through the defaults to set a reasonable value */ +IriSP.configureDefaults = function(libdir, platform_url) { + /* the defaults configuration is messy and complicated. There are two things to know : + - we want to allow overwriting of defaults - that's why we have IriSP.widgetDefaults + and IriSP.defaults.widgetDefaults. The first is filled by the embedder and then fleshed out + with the contents of the first. We use underscore.defaults for that, but there's one problem with + this function : it doesn't work recursively. + - we need to compute some values at runtime instead of at compile time + */ + + IriSP.lib = IriSP.underscore.defaults(IriSP.lib, IriSP.defaults.lib(libdir)); + + /* get the factory defaults for the widgets and merge them with the default the user + may have defined + */ + var factory_defaults = IriSP.defaults.widgetsDefaults(platform_url); + for(var widget in factory_defaults) { + + /* create the object if it doesn't exists */ + if (IriSP.null_or_undefined(IriSP.widgetsDefaults[widget])) + IriSP.widgetsDefaults[widget] = {}; + + IriSP.widgetsDefaults[widget] = IriSP.underscore.defaults(IriSP.widgetsDefaults[widget], factory_defaults[widget]); + } + + IriSP.paths = IriSP.underscore.defaults(IriSP.paths, IriSP.defaults.paths); + IriSP.default_templates_vars = IriSP.underscore.defaults(IriSP.default_templates_vars, + IriSP.defaults.default_templates_vars()); +}; + +/** single point of entry for the metadataplayer */ +IriSP.initPlayer = function(config, metadata_url, libdir, platform_url) { + IriSP.configureDefaults(libdir, platform_url); + IriSP.loadLibs(IriSP.lib, config, metadata_url, + function() { + + var layoutManager = new IriSP.LayoutManager(config.gui); + + var pop = IriSP.configurePopcorn(layoutManager, config.player); + + var widgets = IriSP.configureWidgets(pop, layoutManager, config.gui); + var modules = IriSP.configureModules(pop, config.modules); + }); +}; \ No newline at end of file diff -r 9925bc81b8a8 -r 69a9969daa41 src/js/main.js --- a/src/js/main.js Fri Jan 27 17:27:48 2012 +0100 +++ b/src/js/main.js Mon Jan 30 16:23:55 2012 +0100 @@ -12,6 +12,13 @@ __IriSP = IriSP; } +/* underscore comes bundled with the player and we need + it ASAP, so load it that way +*/ + +IriSP._ = window._.noConflict(); +IriSP.underscore = IriSP._; + IriSP.loadLibs = function( libs, config, metadata_url, callback ) { // Localize jQuery variable IriSP.jQuery = null; @@ -55,8 +62,6 @@ $L.wait(function() { IriSP.jQuery = window.jQuery.noConflict( true ); - IriSP._ = window._.noConflict(); - IriSP.underscore = IriSP._; var css_link_jquery = IriSP.jQuery( "", { rel: "stylesheet", diff -r 9925bc81b8a8 -r 69a9969daa41 src/js/site.js.templ --- a/src/js/site.js.templ Fri Jan 27 17:27:48 2012 +0100 +++ b/src/js/site.js.templ Mon Jan 30 16:23:55 2012 +0100 @@ -1,27 +1,51 @@ /* site.js - all our site-dependent config : player chrome, cdn locations, etc...*/ +IriSP.defaults = {}; + +/* these objects are filled by configureDefaults. The function doesn't overwrite + defaults that were originally defined by the user. +*/ +IriSP.lib = {}; + +/* We need to define those so that the individual settings can be overwritten */ +IriSP.widgetsDefaults = {}; + +IriSP.paths = {}; + IriSP.libdir = "/mdp/src/js/libs/"; IriSP.jwplayer_swf_path = "/mdp/test/libs/player.swf"; IriSP.platform_url = "http://localhost/pf"; +IriSP.default_templates_vars = { }; -IriSP.lib = { - jQuery : "http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.js", - jQueryUI : "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.17/jquery-ui.js", - jQueryToolTip : "http://cdn.jquerytools.org/1.2.4/all/jquery.tools.min.js", - swfObject : "http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js", - cssjQueryUI : "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.4/themes/base/jquery-ui.css", - popcorn : IriSP.libdir + "popcorn.js", - jwplayer : IriSP.libdir + "jwplayer.js", - popcornReplacement: IriSP.libdir + "pop.js", - raphael: IriSP.libdir + "raphael.js", - jquery_sparkline: IriSP.libdir + "jquery.sparkline.js", - "popcorn.mediafragment" : IriSP.libdir + "popcorn.mediafragment.js", - "popcorn.code" : IriSP.libdir + "popcorn.code.js", - "popcorn.jwplayer": IriSP.libdir + "popcorn.jwplayer.js", - "popcorn.youtube": IriSP.libdir + "popcorn.youtube.js" +/** ugly ugly ugly ugly - returns an object defining + the paths to the libs + We need it that way cause it's called at runtime by + IriSP.configureDefaults. +*/ +IriSP.defaults.lib = function(libdir) { + if (IriSP.null_or_undefined(libdir)) + libdir = IriSP.libdir; + + return { + jQuery : "http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.js", + jQueryUI : "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.17/jquery-ui.js", + jQueryToolTip : "http://cdn.jquerytools.org/1.2.4/all/jquery.tools.min.js", + swfObject : "http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js", + cssjQueryUI : "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.4/themes/base/jquery-ui.css", + popcorn : libdir + "popcorn.js", + jwplayer : libdir + "jwplayer.js", + popcornReplacement: libdir + "pop.js", + raphael: libdir + "raphael.js", + jquery_sparkline: libdir + "jquery.sparkline.js", + "popcorn.mediafragment" : libdir + "popcorn.mediafragment.js", + "popcorn.code" : libdir + "popcorn.code.js", + "popcorn.jwplayer": libdir + "popcorn.jwplayer.js", + "popcorn.youtube": libdir + "popcorn.youtube.js" + }; }; //Configuration for the player and utility functions. +// No need to have them configured at runtime IriSP.config = {}; IriSP.config.shortener = { @@ -29,62 +53,71 @@ //shortening_function : IriSP.platform_shorten_url }; -IriSP.widgetsDefaults = { - "LayoutManager" : {spacer_div_height : "0px" }, - "PlayerWidget" : {}, - "AnnotationsWidget": { - "share_text" : "I'm watching ", - "fb_link" : "http://www.facebook.com/share.php?u=", - "tw_link" : "http://twitter.com/home?status=", - "gplus_link" : "" +IriSP.defaults.widgetsDefaults = function(platform_url) { + if (IriSP.null_or_undefined(platform_url)) + platform_url = IriSP.platform_url; + + return { + "LayoutManager" : {spacer_div_height : "0px" }, + "PlayerWidget" : {}, + "AnnotationsWidget": { + "share_text" : "I'm watching ", + "fb_link" : "http://www.facebook.com/share.php?u=", + "tw_link" : "http://twitter.com/home?status=", + "gplus_link" : "" + }, + + "TweetsWidget" : { + default_profile_picture : "https://si0.twimg.com/sticky/default_profile_images/default_profile_1_normal.png", + tweet_display_period: 10000 // how long do we show a tweet ? + + }, + "SliderWidget" : { + minimize_period: 850 // how long does the slider stays maximized after the user leaves the zone ? }, - "TweetsWidget" : { - default_profile_picture : "https://si0.twimg.com/sticky/default_profile_images/default_profile_1_normal.png", - tweet_display_period: 10000, // how long do we show a tweet ? - - }, - "SliderWidget" : { - minimize_period: 850 // how long does the slider stays maximized after the user leaves the zone ? - }, - "createAnnotationWidget" : { - keywords: ["#faux-raccord", "#mot-clef"], - polemic_mode: true, /* enable polemics ? */ - /* polemics - the corresponding class names defined in the css should be for instance : - Ldt-createAnnotation-polemic-plusplus for plusplus - Ldt-createAnnotation-polemic-equalequal for equalequal, etc. - */ - polemics: {"++" : "positive", "--" : "negative", "==" : "reference", "??" : "question"}, - cinecast_version: true /* put to false to enable the platform version, true for the festival cinecast one. */ - }, - "SparklineWidget" : { - column_width: 10 // the width of a column in pixels. - }, - "Main" : { - autoplay: true - }, - "AnnotationsListWidget" : { - ajax_mode: true, /* use ajax to get information about the annotations. - if set to false, only search in the annotations for the - current project. */ - ajax_url: IriSP.platform_url + "ldtplatform/api/ldt/segments/", /* partial - url of - where to - get the - ajax */ - ajax_granularity: 10000, /* how much ms should we look before and after the - current timecode */ - - project_url: IriSP.platform_url + "/ldtplatform/ldt/front/player/" /* the beginning - of a link to the - new front */ - }, + "createAnnotationWidget" : { + keywords: ["#faux-raccord", "#mot-clef"], + polemic_mode: true, /* enable polemics ? */ + /* polemics - the corresponding class names defined in the css should be for instance : + Ldt-createAnnotation-polemic-plusplus for plusplus + Ldt-createAnnotation-polemic-equalequal for equalequal, etc. + */ + polemics: {"++" : "positive", "--" : "negative", "==" : "reference", "??" : "question"}, + cinecast_version: true /* put to false to enable the platform version, true for the festival cinecast one. */ + }, + "SparklineWidget" : { + column_width: 10 // the width of a column in pixels. + }, + "Main" : { + autoplay: true + }, + "AnnotationsListWidget" : { + ajax_mode: true, /* use ajax to get information about the annotations. + if set to false, only search in the annotations for the + current project. */ + ajax_url: platform_url + "/ldtplatform/api/ldt/segments/", /* partial + url of + where to + get the + ajax */ + ajax_granularity: 10000, /* how much ms should we look before and after the + current timecode */ + + project_url: platform_url + "/ldtplatform/ldt/front/player/" /* the beginning + of a link to the + new front */ + } + }; }; -IriSP.paths = { +IriSP.defaults.paths = { // "imgs": "/tweetlive/res/metadataplayer/src/css/imgs" "imgs": "/mdp/src/css/imgs" }; -IriSP.default_templates_vars = { + +IriSP.defaults.default_templates_vars = function() { + return { "img_dir" : IriSP.paths.imgs -}; + }; +}