Giter Club home page Giter Club logo

advanced-jquery-boilerplate's Introduction

Advanced jQuery Boilerplate

A jQuery plugin to create scalable jQuery plugins, fast!

Sample Plugin: jQuery Tabslide

How To

To register a new plugin provide a plugin name, default options, public methods and global methods (if any):

(function($, win, doc, undefined) {

  var pluginName, defaults, methods, global;

  // The name of your plugin
  pluginName = 'myplugin';

  // Default options
  defaults = {

  };

  // Public methods
  methods = {

    // Gets called when creating a new instance
    // this.el is the element on which the plugin was called
    // this.opts contains the options passed to the plugin
    _init: function() {
      this.$el = $(this.el);
    },

    method: function() {

    }
  };

  // Global properties and methods get attached to `$`
  // as opposed to `$.fn` so they can be extended from the outside
  global = {

  };

  // Add the plugin to the jQuery namespace and set-up the boilerplate base
  $.newPlugin(pluginName, defaults, methods, global);

}(jQuery, window, document));

Usage

Now you can use your new plugin on any jQuery collection like so:

// Attach a new instance and run the `init` method
$('selector').myplugin({ options }); 

The plugin attaches an instance of itself to the element(s) so after you initialize it you can call any method by calling the plugin again with the name of the method and its arguments:

$('selector').myplugin('method', arg1, arg2, ...);

All methods return this so everything can be chained by default. If you want to get the returned value of a method, prefix the call with get::

$('selector').myplugin('get:method', arg1, arg2, ...);  

You can access the current instance of the plugin with data:

$instance = $('selector').data('myplugin');
$instance.property;
$instance.method();

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.