Remove APIs now in jquery-compat

This commit is contained in:
Dave Methvin 2012-11-07 19:42:10 -05:00
parent 0ee9415902
commit 6b14cef7a8
3 changed files with 3 additions and 265 deletions

View File

@ -8,7 +8,6 @@ var
// Use the correct document accordingly with window argument (sandbox)
document = window.document,
location = window.location,
navigator = window.navigator,
// Map over jQuery in case of overwrite
_jQuery = window.jQuery,

View File

@ -1,127 +1,4 @@
// Limit scope pollution from any deprecated API
(function() {
// (function() {
var matched, browser, eventAdd, eventRemove,
oldToggle = jQuery.fn.toggle,
rhoverHack = /(?:^|\s)hover(\.\S+|)\b/,
hoverHack = function( events ) {
return jQuery.event.special.hover ? events : events.replace( rhoverHack, "mouseenter$1 mouseleave$1" );
};
// Use of jQuery.browser is frowned upon.
// More details: http://api.jquery.com/jQuery.browser
// jQuery.uaMatch maintained for back-compat
jQuery.uaMatch = function( ua ) {
ua = ua.toLowerCase();
var match = /(chrome)[ \/]([\w.]+)/.exec( ua ) ||
/(webkit)[ \/]([\w.]+)/.exec( ua ) ||
/(opera)(?:.*version|)[ \/]([\w.]+)/.exec( ua ) ||
/(msie) ([\w.]+)/.exec( ua ) ||
ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec( ua ) ||
[];
return {
browser: match[ 1 ] || "",
version: match[ 2 ] || "0"
};
};
matched = jQuery.uaMatch( navigator.userAgent );
browser = {};
if ( matched.browser ) {
browser[ matched.browser ] = true;
browser.version = matched.version;
}
// Chrome is Webkit, but Webkit is also Safari.
if ( browser.chrome ) {
browser.webkit = true;
} else if ( browser.webkit ) {
browser.safari = true;
}
jQuery.browser = browser;
jQuery.sub = function() {
function jQuerySub( selector, context ) {
return new jQuerySub.fn.init( selector, context );
}
jQuery.extend( true, jQuerySub, this );
jQuerySub.superclass = this;
jQuerySub.fn = jQuerySub.prototype = this();
jQuerySub.fn.constructor = jQuerySub;
jQuerySub.sub = this.sub;
jQuerySub.fn.init = function init( selector, context ) {
if ( context && context instanceof jQuery && !(context instanceof jQuerySub) ) {
context = jQuerySub( context );
}
return jQuery.fn.init.call( this, selector, context, rootjQuerySub );
};
jQuerySub.fn.init.prototype = jQuerySub.fn;
var rootjQuerySub = jQuerySub(document);
return jQuerySub;
};
jQuery.fn.toggle = function( fn, fn2 ) {
if ( !jQuery.isFunction( fn ) || !jQuery.isFunction( fn2 ) ) {
return oldToggle.apply( this, arguments );
}
// Save reference to arguments for access in closure
var args = arguments,
guid = fn.guid || jQuery.guid++,
i = 0,
toggler = function( event ) {
// Figure out which function to execute
var lastToggle = ( jQuery._data( this, "lastToggle" + fn.guid ) || 0 ) % i;
jQuery._data( this, "lastToggle" + fn.guid, lastToggle + 1 );
// Make sure that clicks stop
event.preventDefault();
// and execute the function
return args[ lastToggle ].apply( this, arguments ) || false;
};
// link all the functions, so any of them can unbind this click handler
toggler.guid = guid;
while ( i < args.length ) {
args[ i++ ].guid = guid;
}
return this.click( toggler );
};
// Support for 'hover' type
eventAdd = jQuery.event.add;
// Duck punch jQuery.event.add, and jquery.event.remove
// Signatures:
// jQuery.event = {
// add: function( elem, types, handler, data, selector ) {
// remove: function( elem, types, handler, selector, mappedTypes ) {
jQuery.event.add = function( elem, types, handler, data, selector ){
if ( types ) {
types = hoverHack( types );
}
eventAdd.call( this, elem, types, handler, data, selector );
};
eventRemove = jQuery.event.remove;
jQuery.event.remove = function( elem, types, handler, selector, mappedTypes ){
if ( types ) {
types = hoverHack( types );
}
eventRemove.call( this, elem, types, handler, selector, mappedTypes );
};
// Unused in 1.8, left in so attrFn-stabbers won't die; remove in 1.9
jQuery.attrFn = {};
})();
// })();

View File

@ -1,139 +1 @@
if ( jQuery.browser ) {
module("deprecated");
if ( jQuery.get && !isLocal ) {
asyncTest( "browser", function() {
jQuery.get( "data/ua.txt", function( data ) {
var uas = data.split( "\n" );
expect( (uas.length - 1) * 2 );
jQuery.each(uas, function() {
var parts = this.split( "\t" ),
agent = parts[2],
ua;
if ( agent ) {
ua = jQuery.uaMatch( agent );
equal( ua.browser, parts[0], "browser (" + agent + ")" );
equal( ua.version, parts[1], "version (" + agent + ")" );
}
});
start();
});
});
}
test("toggle(Function, Function, ...)", function() {
expect(16);
var count = 0,
fn1 = function(e) { count++; },
fn2 = function(e) { count--; },
preventDefault = function(e) { e.preventDefault(); },
link = jQuery("#mark");
link.click(preventDefault).click().toggle(fn1, fn2).click().click().click().click().click();
equal( count, 1, "Check for toggle(fn, fn)" );
jQuery("#firstp").toggle(function () {
equal(arguments.length, 4, "toggle correctly passes through additional triggered arguments, see #1701" );
}, function() {}).trigger("click", [ 1, 2, 3 ]);
var first = 0;
jQuery("#simon1").one("click", function() {
ok( true, "Execute event only once" );
jQuery(this).toggle(function() {
equal( first++, 0, "toggle(Function,Function) assigned from within one('xxx'), see #1054" );
}, function() {
equal( first, 1, "toggle(Function,Function) assigned from within one('xxx'), see #1054" );
});
return false;
}).click().click().click();
var turn = 0;
var fns = [
function(){
turn = 1;
},
function(){
turn = 2;
},
function(){
turn = 3;
}
];
var $div = jQuery("<div>&nbsp;</div>").toggle( fns[0], fns[1], fns[2] );
$div.click();
equal( turn, 1, "Trying toggle with 3 functions, attempt 1 yields 1");
$div.click();
equal( turn, 2, "Trying toggle with 3 functions, attempt 2 yields 2");
$div.click();
equal( turn, 3, "Trying toggle with 3 functions, attempt 3 yields 3");
$div.click();
equal( turn, 1, "Trying toggle with 3 functions, attempt 4 yields 1");
$div.click();
equal( turn, 2, "Trying toggle with 3 functions, attempt 5 yields 2");
$div.unbind("click",fns[0]);
var data = jQuery._data( $div[0], "events" );
ok( !data, "Unbinding one function from toggle unbinds them all");
// manually clean up detached elements
$div.remove();
// Test Multi-Toggles
var a = [], b = [];
$div = jQuery("<div/>");
$div.toggle(function(){ a.push(1); }, function(){ a.push(2); });
$div.click();
deepEqual( a, [1], "Check that a click worked." );
$div.toggle(function(){ b.push(1); }, function(){ b.push(2); });
$div.click();
deepEqual( a, [1,2], "Check that a click worked with a second toggle." );
deepEqual( b, [1], "Check that a click worked with a second toggle." );
$div.click();
deepEqual( a, [1,2,1], "Check that a click worked with a second toggle, second click." );
deepEqual( b, [1,2], "Check that a click worked with a second toggle, second click." );
// manually clean up detached elements
$div.remove();
});
test("attrFn test", function() {
expect(1);
ok(!!jQuery.attrFn, "attrFnPresent");
});
test("hover pseudo-event", function() {
expect(2);
var balance = 0;
jQuery( "#firstp" )
.on( "hovercraft", function() {
ok( false, "hovercraft is full of ills" );
})
.on( "click.hover.me.not", function( e ) {
equal( e.handleObj.namespace, "hover.me.not", "hover hack doesn't mangle namespaces" );
})
.bind("hover", function( e ) {
if ( e.type === "mouseenter" ) {
balance++;
} else if ( e.type === "mouseleave" ) {
balance--;
} else {
ok( false, "hover pseudo: unknown event type "+e.type );
}
})
.trigger("click")
.trigger("mouseenter")
.trigger("mouseleave")
.unbind("hover")
.trigger("mouseenter");
equal( balance, 0, "hover pseudo-event" );
});
}
module("deprecated");