SlideShare a Scribd company logo
jQuery plugin development
phpXperts seminar – 2010
DHAKA.
Ziaul Haq Zia
Sr. Web Application Developer.
Liveoutsource Ltd.
www.jquerygeeek.com
twitter.com/jquerygeek
facebook.com/jquerygeek
About me
What is jQuery plugin ?
 jQuery method.
 Run as jQuery core method.
 Easy to re-use
Let’s see some jQuery plugins ……
Some plugins
 Image Slider
http://workshop.rs/projects/coin-slider/
Some plugins
 Photo gallery
http://leandrovieira.com/projects/jquery/lightbox/
Some plugins
 Anything Slider
http://css-tricks.com/anythingslider-jquery-plugin/
Some plugins
 Tool tip (qTip)
http://craigsworks.com/projects/qtip/
Some plugins
 UI Tab
http://jqueryui.com/demos/tabs/
Plugins Directory
 Thousands of plugins are ready, look here…
http://plugins.jquery.com/
 jgTab
Similar to ‘UI Tab’, right ???
 jgTab
But, at this time we are going to
develop this together.
Let’s enjoy…!! 
This is pretty simple.
HTML Body
<div id="wrapper">
<div id="tabs">
<ul>
<li>Tab One</li>
<li>Tab Two</li>
<li>Tab Three</li>
</ul>
<div>I am first tab’s content,....</div>
<div>I am tab two's content ....</div>
<div>I am the final content.....</div>
</div>
</div>
Let’s start together …
 Let’s set the plugin name as : jgTab
Start with new method
 Add new method to jQuery.fn (prototype)
jQuery.fn.jgTab = function() {
// Here will be our plugin’s stuffs
};
Execute the method
 Wrap it up with a self executing closure.
(function(){
jQuery.fn.jgTab = function() {
// Here will be our plugin’s stuffs
};
})()
Protect our plugin
 Passing jQuery object to avoid conflict
(function($){
$.fn.jgTab = function() {
// Here will be our plugin’s stuffs
};
})(jQuery)
(function($){
$.fn.jgTab = function() {
return this.each(function() {
// Code to work on each item
});
};
})(jQuery)
Iterate the objects
 Returns jQuery object for each element
Let’s have a look at our template
(function($){
$.fn.jgTab = function() {
return this.each(function() {
// Code to work on each item
});
};
})(jQuery);
Our Plugin’s core code
// Collect selector’s object
var masterObj = $(this);
// Collect tab element’s object
var subObj = $('ul li', masterObj);
// Collect content element’s object
var contentObj = $('div', masterObj);
Our Plugin’s core code
var masterObj = $(this);
var subObj = $('ul li', masterObj);
var contentObj = $('div', masterObj);
// Hide All the content elements
contentObj.hide();
Our Plugin’s core code
var masterObj = $(this);
var subObj = $('ul li', masterObj);
var contentObj = $('div', masterObj);
contentObj.hide();
// Setting initial tab position
var intSelected = 0;
// Show initial tab’s content
contentObj.eq(intSelected).show();
// Applying ‘selected’ class for initial tab
subObj.eq(intSelected).addClass('selected');
Our Plugin’s core code
var masterObj = $(this);
var subObj = $('ul li', masterObj);
var contentObj = $('div', masterObj);
contentObj.hide();
var intSelected = 0;
contentObj.eq(intSelected).show();
subObj.eq(intSelected).addClass('selected');
// Clicking on a tab will trigger this action
subObj.click( function(){
// Related codes go here
});
Our Plugin’s core code
subObj.click( function(){
// Hide all content elements and remove
‘selected’ class
contentObj.hide();
subObj.removeClass('selected');
});
Our Plugin’s core code
subObj.click( function(){
contentObj.hide();
subObj.removeClass('selected');
// Collecting the position of clicked tab
var currentTab = subObj.index($(this));
// Opening related content and applying
'selected' class.
contentObj.eq(currentTab).show();
$(this).addClass('selected');
});
Plugin is ready to use
 Now we will put plugin’s core code to our plugin
template.
 And saving it as jquery.jgTab.js
 It’s ready to run.
 Let’s enjoy 
HTML Body Part
<div id="wrapper">
<div id="tabs">
<ul>
<li>Tab One</li>
<li>Tab Two</li>
<li>Tab Three</li>
</ul>
<div>I am first tab’s content....</div>
<div>I am tab two's content.....</div>
<div>I am the final content.....</div>
</div>
</div>
jgTabStyle.css
#wrapper{
padding: 5px;
border: 1px solid #999999;
width: 400px;
}
#tabs{
background-color:#CCCCCC;
padding: 15px;
}
#tabs div{
margin-top: 4px;
padding:5px;
border: 1px solid #666666;
display:none;
background:#FFFFFF;
}
#tabs ul{
margin: 0px;
padding: 0px;
list-style:none;
}
#tabs ul li{
padding: 4px 8px;
list-style:none;
display:inline;
margin: 2px;
border: 1px solid #666666;
font-weight:bold;
background:#666666;
cursor:pointer;
color:#FFFFFF;
}
#tabs ul li.selected{
background:#FFFFFF;
cursor:pointer;
color: #000000;
border-bottom: 1px solid #FFFFFF;
}
Header Part
<script language="javascript" type="text/javascript"
src="js/jquery.js"></script>
<script language="javascript" type="text/javascript"
src="js/jquery.jgTab.js"></script>
<script language="javascript" type="text/javascript">
$(document).ready( function(){
$('#tabs').jgTab();
});
</script>
<link href="css/jgTabStyle.css" rel="stylesheet"
type="text/css" />
And here is the output
Extend the options
(function($){
$.fn.jgTab = function(options) {
var defaults = {
selected : 1
};
if(options) {
var options = $.extend( defaults, options
);
}
return this.each(function() {
// Code to run for each items
});
};
})(jQuery);
Why jQuery plugin ?
 Re-use easily
 Organize you complex code
 Use jQuery core methods by extending
 Namespace your javascript
 Contribute to open source
How jQuery plugin works ?
 jQuery has extendable architecture
 Allows you to write methods that operate on jQuery
objects
 Allows you to extend entire methods
Resource for core jQuery
http://www.visualjquery.com
Visual jQuery
Resource for plugin development
http://docs.jquery.com/Plugins/Authoring
 On jQuery docs
 Few more on here
http://www.webresourcesdepot.com/jquery-plugin-development-10-tutorials-to-get-star
Reference Books
https://www.packtpub.com/jquery-plugin-development-beginners-guide/book
https://www.packtpub.com/learning-jquery-1.3/book?mid=1802090m1d2r
http://www.manning.com/bibeault2/
Learning jQuery 1.3
jQuery Plugin Development Beginner's Guide
Question ?
Please......
If anymore question or help needed,
please mail me :
jquerygeek@gmail.com
Or
Contact me on :
www.jquerygeek.com
Thank You

More Related Content

PDF
JQuery plugin development fundamentals
ODP
Jquery Plugin
PPT
PPTX
jQuery Best Practice
PPTX
Jquery plugin development
PDF
Introducing jQuery
PPTX
jQuery PPT
PPTX
JQuery plugin development fundamentals
Jquery Plugin
jQuery Best Practice
Jquery plugin development
Introducing jQuery
jQuery PPT

What's hot (20)

PPT
JQuery introduction
PPTX
Introduction to jQuery
PPTX
jQuery Fundamentals
PPT
Intro to jQuery
PPTX
jQuery from the very beginning
PDF
jQuery Loves Developers - Oredev 2009
PPTX
jQuery
PDF
Prototype & jQuery
PPTX
jQuery Presentation
PDF
Learning jQuery in 30 minutes
PPT
jQuery 1.7 Events
PDF
jQuery in 15 minutes
PPT
PDF
[PyConTW 2013] Write Sublime Text 2 Packages with Python
PPTX
How to increase Performance of Web Application using JQuery
PDF
Javascript in Plone
PDF
Dojo Confessions
ODP
Introduction to jQuery
KEY
Sprout core and performance
PPTX
Jquery introduction
JQuery introduction
Introduction to jQuery
jQuery Fundamentals
Intro to jQuery
jQuery from the very beginning
jQuery Loves Developers - Oredev 2009
jQuery
Prototype & jQuery
jQuery Presentation
Learning jQuery in 30 minutes
jQuery 1.7 Events
jQuery in 15 minutes
[PyConTW 2013] Write Sublime Text 2 Packages with Python
How to increase Performance of Web Application using JQuery
Javascript in Plone
Dojo Confessions
Introduction to jQuery
Sprout core and performance
Jquery introduction
Ad

Similar to Jquery plugin development (20)

PPTX
JQuery_and_Ajax.pptx
PPTX
jQuery
KEY
Overlays, Accordions & Tabs, Oh My
PPT
Jquery PPT_Finalfgfgdfgdr5tryeujkhdwappt
PDF
Reactive Type safe Webcomponents with skateJS
PPT
Jqueryforbeginnersjqueryconference2009 090914063709 Phpapp02
PPT
jQuery and_drupal
PPTX
Intro to jQuery
PPTX
Jquery Complete Presentation along with Javascript Basics
PDF
Advanced JQuery Mobile tutorial with Phonegap
PPTX
lec 14-15 Jquery_All About J-query_.pptx
PPTX
presentation_jquery_ppt.pptx
KEY
Geek Moot '09 -- Smarty 101
PDF
Jquery tutorial-beginners
PPT
jQuery Fundamentals
PDF
Jqeury ajax plugins
PDF
Jqeury ajax plugins
PPT
Javascript
JQuery_and_Ajax.pptx
jQuery
Overlays, Accordions & Tabs, Oh My
Jquery PPT_Finalfgfgdfgdr5tryeujkhdwappt
Reactive Type safe Webcomponents with skateJS
Jqueryforbeginnersjqueryconference2009 090914063709 Phpapp02
jQuery and_drupal
Intro to jQuery
Jquery Complete Presentation along with Javascript Basics
Advanced JQuery Mobile tutorial with Phonegap
lec 14-15 Jquery_All About J-query_.pptx
presentation_jquery_ppt.pptx
Geek Moot '09 -- Smarty 101
Jquery tutorial-beginners
jQuery Fundamentals
Jqeury ajax plugins
Jqeury ajax plugins
Javascript
Ad

More from Md. Ziaul Haq (6)

PDF
Pwa with vue js
PDF
Taste of RxJS
PDF
The MEAN Stack
PDF
Optimizing AngularJS Application
PDF
Overview on jQuery mobile
PPT
Kick start with j query
Pwa with vue js
Taste of RxJS
The MEAN Stack
Optimizing AngularJS Application
Overview on jQuery mobile
Kick start with j query

Recently uploaded (20)

PDF
How Onsite IT Support Drives Business Efficiency, Security, and Growth.pdf
PDF
CIFDAQ's Market Wrap: Ethereum Leads, Bitcoin Lags, Institutions Shift
PDF
SAP855240_ALP - Defining the Global Template PUBLIC.pdf
PDF
Reimagining Insurance: Connected Data for Confident Decisions.pdf
PDF
Smarter Business Operations Powered by IoT Remote Monitoring
PDF
Transforming Manufacturing operations through Intelligent Integrations
PDF
Electronic commerce courselecture one. Pdf
PDF
KodekX | Application Modernization Development
PDF
Newfamily of error-correcting codes based on genetic algorithms
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
madgavkar20181017ppt McKinsey Presentation.pdf
PDF
HCSP-Presales-Campus Network Planning and Design V1.0 Training Material-Witho...
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Sensors and Actuators in IoT Systems using pdf
PDF
AI And Its Effect On The Evolving IT Sector In Australia - Elevate
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PPTX
Cloud computing and distributed systems.
PDF
CIFDAQ's Teaching Thursday: Moving Averages Made Simple
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
How Onsite IT Support Drives Business Efficiency, Security, and Growth.pdf
CIFDAQ's Market Wrap: Ethereum Leads, Bitcoin Lags, Institutions Shift
SAP855240_ALP - Defining the Global Template PUBLIC.pdf
Reimagining Insurance: Connected Data for Confident Decisions.pdf
Smarter Business Operations Powered by IoT Remote Monitoring
Transforming Manufacturing operations through Intelligent Integrations
Electronic commerce courselecture one. Pdf
KodekX | Application Modernization Development
Newfamily of error-correcting codes based on genetic algorithms
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
madgavkar20181017ppt McKinsey Presentation.pdf
HCSP-Presales-Campus Network Planning and Design V1.0 Training Material-Witho...
NewMind AI Weekly Chronicles - August'25 Week I
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Sensors and Actuators in IoT Systems using pdf
AI And Its Effect On The Evolving IT Sector In Australia - Elevate
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Cloud computing and distributed systems.
CIFDAQ's Teaching Thursday: Moving Averages Made Simple
How UI/UX Design Impacts User Retention in Mobile Apps.pdf

Jquery plugin development

  • 1. jQuery plugin development phpXperts seminar – 2010 DHAKA.
  • 2. Ziaul Haq Zia Sr. Web Application Developer. Liveoutsource Ltd. www.jquerygeeek.com twitter.com/jquerygeek facebook.com/jquerygeek About me
  • 3. What is jQuery plugin ?  jQuery method.  Run as jQuery core method.  Easy to re-use
  • 4. Let’s see some jQuery plugins ……
  • 5. Some plugins  Image Slider http://workshop.rs/projects/coin-slider/
  • 6. Some plugins  Photo gallery http://leandrovieira.com/projects/jquery/lightbox/
  • 7. Some plugins  Anything Slider http://css-tricks.com/anythingslider-jquery-plugin/
  • 8. Some plugins  Tool tip (qTip) http://craigsworks.com/projects/qtip/
  • 9. Some plugins  UI Tab http://jqueryui.com/demos/tabs/
  • 10. Plugins Directory  Thousands of plugins are ready, look here… http://plugins.jquery.com/
  • 11.  jgTab Similar to ‘UI Tab’, right ???
  • 12.  jgTab But, at this time we are going to develop this together.
  • 13. Let’s enjoy…!!  This is pretty simple.
  • 14. HTML Body <div id="wrapper"> <div id="tabs"> <ul> <li>Tab One</li> <li>Tab Two</li> <li>Tab Three</li> </ul> <div>I am first tab’s content,....</div> <div>I am tab two's content ....</div> <div>I am the final content.....</div> </div> </div>
  • 15. Let’s start together …  Let’s set the plugin name as : jgTab
  • 16. Start with new method  Add new method to jQuery.fn (prototype) jQuery.fn.jgTab = function() { // Here will be our plugin’s stuffs };
  • 17. Execute the method  Wrap it up with a self executing closure. (function(){ jQuery.fn.jgTab = function() { // Here will be our plugin’s stuffs }; })()
  • 18. Protect our plugin  Passing jQuery object to avoid conflict (function($){ $.fn.jgTab = function() { // Here will be our plugin’s stuffs }; })(jQuery)
  • 19. (function($){ $.fn.jgTab = function() { return this.each(function() { // Code to work on each item }); }; })(jQuery) Iterate the objects  Returns jQuery object for each element
  • 20. Let’s have a look at our template (function($){ $.fn.jgTab = function() { return this.each(function() { // Code to work on each item }); }; })(jQuery);
  • 21. Our Plugin’s core code // Collect selector’s object var masterObj = $(this); // Collect tab element’s object var subObj = $('ul li', masterObj); // Collect content element’s object var contentObj = $('div', masterObj);
  • 22. Our Plugin’s core code var masterObj = $(this); var subObj = $('ul li', masterObj); var contentObj = $('div', masterObj); // Hide All the content elements contentObj.hide();
  • 23. Our Plugin’s core code var masterObj = $(this); var subObj = $('ul li', masterObj); var contentObj = $('div', masterObj); contentObj.hide(); // Setting initial tab position var intSelected = 0; // Show initial tab’s content contentObj.eq(intSelected).show(); // Applying ‘selected’ class for initial tab subObj.eq(intSelected).addClass('selected');
  • 24. Our Plugin’s core code var masterObj = $(this); var subObj = $('ul li', masterObj); var contentObj = $('div', masterObj); contentObj.hide(); var intSelected = 0; contentObj.eq(intSelected).show(); subObj.eq(intSelected).addClass('selected'); // Clicking on a tab will trigger this action subObj.click( function(){ // Related codes go here });
  • 25. Our Plugin’s core code subObj.click( function(){ // Hide all content elements and remove ‘selected’ class contentObj.hide(); subObj.removeClass('selected'); });
  • 26. Our Plugin’s core code subObj.click( function(){ contentObj.hide(); subObj.removeClass('selected'); // Collecting the position of clicked tab var currentTab = subObj.index($(this)); // Opening related content and applying 'selected' class. contentObj.eq(currentTab).show(); $(this).addClass('selected'); });
  • 27. Plugin is ready to use  Now we will put plugin’s core code to our plugin template.  And saving it as jquery.jgTab.js  It’s ready to run.  Let’s enjoy 
  • 28. HTML Body Part <div id="wrapper"> <div id="tabs"> <ul> <li>Tab One</li> <li>Tab Two</li> <li>Tab Three</li> </ul> <div>I am first tab’s content....</div> <div>I am tab two's content.....</div> <div>I am the final content.....</div> </div> </div>
  • 29. jgTabStyle.css #wrapper{ padding: 5px; border: 1px solid #999999; width: 400px; } #tabs{ background-color:#CCCCCC; padding: 15px; } #tabs div{ margin-top: 4px; padding:5px; border: 1px solid #666666; display:none; background:#FFFFFF; } #tabs ul{ margin: 0px; padding: 0px; list-style:none; } #tabs ul li{ padding: 4px 8px; list-style:none; display:inline; margin: 2px; border: 1px solid #666666; font-weight:bold; background:#666666; cursor:pointer; color:#FFFFFF; } #tabs ul li.selected{ background:#FFFFFF; cursor:pointer; color: #000000; border-bottom: 1px solid #FFFFFF; }
  • 30. Header Part <script language="javascript" type="text/javascript" src="js/jquery.js"></script> <script language="javascript" type="text/javascript" src="js/jquery.jgTab.js"></script> <script language="javascript" type="text/javascript"> $(document).ready( function(){ $('#tabs').jgTab(); }); </script> <link href="css/jgTabStyle.css" rel="stylesheet" type="text/css" />
  • 31. And here is the output
  • 32. Extend the options (function($){ $.fn.jgTab = function(options) { var defaults = { selected : 1 }; if(options) { var options = $.extend( defaults, options ); } return this.each(function() { // Code to run for each items }); }; })(jQuery);
  • 33. Why jQuery plugin ?  Re-use easily  Organize you complex code  Use jQuery core methods by extending  Namespace your javascript  Contribute to open source
  • 34. How jQuery plugin works ?  jQuery has extendable architecture  Allows you to write methods that operate on jQuery objects  Allows you to extend entire methods
  • 35. Resource for core jQuery http://www.visualjquery.com Visual jQuery
  • 36. Resource for plugin development http://docs.jquery.com/Plugins/Authoring  On jQuery docs  Few more on here http://www.webresourcesdepot.com/jquery-plugin-development-10-tutorials-to-get-star
  • 39. If anymore question or help needed, please mail me : [email protected] Or Contact me on : www.jquerygeek.com