Załaduj migrować i zobaczyć kod tam
Patrz mój post o tym samym
Where has fn.toggle(handler(eventObject), handler(eventObject)...) gone?
Mam Zaproponowali przemianować go fn.toggler zamiast usuwania go
Oto kod - jest samodzielną wtyczką jQuery i można go używać w niezmienionej postaci.
jQuery.fn.toggle = function(fn, fn2) {
// Don't mess with animation or css toggles
if (!jQuery.isFunction(fn) || !jQuery.isFunction(fn2)) {
return oldToggle.apply(this, arguments);
}
// migrateWarn("jQuery.fn.toggle(handler, handler...) is deprecated");
// 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);
};
Shorter, nie testowane wersja:
(function($){
$.fn.toggler = function(fn, fn2) {
var args = arguments,guid = fn.guid || $.guid++,i=0,
toggler = function(event) {
var lastToggle = ($._data(this, "lastToggle" + fn.guid) || 0) % i;
$._data(this, "lastToggle" + fn.guid, lastToggle + 1);
event.preventDefault();
return args[ lastToggle ].apply(this, arguments) || false;
};
toggler.guid = guid;
while (i < args.length) {
args[ i++ ].guid = guid;
}
return this.click(toggler);
};
})(jQuery);
Dzięki za to. Użyłem już wtyczki [jQuery Migrate] (https://github.com/jquery/jquery-migrate/), aby ustalić, że ta funkcja została usunięta (nie została ona udokumentowana bardzo dobrze), ale wolałbym tego nie zostawić wtyczka jako rozwiązanie. Jaki byłby dobry odpowiednik? – AlecRust
Dodaj powyższy kod do swoich skryptów. jest to wtyczka sama w sobie. – mplungjan
Jestem zaskoczony, że nie ma bardziej zwięzłego sposobu na odtworzenie tej funkcjonalności. W każdym razie dzięki! – AlecRust