jQuery: The Write Less, Do More JavaScript Library

Use this extension for dynamic loading of plugins:

$.require('jquery.corner',{jsbase: 'js',
  onload: function(){
    $('#tabs li').corner('top 3px');
  }
});
$.require('jquery.csscheckbox',
  {css: true, jsbase: 'js', cssbase: 'css'});

Options:

  • css: true/false. switch css loading
  • jsbase: base directory for js files
  • cssbase: base directory for css files
  • onload: callback method

Here is the code

// Plugin loading in jquery
// Jose I. Paris
(function(jq){
  jq.extend({
    require: function(plugin, o){
      o = jq.extend({
        css: false,
        jsbase: '',
        cssbase: '',
        onload: null
      }, o || {});
      var src = o.jsbase + '/' + plugin + '.js';
      // Provide a callback function to the getScript function
      jq.getScript(src, o.onload);
      if(o.css){
        var c = document.createElement('link');
        c.type = 'text/css';
        c.rel = 'stylesheet';
        c.href = o.cssbase + '/' + plugin + '.css';
        jq('head')[0].appendChild(c);
      }
    }
  });
})(jQuery);