Code Monkey home page Code Monkey logo

jquery.pluginify's Introduction

jQPluginify v0.1
By: Adam Jaret (http://atj.me)

Create jQuery plugins with abstracted boilerplate code.

Usage: jQPluginify.CreatePlugin(pluginName, defaultOptions, methods)

Example:

   // File: jquery.myplugin.js
   (function($){
      var methods = {
        "_initialize": function() {
          // Anything your plugin needs to do when first loading
          // Access options using this.settings
          var options = this.settings;
          // Access element using this.$el
          this.$el.click(this.handleClick);
          // Find a child element (this is a shortcut for this.$el.find('.child-element'))
          var child = this.$('.child-element');
        }
        ,"handleClick": function(ev) {
          ev.preventDefault();
          console.log('click!');
          this.test(0);
        }
        ,"test": function(n) {
          console.log('here! '+n);
        }
      };
      jQPluginify.CreatePlugin('myplugin', {}, methods);
   })(jQuery);

   // File: main.js
   ...
   // Initialize plugin (like using any other jQuery plugin)
   $('.my-element').myplugin();
   
   // Execute a method by passing it's name and any parameters
   // Note: method names starting with _ are considered private and will not be called
   $('.my-element').myplugin('test', 1);
   ...

   // File: index.html
   ...
   <script type="text/javascript" src="js/jquery.js" />
   <script type="text/javascript" src="js/jquery.pluginify.js" />
   <script type="text/javascript" src="js/jquery.myplugin.js" />
   <script type="text/javascript" src="js/main.js" />
   ...

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.