background preloader

Javascript

Facebook Twitter

Json

MSIE Javascript Annoyances: Using parameters in setTimeout() | Claws and Paws dot Com. Today's programmatic venting is brought to you by Internet Explorer's implementation of the setTimeout() function under Javascript. What is setTimeout()? SetTimeout() schedules an arbitrary function call for some point in future. This is useful when you have functions that do repetitive tasks some milliseconds apartment, but not constantly. The reason why this is used instead of a simply while (true) { ... } loop is because Javascript is a single-threaded language. So if you tie up the interpreter by executing one piece of code over and over, nothing else in the browser gets a chance to run. setTimeout() allows other pieces of Javascript (or browser events, such as clicking on a button) to run, while guaranteeing that your code will be executed at some point.

Sounds cool. Simple, like this: setTimeout(function_name, msec); This will cause a function called function_name to execute a certain number of milliseconds in the future. setTimeout(function_name, msec, arg1); And this works great. F(); Javascript Closures. Introduction Closure A "closure" is an expression (typically a function) that can have free variables together with an environment that binds those variables (that "closes" the expression). Closures are one of the most powerful features of ECMAScript (javascript) but they cannot be property exploited without understanding them. They are, however, relatively easy to create, even accidentally, and their creation has potentially harmful consequences, particularly in some relatively common web browser environments.

To avoid accidentally encountering the drawbacks and to take advantage of the benefits they offer it is necessary to understand their mechanism. This depends heavily on the role of scope chains in identifier resolution and so on the resolution of property names on objects. The simple explanation of a Closure is that ECMAScript allows inner functions; function definitions and function expressions that are inside the function bodes of other functions. Assignment of Values Finally:- An. Javascript Naming Conventions, Coding Guidelines and Best Practices | Live Free. Live Happy. While most of the popular languages (Java, .NET, C++) have elaborate documents on the naming conventions to follow, I couldn't find any such good document for javascript.

All I could find was bits and pieces here and there. This is the main reason why I am creating this page listing the javascript naming conventions I follow. This may not be complete but I shall try to make it as comprehensive as possible. 1. All variables should be prefixed with a letter indicating the data type of the variable (Hungarian notation). S - String n - number b - boolean a - Array o - object (Native Objects, Host Objects and user-defined objects) Further, the first letter of each of the words should be capitalized.

Ex: var sSampleText = "Hello"; 2. G - global m - All member variables (private and public) var gsSampleText = "Hello"; 3. Function Person(_msFirstName, _msLastName) { this.msFirstName = _msFirstName; this.msLastName = _msLastName; } 4. Function XmlParser() { // Do something } 5. 1. 2. 3. 4. 6. If (sAge ! JavaScriptMVC. Code Conventions for the JavaScript Programming Language. This is a set of coding conventions and rules for use in JavaScript programming. The long-term value of software to an organization is in direct proportion to the quality of the codebase. Over its lifetime, a program will be handled by many pairs of hands and eyes. If a program is able to clearly communicate its structure and characteristics, it is less likely that it will break when modified in the never-too-distant future.

Code conventions can help in reducing the brittleness of programs. All of our JavaScript code is sent directly to the public. It should always be of publication quality. Neatness counts. JavaScript Files JavaScript programs should be stored in and delivered as .js files. JavaScript code should not be embedded in HTML files unless the code is specific to a single session. Whitespace Where possible, these rules are consistent with centuries of good practice with literary style. Blank lines improve readability by setting off sections of code that are logically related. Names. In Java. Javascript resources. Regular Expressions. Programmer's Guide to Regular Expressions Credits: This tutorial is written by David Andersson (Liorean).

Please see footnote for more information on author. What is a regular expression? Regular expressions is a form of pattern matching that you can apply on textual content. Take for example the DOS wildcards ? And * which you can use when you're searching for a file. Regular expressions are, in short, a way to effectively handle data, search and replace strings, and provide extended string handling.

RegExp Syntax There are two ways of defining regular expressions in JavaScript — one through an object constructor and one through a literal. Declaration Here are the ways to declare a regular expression in JavaScript. Flags There are three flags that you may use on a RegExp. Operation Cleanout - Unobtrusive Javascript. Web development in the last year(s) has undergone a change, we stopped mixing presentation with structure, and thus made it easier to rebrand and change the layout throughout the site simply by changing the style sheet.

Further separation is possible by not using any inline styles and classes, but inheritance and contextual selectors. HTML: <table border="0" cellpadding="0" width="100%" cellspacing="5"><tr><td><font face="Arial" size="-2">Lorem Ipsum</font></td></tr></table> became and finally The same evolution can and must happen for Javascript. Keeping Javascript separate The first rule of the unobtrusive Javascript club is don't talk about the unobtrusive Javascript club. 1. One of the big powers of Javascript is that it comes in a seperate file. This means - unless there are special circumstances - all we ever need to see in an HTML document is: This is all we ever need, no more inline Javascript. 2. 3.

Javascript: function color(o,col) { o.style.background=col; } works all the time. 4. 5. Document Object Model Core. This section defines a set of objects and interfaces for accessing and manipulating document objects. The functionality specified in this section (the Core functionality) is sufficient to allow software developers and web script authors to access and manipulate parsed HTML and XML content inside conforming products.

The DOM Core API also allows creation and population of a Document object using only DOM API calls; loading a Document and saving it persistently is left to the product that implements the DOM API. 1.1.1. The DOM Structure Model The DOM presents documents as a hierarchy of Node objects that also implement other, more specialized interfaces. Some types of nodes may have child nodes of various types, and others are leaf nodes that cannot have anything below them in the document structure. For XML and HTML, the node types, and which node types they may have as children, are as follows: 1.1.2. Most of the APIs defined by this specification are interfaces rather than classes.

Las funciones Javascript más útiles. Las 10 mejores librerías. El framework más popular de Ajax. Este es un interesante sondeo realizado por Ajaxian, la encuesta llega a su segunda edicion y según los datos el indiscutible ganador es… Prototype, el framework más popular de Ajax, con un 43% de popularidad, el siguiente es Script.aculo.us con un 33% confirmandose ambos cómo los indiscutibles frameworks más populares. Estos son los resultados de la encuesta: Aquellos frameworks con menos de un 3% no son mostrados En cuanto al lenguaje utilizado para el “lado del servidor” Php es el de más popularidad con un 50% de uso: Otros datos interesantes sacados de esta encuesta son: * 25% trabajan de manera directa con el objeto XMLHttpRequest * 11% utilizan la librería JSON para la transferencia de datos, desafortunadamente no hay datos suficientes para comparar esta librería con otros formatos de transferencia * 3% continuan utilizando ASP (Microsoft), 5 encuestados usan C++ * Un encuesta utiliza Delphi (¿Cómo lo estará haciendo?)

Tutorial Básico de AjaxAjaxian. Douglas Crockford&#039;s Wrrrld Wide Web. Easy Ajax and DOM manipulation for dynamic web applications. The Yahoo! User Interface Library (YUI) Request. Douglas Crockford douglas@crockford.com 2006-04-17 (Updated 2012-08-10) Abstract XMLHttpRequest has a security model that is inadequate for supporting the next generation of web applications. JSONRequest is proposed as a new browser service that allows for two-way data exchange with any JSON data server without exposing users or organization to harm. It exchanges data between scripts on pages with JSON servers in the web. Motivation The next generation of web applications will be much more data intensive. XMLHttpRequest is constrained by the Same Origin Policy. If the Same Origin Policy were not in place, then the user could be harmed by XSS (cross site scripting) attacks.

If the Same Origin Policy were not in effect, a pirate.net page could send a request via XMLHttpRequest to penzance.org. The Same Origin Policy frustrates these attacks, but it also frustrates a larger class of legitimate uses. Surprisingly, the Same Origin Policy does not apply to scripts. JSONRequest JSONRequest.post. Ten Javascript Tools Everyone Should Have. Filed: Sun, Mar 04 2007 under Programming|| Tags: toolbox javascript popular list Javascript frameworks have exploded on the scene over the last few years but they're no replacement for a good toolbox: those little snippets of code you seem to include in every single project.

Here's my list of 10 essential Javascript tools everyone should have at their fingertips! #0 - Trim. Trim is one of the things that leave you scratching your head wondering why it was never included in the language to begin with. Thanks to prototyping however it's fairly easy to make up for the original oversight.

String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g,""); } String.prototype.ltrim = function() { return this.replace(/^\s+/g,""); } String.prototype.rtrim = function() { return this.replace(/\s+$/g,""); } Usage… var test = " Test "; var test1 = test.ltrim(); // returns "Test " var test2 = test.rtrim(); // returns " Test" var test3 = test.trim(); // returns "Test" #1 - Numeric Sort. JSON. Understanding JSON: the 3 minute lesson.

'Simon' on Sun, 23 Jul 2006 18:22:02 GMT, sez: Brilliant. I had (sub-consiously) followed steps 1 to 4 exactly as you describe, except the alarm bells were 3 days ago. Thankyou for saving me the agro of looking it up for myself. 'John' on Sun, 23 Jul 2006 19:35:19 GMT, sez: INI files Rule! Anyway, nice post on LEON er, JSON. 'Rumen Stankov' on Mon, 24 Jul 2006 06:29:04 GMT, sez: Ah! 'Wesley Shephard' on Mon, 24 Jul 2006 22:20:38 GMT, sez: Interesting. SQL injection, take two? 'lb' on Tue, 25 Jul 2006 00:04:01 GMT, sez: yeh it looks very 'injectable' -- maybe more prone to XSS (cross site scripting) than sql injection... i guess the main trick is html encoding all user input, so it can't be interpreted as html (or javascript). 'Dustin Diaz' on Tue, 25 Jul 2006 13:49:44 GMT, sez: JSON in and of itself is not what's OO. 'Aaron Bassett' on Tue, 25 Jul 2006 14:30:35 GMT, sez: 'lb' on Wed, 26 Jul 2006 05:07:27 GMT, sez: cheers lb.

The Ultimate Ajax Object. Filed: Thu, Mar 08 2007 under Programming|| Tags: ajax javascript object post get In my recent article Ten Javascript Tools Everyone Should Have I offered an AJAX object as the 10th tool. After publication, I received quite a number of requests to document the object, and so document it I shall. Introduction This object represents the pinnacle of my attempts to create a flexible and robust Ajax object. An Object Lesson Creating a new ajaxObject This AJAX snippet is a javascript object.

When you create the variable assignment, you pass the URL you want that that Ajax object to call. Var myRequest = new ajaxObject(' Defining the Ajax Callback Function If you would like to have a procedure to process the data returned by the server, add the function name you want to handle the request after the URL as such. var myRequest = new ajaxObject(' processData); Here processData will accept responseText and responseStatus. Mr. 50+ Amazing Jquery Examples- Part1. Dec 20 2007 * This post is regularly updated. * Many of us have been using a good deal of jQuery plugins lately. Menu 1) LavaLamp 2) jQuery Collapse -A plugin for jQuery to collapse content of div container. 3) A Navigation Menu- Unordered List with anchors and nested lists, also demonstrates how to add a second level list. 4) SuckerFish Style Tabs 5) jQuery UI Tabs / Tabs 3 – Simple jQuery based tab-navigation 6) TabContainer Theme – JQuery style fade animation that runs as the user navigates between selected tabs.

Accordion 7 ) jQuery Accordion Demo 8) Simple JQuery Accordion menu SlideShows 9) jQZoom- allows you to realize a small magnifier window close to the image or images on your web page easily. 10) Image/Photo Gallery Viewer- allows you to take a grouping of images and turn it into an flash-like image/photo gallery. Transition Effects 11) InnerFade – It’s designed to fade you any element inside a container in and out. 13) Highlight Fade jQuery Carousel Demo : Color Picker 17) jQuery Color Picker.

JQuery Autocomplete Examples. jMedia : Extras : Home : contentwithstructure.com. jMP3: Sean O&#039;s javaScript MP3 Player / jQuery plugin. 15 April 2014 What is it? jMP3 (javaScript MP3 player) is an easy way make any MP3 playable directly on most any web site (to those with Flash & javaScript enabled), using the sleek Flash Single MP3 Player & the fantabulous jQuery. The Del.icio.us Playtagger is OK for basic purposes, but is not very configurable, can often incur startup delays, and is just not very attractive. jMP3 aims to fix all that!

Demos Listen to this sound: sound.mp3 Listen to, scrub and download this sound (conceal the filename): Listen to MP3s from any website (hide download option... let's not get the MAFIAA involved!) The call to this player is simply ignored if not an mp3 (see source):broken.mp4 Instructions First, download the lightweight (3k) Flash Single MP3 Player (Feb 2007: looks like Jeroen has updated his player and removed the old version... grab a local copy of the original Single MP3 Player compatible with jMP3 here) Then, grab the jMP3 plugin (you do have jQuery already as well, yes?) Rock out! Questions? jQuery Autocomplete. jQuery plugin: Autocomplete. Note (2010-06-23): This plugin is deprecated and not developed anymore. Its successor is part of jQuery UI, and this migration guide explains how to get from this plugin to the new one. This page will remain as it is for reference, but won’t be updated anymore. If you’re still using the plugin and can’t upgrade to jQuery UI autocomplete: Someone else is maintaining a GitHub repository with the plugin, including some fixes.

There’s also an update to the original version of the standalone plugin in a Google Code project. Autocomplete an input field to enable users quickly finding and selecting some value, leveraging searching and filtering. By giving an autocompleted field focus or entering something into it, the plugin starts searching for matching entries and displays a list of values to choose from. This can be used to enter previous selected values, eg. for tags, to complete an address, eg. enter a city name and get the zip code, or maybe enter email addresses from an addressbook. Files: Jquery.suggest, an alternative jQuery based autocomplete library at VulgarisOverIP. FaceBook Like - jQuery and autosuggest Search Engine. PHP - PeruCODE » JQuery. Blog Archive » FaceBook Like - jQuery and autosuggest Search Engine. Event order.