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
530
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
38
Making your website work for everyone: accessibility testing
nataliemac
1
51
The Tangled Web We're Weaving: The Future of WordPress Accessibility
nataliemac
0
47
Making the world a better place through web design
nataliemac
0
150
One Percent Better: How little changes add up
nataliemac
1
99
One percent better
nataliemac
2
68
How to make time for a side hustle
nataliemac
0
3.8k
Before You React
nataliemac
2
390
Bulletproof JavaScript for plugins and themes
nataliemac
2
260
Other Decks in Technology
See All in Technology
AWS re:Invent 2024 re:Cap Taipei (for Developer): New Launches that facilitate Developer Workflow and Continuous Innovation
dwchiang
0
180
トラブルシュートを楽しもう (wakamonog meeting 15)
recuraki
1
310
東京Ruby会議12 Ruby と Rust と私 / Tokyo RubyKaigi 12 Ruby, Rust and me
eagletmt
3
950
フラット構造をやめた理由と、EM / Tech Leadを作った理由
baroqueworksdev
0
210
あなたの人生も変わるかも?AWS認定2つで始まったウソみたいな話
iwamot
3
870
CDKのコードレビューを楽にするパッケージcdk-mentorを作ってみた/cdk-mentor
tomoki10
0
210
Goで実践するBFP
hiroyaterui
1
120
20250116_JAWS_Osaka
takuyay0ne
2
210
Oracle Base Database Service 技術詳細
oracle4engineer
PRO
6
55k
2024年活動報告会(人材育成推進WG・ビジネスサブWG) / 20250114-OIDF-J-EduWG-BizSWG
oidfj
0
260
Visual StudioとかIDE関連小ネタ話
kosmosebi
1
380
なぜfreeeはハブ・アンド・スポーク型の データメッシュアーキテクチャにチャレンジするのか?
shinichiro_joya
2
590
Featured
See All Featured
Bash Introduction
62gerente
610
210k
Code Reviewing Like a Champion
maltzj
521
39k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
127
18k
Building Applications with DynamoDB
mza
93
6.2k
Learning to Love Humans: Emotional Interface Design
aarron
274
40k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
330
21k
Java REST API Framework Comparison - PWX 2021
mraible
28
8.3k
Into the Great Unknown - MozCon
thekraken
34
1.6k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
6
500
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
7
570
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
98
18k
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