Skip to content

Instantly share code, notes, and snippets.

@cange
Created March 21, 2010 14:01
Show Gist options
  • Save cange/339316 to your computer and use it in GitHub Desktop.
Save cange/339316 to your computer and use it in GitHub Desktop.
/**
* Mashup of jquery.pyte and jquery.customdata for Component-based plugins
* load classes from JavaScript.
* @see http://github.com/psyk/jquery-pyte
* @see http://github.com/ubilabs/jquery-customdata
*
* @example
* <!-- DOM structure -->
* <div id="myComponent" data-jsc="module.MyComponent">component content</div>
*
* //JavaScript module/MyComponent.js
* module.MyComponent = $.inherit({
* __constructor: function(){
* your components source
* }
* });
*/
$.extend({
autoLoad: function () {
$.require('jquery.customdata.js');
$(":customdata").each(function () {
var jsClass = $(this).customdata().jsc;
if(jsClass.length > 0) {
$.require(jsClass);
window.eval(jsClass.split(/.*\./)[1] + ' = new ' + jsClass);
}
})
}
});
$.autoLoad();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment