SlideShare a Scribd company logo
JQuery Plugin Development
Faruk Hossen
What is JQuery
➢ JQuery is a Javascript Library.
➢ The jQuery library contains the following features:
○ HTML/DOM manipulation
○ CSS manipulation
○ HTML event methods
○ Effects and animations
○ AJAX
○ Utilities
➢jQuery is a javascript object.
var jQuery = function( ) {
//object properties go here.
};
JQuery Object
➢ ‘$’ is shorthand for jQuery
➢ When we call the $() function and pass a selector to it,
we create a new object
$( document );
$(“div.menu”);
$(“div.menu”).click(function(){
$(this).find(“ul”).show();
}
JQuery Object
➢Javascript prototype object is
■ $.fn or
■ jQuery.fn
JQuery Prototype Object
➢ All objects have a prototype property.
➢ The JavaScript prototype property also allows you to add new methods to
an existing prototype.
➢ It is simply an object from which other objects can inherit properties
What is prototype of an object in js
function person(first, last, age, eye) {
this.firstName = first;
this.lastName = last;
this.age = age;
this.eyeColor = eye;
}
person.prototype.name = function() {
return this.firstName + " " + this.lastName
};
var myFather = new person("John", "Doe", 50, "blue");
console.log(myFather.name());
What is prototype of an object in js
function Person(name) {
this.name = name;
}
Person.prototype.sayHello = function () {
alert(this.name + " says hello");
};
var james = new Person("James");
james.sayHello(); // Alerts "James says hello"
What is prototype of an object in js
jQuery.fn = jQuery.prototype.
from jquery source code:
jQuery.fn = jQuery.prototype = {
init: function( selector, context ) {
// ...
return this;
}
// jQuery API methods
}
What is $.fn
➢ In object-oriented programming languages, this (or self) is a keyword
which can be used in instance methods to refer to the object
➢ There are really two main contexts of 'this' in jQuery.
○ ‘this’ first refers to a DOM element
○ ‘this’ refers to a jQuery object.
What is ‘this’
$( "p" ).click(function() {
$( this ).slideUp();//is it wrong?
this.slideUp() //is it wrong?
});
What is ‘this’ (continues…)
jQuery.fn.newTarget = function() {
this.hide(); //will it show error?
$(this).hide(); //will it show error?
}
$(‘p’).newTarget();
What is ‘this’ (continues…)
What is JQuery Plugin
➢ A jQuery plugin is simply a new method that we use to extend jQuery's
prototype object.
➢ By extending the prototype object you enable all jQuery objects to inherit
any methods that you add.
➢ As established, whenever you call jQuery() you're creating a new jQuery
object, with all of jQuery's methods inherited.
➢Portability
➢Time
Why JQuery Plugin
➢ Packaging a common function within a jQuery plugin will normally make
it more portable.
➢ Doing so allows you to easily integrate the plugin into any number of
projects within a short amount of time.
➢ Reusability, another buzz word, comes hand in hand with this.
portability
➢ It will save you (and your users) time.
➢ The time it takes to develop a robust plugin is clearly worth it when you
consider what it enables.
Time
➢ jQuery allows methods to be added to its library.
➢ When called, these methods are passed the jQuery object within the
JavaScript ‘this’ object.
➢ The DOM nodes can be manipulated as required
➢ The method should return ‘this’ so other functions can be chained.
How JQuery Plugin Works
1.plugin function
2.options
3.callback
4.ability to chain.
JQuery Plugin Components
$( "#clickme" ).click(function() {
$( "#book" ).animate({
opacity: 0.25,
left: "+=50",
height: "toggle"
}, 5000, function() {
// Animation complete.
});
});
JQuery Plugin Components
(function($) {
jQuery.fn.hightlight = function(options) { ... };
})(jQuery);
(function($) {
$.fn.hightlight = function(options) { ... };
})(jQuery);
Note: Using ‘jQuery’ rather than ‘$’ ensures there are no conflicts with other
JavaScript libraries.
JQuery Plugin Declaration
//default settings
(function($) {
$.fn.highlight = function(options) {
var settings = {‘highlight-color’:’white’,’highlight-background’:’yellow’};
$.extend(settings,options);
};
})(jQuery);
Options in Plugin
1. $(“p”).highlight(); //uses default settings.
1. $(“p”).highlight(//uses color:white,background:yellow
‘color’:’white’;
);
1. $(“p”).highlight(//uses color:white,background:red
‘color’:’white’
‘background’:’red’;
);
Passing Options
(function($) {
$.fn.highlight = function(options,callback) {
var settings = {‘highlight-color’:’white’,’highlight-background’:’yellow’};
$.extend(settings,options);
callback.call(this);
};
})(jQuery);
Callback function
1. $(“p”).highlight(//uses color:white,background:red
{
‘color’:’white’
‘background’:’red’
},function(){
//execute after complete
}
);
Callback function
(function($) {
$.fn.highlight = function(options,callback) {
var settings = {‘highlight-color’:’white’,’highlight-background’:’yellow’};
$.extend(settings,options);
callback.call(this);
return this; // it is for chaining
};
})(jQuery);
Ability to chain
Ability to chain
THANKS

More Related Content

What's hot (20)

PDF
jQuery secrets
Bastian Feder
 
KEY
jrubykaigi2010-lt-rubeus
Takeshi AKIMA
 
PPTX
Lecture 6: Client Side Programming 2
Artificial Intelligence Institute at UofSC
 
PPTX
Basics of j query
Rupesh Kumar Tiwari
 
PDF
A New Baseline for Front-End Devs
Rebecca Murphey
 
PPTX
Lecture 5: Client Side Programming 1
Artificial Intelligence Institute at UofSC
 
PPT
Kick start with j query
Md. Ziaul Haq
 
PPT
jQuery
Niladri Karmakar
 
PDF
Beyond the DOM: Sane Structure for JS Apps
Rebecca Murphey
 
PDF
Using Objects to Organize your jQuery Code
Rebecca Murphey
 
ODP
JQuery introduction
Pradeep Saraswathi
 
PPTX
J Query The Write Less Do More Javascript Library
rsnarayanan
 
PDF
Learning jQuery in 30 minutes
Simon Willison
 
PPT
jQuery 1.7 Events
dmethvin
 
PDF
How Kris Writes Symfony Apps
Kris Wallsmith
 
PPTX
jQuery Data Manipulate API - A source code dissecting journey
Huiyi Yan
 
PPTX
How to increase Performance of Web Application using JQuery
kolkatageeks
 
PDF
Your Entity, Your Code
Marco Vito Moscaritolo
 
jQuery secrets
Bastian Feder
 
jrubykaigi2010-lt-rubeus
Takeshi AKIMA
 
Lecture 6: Client Side Programming 2
Artificial Intelligence Institute at UofSC
 
Basics of j query
Rupesh Kumar Tiwari
 
A New Baseline for Front-End Devs
Rebecca Murphey
 
Lecture 5: Client Side Programming 1
Artificial Intelligence Institute at UofSC
 
Kick start with j query
Md. Ziaul Haq
 
Beyond the DOM: Sane Structure for JS Apps
Rebecca Murphey
 
Using Objects to Organize your jQuery Code
Rebecca Murphey
 
JQuery introduction
Pradeep Saraswathi
 
J Query The Write Less Do More Javascript Library
rsnarayanan
 
Learning jQuery in 30 minutes
Simon Willison
 
jQuery 1.7 Events
dmethvin
 
How Kris Writes Symfony Apps
Kris Wallsmith
 
jQuery Data Manipulate API - A source code dissecting journey
Huiyi Yan
 
How to increase Performance of Web Application using JQuery
kolkatageeks
 
Your Entity, Your Code
Marco Vito Moscaritolo
 

Viewers also liked (6)

PPTX
Box Sạc Dự Phòng - Công Cụ Cần Có Dành Cho Dân Phượt
Tí Bụng Bự
 
ODP
Jquery Plugin
Simone Gentili
 
PPT
[Java] Khái niệm về RMI trong Java và cách sử dụng RMI
Tí Bụng Bự
 
KEY
jQuery Plugin Creation
benalman
 
PDF
Oop unit 05 một số kỹ thuật java nâng cao
Tráng Hà Viết
 
PDF
Artificial intelligence ai l1-gioi thieu
Tráng Hà Viết
 
Box Sạc Dự Phòng - Công Cụ Cần Có Dành Cho Dân Phượt
Tí Bụng Bự
 
Jquery Plugin
Simone Gentili
 
[Java] Khái niệm về RMI trong Java và cách sử dụng RMI
Tí Bụng Bự
 
jQuery Plugin Creation
benalman
 
Oop unit 05 một số kỹ thuật java nâng cao
Tráng Hà Viết
 
Artificial intelligence ai l1-gioi thieu
Tráng Hà Viết
 
Ad

Similar to Jquery plugin development (20)

PPT
jQuery
Mohammed Arif
 
PPTX
Jqueryppt (1)
AndreaSmile06
 
PPT
J query presentation
sawarkar17
 
PPT
J query presentation
akanksha17
 
PPT
JS Libraries and jQuery Overview
Aleksandr Motsjonov
 
PPTX
J query resh
Resh Mahtani
 
PPTX
Upstate CSCI 450 jQuery
DanWooster1
 
PDF
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
Doris Chen
 
PPTX
JQuery_and_Ajax.pptx
AditiPawale1
 
PPT
Intro to jQuery - LUGOR - Part 1
Ralph Whitbeck
 
PPT
jQuery For Developers Stack Overflow Dev Days Toronto
Ralph Whitbeck
 
PDF
jQuery Interview Questions By ScholarHat.pdf
Scholarhat
 
PPTX
Starting with jQuery
Anil Kumar
 
PDF
jQuery in 15 minutes
Simon Willison
 
PDF
jQuery (DrupalCamp Toronto)
jeresig
 
KEY
Jquery Fundamentals
Rebecca Murphey
 
PPT
JQuery introduction
NexThoughts Technologies
 
KEY
Everything You Need to Know in Order to Start Using jQuery
Dave Ross
 
Jqueryppt (1)
AndreaSmile06
 
J query presentation
sawarkar17
 
J query presentation
akanksha17
 
JS Libraries and jQuery Overview
Aleksandr Motsjonov
 
J query resh
Resh Mahtani
 
Upstate CSCI 450 jQuery
DanWooster1
 
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
Doris Chen
 
JQuery_and_Ajax.pptx
AditiPawale1
 
Intro to jQuery - LUGOR - Part 1
Ralph Whitbeck
 
jQuery For Developers Stack Overflow Dev Days Toronto
Ralph Whitbeck
 
jQuery Interview Questions By ScholarHat.pdf
Scholarhat
 
Starting with jQuery
Anil Kumar
 
jQuery in 15 minutes
Simon Willison
 
jQuery (DrupalCamp Toronto)
jeresig
 
Jquery Fundamentals
Rebecca Murphey
 
JQuery introduction
NexThoughts Technologies
 
Everything You Need to Know in Order to Start Using jQuery
Dave Ross
 
Ad

Recently uploaded (20)

PPTX
GitOps_Without_K8s_Training_detailed git repository
DanialHabibi2
 
PPTX
Snet+Pro+Service+Software_SNET+Pro+2+Instructions.pptx
jenilsatikuvar1
 
PDF
MAD Unit - 2 Activity and Fragment Management in Android (Diploma IT)
JappanMavani
 
PDF
MAD Unit - 1 Introduction of Android IT Department
JappanMavani
 
PPTX
GitOps_Repo_Structure for begeinner(Scaffolindg)
DanialHabibi2
 
PDF
Unified_Cloud_Comm_Presentation anil singh ppt
anilsingh298751
 
PPTX
MobileComputingMANET2023 MobileComputingMANET2023.pptx
masterfake98765
 
PPTX
Day2 B2 Best.pptx
helenjenefa1
 
DOCX
CS-802 (A) BDH Lab manual IPS Academy Indore
thegodhimself05
 
PPTX
美国电子版毕业证南卡罗莱纳大学上州分校水印成绩单USC学费发票定做学位证书编号怎么查
Taqyea
 
PPTX
MPMC_Module-2 xxxxxxxxxxxxxxxxxxxxx.pptx
ShivanshVaidya5
 
PPTX
Arduino Based Gas Leakage Detector Project
CircuitDigest
 
PPTX
Solar Thermal Energy System Seminar.pptx
Gpc Purapuza
 
PDF
PORTFOLIO Golam Kibria Khan — architect with a passion for thoughtful design...
MasumKhan59
 
PPTX
Element 7. CHEMICAL AND BIOLOGICAL AGENT.pptx
merrandomohandas
 
PPTX
Lecture 1 Shell and Tube Heat exchanger-1.pptx
mailforillegalwork
 
PDF
Reasons for the succes of MENARD PRESSUREMETER.pdf
majdiamz
 
PPTX
UNIT DAA PPT cover all topics 2021 regulation
archu26
 
PDF
Biomechanics of Gait: Engineering Solutions for Rehabilitation (www.kiu.ac.ug)
publication11
 
PDF
Ethics and Trustworthy AI in Healthcare – Governing Sensitive Data, Profiling...
AlqualsaDIResearchGr
 
GitOps_Without_K8s_Training_detailed git repository
DanialHabibi2
 
Snet+Pro+Service+Software_SNET+Pro+2+Instructions.pptx
jenilsatikuvar1
 
MAD Unit - 2 Activity and Fragment Management in Android (Diploma IT)
JappanMavani
 
MAD Unit - 1 Introduction of Android IT Department
JappanMavani
 
GitOps_Repo_Structure for begeinner(Scaffolindg)
DanialHabibi2
 
Unified_Cloud_Comm_Presentation anil singh ppt
anilsingh298751
 
MobileComputingMANET2023 MobileComputingMANET2023.pptx
masterfake98765
 
Day2 B2 Best.pptx
helenjenefa1
 
CS-802 (A) BDH Lab manual IPS Academy Indore
thegodhimself05
 
美国电子版毕业证南卡罗莱纳大学上州分校水印成绩单USC学费发票定做学位证书编号怎么查
Taqyea
 
MPMC_Module-2 xxxxxxxxxxxxxxxxxxxxx.pptx
ShivanshVaidya5
 
Arduino Based Gas Leakage Detector Project
CircuitDigest
 
Solar Thermal Energy System Seminar.pptx
Gpc Purapuza
 
PORTFOLIO Golam Kibria Khan — architect with a passion for thoughtful design...
MasumKhan59
 
Element 7. CHEMICAL AND BIOLOGICAL AGENT.pptx
merrandomohandas
 
Lecture 1 Shell and Tube Heat exchanger-1.pptx
mailforillegalwork
 
Reasons for the succes of MENARD PRESSUREMETER.pdf
majdiamz
 
UNIT DAA PPT cover all topics 2021 regulation
archu26
 
Biomechanics of Gait: Engineering Solutions for Rehabilitation (www.kiu.ac.ug)
publication11
 
Ethics and Trustworthy AI in Healthcare – Governing Sensitive Data, Profiling...
AlqualsaDIResearchGr
 

Jquery plugin development

  • 2. What is JQuery ➢ JQuery is a Javascript Library. ➢ The jQuery library contains the following features: ○ HTML/DOM manipulation ○ CSS manipulation ○ HTML event methods ○ Effects and animations ○ AJAX ○ Utilities
  • 3. ➢jQuery is a javascript object. var jQuery = function( ) { //object properties go here. }; JQuery Object
  • 4. ➢ ‘$’ is shorthand for jQuery ➢ When we call the $() function and pass a selector to it, we create a new object $( document ); $(“div.menu”); $(“div.menu”).click(function(){ $(this).find(“ul”).show(); } JQuery Object
  • 5. ➢Javascript prototype object is ■ $.fn or ■ jQuery.fn JQuery Prototype Object
  • 6. ➢ All objects have a prototype property. ➢ The JavaScript prototype property also allows you to add new methods to an existing prototype. ➢ It is simply an object from which other objects can inherit properties What is prototype of an object in js
  • 7. function person(first, last, age, eye) { this.firstName = first; this.lastName = last; this.age = age; this.eyeColor = eye; } person.prototype.name = function() { return this.firstName + " " + this.lastName }; var myFather = new person("John", "Doe", 50, "blue"); console.log(myFather.name()); What is prototype of an object in js
  • 8. function Person(name) { this.name = name; } Person.prototype.sayHello = function () { alert(this.name + " says hello"); }; var james = new Person("James"); james.sayHello(); // Alerts "James says hello" What is prototype of an object in js
  • 9. jQuery.fn = jQuery.prototype. from jquery source code: jQuery.fn = jQuery.prototype = { init: function( selector, context ) { // ... return this; } // jQuery API methods } What is $.fn
  • 10. ➢ In object-oriented programming languages, this (or self) is a keyword which can be used in instance methods to refer to the object ➢ There are really two main contexts of 'this' in jQuery. ○ ‘this’ first refers to a DOM element ○ ‘this’ refers to a jQuery object. What is ‘this’
  • 11. $( "p" ).click(function() { $( this ).slideUp();//is it wrong? this.slideUp() //is it wrong? }); What is ‘this’ (continues…)
  • 12. jQuery.fn.newTarget = function() { this.hide(); //will it show error? $(this).hide(); //will it show error? } $(‘p’).newTarget(); What is ‘this’ (continues…)
  • 13. What is JQuery Plugin ➢ A jQuery plugin is simply a new method that we use to extend jQuery's prototype object. ➢ By extending the prototype object you enable all jQuery objects to inherit any methods that you add. ➢ As established, whenever you call jQuery() you're creating a new jQuery object, with all of jQuery's methods inherited.
  • 15. ➢ Packaging a common function within a jQuery plugin will normally make it more portable. ➢ Doing so allows you to easily integrate the plugin into any number of projects within a short amount of time. ➢ Reusability, another buzz word, comes hand in hand with this. portability
  • 16. ➢ It will save you (and your users) time. ➢ The time it takes to develop a robust plugin is clearly worth it when you consider what it enables. Time
  • 17. ➢ jQuery allows methods to be added to its library. ➢ When called, these methods are passed the jQuery object within the JavaScript ‘this’ object. ➢ The DOM nodes can be manipulated as required ➢ The method should return ‘this’ so other functions can be chained. How JQuery Plugin Works
  • 18. 1.plugin function 2.options 3.callback 4.ability to chain. JQuery Plugin Components
  • 19. $( "#clickme" ).click(function() { $( "#book" ).animate({ opacity: 0.25, left: "+=50", height: "toggle" }, 5000, function() { // Animation complete. }); }); JQuery Plugin Components
  • 20. (function($) { jQuery.fn.hightlight = function(options) { ... }; })(jQuery); (function($) { $.fn.hightlight = function(options) { ... }; })(jQuery); Note: Using ‘jQuery’ rather than ‘$’ ensures there are no conflicts with other JavaScript libraries. JQuery Plugin Declaration
  • 21. //default settings (function($) { $.fn.highlight = function(options) { var settings = {‘highlight-color’:’white’,’highlight-background’:’yellow’}; $.extend(settings,options); }; })(jQuery); Options in Plugin
  • 22. 1. $(“p”).highlight(); //uses default settings. 1. $(“p”).highlight(//uses color:white,background:yellow ‘color’:’white’; ); 1. $(“p”).highlight(//uses color:white,background:red ‘color’:’white’ ‘background’:’red’; ); Passing Options
  • 23. (function($) { $.fn.highlight = function(options,callback) { var settings = {‘highlight-color’:’white’,’highlight-background’:’yellow’}; $.extend(settings,options); callback.call(this); }; })(jQuery); Callback function
  • 25. (function($) { $.fn.highlight = function(options,callback) { var settings = {‘highlight-color’:’white’,’highlight-background’:’yellow’}; $.extend(settings,options); callback.call(this); return this; // it is for chaining }; })(jQuery); Ability to chain