SlideShare a Scribd company logo
Javascript and jQuery for Mobile
Javascript and jQuery for Mobile

Javascript and jQuery for Mobile






Javascript and jQuery for Mobile
•
•
•
•
•
    –
    –
•
    –
    –
    –
    –
•
    –
    –
    –
•
    – x = x + y; x*= 3; x %= y, x = x & y
•
    – x == 3; x != 5; x === y; 5 > 3
•
•
    –
•
    –
•
    condition ? val1 : val2
•
    –

•
    –
    –   delete window.obj
•
    –
    – var mycar = {make:"Opel", model:"Tigra", year:1999};
       "make" in mycar; // returns true
•
    –
    myObj instanceof Object; //returns true
•
    –
    var myself = new Person("Ivano Malavolta");
•
    –
    this.name;
    this[„name‟];
•
    –
    typeof myself.name; // returns string
var

var magicNumber = 42;
var user = App.getCurrentUser();
var loggedUser = (user.isLogged()) ? user.name : undefined


                                              undefined

       Uncaught ReferenceError: c is not defined




var




window.varName
•
    – var bands = [ NIN , Kraftwerk , Rammstein ];
•
    – var logged= true; // false
•
    – var age = 12;
    – var PI = 3.14;
•
    – var hello = „hello‟;
•
    – var band = {name: "NIN", founder: {name: "Trent",
      surname: "Reznor"}};
    – band.name; // NIN
    – band.founder["surname"]; // Reznor
•
•
•
return
Javascript and jQuery for Mobile
Javascript and jQuery for Mobile

new
extends





Javascript and jQuery for Mobile
Javascript and jQuery for Mobile
Javascript and jQuery for Mobile
Javascript and jQuery for Mobile
document




document.body.parentNode
document.body.childNodes
document.body.firstChild
document.body.lastChild
document.body.nextSibling
document.body.previousSibling
document.body.firstChild.nodeName;


document.body.firstChild.firstChild.nodeValue;


document.body.firstChild.innerHTML = "<div>Hello</div>";


document.getElementById("title");


document.getElementsByTagName("DIV");


document.getElementsByClassName("listElement");
var myDiv = document.createElement("A");



document.createTextNode("Hello!");



document.body.appendChild(myDiv);



document.setAttribute("href", "http://www.google.it");
Javascript and jQuery for Mobile
Javascript and jQuery for Mobile
document.getElementbyId("myDiv").addEventListener(
"touchend", manageTouch, false);




function manageTouch(event) {
     console.log("touched " + event.target);
}
event.preventDefault();
•



•



    
Javascript and jQuery for Mobile
•
    –
•
    –
•
    –
•
    –
Javascript and jQuery for Mobile
Javascript and jQuery for Mobile
myDiv {
          transform: translate(200,300);
}




myDiv {
          transform: translate3d(200,300,0);
}
for(var i=0; i<document.getElementsByClassName("c1").length; i++) {
       console.log(document.getElementsByClassName("c1")[i]);
}




var elements = document.getElementsByClassName("c1");
for(var i=0; i<elements.length; i++) {
       console.log(elements[i]);
}
•
•
•
    –
•
•
•
    –
for(var i=0; i<myArray.length; i++) {
       document.getElementById("c1").appendChild(myArray[i]);
}




var subtree = document.createElement("div");
for(var i=0; i<myArray.length; i++) {
       subtree.appendChild(myArray[i]);
}
document.getElementById("c1").appendChild(subtree);

Javascript and jQuery for Mobile
•
    –


•
    –


•
    –
Javascript and jQuery for Mobile
•
•
•
•
•
•
    –

•
•
    –
•
    –
•
•
jQuery()




                   jQuery()
$()
          $("h1");
      $(".important");
–
  –

$.get('myhtmlpage.html', myCallBack);

function myCallBack() {
   // code
}
$.get('myhtmlpage.html', function() {
   // code
});
$.get('myhtmlpage.html', function() {
   myCallBack(„Ivano‟, „Malavolta‟);
});

function myCallBack(name, surname) {
   // code
}
$(„#nav')
$('div#intro h2')
$('#nav li.current a')
$('div.section')




$('div.section').length


$('div.section')[0]
$('div.section')[1]
$('div.section')[2]
$('div.section').size(); // matched elements

$('div.section').each(function(i) {
  console.log("Item " + i + " is ", this);
});
html()


var text = $('span#msg').html();




$('span#msg').text(„Text to Add');
$('div#intro').html('<div>other div</div>');
attr()


var src = $('a#home').attr(„href');

$('a#home').attr(„href', './home.html');

$('a#home').attr({
  'href': './home.html',
  'id': „home'
});

$('a#home').removeAttr('id');
append()



          prepend()





val()



        html()
<form id="add" >
  <input type="text" id="task" >
  <input type="submit" value="Add" >
</form>

$(function(){
  $("#add" ).submit(function(event){
      event.preventDefault();
      var task = $("#task").val();
  });
});
css()



$("label" ).css("color" , "#f00" );

$("h1" ).css(
  {"color" : "red" ,
  "text-decoration" : "underline" }
);
addClass( )
 removeClass( )


$("input" ).focus(function(event){
  $(this).addClass("focused" );
});

$("input" ).blur(function(event){
  $(this).removeClass("focused" );
});
$('p').css('font-size', '20px');

$('p').css({'font-size': '20px', color: 'red'});

$('#intro').addClass('highlighted');

$('#intro').removeClass('highlighted');

$('#intro').toggleClass('highlighted');

$('p').hasClass('foo');
$('div.intro').parent()
$('div.intro').next()
$('div.intro').prev()
$('div.intro').nextAll('div')
$('h1:first').parents()
$('li').not(':even').css('background-color',
  'red');
Javascript and jQuery for Mobile
Javascript and jQuery for Mobile
Javascript and jQuery for Mobile
$("#dataTable tbody tr").on(“touchend",
  function(event){
      alert($(this).text());
  });

$("#dataTable tbody").on("touchend", "tr",
  function(event){
     alert($(this).text());
});
$("button").on(“touchstart", notify);

function notify() {
  console.log(“touched");
}
data
       event.data
$(“#button1").on(“touchstart",
  { name: “Ivano" }, greet);

$(“#button2").on(“touchstart",
  { name: “Andrea" }, greet);

function greet(event) {
  alert("Hello “ + event.data.name);
}
$(“div.block”).on(“touchend”, touched);
function touched(event) {
  console.log(this);
  console.log($(this));
  console.log(event);
}

•
•

•
Javascript and jQuery for Mobile
.click()
.blur()
.focus()
.scroll()
.select()
.submit()
...
Javascript and jQuery for Mobile
$('div.section').hide().addClass('gone');





•
•
Javascript and jQuery for Mobile
Javascript and jQuery for Mobile
$.ajax()

$.ajax({
  url: url,
  dataType: 'json',
  data: data,
  success: callback,
  error: callbackError
});
$('h1').hide('slow');
$(„div.myBlock).show();
$('h1').slideDown('fast');
$('h1').fadeOut(2000);



$('h1').fadeOut(1000).slideDown()
Javascript and jQuery for Mobile
•
•
•
•
Javascript and jQuery for Mobile
Javascript and jQuery for Mobile
Javascript and jQuery for Mobile
Javascript and jQuery for Mobile
•
•
•
•
•
•


    var hammer = new Hammer(document.getElementById(".block"));
    hammer.ondragstart = function(event) {...};
    hammer.ondrag = function(event) {...};
    hammer.ondragend = function(event) {...};
•
•
•
•
•
•
•
•
–
–
–
–

    –


•
•
•
Javascript and jQuery for Mobile

More Related Content

PDF
Working With Ajax Frameworks
PDF
Sis quiz
KEY
jQuery入門
PDF
jQuery - Javascript para quem não sabe Javascript
PDF
Jquery Framework
KEY
JS for Rails developers
TXT
Miniray.php
DOCX
Documentacion edderson callpa_ortiz
Working With Ajax Frameworks
Sis quiz
jQuery入門
jQuery - Javascript para quem não sabe Javascript
Jquery Framework
JS for Rails developers
Miniray.php
Documentacion edderson callpa_ortiz

What's hot (20)

PDF
Jquery2
PPTX
es6.concurrency()
TXT
Index2
PDF
アプリ設定の保存をシンプルに
PPT
Wek14 mysql 2
PDF
Introduction to Service Worker
DOCX
Php codigos interfaces fredy guzman cusihunca
PDF
Prototype UI
DOCX
Crud secara simultan ala php myadmin
PPT
Palestra sobre MongoDB com PHP no PHP'n'Rio
PDF
dojo.basix
PDF
ສ້າງລະບົບ Loin ດ້ວຍ php
PDF
Introducción a Bolt
PDF
jQueryチュートリアル
PPTX
Jquery ui, ajax
PDF
Peek inside the fantastical Ukrainian Village home and studio of artists Jare...
PDF
Introdução a python módulo c
TXT
With enter
DOCX
Simular un next del recordset en php de forma rudimentaria
Jquery2
es6.concurrency()
Index2
アプリ設定の保存をシンプルに
Wek14 mysql 2
Introduction to Service Worker
Php codigos interfaces fredy guzman cusihunca
Prototype UI
Crud secara simultan ala php myadmin
Palestra sobre MongoDB com PHP no PHP'n'Rio
dojo.basix
ສ້າງລະບົບ Loin ດ້ວຍ php
Introducción a Bolt
jQueryチュートリアル
Jquery ui, ajax
Peek inside the fantastical Ukrainian Village home and studio of artists Jare...
Introdução a python módulo c
With enter
Simular un next del recordset en php de forma rudimentaria
Ad

Viewers also liked (20)

PDF
PhoneGap
PDF
Sitemaps & Wireframing
PDF
HTML5 and CSS3 Refresher
PDF
Modeling behaviour via UML state machines [Software Modeling] [Computer Scie...
PDF
CSS Refresher
PDF
[2016/2017] RESEARCH in software engineering
PDF
Backbone.js
PDF
Apache Cordova APIs version 4.3.0
PDF
Local data storage for mobile apps
PDF
The Mobile ecosystem, Context & Strategies
PDF
Mobile geolocation and mapping
PDF
Mobile Apps Development: Technological strategies and Monetization
PDF
Handlebars & Require JS
PDF
PhoneGap: Accessing Device Capabilities
PDF
UI Design Patterns for Mobile Apps
PDF
Backbone JS for mobile apps
PDF
PhoneGap: Local Storage
PDF
Mobile Applications Development - Lecture 0 - Spring 2013
PDF
The Green Lab - [04 B] [PWA] Experiment setup
PDF
The Green Lab - [09 B] Experiment validity
PhoneGap
Sitemaps & Wireframing
HTML5 and CSS3 Refresher
Modeling behaviour via UML state machines [Software Modeling] [Computer Scie...
CSS Refresher
[2016/2017] RESEARCH in software engineering
Backbone.js
Apache Cordova APIs version 4.3.0
Local data storage for mobile apps
The Mobile ecosystem, Context & Strategies
Mobile geolocation and mapping
Mobile Apps Development: Technological strategies and Monetization
Handlebars & Require JS
PhoneGap: Accessing Device Capabilities
UI Design Patterns for Mobile Apps
Backbone JS for mobile apps
PhoneGap: Local Storage
Mobile Applications Development - Lecture 0 - Spring 2013
The Green Lab - [04 B] [PWA] Experiment setup
The Green Lab - [09 B] Experiment validity
Ad

More from Ivano Malavolta (20)

PDF
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
PDF
Conducting Experiments on the Software Architecture of Robotic Systems (QRARS...
PDF
The H2020 experience
PDF
The Green Lab - Research cocktail @Vrije Universiteit Amsterdam (October 2020)
PDF
Software sustainability and Green IT
PDF
Navigation-aware and Personalized Prefetching of Network Requests in Android ...
PDF
How Maintainability Issues of Android Apps Evolve [ICSME 2018]
PDF
Collaborative Model-Driven Software Engineering: a Classification Framework a...
PDF
Experimenting on Mobile Apps Quality - a tale about Energy, Performance, and ...
PDF
Modeling objects interaction via UML sequence diagrams [Software Design] [Com...
PDF
Modeling behaviour via UML state machines [Software Design] [Computer Science...
PDF
Object-oriented design patterns in UML [Software Design] [Computer Science] [...
PDF
Structure modeling with UML [Software Design] [Computer Science] [Vrije Unive...
PDF
Requirements engineering with UML [Software Design] [Computer Science] [Vrije...
PDF
Modeling and abstraction, software development process [Software Design] [Com...
PDF
[2017/2018] Agile development
PDF
Reconstructing microservice-based architectures
PDF
[2017/2018] AADL - Architecture Analysis and Design Language
PDF
[2017/2018] Architectural languages
PDF
[2017/2018] Introduction to Software Architecture
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
Conducting Experiments on the Software Architecture of Robotic Systems (QRARS...
The H2020 experience
The Green Lab - Research cocktail @Vrije Universiteit Amsterdam (October 2020)
Software sustainability and Green IT
Navigation-aware and Personalized Prefetching of Network Requests in Android ...
How Maintainability Issues of Android Apps Evolve [ICSME 2018]
Collaborative Model-Driven Software Engineering: a Classification Framework a...
Experimenting on Mobile Apps Quality - a tale about Energy, Performance, and ...
Modeling objects interaction via UML sequence diagrams [Software Design] [Com...
Modeling behaviour via UML state machines [Software Design] [Computer Science...
Object-oriented design patterns in UML [Software Design] [Computer Science] [...
Structure modeling with UML [Software Design] [Computer Science] [Vrije Unive...
Requirements engineering with UML [Software Design] [Computer Science] [Vrije...
Modeling and abstraction, software development process [Software Design] [Com...
[2017/2018] Agile development
Reconstructing microservice-based architectures
[2017/2018] AADL - Architecture Analysis and Design Language
[2017/2018] Architectural languages
[2017/2018] Introduction to Software Architecture

Javascript and jQuery for Mobile