Hi,

I'm using the great contextmenu plugin and wonder
how I can update/re-init it on the fly ?

I'm not sure if the code below makes any sense but
basically, what I want to do is to get a new menu value
from a input-text field, add it to the context-ul-menu
and then re-init the contextMenu plugin.

I can't get it to work though. Perhaps someone has got
a working example or something.

Cheers, Tobbe

# Some Javascript
<script>

// Setup bindings object for the contextMenu plugin
var tpl_owners = new Object();
tpl_owners["#tobbe"] = function(t) {save_owner("tobbe",t.id);};
tpl_owners["#bill"] = function(t) {save_owner("bill",t.id);};

function setup_cm() {
   // setup the contextMenu
   jQuery("td.owner").contextMenu("#ownerMenu", {
       bindings : tpl_owners
   });
});


jQuery(function() {
  // Setup the contextMenu on load
  setup_cm();

  // On button click, get new user from input-text
  // and update the context menu
  jQuery("#u_create").click(function() {
   var user = jQuery("#u_user").val(); // input-text
   jQuery.get("http://blaha/new.yaws";, // store at the server
              {"q": "user", "u": user},
              function() { // ajax callback, update the contextMenu
               var id = "#"+user;
               tpl_owners[id] = function(t) {save_owner(user, t.id);};
               jQuery("#ownerMenu ul").append('<li id="' + id + '">' + 
user + '</li>');
               setup_cm();
               jQuery("#u_user").val("");
             });
  });

});
</script>


# The HTML part
<div class="contextMenu" id="ownerMenu">
  <ul>
   <li id="tobbe">tobbe</li>
   <li id="bill">bill</li>
  </ul>
</div>


_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/

Reply via email to