Click() not working on mobile version

Hello,

I have this situation with part of the code that works fine when clicked on desktop version but not in mobile. Here’s the code, I really don’t know where’s the error.

I appreciate any suggestion.

[CODE]Wheel.prototype.buttonClick = function(){
//Getting button
var clickedButton = this.buttonCurrent();
clickedButton = this.elem.find(“#”+this.wrapperId+“button”+clickedButton);

//Firing either 'href' attribute if setted, or the click delegate attached if not
var buttonHref = clickedButton.attr('href');
if (buttonHref != undefined && buttonHref != '#'){
	if (clickedButton.attr('target') == '_blank'){
		window.open(buttonHref);			
	}
	else{
		window.location.href = buttonHref;
	}
}
else{
	clickedButton.click();
}

};
[/CODE]

Thanks

@judelgado I’ve moved this to the JavaScript forum from Mobile, as I think it might be more likely to get the required help there. We can always move it again if need be. :smile:

One key thing to note is click events aren’t native to mobile devices therefore the same API’s which work on desktop may not or won’t work because they only support touch events.

It’s a bit hard to actually gauge how the above code is working because we can’t see the execution chain but I will recommend you look into libraries that support native touch events along with fallback’s for desktop browsers.

Thanks Chris,

I know what you meant, everything is working correctly for mouse and touch events. Before this click() event there are few touch events:

	//Killing the events that clicking an img might fire
this.elem.find("img").on("dragstart", function(){ 
	return false; 
});
$(document).on("vmousemove", function(event){
	if (wheel.touched){
		wheel.setPosition(event.pageX, event.pageY);		
		wheel.rotateToCurrentPosition();
		return false;
	}
});
$(divHandler).on("vmousedown touchstart mousedown", function(event){
	event.preventDefault(); 
	//console.log("vmousedown");
	if (wheel.inside(event.pageX, event.pageY)){

		var now = new Date().getTime();

		//'Starting' logic; setting up
		wheel.setPosition(event.pageX, event.pageY);
		wheel.startingHoldingAngle = Wheel.getAngle(wheel.position.x, wheel.position.y);
		wheel.touched = true;
		wheel.elem.addClass("touched");

		//Buttons logic (if any)
		wheel.startingTouchingTime = now;
		if (wheel.hasButtons){
			wheel.lastButtonAngle = wheel.startingHoldingAngle;
			wheel.resetLastButtonAngleTime();
			wheel.timeout = setTimeout(function(){
				wheel.buttonShouldSelect();
			}, 10);
		}
		
		wheel.lastSpeedSampleTime = now;
		wheel.lastSpeedSampleAngle = wheel.currentAngle;
		wheel.speedTimer = setTimeout(function(){
			wheel.updateSpeed();
		}, Wheel.config.speedSampleInterval);
		
	}
});
$(document).on("vmouseup touchend mouseup touchcancel", function(event){
	event.preventDefault(); 
	//console.log("vmouseup");

	if (wheel.touched){
		
		//consolelog("speed: " + wheel.getSpeed()); 
		if (Math.abs(wheel.getSpeed()) > 0){
			wheel.setInertia();
			var inertiaTimer = setTimeout(function(){
				wheel.updateInertia();
			}, Wheel.config.inertiaTimeStep);
		}
		else if (Wheel.config.centerInButton){
			wheel.centerInCurrentButton();				
		}

		//'Ending' logic; clearing up
		wheel.startingAngle = wheel.currentAngle;
		wheel.touched = false;
		wheel.elem.removeClass("touched");
		wheel.speedSamples = new Array(Wheel.config.speedSamplesLength);
		
		var justClicking = wheel.buttonShouldClick(event);
		if (!justClicking){
			if (wheel.selectedButton > -1){
				wheel.buttonDeselect();
			}
		}
		clearTimeout(wheel.timeout);
		clearTimeout(wheel.speedTimer);
	}
});
};