From 85a590ba9b25dcf7827619aa95afd115d17603cf Mon Sep 17 00:00:00 2001 From: Przemyslaw Ciezkowski Date: Thu, 9 May 2013 17:48:13 +0200 Subject: [PATCH] Pinch: Fix jslint errors Fixed jslint errors. Removed unnecessary variables, changed scope of 'current' variable to be available in touchend event. Change-Id: Ic20b523547e4c6549ed792d7a2457b8a6bca0d5e --- src/js/jquery.mobile.tizen.pinch.js | 181 ++++++++++++++++++------------------ 1 file changed, 90 insertions(+), 91 deletions(-) diff --git a/src/js/jquery.mobile.tizen.pinch.js b/src/js/jquery.mobile.tizen.pinch.js index cece62a..7b10c6e 100644 --- a/src/js/jquery.mobile.tizen.pinch.js +++ b/src/js/jquery.mobile.tizen.pinch.js @@ -249,124 +249,123 @@ define( [ //>>excludeEnd("jqmBuildExclude"); -( function( $, window, undefined ) { +( function ( $, undefined ) { -pinch_event = { - setup: function () { - var thisObject = this, - $this = $( thisObject ); + var pinch_event = { + setup: function () { + var thisObject = this, + $this = $( thisObject ); - if ( !$.mobile.support.touch ) { - return; - } - - function getSize( point ) { - var x = point[0].x - point[1].x, - y = point[0].y - point[1].y; - - return Math.abs( x * y ); - } - - function getParameter( point, ratio ) { - return { point: point, ratio: ratio }; - } - - $this.bind( "touchstart", function ( event ) { - var data = event.originalEvent.touches, - origin, - last_ratio = 1, - processing = false; - - if ( !$.mobile.pinch.enabled ) { + if ( !$.mobile.support.touch ) { return; } - if ( data.length != 2 ) { - return; - } + function getSize( point ) { + var x = point[0].x - point[1].x, + y = point[0].y - point[1].y; - origin = [ - { x: data[0].pageX, y: data[0].pageY }, - { x: data[1].pageX, y: data[1].pageY } - ]; + return Math.abs( x * y ); + } - $( event.target ).trigger( "pinchstart", getParameter( origin, undefined ) ); + function getParameter( point, ratio ) { + return { point: point, ratio: ratio }; + } - function pinchHandler( event ) { + $this.bind( "touchstart", function ( event ) { var data = event.originalEvent.touches, - current, - ratio, - delta, - factor = $( window ).width() / $.mobile.pinch.factor; + origin, + last_ratio = 1, + processing = false, + current; - if ( processing ) { + if ( !$.mobile.pinch.enabled ) { return; } - if ( !origin ) { + if ( data.length != 2 ) { return; } - current = [ + origin = [ + { x: data[0].pageX, y: data[0].pageY }, + { x: data[1].pageX, y: data[1].pageY } + ]; + + $( event.target ).trigger( "pinchstart", getParameter( origin, undefined ) ); + + function pinchHandler( event ) { + var data = event.originalEvent.touches, + ratio, + delta; + + if ( processing ) { + return; + } + + if ( !origin ) { + return; + } + + current = [ { x: data[0].pageX, y: data[0].pageY }, { x: data[1].pageX, y: data[1].pageY } - ]; + ]; - delta = Math.sqrt( getSize( current ) / getSize( origin ) ) ; - if( delta ) { - ratio = delta; - } + delta = Math.sqrt( getSize( current ) / getSize( origin ) ) ; + if ( delta ) { + ratio = delta; + } - if ( ratio < $.mobile.pinch.min ) { - ratio = $.mobile.pinch.min; - } else if ( ratio > $.mobile.pinch.max ) { - ratio = $.mobile.pinch.max; - } + if ( ratio < $.mobile.pinch.min ) { + ratio = $.mobile.pinch.min; + } else if ( ratio > $.mobile.pinch.max ) { + ratio = $.mobile.pinch.max; + } - if ( Math.abs( ratio - last_ratio ) < $.mobile.pinch.threshold ) { - return; - } + if ( Math.abs( ratio - last_ratio ) < $.mobile.pinch.threshold ) { + return; + } - $( event.target ).trigger( "pinch", getParameter( current, ratio ) ); + $( event.target ).trigger( "pinch", getParameter( current, ratio ) ); - last_ratio = ratio; + last_ratio = ratio; - if ( $.mobile.pinch.interval ) { - processing = true; + if ( $.mobile.pinch.interval ) { + processing = true; - setTimeout( function () { - processing = false; - }, $.mobile.pinch.interval ); + setTimeout( function () { + processing = false; + }, $.mobile.pinch.interval ); + } } - } - $this.bind( "touchmove", pinchHandler ) - .one( "touchend", function ( event ) { - $this.unbind( "touchmove", pinchHandler ); - $( event.target ).trigger( "pinchend", - getParameter( undefined, last_ratio ) ); - - origin = undefined; - current = undefined; - last_ratio = 1; - processing = false; - }); - }); - } -}; - -$.event.special["pinch"] = pinch_event; - -$.mobile.pinch = { - enabled: true, - min: 0.1, - max: 3, - factor: 4, - threshold: 0.01, - interval: 50 -}; - -})( jQuery, this ); + $this.bind( "touchmove", pinchHandler ) + .one( "touchend", function ( event ) { + $this.unbind( "touchmove", pinchHandler ); + $( event.target ).trigger( "pinchend", + getParameter( undefined, last_ratio ) ); + + origin = undefined; + current = undefined; + last_ratio = 1; + processing = false; + }); + }); + } + }; + + $.event.special.pinch = pinch_event; + + $.mobile.pinch = { + enabled: true, + min: 0.1, + max: 3, + factor: 4, + threshold: 0.01, + interval: 50 + }; + +}( jQuery, this ) ); //>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude); } ); -- 2.7.4