From cbd97ec9a56e2f3a048e6976e20f230ced468ca7 Mon Sep 17 00:00:00 2001 From: slr1979 Date: Fri, 11 Dec 2015 10:33:44 +0000 Subject: [PATCH] Add support for touch events Added the touchstart event to click handlers to allow for touch devices --- jquery.djax.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/jquery.djax.js b/jquery.djax.js index 6529c15..6832970 100644 --- a/jquery.djax.js +++ b/jquery.djax.js @@ -32,7 +32,7 @@ // ==/ClosureCompiler== // http://closure-compiler.appspot.com/home -(function ($, exports) { +;(function ($, exports) { 'use strict'; $.fn.djax = function (selector, exceptions, replaceBlockWithFunc) { @@ -85,6 +85,9 @@ // From this point on, we handle the behaviour event.preventDefault(); + + //Allow for touch events - http://stackoverflow.com/a/11507558 + event.stopPropagation(); // If we're already doing djaxing, return now and silently fail if (self.djaxing) { @@ -143,9 +146,10 @@ newBlock = newBlocks.filter(id), block = $(this); + // Only add a class to internal links and allow for touch events - http://stackoverflow.com/a/11507558 $('a', newBlock).filter(function () { return this.hostname === location.hostname; - }).addClass('dJAX_internal').on('click', function (event) { + }).addClass('dJAX_internal').on('click touchstart', function (event) { return self.attachClick(this, event); }); @@ -182,10 +186,10 @@ } } - // Only add a class to internal links + // Only add a class to internal links and allow for touch events - http://stackoverflow.com/a/11507558 $('a', newBlock).filter(function () { return this.hostname === location.hostname; - }).addClass('dJAX_internal').on('click', function (event) { + }).addClass('dJAX_internal').on('click touchstart', function (event) { return self.attachClick(this, event); }); @@ -216,10 +220,10 @@ }); }; /* End self.navigate */ - // Only add a class to internal links + // Only add a class to internal links and allow for touch events - http://stackoverflow.com/a/11507558 $(this).find('a').filter(function () { return this.hostname === location.hostname; - }).addClass('dJAX_internal').on('click', function (event) { + }).addClass('dJAX_internal').on('click touchstart', function(event){ return self.attachClick(this, event); });