24.10.2014 Views

Hafez Rouzati

Hafez Rouzati

Hafez Rouzati

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Argon +<br />

Web Programing<br />

<strong>Hafez</strong> <strong>Rouzati</strong>


Event Handling<br />

<br />

Overlay HTML<br />

<br />

div.overlaystyle<br />

{<br />

width: 320px;<br />

height: 50px;<br />

position: relative;<br />

}<br />

<br />

<br />

]]><br />

<br />

<br />

#undecorated_style<br />


Scope<br />

// Global variables are global<br />

var GLOBAL_VAR;<br />

// anonymous / immediate function (code inside is called as soon as evaluated<br />

(function(){<br />

// local to inner scope<br />

var local_to_function;<br />

})();<br />

init();<br />

// object literal syntax<br />

var dog = {<br />

! name: "Lassie",<br />

! getName : function () {<br />

! ! return this.name;<br />

! }<br />

};<br />

// Function “Object” syntax<br />

function Person(params) {<br />

! this.name = params.name;<br />

! this.address = params.address;<br />

! this.id = 1234567;<br />

};<br />

// Extending the Person prototype<br />

Person.prototype.sayHi = function() {<br />

! console.log("Hi my name is " + this.name);<br />

};


External Scripts<br />

// inline (asynchronous but order not guaranteed)<br />

<br />

// adding async attribute allows us to use onload property (order<br />

not guaranteed)<br />

<br />

// create script element<br />

var script = document.createElement('script');<br />

script.type = 'text/javascript';<br />

script.src = url;<br />

script.onload = onloadHandler;<br />

document.body.appendChild(script);


External Scripts<br />

//example of chaining loads to guarantee order<br />

(function(){<br />

! function load_script_async(url, onloadHandler)<br />

! {<br />

! console.log("Loading " + url);<br />

! var script = document.createElement('script');<br />

! script.type = 'text/javascript';<br />

! script.src = url;<br />

! script.onload = onloadHandler;<br />

! document.body.appendChild(script);<br />

! }<br />

!<br />

! function load_scripts(scriptUrlArray)<br />

! {<br />

! ! load_script_async(scriptUrlArray.shift(), function(){ if (scriptUrlArray.length > 0) load_scripts(scriptUrlArray)});<br />

! }<br />

!<br />

! function load()<br />

! {<br />

! console.log("Loading Scripts...");<br />

! ! load_scripts(["script1.js", "script2.js", "script3.js"]);<br />

! }<br />

})();


KHARMA<br />

function locationChanged() {<br />

! // accessing the KHARMA object<br />

! var myLoc = KHARMA.getLocation();<br />

! if(myLoc != null)<br />

! {<br />

! var lat = myLoc.latitude;<br />

! var lon = myLoc.longitude;<br />

! ! // do something with location<br />

! }<br />

}<br />

document.addEventListener('locationChanged', function(event) { locationChanged();})


JSON<br />

// key-value pair provides “dictionary” style behavior<br />

var jsonInfo = { "key" : "value" };<br />

// nested dictionaries<br />

var multiJson = { "id" : "someString",<br />

"userData" : { "name" : "Bob", "email" : "bob@bob.com" }};<br />

// dictionaries as array elements<br />

var jsonArray = [ { "first Item" : "value"},<br />

{ "second item" : "someOtherValue" } ];


KHARMA JSON<br />

// 1. JSON representation of a placemark with a balloon<br />

var myFeatureJSON =!<br />

{<br />

balloonVisibility : "1",<br />

description : "function balloon_relative_init(){console.debug('balloon<br />

relative init'); folder_test()}; Example balloon relative to device",<br />

iconVisibility : "1",<br />

id : "balloon_relative",<br />

labelVisibility : "0",<br />

name : "Balloon Relative",<br />

};<br />

type : "placemark",<br />

visibility : "1",<br />

parent : "folder",<br />

extendedData : {<br />

id : "asfasfasdf",<br />

type : "extendeddata",<br />

data : [{ type : "data",<br />

Data_name : "tag",<br />

DisplayName : "the hash",<br />

value : "aelatgt"},<br />

{ type : "data",<br />

Data_name : "value",<br />

value : "2"<br />

}]<br />

},<br />

geometry : [{<br />

altitudeMode : "clampToGround",<br />

id : "balloon3”,<br />

location : {<br />

altitude : "0",<br />

id : "location_relative",<br />

latitude : "6",<br />

latitude_units : "meters",<br />

longitude : "0",<br />

type : "location",<br />

parent : "balloon3”<br />

},<br />

locationMode : "relative",<br />

locationMode_targetId : "clampToGround",<br />

orientationMode : "clampToGround",<br />

orientationMode_targetId : "clampToGround",<br />

scaleMode : "clampToGround",<br />

type : "balloon",<br />

parent : "balloon_relative"<br />

}]<br />

// 2. use JSON to create dynamically create placemark<br />

var myFeature = new KMLPlacemark(myFeatureJSON);<br />

// 3. getting a handle to the object later<br />

var myReference = KHARMA.getKMLElementByID("balloon_relative");


AJAX<br />

var url = 'http://twitter.com/firehose';<br />

var req = new XMLHttpRequest();<br />

req.onReadyStateChange = function () {<br />

! if (req.readyState === 4) {<br />

! ! ! var data = req.responseText;<br />

! ! ! // process the data<br />

! ! }<br />

}<br />

req.open('GET', url, true);<br />

req.send(null);


CSS Media Queries<br />

/* iPhone 4/4s portrait */<br />

@media screen and (-webkit-min-device-pixel-ratio: 2) and (orientation: portrait) {<br />

}<br />

/* iPhone 4/4s landscape */<br />

@media screen and (-webkit-min-device-pixel-ratio: 2) and (orientation: landscape) {<br />

}<br />

/* iPhone portrait */<br />

@media screen and (min-device-width: 320px) and (orientation: portrait) {<br />

}<br />

/* iPhone landscape */<br />

@media screen and (min-device-width: 320px) and (orientation: landscape) {<br />

}<br />

/* iPad portrait */<br />

@media screen and (min-device-width: 768px) and (orientation: portrait) {<br />

}<br />

/* iPad landscape */<br />

@media only screen and (min-device-width: 768px) and (orientation: landscape)<br />

{<br />

}


Selectors<br />

// get all the divs with class warning and notice<br />

var elements = document.querySelectorAll('div.warning, div.notice');<br />

// get all the a elements contained by div with id ‘menu’<br />

var elements = document.querySelectorAll('#menu a');


Math3D JS<br />

http://code.google.com/p/earth-api-samples/source/browse/trunk/lib/math3d.js


Zepto<br />

http://zeptojs.com

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!