2 * Copyright 2010-2013 Ben Birch
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this software except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 (function( $, joey, app ) {
18 var ui = app.ns("ui");
19 var ux = app.ns("ux");
21 ui.AbstractWidget = ux.Observable.extend({
23 id: null // the id of the widget
26 el: null, // this is the jquery wrapped dom element(s) that is the root of the widget
30 for(var prop in this) { // automatically bind all the event handlers
31 if(prop.contains("_handler")) {
32 this[prop] = this[prop].bind(this);
37 id: function(suffix) {
38 return this.config.id ? (this.config.id + (suffix ? "-" + suffix : "")) : undefined;
41 attach: function( parent, method ) {
43 this.el[ method || "appendTo"]( parent );
45 this.fire("attached", this );
51 this.fire("removed", this );
52 this.removeAllObservers();
58 joey.plugins.push( function( obj ) {
59 if( obj instanceof ui.AbstractWidget ) {
64 })( this.jQuery, this.joey, this.app );