开发者

Detecting if a plugin has been applied

开发者 https://www.devze.com 2023-02-28 11:03 出处:网络
I have an app that loads conversations. Each time a conversation is loaded I need to destroy and re init the file uploader.

I have an app that loads conversations. Each time a conversation is loaded I need to destroy and re init the file uploader.

Per: https://github.com/blueimp/jQuery-File-Upload/wiki/API

I'm trying:

// First destroy existing instance
$('.uploa开发者_JS百科d').fileUpload('destroy');
    // Init
$('.upload').fileUploadUI({
      ........

Problem is on first run I get an error: "Uncaught No FileUpload with namespace "file_upload" assigned to this element"

Any ideas on how I can somehow detect if the plugin has been applied and only then destroy? Thansk


You should be able to detect if the plugin has been applied to an element using the "namespace" (as the plugin refers to it), which is the .data() key the plugin uses.

With the current defaultNamespace being 'file_upload', try:

var upload = $('.upload');

if (upload.data('file_upload'))
    upload.fileUpload('destroy');

Instead of just:

$('.upload').fileUpload('destroy');

This will mirror the plugin's own test, which you can see around line 920 of the current source.

0

精彩评论

暂无评论...
验证码 换一张
取 消