Return to Snippet

Revision: 38182
at December 30, 2010 03:22 by ringingEars


Updated Code
<script type="text/javascript"> 

function touchHandler(event)
{
    var touches = event.changedTouches,
        first = touches[0],
        type = "";
        
    
    switch(event.type)
    {
        case "touchstart":
            type = "mousedown";
            break;
            
        case "touchmove":
            type="mousemove";        
            event.preventDefault();
            break;        
            
        case "touchend":
            type="mouseup";
            break;
            
        default:
            return;
    }
    
    var simulatedEvent = document.createEvent("MouseEvent");
    
    //initMouseEvent(type, canBubble, cancelable, view, clickCount, screenX, screenY, clientX, clientY, 
    //               ctrlKey, altKey, shiftKey, metaKey, button, relatedTarget);
    
    simulatedEvent.initMouseEvent(type, true, true, window, 1, first.screenX, first.screenY, first.clientX, first.clientY,
                                  false, false, false, false, 0/*left*/, null);
                                                                            
    first.target.dispatchEvent(simulatedEvent);
 
    //event.preventDefault();
}
 
function init() 
{
    document.addEventListener("touchstart", touchHandler, false);
    document.addEventListener("touchmove", touchHandler, false);
    document.addEventListener("touchend", touchHandler, false);
    document.addEventListener("touchcancel", touchHandler, false);    
}

//and what i've done here is create a load_function yield statement that attaches init() to the body onload= tag if you are using rails - otherwise just do <body onload="init();"> 

 <% load_function "init();"%>
       
        </script>

Revision: 38181
at December 28, 2010 09:51 by ringingEars


Initial Code
<script type="text/javascript"> 

$(function(){
	$(".action a").click(function(){
		var myClass=$(this).attr('class')
		$(".info").hide();
		$("." + myClass).show();
				

		
	})
		$(".help").click(function(){
		$(".helptext").toggle("fast");
		
	})
})


	



$(function(){

	$(".643").show();
    $(".try").fancybox({

						'transitionIn' : 'elastic',
						'transitionOut' : 'elastic',
						'titlePosition'	: 'outside'
					});

    })
    
    




		
	


function touchHandler(event)
{
    var touches = event.changedTouches,
        first = touches[0],
        type = "";
        
    
    switch(event.type)
    {
        case "touchstart":
            type = "mousedown";
            break;
            
        case "touchmove":
            type="mousemove";        
            event.preventDefault();
            break;        
            
        case "touchend":
            type="mouseup";
            break;
            
        default:
            return;
    }
    
    
    var simulatedEvent = document.createEvent("MouseEvent");
    
    //initMouseEvent(type, canBubble, cancelable, view, clickCount, screenX, screenY, clientX, clientY, 
    //               ctrlKey, altKey, shiftKey, metaKey, button, relatedTarget);
    
    simulatedEvent.initMouseEvent(type, true, true, window, 1, first.screenX, first.screenY, first.clientX, first.clientY,
                                  false, false, false, false, 0/*left*/, null);
                                                                            
    first.target.dispatchEvent(simulatedEvent);
 
    //event.preventDefault();
}
 
function init() 
{
    document.addEventListener("touchstart", touchHandler, false);
    document.addEventListener("touchmove", touchHandler, false);
    document.addEventListener("touchend", touchHandler, false);
    document.addEventListener("touchcancel", touchHandler, false);    
}
 <% load_function "init();"%>
       
        </script>

Initial URL
http://www.gorankem.com/bestof2010

Initial Description
turns screen touches into mouse clicks - useful for porting drag n drop to iphone / ipad

Initial Title
drag n drop javascript to iphone support

Initial Tags

                                

Initial Language
iPhone