Created
December 10, 2012 03:22
-
-
Save mockee/4248194 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*jshint eqnull:true*/ | |
define('jquery', ['jquery-src'], function() { | |
if (!('ontouchstart' in window)) { return jQuery } | |
require('mod/touch', function(){}) | |
function returnFalse() { | |
return false | |
} | |
jQuery.fn.extend({ | |
on: function( types, selector, data, fn, /*INTERNAL*/ one ){ | |
var origFn, type | |
// Types can be a map of types/handlers | |
if (typeof types === "object") { | |
// ( types-Object, selector, data ) | |
if (typeof selector !== "string") { // && selector != null | |
// ( types-Object, data ) | |
data = data || selector | |
selector = undefined | |
} | |
for (type in types) { | |
this.on(type, selector, data, types[ type ], one) | |
} | |
return this | |
} | |
if (data == null && fn == null) { | |
fn = selector | |
data = selector = undefined | |
} else if (fn == null) { | |
if (typeof selector === "string") { | |
fn = data | |
data = undefined | |
} else { | |
fn = data | |
data = selector | |
selector = undefined | |
} | |
} | |
if (fn === false) { | |
fn = returnFalse | |
} else if (!fn) { | |
return this | |
} | |
if (one === 1) { | |
origFn = fn | |
fn = function(event) { | |
// Can use an empty set, since event contains the info | |
jQuery().off(event) | |
return origFn.apply(this, arguments) | |
} | |
// Use same guid so caller can remove using origFn | |
fn.guid = origFn.guid || (origFn.guid = jQuery.guid++) | |
} | |
return this.each(function() { | |
types = /click/g.test(types) | |
&& !/preventDefault/g.test(fn) | |
&& selector ? types.replace('click', 'tap') : types | |
jQuery.event.add(this, types, fn, data, selector) | |
}) | |
} | |
}) | |
return jQuery | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment