Posts tagged as:

javascript

There are many instances where we have to execute a function where we have no idea whether it actually exists or not. Let’s say for example, a function expects another function passed to it as parameter, which would later be executed as callback. A very common usage would be the callback function sent to AJAX requests.

Generally, we would code it with an if-block and check whether the variable (say, callback) is a function or not. If it is, we execute it when we have the work completed (say marked by a variable called workIsDone.)

Continue reading

{ 0 comments }

Often, there are conditions where we need to provide a default value of a variable if it is undefined. As a case study, we will take up the situation, where we are passing a Boolean value to function and if the input is true, some action has to be taken. In case someone does not pass any value, the input is assumed to be true.

Continue reading

{ 3 comments }

Infinite Ways to Detect Array in JavaScript

Technical Publications

JavaScript (ECMA script in general) is a miraculous language. It allows us to prove that coding is creativity. One reason for that is the numerous ways a single objective can be coded. For instance, checking whether a variable is an Array, can be done in four different ways. And probably more!

Some months back I had come across this Quora article: What’s the best way to tell the different between an Array and other kinds of objects in JavaScript? There were already five different methods available there from Tom, John, Rick, Ken and Eric. And even I was surprised that I could add one more! I would take some time and explain all the methods with its pros and cons and finally we can conclude upon the best method.…

August 27, 2011 0 comments

Minor Bug Fix to jQuery Touch Drag Plugin

Project Updates

On 21st of June, the jQuery drag event plugin with iPhone (iOS) touch support was released. It has helped to add touch-based drag functionality to many existing web applications using the jQuery drag plugin. A minor update is released for this plugin that fixes the possibility of lack of touch-drag functionality on certain touch devices.…

July 30, 2011 0 comments

JavaScript Drag Events on iPhone and Other Touch Based Devices

Project Updates
Thumbnail image for JavaScript Drag Events on iPhone and Other Touch Based Devices

For quite a while this week, we were trying to work on dragging JavaScript elements on iPad and other devices with touch input. For our case, we already had jQuery included in our codes, hence we were tempted to use the touchmove event and depend on native jQuery to do the rest.

Things turned out to be a bit trickier. After implementation, it struck us that with jQuery bound events, event.pageX and other related mouse coordinate attributes would not work. Add to that, we were using the jQuery.event.drag plugin by ThreeDubsmedia to seal of the dirty job of drag-related coding.

Armed with the above two problems, we started to do what we thought would be the fastest solution – modify the jQuery.event.drag plugin for a graceful upscale!…

June 21, 2011 0 comments

Optimized Trapping of Undefined-like Values In JavaScript

FusionCharts

While working on the FusionCharts JavaScript charts, there was a frequent need to test whether a variable was null, undefined, NaN or an empty string. The “frequent” need was so frequent that the probing function alone took up 15% of the chart’s execution time.

December 30, 2010 0 comments

Dynamically Update FusionCharts XML Attributes

FusionCharts
Thumbnail image for Dynamically Update FusionCharts XML Attributes

This snippet of code adds the functionality to dynamically update FusionCharts DataXML root attributes (also known as “chart attributes”) on-the-fly using JavaScript.

In case user requires to update chart cosmetics like turn off animation or change chart caption, this script will allow developers to do that in one line of code!

May 30, 2010 1 comment

Making FusionCharts Occupy 100% Width and Height of Container

FusionCharts

Under certain circumstances, one may want FusionCharts to occupy 100% (or a certain percentage) width and height of the container element. This can be achieved using two methods using the jQuery Plugin for FusionCharts.

March 30, 2010 6 comments

Transpose An Array In JavaScript and jQuery

Technical Publications

This JavaScript code adds the functionality to transpose a two-dimensional JavaScript array (array within array). Transposing, in simple terms, is to interchange rows and columns of a matrix (two-dimensional array).

It also extends jQuery to allow transposing of arrays using common jQuery syntax.

February 24, 2010 1 comment

Executing jQuery Within FusionCharts Link Attribute

FusionCharts

FusionCharts Flash charting suite has an amazing integration with JavaScript. It allows charts to be created using JavaScript, raises appropriate JavaScript events, allows charts to be updated using its simple JavaScript API and a lot more. There is a blog post on FusionCharts blog, describing the same.

February 14, 2010 3 comments