Reputation: 57
I have a trouble with a phonegap build, a function run two time (on my mobile with the phonegap build), differently when i execute the script on firefox.
Thats a part of my code :
$(".blackcase").click(function(e)
{
if (elemIsEmpty($(this)) && isSelected("black"))
{
return;
}
if (isSelected("white"))
{
//swap white to black
alert("swap b to w");
if ($(this).html() == valueoffirst.html())
{
$(valueoffirst.html(""));
alert("swap b to w1");
}
else
{
swapValuesFromTo($("#" + selectedCase.id), $(this));
alert("swap b to w 2");
}
clearSelectedCase();
removeSelectionWithRed();
return;
}
if (isSelected("black"))
{
alert("swap b to b");
$("#" + selectedCase.id).removeClass('red');
if ($(this).html() == valueoffirst.html() && $(this).attr('id') != valueoffirst.attr('id'))
{
$(valueoffirst.html(""));
alert("swap b to b1");
}
else
{
swapValuesFromTo($("#" + selectedCase.id), $(this));
alert("swap b to b 2");
}
clearSelectedCase();
removeSelectionWithRed();
return;
}
//alert("black is selected");
selectWithRed($(this));
updateSelectedCase("black", $(this).attr("id"), $(this).html());
valueoffirst = $(this);
});
function removeSelectionWithRed()
{
$('div').removeClass('red');
}
function selectWithRed(element)
{
removeSelectionWithRed();
element.addClass('red');
}
function updateSelectedCase(color, id)
{
selectedCase.color = color;
selectedCase.id = id;
}
function moveValueFromTo(elemFrom, elemTo)
{
elemTo.html(elemFrom.html());
setValueToElem("", elemFrom);
}
function setValueToElem(value, elem)
{
elem.html(value);
}
function swapValuesFromTo(elemFrom, elemTo)
{
var fromValue = elemFrom.html();
var toValue = elemTo.html();
setValueToElem(fromValue, elemTo);
setValueToElem(toValue, elemFrom);
}
function isSelected(color)
{
return selectedCase.color == color;
}
function clearSelectedCase()
{
selectedCase.color = "";
selectedCase.id = "";
}
function elemIsEmpty(elem)
{
return elem.html().length == 0;
}
When i run my code on firefox, if i click on black case then on another blackcase, it's swapping the values and i have two alerts :
swap b to b
Swap b to b2
All is ok, but on my mobile with my phongap build test, if i click on blackcase then another blackcase the values don't swap and i have 4 alerts :
swap b to b
Swap b to b2
swap b to b
Swap b to b2
So i think values swap but reswap so values are sames of the starting values (like nothing changing).
Thanks a lot for your help !
Upvotes: 0
Views: 53
Reputation: 21
Probably it fired the touch event as well while run in mobile platform. Try to register touch event to test if it does fired.
Upvotes: 2