src/js/init.js
author hamidouk
Tue, 24 Jan 2012 17:29:45 +0100
branchembed-playerapi-rewrite
changeset 701 a773f117d2e7
parent 632 720ffcc65e36
child 705 83197a7a4281
permissions -rw-r--r--
adapted init to use the new api.
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];
123
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    26
    
127
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    27
    switch(options.type) {
123
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    28
      /*
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    29
        todo : dynamically create the div/video tag which
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    30
        will contain the video.
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    31
      */
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    32
      case "html5":
158
1813e6e4f0d6 made a small change to the way popcorn is integrated into the page.
hamidouk
parents: 141
diff changeset
    33
           var tmpId = Popcorn.guid("video"); 
1813e6e4f0d6 made a small change to the way popcorn is integrated into the page.
hamidouk
parents: 141
diff changeset
    34
           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
    35
6148fb647f46 html5 video can now set the height and width of the video.
hamidouk
parents: 315
diff changeset
    36
           if (options.hasOwnProperty("width"))
6148fb647f46 html5 video can now set the height and width of the video.
hamidouk
parents: 315
diff changeset
    37
             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
    38
           
6148fb647f46 html5 video can now set the height and width of the video.
hamidouk
parents: 315
diff changeset
    39
           if (options.hasOwnProperty("height"))
6148fb647f46 html5 video can now set the height and width of the video.
hamidouk
parents: 315
diff changeset
    40
             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
    41
500
a784e70993b3 removed mediafragment references as they're implemented by the mediafragment
hamidouk
parents: 461
diff changeset
    42
           pop = Popcorn("#" + tmpId);
123
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    43
        break;
127
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    44
        
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    45
      case "jwplayer":
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    46
          var opts = IriSP.jQuery.extend({}, options);
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    47
          delete opts.container;
558
29a370694c53 delete type variable which seemed to sometimes (but not always) confuse the jwplayer,
hamidouk
parents: 557
diff changeset
    48
          delete opts.type;
453
8568e47379a2 added autoconfiguration of the media source for rtmp streams.
hamidouk
parents: 430
diff changeset
    49
456
7fcdb501effd added a switch to choose different options if using rtmp or not.
hamidouk
parents: 453
diff changeset
    50
          if (options.provider === "rtmp") {
7fcdb501effd added a switch to choose different options if using rtmp or not.
hamidouk
parents: 453
diff changeset
    51
            /* 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
    52
            if (typeof(IriSP.__jsonMetadata) === "undefined") {
7fcdb501effd added a switch to choose different options if using rtmp or not.
hamidouk
parents: 453
diff changeset
    53
                break;
7fcdb501effd added a switch to choose different options if using rtmp or not.
hamidouk
parents: 453
diff changeset
    54
            };
453
8568e47379a2 added autoconfiguration of the media source for rtmp streams.
hamidouk
parents: 430
diff changeset
    55
8568e47379a2 added autoconfiguration of the media source for rtmp streams.
hamidouk
parents: 430
diff changeset
    56
632
720ffcc65e36 added automatic streamer detection.
hamidouk
parents: 582
diff changeset
    57
             
456
7fcdb501effd added a switch to choose different options if using rtmp or not.
hamidouk
parents: 453
diff changeset
    58
            // the json format is totally illogical
632
720ffcc65e36 added automatic streamer detection.
hamidouk
parents: 582
diff changeset
    59
            //opts.streamer = IriSP.__jsonMetadata["medias"][0]["meta"]["item"]["value"];
720ffcc65e36 added automatic streamer detection.
hamidouk
parents: 582
diff changeset
    60
            //var source = IriSP.__jsonMetadata["medias"][0]["href"];
453
8568e47379a2 added autoconfiguration of the media source for rtmp streams.
hamidouk
parents: 430
diff changeset
    61
456
7fcdb501effd added a switch to choose different options if using rtmp or not.
hamidouk
parents: 453
diff changeset
    62
            // 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
    63
            // streamer url, so we've got to remove the common part.
632
720ffcc65e36 added automatic streamer detection.
hamidouk
parents: 582
diff changeset
    64
            //opts.file = source.slice(opts.streamer.length);
720ffcc65e36 added automatic streamer detection.
hamidouk
parents: 582
diff changeset
    65
            
720ffcc65e36 added automatic streamer detection.
hamidouk
parents: 582
diff changeset
    66
            /* sometimes we get served a file with a wrong path and streamer.
720ffcc65e36 added automatic streamer detection.
hamidouk
parents: 582
diff changeset
    67
               as a streamer is of the form rtmp://domain/path/ and the media is
720ffcc65e36 added automatic streamer detection.
hamidouk
parents: 582
diff changeset
    68
               the rest, we uglily do this :
720ffcc65e36 added automatic streamer detection.
hamidouk
parents: 582
diff changeset
    69
            */
720ffcc65e36 added automatic streamer detection.
hamidouk
parents: 582
diff changeset
    70
            opts.file = "";
720ffcc65e36 added automatic streamer detection.
hamidouk
parents: 582
diff changeset
    71
            opts.streamer = "";
720ffcc65e36 added automatic streamer detection.
hamidouk
parents: 582
diff changeset
    72
            var fullPath = IriSP.__jsonMetadata["medias"][0]["href"];
720ffcc65e36 added automatic streamer detection.
hamidouk
parents: 582
diff changeset
    73
            var pathSplit = fullPath.split('/');
720ffcc65e36 added automatic streamer detection.
hamidouk
parents: 582
diff changeset
    74
            
720ffcc65e36 added automatic streamer detection.
hamidouk
parents: 582
diff changeset
    75
            for (var i = 0; i < pathSplit.length; i++) {
720ffcc65e36 added automatic streamer detection.
hamidouk
parents: 582
diff changeset
    76
              if (i < 4) {
720ffcc65e36 added automatic streamer detection.
hamidouk
parents: 582
diff changeset
    77
                 opts.streamer += pathSplit[i] + "/";
720ffcc65e36 added automatic streamer detection.
hamidouk
parents: 582
diff changeset
    78
              } else {
720ffcc65e36 added automatic streamer detection.
hamidouk
parents: 582
diff changeset
    79
                 opts.file += pathSplit[i];
720ffcc65e36 added automatic streamer detection.
hamidouk
parents: 582
diff changeset
    80
                 /* omit the last slash if we're on the last element */
720ffcc65e36 added automatic streamer detection.
hamidouk
parents: 582
diff changeset
    81
                 if (i < pathSplit.length - 1)
720ffcc65e36 added automatic streamer detection.
hamidouk
parents: 582
diff changeset
    82
                  opts.file += "/";
720ffcc65e36 added automatic streamer detection.
hamidouk
parents: 582
diff changeset
    83
              }
720ffcc65e36 added automatic streamer detection.
hamidouk
parents: 582
diff changeset
    84
            }
720ffcc65e36 added automatic streamer detection.
hamidouk
parents: 582
diff changeset
    85
456
7fcdb501effd added a switch to choose different options if using rtmp or not.
hamidouk
parents: 453
diff changeset
    86
          } else {
7fcdb501effd added a switch to choose different options if using rtmp or not.
hamidouk
parents: 453
diff changeset
    87
            /* other providers type, video for instance -
7fcdb501effd added a switch to choose different options if using rtmp or not.
hamidouk
parents: 453
diff changeset
    88
               pass everything as is */
7fcdb501effd added a switch to choose different options if using rtmp or not.
hamidouk
parents: 453
diff changeset
    89
          }
7fcdb501effd added a switch to choose different options if using rtmp or not.
hamidouk
parents: 453
diff changeset
    90
557
e331072ce8fd added more autoconfig, and an option to specify in site.js where to get the
hamidouk
parents: 539
diff changeset
    91
          if (!options.hasOwnProperty("flashplayer")) {
558
29a370694c53 delete type variable which seemed to sometimes (but not always) confuse the jwplayer,
hamidouk
parents: 557
diff changeset
    92
            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
    93
          }
e331072ce8fd added more autoconfig, and an option to specify in site.js where to get the
hamidouk
parents: 539
diff changeset
    94
e331072ce8fd added more autoconfig, and an option to specify in site.js where to get the
hamidouk
parents: 539
diff changeset
    95
          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
    96
            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
    97
          }
558
29a370694c53 delete type variable which seemed to sometimes (but not always) confuse the jwplayer,
hamidouk
parents: 557
diff changeset
    98
701
a773f117d2e7 adapted init to use the new api.
hamidouk
parents: 632
diff changeset
    99
          pop = new IriSP.PopcornReplacement.jwplayer("#" + containerDiv, opts);
127
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
   100
        break;
198
8ffb1b7a9c6b activated youtube support.
hamidouk
parents: 175
diff changeset
   101
      
8ffb1b7a9c6b activated youtube support.
hamidouk
parents: 175
diff changeset
   102
      case "youtube":
8ffb1b7a9c6b activated youtube support.
hamidouk
parents: 175
diff changeset
   103
          var opts = IriSP.jQuery.extend({}, options);
8ffb1b7a9c6b activated youtube support.
hamidouk
parents: 175
diff changeset
   104
          delete opts.container;
8ffb1b7a9c6b activated youtube support.
hamidouk
parents: 175
diff changeset
   105
          opts.controls = 0;
8ffb1b7a9c6b activated youtube support.
hamidouk
parents: 175
diff changeset
   106
          opts.autostart = false;
204
a5e807f33a67 fixed a margin in youtube player div.
hamidouk
parents: 198
diff changeset
   107
          templ = "width: {{width}}px; height: {{height}}px;";
198
8ffb1b7a9c6b activated youtube support.
hamidouk
parents: 175
diff changeset
   108
          var str = Mustache.to_html(templ, {width: opts.width, height: opts.height});    
8ffb1b7a9c6b activated youtube support.
hamidouk
parents: 175
diff changeset
   109
          // 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
   110
          IriSP.jQuery("#" + containerDiv).attr("style", str);
8ffb1b7a9c6b activated youtube support.
hamidouk
parents: 175
diff changeset
   111
          
500
a784e70993b3 removed mediafragment references as they're implemented by the mediafragment
hamidouk
parents: 461
diff changeset
   112
          pop = Popcorn.youtube("#" + containerDiv, opts.video, opts);
198
8ffb1b7a9c6b activated youtube support.
hamidouk
parents: 175
diff changeset
   113
        break;
127
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
   114
        
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
   115
      default:
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
   116
        pop = undefined;
123
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
   117
    };
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
   118
    
127
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
   119
    return pop;
123
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
   120
};
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
   121
531
e7f27746668e beefed up the docs.
hamidouk
parents: 500
diff changeset
   122
/** Configure the gui and instantiate the widgets passed as parameters
e7f27746668e beefed up the docs.
hamidouk
parents: 500
diff changeset
   123
    @param guiOptions the gui object as seen in the examples.
e7f27746668e beefed up the docs.
hamidouk
parents: 500
diff changeset
   124
 */
158
1813e6e4f0d6 made a small change to the way popcorn is integrated into the page.
hamidouk
parents: 141
diff changeset
   125
IriSP.configureWidgets = function (popcornInstance, layoutManager, guiOptions) {
453
8568e47379a2 added autoconfiguration of the media source for rtmp streams.
hamidouk
parents: 430
diff changeset
   126
 
8568e47379a2 added autoconfiguration of the media source for rtmp streams.
hamidouk
parents: 430
diff changeset
   127
  var serialFactory = new IriSP.SerializerFactory(IriSP.__dataloader);
127
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
   128
  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
   129
127
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
   130
  var ret_widgets = [];
141
becd5f52fa24 this commit fixes an elusive integration bug where the object would get called
hamidouk
parents: 136
diff changeset
   131
  var index;
127
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
   132
  
141
becd5f52fa24 this commit fixes an elusive integration bug where the object would get called
hamidouk
parents: 136
diff changeset
   133
  for (index = 0; index < guiOptions.widgets.length; index++) {    
171
158f0193ec54 added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents: 158
diff changeset
   134
    var widgetConfig = guiOptions.widgets[index];
158f0193ec54 added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents: 158
diff changeset
   135
    var widget = IriSP.instantiateWidget(popcornInstance, serialFactory, layoutManager, widgetConfig);
127
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
   136
    ret_widgets.push(widget);
141
becd5f52fa24 this commit fixes an elusive integration bug where the object would get called
hamidouk
parents: 136
diff changeset
   137
   
127
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
   138
  };
141
becd5f52fa24 this commit fixes an elusive integration bug where the object would get called
hamidouk
parents: 136
diff changeset
   139
127
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
   140
  return ret_widgets;
171
158f0193ec54 added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents: 158
diff changeset
   141
};
158f0193ec54 added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents: 158
diff changeset
   142
531
e7f27746668e beefed up the docs.
hamidouk
parents: 500
diff changeset
   143
/** configure modules. @see configureWidgets */
461
a9c5eeca190c added modules and tbe tests to test them.
hamidouk
parents: 456
diff changeset
   144
IriSP.configureModules = function (popcornInstance, modulesList) {
a9c5eeca190c added modules and tbe tests to test them.
hamidouk
parents: 456
diff changeset
   145
 
a9c5eeca190c added modules and tbe tests to test them.
hamidouk
parents: 456
diff changeset
   146
  var serialFactory = new IriSP.SerializerFactory(IriSP.__dataloader);
a9c5eeca190c added modules and tbe tests to test them.
hamidouk
parents: 456
diff changeset
   147
  var ret_modules = [];
a9c5eeca190c added modules and tbe tests to test them.
hamidouk
parents: 456
diff changeset
   148
  var index;
a9c5eeca190c added modules and tbe tests to test them.
hamidouk
parents: 456
diff changeset
   149
  
a9c5eeca190c added modules and tbe tests to test them.
hamidouk
parents: 456
diff changeset
   150
  for (index = 0; index < modulesList.length; index++) {    
a9c5eeca190c added modules and tbe tests to test them.
hamidouk
parents: 456
diff changeset
   151
    var moduleConfig = modulesList[index];
a9c5eeca190c added modules and tbe tests to test them.
hamidouk
parents: 456
diff changeset
   152
    
a9c5eeca190c added modules and tbe tests to test them.
hamidouk
parents: 456
diff changeset
   153
    var serializer = serialFactory.getSerializer(moduleConfig.metadata);
a9c5eeca190c added modules and tbe tests to test them.
hamidouk
parents: 456
diff changeset
   154
    var module = new IriSP[moduleConfig.type](popcornInstance, moduleConfig, serializer);    
a9c5eeca190c added modules and tbe tests to test them.
hamidouk
parents: 456
diff changeset
   155
    ret_modules.push(module);
a9c5eeca190c added modules and tbe tests to test them.
hamidouk
parents: 456
diff changeset
   156
  };
a9c5eeca190c added modules and tbe tests to test them.
hamidouk
parents: 456
diff changeset
   157
a9c5eeca190c added modules and tbe tests to test them.
hamidouk
parents: 456
diff changeset
   158
  return ret_modules;
a9c5eeca190c added modules and tbe tests to test them.
hamidouk
parents: 456
diff changeset
   159
};
a9c5eeca190c added modules and tbe tests to test them.
hamidouk
parents: 456
diff changeset
   160
531
e7f27746668e beefed up the docs.
hamidouk
parents: 500
diff changeset
   161
/** instantiate a widget - only called by configureWidgets, never by the user. Handles widget 
e7f27746668e beefed up the docs.
hamidouk
parents: 500
diff changeset
   162
    dependencies.
e7f27746668e beefed up the docs.
hamidouk
parents: 500
diff changeset
   163
    @param popcornInstance popcorn instance the widget will user
e7f27746668e beefed up the docs.
hamidouk
parents: 500
diff changeset
   164
    @param serialFactory serializer factory to instantiate the widget with
e7f27746668e beefed up the docs.
hamidouk
parents: 500
diff changeset
   165
    @param layoutManager layout manager
e7f27746668e beefed up the docs.
hamidouk
parents: 500
diff changeset
   166
    @param widgetConfig configuration options for the widget
e7f27746668e beefed up the docs.
hamidouk
parents: 500
diff changeset
   167
 */
171
158f0193ec54 added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents: 158
diff changeset
   168
IriSP.instantiateWidget = function(popcornInstance, serialFactory, layoutManager, widgetConfig) {
287
5c7495102bd7 added a spacer div to simplify some graphic animations.
hamidouk
parents: 216
diff changeset
   169
175
b0cb7132accb variable rename.
hamidouk
parents: 171
diff changeset
   170
    var arr = IriSP.jQuery.extend({}, widgetConfig);
b0cb7132accb variable rename.
hamidouk
parents: 171
diff changeset
   171
    
582
1bca6b7f56e1 give the possibility to specify containers for widgets.
hamidouk
parents: 577
diff changeset
   172
    /* 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
   173
    if (!arr.hasOwnProperty("container")) {
1bca6b7f56e1 give the possibility to specify containers for widgets.
hamidouk
parents: 577
diff changeset
   174
      /* 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
   175
      var ret = layoutManager.createDiv(widgetConfig.type);        
1bca6b7f56e1 give the possibility to specify containers for widgets.
hamidouk
parents: 577
diff changeset
   176
      var container = ret[0];
1bca6b7f56e1 give the possibility to specify containers for widgets.
hamidouk
parents: 577
diff changeset
   177
      var spacer = ret[1];           
1bca6b7f56e1 give the possibility to specify containers for widgets.
hamidouk
parents: 577
diff changeset
   178
      arr.container = container;
1bca6b7f56e1 give the possibility to specify containers for widgets.
hamidouk
parents: 577
diff changeset
   179
      arr.spacer = spacer;
1bca6b7f56e1 give the possibility to specify containers for widgets.
hamidouk
parents: 577
diff changeset
   180
      arr.layoutManager = layoutManager;
1bca6b7f56e1 give the possibility to specify containers for widgets.
hamidouk
parents: 577
diff changeset
   181
    }
171
158f0193ec54 added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents: 158
diff changeset
   182
    var serializer = serialFactory.getSerializer(widgetConfig.metadata);    
175
b0cb7132accb variable rename.
hamidouk
parents: 171
diff changeset
   183
    
b0cb7132accb variable rename.
hamidouk
parents: 171
diff changeset
   184
    if (typeof serializer == "undefined")   
b0cb7132accb variable rename.
hamidouk
parents: 171
diff changeset
   185
      debugger;
b0cb7132accb variable rename.
hamidouk
parents: 171
diff changeset
   186
    
171
158f0193ec54 added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents: 158
diff changeset
   187
    // 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
   188
    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
   189
    
158f0193ec54 added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents: 158
diff changeset
   190
    if (widgetConfig.hasOwnProperty("requires")) {
158f0193ec54 added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents: 158
diff changeset
   191
      // 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
   192
      // 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
   193
      // 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
   194
      
175
b0cb7132accb variable rename.
hamidouk
parents: 171
diff changeset
   195
      var i = 0;
b0cb7132accb variable rename.
hamidouk
parents: 171
diff changeset
   196
      for(i = 0; i < widgetConfig.requires.length; i++) {
b0cb7132accb variable rename.
hamidouk
parents: 171
diff changeset
   197
        var widgetName = widgetConfig.requires[i]["type"];
b0cb7132accb variable rename.
hamidouk
parents: 171
diff changeset
   198
        widget[widgetName] = IriSP.instantiateWidget(popcornInstance, serialFactory, layoutManager, widgetConfig.requires[i]);
171
158f0193ec54 added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents: 158
diff changeset
   199
      }
175
b0cb7132accb variable rename.
hamidouk
parents: 171
diff changeset
   200
    }       
b0cb7132accb variable rename.
hamidouk
parents: 171
diff changeset
   201
     
171
158f0193ec54 added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents: 158
diff changeset
   202
    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
   203
    return widget;
287
5c7495102bd7 added a spacer div to simplify some graphic animations.
hamidouk
parents: 216
diff changeset
   204
};