A video of this classis (or will be) posted at: http://echo360.uml.edu/heines201516/guiprogramming1.html
Assignment No. 7 is now posted
Academic Calendar Note: Enrollment opens for Spring 2016 courses per enrollment appointments shown on SiS on Monday, November 2
$.getJSON()
challenge
Related reading for this class: JS&jQ:TMM Ch. 9
As noted earlier, anonymous functions are critical in places that expect (in C/C++ terms) pointers to functions
We have seen anonymous functions before, and they will be even more important when we look at events next week (JS&jQ:TMM Ch. 5)
The textbook uses the each()
function to demonstrate how anonymous functions are used with jQuery
[figure source: JavaScript & jQuery: The Missing Manual, by McFarland, fig. 4-6, p. 148]Figure Caption: jQuery’s
each()
function lets you loop through a selection of page elements and perform a series of tasks on each elemement. The key to using the function is understanding anonymous functions.
N.B. In the example at the bottom of page 148, the author uses the alert()
function:
$('img').each( function() { alert( 'I found an image' ) ; });
console.log( 'I found an image' ) ;
Reference: HTML5: The Missing Manual by Matthew MacDonald, Chapter 4
New type attributes for the input tag
Browser support for these types is all over the map
Sample programs to explore on your own (PDF containing all code listings)
Important Note: Only a few of these work in Firefox. Use Google Chrome or Opera.
JavaScript timers in this demo — www.w3schools.com/js/js_timing.asp
var myTimer ;
var TimerPulse = function() {
//
do whatever you want here
}
myTimer = window.setInterval( TimerPulse, 500 ) ;
//
window.
is optional, 2nd parameter is in milliseconds
window.clearInterval( myTimer ) ;
//
window.
is optional
Source: jQuery: Novice to Ninja, by Castledine & Sharkie, pp. 32-37
<input type="button" id="hideButton" value="Hide Disclaimer" />
$('#hideButton').click( function() { $('#disclaimer').hide(); });
This is the first disclaimer paragraph. Watch it carefully!
$('#hideButton').click( function() { $(this).hide(); // a curious disappearing button });
$(this)
is the “target” of the action, that is, the element that caused the event to be fired$('#hideButton').click( // caution: anti-pattern $('#disclaimer').hide() ; );
<input type="button" id="showButton" value="show" />
$('#showButton').click( function() { $('#disclaimer').show(); });
This is the second disclaimer paragraph.
<input type="button" id="toggleButton" value="toggle" />
$('#toggleButton').click( function() { if ($('#disclaimer').is(':visible')) { $('#disclaimer').hide(); } else { $('#disclaimer').show(); } });
is
action:visible
pseudo-selector
This is the third disclaimer paragraph.
$('#toggleButton').click( function() { $('#disclaimer').toggle(); });
This is the fourth disclaimer paragraph.
$('#toggleButton').click( function() { $('#disclaimer').toggle(); if ($('#disclaimer').is(':visible')) { $(this).val('Hide'); } else { $(this).val('Show'); } });
This is the fifth disclaimer paragraph.