src/js/init.js
author hamidouk
Mon, 14 Nov 2011 10:47:44 +0100
branchslider-port
changeset 230 9b86d3c52211
parent 216 d1e891627286
child 238 6008172a0592
child 287 5c7495102bd7
child 341 e9442357851b
permissions -rw-r--r--
added a handler to seek the slider.
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>");
216
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents: 204
diff changeset
    18
           pop = Popcorn("#" + tmpId).mediafragment({start : 0});
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;
216
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents: 204
diff changeset
    24
          pop = Popcorn.jwplayer("#" + containerDiv, "", opts).mediafragment({start : 0});
127
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    25
        break;
198
8ffb1b7a9c6b activated youtube support.
hamidouk
parents: 175
diff changeset
    26
      
8ffb1b7a9c6b activated youtube support.
hamidouk
parents: 175
diff changeset
    27
      case "youtube":
8ffb1b7a9c6b activated youtube support.
hamidouk
parents: 175
diff changeset
    28
          var opts = IriSP.jQuery.extend({}, options);
8ffb1b7a9c6b activated youtube support.
hamidouk
parents: 175
diff changeset
    29
          delete opts.container;
8ffb1b7a9c6b activated youtube support.
hamidouk
parents: 175
diff changeset
    30
          opts.controls = 0;
8ffb1b7a9c6b activated youtube support.
hamidouk
parents: 175
diff changeset
    31
          opts.autostart = false;
204
a5e807f33a67 fixed a margin in youtube player div.
hamidouk
parents: 198
diff changeset
    32
          templ = "width: {{width}}px; height: {{height}}px;";
198
8ffb1b7a9c6b activated youtube support.
hamidouk
parents: 175
diff changeset
    33
          var str = Mustache.to_html(templ, {width: opts.width, height: opts.height});    
8ffb1b7a9c6b activated youtube support.
hamidouk
parents: 175
diff changeset
    34
          // 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
    35
          IriSP.jQuery("#" + containerDiv).attr("style", str);
8ffb1b7a9c6b activated youtube support.
hamidouk
parents: 175
diff changeset
    36
          
216
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents: 204
diff changeset
    37
          pop = Popcorn.youtube("#" + containerDiv, opts.video, opts).mediafragment({start : 0});
198
8ffb1b7a9c6b activated youtube support.
hamidouk
parents: 175
diff changeset
    38
        break;
127
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    39
        
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    40
      default:
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    41
        pop = undefined;
123
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    42
    };
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    43
    
127
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    44
    return pop;
123
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    45
};
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    46
158
1813e6e4f0d6 made a small change to the way popcorn is integrated into the page.
hamidouk
parents: 141
diff changeset
    47
IriSP.configureWidgets = function (popcornInstance, layoutManager, guiOptions) {
123
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    48
127
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    49
  var dt = new IriSP.DataLoader();
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    50
  var serialFactory = new IriSP.SerializerFactory(dt);
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    51
  
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    52
  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
    53
127
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    54
  var ret_widgets = [];
141
becd5f52fa24 this commit fixes an elusive integration bug where the object would get called
hamidouk
parents: 136
diff changeset
    55
  var index;
127
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    56
  
141
becd5f52fa24 this commit fixes an elusive integration bug where the object would get called
hamidouk
parents: 136
diff changeset
    57
  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
    58
    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
    59
    var widget = IriSP.instantiateWidget(popcornInstance, serialFactory, layoutManager, widgetConfig);
127
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    60
    ret_widgets.push(widget);
141
becd5f52fa24 this commit fixes an elusive integration bug where the object would get called
hamidouk
parents: 136
diff changeset
    61
   
127
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    62
  };
141
becd5f52fa24 this commit fixes an elusive integration bug where the object would get called
hamidouk
parents: 136
diff changeset
    63
127
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    64
  return ret_widgets;
171
158f0193ec54 added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents: 158
diff changeset
    65
};
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
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
    68
    var container = layoutManager.createDiv();        
175
b0cb7132accb variable rename.
hamidouk
parents: 171
diff changeset
    69
    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
    70
    arr.container = container;
175
b0cb7132accb variable rename.
hamidouk
parents: 171
diff changeset
    71
    
171
158f0193ec54 added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents: 158
diff changeset
    72
    var serializer = serialFactory.getSerializer(widgetConfig.metadata);    
175
b0cb7132accb variable rename.
hamidouk
parents: 171
diff changeset
    73
    
b0cb7132accb variable rename.
hamidouk
parents: 171
diff changeset
    74
    if (typeof serializer == "undefined")   
b0cb7132accb variable rename.
hamidouk
parents: 171
diff changeset
    75
      debugger;
b0cb7132accb variable rename.
hamidouk
parents: 171
diff changeset
    76
    
171
158f0193ec54 added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents: 158
diff changeset
    77
    // 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
    78
    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
    79
    
158f0193ec54 added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents: 158
diff changeset
    80
    if (widgetConfig.hasOwnProperty("requires")) {
158f0193ec54 added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents: 158
diff changeset
    81
      // 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
    82
      // 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
    83
      // 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
    84
      
175
b0cb7132accb variable rename.
hamidouk
parents: 171
diff changeset
    85
      var i = 0;
b0cb7132accb variable rename.
hamidouk
parents: 171
diff changeset
    86
      for(i = 0; i < widgetConfig.requires.length; i++) {
b0cb7132accb variable rename.
hamidouk
parents: 171
diff changeset
    87
        var widgetName = widgetConfig.requires[i]["type"];
b0cb7132accb variable rename.
hamidouk
parents: 171
diff changeset
    88
        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
    89
      }
175
b0cb7132accb variable rename.
hamidouk
parents: 171
diff changeset
    90
    }       
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
    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
    93
    return widget;
123
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    94
};