Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<pre><code>(function($){ $.widget( "ui.my_ui_widget", { //------------------------------------------------------------------ _init : function(){ var o = this.options; // 2 o.context = this; ... // 3 $('#'+o.id).bind('change', {context:this}, this.on_change ); ... }, //------------------------------------------------------------------ on_change: function(event) { var context = event.data.context; // 4 var o = context.options; o.id = ''; // 5 var sel = this; // event handler context var selectedIndex = sel.selectedIndex; if (selectedIndex &lt; 0) return; o.id = sel.options[selectedIndex].value; // 5 context.update_ui(); // 6 }, //------------------------------------------------------------------ } ); //-------------------------------------------------------------------------- $.extend( $.ui.my_ui_widget, { getter : "id", getterSetter : "xxx, yyy", defaults : { ... context : undefined, // 1 ... on_change : undefined, ... } } ); //-------------------------------------------------------------------------- })(jQuery); $(document).ready(function() { $('.my_ui_widget').each( function(i) { var id = this.id; var mode = ''; try{ mode = this.attributes['mode'].value; } catch(err) { mode = 'unlinked'; } $('#'+id).my_ui_widget( {id:id, mode:mode} ); } ); }); </code></pre> <ol> <li>Enable context from the beginning</li> <li>Remember the widget's this as context (or self if preferred)</li> <li>Pass the context in the jquery way to event handler </li> <li>Extract when needed on the handler side</li> <li>Access the widget data</li> <li>Call widget methods as needed</li> </ol>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload