Friday, January 15, 2016

The DOM API


Browsers come with a set of built-in objects that model data used and operations performed by your applications:
  • The Browser Object Model API (BOM) features Window object that models browser's windows and tabs.
  • The Document Object Model API (DOM) features Document object that models web pages displayed in browser's windows.

The DOM API specification serves two purposes:

  • how browser should make a model of HTML documents using objects:
    When a browser loads a web page, it creates a structure, a DOM tree, that is a live representation of the web page. The DOM tree is made of Node objects and each node represents an element that is part of the web page.
  • how JS programs can access this model for changing HTML documents:
    JavaScript program can access the DOM tree for modifying the HTML document. This does not change the HTML code, but only the DOM, the representation of the document.

Friday, January 1, 2016

HTML attributes and DOM Element properties

HTML Global Attributes

An HTML element consists of a tag and a set of attributes, an attribute being a pair name="value".

HTML Global attributes are attribute common to all HTML elements. They are divided in three subtypes: core attributes, event-handler attributes and xml attributes

HTML 4.1 Core Attributes
  • id: a unique identifier for the element
  • class: classifies similar elements, for semantic purposes or for presentation purposes.
  • style: adds presentational properties to the element
  • title: attaches textual explanation to the element
  • lang: defines the language of the element
  • dir: the reading direction
  • accesskey: indicates a keyboard shortcut key
  • tabindex: specifies the tab order index
HTML 5 Core Attributes
  • contenteditable: specifies whether a user can edit the content of the element
  • contextmenu: specifies a <menu> for the element
  • data-*: custom attribute for the element
  • draggable: specifies whether a user can drag the element
  • hidden: hides the element
  • spellcheck: specifies whether the element should be checked for spelling and grammar or not
  • translate: specifies whether content of the element is to be translated or not when page is localized

Example: attributes of <body> element

See the Pen DOM tree: document.body.attributes by Massimiliano De Simone (@maxdesimone) on CodePen.

HTML Attributes as DOM Element Properties

In the DOM an HTMLElement object represents an element of an HTML document. The attributes of an element become properties of the corresponding DOM HTMLElement object.

For example, you may set up google analytics for your web site, in that case you have to include in the home page a script like the one below, where you create a <script> element and then you set the attributes type, async and src using the dot notation.

<script>
var _ga = document.createElement('script'); 
 _ga.type = 'text/javascript'; 
 _ga.async = true;
 _ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
<script>

Saturday, March 21, 2015

Client JavaScript Programs Timeline

An UML state machine diagram is used to show the behaviour of a system. In this case a state machine diagram demonstrates the behaviour of the document object that is its life cycle.


Tuesday, November 4, 2014

Advanced Regular Expression Features


If you want to employ all regular expressions constructs and features you can't make it with a simple shell command or a tool, but you need to use a programming language. I use Perl, because it has the best and longest established support for regular expression.

Parenthesized Subexpressions

Earlier, we saw that regex engines support metacharacters \1, \2, \3, etc. to refer to the text matched by parenthesized subexpressions. Perl and most other modern regex-endowed languages also provide a way to refer to the text matched by parenthesized subexpressions from code outside of the regular expression, after a match has been successfully completed.

Saturday, November 1, 2014

Introduction to Perl

This guide introduces the Perl language through a number of sample programs. The aim of this guide is to understand how to use regular expressions with Perl.

1 - What is Perl Language

Perl is a scripting language suitable for web-processing. Perl was developed deriving its concepts of text handling and regular expression from two specialized languages called awk and sed.

Tuesday, July 29, 2014

Regular expressions Introduction

1. What is a regular expression?

"A regular expression is a pattern which specifies a set of strings of characters; it is said to match certain strings."[Ken Thompson]

From the English dictionary:

    pattern = (noun) a regularly repeated arrangement of something.
    to match = (verb) to be equal.

A regex can or cannot match a string and, if it does, can match the string once or multiple times.

Monday, March 17, 2014

The <script> element

The unobtrusive javaScript programming paradigm

Unobtrusive JavaScript is an approach to web programming that supports separation of behaviour (JavaScript code), structure (HTML code) and presentation (CSS code).
According to this programming paradigm, to accomplish separation is best to write all your JavaScript in an external file and embed it in HTML document using a <script> element with src attribute.

The <script> element is synchronous by default

Let's examin how the <script> element allow you to insert javascript in a HTML document.
<script src="scripts/javascript_app.js"> </script> <!--synchronous script-->

When JavaScript engines encounters a <script> element, they stop parsing HTML to download and interpreter the JS file, then they resume parsing and rendering HTML.

The <script> element has two important attribute: HTML 4.1 defines the async attribute and HTML5 introduces the defer attribute. These two attributes cause scripts to be executed differently, in browsers supporting them.

Sunday, February 16, 2014

JavaScript Execution Contexts

1 - Execution Context or Context


The execution context or context is the environment where JavaScript code is evaluated.
→ Global (execution) context
The global execution context is the most outer execution context.
In browsers the global context is also known as window context. In a browser global variables are window properties and global functions are window methods. 
→ Function or Local (execution) context
When a function is called a function execution context is created.

Thursday, November 21, 2013

Type Scales



The Twelve Pixel Scale


body p h3 h2 h1
pixel 12px - 14px 18px 24px
percentage 75% - 117% 150% 200%
em 100% 0.75em 1.17em 1.3em 1.5em



The Sixteen Pixel Scale


body p h3 h2 h1
pixel 16px - 18px 24px 32px
percentage 100% - 133% 150% 200%
em 100% 1em 1.125em 1.5em 2em


Read about why using em to size types:
http://adamdscott.com/better-web-typography-sizing-type-with-ems/

Thursday, November 14, 2013

vertical-align CSS property

What is vertical-align CSS property for ?
Is the purpose of the vertical-align property similar to the HTML align attribute ?

align HTML 3.2 attribute

The attribute align (deprecated in HTML4) belongs to img, applet, object tags, and defines the position of those elements with respect to its context.
This attribute can assume values: bottom, middle, top, left and right, the default value is bottom.
The bottom, middle, top values concern the object's position with respect to surrounding text.
The left and right values cause the element float to the left or right margin.
The align attribute also appears in td elements of tables.

vertical-align CSS property

The vertical-align CSS property specifies the vertical alignment of inline elements.
This attribute can assume values: baseline, middle, top, bottom, text-top, text-bottom, etc. The default value is baseline.

In typography the baseline is an imaginary line where letters sit upon.
With the baseline value inline elements will be lined up with text at baseline of text. The value middle aligns all elements with the mean line of text. The text-bottom and text-top values align elements with the lowest point text's descenders goes down to and with the highest point the text reach. The values top and bottom work with the highest and lowest points of inline non-textual elements on the line.

Example

In the form on the linked page, textarea and input texts are lined up using the CSS property vertical-align set to middle:
http://libreriamusicale.altervista.org/contacts.html

 
The vertical-align property can also be applied to table cells elements.

Wednesday, September 4, 2013

Viewport Vs Canvas

If you are a web developer, you have probably wondered what is the viewport or what is the canvas. Maybe you have asked yourself whether there is any relationship between viewport and canvas.

A common definition of canvas is: "the canvas is the space where the formatting structure of a document is rendered ".
A common definitions of viewport is: "the browser viewport is the visible portion of the canvas".
Actually, the viewport definition is a little complicated because it refers to the canvas.

So, let's try to find some better ways to define canvas and viewport.

The Canvas or Document's Canvas

The browser renders HTML documents on a canvas. You can think of canvas as infinite in the two dimension of the space, but the rendering takes place in a finite region of the canvas.