Today, JavaScript is a toolbox for every web developer. JS is the basic and most important client-side language. It is unmatched when it comes to manipulating the document and the browser window. The options offered by this language give the developer a real arsenal, including DOM manipulation, regular expression support, XML and JSON as well as Ajax technology, WebGL, node.js, CoffeeScript and other splendour that modern JavaScript gives us. When writing applications for the Facebook platform, we have SDK for JavaScript with big possibilities. There are many indications that in the future JavaScript and its frameworks, HTML5, CSS will be the developer's key tools (Wiley 2013).
The general function declaration has the following form:
function exampleFunction(p1, p2) {
return p1 * p2; // The function returns the product of p1 and p2
}
Example of a function with parameters:
function name(parameter1, parameter2, parameter3) {
instructions;
}
Example of calling the function:
var x = myFunction(4, 3); // Function is called, return value will end up in x
function myFunction(a, b) {
return a * b; // Function returns the multiplication of a and b
}
jQuery is a framework written in JavaScript. Thanks to it, we can easily embellish our pages through various effects, ranging from the dynamic addition of classes and identifiers for HTML tags to moving animations. Most of them are obtained with minimal effort, because it is a tool focused on the least amount of work, and the greatest performance. JQuery is a small library but it has a lot of functions. Many long instances can be replaced with a few lines of code using JQuery. It is a set of functions that will avoid long structures and repeating code, will do a lot for us, starting from detection when the browser window will be loaded. What's more, we do not have to wait in this case until all the elements (pictures, flash elements, etc.) are loaded. As soon as the skeleton of the document tags (DOM) is passed to the browser, jQuery will detect it and it will start working immediately (Wiley 2013).
There are many JavaScript frameworks - one can mention names such as Prototype, Dojo or Moo Tools. They all offer unique solutions as well as basic tools, usually improving the work of the DOM and enabling the performance of various animation effects.
Events are actions that happen in the browser. It can be called by the user, but also by every element on the page. For example, by clicking on the button on the page, we call the click event. By selecting another tab in the form with the tab key, we call the focus event. Leaving such an element, we cause blur. The picture was uploaded? Invokes the load event. The form is sent? The submit event is called. Of course, there are many, many more such events, and these are just tiny examples (Wiley 2013).
Below are some events:
Event type | Description |
---|---|
Click | launched when the object was clicked (e.g. input) |
change | launched when the object changed its content (e.g. text field) |
mouseover | launched when the cursor was on the object |
mouseout | launched when the cursor has left the object |
dblclick | launched when the cursor has left the object |
mouseout | launched when double clicking on the object (e.g. input) |
submit | launched when the form has been sent |
resize | launched when the size of the browser window is changed |
focus | launched when fired when the object has been selected (e.g., text field) |
blur | launched when the object has stopped being active (e.g. input) |
keydown | launched when the key was pressed on the keyboard |
keyup | launched when we release the key on the keyboard |
input | similar to the above, but launched synchronously while holding the key (e.g. holding the A key in the text field) |
load | launched when the object has been loaded (eg whole page) |
contextmenu | launched when the right mouse button was clicked and a context menu appeared |
wheel | games are rotated by a mouse wheel |
select | launched when the content of the object has been selected |
unload | launched when the user leaves the page |
animationstart | launched when the css animation starts |
animationend | launched when the css animation starts |
animationiteration | launched when the css animation does one iteration |
transitionstart | launched when transition css starts |
transitionend | launched when transition css starts |
transitionrun | launched when transition css starts (fired before delay transition) |