ap computer science mootools presentation

38
A MICRO-INTRODUCTION TO THE JAVASCRIPT WEB FRAMEWORK, MOOTOOLS!

Upload: ryan-rampersad

Post on 18-Jul-2015

820 views

Category:

Education


2 download

TRANSCRIPT

Page 1: AP Computer Science MooTools Presentation

A M I C R O - I N T R O D U C T I O N T O T H E

J AV A S C R I P T W E B F R A M E W O R K ,

M O O T O O L S !

Page 2: AP Computer Science MooTools Presentation

JAVASCRIPT != JAVA

• Everybody thinks Java and Javascript are related

• “Java and Javascript are similar like Car and Carpet are

similar.” – Greg Hewgill

• They are not

• They share a similar name for marketing purposes

Page 3: AP Computer Science MooTools Presentation

JAVASCRIPT RUNS…

• Javascript is run in a browser, but can be found other places like…

• Photoshop widgets

• AIR Applications

• Text-editor extensions

• Flash

• Unlike Java, there is no official runtime; each browser has its own

implementation

• SquirelFish, SpiderMonkey, JagerMonkey, V8 & more…

Page 4: AP Computer Science MooTools Presentation

SOME JIFFERENCES DIFFERENCES

J A V A S C R I P T

• Untyped variables

• Function Based Scope

• Prototypical Inheritance

• Constructors are regular

functions

• Implicit Global Scope

J A V A

• Typed variables

• Block Based Scope

• Classical Class-based

Inheritance

• Constructors are special

pseudo-methods

• Implicit this attached to

non-static member

methods

Page 5: AP Computer Science MooTools Presentation
Page 6: AP Computer Science MooTools Presentation

VARIABLES

Variables have no named types, but there are types: strings, integers,

floats, arrays, booleans and objects.

var aString = "stringy string string";

var aNumber = 1337;

var aFloat = 1337.314;

var anArray = ["pirates", "ninjas“, “penguins”];

var aBoolean = true;

var anObject = {name: "ryan", age: 17};

Syntax: var varName = varValue;

Page 7: AP Computer Science MooTools Presentation

FUNCTIONS

Functions are globally accessible; methods are attached to an Object.

function myMethod(param1, param2) {

return param1 + (param1 * param2);

}

There are no return types, there are no parameter types. Obviously, this has

something to do with numbers though.

Page 8: AP Computer Science MooTools Presentation

STRANGE FUNCTIONS

Functions are actually like variables in a way; you can pass them into other functions.

function runAFunctionToday(fn) {return fn(2, 4);

}

function myMethod(param1, param2) {return param1 + (param1 * param2);

}

runAFunctionToday(myMethod); // returns 10

The myMethod function is passed to the runAFunctionToday function and inside, is supplied the proper parameters to run.

Page 9: AP Computer Science MooTools Presentation

A JAVASCRIPT MASTER

Can you believe you’ve mastered

Javascript already?

That’s all there is to JS since you already know

Java.

Questions?

Page 10: AP Computer Science MooTools Presentation
Page 11: AP Computer Science MooTools Presentation

DIVIDERS AS BLOCKS

• There are HTML elements, they make up webpages.

• Elements have IDs and Classes. These are used as hooks.

<div id="myDiv" class="myCoolStuff">My really cool stuff div!</div>

• Notice the div part, that’s a block, or a square. It holds things. myDiv is

the ID of the div, myCoolStuff is the class of the div.

• Notice that you <open> and </close> the div?

Page 12: AP Computer Science MooTools Presentation

LINKS

Links are important in HTML.

They can be clicked.

<a href="http://google.com/search?q=pirates">Search Google for Pirates</a>

That makes an underlined clickable piece of text: Search Google for Pirates

Page 13: AP Computer Science MooTools Presentation

DONE WITH HTML ALREADY!

You’re not a master with HTML yet, but this is

enough to get the job done for now.

Questions?

Page 14: AP Computer Science MooTools Presentation
Page 15: AP Computer Science MooTools Presentation
Page 16: AP Computer Science MooTools Presentation
Page 17: AP Computer Science MooTools Presentation

THE MOO IN MOOTOOLS

MOO: My Object Oriented – Tools

MooTools is a library that allows developers to write code in a familiar

Object Oriented manner (because javascript is not object oriented in the

way we know it).

MooTools also adds loads and loads of enhancements to otherwise

boring webpages, such as dynamic loading and fancy effects (think

fades, rescaling and so on).

Page 18: AP Computer Science MooTools Presentation

WHERE TO LEARN THIS FOR REAL

This Mirco-Introduction will not tell you everything you need to know, like

HTML, CSS and Java Script. But it will get you started. That’s all.

Two years ago, I started the mooWalkthrough, a walk-through-style wiki

designed to guide beginners in their MooTools endeavors. Check it out!

walkthrough.ifupdown.com

Page 19: AP Computer Science MooTools Presentation

THE MOOSHELL

A live testing environment for MooTools javascript, complete with tabbing

and highlighting support, completely browser based.

All of the examples during this presentation can be tested-out-live by using

the MooShell: enter the code into the correct box and hit run & watch

the result.

Page 20: AP Computer Science MooTools Presentation
Page 21: AP Computer Science MooTools Presentation

IMAGINE A BOX…

Let’s say it’s a div with the ID of myBox.

<div id="myBox">your little box</div>

What if we wanted that box to become red? We’d do this:

$("myBox").setStyle("background-color", "red");

What if we wanted that box to have blue borders?

$("myBox").setStyle("border", "1px solid blue");

How about some white text now?

$("myBox").setStyle("color", "white");

Page 22: AP Computer Science MooTools Presentation

BUTTON FUN…

Let’s say there’s a button (link)

<a id="myButton" href="#">Greenify</a>

We want this button to make our box become green when we click the link.

How? MooMagic™.

$("myButton").addEvent("click", function(){

$("myBox").setStyle("background-color", "green");

});

Page 23: AP Computer Science MooTools Presentation

A FADING BOX…

Now, instead of having a button, we want the box to fade away when the

mouse is over it and fade in when the mouse is not over it. (This is a bit

harder.)

$("myBox").addEvent("mouseenter", function(){

this.tween("opacity", 0); // fade out

});

$("myBox").addEvent("mouseleave", function(){

this.tween("opacity", 1); // fade in

});

Page 24: AP Computer Science MooTools Presentation

YOU’VE EXPERIENCED THE 3 – E’S OF JS

• The Three E’s of Java Script are: Elements, Events and Effects.

$("get-an-element"); // gets an element by ID

$("someElement").addEvent("someEvent", function(){/* some kind of event */});

$("someElement").tween("some-style", "some new end-result style");

Questions?

Page 25: AP Computer Science MooTools Presentation

MOOTOOLS CLASSES

Since Java Script does not have classes as we (Java Programmers) know,

MooTools allows us to write as if Java Script did.

var Animal = new Class({

initialize: function(name) {

this.name = name;

this.isAlive = true;

}

});

Page 26: AP Computer Science MooTools Presentation

MOOTOOLS CLASSES / 2

If you have your Animal class, you could make a Cat class.var Animal = new Class({

initialize: function(name) {

this.name = name;

this.isAlive = true;

}

});

var Cat = new Class({Extends: Animal,

initialize: function(name) {this.parent(name);this.energy = 10;

}

eat: function(animal) {if (animal.isAlive == false) return false;this.energy++;animal.isAlive = false;

}

});

Page 27: AP Computer Science MooTools Presentation

MOOTOOLS CLASSES / 3

A handy feature of MooTools is that you can add methods to an inheritance

chain without rewriting the original script. For instance, if we want to

add a reproduce method to animal, we can simply implement the new

method on.

Animal.implement({

reproduce: function() {

return Math.random() < .5;

}

});

The original Animal class is intact, but the subclasses of Animal all now

have a reproduce method.

Page 28: AP Computer Science MooTools Presentation

MOOTOOLS CLASSES / 4

MooTools really shines when it comes to classes

It allows for reusability and organization

The familiar new Class(…) style makes it easier for people

Page 29: AP Computer Science MooTools Presentation
Page 30: AP Computer Science MooTools Presentation

RESOURCES

HTML: www.w3schools.com/html/html_intro.asp

CSS: www.w3schools.com/css/css_intro.asp

Java Script: www.w3schools.com/js/js_intro.asp

mootools.net

walkthrough.ifupdown.com

Page 31: AP Computer Science MooTools Presentation

WEB DEVELOPMENT

Web Development is a jack-of-many-trades kind of craft; you have HTML,

CSS, Java Script, PHP, Java, ASP.net, Photoshop, Flash and many other

aspects.

Knowing basic HTML, CSS and Java Script is all you really need to get

started though.

Page 32: AP Computer Science MooTools Presentation
Page 33: AP Computer Science MooTools Presentation

MATH DEPARTMENT WARMUPS

Page 34: AP Computer Science MooTools Presentation

CENTRAL HP DEMO

Page 35: AP Computer Science MooTools Presentation
Page 36: AP Computer Science MooTools Presentation

BUT A QUICK QUIZ IS BETTER!

1. Name the 5 browsers that were used in this presentation.

2. What is ryan’s domain name?

3. What does the MOO stand for in MooTools?

4. What slide is this (as in number)?

5. Did you think the presentation was over?

6. Do you think the presentation is over?

Page 37: AP Computer Science MooTools Presentation
Page 38: AP Computer Science MooTools Presentation

THANKS FOR LISTENING

ifupdown.com

[email protected]

twitter.com/ryanmr

facebook.com/ryan.rampersad