我正在使用Nadia Alramli的Jquery插件“确认”。我在这个插件中添加了一些功能,但是得到了这样的错误:“未捕获的TypeError:对象[对象编号]没有方法'应用'”,我检查了,真的无法搞清楚,请帮忙......
jQuery.fn.confirm = function(options) {
options = jQuery.extend({
msg: 'Are you sure?', stopAfter: 'never', wrapper: '<span></span>',
eventType: 'click', dialogShow: 'show', dialogSpeed: '', timeout: 0,
//**belows are what I added**
wrapperLeft: 0, wrapperTop: 0,
outerWrapper: '<span class="relative"></span>',
mask: '<span class="confirmMask"></span>',
//**aboves are what I added**
}, options);
options.stopAfter = options.stopAfter.toLowerCase();
if (!options.stopAfter in ['never', 'once', 'ok', 'cancel']) {
options.stopAfter = 'never';
}
options.buttons = jQuery.extend({
ok: 'Yes', cancel: 'No', wrapper: '<a href="#"></a>', separator: '/'
}, options.buttons);
// Shortcut to eventType.
var type = options.eventType;
return this.each(function() {
var target = this, $target = jQuery(target), timer;
var saveHandlers = function() {
var events = jQuery._data(target, 'events'); //for jquery high version
if (!events && target.href) {
// No handlers but we have href
$target.bind('click', function() { document.location = target.href });
events = jQuery._data(target, 'events');
} else if (!events) {
// There are no handlers to save.
return;
}
target._handlers = new Array();
for (var i in events[type]) {
target._handlers.push(events[type][i]);
}
}
// Create ok button, and bind in to a click handler.
var $ok = jQuery(options.buttons.wrapper).append(options.buttons.ok).click(function() {
// Check if timeout is set.
if (options.timeout != 0) {
clearTimeout(timer);
}
$target.unbind(type, handler);
//$target.show(); //no hide
$dialog.hide();
// Rebind the saved handlers.
if (target._handlers != undefined) {
jQuery.each(target._handlers, function() {
$target.click(this);
});
}
// Trigger click event.
$target.click();
if (options.stopAfter != 'ok' && options.stopAfter != 'once') {
$target.unbind(type);
// Rebind the confirmation handler.
$target.one(type, handler);
}
return false;
})
var $cancel = jQuery(options.buttons.wrapper).append(options.buttons.cancel).click(function() {
// Check if timeout is set.
if (options.timeout != 0) {
clearTimeout(timer);
}
if (options.stopAfter != 'cancel' && options.stopAfter != 'once') {
$target.one(type, handler);
}
//$target.show(); //no hide
$dialog.hide();
return false;
});
if (options.buttons.cls) {
$ok.addClass(options.buttons.cls);
$cancel.addClass(options.buttons.cls);
}
//**belows are what I added**
var $mask = jQuery(options.mask);
var $wrapper = jQuery(options.wrapper);
//**aboves are what I added**
var $dia = jQuery($wrapper).append(options.msg).append($ok).append(options.buttons.separator).append($cancel);
var $dialog = jQuery(options.outerWrapper).append($mask).append($dia);
var handler = function() {
//jQuery(this).hide(); //no hide
// Do this check because of a jQuery bug
if (options.dialogShow != 'show') {
$dialog.hide();
}
$dialog.insertBefore(this);
//**belows are what I added**
$mask.css({ width: document.body.scrollWidth,
height: document.body.scrollHeight,
top: -$mask.offset().top,
left: -$mask.offset().left
});
$wrapper.css({ top: options.wrapperTop, left: options.wrapperLeft });
//**aboves are what I added**
// Display the dialog.
$dialog[options.dialogShow](options.dialogSpeed);
if (options.timeout != 0) {
// Set timeout
clearTimeout(timer);
timer = setTimeout(function() { $cancel.click(); $target.one(type, handler); }, options.timeout);
}
return false;
};
saveHandlers();
$target.unbind(type);
target._confirm = handler
target._confirmEvent = type;
$target.one(type, handler);
});
}