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.
This commit is contained in:
reliberate 2016-03-31 17:11:37 -06:00
parent a4005f46e3
commit 9cfedbf2e9
7 changed files with 196 additions and 167 deletions

View File

@ -137,31 +137,20 @@ echo "</script>";
// keyboard shortcut bindings // keyboard shortcut bindings
echo "<script language='JavaScript' type='text/javascript' src='".PROJECT_PATH."/resources/jquery/jquery-1.11.1.js'></script>\n"; echo "<script language='JavaScript' type='text/javascript' src='".PROJECT_PATH."/resources/jquery/jquery-1.11.1.js'></script>\n";
echo "<script>\n";
echo " $(window).keypress(function(event) {\n";
echo " //save file [Ctrl+S]\n";
echo " if ((event.which == 115 && event.ctrlKey) || (event.which == 19)) {\n";
echo " parent.$('form#frm_edit').submit();\n";
echo " return false;\n";
echo " }\n";
echo " //open file manager/clip library pane [Ctrl+Q]\n";
echo " else if ((event.which == 113 && event.ctrlKey) || (event.which == 19)) {\n";
echo " parent.toggle_sidebar();\n";
echo " parent.focus_editor();\n";
echo " return false;\n";
echo " }\n";
echo " //block backspace\n";
echo " else if (event.which == 8) {\n";
echo " return false;\n";
echo " }\n";
echo " //otherwise, default action\n";
echo " else {\n";
echo " return true;\n";
echo " }\n";
echo " });\n";
echo "</script>\n";
echo "<head>\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 "</head>\n";
echo "<body style='margin: 0; padding: 5px;' onfocus='blur();'>\n"; echo "<body style='margin: 0; padding: 5px;' onfocus='blur();'>\n";
echo "<div style='text-align: left; padding-top: 3px;'>\n"; echo "<div style='text-align: left; padding-top: 3px;'>\n";

View File

@ -180,29 +180,15 @@ echo "</SCRIPT>";
// keyboard shortcut bindings // keyboard shortcut bindings
echo "<script language='JavaScript' type='text/javascript' src='".PROJECT_PATH."/resources/jquery/jquery-1.11.1.js'></script>\n"; echo "<script language='JavaScript' type='text/javascript' src='".PROJECT_PATH."/resources/jquery/jquery-1.11.1.js'></script>\n";
echo "<script>\n";
echo " $(window).keypress(function(event) {\n"; //save file
echo " //save file [Ctrl+S]\n"; key_press('ctrl+s', 'down', 'window', null, null, "parent.$('form#frm_edit').submit(); return false;", true);
echo " if ((event.which == 115 && event.ctrlKey) || (event.which == 19)) {\n";
echo " parent.$('form#frm_edit').submit();\n"; //open file manager/clip library pane
echo " return false;\n"; key_press('ctrl+q', 'down', 'window', null, null, 'parent.toggle_sidebar(); parent.focus_editor(); return false;', true);
echo " }\n";
echo " //open file manager/clip library pane [Ctrl+Q]\n"; //prevent backspace (browser history back)
echo " else if ((event.which == 113 && event.ctrlKey) || (event.which == 19)) {\n"; key_press('backspace', 'down', 'window', null, null, 'return false;', true);
echo " parent.toggle_sidebar();\n";
echo " parent.focus_editor();\n";
echo " return false;\n";
echo " }\n";
echo " //block backspace\n";
echo " else if (event.which == 8) {\n";
echo " return false;\n";
echo " }\n";
echo " //otherwise, default action\n";
echo " else {\n";
echo " return true;\n";
echo " }\n";
echo " });\n";
echo "</script>";
echo "</head>\n"; echo "</head>\n";
echo "<body style='margin: 0px; padding: 5px;'>\n"; echo "<body style='margin: 0px; padding: 5px;'>\n";

View File

@ -273,28 +273,14 @@ else {
document.getElementById('editor').style.fontSize='<?php echo $setting_size;?>'; document.getElementById('editor').style.fontSize='<?php echo $setting_size;?>';
focus_editor(); focus_editor();
//prevent submit (file save) with enter key on file path input //prevent form submit with enter key on file path input
$('#current_file').keypress(function(event){ <?php key_press('enter', 'down', '#current_file', null, null, 'return false;', false); ?>
if (event.which == 13) { return false; }
});
//keyboard shortcut to save file //save file
$(window).keypress(function(event) { <?php key_press('ctrl+s', 'down', 'window', null, null, "$('form#frm_edit').submit(); return false;", false); ?>
//save file [Ctrl+S]
if ((event.which == 115 && event.ctrlKey) || (event.which == 19)) { //open file manager/clip library pane
$('form#frm_edit').submit(); <?php key_press('ctrl+q', 'down', 'window', null, null, 'toggle_sidebar(); focus_editor(); return false;', false); ?>
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;
}
});
//remove certain keyboard shortcuts //remove certain keyboard shortcuts
editor.commands.bindKey("Ctrl-T", null); //new browser tab editor.commands.bindKey("Ctrl-T", null); //new browser tab

View File

@ -425,18 +425,9 @@ else {
document.getElementById('editor').style.fontSize='<?php echo $setting_size;?>'; document.getElementById('editor').style.fontSize='<?php echo $setting_size;?>';
focus_editor(); focus_editor();
//keyboard shortcuts //keyboard shortcut to execute command
$(window).keypress(function(event) { <?php key_press('ctrl+enter', 'down', 'window', null, null, "$('form#frm').submit();", false); ?>
//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;
}
});
//remove certain keyboard shortcuts //remove certain keyboard shortcuts
editor.commands.bindKey("Ctrl-T", null); //new browser tab editor.commands.bindKey("Ctrl-T", null); //new browser tab
</script> </script>

View File

@ -138,7 +138,7 @@ else {
echo " </td>\n"; echo " </td>\n";
echo " <td width='30%' align='right' valign='top'>\n"; echo " <td width='30%' align='right' valign='top'>\n";
echo " <form method='get' action=''>\n"; echo " <form method='get' action=''>\n";
echo " <input type='text' class='txt' style='width: 150px' name='search' value='".$search."'>"; echo " <input type='text' class='txt' style='width: 150px' name='search' id='search' value='".$search."'>";
echo " <input type='submit' class='btn' name='submit' value='".$text['button-search']."'>"; echo " <input type='submit' class='btn' name='submit' value='".$text['button-search']."'>";
echo " </form>\n"; echo " </form>\n";
echo " </td>\n"; echo " </td>\n";
@ -241,6 +241,7 @@ else {
if (sizeof($vm_ids) > 0) { if (sizeof($vm_ids) > 0) {
echo "<script>\n"; echo "<script>\n";
echo " function check(what) {\n"; echo " function check(what) {\n";
echo " document.getElementById('chk_all').checked = (what == 'all') ? true : false;\n";
foreach ($vm_ids as $vm_id) { foreach ($vm_ids as $vm_id) {
echo " document.getElementById('".$vm_id."').checked = (what == 'all') ? true : false;\n"; echo " document.getElementById('".$vm_id."').checked = (what == 'all') ? true : false;\n";
} }
@ -248,6 +249,12 @@ else {
echo "</script>\n"; echo "</script>\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 { else {
echo "<br />"; echo "<br />";

View File

@ -1592,6 +1592,7 @@ function number_pad($number,$n) {
} }
//email validate //email validate
if (!function_exists('email_validate')) {
function email_validate($strEmail){ function email_validate($strEmail){
$validRegExp = '/^[a-zA-Z0-9\._-]+@[a-zA-Z0-9\._-]+\.[a-zA-Z]{2,3}$/'; $validRegExp = '/^[a-zA-Z0-9\._-]+@[a-zA-Z0-9\._-]+\.[a-zA-Z]{2,3}$/';
// search email text for regular exp matches // search email text for regular exp matches
@ -1603,8 +1604,75 @@ function number_pad($number,$n) {
return 1; 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 "<script language='JavaScript' type='text/javascript'>\n";
}
echo " $(".$subject.").key".$direction."(function(e) {\n";
echo " if (".$exceptions.$key_code.") {\n";
if ($prompt != '') {
$action = ($action != '') ? $action : "alert('".$key."');";
echo " if (confirm('".$prompt."')) {\n";
echo " e.preventDefault();\n";
echo " ".$action."\n";
echo " }\n";
}
else {
echo " e.preventDefault();\n";
echo " ".$action."\n";
}
echo " }\n";
echo " });\n";
if ($script_wrapper) {
echo "</script>\n";
}
echo "\n\n\n";
}
}
//converts a string to a regular expression //converts a string to a regular expression
if (!function_exists('string_to_regex')) {
function string_to_regex($string) { function string_to_regex($string) {
//escape the plus //escape the plus
if (substr($string, 0, 1) == "+") { if (substr($string, 0, 1) == "+") {
@ -1653,5 +1721,6 @@ function number_pad($number,$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 = "2089068227)$"; echo $string." ".string_to_regex($string)."\n"; //$string = "2089068227)$"; echo $string." ".string_to_regex($string)."\n";
}
?> ?>

View File

@ -165,6 +165,7 @@
margin: 0; margin: 0;
padding: 0; padding: 0;
overflow: auto; 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; top: 0;
right: 0; right: 0;
bottom: 0; bottom: 0;
@ -1403,18 +1404,22 @@
$("#message_text").mouseover(function() { $(this).hide(); $("#message_container").hide(); }); $("#message_text").mouseover(function() { $(this).hide(); $("#message_container").hide(); });
<?php
if (permission_exists("domain_select") && count($_SESSION['domains']) > 1) {
?>
//domain selector controls //domain selector controls
$(".domain_selector_domain").click(function() { show_domains(); }); $(".domain_selector_domain").click(function() { show_domains(); });
$("#domains_hide").click(function() { hide_domains(); }); $("#domains_hide").click(function() { hide_domains(); });
function show_domains() { function show_domains() {
var scrollbar_width = (window.innerWidth - $(window).width()); //gold: only solution that worked with body { overflow:auto }, even when scrollbar not visible var scrollbar_width = (window.innerWidth - $(window).width()); //gold: only solution that worked with body { overflow:auto } (add -ms-overflow-style: scrollbar; to <body> style for ie 10+)
if (scrollbar_width > 0) { if (scrollbar_width > 0) {
$("body").css({'margin-right':scrollbar_width, 'overflow':'hidden'}); //disable body scroll bars $("body").css({'margin-right':scrollbar_width, 'overflow':'hidden'}); //disable body scroll bars
$(".navbar").css('margin-right',scrollbar_width); //adjust navbar margin to compensate $(".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('right',-scrollbar_width); //domain container right position to compensate
} }
$("#domains_container").show(); $("#domains_container").css({top: $(document).scrollTop(), height: window.innerHeight}).show();
$("#domains_block").animate({marginRight: '+=300'}, 400); $("#domains_block").animate({marginRight: '+=300'}, 400);
$("#domain_filter").focus(); $("#domain_filter").focus();
document.getElementById('domains_visible').value = 1; document.getElementById('domains_visible').value = 1;
@ -1434,14 +1439,10 @@
document.getElementById('domains_visible').value = 0; document.getElementById('domains_visible').value = 0;
} }
$(document).keyup(function(e) { //escape toggles visibility <?php
if (e.keyCode == 27 && document.getElementById('domains_visible').value == 0) { key_press('escape', 'up', 'document', null, null, "if (document.getElementById('domains_visible').value == 0) { show_domains(); } else if (document.getElementById('domains_visible').value == 1) { hide_domains(); }", false);
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 <tr> tag //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 <tr> tag