Skip to content

Instantly share code, notes, and snippets.

@mockee
Created December 10, 2012 03:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mockee/4248194 to your computer and use it in GitHub Desktop.
Save mockee/4248194 to your computer and use it in GitHub Desktop.
/*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