bf3b4c8b681a51e5381a0fdbf713da7b7ef7a5b9
[ccsdk/features.git] /
1 (function( $, joey, app ) {
2
3         var ui = app.ns("ui");
4         var ux = app.ns("ux");
5
6         ui.AbstractWidget = ux.Observable.extend({
7                 defaults : {
8                         id: null     // the id of the widget
9                 },
10
11                 el: null,       // this is the jquery wrapped dom element(s) that is the root of the widget
12
13                 init: function() {
14                         this._super();
15                         for(var prop in this) {       // automatically bind all the event handlers
16                                 if(prop.contains("_handler")) {
17                                         this[prop] = this[prop].bind(this);
18                                 }
19                         }
20                 },
21
22                 id: function(suffix) {
23                         return this.config.id ? (this.config.id + (suffix ? "-" + suffix : "")) : undefined;
24                 },
25
26                 attach: function( parent, method ) {
27                         if( parent ) {
28                                 this.el[ method || "appendTo"]( parent );
29                         }
30                         this.fire("attached", this );
31                         return this;
32                 },
33
34                 remove: function() {
35                         this.el.remove();
36                         this.fire("removed", this );
37                         this.removeAllObservers();
38                         this.el = null;
39                         return this;
40                 }
41         });
42
43         joey.plugins.push( function( obj ) {
44                 if( obj instanceof ui.AbstractWidget ) {
45                         return obj.el[0];
46                 }
47         });
48
49 })( this.jQuery, this.joey, this.app );