SlideShare a Scribd company logo
1 of 35
Download to read offline
JavaScript




                                                                 EESTEC Summer School 2012
     &
  jQuery
Matic Jesenovec,
Chairman of EESTEC LC Ljubljana & Web Developer at Abakus Plus
                                                                       1
Introduction




                                                                 EESTEC Summer School 2012
• THE scripting language of the Web
• It copies many names from Java, otherwise they are unrelated
• Add functionality, validate forms, communicate with the
  server, provide better UX
• Runs on client side
• Web page should always be functional also without JS
• Today you can sometimes also use HTML5 and CSS3




                                                                       2
Embeding & linking JS in HTML files




                                                           EESTEC Summer School 2012
• <script language="javascript" type= "text/javascript">
       // some code
  </script>

• <script language="javascript" src="script.js">

• <noscript>
      This page looks way cooler with JavaScript
  </noscript>


                                                                 3
Comments




                        EESTEC Summer School 2012
• // one line comment

• /*
  multiple
  lines
  comment
  */




                              4
Variables




                                                                  EESTEC Summer School 2012
•   Locations where you store information
•   The name of your variable can contain any letter or number
•   Within a function you can add var, to create local variable
•   You can change the value of a variable at anytime
•   JS is loosely typed – you don‘t need to tell which type of
    information you will assign to a variable
    • Exceptions: Array and Date


•   x = 3;
•   s = "This is a string";
•   emptyArray = new array();                                           5
•   something = TRUE;
Variables: Datatypes




                                     EESTEC Summer School 2012
•   String – "Something"
•   Number – 42
•   Boolean – TRUE, FALSE
•   Object
    • Array – new Array(1, 2, 3);
    • Date – new Date(1990, 2, 6);
    • ...

• Null
• Undefined
                                           6
Datatypes: Arrays




                                                              EESTEC Summer School 2012
• There are 1 types of people in the world. Those who start
  counting at 0 and those who start counting at 1.

vehicles = new Array("car", "truck", "van");
vehicles[0] // car
vehicles[3] = "bicycle";
vehicles[vehicles.length-1]



anotherArray= ["First", "Second", "Last"];

                                                                    7
Conditional statements




                                                                    EESTEC Summer School 2012
• The ability to do one thing if something is true and do another
  thing if it is false

x = 5;
if(x == 10)
{
         document.writelin("X equals 10");
}
else
{
         document.writelin("X doesn‘t equal 10");
}
                                                                          8
Conditionals: Switch




                                                       EESTEC Summer School 2012
fruits = new Array("Banana", "Apple", "Strawberry");
for(fruit in fruits){
   switch(fruit){
         case "Banana ":
                    document.writelin("Yellow!");
                    break;
         case "Strawberry ":
                    document.writelin("Red!");
                    break;
         default:
                    document.writelin("Unknown!");
   }                                                         9
}
Operators




                                                                  EESTEC Summer School 2012
• + (Addition): Used to add numeric values or combine 2 strings
  of text
• - (Subtraction): Used to subtract values
• * (Multiplication): Used to multiply values
• / (Division): Used to divide values
• % (Modulus): Used to return the remainder of a division of
  two numbers.
  • Example: 15 % 7 = 1
• ++ (Increment): Shorthand way to add one to a value.
  • Example: number++;
• -- (Decrement): Shorthand way to subtract one from a value
                                                                  10
Operators: Comparison




                                              EESTEC Summer School 2012
•   x == y: x equals y
•   x < y: x is less than y
•   x > y: x is greater than y
•   x <= y: x is less than or equal to y
•   x >= y: x is greater than or equal to y
•   x != y: x is not equal to y




                                              11
Operators: Logical




                                                                      EESTEC Summer School 2012
• && (AND): used to check if both values are true
  • Example: if ( x < y && a > b )

• || (OR): used to check if at least one of the values is true

• ! (NOT): used to check if values are not equal to the variable it
  is being used on
  • Example: if(!x)




                                                                      12
Operators: Usefull tricks




                                                                       EESTEC Summer School 2012
• x += y; Adds x and y, then stores that value in the variable x
• x -= y; Subtracts y from x, then stores that value in the variable
  x

• x = (y < 5) ? 10 : 15; Shorthand way to test and then assign a
  value based on the test.
  • If y<5 then x = 10, else x = 15




                                                                       13
Loops




                                                                   EESTEC Summer School 2012
• Perform a repetitive action over and over until some condition
  is met




                                                                   14
Loops: For




                                                                    EESTEC Summer School 2012
• for (initial expression; condition to be met; edit the value of
  expression)
  {
        javascript code…
  }

for (var i = 1; i < 10; i++)
{
        document.writelin(i);
}


                                                                    15
Loops: While




                                EESTEC Summer School 2012
• while (condition)
  {
       code…
       iterator
  }

var i = 1;
while (i < 10)
{
        document.writelin(i);
        i++;
}
                                16
Loops: Do-While




                                EESTEC Summer School 2012
• do {
         code…
  }
  while (i < 10)

var i = 1;
do{
        document.writelin(i);
        i++;
}
while(i < 10)
                                17
Loops: For-In




                                                                EESTEC Summer School 2012
• for (var objectVariable in objectItself)
  {
        code…
  }

var theUniverse = array("Mercury", "Venus", "Earth", "Mars");
for(var planet in theUniverse)
{
        document.writelin(planet);
}


                                                                18
Functions




                                                                EESTEC Summer School 2012
• Groupings of statements that you can type once and then use
  over and over again.

• function nameOfFunction(parameter1, parameter2)
  {
       javascript code…
       return value;
  }




                                                                19
Functions: Example




                                                  EESTEC Summer School 2012
function addThese(numberOne, numberTwo)
{
       var total = numberOne + numberTwo;
       return total;
}

firstNumber = 3;
secondNumber = 2;
addition = addThese(firstNumber, secondNumber);



                                                  20
Built-in functions




                                       EESTEC Summer School 2012
•   array.length
•   string.charAt(index)
•   string.indexOf(value)
•   string.split(separator)
•   string.substring(index1, index2)
•   string.length()
•   string.toLowerCase()
•   number.toString()
•   date.getDay()
•   Math.round(x)
                                       21
The Document Object Model




                                                                EESTEC Summer School 2012
• DOM defines logical structure of HTML (XML) documents
• It enables you to build, modify, navigate and add or delete
  HTML elements and content
• The DOM itself is language-independent




                                                                22
Event handlers




                                                                    EESTEC Summer School 2012
• JavaScript code that is not added inside the <script> tags, but
  rather, inside HTML tags.
• They execute JS when something happens

•   onClick
•   onMouseOver
•   onMouseOut
•   onUnload
•   onLoad (only for <body> and <img>)

<a href="http://eestec.net" onClick="alert('hello!')">EESTEC</a>    23
Firebug debugging




                                                        EESTEC Summer School 2012
•   www.getfirebug.com
•   Find all included JS files easily
•   It shows errors that accure during the execution
•   Set a breakpoint and pause execution at any point
    • Continue one line at a time
    • Observe variable values
• Console to execute JS on the run
• console.log(„text“);



                                                        24
jQuery

25




     EESTEC Summer School 2012
Introduction




                                                                  EESTEC Summer School 2012
• jQuery is a JavaScript Library that simplifies HTML document
  traversing, event handling, animating, and Ajax interactions.

• Download it from jquery.com and include it in your web page

• $(document).ready(function(){
      // Your code here
  });




                                                                  26
Selectors




                                                       EESTEC Summer School 2012
• Used for matching a set of elements in a document.

•   * (all)
•   .class
•   #id
•   :contains()
•   :empty

$(".myClass").css("color","red");

                                                       27
Traversing




                                                            EESTEC Summer School 2012
• In addition to selectors, these methods help you select
  elements.

•   children()
•   each()
•   first()
•   parent()

$("div").add("p");

$('li').each(function(index) {
         console.log(index + ': ' + $(this).text());        28
});
Attributes




                                                             EESTEC Summer School 2012
• Methods, used to get and set DOM attributes of elements.

•   addClass()
•   attr()
•   hasClass()
•   removeClass()
•   html()
•   val()

$("#button").removeClass("enabled").addClass("disabled");
                                                             29
Manipulation




                                                           EESTEC Summer School 2012
• Methods for manipulating the DOM. Changing attributes,
  setting style properties, modifying elements,...

•   append()
•   css()
•   remove()
•   width()
•   empty()

$( this ).css( "width","+=200" );
                                                           30
CSS




                                                           EESTEC Summer School 2012
• Methods, used to get and set CSS-related properties of
  elements.

•   css()
•   position()
•   addClass()
•   hasClass()

p = $("p:first");
position = p.position();
                                                           31
Events




                                                               EESTEC Summer School 2012
• Methods, used to register behavior to take effect when the
  user interacts with the browser.

•   bind(eventType [, eventData], handler(eventObject))
•   click(eventData], handler(eventObject))
•   keypress([eventData], handler(eventObject))
•   hover(handler(eventObject))
•   ...

$('#clickMe').bind('click', function() {
        console.log ('User clicked me!');                      32
});
Effects




                                                               EESTEC Summer School 2012
• Techniques for adding animation to a web page

•   animate(properties [, duration] [, easing] [, complete])
•   fadeIn() / fadeOut([duration] [, callback])
•   hide() / show()
•   slideDown()
•   toggle()

$('#book').animate({
       opacity: 0.25, left: '+=50', height: 'toggle' },
       5000,
       function() {
               console.log('Animation complete.');             33
});
jQuery plugins




                              EESTEC Summer School 2012
• jQuery UI
  •   Dragging
  •   Resizing
  •   Sorting
  •   Datepicker (calendar)
  •   Progressbar
  •   ...




                              34
Thank You!

35




     EESTEC Summer School 2012

More Related Content

Similar to EESTEC Summer School 2012 - java script & jquery - Matic Jesenovec

AVR_Course_Day3 c programming
AVR_Course_Day3 c programmingAVR_Course_Day3 c programming
AVR_Course_Day3 c programmingMohamed Ali
 
JS Responsibilities
JS ResponsibilitiesJS Responsibilities
JS ResponsibilitiesBrendan Eich
 
Mock Objects from Concept to Code
Mock Objects from Concept to CodeMock Objects from Concept to Code
Mock Objects from Concept to CodeRob Myers
 
Windowing functions session for Slovak SQL Pass & BI
Windowing functions session for Slovak SQL Pass & BIWindowing functions session for Slovak SQL Pass & BI
Windowing functions session for Slovak SQL Pass & BIAndrej Zafka
 
Ceylon - the language and its tools
Ceylon - the language and its toolsCeylon - the language and its tools
Ceylon - the language and its toolsMax Andersen
 
Introduction to java 101
Introduction to java 101Introduction to java 101
Introduction to java 101kankemwa Ishaku
 
SOLID, DRY, SLAP design principles
SOLID, DRY, SLAP design principlesSOLID, DRY, SLAP design principles
SOLID, DRY, SLAP design principlesSergey Karpushin
 
Automatic Assessment In Math Education
Automatic Assessment In Math EducationAutomatic Assessment In Math Education
Automatic Assessment In Math Educationtelss09
 
Class[2][29th may] [javascript]
Class[2][29th may] [javascript]Class[2][29th may] [javascript]
Class[2][29th may] [javascript]Saajid Akram
 
The Present and Future of the Web Platform
The Present and Future of the Web PlatformThe Present and Future of the Web Platform
The Present and Future of the Web PlatformC4Media
 
Building Domain-Specific Decision Models
Building Domain-Specific Decision ModelsBuilding Domain-Specific Decision Models
Building Domain-Specific Decision ModelsJacob Feldman
 
Decision CAMP 2014 - Jacob Feldman - Building Domain-Specific Decision Models
Decision CAMP 2014 - Jacob Feldman - Building Domain-Specific Decision ModelsDecision CAMP 2014 - Jacob Feldman - Building Domain-Specific Decision Models
Decision CAMP 2014 - Jacob Feldman - Building Domain-Specific Decision ModelsDecision CAMP
 
Java Review
Java ReviewJava Review
Java Reviewpdgeorge
 
Beyond JavaScript Frameworks: Writing Reliable Web Apps With Elm - Erik Wende...
Beyond JavaScript Frameworks: Writing Reliable Web Apps With Elm - Erik Wende...Beyond JavaScript Frameworks: Writing Reliable Web Apps With Elm - Erik Wende...
Beyond JavaScript Frameworks: Writing Reliable Web Apps With Elm - Erik Wende...Codemotion
 

Similar to EESTEC Summer School 2012 - java script & jquery - Matic Jesenovec (20)

Matlab programming
Matlab programmingMatlab programming
Matlab programming
 
AVR_Course_Day3 c programming
AVR_Course_Day3 c programmingAVR_Course_Day3 c programming
AVR_Course_Day3 c programming
 
Javascript
JavascriptJavascript
Javascript
 
JS Responsibilities
JS ResponsibilitiesJS Responsibilities
JS Responsibilities
 
Mock Objects from Concept to Code
Mock Objects from Concept to CodeMock Objects from Concept to Code
Mock Objects from Concept to Code
 
Java 101
Java 101Java 101
Java 101
 
Windowing functions session for Slovak SQL Pass & BI
Windowing functions session for Slovak SQL Pass & BIWindowing functions session for Slovak SQL Pass & BI
Windowing functions session for Slovak SQL Pass & BI
 
Ceylon - the language and its tools
Ceylon - the language and its toolsCeylon - the language and its tools
Ceylon - the language and its tools
 
Introduction to java 101
Introduction to java 101Introduction to java 101
Introduction to java 101
 
SOLID, DRY, SLAP design principles
SOLID, DRY, SLAP design principlesSOLID, DRY, SLAP design principles
SOLID, DRY, SLAP design principles
 
Automatic Assessment In Math Education
Automatic Assessment In Math EducationAutomatic Assessment In Math Education
Automatic Assessment In Math Education
 
Class[2][29th may] [javascript]
Class[2][29th may] [javascript]Class[2][29th may] [javascript]
Class[2][29th may] [javascript]
 
Java
Java Java
Java
 
The Present and Future of the Web Platform
The Present and Future of the Web PlatformThe Present and Future of the Web Platform
The Present and Future of the Web Platform
 
Building Domain-Specific Decision Models
Building Domain-Specific Decision ModelsBuilding Domain-Specific Decision Models
Building Domain-Specific Decision Models
 
Decision CAMP 2014 - Jacob Feldman - Building Domain-Specific Decision Models
Decision CAMP 2014 - Jacob Feldman - Building Domain-Specific Decision ModelsDecision CAMP 2014 - Jacob Feldman - Building Domain-Specific Decision Models
Decision CAMP 2014 - Jacob Feldman - Building Domain-Specific Decision Models
 
Return of c++
Return of c++Return of c++
Return of c++
 
Java Review
Java ReviewJava Review
Java Review
 
Beyond JavaScript Frameworks: Writing Reliable Web Apps With Elm - Erik Wende...
Beyond JavaScript Frameworks: Writing Reliable Web Apps With Elm - Erik Wende...Beyond JavaScript Frameworks: Writing Reliable Web Apps With Elm - Erik Wende...
Beyond JavaScript Frameworks: Writing Reliable Web Apps With Elm - Erik Wende...
 
Hello my name is DAX
Hello my name is DAXHello my name is DAX
Hello my name is DAX
 

More from EESTEC LC Trieste

EESTEC Summer School 2012 - Windows Phone 7 Applications- Davide Luzzu
EESTEC Summer School 2012 - Windows Phone 7 Applications- Davide LuzzuEESTEC Summer School 2012 - Windows Phone 7 Applications- Davide Luzzu
EESTEC Summer School 2012 - Windows Phone 7 Applications- Davide LuzzuEESTEC LC Trieste
 
EESTEC Summer School 2012 - Windows Phone 7 design - Davide Luzzu
EESTEC Summer School 2012 - Windows Phone 7 design - Davide LuzzuEESTEC Summer School 2012 - Windows Phone 7 design - Davide Luzzu
EESTEC Summer School 2012 - Windows Phone 7 design - Davide LuzzuEESTEC LC Trieste
 
EESTEC Summer School 2012 - Entity Framework - Erni Durdevic
EESTEC Summer School 2012 - Entity Framework - Erni DurdevicEESTEC Summer School 2012 - Entity Framework - Erni Durdevic
EESTEC Summer School 2012 - Entity Framework - Erni DurdevicEESTEC LC Trieste
 
EESTEC Summer School 2012 - Photoshop - Giulia Galvani
EESTEC Summer School 2012 - Photoshop - Giulia GalvaniEESTEC Summer School 2012 - Photoshop - Giulia Galvani
EESTEC Summer School 2012 - Photoshop - Giulia GalvaniEESTEC LC Trieste
 
EESTEC Summer School 2012 - Logo Design - Darija Dašić
EESTEC Summer School 2012 - Logo Design - Darija DašićEESTEC Summer School 2012 - Logo Design - Darija Dašić
EESTEC Summer School 2012 - Logo Design - Darija DašićEESTEC LC Trieste
 
EESTEC Summer School 2012 - Vector Design - Darija Dašić
EESTEC Summer School 2012 - Vector Design - Darija DašićEESTEC Summer School 2012 - Vector Design - Darija Dašić
EESTEC Summer School 2012 - Vector Design - Darija DašićEESTEC LC Trieste
 
EESTEC Summer School 2012 - Branding Guidelines - Milosh Pivic
EESTEC Summer School 2012 - Branding Guidelines - Milosh PivicEESTEC Summer School 2012 - Branding Guidelines - Milosh Pivic
EESTEC Summer School 2012 - Branding Guidelines - Milosh PivicEESTEC LC Trieste
 
EESTEC Summer School 2012 - Group 7 - red cells
EESTEC Summer School 2012 - Group 7 - red cellsEESTEC Summer School 2012 - Group 7 - red cells
EESTEC Summer School 2012 - Group 7 - red cellsEESTEC LC Trieste
 
EESTEC Summer School 2012 - Group 8 - tridentinas
EESTEC Summer School 2012 - Group 8 - tridentinasEESTEC Summer School 2012 - Group 8 - tridentinas
EESTEC Summer School 2012 - Group 8 - tridentinasEESTEC LC Trieste
 
EESTEC Summer School 2012 - Group 6 - createam
EESTEC Summer School 2012 - Group 6 - createamEESTEC Summer School 2012 - Group 6 - createam
EESTEC Summer School 2012 - Group 6 - createamEESTEC LC Trieste
 
EESTEC Summer School 2012 - Group 1 - grande
EESTEC Summer School 2012 - Group 1 - grandeEESTEC Summer School 2012 - Group 1 - grande
EESTEC Summer School 2012 - Group 1 - grandeEESTEC LC Trieste
 
EESTEC Summer School 2012 - Group 10 - vampire hunters
EESTEC Summer School 2012 - Group 10 - vampire huntersEESTEC Summer School 2012 - Group 10 - vampire hunters
EESTEC Summer School 2012 - Group 10 - vampire huntersEESTEC LC Trieste
 
EESTEC Summer School 2012 - Group 9 - kuma
EESTEC Summer School 2012 - Group 9 - kumaEESTEC Summer School 2012 - Group 9 - kuma
EESTEC Summer School 2012 - Group 9 - kumaEESTEC LC Trieste
 

More from EESTEC LC Trieste (20)

ESS 2013: Osmiza may gic
ESS 2013: Osmiza may gicESS 2013: Osmiza may gic
ESS 2013: Osmiza may gic
 
ESS 2013: Whats art
ESS 2013: Whats artESS 2013: Whats art
ESS 2013: Whats art
 
ESS 2013: Osmizeyourself
ESS 2013: OsmizeyourselfESS 2013: Osmizeyourself
ESS 2013: Osmizeyourself
 
ESS 2013: Triesting around
ESS 2013: Triesting aroundESS 2013: Triesting around
ESS 2013: Triesting around
 
ESS 2013: FRIVEGI
ESS 2013: FRIVEGIESS 2013: FRIVEGI
ESS 2013: FRIVEGI
 
ESS 2013: Catchmybus
ESS 2013: CatchmybusESS 2013: Catchmybus
ESS 2013: Catchmybus
 
Ankara
AnkaraAnkara
Ankara
 
EESTEC Summer School 2012 - Windows Phone 7 Applications- Davide Luzzu
EESTEC Summer School 2012 - Windows Phone 7 Applications- Davide LuzzuEESTEC Summer School 2012 - Windows Phone 7 Applications- Davide Luzzu
EESTEC Summer School 2012 - Windows Phone 7 Applications- Davide Luzzu
 
EESTEC Summer School 2012 - Windows Phone 7 design - Davide Luzzu
EESTEC Summer School 2012 - Windows Phone 7 design - Davide LuzzuEESTEC Summer School 2012 - Windows Phone 7 design - Davide Luzzu
EESTEC Summer School 2012 - Windows Phone 7 design - Davide Luzzu
 
EESTEC Summer School 2012 - Entity Framework - Erni Durdevic
EESTEC Summer School 2012 - Entity Framework - Erni DurdevicEESTEC Summer School 2012 - Entity Framework - Erni Durdevic
EESTEC Summer School 2012 - Entity Framework - Erni Durdevic
 
EESTEC Summer School 2012 - Photoshop - Giulia Galvani
EESTEC Summer School 2012 - Photoshop - Giulia GalvaniEESTEC Summer School 2012 - Photoshop - Giulia Galvani
EESTEC Summer School 2012 - Photoshop - Giulia Galvani
 
EESTEC Summer School 2012 - Logo Design - Darija Dašić
EESTEC Summer School 2012 - Logo Design - Darija DašićEESTEC Summer School 2012 - Logo Design - Darija Dašić
EESTEC Summer School 2012 - Logo Design - Darija Dašić
 
EESTEC Summer School 2012 - Vector Design - Darija Dašić
EESTEC Summer School 2012 - Vector Design - Darija DašićEESTEC Summer School 2012 - Vector Design - Darija Dašić
EESTEC Summer School 2012 - Vector Design - Darija Dašić
 
EESTEC Summer School 2012 - Branding Guidelines - Milosh Pivic
EESTEC Summer School 2012 - Branding Guidelines - Milosh PivicEESTEC Summer School 2012 - Branding Guidelines - Milosh Pivic
EESTEC Summer School 2012 - Branding Guidelines - Milosh Pivic
 
EESTEC Summer School 2012 - Group 7 - red cells
EESTEC Summer School 2012 - Group 7 - red cellsEESTEC Summer School 2012 - Group 7 - red cells
EESTEC Summer School 2012 - Group 7 - red cells
 
EESTEC Summer School 2012 - Group 8 - tridentinas
EESTEC Summer School 2012 - Group 8 - tridentinasEESTEC Summer School 2012 - Group 8 - tridentinas
EESTEC Summer School 2012 - Group 8 - tridentinas
 
EESTEC Summer School 2012 - Group 6 - createam
EESTEC Summer School 2012 - Group 6 - createamEESTEC Summer School 2012 - Group 6 - createam
EESTEC Summer School 2012 - Group 6 - createam
 
EESTEC Summer School 2012 - Group 1 - grande
EESTEC Summer School 2012 - Group 1 - grandeEESTEC Summer School 2012 - Group 1 - grande
EESTEC Summer School 2012 - Group 1 - grande
 
EESTEC Summer School 2012 - Group 10 - vampire hunters
EESTEC Summer School 2012 - Group 10 - vampire huntersEESTEC Summer School 2012 - Group 10 - vampire hunters
EESTEC Summer School 2012 - Group 10 - vampire hunters
 
EESTEC Summer School 2012 - Group 9 - kuma
EESTEC Summer School 2012 - Group 9 - kumaEESTEC Summer School 2012 - Group 9 - kuma
EESTEC Summer School 2012 - Group 9 - kuma
 

Recently uploaded

4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17Celine George
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)cama23
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxMaryGraceBautista27
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
FILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipinoFILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipinojohnmickonozaleda
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parentsnavabharathschool99
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4MiaBumagat1
 

Recently uploaded (20)

Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptx
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
FILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipinoFILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipino
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4
 

EESTEC Summer School 2012 - java script & jquery - Matic Jesenovec

  • 1. JavaScript EESTEC Summer School 2012 & jQuery Matic Jesenovec, Chairman of EESTEC LC Ljubljana & Web Developer at Abakus Plus 1
  • 2. Introduction EESTEC Summer School 2012 • THE scripting language of the Web • It copies many names from Java, otherwise they are unrelated • Add functionality, validate forms, communicate with the server, provide better UX • Runs on client side • Web page should always be functional also without JS • Today you can sometimes also use HTML5 and CSS3 2
  • 3. Embeding & linking JS in HTML files EESTEC Summer School 2012 • <script language="javascript" type= "text/javascript"> // some code </script> • <script language="javascript" src="script.js"> • <noscript> This page looks way cooler with JavaScript </noscript> 3
  • 4. Comments EESTEC Summer School 2012 • // one line comment • /* multiple lines comment */ 4
  • 5. Variables EESTEC Summer School 2012 • Locations where you store information • The name of your variable can contain any letter or number • Within a function you can add var, to create local variable • You can change the value of a variable at anytime • JS is loosely typed – you don‘t need to tell which type of information you will assign to a variable • Exceptions: Array and Date • x = 3; • s = "This is a string"; • emptyArray = new array(); 5 • something = TRUE;
  • 6. Variables: Datatypes EESTEC Summer School 2012 • String – "Something" • Number – 42 • Boolean – TRUE, FALSE • Object • Array – new Array(1, 2, 3); • Date – new Date(1990, 2, 6); • ... • Null • Undefined 6
  • 7. Datatypes: Arrays EESTEC Summer School 2012 • There are 1 types of people in the world. Those who start counting at 0 and those who start counting at 1. vehicles = new Array("car", "truck", "van"); vehicles[0] // car vehicles[3] = "bicycle"; vehicles[vehicles.length-1] anotherArray= ["First", "Second", "Last"]; 7
  • 8. Conditional statements EESTEC Summer School 2012 • The ability to do one thing if something is true and do another thing if it is false x = 5; if(x == 10) { document.writelin("X equals 10"); } else { document.writelin("X doesn‘t equal 10"); } 8
  • 9. Conditionals: Switch EESTEC Summer School 2012 fruits = new Array("Banana", "Apple", "Strawberry"); for(fruit in fruits){ switch(fruit){ case "Banana ": document.writelin("Yellow!"); break; case "Strawberry ": document.writelin("Red!"); break; default: document.writelin("Unknown!"); } 9 }
  • 10. Operators EESTEC Summer School 2012 • + (Addition): Used to add numeric values or combine 2 strings of text • - (Subtraction): Used to subtract values • * (Multiplication): Used to multiply values • / (Division): Used to divide values • % (Modulus): Used to return the remainder of a division of two numbers. • Example: 15 % 7 = 1 • ++ (Increment): Shorthand way to add one to a value. • Example: number++; • -- (Decrement): Shorthand way to subtract one from a value 10
  • 11. Operators: Comparison EESTEC Summer School 2012 • x == y: x equals y • x < y: x is less than y • x > y: x is greater than y • x <= y: x is less than or equal to y • x >= y: x is greater than or equal to y • x != y: x is not equal to y 11
  • 12. Operators: Logical EESTEC Summer School 2012 • && (AND): used to check if both values are true • Example: if ( x < y && a > b ) • || (OR): used to check if at least one of the values is true • ! (NOT): used to check if values are not equal to the variable it is being used on • Example: if(!x) 12
  • 13. Operators: Usefull tricks EESTEC Summer School 2012 • x += y; Adds x and y, then stores that value in the variable x • x -= y; Subtracts y from x, then stores that value in the variable x • x = (y < 5) ? 10 : 15; Shorthand way to test and then assign a value based on the test. • If y<5 then x = 10, else x = 15 13
  • 14. Loops EESTEC Summer School 2012 • Perform a repetitive action over and over until some condition is met 14
  • 15. Loops: For EESTEC Summer School 2012 • for (initial expression; condition to be met; edit the value of expression) { javascript code… } for (var i = 1; i < 10; i++) { document.writelin(i); } 15
  • 16. Loops: While EESTEC Summer School 2012 • while (condition) { code… iterator } var i = 1; while (i < 10) { document.writelin(i); i++; } 16
  • 17. Loops: Do-While EESTEC Summer School 2012 • do { code… } while (i < 10) var i = 1; do{ document.writelin(i); i++; } while(i < 10) 17
  • 18. Loops: For-In EESTEC Summer School 2012 • for (var objectVariable in objectItself) { code… } var theUniverse = array("Mercury", "Venus", "Earth", "Mars"); for(var planet in theUniverse) { document.writelin(planet); } 18
  • 19. Functions EESTEC Summer School 2012 • Groupings of statements that you can type once and then use over and over again. • function nameOfFunction(parameter1, parameter2) { javascript code… return value; } 19
  • 20. Functions: Example EESTEC Summer School 2012 function addThese(numberOne, numberTwo) { var total = numberOne + numberTwo; return total; } firstNumber = 3; secondNumber = 2; addition = addThese(firstNumber, secondNumber); 20
  • 21. Built-in functions EESTEC Summer School 2012 • array.length • string.charAt(index) • string.indexOf(value) • string.split(separator) • string.substring(index1, index2) • string.length() • string.toLowerCase() • number.toString() • date.getDay() • Math.round(x) 21
  • 22. The Document Object Model EESTEC Summer School 2012 • DOM defines logical structure of HTML (XML) documents • It enables you to build, modify, navigate and add or delete HTML elements and content • The DOM itself is language-independent 22
  • 23. Event handlers EESTEC Summer School 2012 • JavaScript code that is not added inside the <script> tags, but rather, inside HTML tags. • They execute JS when something happens • onClick • onMouseOver • onMouseOut • onUnload • onLoad (only for <body> and <img>) <a href="http://eestec.net" onClick="alert('hello!')">EESTEC</a> 23
  • 24. Firebug debugging EESTEC Summer School 2012 • www.getfirebug.com • Find all included JS files easily • It shows errors that accure during the execution • Set a breakpoint and pause execution at any point • Continue one line at a time • Observe variable values • Console to execute JS on the run • console.log(„text“); 24
  • 25. jQuery 25 EESTEC Summer School 2012
  • 26. Introduction EESTEC Summer School 2012 • jQuery is a JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions. • Download it from jquery.com and include it in your web page • $(document).ready(function(){ // Your code here }); 26
  • 27. Selectors EESTEC Summer School 2012 • Used for matching a set of elements in a document. • * (all) • .class • #id • :contains() • :empty $(".myClass").css("color","red"); 27
  • 28. Traversing EESTEC Summer School 2012 • In addition to selectors, these methods help you select elements. • children() • each() • first() • parent() $("div").add("p"); $('li').each(function(index) { console.log(index + ': ' + $(this).text()); 28 });
  • 29. Attributes EESTEC Summer School 2012 • Methods, used to get and set DOM attributes of elements. • addClass() • attr() • hasClass() • removeClass() • html() • val() $("#button").removeClass("enabled").addClass("disabled"); 29
  • 30. Manipulation EESTEC Summer School 2012 • Methods for manipulating the DOM. Changing attributes, setting style properties, modifying elements,... • append() • css() • remove() • width() • empty() $( this ).css( "width","+=200" ); 30
  • 31. CSS EESTEC Summer School 2012 • Methods, used to get and set CSS-related properties of elements. • css() • position() • addClass() • hasClass() p = $("p:first"); position = p.position(); 31
  • 32. Events EESTEC Summer School 2012 • Methods, used to register behavior to take effect when the user interacts with the browser. • bind(eventType [, eventData], handler(eventObject)) • click(eventData], handler(eventObject)) • keypress([eventData], handler(eventObject)) • hover(handler(eventObject)) • ... $('#clickMe').bind('click', function() { console.log ('User clicked me!'); 32 });
  • 33. Effects EESTEC Summer School 2012 • Techniques for adding animation to a web page • animate(properties [, duration] [, easing] [, complete]) • fadeIn() / fadeOut([duration] [, callback]) • hide() / show() • slideDown() • toggle() $('#book').animate({ opacity: 0.25, left: '+=50', height: 'toggle' }, 5000, function() { console.log('Animation complete.'); 33 });
  • 34. jQuery plugins EESTEC Summer School 2012 • jQuery UI • Dragging • Resizing • Sorting • Datepicker (calendar) • Progressbar • ... 34
  • 35. Thank You! 35 EESTEC Summer School 2012