src/js/init.js
author hamidouk
Thu, 27 Oct 2011 13:36:49 +0200
branchpopcorn-port
changeset 158 1813e6e4f0d6
parent 141 becd5f52fa24
child 171 158f0193ec54
permissions -rw-r--r--
made a small change to the way popcorn is integrated into the page.
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++) {    
127
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    45
    var widget = guiOptions.widgets[index];
158
1813e6e4f0d6 made a small change to the way popcorn is integrated into the page.
hamidouk
parents: 141
diff changeset
    46
    var container = layoutManager.createDiv();
127
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    47
        
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    48
    var arr = IriSP.jQuery.extend({}, widget);
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    49
    arr.container = container;
141
becd5f52fa24 this commit fixes an elusive integration bug where the object would get called
hamidouk
parents: 136
diff changeset
    50
129
296d9ddf9cc1 init now more or less passes unit tests.
hamidouk
parents: 127
diff changeset
    51
    var serializer = serialFactory.getSerializer(widget.metadata);    
141
becd5f52fa24 this commit fixes an elusive integration bug where the object would get called
hamidouk
parents: 136
diff changeset
    52
127
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    53
    // instantiate the object passed as a string
141
becd5f52fa24 this commit fixes an elusive integration bug where the object would get called
hamidouk
parents: 136
diff changeset
    54
    var widget = new IriSP[widget.type](popcornInstance, arr, serializer);
becd5f52fa24 this commit fixes an elusive integration bug where the object would get called
hamidouk
parents: 136
diff changeset
    55
    
becd5f52fa24 this commit fixes an elusive integration bug where the object would get called
hamidouk
parents: 136
diff changeset
    56
    serializer.sync(IriSP.wrap(widget, function() { this.draw(); }));
127
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    57
    ret_widgets.push(widget);
141
becd5f52fa24 this commit fixes an elusive integration bug where the object would get called
hamidouk
parents: 136
diff changeset
    58
   
127
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    59
  };
141
becd5f52fa24 this commit fixes an elusive integration bug where the object would get called
hamidouk
parents: 136
diff changeset
    60
127
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    61
  return ret_widgets;
123
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    62
};