src/js/init.js
author hamidouk
Wed, 07 Dec 2011 14:30:59 +0100
branchpopcorn-port
changeset 422 b14a1a83ebc1
parent 420 03beb43df33a
child 430 c0b529ae20d2
permissions -rw-r--r--
removed noConflict feature.
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>");
402
6148fb647f46 html5 video can now set the height and width of the video.
hamidouk
parents: 315
diff changeset
    19
6148fb647f46 html5 video can now set the height and width of the video.
hamidouk
parents: 315
diff changeset
    20
           if (options.hasOwnProperty("width"))
6148fb647f46 html5 video can now set the height and width of the video.
hamidouk
parents: 315
diff changeset
    21
             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
    22
           
6148fb647f46 html5 video can now set the height and width of the video.
hamidouk
parents: 315
diff changeset
    23
           if (options.hasOwnProperty("height"))
6148fb647f46 html5 video can now set the height and width of the video.
hamidouk
parents: 315
diff changeset
    24
             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
    25
216
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents: 204
diff changeset
    26
           pop = Popcorn("#" + tmpId).mediafragment({start : 0});
123
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    27
        break;
127
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    28
        
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    29
      case "jwplayer":
422
b14a1a83ebc1 removed noConflict feature.
hamidouk
parents: 420
diff changeset
    30
          // Popcorn.noConflict(true); /* remove current popcorn instance */
420
03beb43df33a call our Popcorn replacement when using jwplayer instead of the real popcorn.
hamidouk
parents: 418
diff changeset
    31
          Popcorn = PopcornReplacement;
127
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    32
          var opts = IriSP.jQuery.extend({}, options);
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    33
          delete opts.container;
389
2f855c3efd48 changed init to accomodate the popcorn replacement.
hamidouk
parents: 315
diff changeset
    34
          pop = Popcorn.jwplayer("#" + containerDiv, opts);
127
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    35
        break;
198
8ffb1b7a9c6b activated youtube support.
hamidouk
parents: 175
diff changeset
    36
      
8ffb1b7a9c6b activated youtube support.
hamidouk
parents: 175
diff changeset
    37
      case "youtube":
8ffb1b7a9c6b activated youtube support.
hamidouk
parents: 175
diff changeset
    38
          var opts = IriSP.jQuery.extend({}, options);
8ffb1b7a9c6b activated youtube support.
hamidouk
parents: 175
diff changeset
    39
          delete opts.container;
8ffb1b7a9c6b activated youtube support.
hamidouk
parents: 175
diff changeset
    40
          opts.controls = 0;
8ffb1b7a9c6b activated youtube support.
hamidouk
parents: 175
diff changeset
    41
          opts.autostart = false;
204
a5e807f33a67 fixed a margin in youtube player div.
hamidouk
parents: 198
diff changeset
    42
          templ = "width: {{width}}px; height: {{height}}px;";
198
8ffb1b7a9c6b activated youtube support.
hamidouk
parents: 175
diff changeset
    43
          var str = Mustache.to_html(templ, {width: opts.width, height: opts.height});    
8ffb1b7a9c6b activated youtube support.
hamidouk
parents: 175
diff changeset
    44
          // 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
    45
          IriSP.jQuery("#" + containerDiv).attr("style", str);
8ffb1b7a9c6b activated youtube support.
hamidouk
parents: 175
diff changeset
    46
          
216
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents: 204
diff changeset
    47
          pop = Popcorn.youtube("#" + containerDiv, opts.video, opts).mediafragment({start : 0});
198
8ffb1b7a9c6b activated youtube support.
hamidouk
parents: 175
diff changeset
    48
        break;
127
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    49
        
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    50
      default:
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    51
        pop = undefined;
123
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    52
    };
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    53
    
127
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    54
    return pop;
123
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    55
};
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    56
158
1813e6e4f0d6 made a small change to the way popcorn is integrated into the page.
hamidouk
parents: 141
diff changeset
    57
IriSP.configureWidgets = function (popcornInstance, layoutManager, guiOptions) {
123
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    58
127
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    59
  var dt = new IriSP.DataLoader();
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    60
  var serialFactory = new IriSP.SerializerFactory(dt);
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    61
  
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    62
  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
    63
127
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    64
  var ret_widgets = [];
141
becd5f52fa24 this commit fixes an elusive integration bug where the object would get called
hamidouk
parents: 136
diff changeset
    65
  var index;
127
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    66
  
141
becd5f52fa24 this commit fixes an elusive integration bug where the object would get called
hamidouk
parents: 136
diff changeset
    67
  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
    68
    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
    69
    var widget = IriSP.instantiateWidget(popcornInstance, serialFactory, layoutManager, widgetConfig);
127
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    70
    ret_widgets.push(widget);
141
becd5f52fa24 this commit fixes an elusive integration bug where the object would get called
hamidouk
parents: 136
diff changeset
    71
   
127
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    72
  };
141
becd5f52fa24 this commit fixes an elusive integration bug where the object would get called
hamidouk
parents: 136
diff changeset
    73
127
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    74
  return ret_widgets;
171
158f0193ec54 added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents: 158
diff changeset
    75
};
158f0193ec54 added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents: 158
diff changeset
    76
158f0193ec54 added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents: 158
diff changeset
    77
IriSP.instantiateWidget = function(popcornInstance, serialFactory, layoutManager, widgetConfig) {
287
5c7495102bd7 added a spacer div to simplify some graphic animations.
hamidouk
parents: 216
diff changeset
    78
    /* 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
    79
    var ret = layoutManager.createDiv(widgetConfig.type);        
287
5c7495102bd7 added a spacer div to simplify some graphic animations.
hamidouk
parents: 216
diff changeset
    80
    var container = ret[0];
5c7495102bd7 added a spacer div to simplify some graphic animations.
hamidouk
parents: 216
diff changeset
    81
    var spacer = ret[1];
5c7495102bd7 added a spacer div to simplify some graphic animations.
hamidouk
parents: 216
diff changeset
    82
175
b0cb7132accb variable rename.
hamidouk
parents: 171
diff changeset
    83
    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
    84
    arr.container = container;
287
5c7495102bd7 added a spacer div to simplify some graphic animations.
hamidouk
parents: 216
diff changeset
    85
    arr.spacer = spacer;
175
b0cb7132accb variable rename.
hamidouk
parents: 171
diff changeset
    86
    
171
158f0193ec54 added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents: 158
diff changeset
    87
    var serializer = serialFactory.getSerializer(widgetConfig.metadata);    
175
b0cb7132accb variable rename.
hamidouk
parents: 171
diff changeset
    88
    
b0cb7132accb variable rename.
hamidouk
parents: 171
diff changeset
    89
    if (typeof serializer == "undefined")   
b0cb7132accb variable rename.
hamidouk
parents: 171
diff changeset
    90
      debugger;
b0cb7132accb variable rename.
hamidouk
parents: 171
diff changeset
    91
    
171
158f0193ec54 added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents: 158
diff changeset
    92
    // 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
    93
    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
    94
    
158f0193ec54 added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents: 158
diff changeset
    95
    if (widgetConfig.hasOwnProperty("requires")) {
158f0193ec54 added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents: 158
diff changeset
    96
      // 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
    97
      // 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
    98
      // 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
    99
      
175
b0cb7132accb variable rename.
hamidouk
parents: 171
diff changeset
   100
      var i = 0;
b0cb7132accb variable rename.
hamidouk
parents: 171
diff changeset
   101
      for(i = 0; i < widgetConfig.requires.length; i++) {
b0cb7132accb variable rename.
hamidouk
parents: 171
diff changeset
   102
        var widgetName = widgetConfig.requires[i]["type"];
b0cb7132accb variable rename.
hamidouk
parents: 171
diff changeset
   103
        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
   104
      }
175
b0cb7132accb variable rename.
hamidouk
parents: 171
diff changeset
   105
    }       
b0cb7132accb variable rename.
hamidouk
parents: 171
diff changeset
   106
     
171
158f0193ec54 added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents: 158
diff changeset
   107
    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
   108
    return widget;
287
5c7495102bd7 added a spacer div to simplify some graphic animations.
hamidouk
parents: 216
diff changeset
   109
};