JQueryUI 1.9: how to check widget initialization (it is not possible to call a method before initialization)

I am currently porting some code from 1.8 to 1.9.2, and I am facing a situation where widgets are destroyed before initialization. For example, in 1.9.2 it may be wrong (throwing an exception): is there a way to verify that a call is possible:

$div.buttonset("destroy") 
+6
source share
2 answers

You can verify the existence of the widget using $ element.data ("widget-name"), and then call what you want.

The widget's own name is the namespace + dash + plugin name. For example: ui-tabs, ui-dialog, etc.

In my project, I have a widget with the full name mediaITPro.player. The correct name for transferring a data call is "mediaITPro-player".

The following line does the job for me:

 if (p.data("mediaITPro-player")) p.player("destroy"); 

Hope this helps.

PS Documents on naming conventions for calling .data http://jqueryui.com/upgrade-guide/1.9/#changed-naming-convention-for-data-keys

+3
source

At least for a dialog widget you can use div.is(":ui-dialog") . Note that with jQuery UI 1.10.1, the old if (div.data("dialog")) does not work (at least for me).

+1
source

All Articles