JavaScript for PHP Developers


2012-11-02: TrueNorth PHP Conference

A. Alfred Ayache, ZCE
@notrswebmaster
alfred@notoriouswebmaster.com

What We'll Cover


By the time we're done, you'll be able to:

A Little JS History

JavaScript: What Is It Good For?

The JavaScript Developer's Toolbelt

  • Firefox: other browsers are merely for testing.
  • Firebug: JavaScript and CSS debugger. Absolutely de rigueur.
  • Your favourite editor/IDE. Season to taste.

JavaScript: Let's Get Stuck In

JS: Basics

Including JS in Your Page

Including JS in Your WordPress Theme

JS Language Basics

Comments

*/ ?>

JS Language Basics

Variables

JS Language Basics

Types

JS Language Basics

About Those Primitive Types...

JS Language Basics

Numerics 3

JS Language Basics

Strings

JS Language Basics

Booleans I

JS Language Basics

Booleans II

JS Language Basics

null and undefined

JS Language Basics

Objects 1

// declaring object with a literal
var myObject = {
  computer: 'MacBook Pro',
  os: 'OSX',
  age: 3,
  "screen-shot": '2012-09-30 screenshot.png'
};

// referencing the object
console.log(myObject.computer);
console.log(myObject['screen-shot']);
        

JS Language Basics

Objects 2

var myObject = {
  computer: 'MacBook Pro',
  os: 'OSX',
  age: 3,
  software: {
    title: 'Firefox', 
    publisher: 'Mozilla', 
    version: 15.0
  }
};

console.log(myObject);
console.log(myObject && myObject.age);
console.log(myObject && myObject.software.title);
        
Demo

JS Language Basics

Arrays

JS Language Basics

Control Structures

JavaScript has pretty much the same control structures as PHP:

There are more, but these will suffice for our purposes.

JS Language Basics

for/in

JS Language Basics

Functions

JS Language Basics

Invocation Context

The document Object
(World DOMination)

var el = document.getElementById('myDiv');
el.innerHTML = 'This is my new content';
          
Demo 1 Demo 2 Demo 3

Before the DOM

Events in JavaScript

COMING SOON

AJAX: Dynamically Updating Your Page

COMING SOON

*/ ?>

jQuery and Why We Need JS Libraries

jQuery

Including jQuery in Your Page

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js">
<script src="http://code.jquery.com/jquery-latest.js">


<script>window.jQuery || document.write('<script src="/path/to/local/copy/jquery-1.8.2.min.js"><\/script>')
        

A couple of interesting side notes:

jQuery

$ vs. jQuery

jQuery

What a $ Buys You

jQuery packs a LOT of functionality into one variable. Here's what you get:

jQuery

The Document Ready Handler

jQuery

Selectors

jQuery

Our First Wrapper Methods

jQuery

Event Handlers

blur() focusin() mousedown() mouseup()
change() focusout() mouseenter() resize()
click() keydown() mouseleave() scroll()
dblclick() keypress() mousemove() select()
error() keyup() mouseout() submit()
focus() load() mouseover() unload()

jQuery

Coming Clean with AJAX

Animation

Resources 1

Tools
Books

Resources 2

Docs

Resources 3

Training and Videos