SlideShare a Scribd company logo
How to Create Your Own jQuery Plugin by Elijah Manor
Who Am I?Sommet Group, offering expertise in payroll, human resources, technology, risk management and insurance to help simplify your business.  Elijah Manorelijah.manor@gmail.com
@elijahmanor
http://elijahmanor.comWhy Create a jQuery Plugin?Reuse, Reuse, & Reuse Encapsulation Prevent Collisions using Namespaces
They are easy to create
Because they are soooo cool    @elijahmanor
How Does a jQuery Plugin Work?Plugins are passed the this object which references the jQuery object Plugin manipulates the DOM When finished, the Plugin should return this to facilitate chaining @elijahmanor
Plugin DeclarationjQuery.prototype.tooltip= function(options) {  $.fn.tooltip = function(options) {   Self Invoking Anonymous Function   (function($){    $.fn.tooltip =       function(options) { ... }   })(jQuery); @elijahmanor
Plugin Parameters: Part 1You could pass individual parameters to your jQueryPlugin$.fn.tooltip =    function(text, color) {};   $('#helloWorld')    .tooltip('Hello World!',      '#cccccc'); However, I am more a proponent of passing a JSON object... @elijahmanor
Plugin Parameters: Part 2Provide a set of Public Accessible Default Plugin Settings for User to Manipulate
Accept Custom Settings from the User
Merge the Default Settings and Custom Settings and use the Union within the Plugin   $.fn.tooltip = function(options){};   $('#helloWorld').tooltip({    text: 'Hello World!',    color: '#cccccc'  });    @elijahmanor
For EachNote: The Plugin may have been passed one or more elements A common technique is to use jQuery'seachmethod to enumerate through the elements   this.each(function() {      var $this = $(this);      //etc...  }  @elijahmanor
Public Functions  $.fn.tooltip = function(options) {    return this.each(function() {    var$this = $(this);    varmessage =         $.fn.tooltip.public();    });};$.fn.tooltip.public = function(){     return 'Hello World!';};@elijahmanor
Private Functions  (function($) {    $.fn.tooltip = function(options) {     varmessage = private();    };      function private() {      return 'Hello World!';    };})(jQuery);@elijahmanor

More Related Content

PDF
Count to 10 and Say Yes
PDF
Magento Attributes - Fresh View
PDF
CFUGbe talk about Angular JS
PDF
Meet Elcodi, the flexible e-commerce components built on Symfony2
PPTX
Cakefest 2010: API Development
PDF
Best Practices for Magento Debugging
ODP
HTML::FormHandler
PPT
WordPress Third Party Authentication
Count to 10 and Say Yes
Magento Attributes - Fresh View
CFUGbe talk about Angular JS
Meet Elcodi, the flexible e-commerce components built on Symfony2
Cakefest 2010: API Development
Best Practices for Magento Debugging
HTML::FormHandler
WordPress Third Party Authentication

What's hot (10)

PPT
Advance jquery-plugin
PDF
Biglietti, prego! A ticket for the (command) bus
PPT
Smarter Interfaces with jQuery (and Drupal)
PPT
Zend framework 04 - forms
KEY
Single Page Web Apps with Backbone.js and Rails
PPSX
Php using variables-operators
PDF
The Human Linter
PPT
Ch 5 boolean logical in alice
PDF
PDF
WordPress: From Antispambot to Zeroize
Advance jquery-plugin
Biglietti, prego! A ticket for the (command) bus
Smarter Interfaces with jQuery (and Drupal)
Zend framework 04 - forms
Single Page Web Apps with Backbone.js and Rails
Php using variables-operators
The Human Linter
Ch 5 boolean logical in alice
WordPress: From Antispambot to Zeroize
Ad

Viewers also liked (8)

PPTX
All in one off page seo
PDF
Making the Work Visible
ODP
Jquery Plugin
PDF
Jquery plugin development
PDF
Test Driving a jQuery Plugin
PDF
So, you want to be a plugin developer?
PDF
An easy guide to Plugin Development
KEY
jQuery Plugin Creation
All in one off page seo
Making the Work Visible
Jquery Plugin
Jquery plugin development
Test Driving a jQuery Plugin
So, you want to be a plugin developer?
An easy guide to Plugin Development
jQuery Plugin Creation
Ad

Similar to jQuery Plugin (20)

PPT
Building Robust jQuery Plugins
PDF
Converting your JS library to a jQuery plugin
PPT
PPT
Intro to jQuery - LUGOR - Part 1
PPT
jQuery For Developers Stack Overflow Dev Days Toronto
PPTX
Jquery plugin development
PDF
Plugin jQuery, Design Patterns
PPT
Jquery presentation
PPT
Eugene Andruszczenko: jQuery
PPT
jQuery Presentation - Refresh Events
PDF
Download full ebook of Extending jQuery Keith Wood download pdf instant downl...
KEY
Jquery Fundamentals
PDF
State of jQuery and Drupal
PDF
DOM Scripting Toolkit - jQuery
PPTX
jQuery
ODP
Making a simple jQuery plug-in
PDF
jQuery State of the Union - Yehuda Katz
PPTX
Client side modularization for modern web applications
PDF
Avinash Kundaliya: Javascript and WordPress
PDF
Remy Sharp The DOM scripting toolkit jQuery
Building Robust jQuery Plugins
Converting your JS library to a jQuery plugin
Intro to jQuery - LUGOR - Part 1
jQuery For Developers Stack Overflow Dev Days Toronto
Jquery plugin development
Plugin jQuery, Design Patterns
Jquery presentation
Eugene Andruszczenko: jQuery
jQuery Presentation - Refresh Events
Download full ebook of Extending jQuery Keith Wood download pdf instant downl...
Jquery Fundamentals
State of jQuery and Drupal
DOM Scripting Toolkit - jQuery
jQuery
Making a simple jQuery plug-in
jQuery State of the Union - Yehuda Katz
Client side modularization for modern web applications
Avinash Kundaliya: Javascript and WordPress
Remy Sharp The DOM scripting toolkit jQuery

Recently uploaded (20)

PDF
cuic standard and advanced reporting.pdf
PDF
A comparative analysis of optical character recognition models for extracting...
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Machine learning based COVID-19 study performance prediction
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Empathic Computing: Creating Shared Understanding
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
Cloud computing and distributed systems.
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
MYSQL Presentation for SQL database connectivity
cuic standard and advanced reporting.pdf
A comparative analysis of optical character recognition models for extracting...
20250228 LYD VKU AI Blended-Learning.pptx
Machine learning based COVID-19 study performance prediction
Assigned Numbers - 2025 - Bluetooth® Document
MIND Revenue Release Quarter 2 2025 Press Release
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Empathic Computing: Creating Shared Understanding
Building Integrated photovoltaic BIPV_UPV.pdf
Advanced methodologies resolving dimensionality complications for autism neur...
“AI and Expert System Decision Support & Business Intelligence Systems”
Cloud computing and distributed systems.
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Encapsulation_ Review paper, used for researhc scholars
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Programs and apps: productivity, graphics, security and other tools
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
MYSQL Presentation for SQL database connectivity

jQuery Plugin

  • 1. How to Create Your Own jQuery Plugin by Elijah Manor
  • 2. Who Am I?Sommet Group, offering expertise in payroll, human resources, technology, risk management and insurance to help simplify your business.  Elijah Manorelijah.manor@gmail.com
  • 4. http://elijahmanor.comWhy Create a jQuery Plugin?Reuse, Reuse, & Reuse Encapsulation Prevent Collisions using Namespaces
  • 5. They are easy to create
  • 6. Because they are soooo cool    @elijahmanor
  • 7. How Does a jQuery Plugin Work?Plugins are passed the this object which references the jQuery object Plugin manipulates the DOM When finished, the Plugin should return this to facilitate chaining @elijahmanor
  • 8. Plugin DeclarationjQuery.prototype.tooltip= function(options) {  $.fn.tooltip = function(options) {   Self Invoking Anonymous Function   (function($){    $.fn.tooltip =       function(options) { ... }   })(jQuery); @elijahmanor
  • 9. Plugin Parameters: Part 1You could pass individual parameters to your jQueryPlugin$.fn.tooltip = function(text, color) {};   $('#helloWorld')   .tooltip('Hello World!', '#cccccc'); However, I am more a proponent of passing a JSON object... @elijahmanor
  • 10. Plugin Parameters: Part 2Provide a set of Public Accessible Default Plugin Settings for User to Manipulate
  • 11. Accept Custom Settings from the User
  • 12. Merge the Default Settings and Custom Settings and use the Union within the Plugin   $.fn.tooltip = function(options){};   $('#helloWorld').tooltip({    text: 'Hello World!',    color: '#cccccc'  });    @elijahmanor
  • 13. For EachNote: The Plugin may have been passed one or more elements A common technique is to use jQuery'seachmethod to enumerate through the elements   this.each(function() {      var $this = $(this);      //etc...  }  @elijahmanor
  • 14. Public Functions $.fn.tooltip = function(options) {  return this.each(function() {    var$this = $(this);    varmessage =       $.fn.tooltip.public();  });};$.fn.tooltip.public = function(){   return 'Hello World!';};@elijahmanor
  • 15. Private Functions (function($) {  $.fn.tooltip = function(options) {     varmessage = private();  };    function private() {    return 'Hello World!';  };})(jQuery);@elijahmanor
  • 16. Support the Metadata Plugin: Part 1Provide Additional Information to a particular element…  <li class="someclass{some: 'data'}"> </li> <lidata="{some:'random', json: 'data'}"></li>Etc…@elijahmanor
  • 17. Support the Metadata Plugin: Part 2  $.fn.tooltip = function(options) {     var opts = $.extend({},         $.fn.tooltip.defaults, options);    return this.each(function() {      var $this = $(this);      //Element Specific Options      var o= $.meta ? $.extend({}, opts, $this.data()):opts; //Plugin Logic Here…    }   }@elijahmanor
  • 18. Allow for Chaining!As with most jQuery functions and Plugins, it is desirable to return the jQuery object to facilitate chaining  $(‘a’).css(‘color’, ‘red’).fadeIn();  (function($){    $.fn.tooltip = function(options){       return this; //chainability      }    })(jQuery); @elijahmanor
  • 25. http://elijahmanor.comIndividuals with a Relevant Question will Receive a Sommet GroupConcept, Code, Conquer jQueryPlugin T-Shirt

Editor's Notes

  • #4: Show Some Demos of Plugins
  • #5: Show jquery.devlink.js