From ac62dcce9d8872caea742c78e149f4cee8a32c3e Mon Sep 17 00:00:00 2001 From: wvengen Date: Thu, 13 Jun 2013 11:59:05 +0200 Subject: [PATCH] make touch device events work on buttons (closes foodcoop-rostock/foodsoft#34, closes foodcoops/foodsoft#104) --- app/assets/javascripts/application.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 04098d88..5509e1f3 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -10,6 +10,19 @@ //= require_self //= require ordering +// allow touch devices to work on click events +// http://stackoverflow.com/a/16221066 +$.fn.extend({ _on: (function(){ return $.fn.on; })() }); +$.fn.extend({ + on: (function(){ + var isTouchSupported = 'ontouchstart' in window || window.DocumentTouch && document instanceof DocumentTouch; + return function( types, selector, data, fn, one ) { + if (typeof types == 'string' && isTouchSupported && !(types.match(/touch/gi))) types = types.replace(/click/gi, 'touchstart'); + return this._on( types, selector, data, fn); + }; + }()), +}); + // Load following statements, when DOM is ready $(function() { @@ -118,4 +131,4 @@ function highlightRow(checkbox) { // There must be a hidden field with the id 'hidden_field' function setHiddenId(text, li) { $('hidden_id').value = li.id; -} \ No newline at end of file +}