Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Developing a jQuery Plugin
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
James Hughes
October 22, 2010
Programming
210
3
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Developing a jQuery Plugin
Old presentation from the archives.
James Hughes
October 22, 2010
More Decks by James Hughes
See All by James Hughes
Functional Programming with Clojure
kouphax
1
170
Tyrannosaurus Rx
kouphax
0
140
React
kouphax
2
760
Play for (Java|Scala)
kouphax
0
160
Devops: A Case Study
kouphax
0
110
Scala for C# Developers
kouphax
5
2.7k
Dropwizard - Production Ready Web Services
kouphax
3
1.7k
Scala for Fun & Profit
kouphax
4
680
What Agile Means To Me
kouphax
0
190
Other Decks in Programming
See All in Programming
iOSDCのペンライトを自動制御したい!
akkeylab
0
310
カツオ、ご期待ください
suneo3476
0
130
Starting & Sustaining Code-Based E2E Testing for Non-Coding QA Teams( #jasstniigata )
teyamagu
PRO
1
800
一人だけ、Kiroが静止する日
hideg
0
140
setup-vp GitLab対応の裏側
naokihaba
0
140
FreeBSDでZabbixを動かす
kenkino
0
340
Verilogで学ぶCPU自作入門.pdf
uyuki234
7
3.9k
SONY CISC-NEWS NWS-1750 + NWB-225 フレームバッファの NetBSD/news68k ドライバ実装 / OSC2026Hiroshima
tsutsui
0
160
MVNOの申込からeSIM開通までをiOSアプリでつなぐ- 本人確認・MNP・通信事業者基盤をまたぐ実装
satotakeshi
0
510
Webの地図
yosuke_furukawa
PRO
6
5k
Findy - エンジニア向け会社紹介/Findy Company Deck
findyinc
6
400k
AGENTS.md Is Not Enough:Build Skills, Don't Download Them
lx_t
0
130
Featured
See All Featured
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
1
430
Building the Perfect Custom Keyboard
takai
2
890
Color Theory Basics | Prateek | Gurzu
gurzu
1
480
Highjacked: Video Game Concept Design
rkendrick25
PRO
1
470
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
750
The Invisible Side of Design
smashingmag
301
52k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
203
76k
AI: The stuff that nobody shows you
jnunemaker
PRO
10
1.1k
[Rails World 2026] Durable orchestration on Rails: from continuation to workflow
palkan
1
400
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
420
The SEO Collaboration Effect
kristinabergwall1
1
580
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
690
Transcript
Introduc)on to jQuery
Developing a Plugin
The Original Func)on /* Make Element Standout */
func)on standout(element){ element.style.border = “1px solid #f00”; } standout(document.getElementById(‘myelement’) );
Steps 1. Convert to Plugin 2. Encapsulate Plugin
Specific Code 3. Support Chaining 4. Expose Global Defaults 5. Support “Per-‐Call” ConfiguraCon 6. Support “Per-‐Element” ConfiguraCon
As a Plugin /* plugin code */
$.fn.standout = func)on() this.css(“border”, “1px solid #f00”); } $(“div”).standout()
Encapsulate Plugin Specific Code (func)on($){
/* plugin code */ $.fn.standout = func)on() debug(this); this.css(“border”, “1px solid #f00”); }; /* private debug method */ func)on debug(o) { console.log(“Count:” + o.length); } })(jQuery);
Facilitate Chaining (func)on($){ /*
plugin code */ $.fn.standout = func)on() debug(this); return this.css(“border”, “1px solid #f00”); } func)on debug(o) { … } })(jQuery); $(“div”).standout().fadeOut()
Expose Global Defaults /* plugin code
*/ $.fn.standout = func)on() if($.fn.standout.defaults.debug){ debug(this); } return this.css( "border", $.fn.standout.defaults.borderStyle ); } /* global defaults*/ $.fn.standout.defaults = { borderStyle : "1px solid #f00” debug: window.console && window.console.log }
Support “Per-‐Call” Configura)on /* plugin code
*/ $.fn.standout = func)on(opts) var o = $.extend({}, $.fn.standout.defaults, opts); return this.css("border", o.borderStyle); }; /* global defaults */ $.fn.standout.defaults = { borderStyle : "1px solid #f00” debug: window.console && window.console.log } $(“div”).standout({debug:false})
Support “Per-‐Element” Configura)on /* plugin code
*/ $.fn.standout = func)on(opts) var o = $.extend({}, $.fn.standout.defaults, opts); return this.each(func)on() { var t = $(this); var eo = $.meta ? $.extend({}, o, t.data()) : o; t.css("border", eo.borderStyle); }); }; <div class=“{borderStyle: ‘1px solid blue’}”></div>
Sta)c Plugins
getParam Method (func)on($){ /* extract
a parameter from URL */ $.getParam = func)on(name) { var param = new RegExp( '[\\?&]' + name + '=([^&#]*)’ ).exec(window.loca)on.href); return (param) ? param[1] : null; }; })(jQuery); // hip://www.mysite.com/?username=jameshu $.getParam(“username”); // <-‐-‐ “jameshu”
getParam Method (Alterna)ve) $.extend({
/* extract a parameter from URL */ getParam : func)on(name) { var param = new RegExp( '[\\?&]' + name + '=([^&#]*)’ ).exec(window.loca)on.href); return (param) ? param[1] : null; } });
Pseudo Selectors
Modified Input Field Selector /* Add Modified Input Field
Selector*/ $.extend($.expr[':'], { modified: func)on(el, idx, tokens) { /* tokens[3] = args*/ return $(el).is("input") && el.defaultValue != el.value; } }); /* Clear all modified input elements */ $("input:modified") .val(“”);
Ques)ons?