jQuery: как расширить расширение?
Я видел, что плагины jQuery могут быть расширены следующим образом:
$.ui.plugin.add('draggable', 'zIndex', {
start: function(event, ui) { //... }
})
Мне интересно, можно ли продлить расширение? Итак, скажем, я хочу что-то изменить (не все) в расширении zIndex перетаскиваемого плагина, то есть разместить собственный код в самом начале функции обратного вызова start. Как бы я пошел по этому поводу? Как получить доступ к этой функции, чтобы прокси?
1 ответ
Вдоль этих линий:
(function ($) {
function proxyPlugin(plugin, callback, option, func) {
$.each($.ui[plugin].prototype.plugins[callback], function (k, v) {
if (v[0] == option) {
var fn = v[1];
v[1] = function () {
func.apply(this, arguments);
fn.apply(this, arguments);
}
}
});
}
proxyPlugin('draggable', 'start', 'zIndex', function (e, ui) {
// we are in our custom function that will be triggered before the original one.
// our custom function receives all the arguments the original one has.
// for example, let's add a property by the name of foo to the ui object.
ui.foo = true;
});
})(jQuery);