From 12bb026ac96c63680f9af1a1f340f4a460b73c5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Sj=C3=B6berg?= Date: Wed, 4 Sep 2013 15:23:10 -0500 Subject: [PATCH] Updated autolink.js and taphold.js to the latest from their upstream repos. The changes are mainly bugfixes and a few performance improvements. Note that autolink.js is now the minified version from upstream. --- external/autolink.js | 34 +-------------------------------- external/taphold.js | 45 +++++++++++++++++++++++++++----------------- 2 files changed, 29 insertions(+), 50 deletions(-) diff --git a/external/autolink.js b/external/autolink.js index 013025a7..c86f5727 100644 --- a/external/autolink.js +++ b/external/autolink.js @@ -1,33 +1 @@ -// Generated by CoffeeScript 1.4.0 -(function() { - var autoLink, - __slice = [].slice; - - autoLink = function() { - var callbackThunk, key, link_attributes, option, options, url_pattern, value; - options = 1 <= arguments.length ? __slice.call(arguments, 0) : []; - link_attributes = ''; - option = options[0]; - url_pattern = /(^|\s)(\b(https?|ftp):\/\/[\-A-Z0-9+\u0026@#\/%?=~_|!:,.;]*[\-A-Z0-9+\u0026@#\/%=~_|])/gi; - if (!(options.length > 0)) { - return this.replace(url_pattern, "$1$2"); - } - if ((option['callback'] != null) && typeof option['callback'] === 'function') { - callbackThunk = option['callback']; - delete option['callback']; - } - for (key in option) { - value = option[key]; - link_attributes += " " + key + "='" + value + "'"; - } - return this.replace(url_pattern, function(match, space, url) { - var link, returnCallback; - returnCallback = callbackThunk && callbackThunk(url); - link = returnCallback || ("" + url + ""); - return "" + space + link; - }); - }; - - String.prototype['autoLink'] = autoLink; - -}).call(this); +(function(){var f=[].slice;String.prototype.autoLink=function(){var c,e,d,a,b;a=1<=arguments.length?f.call(arguments,0):[];e="";d=a[0];b=/(^|\s)((?:https?|ftp):\/\/[\-A-Z0-9+\u0026@#\/%?=~_|!:,.;]*[\-A-Z0-9+\u0026@#\/%=~_|])/gi;if(!(0$2");for(c in d)a=d[c],"callback"!==c&&(e+=" "+c+"='"+a+"'");return this.replace(b,function(a,c,b){a=("function"===typeof d.callback?d.callback(b):void 0)||""+b+"";return""+c+a})}}).call(this); diff --git a/external/taphold.js b/external/taphold.js index 966d00c0..0624fa77 100644 --- a/external/taphold.js +++ b/external/taphold.js @@ -1,26 +1,35 @@ // @author Rich Adams // Implements a tap and hold functionality. If you click/tap and release, it will trigger a normal -// click event. But if you click/tap and hold for 1s, it will trigger a taphold event instead. +// click event. But if you click/tap and hold for 1s (default), it will trigger a taphold event instead. ;(function($) { + // Default options + var defaults = { + duration: 1000, // ms + clickHandler: null + } + // When start of a taphold event is triggered. function startHandler(event) { var $elem = jQuery(this); + // Merge the defaults and any user defined settings. + settings = jQuery.extend({}, defaults, event.data); + // If object also has click handler, store it and unbind. Taphold will trigger the // click itself, rather than normal propagation. - if (typeof $elem.data("events") != "undefined" - && typeof $elem.data("events").click != "undefined") + if (typeof $_data($elem, "events") != "undefined" + && typeof $_data($elem, "events").click != "undefined") { // Find the one without a namespace defined. - for (var c in $elem.data("events").click) + for (var c in $_data($elem, "events").click) { - if ($elem.data("events").click[c].namespace == "") + if ($_data($elem, "events").click[c].namespace == "") { - var handler = $elem.data("events").click[c].handler + var handler = $_data($elem, "events").click[c].handler $elem.data("taphold_click_handler", handler); $elem.unbind("click", handler); break; @@ -28,11 +37,9 @@ } } // Otherwise, if a custom click handler was explicitly defined, then store it instead. - else if (typeof event.data != "undefined" - && event.data != null - && typeof event.data.clickHandler == "function") + else if (typeof settings.clickHandler == "function") { - $elem.data("taphold_click_handler", event.data.clickHandler); + $elem.data("taphold_click_handler", settings.clickHandler); } // Reset the flags @@ -52,7 +59,7 @@ $elem.trigger(jQuery.extend(event, jQuery.Event("taphold"))); $elem.data("taphold_triggered", true); } - }, 1000)); + }, settings.duration)); } // When user ends a tap or click, decide what we should do. @@ -88,19 +95,23 @@ $(this).data("taphold_cancelled", true); } + // Determine if touch events are supported. + var touchSupported = ("ontouchstart" in window) // Most browsers + || ("onmsgesturechange" in window); // Mircosoft + var taphold = $.event.special.taphold = { setup: function(data) { - $(this).bind("touchstart mousedown", data, startHandler) - .bind("touchend mouseup", stopHandler) - .bind("touchmove mouseleave", leaveHandler); + $(this).bind((touchSupported ? "touchstart" : "mousedown"), data, startHandler) + .bind((touchSupported ? "touchend" : "mouseup"), stopHandler) + .bind((touchSupported ? "touchmove" : "mouseleave"), leaveHandler); }, teardown: function(namespaces) { - $(this).unbind("touchstart mousedown", startHandler) - .unbind("touchend mouseup", stopHandler) - .unbind("touchmove mouseleave", leaveHandler); + $(this).unbind((touchSupported ? "touchstart" : "mousedown"), startHandler) + .unbind((touchSupported ? "touchend" : "mouseup"), stopHandler) + .unbind((touchSupported ? "touchmove" : "mouseleave"), leaveHandler); } }; })(jQuery);