Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
WordCamp Phoenix 2013: WordPress 301: JavaScript
Search
Natalie MacLees
January 18, 2013
Technology
2
520
WordCamp Phoenix 2013: WordPress 301: JavaScript
A talk introducing JavaScript in general and how to correctly use JavaScript in WordPress.
Natalie MacLees
January 18, 2013
Tweet
Share
More Decks by Natalie MacLees
See All by Natalie MacLees
Creating content for everyone
nataliemac
0
34
Making your website work for everyone: accessibility testing
nataliemac
1
50
The Tangled Web We're Weaving: The Future of WordPress Accessibility
nataliemac
0
40
Making the world a better place through web design
nataliemac
0
110
One Percent Better: How little changes add up
nataliemac
1
85
One percent better
nataliemac
2
53
How to make time for a side hustle
nataliemac
0
3.7k
Before You React
nataliemac
2
330
Bulletproof JavaScript for plugins and themes
nataliemac
2
240
Other Decks in Technology
See All in Technology
Prisma ORMを2年運用して培ったノウハウを共有する
tockn
19
5k
知識と実践を紡ぐGenAI / Connecting Knowledge and experience with GenAI
aki_moon
2
170
[2024년 5월 세미나] 생성형 AI와 함께하는 데이터 분석가 커리어
datarian
0
1.2k
Dungeons and Dragons and Rails
joelq
0
230
日本が誇るイタリアのダンスミュージック!? ユーロビートって何??
minorun365
PRO
1
180
TailwindCSSでUIライブラリを作る際のハマりどころ
shuta13
0
230
本当のガバクラ基礎
toru_kubota
0
310
本番環境で Cloudflareを 使ってみた話
miu_crescent
2
120
テストコードを書きながらCompose Multiplatformを乗りこなす
subroh0508
0
140
AI JIMY - 登壇(インストール編)
hanacchi
0
150
複雑なビジネスルールに挑む:正確性と効率性を両立するfp-tsのチーム活用術 / Strike a balance between correctness and efficiency with fp-ts
kakehashi
5
3.5k
iThome2024 Wailing Wall of Enterprise Security
notsurprised
0
280
Featured
See All Featured
Code Review Best Practice
trishagee
56
15k
Fireside Chat
paigeccino
22
2.7k
How to Ace a Technical Interview
jacobian
273
22k
Fontdeck: Realign not Redesign
paulrobertlloyd
76
4.9k
Put a Button on it: Removing Barriers to Going Fast.
kastner
58
3.1k
Web development in the modern age
philhawksworth
203
10k
Java REST API Framework Comparison - PWX 2021
mraible
PRO
18
7k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
15
1.6k
Making the Leap to Tech Lead
cromwellryan
125
8.6k
A designer walks into a library…
pauljervisheath
201
23k
Imperfection Machines: The Place of Print at Facebook
scottboms
261
12k
Optimising Largest Contentful Paint
csswizardry
13
2.4k
Transcript
WordPress 301: JavaScript Natalie MacLees
About Me • Purple Pen Productions founder + principal •
jQuery for Designers author • SoCal WP Users’ Group organizer • jQuery LA Users’ Group founder + organizer @nataliemac | nataliemac.com
What is JavaScript? http://www.flickr.com/photos/bijoubaby/4539701617/
Extend HTML & CSS http://www.flickr.com/photos/liquene/3329868155/
Learning JavaScript How do we get started?
The Ideal http://www.flickr.com/photos/simonov/476780331/ learn it all perfectly, and then use
it
erinaceous lamprophony depone finnimbrun floccinaucinihilipilification inaniloquent limerance mesonoxian mungo nihilarian
The Reality http://www.flickr.com/photos/scalino/6629580443/ haphazard, learn as you go
Copy http://www.flickr.com/photos/5tein/2347819459/ and learn
Best Practices Things to keep in mind
Progressive Enhancement http://www.flickr.com/photos/kassel1/3104649691/ & graceful degradation
Layers Start with one and add on
Backend http://www.flickr.com/photos/14550765@N02/2505010784/
Content http://www.flickr.com/photos/andrea_r/3973740643 html
Presentation http://www.flickr.com/photos/lynstar/3880196378/ css
Behavior http://www.flickr.com/photos/auxesis/2964133796/ javascript
JavaScript in WordPress
Including JavaScript header.php <head> <meta charset="<?php bloginfo( 'charset' ); ?>"
/> <title><?php wp_title( '|', true, 'right' ); ?></ title> <script src="/wp-content/themes/twentytwelve/scripts/ my-script.js"></script> <?php wp_head(); ?> </head>
Including JavaScript header.php <head> <meta charset="<?php bloginfo( 'charset' ); ?>"
/> <title><?php wp_title( '|', true, 'right' ); ?></ title> <script src="/wp-content/themes/twentytwelve/scripts/ my-script.js"></script> <?php wp_head(); ?> </head>
Including JavaScript header.php <head> <meta charset="<?php bloginfo( 'charset' ); ?>"
/> <title><?php wp_title( '|', true, 'right' ); ?></ title> <script src="<?php bloginfo('template_directory'); ?>/ scripts/my-script.js"></script> <?php wp_head(); ?> </head>
Including JavaScript header.php <head> <meta charset="<?php bloginfo( 'charset' ); ?>"
/> <title><?php wp_title( '|', true, 'right' ); ?></ title> <script src="<?php bloginfo('template_directory'); ?>/ scripts/my-script.js"></script> <?php wp_head(); ?> </head>
WP Helper Functions wp_register_script( $handle, $src, $deps, $ver, $in_footer );
wp_enqueue_script( $handle, $src, $deps, $ver, $in_footer );
Including JavaScript functions.php function prefix_load_scripts() { ! wp_register_script( 'my-script', get_template_directory_uri()
. '/scripts/my- script.js' ); ! wp_enqueue_script( 'my-script' ); } add_action( 'wp_enqueue_scripts', 'prefix_load_scripts' );
Using Included Libraries functions.php function prefix_load_scripts() { ! wp_register_script( 'my-script',
get_template_directory_uri() . '/scripts/my-script.js', array( 'jquery' ), '1.0', true ); ! wp_enqueue_script( 'my-script' ); } add_action( 'wp_enqueue_scripts', 'prefix_load_scripts' );
Superfish Dropdowns Let’s get our hands dirty, shall we?
Dropdown Menus css-only
Suckerfish Dropdowns alistapart.com http://www.alistapart.com/articles/dropdowns/
Suckerfish Dropdowns alistapart.com http://www.alistapart.com/articles/dropdowns/
Superfish Dropdowns adding jQuery magic http://users.tpg.com.au/j_birch/plugins/superfish/
Quick Start Guide easy as 1-2-3 http://users.tpg.com.au/j_birch/plugins/superfish/
superfish functions.php scripts custom.js hoverIntent.js superfish.js style.css Set up a
Child Theme I’m naming my child theme ‘superfish’
superfish functions.php scripts custom.js hoverIntent.js superfish.js style.css Set up a
Child Theme most important file!
superfish functions.php scripts custom.js hoverIntent.js superfish.js style.css Set up a
Child Theme blank functions.php to start
superfish functions.php scripts custom.js hoverIntent.js superfish.js style.css Set up a
Child Theme collect all of our javascript files together
superfish functions.php scripts custom.js hoverIntent.js superfish.js style.css Set up a
Child Theme blank javascript file where we’ll write our script
superfish functions.php scripts custom.js hoverIntent.js superfish.js style.css Set up a
Child Theme from the superfish download
superfish functions.php scripts custom.js hoverIntent.js superfish.js style.css Set up a
Child Theme from the superfish download
style.css /* Theme Name: Superfish Theme URI: http://purplepen.com Description: Child
theme for the Twenty Twelve theme adding Superfish menus Author: Natalie MacLees Author URI: http://nataliemac.com Template: twentytwelve Version: 0.1.0 */ @import url("../twentytwelve/style.css");
style.css /* Theme Name: Superfish Theme URI: http://purplepen.com Description: Child
theme for the Twenty Twelve theme adding Superfish menus Author: Natalie MacLees Author URI: http://nataliemac.com Template: twentytwelve Version: 0.1.0 */ @import url("../twentytwelve/style.css");
functions.php function superfish_load_scripts() { wp_register_script( 'hoverintent', get_stylesheet_directory_uri() . '/scripts/ hoverIntent.js',
array( 'jquery' ), '1.0', true ); }
functions.php function superfish_load_scripts() { ... wp_register_script( 'superfish', get_stylesheet_directory_uri() . '/scripts/
superfish.js', array( 'jquery', 'hoverintent' ), '1.0', true ); wp_register_script( 'custom-script', get_stylesheet_directory_uri() . '/scripts/custom.js', array( 'jquery', 'hoverintent', 'superfish' ), '1.3', true ); }
functions.php function superfish_load_scripts() { ... wp_enqueue_script( 'custom-script' ); } add_action(
'wp_enqueue_scripts', 'superfish_load_scripts' );
custom.js jQuery(document).ready(function() { jQuery('.main-navigation ul.nav-menu,.main-navigation div.nav-menu > ul').superfish(); });
custom.js jQuery(document).ready(function() { jQuery('.main-navigation ul.nav-menu,.main-navigation div.nav-menu > ul').superfish(); });
style.css ... @media screen and (min-width: 600px) { .sf-js-enabled li
ul { display: block; } }
custom.js jQuery(document).ready(function() { jQuery('.main-navigation ul.nav-menu,.main-navigation div.nav-menu > ul').superfish({ animation: {
height: 'show' } }); });
Resources Keep on learning
jQuery for Designers by some author http://www.amazon.com/jQuery-Designers-Beginners-Natalie-MacLees/dp/1849516707
JavaScript & WordPress by avk from WordCamp Nepal https://speakerdeck.com/avk/javascript-and-wordpress
Codrops lots of awesome tutorials http://tympanus.net/codrops/category/tutorials/
Codeacademy free JavaScript lessons http://www.codecademy.com
Eloquent JavaScript free interactive JavaScript book http://eloquentjavascript.net/
CodePen experiment and learn http://codepen.io/
Questions? Ask!
Thank YOU Have fun playing with JavaScript! @nataliemac | nataliemac.com