Merge pull request #538 from gabrielsjoberg/external_updates
Update autolink.js and taphold.js from upstream.
This commit is contained in:
commit
1d5412689b
34
external/autolink.js
vendored
34
external/autolink.js
vendored
@ -1,33 +1 @@
|
|||||||
// Generated by CoffeeScript 1.4.0
|
(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<a.length))return this.replace(b,"$1<a href='$2'>$2</a>");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)||"<a href='"+b+"'"+e+">"+b+"</a>";return""+c+a})}}).call(this);
|
||||||
(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<a href='$2'>$2</a>");
|
|
||||||
}
|
|
||||||
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 || ("<a href='" + url + "'" + link_attributes + ">" + url + "</a>");
|
|
||||||
return "" + space + link;
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
String.prototype['autoLink'] = autoLink;
|
|
||||||
|
|
||||||
}).call(this);
|
|
||||||
|
45
external/taphold.js
vendored
45
external/taphold.js
vendored
@ -1,26 +1,35 @@
|
|||||||
// @author Rich Adams <rich@richadams.me>
|
// @author Rich Adams <rich@richadams.me>
|
||||||
|
|
||||||
// Implements a tap and hold functionality. If you click/tap and release, it will trigger a normal
|
// 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($)
|
;(function($)
|
||||||
{
|
{
|
||||||
|
// Default options
|
||||||
|
var defaults = {
|
||||||
|
duration: 1000, // ms
|
||||||
|
clickHandler: null
|
||||||
|
}
|
||||||
|
|
||||||
// When start of a taphold event is triggered.
|
// When start of a taphold event is triggered.
|
||||||
function startHandler(event)
|
function startHandler(event)
|
||||||
{
|
{
|
||||||
var $elem = jQuery(this);
|
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
|
// If object also has click handler, store it and unbind. Taphold will trigger the
|
||||||
// click itself, rather than normal propagation.
|
// click itself, rather than normal propagation.
|
||||||
if (typeof $elem.data("events") != "undefined"
|
if (typeof $_data($elem, "events") != "undefined"
|
||||||
&& typeof $elem.data("events").click != "undefined")
|
&& typeof $_data($elem, "events").click != "undefined")
|
||||||
{
|
{
|
||||||
// Find the one without a namespace defined.
|
// 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.data("taphold_click_handler", handler);
|
||||||
$elem.unbind("click", handler);
|
$elem.unbind("click", handler);
|
||||||
break;
|
break;
|
||||||
@ -28,11 +37,9 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Otherwise, if a custom click handler was explicitly defined, then store it instead.
|
// Otherwise, if a custom click handler was explicitly defined, then store it instead.
|
||||||
else if (typeof event.data != "undefined"
|
else if (typeof settings.clickHandler == "function")
|
||||||
&& event.data != null
|
|
||||||
&& typeof event.data.clickHandler == "function")
|
|
||||||
{
|
{
|
||||||
$elem.data("taphold_click_handler", event.data.clickHandler);
|
$elem.data("taphold_click_handler", settings.clickHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset the flags
|
// Reset the flags
|
||||||
@ -52,7 +59,7 @@
|
|||||||
$elem.trigger(jQuery.extend(event, jQuery.Event("taphold")));
|
$elem.trigger(jQuery.extend(event, jQuery.Event("taphold")));
|
||||||
$elem.data("taphold_triggered", true);
|
$elem.data("taphold_triggered", true);
|
||||||
}
|
}
|
||||||
}, 1000));
|
}, settings.duration));
|
||||||
}
|
}
|
||||||
|
|
||||||
// When user ends a tap or click, decide what we should do.
|
// When user ends a tap or click, decide what we should do.
|
||||||
@ -88,19 +95,23 @@
|
|||||||
$(this).data("taphold_cancelled", true);
|
$(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 =
|
var taphold = $.event.special.taphold =
|
||||||
{
|
{
|
||||||
setup: function(data)
|
setup: function(data)
|
||||||
{
|
{
|
||||||
$(this).bind("touchstart mousedown", data, startHandler)
|
$(this).bind((touchSupported ? "touchstart" : "mousedown"), data, startHandler)
|
||||||
.bind("touchend mouseup", stopHandler)
|
.bind((touchSupported ? "touchend" : "mouseup"), stopHandler)
|
||||||
.bind("touchmove mouseleave", leaveHandler);
|
.bind((touchSupported ? "touchmove" : "mouseleave"), leaveHandler);
|
||||||
},
|
},
|
||||||
teardown: function(namespaces)
|
teardown: function(namespaces)
|
||||||
{
|
{
|
||||||
$(this).unbind("touchstart mousedown", startHandler)
|
$(this).unbind((touchSupported ? "touchstart" : "mousedown"), startHandler)
|
||||||
.unbind("touchend mouseup", stopHandler)
|
.unbind((touchSupported ? "touchend" : "mouseup"), stopHandler)
|
||||||
.unbind("touchmove mouseleave", leaveHandler);
|
.unbind((touchSupported ? "touchmove" : "mouseleave"), leaveHandler);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
})(jQuery);
|
})(jQuery);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user