src/js/widgets.js
author veltr
Tue, 17 Apr 2012 15:03:40 +0200
branchnew-model
changeset 866 3bf7aa8216e5
parent 842 4ae2247a59f4
child 868 a525cc2214e7
permissions -rw-r--r--
IriSP.Model.List now inherits from Array
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
66
13013b9452af Added a new file to the build, widgets.js, to contain widget classes.
hamidouk
parents:
diff changeset
     1
/* the widget classes and definitions */
13013b9452af Added a new file to the build, widgets.js, to contain widget classes.
hamidouk
parents:
diff changeset
     2
520
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents: 287
diff changeset
     3
/**
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents: 287
diff changeset
     4
  * @class Widget is an "abstract" class. It's mostly used to define some properties common to every widget.
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents: 287
diff changeset
     5
  *
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents: 287
diff changeset
     6
  *  Note that widget constructors are never called directly by the user. Instead, the widgets are instantiated by functions
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents: 287
diff changeset
     7
  *  defined in init.js
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents: 287
diff changeset
     8
  *  
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents: 287
diff changeset
     9
  * @constructor
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents: 287
diff changeset
    10
  * @param Popcorn a reference to the popcorn Object
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents: 287
diff changeset
    11
  * @param config configuration options for the widget
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents: 287
diff changeset
    12
  * @param Serializer a serializer instance from which the widget reads data fromCharCode  
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents: 287
diff changeset
    13
*/
74
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents: 66
diff changeset
    14
IriSP.Widget = function(Popcorn, config, Serializer) {
114
eda061f1aa75 added a .selector object to all the widgets.
hamidouk
parents: 98
diff changeset
    15
eda061f1aa75 added a .selector object to all the widgets.
hamidouk
parents: 98
diff changeset
    16
  if (config === undefined || config === null) {
eda061f1aa75 added a .selector object to all the widgets.
hamidouk
parents: 98
diff changeset
    17
    config = {}
eda061f1aa75 added a .selector object to all the widgets.
hamidouk
parents: 98
diff changeset
    18
  }
eda061f1aa75 added a .selector object to all the widgets.
hamidouk
parents: 98
diff changeset
    19
  
74
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents: 66
diff changeset
    20
  this._Popcorn = Popcorn;
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents: 66
diff changeset
    21
  this._config = config;  
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents: 66
diff changeset
    22
  this._serializer = Serializer;
114
eda061f1aa75 added a .selector object to all the widgets.
hamidouk
parents: 98
diff changeset
    23
  
124
2758dfb208b2 changed widget.js to add some properties to the widget. Widgets now only get the
hamidouk
parents: 122
diff changeset
    24
  if (config.hasOwnProperty("container")) {
2758dfb208b2 changed widget.js to add some properties to the widget. Widgets now only get the
hamidouk
parents: 122
diff changeset
    25
     this._id = config.container;
114
eda061f1aa75 added a .selector object to all the widgets.
hamidouk
parents: 98
diff changeset
    26
     this.selector = IriSP.jQuery("#" + this._id);
124
2758dfb208b2 changed widget.js to add some properties to the widget. Widgets now only get the
hamidouk
parents: 122
diff changeset
    27
  }
2758dfb208b2 changed widget.js to add some properties to the widget. Widgets now only get the
hamidouk
parents: 122
diff changeset
    28
287
5c7495102bd7 added a spacer div to simplify some graphic animations.
hamidouk
parents: 170
diff changeset
    29
  if (config.hasOwnProperty("spacer")) {
5c7495102bd7 added a spacer div to simplify some graphic animations.
hamidouk
parents: 170
diff changeset
    30
     this._spacerId = config.spacer;
5c7495102bd7 added a spacer div to simplify some graphic animations.
hamidouk
parents: 170
diff changeset
    31
     this.spacer = IriSP.jQuery("#" + this._spacerId);
5c7495102bd7 added a spacer div to simplify some graphic animations.
hamidouk
parents: 170
diff changeset
    32
  }
5c7495102bd7 added a spacer div to simplify some graphic animations.
hamidouk
parents: 170
diff changeset
    33
5c7495102bd7 added a spacer div to simplify some graphic animations.
hamidouk
parents: 170
diff changeset
    34
124
2758dfb208b2 changed widget.js to add some properties to the widget. Widgets now only get the
hamidouk
parents: 122
diff changeset
    35
  if (config.hasOwnProperty("width")) {
2758dfb208b2 changed widget.js to add some properties to the widget. Widgets now only get the
hamidouk
parents: 122
diff changeset
    36
     // this.width and not this._width because we consider it public.
2758dfb208b2 changed widget.js to add some properties to the widget. Widgets now only get the
hamidouk
parents: 122
diff changeset
    37
     this.width = config.width;     
2758dfb208b2 changed widget.js to add some properties to the widget. Widgets now only get the
hamidouk
parents: 122
diff changeset
    38
  }
2758dfb208b2 changed widget.js to add some properties to the widget. Widgets now only get the
hamidouk
parents: 122
diff changeset
    39
  
170
5150ae56e0a6 added two new config values for a widget : heightmax and widthmax.
hamidouk
parents: 124
diff changeset
    40
  if (config.hasOwnProperty("height")) {    
124
2758dfb208b2 changed widget.js to add some properties to the widget. Widgets now only get the
hamidouk
parents: 122
diff changeset
    41
     this.height = config.height;     
2758dfb208b2 changed widget.js to add some properties to the widget. Widgets now only get the
hamidouk
parents: 122
diff changeset
    42
  }
2758dfb208b2 changed widget.js to add some properties to the widget. Widgets now only get the
hamidouk
parents: 122
diff changeset
    43
  
170
5150ae56e0a6 added two new config values for a widget : heightmax and widthmax.
hamidouk
parents: 124
diff changeset
    44
  if (config.hasOwnProperty("heightmax")) {
5150ae56e0a6 added two new config values for a widget : heightmax and widthmax.
hamidouk
parents: 124
diff changeset
    45
     this.heightmax = config.heightmax;     
5150ae56e0a6 added two new config values for a widget : heightmax and widthmax.
hamidouk
parents: 124
diff changeset
    46
  }
5150ae56e0a6 added two new config values for a widget : heightmax and widthmax.
hamidouk
parents: 124
diff changeset
    47
5150ae56e0a6 added two new config values for a widget : heightmax and widthmax.
hamidouk
parents: 124
diff changeset
    48
  if (config.hasOwnProperty("widthmax")) {
5150ae56e0a6 added two new config values for a widget : heightmax and widthmax.
hamidouk
parents: 124
diff changeset
    49
     this.widthmax = config.widthmax;     
539
3ba5b82aebb6 added code to select widgets to the layoutmanager, similar to what jquery does.
hamidouk
parents: 520
diff changeset
    50
  } 
3ba5b82aebb6 added code to select widgets to the layoutmanager, similar to what jquery does.
hamidouk
parents: 520
diff changeset
    51
3ba5b82aebb6 added code to select widgets to the layoutmanager, similar to what jquery does.
hamidouk
parents: 520
diff changeset
    52
  if (config.hasOwnProperty("layoutManager")) {
830
18ca612e9ff0 Lots of changes
veltr
parents: 826
diff changeset
    53
     this.layoutManager = config.layoutManager;
170
5150ae56e0a6 added two new config values for a widget : heightmax and widthmax.
hamidouk
parents: 124
diff changeset
    54
  }
830
18ca612e9ff0 Lots of changes
veltr
parents: 826
diff changeset
    55
  if (typeof this.selector != "undefined") {
18ca612e9ff0 Lots of changes
veltr
parents: 826
diff changeset
    56
      this.selector.addClass("Ldt-TraceMe").addClass("Ldt-Widget");
835
a8af9da7c622 Integrated trace manager
veltr
parents: 830
diff changeset
    57
      this.selector.attr("widget-type", this._config.type);
826
c7ae4f126e51 Starting implementing a trace widget
veltr
parents: 539
diff changeset
    58
  }
124
2758dfb208b2 changed widget.js to add some properties to the widget. Widgets now only get the
hamidouk
parents: 122
diff changeset
    59
  
842
4ae2247a59f4 Changes for Cinecast
veltr
parents: 835
diff changeset
    60
  // Parsing Widget Defaults
4ae2247a59f4 Changes for Cinecast
veltr
parents: 835
diff changeset
    61
  var _this = this;
4ae2247a59f4 Changes for Cinecast
veltr
parents: 835
diff changeset
    62
  
4ae2247a59f4 Changes for Cinecast
veltr
parents: 835
diff changeset
    63
  if (typeof config.type == "string" && typeof IriSP.widgetsDefaults[config.type] == "object") {
866
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 842
diff changeset
    64
      config = IriSP._.defaults(IriSP.widgetsDefaults[config.type]);
842
4ae2247a59f4 Changes for Cinecast
veltr
parents: 835
diff changeset
    65
  }
4ae2247a59f4 Changes for Cinecast
veltr
parents: 835
diff changeset
    66
  
66
13013b9452af Added a new file to the build, widgets.js, to contain widget classes.
hamidouk
parents:
diff changeset
    67
};
13013b9452af Added a new file to the build, widgets.js, to contain widget classes.
hamidouk
parents:
diff changeset
    68
830
18ca612e9ff0 Lots of changes
veltr
parents: 826
diff changeset
    69
842
4ae2247a59f4 Changes for Cinecast
veltr
parents: 835
diff changeset
    70
IriSP.Widget.prototype.currentMedia = function() {
4ae2247a59f4 Changes for Cinecast
veltr
parents: 835
diff changeset
    71
    return this._serializer.currentMedia();
4ae2247a59f4 Changes for Cinecast
veltr
parents: 835
diff changeset
    72
}
4ae2247a59f4 Changes for Cinecast
veltr
parents: 835
diff changeset
    73
4ae2247a59f4 Changes for Cinecast
veltr
parents: 835
diff changeset
    74
IriSP.Widget.prototype.getDuration = function() {
4ae2247a59f4 Changes for Cinecast
veltr
parents: 835
diff changeset
    75
    return this._serializer.getDuration();
830
18ca612e9ff0 Lots of changes
veltr
parents: 826
diff changeset
    76
}
18ca612e9ff0 Lots of changes
veltr
parents: 826
diff changeset
    77
520
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents: 287
diff changeset
    78
/**
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents: 287
diff changeset
    79
  * This method responsible of drawing a widget on screen.
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents: 287
diff changeset
    80
  */
66
13013b9452af Added a new file to the build, widgets.js, to contain widget classes.
hamidouk
parents:
diff changeset
    81
IriSP.Widget.prototype.draw = function() {
13013b9452af Added a new file to the build, widgets.js, to contain widget classes.
hamidouk
parents:
diff changeset
    82
  /* implemented by "sub-classes" */  
13013b9452af Added a new file to the build, widgets.js, to contain widget classes.
hamidouk
parents:
diff changeset
    83
};
74
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents: 66
diff changeset
    84
520
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents: 287
diff changeset
    85
/**
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents: 287
diff changeset
    86
  * Optional method if you want your widget to support redraws.
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents: 287
diff changeset
    87
  */
74
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents: 66
diff changeset
    88
IriSP.Widget.prototype.redraw = function() {
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents: 66
diff changeset
    89
  /* implemented by "sub-classes" */  
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents: 66
diff changeset
    90
};