Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQueryUI 1.9 : how to check for widget initialized (cannot call method prior to initialization)

I'm currently migrating some code from 1.8 to 1.9.2 and I'm facing the situation where widgets are destroyed before being initialized. For example, the following can be faulty (throwing an exception) now in 1.9.2 : is there any way I can check the call is possible :

$div.buttonset("destroy")
like image 919
Marc Polizzi Avatar asked Nov 28 '12 01:11

Marc Polizzi


2 Answers

You can check for widget's existence using $element.data("widget-name") then call what you want.

The proper name of the widget is namespace + dash + plugin name. For ex.: ui-tabs, ui-dialog etc.

In my project I have a widget with full name mediaITPro.player. The right name to pass to data call is "mediaITPro-player".

The following line does the job for me:

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

I hope this helps.

P.S. The docs on naming conventions for .data call http://jqueryui.com/upgrade-guide/1.9/#changed-naming-convention-for-data-keys

like image 54
Nek Avatar answered Oct 18 '22 09:10

Nek


At least for 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).

like image 31
Michael Logutov Avatar answered Oct 18 '22 09:10

Michael Logutov