我已经看到jQuery的插件可以这样扩展:
$.ui.plugin.add('draggable', 'zIndex', {
start: function(event, ui) { //... }
})我想知道是否可以扩展扩展?因此,比方说,我想要更改draggable插件的zIndex扩展中的某些内容(不是全部),即在start回调函数的最开始处放置一些我自己的代码。我该怎么做呢?如何访问该函数来代理它?
发布于 2011-08-26 09:06:35
沿着这些思路:
(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);https://stackoverflow.com/questions/7185283
复制相似问题