From d62864b7de7d55ff2503375a0831bf2fa9d8696f Mon Sep 17 00:00:00 2001 From: Kin Blas Date: Fri, 25 Mar 2011 20:35:24 -0700 Subject: [PATCH] Add dummy mouse/click handlers on bind elements so that they remain clickable on Opera Mini. --- js/jquery.mobile.vmouse.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/js/jquery.mobile.vmouse.js b/js/jquery.mobile.vmouse.js index 10820b2f..d1b98371 100644 --- a/js/jquery.mobile.vmouse.js +++ b/js/jquery.mobile.vmouse.js @@ -306,14 +306,18 @@ function hasVirtualBindings($ele) return false; } +function dummyMouseHandler(){} + function getSpecialEventObject(eventType) { + var realType = eventType.substr(1); return { setup: function(data, namespace) { // If this is the first virtual mouse binding for this element, // add a bindings object to its data. var $this = $(this); + if (!hasVirtualBindings($this)){ $this.data(dataPropertyName, {}); } @@ -329,9 +333,15 @@ function getSpecialEventObject(eventType) activeDocHandlers[eventType] = (activeDocHandlers[eventType] || 0) + 1; if (activeDocHandlers[eventType] == 1){ - $document.bind(eventType.substr(1), mouseEventCallback); + $document.bind(realType, mouseEventCallback); } + // Some browsers, like Opera Mini, won't dispatch mouse/click events + // for elements unless they actually have handlers registered on them. + // To get around this, we register dummy handlers on the elements. + + $this.bind(realType, dummyMouseHandler); + // For now, if event capture is not supported, we rely on mouse handlers. if (eventCaptureSupported){ // If this is the first virtual mouse binding for the document, @@ -350,7 +360,7 @@ function getSpecialEventObject(eventType) --activeDocHandlers[eventType]; if (!activeDocHandlers[eventType]){ - $document.unbind(eventType.substr(1), mouseEventCallback); + $document.unbind(realType, mouseEventCallback); } if (eventCaptureSupported){ @@ -367,6 +377,10 @@ function getSpecialEventObject(eventType) bindings = $this.data(dataPropertyName); bindings[eventType] = false; + // Unregister the dummy event handler. + + $this.unbind(realType, dummyMouseHandler); + // If this is the last virtual mouse binding on the // element, remove the binding data from the element.