From 10ad63cbca1762b44197e7d94367f702d7d6c595 Mon Sep 17 00:00:00 2001 From: Christian Prescott Date: Sat, 1 Aug 2015 18:30:23 -0600 Subject: [PATCH 1/3] Fix dialog repeatedly binding keypress event on each open of dialog (or prompt) --- src/js/utils.js | 45 ++++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/src/js/utils.js b/src/js/utils.js index fe8d843..79fd985 100755 --- a/src/js/utils.js +++ b/src/js/utils.js @@ -639,7 +639,30 @@ $(document).ready(function(){ settings = jQuery.extend(settings, options); - $( app.helpers.getSelector('dialog') ).dialog( settings ); + var $dialog = $( app.helpers.getSelector('dialog') ); + + $dialog.dialog( settings ); + + // bind to enter + $dialog.keypress(function(e) { + if (e.keyCode == $.ui.keyCode.ENTER) { + // look for a button with class "bind-enter" first, fallback to OK btn, fallback to none. + var $parent = $(this).parent(), + $enterButton = $parent.find('.bind-enter'), + $btn = ($enterButton.length === 0 ? $parent.find('.ui-dialog-buttonpane button:first') : $enterButton); + // if button pane exists + if($parent.find('.ui-dialog-buttonpane button').length > 0){ + console.log("clicking"); + $btn.trigger("click"); + } + } + }); + + //fix scrollTo issue with dialog + $dialog.bind( "dialogopen", function(event, ui) { + $('.ui-widget-overlay, .ui-dialog').css('position', 'fixed'); + $('.dialog-menu a:last').addClass('last'); + }); }; @@ -664,26 +687,6 @@ $(document).ready(function(){ $dialog.html(content); $dialog.dialog( "option", options ); - //fix scrollTo issue with dialog - $dialog.bind( "dialogopen", function(event, ui) { - $('.ui-widget-overlay, .ui-dialog').css('position', 'fixed'); - $('.dialog-menu a:last').addClass('last'); - - // bind to enter - $dialog.keypress(function(e) { - if (e.keyCode == $.ui.keyCode.ENTER) { - // look for a button with class "bind-enter" first, fallback to OK btn, fallback to none. - var $parent = $(this).parent(), - $enterButton = $parent.find('.bind-enter'), - $btn = ($enterButton.length === 0 ? $parent.find('.ui-dialog-buttonpane button:first') : $enterButton); - // if button pane exists - if($parent.find('.ui-dialog-buttonpane button').length > 0){ - $btn.trigger("click"); - } - } - }); - }); - //open $dialog.dialog( "open" ); From 0ae0a19bc2174215344085e859d911c9c9a9172f Mon Sep 17 00:00:00 2001 From: Christian Prescott Date: Sat, 1 Aug 2015 19:14:23 -0600 Subject: [PATCH 2/3] Revert "Fix dialog repeatedly binding keypress event on each open of dialog (or prompt)" This reverts commit 10ad63cbca1762b44197e7d94367f702d7d6c595. --- src/js/utils.js | 45 +++++++++++++++++++++------------------------ 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/src/js/utils.js b/src/js/utils.js index 79fd985..fe8d843 100755 --- a/src/js/utils.js +++ b/src/js/utils.js @@ -639,30 +639,7 @@ $(document).ready(function(){ settings = jQuery.extend(settings, options); - var $dialog = $( app.helpers.getSelector('dialog') ); - - $dialog.dialog( settings ); - - // bind to enter - $dialog.keypress(function(e) { - if (e.keyCode == $.ui.keyCode.ENTER) { - // look for a button with class "bind-enter" first, fallback to OK btn, fallback to none. - var $parent = $(this).parent(), - $enterButton = $parent.find('.bind-enter'), - $btn = ($enterButton.length === 0 ? $parent.find('.ui-dialog-buttonpane button:first') : $enterButton); - // if button pane exists - if($parent.find('.ui-dialog-buttonpane button').length > 0){ - console.log("clicking"); - $btn.trigger("click"); - } - } - }); - - //fix scrollTo issue with dialog - $dialog.bind( "dialogopen", function(event, ui) { - $('.ui-widget-overlay, .ui-dialog').css('position', 'fixed'); - $('.dialog-menu a:last').addClass('last'); - }); + $( app.helpers.getSelector('dialog') ).dialog( settings ); }; @@ -687,6 +664,26 @@ $(document).ready(function(){ $dialog.html(content); $dialog.dialog( "option", options ); + //fix scrollTo issue with dialog + $dialog.bind( "dialogopen", function(event, ui) { + $('.ui-widget-overlay, .ui-dialog').css('position', 'fixed'); + $('.dialog-menu a:last').addClass('last'); + + // bind to enter + $dialog.keypress(function(e) { + if (e.keyCode == $.ui.keyCode.ENTER) { + // look for a button with class "bind-enter" first, fallback to OK btn, fallback to none. + var $parent = $(this).parent(), + $enterButton = $parent.find('.bind-enter'), + $btn = ($enterButton.length === 0 ? $parent.find('.ui-dialog-buttonpane button:first') : $enterButton); + // if button pane exists + if($parent.find('.ui-dialog-buttonpane button').length > 0){ + $btn.trigger("click"); + } + } + }); + }); + //open $dialog.dialog( "open" ); From faf47ab547b49dc17d2ef7f22a61bd3cd16fdc57 Mon Sep 17 00:00:00 2001 From: Christian Prescott Date: Sat, 1 Aug 2015 19:15:02 -0600 Subject: [PATCH 3/3] Return bindings to app.helpers.dialog and remove old bindings on each call --- src/js/utils.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/js/utils.js b/src/js/utils.js index fe8d843..4bc539f 100755 --- a/src/js/utils.js +++ b/src/js/utils.js @@ -664,6 +664,9 @@ $(document).ready(function(){ $dialog.html(content); $dialog.dialog( "option", options ); + // remove old event bindings + $dialog.unbind(); + //fix scrollTo issue with dialog $dialog.bind( "dialogopen", function(event, ui) { $('.ui-widget-overlay, .ui-dialog').css('position', 'fixed');