From 96039611f746f7cd6d66113972c1a604bb931d8a Mon Sep 17 00:00:00 2001 From: Jeremy Goecks Date: Fri, 20 Sep 2013 14:01:49 -0400 Subject: [PATCH] Popup menu implementation: (a) use trigger rather than reimplementing anchor functionality and (b) set URLs for menu options for clarity and utility. --- static/scripts/galaxy.base.js | 60 ++++++++++++++--------------------- 1 file changed, 23 insertions(+), 37 deletions(-) diff --git a/static/scripts/galaxy.base.js b/static/scripts/galaxy.base.js index 0b53fc40e77..595cea79200 100644 --- a/static/scripts/galaxy.base.js +++ b/static/scripts/galaxy.base.js @@ -66,7 +66,10 @@ $.fn.makeAbsolute = function(rebase) { }; /** - * Sets up popupmenu rendering and binds options functions to the appropriate links + * Sets up popupmenu rendering and binds options functions to the appropriate links. + * initial_options is a dict with text describing the option pointing to either (a) a + * function to perform; or (b) another dict with two required keys, 'url' and 'action' (the + * function to perform. (b) is useful for exposing the underlying URL of the option. */ function make_popupmenu(button_element, initial_options) { /* Use the $.data feature to store options with the link element. @@ -92,7 +95,9 @@ function make_popupmenu(button_element, initial_options) { } $.each( options, function( k, v ) { if (v) { - menu_element.append( $("
  • ").append( $("").html(k).click(v) ) ); + // Action can be either an anonymous function and a mapped dict. + var action = v.action || v; + menu_element.append( $("
  • ").append( $("").attr("href", v.url).html(k).click(action) ) ); } else { menu_element.append( $("
  • ").addClass( "head" ).append( $("
    ").html(k) ) ); } @@ -164,43 +169,24 @@ function make_popup_menus( parent ) { options[ link.text() ] = null; } else { - options[ link.text() ] = function() { + options[ link.text() ] = { + url: href, + action: function() { - // if theres confirm text, send the dialog - if ( !confirmtext || confirm( confirmtext ) ) { - var f; - // relocate the center panel - if ( target === "_parent" ) { - window.parent.location = href; - - // relocate the entire window - } else if ( target === "_top" ) { - window.top.location = href; - - // Http request target is a window named demolocal on the local box - } else if ( target === "demo" ) { - if ( f === undefined || f.closed ) { - f = window.open( href,target ); - f.creator = self; + // if theres confirm text, send the dialog + if ( !confirmtext || confirm( confirmtext ) ) { + var f; + // Http request target is a window named demolocal on the local box + if ( target === "demo" ) { + if ( f === undefined || f.closed ) { + f = window.open( href,target ); + f.creator = self; + } + } - - // this panel or other, valid panels - } else { - // it may be that the button and menu href are not in the same frame: - // allow certain frame names to be used as a target - var other_valid_targets = [ - 'galaxy_main' - // following are blocked until needed - //'galaxy_tools', - //'galaxy_history' - ]; - if( ( target && ( target in window ) - && ( other_valid_targets.indexOf( target ) !== -1 ) ) ){ - window[ target ].location = href; - - // relocate this panel - } else { - window.location = href; + // For all other links, do the default action. + else { + link.trigger('click'); } } }