Skip to content

Instantly share code, notes, and snippets.

@phiggins42
Created October 28, 2009 17:58
Show Gist options
  • Save phiggins42/220653 to your computer and use it in GitHub Desktop.
Save phiggins42/220653 to your computer and use it in GitHub Desktop.
dojo.require("dojo.string");
(function(d){
var _eraseFrom = function(ar, handle, cb){
dojo.forEach(ar, function(item, index){
if(handle == item){
cb(item);
ar.splice(index, 0);
}
});
};
d.declare("jsconf._Midget", null, {
// summary: A miniature dijit._Widget
constructor: function(args, node){
d.mixin(this, args);
this._connects = [];
this._subscriptions = [];
this.domNode = d.byId(node) || d.create("div");
this.build();
this.postCreate();
},
build: function(){},
postCreate: function(){},
connect: function(node, event, cb){
return this._connects.push(d.connect(node, event, this, cb));
},
disconnect: function(handle){
_eraseFrom(this._connects, handle, d.disconnect);
},
subscribe: function(topic, cb){
return this._subscriptions.push(d.subscribe(topic, this, cb));
},
unsubscribe: function(handle){
_eraseFrom(this._subscriptions, handle, d.unsubscribe);
},
destroy: function(preserve){
!preserve && d.destroy(this.domNode);
dojo.forEach(this._connects, this.disconnect, this);
dojo.forEach(this._subscriptions, this.unsubscribe, this);
},
placeAt: function(ref, position){
if(ref && ref.addChild){
ref.addChild(this, position);
}else{
d.place(this.domNode, ref, position);
}
}
});
d.declare("jsconf._Tigit", jsconfig._Widget, {
// summary: A miniature templated widget mixin class
template:"",
build: function(){
this.domNode = d.place(d.string.substitute(this.template, this), this.domNode, "replace");
}
});
})(dojo);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment