Archive

Archive for the ‘jQuery’ Category

Tips for Better use of JavaScript

September 18, 2011 Leave a comment

Variables notation and initialization

Object    var oObject = null;
Array    var aArray = [];
Number    var nNumber = -1;
String    var sString = ”;
Boolean    var bBoolean = false;
jQuery    $object

Cache results of DOM search

Twice the same DOM request, not efficient:

document.getElementById(‘tal’).style.display = ‘block’;
document.getElementById(‘tal’).value = ‘Could be cached’;

Better, save the element into a variable:
var oTal = document.getElementById(‘tal’);

oTal.style.display = ‘block’;
oTal.value = ‘Is cached’;

Example of a commented method

/**
* This method does stuff, talk about it here.
* @author Author
* @member ClassName.prototype
* @param {type} oParam Describe the parameter.
* @returns {type} Describe the return value.
*/
ClassName.prototype.aFunction = function(oParam){}

Reference: jsdoc-toolkit

jQuery to Native snippets

jQuery Native  
$(‘#idElement’); document.getElementById(‘idElement’);  
$(‘#idElement’).jQueryMethod(); $(document.getElementById(‘idElement’)).jQueryMethod()  ;
$(‘#idElement’).click(function(){}); $(document.getElementById(‘idElement’)).bind(‘click’, function(){});
$(‘.className’); more than one element:var aArray = $.makeArray($(‘.className’)) // turns a jQuery collection into an array of DOM elements;only one element:

$(‘.className’)[0] // returns the DOM element only;

$object.val() oObject.value;
$object.attr(‘name’) oObject.name // Works for most the attributes of an element
$object.css(‘styleName’, ‘value’) oObject.style.[styleName] = ‘value’
$(‘.className’).each(); var aArray = $.makeArray($(‘.className’));var nArrayLen = aArray.length;var nCounter = 0; // Here initialized at 0 rather than -1!;

for(; nCounter < nArrayLen ; nCounter++){}

$object.addClass(‘className’); oObject.className += ‘ className’;
$object.removeClass(‘className’); oObject.className = oObject.className.replace(‘className’, ”);
$object.html(‘tal’); oObject.innerHTML = ‘tal’;
$object.append(”); oObject.innerHTML = ”;oroObject.appendChild(oChild);
Categories: HTML, JavaScript, jQuery

10 Useful Frameworks To Develop HTML-Based Webapps for Touch Devices

August 26, 2010 Leave a comment

I came across this article about different frameworks for building Mobile Apps/ Web sites by Antonio Lupetti

Intro of the Article is:

Make HTML-based touch applications. Easy.

In the last two years the rapid growth and diffusion of touch devices such as iOS or Android based platforms has forced developers and web designers to rethink the model of their own webapps for the new “touch experience” introduced by the iPhone in 2007.

During this period several frameworks have been released to help web developers implement quickly applications for this kind of touch devices. Here is a collection of some useful frameworks to develop easily HTML-based webapps that will work on all popular smartphone and tablet touch platforms.

Link to the article->

How to make call using Ajax/ JQuery

April 21, 2009 Leave a comment

First thing you got to include Jquery library
Second thing:
create some functions inside jqueries ready function like this:
$(document).ready(
function()
{
// if you want to take any action on load
});
Third:
There are few ways to do this call and here are 3 ways of them:

1) This is a get call
$(“#DivToDisplayResult).load(‘pageToBeCalled.cfm’,{
Param1: param1value,
Param2: param2value,
Param2: param2value,
Param2: param2value,
……..
},
// following function is required, which is being called after we get the result back
function(responseText, textStatus, XMLHttpRequest){
//alert(responseText);
}
2) $.getJSON(‘pageToBeCalled.cfm’,{UserProfileCode: userProfCode}, function(j){
// here you can put the action and you would get result in “j” variable
// like
$(“#divName”).html(j);
});
3) Post
$.post(
pageToBeCalled.cfm,
{
Param1: param1value,
Param2: param2value,
Param2: param2value, },
function(j) {
//here you can take action by reading “j” variable
}
);

Categories: Ajex, HTML, jQuery