check if jQuery UI tabs have been initialized (without checking for class)

后端 未结 2 897
悲哀的现实
悲哀的现实 2021-01-03 23:36

Using jQuery UI tabs - and I\'ve written a plugin that integrates with ui tabs. I\'ve got the plugin setup to initiate jQuery UI tabs if it .tabs() hasn\'t been

相关标签:
2条回答
  • 2021-01-03 23:50

    You can query the attached widget with data():

    if (!$globalTabs.data("tabs")) {
        $globalTabs.tabs();
    }
    

    This behavior is documented in the Widget factory page of jQuery UI's Development & Planning Wiki:

    • Plugin instance accessible via $( "#something" ).data( "pluginname" )

      • A reference to a jQuery object containing the DOM element is available as a property of the instance as this.element, so it is easy to go back and forth between the object and the element.

    Update: From jQuery UI 1.9 onwards, the widget key becomes the widget's fully qualified name, with dots replaced with dashes, as in:

    if (!$globalTabs.data("ui-tabs")) {
        $globalTabs.tabs();
    }
    

    Using unqualified names is still supported in 1.9 but is deprecated, and support will be dropped in 1.10.

    0 讨论(0)
  • 2021-01-03 23:57

    somehow it causes some error when i try to check the instance.

    i need to reinitialize the tabs and for me a try catch did the trick:

    try {
        $('.mytabs').tabs('destroy');
    } catch (exception) {}
    

    and after that just initialize again:

    $('.mytabs').tabs();
    
    0 讨论(0)
提交回复
热议问题