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
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 "<div style='text-align: left; padding-top: 3px;'>\n";

View File

@ -180,29 +180,15 @@ echo "</SCRIPT>";
// keyboard shortcut bindings
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>";
//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 "</head>\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;?>';
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
<?php key_press('enter', 'down', '#current_file', null, null, 'return false;', false); ?>
//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
<?php key_press('ctrl+s', 'down', 'window', null, null, "$('form#frm_edit').submit(); return false;", false); ?>
//open file manager/clip library pane
<?php key_press('ctrl+q', 'down', 'window', null, null, 'toggle_sidebar(); focus_editor(); return false;', false); ?>
//remove certain keyboard shortcuts
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;?>';
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
<?php key_press('ctrl+enter', 'down', 'window', null, null, "$('form#frm').submit();", false); ?>
//remove certain keyboard shortcuts
editor.commands.bindKey("Ctrl-T", null); //new browser tab
</script>

View File

@ -138,7 +138,7 @@ else {
echo " </td>\n";
echo " <td width='30%' align='right' valign='top'>\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 " </form>\n";
echo " </td>\n";
@ -241,13 +241,20 @@ else {
if (sizeof($vm_ids) > 0) {
echo "<script>\n";
echo " function check(what) {\n";
echo " document.getElementById('chk_all').checked = (what == 'all') ? true : false;\n";
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";
}
echo " }\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 {
echo "<br />";

View File

@ -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 "<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
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";
?>

View File

@ -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(); });
<?php
if (permission_exists("domain_select") && count($_SESSION['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 <body> 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();
}
});
<?php
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);
}
?>
//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