src/js/init.js
author veltr
Mon, 05 Mar 2012 17:34:48 +0100
branchpopcorn-port
changeset 827 1dc2f85c3b89
parent 822 45083178c1d2
child 828 bcf0c2bdcb8e
permissions -rw-r--r--
BUGFIX: Tooltips are now positioned relative to their parent widget.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
123
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
     1
/* init.js - initialization and configuration of Popcorn and the widgets
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
     2
exemple json configuration:
141
becd5f52fa24 this commit fixes an elusive integration bug where the object would get called
hamidouk
parents: 136
diff changeset
     3
 
123
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
     4
 */
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
     5
531
e7f27746668e beefed up the docs.
hamidouk
parents: 500
diff changeset
     6
/**
e7f27746668e beefed up the docs.
hamidouk
parents: 500
diff changeset
     7
    set up the IriSP.__dataloader instance - 
e7f27746668e beefed up the docs.
hamidouk
parents: 500
diff changeset
     8
    we need it because we have to get the metadata
e7f27746668e beefed up the docs.
hamidouk
parents: 500
diff changeset
     9
    about the video before that the widget have even
e7f27746668e beefed up the docs.
hamidouk
parents: 500
diff changeset
    10
    loaded.
e7f27746668e beefed up the docs.
hamidouk
parents: 500
diff changeset
    11
*/
453
8568e47379a2 added autoconfiguration of the media source for rtmp streams.
hamidouk
parents: 430
diff changeset
    12
IriSP.setupDataLoader = function() {
8568e47379a2 added autoconfiguration of the media source for rtmp streams.
hamidouk
parents: 430
diff changeset
    13
  /* we set it up separately because we need to
8568e47379a2 added autoconfiguration of the media source for rtmp streams.
hamidouk
parents: 430
diff changeset
    14
     get data at the very beginning, for instance when
8568e47379a2 added autoconfiguration of the media source for rtmp streams.
hamidouk
parents: 430
diff changeset
    15
     setting up the video */
8568e47379a2 added autoconfiguration of the media source for rtmp streams.
hamidouk
parents: 430
diff changeset
    16
  IriSP.__dataloader = new IriSP.DataLoader();
8568e47379a2 added autoconfiguration of the media source for rtmp streams.
hamidouk
parents: 430
diff changeset
    17
};
8568e47379a2 added autoconfiguration of the media source for rtmp streams.
hamidouk
parents: 430
diff changeset
    18
531
e7f27746668e beefed up the docs.
hamidouk
parents: 500
diff changeset
    19
/** do some magic to configure popcorn according to the options object passed.
e7f27746668e beefed up the docs.
hamidouk
parents: 500
diff changeset
    20
    Works for html5, jwplayer and youtube videos 
e7f27746668e beefed up the docs.
hamidouk
parents: 500
diff changeset
    21
*/
158
1813e6e4f0d6 made a small change to the way popcorn is integrated into the page.
hamidouk
parents: 141
diff changeset
    22
IriSP.configurePopcorn = function (layoutManager, options) {
123
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    23
    var pop;
287
5c7495102bd7 added a spacer div to simplify some graphic animations.
hamidouk
parents: 216
diff changeset
    24
    var ret = layoutManager.createDiv(); 
5c7495102bd7 added a spacer div to simplify some graphic animations.
hamidouk
parents: 216
diff changeset
    25
    var containerDiv = ret[0];
767
645d06da3d5b automatically insert 1px of margin between the video and the first widget.
hamidouk
parents: 743
diff changeset
    26
    var spacerDiv = ret[1];
645d06da3d5b automatically insert 1px of margin between the video and the first widget.
hamidouk
parents: 743
diff changeset
    27
    
645d06da3d5b automatically insert 1px of margin between the video and the first widget.
hamidouk
parents: 743
diff changeset
    28
    /* insert one pixel of margin between the video and the first widget, using the 
645d06da3d5b automatically insert 1px of margin between the video and the first widget.
hamidouk
parents: 743
diff changeset
    29
       spacer.
645d06da3d5b automatically insert 1px of margin between the video and the first widget.
hamidouk
parents: 743
diff changeset
    30
    */
645d06da3d5b automatically insert 1px of margin between the video and the first widget.
hamidouk
parents: 743
diff changeset
    31
    IriSP.jQuery("#" + spacerDiv).css("height", "1px");
123
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    32
    
127
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    33
    switch(options.type) {
123
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    34
      /*
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    35
        todo : dynamically create the div/video tag which
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    36
        will contain the video.
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    37
      */
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    38
      case "html5":
158
1813e6e4f0d6 made a small change to the way popcorn is integrated into the page.
hamidouk
parents: 141
diff changeset
    39
           var tmpId = Popcorn.guid("video"); 
1813e6e4f0d6 made a small change to the way popcorn is integrated into the page.
hamidouk
parents: 141
diff changeset
    40
           IriSP.jQuery("#" + containerDiv).append("<video src='" + options.file + "' id='" + tmpId + "'></video>");
402
6148fb647f46 html5 video can now set the height and width of the video.
hamidouk
parents: 315
diff changeset
    41
6148fb647f46 html5 video can now set the height and width of the video.
hamidouk
parents: 315
diff changeset
    42
           if (options.hasOwnProperty("width"))
6148fb647f46 html5 video can now set the height and width of the video.
hamidouk
parents: 315
diff changeset
    43
             IriSP.jQuery("#" + containerDiv).css("width", options.width);
6148fb647f46 html5 video can now set the height and width of the video.
hamidouk
parents: 315
diff changeset
    44
           
6148fb647f46 html5 video can now set the height and width of the video.
hamidouk
parents: 315
diff changeset
    45
           if (options.hasOwnProperty("height"))
6148fb647f46 html5 video can now set the height and width of the video.
hamidouk
parents: 315
diff changeset
    46
             IriSP.jQuery("#" + containerDiv).css("height", options.height);
6148fb647f46 html5 video can now set the height and width of the video.
hamidouk
parents: 315
diff changeset
    47
500
a784e70993b3 removed mediafragment references as they're implemented by the mediafragment
hamidouk
parents: 461
diff changeset
    48
           pop = Popcorn("#" + tmpId);
123
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    49
        break;
127
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    50
        
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    51
      case "jwplayer":
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    52
          var opts = IriSP.jQuery.extend({}, options);
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    53
          delete opts.container;
558
29a370694c53 delete type variable which seemed to sometimes (but not always) confuse the jwplayer,
hamidouk
parents: 557
diff changeset
    54
          delete opts.type;
453
8568e47379a2 added autoconfiguration of the media source for rtmp streams.
hamidouk
parents: 430
diff changeset
    55
707
1ebfd2a7366b cleared the code.
hamidouk
parents: 705
diff changeset
    56
          
1ebfd2a7366b cleared the code.
hamidouk
parents: 705
diff changeset
    57
          /* Try to guess options.file and options.streamer only if file and streamer
1ebfd2a7366b cleared the code.
hamidouk
parents: 705
diff changeset
    58
             are not already defined in the configuration */
1ebfd2a7366b cleared the code.
hamidouk
parents: 705
diff changeset
    59
          if (options.provider === "rtmp" && !opts.hasOwnProperty("file") && !opts.hasOwnProperty("streamer")) {
456
7fcdb501effd added a switch to choose different options if using rtmp or not.
hamidouk
parents: 453
diff changeset
    60
            /* exit if we can't access the metadata */
7fcdb501effd added a switch to choose different options if using rtmp or not.
hamidouk
parents: 453
diff changeset
    61
            if (typeof(IriSP.__jsonMetadata) === "undefined") {
7fcdb501effd added a switch to choose different options if using rtmp or not.
hamidouk
parents: 453
diff changeset
    62
                break;
7fcdb501effd added a switch to choose different options if using rtmp or not.
hamidouk
parents: 453
diff changeset
    63
            };
453
8568e47379a2 added autoconfiguration of the media source for rtmp streams.
hamidouk
parents: 430
diff changeset
    64
456
7fcdb501effd added a switch to choose different options if using rtmp or not.
hamidouk
parents: 453
diff changeset
    65
            // the json format is totally illogical
632
720ffcc65e36 added automatic streamer detection.
hamidouk
parents: 582
diff changeset
    66
            //opts.streamer = IriSP.__jsonMetadata["medias"][0]["meta"]["item"]["value"];
720ffcc65e36 added automatic streamer detection.
hamidouk
parents: 582
diff changeset
    67
            //var source = IriSP.__jsonMetadata["medias"][0]["href"];
453
8568e47379a2 added autoconfiguration of the media source for rtmp streams.
hamidouk
parents: 430
diff changeset
    68
456
7fcdb501effd added a switch to choose different options if using rtmp or not.
hamidouk
parents: 453
diff changeset
    69
            // the source if a full url but jwplayer wants an url relative to the
7fcdb501effd added a switch to choose different options if using rtmp or not.
hamidouk
parents: 453
diff changeset
    70
            // streamer url, so we've got to remove the common part.
632
720ffcc65e36 added automatic streamer detection.
hamidouk
parents: 582
diff changeset
    71
            //opts.file = source.slice(opts.streamer.length);
720ffcc65e36 added automatic streamer detection.
hamidouk
parents: 582
diff changeset
    72
            
720ffcc65e36 added automatic streamer detection.
hamidouk
parents: 582
diff changeset
    73
            /* sometimes we get served a file with a wrong path and streamer.
720ffcc65e36 added automatic streamer detection.
hamidouk
parents: 582
diff changeset
    74
               as a streamer is of the form rtmp://domain/path/ and the media is
720ffcc65e36 added automatic streamer detection.
hamidouk
parents: 582
diff changeset
    75
               the rest, we uglily do this :
720ffcc65e36 added automatic streamer detection.
hamidouk
parents: 582
diff changeset
    76
            */
720ffcc65e36 added automatic streamer detection.
hamidouk
parents: 582
diff changeset
    77
            opts.file = "";
720ffcc65e36 added automatic streamer detection.
hamidouk
parents: 582
diff changeset
    78
            opts.streamer = "";
822
45083178c1d2 Corrections
veltr
parents: 816
diff changeset
    79
            var fullPath = IriSP.get_aliased(IriSP.__jsonMetadata["medias"][0], ["href","url"]);
816
e97e22801146 use href or url indiscriminately to get the source of the rtmp.
hamidouk
parents: 811
diff changeset
    80
            
822
45083178c1d2 Corrections
veltr
parents: 816
diff changeset
    81
            if (fullPath === null) {
816
e97e22801146 use href or url indiscriminately to get the source of the rtmp.
hamidouk
parents: 811
diff changeset
    82
              console.log("no url or href field defined in the metadata.");
e97e22801146 use href or url indiscriminately to get the source of the rtmp.
hamidouk
parents: 811
diff changeset
    83
            }
e97e22801146 use href or url indiscriminately to get the source of the rtmp.
hamidouk
parents: 811
diff changeset
    84
            
632
720ffcc65e36 added automatic streamer detection.
hamidouk
parents: 582
diff changeset
    85
            var pathSplit = fullPath.split('/');
720ffcc65e36 added automatic streamer detection.
hamidouk
parents: 582
diff changeset
    86
            
720ffcc65e36 added automatic streamer detection.
hamidouk
parents: 582
diff changeset
    87
            for (var i = 0; i < pathSplit.length; i++) {
720ffcc65e36 added automatic streamer detection.
hamidouk
parents: 582
diff changeset
    88
              if (i < 4) {
720ffcc65e36 added automatic streamer detection.
hamidouk
parents: 582
diff changeset
    89
                 opts.streamer += pathSplit[i] + "/";
720ffcc65e36 added automatic streamer detection.
hamidouk
parents: 582
diff changeset
    90
              } else {
720ffcc65e36 added automatic streamer detection.
hamidouk
parents: 582
diff changeset
    91
                 opts.file += pathSplit[i];
720ffcc65e36 added automatic streamer detection.
hamidouk
parents: 582
diff changeset
    92
                 /* omit the last slash if we're on the last element */
720ffcc65e36 added automatic streamer detection.
hamidouk
parents: 582
diff changeset
    93
                 if (i < pathSplit.length - 1)
720ffcc65e36 added automatic streamer detection.
hamidouk
parents: 582
diff changeset
    94
                  opts.file += "/";
720ffcc65e36 added automatic streamer detection.
hamidouk
parents: 582
diff changeset
    95
              }
707
1ebfd2a7366b cleared the code.
hamidouk
parents: 705
diff changeset
    96
            }            
456
7fcdb501effd added a switch to choose different options if using rtmp or not.
hamidouk
parents: 453
diff changeset
    97
          } else {
7fcdb501effd added a switch to choose different options if using rtmp or not.
hamidouk
parents: 453
diff changeset
    98
            /* other providers type, video for instance -
7fcdb501effd added a switch to choose different options if using rtmp or not.
hamidouk
parents: 453
diff changeset
    99
               pass everything as is */
7fcdb501effd added a switch to choose different options if using rtmp or not.
hamidouk
parents: 453
diff changeset
   100
          }
7fcdb501effd added a switch to choose different options if using rtmp or not.
hamidouk
parents: 453
diff changeset
   101
557
e331072ce8fd added more autoconfig, and an option to specify in site.js where to get the
hamidouk
parents: 539
diff changeset
   102
          if (!options.hasOwnProperty("flashplayer")) {
558
29a370694c53 delete type variable which seemed to sometimes (but not always) confuse the jwplayer,
hamidouk
parents: 557
diff changeset
   103
            opts.flashplayer = IriSP.jwplayer_swf_path;
557
e331072ce8fd added more autoconfig, and an option to specify in site.js where to get the
hamidouk
parents: 539
diff changeset
   104
          }
e331072ce8fd added more autoconfig, and an option to specify in site.js where to get the
hamidouk
parents: 539
diff changeset
   105
e331072ce8fd added more autoconfig, and an option to specify in site.js where to get the
hamidouk
parents: 539
diff changeset
   106
          if (!options.hasOwnProperty("controlbar.position")) {
558
29a370694c53 delete type variable which seemed to sometimes (but not always) confuse the jwplayer,
hamidouk
parents: 557
diff changeset
   107
            opts["controlbar.position"] = "none";
557
e331072ce8fd added more autoconfig, and an option to specify in site.js where to get the
hamidouk
parents: 539
diff changeset
   108
          }
558
29a370694c53 delete type variable which seemed to sometimes (but not always) confuse the jwplayer,
hamidouk
parents: 557
diff changeset
   109
701
a773f117d2e7 adapted init to use the new api.
hamidouk
parents: 632
diff changeset
   110
          pop = new IriSP.PopcornReplacement.jwplayer("#" + containerDiv, opts);
127
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
   111
        break;
198
8ffb1b7a9c6b activated youtube support.
hamidouk
parents: 175
diff changeset
   112
      
8ffb1b7a9c6b activated youtube support.
hamidouk
parents: 175
diff changeset
   113
      case "youtube":
8ffb1b7a9c6b activated youtube support.
hamidouk
parents: 175
diff changeset
   114
          var opts = IriSP.jQuery.extend({}, options);
8ffb1b7a9c6b activated youtube support.
hamidouk
parents: 175
diff changeset
   115
          delete opts.container;
8ffb1b7a9c6b activated youtube support.
hamidouk
parents: 175
diff changeset
   116
          opts.controls = 0;
8ffb1b7a9c6b activated youtube support.
hamidouk
parents: 175
diff changeset
   117
          opts.autostart = false;
204
a5e807f33a67 fixed a margin in youtube player div.
hamidouk
parents: 198
diff changeset
   118
          templ = "width: {{width}}px; height: {{height}}px;";
198
8ffb1b7a9c6b activated youtube support.
hamidouk
parents: 175
diff changeset
   119
          var str = Mustache.to_html(templ, {width: opts.width, height: opts.height});    
8ffb1b7a9c6b activated youtube support.
hamidouk
parents: 175
diff changeset
   120
          // Popcorn.youtube wants us to specify the size of the player in the style attribute of its container div.
8ffb1b7a9c6b activated youtube support.
hamidouk
parents: 175
diff changeset
   121
          IriSP.jQuery("#" + containerDiv).attr("style", str);
8ffb1b7a9c6b activated youtube support.
hamidouk
parents: 175
diff changeset
   122
          
500
a784e70993b3 removed mediafragment references as they're implemented by the mediafragment
hamidouk
parents: 461
diff changeset
   123
          pop = Popcorn.youtube("#" + containerDiv, opts.video, opts);
198
8ffb1b7a9c6b activated youtube support.
hamidouk
parents: 175
diff changeset
   124
        break;
785
980163a156d1 Added Dailymotion support
veltr
parents: 767
diff changeset
   125
      
980163a156d1 Added Dailymotion support
veltr
parents: 767
diff changeset
   126
    case "dailymotion":
980163a156d1 Added Dailymotion support
veltr
parents: 767
diff changeset
   127
        pop = new IriSP.PopcornReplacement.dailymotion("#" + containerDiv, options);
980163a156d1 Added Dailymotion support
veltr
parents: 767
diff changeset
   128
        break;
980163a156d1 Added Dailymotion support
veltr
parents: 767
diff changeset
   129
             
705
83197a7a4281 add a switch case to use the allocine player.
hamidouk
parents: 701
diff changeset
   130
      case "allocine":
83197a7a4281 add a switch case to use the allocine player.
hamidouk
parents: 701
diff changeset
   131
          /* pass the options as-is to the allocine player and let it handle everything */
707
1ebfd2a7366b cleared the code.
hamidouk
parents: 705
diff changeset
   132
          pop = new IriSP.PopcornReplacement.allocine("#" + containerDiv, options);
705
83197a7a4281 add a switch case to use the allocine player.
hamidouk
parents: 701
diff changeset
   133
          break;
83197a7a4281 add a switch case to use the allocine player.
hamidouk
parents: 701
diff changeset
   134
          
127
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
   135
      default:
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
   136
        pop = undefined;
123
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
   137
    };
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
   138
    
127
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
   139
    return pop;
123
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
   140
};
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
   141
531
e7f27746668e beefed up the docs.
hamidouk
parents: 500
diff changeset
   142
/** Configure the gui and instantiate the widgets passed as parameters
e7f27746668e beefed up the docs.
hamidouk
parents: 500
diff changeset
   143
    @param guiOptions the gui object as seen in the examples.
e7f27746668e beefed up the docs.
hamidouk
parents: 500
diff changeset
   144
 */
158
1813e6e4f0d6 made a small change to the way popcorn is integrated into the page.
hamidouk
parents: 141
diff changeset
   145
IriSP.configureWidgets = function (popcornInstance, layoutManager, guiOptions) {
453
8568e47379a2 added autoconfiguration of the media source for rtmp streams.
hamidouk
parents: 430
diff changeset
   146
 
8568e47379a2 added autoconfiguration of the media source for rtmp streams.
hamidouk
parents: 430
diff changeset
   147
  var serialFactory = new IriSP.SerializerFactory(IriSP.__dataloader);
127
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
   148
  var params = {width: guiOptions.width, height: guiOptions.height};
158
1813e6e4f0d6 made a small change to the way popcorn is integrated into the page.
hamidouk
parents: 141
diff changeset
   149
810
85a278e12495 added default options for the widgets.
hamidouk
parents: 795
diff changeset
   150
  var default_options = guiOptions.default_options;
85a278e12495 added default options for the widgets.
hamidouk
parents: 795
diff changeset
   151
  if (IriSP.null_or_undefined(default_options))
85a278e12495 added default options for the widgets.
hamidouk
parents: 795
diff changeset
   152
    default_options = {};
85a278e12495 added default options for the widgets.
hamidouk
parents: 795
diff changeset
   153
  
127
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
   154
  var ret_widgets = [];
141
becd5f52fa24 this commit fixes an elusive integration bug where the object would get called
hamidouk
parents: 136
diff changeset
   155
  var index;
127
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
   156
  
141
becd5f52fa24 this commit fixes an elusive integration bug where the object would get called
hamidouk
parents: 136
diff changeset
   157
  for (index = 0; index < guiOptions.widgets.length; index++) {    
811
b9dd62e35e30 less useless code - required widgets now support defaultOptions too.
hamidouk
parents: 810
diff changeset
   158
    var widget = IriSP.instantiateWidget(popcornInstance, serialFactory, layoutManager, guiOptions.widgets[index], default_options);
810
85a278e12495 added default options for the widgets.
hamidouk
parents: 795
diff changeset
   159
   
767
645d06da3d5b automatically insert 1px of margin between the video and the first widget.
hamidouk
parents: 743
diff changeset
   160
    ret_widgets.push(widget);   
127
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
   161
  };
141
becd5f52fa24 this commit fixes an elusive integration bug where the object would get called
hamidouk
parents: 136
diff changeset
   162
127
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
   163
  return ret_widgets;
171
158f0193ec54 added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents: 158
diff changeset
   164
};
158f0193ec54 added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents: 158
diff changeset
   165
531
e7f27746668e beefed up the docs.
hamidouk
parents: 500
diff changeset
   166
/** configure modules. @see configureWidgets */
461
a9c5eeca190c added modules and tbe tests to test them.
hamidouk
parents: 456
diff changeset
   167
IriSP.configureModules = function (popcornInstance, modulesList) {
795
8b69c3dbbc18 changed default user paths.
hamidouk
parents: 785
diff changeset
   168
  if (IriSP.null_or_undefined(modulesList))
8b69c3dbbc18 changed default user paths.
hamidouk
parents: 785
diff changeset
   169
    return;
8b69c3dbbc18 changed default user paths.
hamidouk
parents: 785
diff changeset
   170
  
461
a9c5eeca190c added modules and tbe tests to test them.
hamidouk
parents: 456
diff changeset
   171
  var serialFactory = new IriSP.SerializerFactory(IriSP.__dataloader);
a9c5eeca190c added modules and tbe tests to test them.
hamidouk
parents: 456
diff changeset
   172
  var ret_modules = [];
a9c5eeca190c added modules and tbe tests to test them.
hamidouk
parents: 456
diff changeset
   173
  var index;
a9c5eeca190c added modules and tbe tests to test them.
hamidouk
parents: 456
diff changeset
   174
  
a9c5eeca190c added modules and tbe tests to test them.
hamidouk
parents: 456
diff changeset
   175
  for (index = 0; index < modulesList.length; index++) {    
a9c5eeca190c added modules and tbe tests to test them.
hamidouk
parents: 456
diff changeset
   176
    var moduleConfig = modulesList[index];
a9c5eeca190c added modules and tbe tests to test them.
hamidouk
parents: 456
diff changeset
   177
    
a9c5eeca190c added modules and tbe tests to test them.
hamidouk
parents: 456
diff changeset
   178
    var serializer = serialFactory.getSerializer(moduleConfig.metadata);
a9c5eeca190c added modules and tbe tests to test them.
hamidouk
parents: 456
diff changeset
   179
    var module = new IriSP[moduleConfig.type](popcornInstance, moduleConfig, serializer);    
a9c5eeca190c added modules and tbe tests to test them.
hamidouk
parents: 456
diff changeset
   180
    ret_modules.push(module);
a9c5eeca190c added modules and tbe tests to test them.
hamidouk
parents: 456
diff changeset
   181
  };
a9c5eeca190c added modules and tbe tests to test them.
hamidouk
parents: 456
diff changeset
   182
a9c5eeca190c added modules and tbe tests to test them.
hamidouk
parents: 456
diff changeset
   183
  return ret_modules;
a9c5eeca190c added modules and tbe tests to test them.
hamidouk
parents: 456
diff changeset
   184
};
a9c5eeca190c added modules and tbe tests to test them.
hamidouk
parents: 456
diff changeset
   185
531
e7f27746668e beefed up the docs.
hamidouk
parents: 500
diff changeset
   186
/** instantiate a widget - only called by configureWidgets, never by the user. Handles widget 
e7f27746668e beefed up the docs.
hamidouk
parents: 500
diff changeset
   187
    dependencies.
e7f27746668e beefed up the docs.
hamidouk
parents: 500
diff changeset
   188
    @param popcornInstance popcorn instance the widget will user
e7f27746668e beefed up the docs.
hamidouk
parents: 500
diff changeset
   189
    @param serialFactory serializer factory to instantiate the widget with
e7f27746668e beefed up the docs.
hamidouk
parents: 500
diff changeset
   190
    @param layoutManager layout manager
e7f27746668e beefed up the docs.
hamidouk
parents: 500
diff changeset
   191
    @param widgetConfig configuration options for the widget
811
b9dd62e35e30 less useless code - required widgets now support defaultOptions too.
hamidouk
parents: 810
diff changeset
   192
    @param defaultOptions a dictionnary with some options defined for every widget.
531
e7f27746668e beefed up the docs.
hamidouk
parents: 500
diff changeset
   193
 */
811
b9dd62e35e30 less useless code - required widgets now support defaultOptions too.
hamidouk
parents: 810
diff changeset
   194
IriSP.instantiateWidget = function(popcornInstance, serialFactory, layoutManager, widgetConfig, defaultOptions) {
b9dd62e35e30 less useless code - required widgets now support defaultOptions too.
hamidouk
parents: 810
diff changeset
   195
b9dd62e35e30 less useless code - required widgets now support defaultOptions too.
hamidouk
parents: 810
diff changeset
   196
    if (IriSP.null_or_undefined(defaultOptions))
b9dd62e35e30 less useless code - required widgets now support defaultOptions too.
hamidouk
parents: 810
diff changeset
   197
      defaultOptions = {};
b9dd62e35e30 less useless code - required widgets now support defaultOptions too.
hamidouk
parents: 810
diff changeset
   198
    
b9dd62e35e30 less useless code - required widgets now support defaultOptions too.
hamidouk
parents: 810
diff changeset
   199
    widgetConfig = IriSP.underscore.defaults(widgetConfig, defaultOptions);
287
5c7495102bd7 added a spacer div to simplify some graphic animations.
hamidouk
parents: 216
diff changeset
   200
175
b0cb7132accb variable rename.
hamidouk
parents: 171
diff changeset
   201
    var arr = IriSP.jQuery.extend({}, widgetConfig);
b0cb7132accb variable rename.
hamidouk
parents: 171
diff changeset
   202
    
582
1bca6b7f56e1 give the possibility to specify containers for widgets.
hamidouk
parents: 577
diff changeset
   203
    /* create a div for those widgets who didn't already specify a container; */
1bca6b7f56e1 give the possibility to specify containers for widgets.
hamidouk
parents: 577
diff changeset
   204
    if (!arr.hasOwnProperty("container")) {
1bca6b7f56e1 give the possibility to specify containers for widgets.
hamidouk
parents: 577
diff changeset
   205
      /* create div returns us a container for the widget and a spacer */    
1bca6b7f56e1 give the possibility to specify containers for widgets.
hamidouk
parents: 577
diff changeset
   206
      var ret = layoutManager.createDiv(widgetConfig.type);        
1bca6b7f56e1 give the possibility to specify containers for widgets.
hamidouk
parents: 577
diff changeset
   207
      var container = ret[0];
1bca6b7f56e1 give the possibility to specify containers for widgets.
hamidouk
parents: 577
diff changeset
   208
      var spacer = ret[1];           
1bca6b7f56e1 give the possibility to specify containers for widgets.
hamidouk
parents: 577
diff changeset
   209
      arr.container = container;
1bca6b7f56e1 give the possibility to specify containers for widgets.
hamidouk
parents: 577
diff changeset
   210
      arr.spacer = spacer;
1bca6b7f56e1 give the possibility to specify containers for widgets.
hamidouk
parents: 577
diff changeset
   211
      arr.layoutManager = layoutManager;
1bca6b7f56e1 give the possibility to specify containers for widgets.
hamidouk
parents: 577
diff changeset
   212
    }
171
158f0193ec54 added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents: 158
diff changeset
   213
    var serializer = serialFactory.getSerializer(widgetConfig.metadata);    
175
b0cb7132accb variable rename.
hamidouk
parents: 171
diff changeset
   214
    
b0cb7132accb variable rename.
hamidouk
parents: 171
diff changeset
   215
    if (typeof serializer == "undefined")   
b0cb7132accb variable rename.
hamidouk
parents: 171
diff changeset
   216
      debugger;
b0cb7132accb variable rename.
hamidouk
parents: 171
diff changeset
   217
    
171
158f0193ec54 added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents: 158
diff changeset
   218
    // instantiate the object passed as a string
158f0193ec54 added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents: 158
diff changeset
   219
    var widget = new IriSP[widgetConfig.type](popcornInstance, arr, serializer);    
158f0193ec54 added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents: 158
diff changeset
   220
    
158f0193ec54 added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents: 158
diff changeset
   221
    if (widgetConfig.hasOwnProperty("requires")) {
158f0193ec54 added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents: 158
diff changeset
   222
      // also create the widgets this one depends on.
158f0193ec54 added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents: 158
diff changeset
   223
      // the dependency widget is available in the parent widget context as
158f0193ec54 added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents: 158
diff changeset
   224
      // this.WidgetName (for instance, this.TipWidget);
158f0193ec54 added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents: 158
diff changeset
   225
      
175
b0cb7132accb variable rename.
hamidouk
parents: 171
diff changeset
   226
      var i = 0;
b0cb7132accb variable rename.
hamidouk
parents: 171
diff changeset
   227
      for(i = 0; i < widgetConfig.requires.length; i++) {
827
1dc2f85c3b89 BUGFIX: Tooltips are now positioned relative to their parent widget.
veltr
parents: 822
diff changeset
   228
        var widgetName = widgetConfig.requires[i]["type"],
1dc2f85c3b89 BUGFIX: Tooltips are now positioned relative to their parent widget.
veltr
parents: 822
diff changeset
   229
            _configobj = IriSP.jQuery.extend({}, widgetConfig.requires[i]),
1dc2f85c3b89 BUGFIX: Tooltips are now positioned relative to their parent widget.
veltr
parents: 822
diff changeset
   230
            _div = document.createElement('div'),
1dc2f85c3b89 BUGFIX: Tooltips are now positioned relative to their parent widget.
veltr
parents: 822
diff changeset
   231
            _container = IriSP.guid(arr.container + '_' + widgetName + '_');
1dc2f85c3b89 BUGFIX: Tooltips are now positioned relative to their parent widget.
veltr
parents: 822
diff changeset
   232
        _configobj.container = _container;
1dc2f85c3b89 BUGFIX: Tooltips are now positioned relative to their parent widget.
veltr
parents: 822
diff changeset
   233
        _div.id = _container;
1dc2f85c3b89 BUGFIX: Tooltips are now positioned relative to their parent widget.
veltr
parents: 822
diff changeset
   234
        widget.selector.append(_div);
1dc2f85c3b89 BUGFIX: Tooltips are now positioned relative to their parent widget.
veltr
parents: 822
diff changeset
   235
        console.log(_configobj);
1dc2f85c3b89 BUGFIX: Tooltips are now positioned relative to their parent widget.
veltr
parents: 822
diff changeset
   236
        widget[widgetName] = IriSP.instantiateWidget(popcornInstance, serialFactory, layoutManager, _configobj, defaultOptions);
171
158f0193ec54 added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents: 158
diff changeset
   237
      }
175
b0cb7132accb variable rename.
hamidouk
parents: 171
diff changeset
   238
    }       
b0cb7132accb variable rename.
hamidouk
parents: 171
diff changeset
   239
     
171
158f0193ec54 added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents: 158
diff changeset
   240
    serializer.sync(IriSP.wrap(widget, function() { this.draw(); }));
158f0193ec54 added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents: 158
diff changeset
   241
    return widget;
287
5c7495102bd7 added a spacer div to simplify some graphic animations.
hamidouk
parents: 216
diff changeset
   242
};
743
69a9969daa41 better defaults - paths are now computed at run-time.
hamidouk
parents: 707
diff changeset
   243
69a9969daa41 better defaults - paths are now computed at run-time.
hamidouk
parents: 707
diff changeset
   244
/** Go through the defaults to set a reasonable value */
69a9969daa41 better defaults - paths are now computed at run-time.
hamidouk
parents: 707
diff changeset
   245
IriSP.configureDefaults = function(libdir, platform_url) {
69a9969daa41 better defaults - paths are now computed at run-time.
hamidouk
parents: 707
diff changeset
   246
  /* the defaults configuration is messy and complicated. There are two things to know :
69a9969daa41 better defaults - paths are now computed at run-time.
hamidouk
parents: 707
diff changeset
   247
     - we want to allow overwriting of defaults - that's why we have IriSP.widgetDefaults
69a9969daa41 better defaults - paths are now computed at run-time.
hamidouk
parents: 707
diff changeset
   248
       and IriSP.defaults.widgetDefaults. The first is filled by the embedder and then fleshed out
69a9969daa41 better defaults - paths are now computed at run-time.
hamidouk
parents: 707
diff changeset
   249
       with the contents of the first. We use underscore.defaults for that, but there's one problem with
69a9969daa41 better defaults - paths are now computed at run-time.
hamidouk
parents: 707
diff changeset
   250
       this function : it doesn't work recursively.
69a9969daa41 better defaults - paths are now computed at run-time.
hamidouk
parents: 707
diff changeset
   251
     - we need to compute some values at runtime instead of at compile time
69a9969daa41 better defaults - paths are now computed at run-time.
hamidouk
parents: 707
diff changeset
   252
  */
69a9969daa41 better defaults - paths are now computed at run-time.
hamidouk
parents: 707
diff changeset
   253
    
69a9969daa41 better defaults - paths are now computed at run-time.
hamidouk
parents: 707
diff changeset
   254
  IriSP.lib = IriSP.underscore.defaults(IriSP.lib, IriSP.defaults.lib(libdir));
69a9969daa41 better defaults - paths are now computed at run-time.
hamidouk
parents: 707
diff changeset
   255
  
69a9969daa41 better defaults - paths are now computed at run-time.
hamidouk
parents: 707
diff changeset
   256
  /* get the factory defaults for the widgets and merge them with the default the user
69a9969daa41 better defaults - paths are now computed at run-time.
hamidouk
parents: 707
diff changeset
   257
     may have defined 
69a9969daa41 better defaults - paths are now computed at run-time.
hamidouk
parents: 707
diff changeset
   258
  */
69a9969daa41 better defaults - paths are now computed at run-time.
hamidouk
parents: 707
diff changeset
   259
  var factory_defaults = IriSP.defaults.widgetsDefaults(platform_url);
69a9969daa41 better defaults - paths are now computed at run-time.
hamidouk
parents: 707
diff changeset
   260
  for(var widget in factory_defaults) {
69a9969daa41 better defaults - paths are now computed at run-time.
hamidouk
parents: 707
diff changeset
   261
  
69a9969daa41 better defaults - paths are now computed at run-time.
hamidouk
parents: 707
diff changeset
   262
      /* create the object if it doesn't exists */
69a9969daa41 better defaults - paths are now computed at run-time.
hamidouk
parents: 707
diff changeset
   263
      if (IriSP.null_or_undefined(IriSP.widgetsDefaults[widget]))
69a9969daa41 better defaults - paths are now computed at run-time.
hamidouk
parents: 707
diff changeset
   264
        IriSP.widgetsDefaults[widget] = {};
69a9969daa41 better defaults - paths are now computed at run-time.
hamidouk
parents: 707
diff changeset
   265
        
69a9969daa41 better defaults - paths are now computed at run-time.
hamidouk
parents: 707
diff changeset
   266
      IriSP.widgetsDefaults[widget] = IriSP.underscore.defaults(IriSP.widgetsDefaults[widget], factory_defaults[widget]);
69a9969daa41 better defaults - paths are now computed at run-time.
hamidouk
parents: 707
diff changeset
   267
  }
69a9969daa41 better defaults - paths are now computed at run-time.
hamidouk
parents: 707
diff changeset
   268
  
69a9969daa41 better defaults - paths are now computed at run-time.
hamidouk
parents: 707
diff changeset
   269
  IriSP.paths = IriSP.underscore.defaults(IriSP.paths, IriSP.defaults.paths);
69a9969daa41 better defaults - paths are now computed at run-time.
hamidouk
parents: 707
diff changeset
   270
  IriSP.default_templates_vars = IriSP.underscore.defaults(IriSP.default_templates_vars, 
69a9969daa41 better defaults - paths are now computed at run-time.
hamidouk
parents: 707
diff changeset
   271
                                       IriSP.defaults.default_templates_vars());
795
8b69c3dbbc18 changed default user paths.
hamidouk
parents: 785
diff changeset
   272
8b69c3dbbc18 changed default user paths.
hamidouk
parents: 785
diff changeset
   273
  if (IriSP.null_or_undefined(IriSP.user))
8b69c3dbbc18 changed default user paths.
hamidouk
parents: 785
diff changeset
   274
    IriSP.user = {};
8b69c3dbbc18 changed default user paths.
hamidouk
parents: 785
diff changeset
   275
  
8b69c3dbbc18 changed default user paths.
hamidouk
parents: 785
diff changeset
   276
  IriSP.user = IriSP.underscore.defaults(IriSP.user, IriSP.defaults.user());
743
69a9969daa41 better defaults - paths are now computed at run-time.
hamidouk
parents: 707
diff changeset
   277
};
69a9969daa41 better defaults - paths are now computed at run-time.
hamidouk
parents: 707
diff changeset
   278
69a9969daa41 better defaults - paths are now computed at run-time.
hamidouk
parents: 707
diff changeset
   279
/** single point of entry for the metadataplayer */
69a9969daa41 better defaults - paths are now computed at run-time.
hamidouk
parents: 707
diff changeset
   280
IriSP.initPlayer = function(config, metadata_url, libdir, platform_url) {
69a9969daa41 better defaults - paths are now computed at run-time.
hamidouk
parents: 707
diff changeset
   281
    IriSP.configureDefaults(libdir, platform_url);
69a9969daa41 better defaults - paths are now computed at run-time.
hamidouk
parents: 707
diff changeset
   282
    IriSP.loadLibs(IriSP.lib, config, metadata_url,
69a9969daa41 better defaults - paths are now computed at run-time.
hamidouk
parents: 707
diff changeset
   283
      function() {   
69a9969daa41 better defaults - paths are now computed at run-time.
hamidouk
parents: 707
diff changeset
   284
              
69a9969daa41 better defaults - paths are now computed at run-time.
hamidouk
parents: 707
diff changeset
   285
              var layoutManager = new IriSP.LayoutManager(config.gui);
69a9969daa41 better defaults - paths are now computed at run-time.
hamidouk
parents: 707
diff changeset
   286
69a9969daa41 better defaults - paths are now computed at run-time.
hamidouk
parents: 707
diff changeset
   287
              var pop = IriSP.configurePopcorn(layoutManager, config.player);
69a9969daa41 better defaults - paths are now computed at run-time.
hamidouk
parents: 707
diff changeset
   288
              
69a9969daa41 better defaults - paths are now computed at run-time.
hamidouk
parents: 707
diff changeset
   289
              var widgets = IriSP.configureWidgets(pop, layoutManager, config.gui); 
69a9969daa41 better defaults - paths are now computed at run-time.
hamidouk
parents: 707
diff changeset
   290
              var modules = IriSP.configureModules(pop, config.modules); 
69a9969daa41 better defaults - paths are now computed at run-time.
hamidouk
parents: 707
diff changeset
   291
      });
69a9969daa41 better defaults - paths are now computed at run-time.
hamidouk
parents: 707
diff changeset
   292
};