From 9cfedbf2e9662a9c2524e738812e2fc8bd4b18ee Mon Sep 17 00:00:00 2001 From: reliberate Date: Thu, 31 Mar 2016 17:11:37 -0600 Subject: [PATCH] Function: Created key_press function to dynamically generate key detection javascript. Voicemail: Ctrl+A checks all checkboxes, pressing Delete deletes the checked Voicemails. Editor: Integrated key_press function. Command: Integrated key_press function. --- app/edit/cliplist.php | 37 +++----- app/edit/filelist.php | 32 ++----- app/edit/index.php | 28 ++---- app/exec/exec.php | 15 +-- app/voicemails/voicemails.php | 11 ++- resources/functions.php | 171 ++++++++++++++++++++++++---------- themes/default/template.php | 69 +++++++------- 7 files changed, 196 insertions(+), 167 deletions(-) diff --git a/app/edit/cliplist.php b/app/edit/cliplist.php index a6914ad6aa..67572ee658 100644 --- a/app/edit/cliplist.php +++ b/app/edit/cliplist.php @@ -137,31 +137,20 @@ echo ""; // keyboard shortcut bindings echo "\n"; -echo "\n"; -echo "\n"; +//save file +key_press('ctrl+s', 'down', 'window', null, null, "if (parent.document.getElementById('frm_edit')) { parent.$('form#frm_edit').submit(); return false; }", true); + +//open file manager/clip library pane +key_press('ctrl+q', 'down', 'window', null, null, "if (parent.document.getElementById('sidebar')) { parent.toggle_sidebar(); parent.focus_editor(); return false; }", true); + +//prevent backspace (browser history back) +key_press('backspace', 'down', 'window', null, null, 'return false;', true); + +//keyboard shortcut to execute command (when included on command page) +key_press('ctrl+enter', 'down', 'window', null, null, "if (!parent.document.getElementById('sidebar')) { parent.$('form#frm').submit(); return false; }", true); + +echo "\n"; echo "\n"; echo "
\n"; diff --git a/app/edit/filelist.php b/app/edit/filelist.php index 07488aa228..2fc19c56fa 100644 --- a/app/edit/filelist.php +++ b/app/edit/filelist.php @@ -180,29 +180,15 @@ echo ""; // keyboard shortcut bindings echo "\n"; -echo ""; + +//save file +key_press('ctrl+s', 'down', 'window', null, null, "parent.$('form#frm_edit').submit(); return false;", true); + +//open file manager/clip library pane +key_press('ctrl+q', 'down', 'window', null, null, 'parent.toggle_sidebar(); parent.focus_editor(); return false;', true); + +//prevent backspace (browser history back) +key_press('backspace', 'down', 'window', null, null, 'return false;', true); echo "\n"; echo "\n"; diff --git a/app/edit/index.php b/app/edit/index.php index 1cd12b326a..ed02958aed 100644 --- a/app/edit/index.php +++ b/app/edit/index.php @@ -273,28 +273,14 @@ else { document.getElementById('editor').style.fontSize=''; focus_editor(); - //prevent submit (file save) with enter key on file path input - $('#current_file').keypress(function(event){ - if (event.which == 13) { return false; } - }); + //prevent form submit with enter key on file path input + - //keyboard shortcut to save file - $(window).keypress(function(event) { - //save file [Ctrl+S] - if ((event.which == 115 && event.ctrlKey) || (event.which == 19)) { - $('form#frm_edit').submit(); - return false; - } - //open file manager/clip library pane [Ctrl+Q] - else if ((event.which == 113 && event.ctrlKey) || (event.which == 19)) { - toggle_sidebar(); - return false; - } - //otherwise, default action - else { - return true; - } - }); + //save file + + + //open file manager/clip library pane + //remove certain keyboard shortcuts editor.commands.bindKey("Ctrl-T", null); //new browser tab diff --git a/app/exec/exec.php b/app/exec/exec.php index db2988c4ef..8c07df3a0d 100644 --- a/app/exec/exec.php +++ b/app/exec/exec.php @@ -425,18 +425,9 @@ else { document.getElementById('editor').style.fontSize=''; focus_editor(); - //keyboard shortcuts - $(window).keypress(function(event) { - //execute command [Ctrl+Enter] - if (((event.which == 13 || event.which == 10) && event.ctrlKey) || (event.which == 19)) { - $('form#frm').submit(); - return false; - } - //otherwise, default action - else { - return true; - } - }); + //keyboard shortcut to execute command + + //remove certain keyboard shortcuts editor.commands.bindKey("Ctrl-T", null); //new browser tab diff --git a/app/voicemails/voicemails.php b/app/voicemails/voicemails.php index 5fdc12a912..e0130a486d 100644 --- a/app/voicemails/voicemails.php +++ b/app/voicemails/voicemails.php @@ -138,7 +138,7 @@ else { echo " \n"; echo " \n"; echo "
\n"; - echo " "; + echo " "; echo " "; echo "
\n"; echo " \n"; @@ -241,13 +241,20 @@ else { if (sizeof($vm_ids) > 0) { echo "\n"; } + // check all checkboxes + key_press('ctrl+a', 'down', 'document', null, null, "check('all');", true); + + // delete checked + key_press('delete', 'up', 'document', array('#search'), $text['confirm-delete'], 'document.forms.frm.submit();', true); + } else { echo "
"; diff --git a/resources/functions.php b/resources/functions.php index bb1c42eee3..37e2d2e2d0 100644 --- a/resources/functions.php +++ b/resources/functions.php @@ -1592,66 +1592,135 @@ function number_pad($number,$n) { } //email validate - function email_validate($strEmail){ - $validRegExp = '/^[a-zA-Z0-9\._-]+@[a-zA-Z0-9\._-]+\.[a-zA-Z]{2,3}$/'; - // search email text for regular exp matches - preg_match($validRegExp, $strEmail, $matches, PREG_OFFSET_CAPTURE); - if (count($matches) == 0) { - return 0; + if (!function_exists('email_validate')) { + function email_validate($strEmail){ + $validRegExp = '/^[a-zA-Z0-9\._-]+@[a-zA-Z0-9\._-]+\.[a-zA-Z]{2,3}$/'; + // search email text for regular exp matches + preg_match($validRegExp, $strEmail, $matches, PREG_OFFSET_CAPTURE); + if (count($matches) == 0) { + return 0; + } + else { + return 1; + } } - else { - return 1; + } + +//write javascript function that detects select key combinations to perform designated actions + if (!function_exists('key_press')) { + function key_press($key, $direction = 'up', $subject = 'document', $exceptions = array(), $prompt = null, $action = null, $script_wrapper = true) { + //determine key code + switch (strtolower($key)) { + case 'escape': + $key_code = '(e.which == 27)'; + break; + case 'delete': + $key_code = '(e.which == 46)'; + break; + case 'enter': + $key_code = '(e.which == 13)'; + break; + case 'backspace': + $key_code = '(e.which == 8)'; + break; + case 'ctrl+s': + $key_code = '(((e.which == 115 || e.which == 83) && (e.ctrlKey || e.metaKey)) || (e.which == 19))'; + break; + case 'ctrl+q': + $key_code = '(((e.which == 113 || e.which == 81) && (e.ctrlKey || e.metaKey)) || (e.which == 19))'; + break; + case 'ctrl+a': + $key_code = '(((e.which == 97 || e.which == 65) && (e.ctrlKey || e.metaKey)) || (e.which == 19))'; + break; + case 'ctrl+enter': + $key_code = '(((e.which == 13 || e.which == 10) && (e.ctrlKey || e.metaKey)) || (e.which == 19))'; + break; + default: + return; + } + //check for element exceptions + if (sizeof($exceptions) > 0) { + $exceptions = "!$(e.target).is('".implode(',', $exceptions)."') && "; + } + //quote if selector is id or class + $subject = ($subject != 'window' && $subject != 'document') ? "'".$subject."'" : $subject; + //output script + echo "\n\n\n"; + if ($script_wrapper) { + echo "\n"; + } + echo "\n\n\n"; } } //converts a string to a regular expression - function string_to_regex($string) { - //escape the plus - if (substr($string, 0, 1) == "+") { - $string = "^\\+(".substr($string, 1).")$"; - } - //convert N,X,Z syntax to regex - $string = str_ireplace("N", "[2-9]", $string); - $string = str_ireplace("X", "[0-9]", $string); - $string = str_ireplace("Z", "[1-9]", $string); - //add ^ to the start of the string if missing - if (substr($string, 0, 1) != "^") { - $string = "^".$string; - } - //add $ to the end of the string if missing - if (substr($string, -1) != "$") { - $string = $string."$"; - } - //add the round brackgets ( and ) - if (!strstr($string, '(')) { - if (strstr($string, '^')) { - $string = str_replace("^", "^(", $string); + if (!function_exists('string_to_regex')) { + function string_to_regex($string) { + //escape the plus + if (substr($string, 0, 1) == "+") { + $string = "^\\+(".substr($string, 1).")$"; } - else { - $string = '^('.$string; + //convert N,X,Z syntax to regex + $string = str_ireplace("N", "[2-9]", $string); + $string = str_ireplace("X", "[0-9]", $string); + $string = str_ireplace("Z", "[1-9]", $string); + //add ^ to the start of the string if missing + if (substr($string, 0, 1) != "^") { + $string = "^".$string; } - } - if (!strstr($string, ')')) { - if (strstr($string, '$')) { - $string = str_replace("$", ")$", $string); + //add $ to the end of the string if missing + if (substr($string, -1) != "$") { + $string = $string."$"; } - else { - $string = $string.')$'; + //add the round brackgets ( and ) + if (!strstr($string, '(')) { + if (strstr($string, '^')) { + $string = str_replace("^", "^(", $string); + } + else { + $string = '^('.$string; + } } - } - //return the result - return $string; + if (!strstr($string, ')')) { + if (strstr($string, '$')) { + $string = str_replace("$", ")$", $string); + } + else { + $string = $string.')$'; + } + } + //return the result + return $string; + } + //$string = "+12089068227"; echo $string." ".string_to_regex($string)."\n"; + //$string = "12089068227"; echo $string." ".string_to_regex($string)."\n"; + //$string = "2089068227"; echo $string." ".string_to_regex($string)."\n"; + //$string = "^(20890682[0-9][0-9])$"; echo $string." ".string_to_regex($string)."\n"; + //$string = "1208906xxxx"; echo $string." ".string_to_regex($string)."\n"; + //$string = "nxxnxxxxxxx"; echo $string." ".string_to_regex($string)."\n"; + //$string = "208906xxxx"; echo $string." ".string_to_regex($string)."\n"; + //$string = "^(2089068227"; echo $string." ".string_to_regex($string)."\n"; + //$string = "^2089068227)"; echo $string." ".string_to_regex($string)."\n"; + //$string = "2089068227$"; echo $string." ".string_to_regex($string)."\n"; + //$string = "2089068227)$"; echo $string." ".string_to_regex($string)."\n"; } - //$string = "+12089068227"; echo $string." ".string_to_regex($string)."\n"; - //$string = "12089068227"; echo $string." ".string_to_regex($string)."\n"; - //$string = "2089068227"; echo $string." ".string_to_regex($string)."\n"; - //$string = "^(20890682[0-9][0-9])$"; echo $string." ".string_to_regex($string)."\n"; - //$string = "1208906xxxx"; echo $string." ".string_to_regex($string)."\n"; - //$string = "nxxnxxxxxxx"; echo $string." ".string_to_regex($string)."\n"; - //$string = "208906xxxx"; echo $string." ".string_to_regex($string)."\n"; - //$string = "^(2089068227"; echo $string." ".string_to_regex($string)."\n"; - //$string = "^2089068227)"; echo $string." ".string_to_regex($string)."\n"; - //$string = "2089068227$"; echo $string." ".string_to_regex($string)."\n"; - //$string = "2089068227)$"; echo $string." ".string_to_regex($string)."\n"; ?> \ No newline at end of file diff --git a/themes/default/template.php b/themes/default/template.php index 97be1d8fcf..92e024a080 100644 --- a/themes/default/template.php +++ b/themes/default/template.php @@ -165,6 +165,7 @@ margin: 0; padding: 0; overflow: auto; + -ms-overflow-style: scrollbar; /* stops ie10+ from displaying auto-hiding scroll bar on top of the body content (the domain selector, specifically) */ top: 0; right: 0; bottom: 0; @@ -1403,45 +1404,45 @@ $("#message_text").mouseover(function() { $(this).hide(); $("#message_container").hide(); }); - //domain selector controls - $(".domain_selector_domain").click(function() { show_domains(); }); - $("#domains_hide").click(function() { hide_domains(); }); + 1) { + ?> - function show_domains() { - var scrollbar_width = (window.innerWidth - $(window).width()); //gold: only solution that worked with body { overflow:auto }, even when scrollbar not visible - if (scrollbar_width > 0) { - $("body").css({'margin-right':scrollbar_width, 'overflow':'hidden'}); //disable body scroll bars - $(".navbar").css('margin-right',scrollbar_width); //adjust navbar margin to compensate - $("#domains_container").css('right',-scrollbar_width); //domain container right position to compensate + //domain selector controls + $(".domain_selector_domain").click(function() { show_domains(); }); + $("#domains_hide").click(function() { hide_domains(); }); + + function show_domains() { + var scrollbar_width = (window.innerWidth - $(window).width()); //gold: only solution that worked with body { overflow:auto } (add -ms-overflow-style: scrollbar; to style for ie 10+) + if (scrollbar_width > 0) { + $("body").css({'margin-right':scrollbar_width, 'overflow':'hidden'}); //disable body scroll bars + $(".navbar").css('margin-right',scrollbar_width); //adjust navbar margin to compensate + $("#domains_container").css('right',-scrollbar_width); //domain container right position to compensate + } + $("#domains_container").css({top: $(document).scrollTop(), height: window.innerHeight}).show(); + $("#domains_block").animate({marginRight: '+=300'}, 400); + $("#domain_filter").focus(); + document.getElementById('domains_visible').value = 1; } - $("#domains_container").show(); - $("#domains_block").animate({marginRight: '+=300'}, 400); - $("#domain_filter").focus(); - document.getElementById('domains_visible').value = 1; - } - function hide_domains() { - $(document).ready(function() { - $("#domains_block").animate({marginRight: '-=300'}, 400, function() { - $("#domain_filter").val(''); - domain_search($("#domain_filter").val()); - $(".navbar").css('margin-right','0'); //restore navbar margin - $("#domains_container").css('right','0'); //domain container right position - $("#domains_container").hide(); - $("body").css({'margin-right':'0','overflow':'auto'}); //enable body scroll bars + function hide_domains() { + $(document).ready(function() { + $("#domains_block").animate({marginRight: '-=300'}, 400, function() { + $("#domain_filter").val(''); + domain_search($("#domain_filter").val()); + $(".navbar").css('margin-right','0'); //restore navbar margin + $("#domains_container").css('right','0'); //domain container right position + $("#domains_container").hide(); + $("body").css({'margin-right':'0','overflow':'auto'}); //enable body scroll bars + }); }); - }); - document.getElementById('domains_visible').value = 0; - } + document.getElementById('domains_visible').value = 0; + } - $(document).keyup(function(e) { //escape toggles visibility - if (e.keyCode == 27 && document.getElementById('domains_visible').value == 0) { - show_domains(); - } - else if (e.keyCode == 27 && document.getElementById('domains_visible').value == 1) { - hide_domains(); - } - }); + //link table rows (except the last - the list_control_icons cell) on a table with a class of 'tr_hover', according to the href attribute of the tag