src/js/init.js
author hamidouk
Tue, 29 Nov 2011 11:09:08 +0100
branchpopcorn-port
changeset 345 8a088f7daa66
parent 315 4466bf448426
child 389 2f855c3efd48
child 402 6148fb647f46
permissions -rw-r--r--
rollover over the interface buttons now works as expected. Also changed the width of the buttons to the correct size. Resized the width and height of the sprites to be the same as the boxes we display them in.
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;
287
5c7495102bd7 added a spacer div to simplify some graphic animations.
hamidouk
parents: 216
diff changeset
     8
    var ret = layoutManager.createDiv(); 
5c7495102bd7 added a spacer div to simplify some graphic animations.
hamidouk
parents: 216
diff changeset
     9
    var containerDiv = ret[0];
123
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    10
    
127
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    11
    switch(options.type) {
123
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    12
      /*
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    13
        todo : dynamically create the div/video tag which
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    14
        will contain the video.
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    15
      */
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    16
      case "html5":
158
1813e6e4f0d6 made a small change to the way popcorn is integrated into the page.
hamidouk
parents: 141
diff changeset
    17
           var tmpId = Popcorn.guid("video"); 
1813e6e4f0d6 made a small change to the way popcorn is integrated into the page.
hamidouk
parents: 141
diff changeset
    18
           IriSP.jQuery("#" + containerDiv).append("<video src='" + options.file + "' id='" + tmpId + "'></video>");
216
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents: 204
diff changeset
    19
           pop = Popcorn("#" + tmpId).mediafragment({start : 0});
123
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    20
        break;
127
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    21
        
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    22
      case "jwplayer":
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    23
          var opts = IriSP.jQuery.extend({}, options);
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    24
          delete opts.container;
216
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents: 204
diff changeset
    25
          pop = Popcorn.jwplayer("#" + containerDiv, "", opts).mediafragment({start : 0});
127
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    26
        break;
198
8ffb1b7a9c6b activated youtube support.
hamidouk
parents: 175
diff changeset
    27
      
8ffb1b7a9c6b activated youtube support.
hamidouk
parents: 175
diff changeset
    28
      case "youtube":
8ffb1b7a9c6b activated youtube support.
hamidouk
parents: 175
diff changeset
    29
          var opts = IriSP.jQuery.extend({}, options);
8ffb1b7a9c6b activated youtube support.
hamidouk
parents: 175
diff changeset
    30
          delete opts.container;
8ffb1b7a9c6b activated youtube support.
hamidouk
parents: 175
diff changeset
    31
          opts.controls = 0;
8ffb1b7a9c6b activated youtube support.
hamidouk
parents: 175
diff changeset
    32
          opts.autostart = false;
204
a5e807f33a67 fixed a margin in youtube player div.
hamidouk
parents: 198
diff changeset
    33
          templ = "width: {{width}}px; height: {{height}}px;";
198
8ffb1b7a9c6b activated youtube support.
hamidouk
parents: 175
diff changeset
    34
          var str = Mustache.to_html(templ, {width: opts.width, height: opts.height});    
8ffb1b7a9c6b activated youtube support.
hamidouk
parents: 175
diff changeset
    35
          // 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
    36
          IriSP.jQuery("#" + containerDiv).attr("style", str);
8ffb1b7a9c6b activated youtube support.
hamidouk
parents: 175
diff changeset
    37
          
216
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents: 204
diff changeset
    38
          pop = Popcorn.youtube("#" + containerDiv, opts.video, opts).mediafragment({start : 0});
198
8ffb1b7a9c6b activated youtube support.
hamidouk
parents: 175
diff changeset
    39
        break;
127
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    40
        
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    41
      default:
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    42
        pop = undefined;
123
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    43
    };
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    44
    
127
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    45
    return pop;
123
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    46
};
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    47
158
1813e6e4f0d6 made a small change to the way popcorn is integrated into the page.
hamidouk
parents: 141
diff changeset
    48
IriSP.configureWidgets = function (popcornInstance, layoutManager, guiOptions) {
123
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    49
127
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    50
  var dt = new IriSP.DataLoader();
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    51
  var serialFactory = new IriSP.SerializerFactory(dt);
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    52
  
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    53
  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
    54
127
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    55
  var ret_widgets = [];
141
becd5f52fa24 this commit fixes an elusive integration bug where the object would get called
hamidouk
parents: 136
diff changeset
    56
  var index;
127
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    57
  
141
becd5f52fa24 this commit fixes an elusive integration bug where the object would get called
hamidouk
parents: 136
diff changeset
    58
  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
    59
    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
    60
    var widget = IriSP.instantiateWidget(popcornInstance, serialFactory, layoutManager, widgetConfig);
127
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    61
    ret_widgets.push(widget);
141
becd5f52fa24 this commit fixes an elusive integration bug where the object would get called
hamidouk
parents: 136
diff changeset
    62
   
127
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    63
  };
141
becd5f52fa24 this commit fixes an elusive integration bug where the object would get called
hamidouk
parents: 136
diff changeset
    64
127
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    65
  return ret_widgets;
171
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
158f0193ec54 added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents: 158
diff changeset
    68
IriSP.instantiateWidget = function(popcornInstance, serialFactory, layoutManager, widgetConfig) {
287
5c7495102bd7 added a spacer div to simplify some graphic animations.
hamidouk
parents: 216
diff changeset
    69
    /* create div returns us a container for the widget and a spacer */
315
4466bf448426 updated layout and init to give more meaningful names to the widgets divs.
hamidouk
parents: 287
diff changeset
    70
    var ret = layoutManager.createDiv(widgetConfig.type);        
287
5c7495102bd7 added a spacer div to simplify some graphic animations.
hamidouk
parents: 216
diff changeset
    71
    var container = ret[0];
5c7495102bd7 added a spacer div to simplify some graphic animations.
hamidouk
parents: 216
diff changeset
    72
    var spacer = ret[1];
5c7495102bd7 added a spacer div to simplify some graphic animations.
hamidouk
parents: 216
diff changeset
    73
175
b0cb7132accb variable rename.
hamidouk
parents: 171
diff changeset
    74
    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
    75
    arr.container = container;
287
5c7495102bd7 added a spacer div to simplify some graphic animations.
hamidouk
parents: 216
diff changeset
    76
    arr.spacer = spacer;
175
b0cb7132accb variable rename.
hamidouk
parents: 171
diff changeset
    77
    
171
158f0193ec54 added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents: 158
diff changeset
    78
    var serializer = serialFactory.getSerializer(widgetConfig.metadata);    
175
b0cb7132accb variable rename.
hamidouk
parents: 171
diff changeset
    79
    
b0cb7132accb variable rename.
hamidouk
parents: 171
diff changeset
    80
    if (typeof serializer == "undefined")   
b0cb7132accb variable rename.
hamidouk
parents: 171
diff changeset
    81
      debugger;
b0cb7132accb variable rename.
hamidouk
parents: 171
diff changeset
    82
    
171
158f0193ec54 added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents: 158
diff changeset
    83
    // 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
    84
    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
    85
    
158f0193ec54 added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents: 158
diff changeset
    86
    if (widgetConfig.hasOwnProperty("requires")) {
158f0193ec54 added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents: 158
diff changeset
    87
      // 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
    88
      // 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
    89
      // 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
    90
      
175
b0cb7132accb variable rename.
hamidouk
parents: 171
diff changeset
    91
      var i = 0;
b0cb7132accb variable rename.
hamidouk
parents: 171
diff changeset
    92
      for(i = 0; i < widgetConfig.requires.length; i++) {
b0cb7132accb variable rename.
hamidouk
parents: 171
diff changeset
    93
        var widgetName = widgetConfig.requires[i]["type"];
b0cb7132accb variable rename.
hamidouk
parents: 171
diff changeset
    94
        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
    95
      }
175
b0cb7132accb variable rename.
hamidouk
parents: 171
diff changeset
    96
    }       
b0cb7132accb variable rename.
hamidouk
parents: 171
diff changeset
    97
     
171
158f0193ec54 added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents: 158
diff changeset
    98
    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
    99
    return widget;
287
5c7495102bd7 added a spacer div to simplify some graphic animations.
hamidouk
parents: 216
diff changeset
   100
};