// IE doesn't implement Array.indexOf if (!Array.indexOf) { Array.prototype.indexOf = function(obj) { for (var i = 0, len = this.length; i < len; i++) { if (this[i] == obj) { return i; } } return -1; }; } // Returns the number of keys (elements) in an array/dictionary. function obj_length(obj) { if (obj.length !== undefined) { return obj.length; } var count = 0; for (var element in obj) { count++; } return count; } $.fn.makeAbsolute = function(rebase) { return this.each(function() { var el = $(this); var pos = el.position(); el.css({ position: "absolute", marginLeft: 0, marginTop: 0, top: pos.top, left: pos.left, right: $(window).width() - ( pos.left + el.width() ) }); if (rebase) { el.remove().appendTo("body"); } }); }; function make_popupmenu(button_element, initial_options) { /* Use the $.data feature to store options with the link element. This allows options to be changed at a later time */ var element_menu_exists = (button_element.data("menu_options")); button_element.data("menu_options", initial_options); // If element already has menu, nothing else to do since HTML and actions are already set. if (element_menu_exists) { return; } button_element.bind("click.show_popup", function(e) { // Close existing visible menus $(".popmenu-wrapper").remove(); // Need setTimeouts so clicks don't interfere with each other setTimeout( function() { // Dynamically generate the wrapper holding all the selectable options of the menu. var menu_element = $( "