src/js/init.js
author hamidouk
Thu, 03 Nov 2011 13:08:49 +0100
branchpopcorn-port
changeset 175 b0cb7132accb
parent 171 158f0193ec54
child 198 8ffb1b7a9c6b
permissions -rw-r--r--
variable rename.
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
158
1813e6e4f0d6 made a small change to the way popcorn is integrated into the page.
hamidouk
parents: 141
diff changeset
     6
IriSP.configurePopcorn = function (layoutManager, options) {
123
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
     7
    var pop;
158
1813e6e4f0d6 made a small change to the way popcorn is integrated into the page.
hamidouk
parents: 141
diff changeset
     8
    var containerDiv = layoutManager.createDiv();
123
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
     9
    
127
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    10
    switch(options.type) {
123
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    11
      /*
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    12
        todo : dynamically create the div/video tag which
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    13
        will contain the video.
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    14
      */
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    15
      case "html5":
158
1813e6e4f0d6 made a small change to the way popcorn is integrated into the page.
hamidouk
parents: 141
diff changeset
    16
           var tmpId = Popcorn.guid("video"); 
1813e6e4f0d6 made a small change to the way popcorn is integrated into the page.
hamidouk
parents: 141
diff changeset
    17
           IriSP.jQuery("#" + containerDiv).append("<video src='" + options.file + "' id='" + tmpId + "'></video>");
1813e6e4f0d6 made a small change to the way popcorn is integrated into the page.
hamidouk
parents: 141
diff changeset
    18
           pop = Popcorn("#" + tmpId);
123
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    19
        break;
127
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    20
        
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    21
      case "jwplayer":
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    22
          var opts = IriSP.jQuery.extend({}, options);
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    23
          delete opts.container;
158
1813e6e4f0d6 made a small change to the way popcorn is integrated into the page.
hamidouk
parents: 141
diff changeset
    24
          pop = Popcorn.jwplayer("#" + containerDiv, "", opts);
127
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    25
        break;
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    26
        
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    27
      default:
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    28
        pop = undefined;
123
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    29
    };
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    30
    
127
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    31
    return pop;
123
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    32
};
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    33
158
1813e6e4f0d6 made a small change to the way popcorn is integrated into the page.
hamidouk
parents: 141
diff changeset
    34
IriSP.configureWidgets = function (popcornInstance, layoutManager, guiOptions) {
123
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    35
127
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    36
  var dt = new IriSP.DataLoader();
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    37
  var serialFactory = new IriSP.SerializerFactory(dt);
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    38
  
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    39
  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
    40
127
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    41
  var ret_widgets = [];
141
becd5f52fa24 this commit fixes an elusive integration bug where the object would get called
hamidouk
parents: 136
diff changeset
    42
  var index;
127
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    43
  
141
becd5f52fa24 this commit fixes an elusive integration bug where the object would get called
hamidouk
parents: 136
diff changeset
    44
  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
    45
    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
    46
    var widget = IriSP.instantiateWidget(popcornInstance, serialFactory, layoutManager, widgetConfig);
127
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    47
    ret_widgets.push(widget);
141
becd5f52fa24 this commit fixes an elusive integration bug where the object would get called
hamidouk
parents: 136
diff changeset
    48
   
127
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    49
  };
141
becd5f52fa24 this commit fixes an elusive integration bug where the object would get called
hamidouk
parents: 136
diff changeset
    50
127
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    51
  return ret_widgets;
171
158f0193ec54 added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents: 158
diff changeset
    52
};
158f0193ec54 added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents: 158
diff changeset
    53
158f0193ec54 added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents: 158
diff changeset
    54
IriSP.instantiateWidget = function(popcornInstance, serialFactory, layoutManager, widgetConfig) {
158f0193ec54 added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents: 158
diff changeset
    55
    var container = layoutManager.createDiv();        
175
b0cb7132accb variable rename.
hamidouk
parents: 171
diff changeset
    56
    var arr = IriSP.jQuery.extend({}, widgetConfig);
171
158f0193ec54 added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents: 158
diff changeset
    57
    arr.container = container;
175
b0cb7132accb variable rename.
hamidouk
parents: 171
diff changeset
    58
    
171
158f0193ec54 added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents: 158
diff changeset
    59
    var serializer = serialFactory.getSerializer(widgetConfig.metadata);    
175
b0cb7132accb variable rename.
hamidouk
parents: 171
diff changeset
    60
    
b0cb7132accb variable rename.
hamidouk
parents: 171
diff changeset
    61
    if (typeof serializer == "undefined")   
b0cb7132accb variable rename.
hamidouk
parents: 171
diff changeset
    62
      debugger;
b0cb7132accb variable rename.
hamidouk
parents: 171
diff changeset
    63
    
171
158f0193ec54 added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents: 158
diff changeset
    64
    // 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
    65
    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
    66
    
158f0193ec54 added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents: 158
diff changeset
    67
    if (widgetConfig.hasOwnProperty("requires")) {
158f0193ec54 added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents: 158
diff changeset
    68
      // 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
    69
      // 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
    70
      // 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
    71
      
175
b0cb7132accb variable rename.
hamidouk
parents: 171
diff changeset
    72
      var i = 0;
b0cb7132accb variable rename.
hamidouk
parents: 171
diff changeset
    73
      for(i = 0; i < widgetConfig.requires.length; i++) {
b0cb7132accb variable rename.
hamidouk
parents: 171
diff changeset
    74
        var widgetName = widgetConfig.requires[i]["type"];
b0cb7132accb variable rename.
hamidouk
parents: 171
diff changeset
    75
        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
    76
      }
175
b0cb7132accb variable rename.
hamidouk
parents: 171
diff changeset
    77
    }       
b0cb7132accb variable rename.
hamidouk
parents: 171
diff changeset
    78
     
171
158f0193ec54 added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents: 158
diff changeset
    79
    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
    80
    return widget;
123
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    81
};