Home

Follow Skinkers.

Recieve all the updates from Skinkers via email:

 

JavaScript

2

Fixing Internet Explorer’s setTimeout / setInterval scoping issues AND Overcome API’s/Frameworks that don’t allow arguments to be passed to callback methods..

May 31st, 2011 | JavaScript | Matt Bryson

When using setTimeout or setInterval in IE, there is no way to pass any data to the method you want to execute.
You can obviously create lots of global variables, but this is a very messy solution, and not object oriented.

Similarly, if you are using an API that makes an A-Synchronous call and you can set a callback handler, you may well want to pass extra data to the handler, and the API may not let you.

To get round this you can use a delegate function. You basically tell another function what to execute, what to pass it and the scope to execute it in.

NOTE : This method uses jQuery for browser detection. However you can add whichever browser detection you like and replace the $.browser.mozilla check in the method.

/**
* @param scope Object :  The scope in which to execute the delegated function.
* @param func Function : The function to execute
* @param data Object or Array : The data to pass to the function. If the function is also passed arguments, the data is appended to the arguments list. If the data is an Array, each item is appended as a new argument.
* @param isTimeout Boolean : Indicates if the delegate is being executed as part of timeout/interval method or not. This is required for Mozilla/Gecko based browsers when you are passing in extra arguments. This is not needed if you are not passing extra data in.
*/
function delegate(scope, func, data, isTimeout)
{
	return function()
	{
		var args = Array.prototype.slice.apply(arguments).concat(data);
		//Mozilla/Gecko passes a extra arg to indicate the "lateness" of the interval
		//this needs to be removed otherwise your handler receives more arguments than you expected.
                //NOTE : This uses jQuery for browser detection, you can add whatever browser detection you like and replace the below.
		if (isTimeout && $.browser.mozilla)
			args.shift();	

		func.apply(scope, args);
	}
}

Read the rest of this entry »

61

Skinkers release TouchSwipe jQuery plugin for iPad, iPhone and Android.

February 11th, 2011 | Android, Apple, iOS, iPad, iPhone, JavaScript, jQuery | Matt Bryson

Skinkers’ TouchSwipe jQuery plugin enables the detection of swipe gestures on touch based devices.

Features

  • Detects swipes in 4 directions, “up”, “down”, “left” and “right”
  • Supports single finger or double finger touch events
  • Supports click as well as swipe
  • Definable threshold to determin when a gesture is actually a swipe
  • Events triggered for swipe “start”,”move”,”end” and “cancel”
  • End event can be triggered either on touch release, or as soon as threshold is met
  • Allows swiping and page scrolling

Download the plugin at :
http://plugins.jquery.com/project/touchSwipe

Demos and docs at:
http://labs.skinkers.com/touchSwipe/