var activeTicker; //This function should be called by the opened window once a ticker has //been submitted using the submit button. function onTickerSubmit() { activeTicker.val(this.getSelectedTicker()); activeTicker.prev("input[name^='INSTRUMENT']").val(this.getSelectedInstrument()); } $(function() { //Hide all ticker add and remove buttons. $(".ticker").children(".add, .remove").addClass("hidden"); //Show add and remove buttons for last visible ticker. var lastVisible = $(".ticker:visible:last").children(".add, .remove").removeClass("hidden").end(); //If the last visible ticker is the first ticker, hide the remove button. if (!lastVisible.prevAll(".ticker:first").length) lastVisible.children(".remove").addClass("hidden"); //If the last visible ticker is the last ticker, hide the add button. else if (!lastVisible.nextAll(".ticker:first").length) lastVisible.children(".add").addClass("hidden"); //Attach behaviour to select element for controlling calendar element visibility. $("select[name='TIME_SPAN']").change(function() { ($(this).val() == "CUSTOM") ? $(".calendar").show() : $(".calendar").hide(); }) //Hide calendar elements if time span is not set to custom. .change(); //Attach behavior to ticker find buttons. $(".ticker .find").click(function(event) { activeTicker = $(this).siblings(":text[name^='TICKER']"); window.open("/factsheet/ticker_lookup.html", "_blank", "width=400, height=350, scrollbars=1, resizable=1"); event.preventDefault(); }); //Attach behavior to ticker add buttons. $(".ticker .add").click(function(event) { //Hide add and remove buttons for the current ticker. var nextTicker = $(this).siblings(".remove").andSelf().addClass("hidden") //Select the next ticker. .parent(".ticker").nextAll(".ticker:first"); //Clear text field for this ticker. nextTicker.children(":text:first").val('').end() //Show this ticker and the add and remove buttons for this ticker. .children(".add, .remove").andSelf().prev().andSelf().removeClass("hidden"); //If the next ticker is the last ticker, hide the add button. if (!nextTicker.nextAll(".ticker:first").length) nextTicker.children(".add").addClass("hidden"); event.preventDefault(); }); //Attach behavior to ticker remove buttons. $(".ticker .remove").click(function(event) { //Hide this ticker. var prevTicker = $(this).parent(".ticker").prev().andSelf().addClass("hidden") //Clear text field for this ticker. .children(":text:first").val('').end() //Select previous ticker. .prevAll(".ticker:first"); //Show the add and remove buttons for the previous ticker. prevTicker.children(".add, .remove").removeClass("hidden"); //If the previous ticker is the last ticker, hide the remove button. if (!prevTicker.prevAll(".ticker:first").length) prevTicker.children(".remove").addClass("hidden"); event.preventDefault(); }); //Prevent focus rectangle from drawing in Mozilla. $(".ticker a").mousedown(function(event) { event.preventDefault(); }); });