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
46
Making the world a better place through web design
nataliemac
0
150
One Percent Better: How little changes add up
nataliemac
1
93
One percent better
nataliemac
2
68
How to make time for a side hustle
nataliemac
0
3.8k
Before You React
nataliemac
2
380
Bulletproof JavaScript for plugins and themes
nataliemac
2
250
Other Decks in Technology
See All in Technology
なぜCodeceptJSを選んだか
goataka
0
160
Wvlet: A New Flow-Style Query Language For Functional Data Modeling and Interactive Data Analysis - Trino Summit 2024
xerial
1
110
OpenShift Virtualizationのネットワーク構成を真剣に考えてみた/OpenShift Virtualization's Network Configuration
tnk4on
0
130
AI時代のデータセンターネットワーク
lycorptech_jp
PRO
1
280
LINE Developersプロダクト(LIFF/LINE Login)におけるフロントエンド開発
lycorptech_jp
PRO
0
120
Oracle Cloudの生成AIサービスって実際どこまで使えるの? エンジニア目線で試してみた
minorun365
PRO
4
280
オプトインカメラ:UWB測位を応用したオプトイン型のカメラ計測
matthewlujp
0
170
Amazon Kendra GenAI Index 登場でどう変わる? 評価から学ぶ最適なRAG構成
naoki_0531
0
100
Amazon VPC Lattice 最新アップデート紹介 - PrivateLink も似たようなアップデートあったけど違いとは
bigmuramura
0
190
アップデート紹介:AWS Data Transfer Terminal
stknohg
PRO
0
180
KubeCon NA 2024 Recap / Running WebAssembly (Wasm) Workloads Side-by-Side with Container Workloads
z63d
1
240
サイボウズフロントエンドエキスパートチームについて / FrontendExpert Team
cybozuinsideout
PRO
5
38k
Featured
See All Featured
Gamification - CAS2011
davidbonilla
80
5.1k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.3k
GitHub's CSS Performance
jonrohan
1030
460k
Unsuck your backbone
ammeep
669
57k
Six Lessons from altMBA
skipperchong
27
3.5k
How to Think Like a Performance Engineer
csswizardry
22
1.2k
Testing 201, or: Great Expectations
jmmastey
40
7.1k
Optimizing for Happiness
mojombo
376
70k
How STYLIGHT went responsive
nonsquared
95
5.2k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
95
17k
GraphQLとの向き合い方2022年版
quramy
44
13k
Designing for humans not robots
tammielis
250
25k
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