From a576e5ae814d5fc5e1214023435d1413a27caf64 Mon Sep 17 00:00:00 2001 From: Jared Hancock <jared@osticket.com> Date: Mon, 27 Apr 2015 11:44:24 -0500 Subject: [PATCH] ui: Make autofocused fields declarative Instead of selecting the first enabled, visible, non datepicker field, just use the new @autofucus HTML5 attribute to automatically select the autofocused field --- include/staff/apikey.inc.php | 3 ++- include/staff/banlist.inc.php | 5 +++-- include/staff/department.inc.php | 3 ++- include/staff/dynamic-form.inc.php | 2 +- include/staff/dynamic-list.inc.php | 2 +- include/staff/email.inc.php | 3 ++- include/staff/faq-categories.inc.php | 3 ++- include/staff/filter.inc.php | 3 ++- include/staff/group.inc.php | 2 +- include/staff/helptopic.inc.php | 2 +- include/staff/login.tpl.php | 4 +++- include/staff/orgs.inc.php | 5 +++-- include/staff/page.inc.php | 2 +- include/staff/role.inc.php | 3 ++- include/staff/slaplan.inc.php | 2 +- include/staff/staff.inc.php | 2 +- include/staff/team.inc.php | 2 +- include/staff/templates/org-lookup.tmpl.php | 3 ++- include/staff/templates/user-lookup.tmpl.php | 4 ++-- include/staff/tickets.inc.php | 5 ++--- include/staff/users.inc.php | 5 +++-- scp/css/scp.css | 4 ++++ scp/emailtest.php | 3 ++- scp/js/scp.js | 5 ++++- 24 files changed, 48 insertions(+), 29 deletions(-) diff --git a/include/staff/apikey.inc.php b/include/staff/apikey.inc.php index fdf30da4b..5096c5150 100644 --- a/include/staff/apikey.inc.php +++ b/include/staff/apikey.inc.php @@ -70,7 +70,8 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info); </td> <td> <span> - <input type="text" size="30" name="ipaddr" value="<?php echo $info['ipaddr']; ?>"> + <input type="text" size="30" name="ipaddr" value="<?php echo $info['ipaddr']; ?>"i + autofocus> <span class="error">* <?php echo $errors['ipaddr']; ?></span> <i class="help-tip icon-question-sign" href="#ip_addr"></i> </span> diff --git a/include/staff/banlist.inc.php b/include/staff/banlist.inc.php index 3fd33ed5a..409343957 100644 --- a/include/staff/banlist.inc.php +++ b/include/staff/banlist.inc.php @@ -55,8 +55,9 @@ $query="$select $from $where ORDER BY $order_by LIMIT ".$pageNav->getStart()."," <form action="banlist.php" method="GET" name="filter"> <input type="hidden" name="a" value="filter" > <div> - <?php echo __('Query');?>: <input name="q" type="text" size="20" value="<?php echo Format::htmlchars($_REQUEST['q']); ?>"> - + <?php echo __('Query');?>: + <input name="q" type="search" size="30" autofocus + value="<?php echo Format::htmlchars($_REQUEST['q']); ?>"> <input type="submit" name="submit" value="<?php echo __('Search');?>"/> </div> </form> diff --git a/include/staff/department.inc.php b/include/staff/department.inc.php index 5d7aa8426..826c2ab2e 100644 --- a/include/staff/department.inc.php +++ b/include/staff/department.inc.php @@ -72,7 +72,8 @@ $info = Format::htmlchars(($errors && $_POST) ? $_POST : $info); </td> <td> <input data-translate-tag="<?php echo $dept ? $dept->getTranslateTag() : ''; - ?>" type="text" size="30" name="name" value="<?php echo $info['name']; ?>"> + ?>" type="text" size="30" name="name" value="<?php echo $info['name']; ?>" + autofocus> <span class="error">* <?php echo $errors['name']; ?></span> </td> </tr> diff --git a/include/staff/dynamic-form.inc.php b/include/staff/dynamic-form.inc.php index 5415ba03c..0bf1f1039 100644 --- a/include/staff/dynamic-form.inc.php +++ b/include/staff/dynamic-form.inc.php @@ -73,7 +73,7 @@ if ($form && count($langs) > 1) { ?> lang="<?php echo $cfg->getPrimaryLanguage(); ?>"> <div class="required"><?php echo __('Title'); ?>:</div> <div> - <input type="text" name="title" size="60" + <input type="text" name="title" size="60" autofocus value="<?php echo $info['title']; ?>"/> <i class="help-tip icon-question-sign" href="#form_title"></i> <div class="error"><?php diff --git a/include/staff/dynamic-list.inc.php b/include/staff/dynamic-list.inc.php index 8b9dd9557..3755f2e38 100644 --- a/include/staff/dynamic-list.inc.php +++ b/include/staff/dynamic-list.inc.php @@ -57,7 +57,7 @@ $info=Format::htmlchars(($errors && $_POST) ? array_merge($info,$_POST) : $info) echo $list->getName(); else { echo sprintf('<input size="50" type="text" name="name" - data-translate-tag="%s" + data-translate-tag="%s" autofocus value="%s"/> <span class="error">*<br/>%s</span>', $trans['name'], $info['name'], $errors['name']); diff --git a/include/staff/email.inc.php b/include/staff/email.inc.php index 8958d43a0..5cc183baa 100644 --- a/include/staff/email.inc.php +++ b/include/staff/email.inc.php @@ -55,7 +55,8 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info); <?php echo __('Email Address');?> </td> <td> - <input type="text" size="35" name="email" value="<?php echo $info['email']; ?>"> + <input type="text" size="35" name="email" value="<?php echo $info['email']; ?>" + autofocus> <span class="error">* <?php echo $errors['email']; ?></span> </td> </tr> diff --git a/include/staff/faq-categories.inc.php b/include/staff/faq-categories.inc.php index d66c24470..52d4f8d49 100644 --- a/include/staff/faq-categories.inc.php +++ b/include/staff/faq-categories.inc.php @@ -6,7 +6,8 @@ if(!defined('OSTSTAFFINC') || !$thisstaff) die('Access Denied'); <form id="kbSearch" action="kb.php" method="get"> <input type="hidden" name="a" value="search"> <div> - <input id="query" type="text" size="20" name="q" value="<?php echo Format::htmlchars($_REQUEST['q']); ?>"> + <input id="query" type="search" size="20" name="q" autofocus + value="<?php echo Format::htmlchars($_REQUEST['q']); ?>"> <select name="cid" id="cid"> <option value="">— <?php echo __('All Categories');?> —</option> <?php diff --git a/include/staff/filter.inc.php b/include/staff/filter.inc.php index 3c0f8f49a..144d0321a 100644 --- a/include/staff/filter.inc.php +++ b/include/staff/filter.inc.php @@ -42,7 +42,8 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info); <?php echo __('Filter Name');?>: </td> <td> - <input type="text" size="30" name="name" value="<?php echo $info['name']; ?>"> + <input type="text" size="30" name="name" value="<?php echo $info['name']; ?>" + autofocus> <span class="error">* <?php echo $errors['name']; ?></span> </td> </tr> diff --git a/include/staff/group.inc.php b/include/staff/group.inc.php index e64857da0..d13205385 100644 --- a/include/staff/group.inc.php +++ b/include/staff/group.inc.php @@ -54,7 +54,7 @@ $roles = Role::getActiveRoles(); <td width="180" class="required"><?php echo __('Name'); ?>:</td> <td> <input size="50" type="text" name="name" value="<?php echo $info['name']; ?>" - data-translate-tag="<?php echo $trans['name']; ?>"/> + autofocus data-translate-tag="<?php echo $trans['name']; ?>"/> <span class="error">* <?php echo $errors['name']; ?></span> </td> </tr> diff --git a/include/staff/helptopic.inc.php b/include/staff/helptopic.inc.php index cd0b54bdd..834cc5a72 100644 --- a/include/staff/helptopic.inc.php +++ b/include/staff/helptopic.inc.php @@ -54,7 +54,7 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info); </td> <td> <input type="text" size="30" name="topic" value="<?php echo $info['topic']; ?>" - data-translate-tag="<?php echo $trans['name']; ?>"/> + autofocus data-translate-tag="<?php echo $trans['name']; ?>"/> <span class="error">* <?php echo $errors['topic']; ?></span> <i class="help-tip icon-question-sign" href="#topic"></i> </td> </tr> diff --git a/include/staff/login.tpl.php b/include/staff/login.tpl.php index cbb5b5894..296b76af9 100644 --- a/include/staff/login.tpl.php +++ b/include/staff/login.tpl.php @@ -13,7 +13,9 @@ $info = ($_POST && $errors)?Format::htmlchars($_POST):array(); <?php csrf_token(); ?> <input type="hidden" name="do" value="scplogin"> <fieldset> - <input type="text" name="userid" id="name" value="<?php echo $info['userid']; ?>" placeholder="<?php echo __('Email or Username'); ?>" autocorrect="off" autocapitalize="off"> + <input type="text" name="userid" id="name" value="<?php + echo $info['userid']; ?>" placeholder="<?php echo __('Email or Username'); ?>" + autofocus autocorrect="off" autocapitalize="off"> <input type="password" name="passwd" id="pass" placeholder="<?php echo __('Password'); ?>" autocorrect="off" autocapitalize="off"> <?php if ($show_reset && $cfg->allowPasswordReset()) { ?> <h3 style="display:inline"><a href="pwreset.php"><?php echo __('Forgot my password'); ?></a></h3> diff --git a/include/staff/orgs.inc.php b/include/staff/orgs.inc.php index 84288aeda..bc41711ff 100644 --- a/include/staff/orgs.inc.php +++ b/include/staff/orgs.inc.php @@ -78,8 +78,9 @@ $_SESSION['orgs_qs_'.$qhash] = $query; <input type="hidden" name="a" value="search"> <table> <tr> - <td><input type="text" id="basic-org-search" name="query" size=30 value="<?php echo Format::htmlchars($_REQUEST['query']); ?>" - autocomplete="off" autocorrect="off" autocapitalize="off"></td> + <td><input type="search" id="basic-org-search" name="query" + autofocus size="30" value="<?php echo Format::htmlchars($_REQUEST['query']); ?>" + autocomplete="off" autocorrect="off" autocapitalize="off"></td> <td><input type="submit" name="basic_search" class="button" value="<?php echo __('Search'); ?>"></td> <!-- <td> <a href="" id="advanced-user-search">[advanced]</a></td> --> </tr> diff --git a/include/staff/page.inc.php b/include/staff/page.inc.php index 0a7359ae0..ae445a656 100644 --- a/include/staff/page.inc.php +++ b/include/staff/page.inc.php @@ -62,7 +62,7 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info); </td> <td> <input type="text" size="40" name="name" value="<?php echo $info['name']; ?>" - data-translate-tag="<?php echo $trans['name']; ?>"/> + autofocus data-translate-tag="<?php echo $trans['name']; ?>"/> <span class="error">* <?php echo $errors['name']; ?></span> </td> </tr> diff --git a/include/staff/role.inc.php b/include/staff/role.inc.php index e597c1f27..7730ea551 100644 --- a/include/staff/role.inc.php +++ b/include/staff/role.inc.php @@ -49,7 +49,8 @@ $info = Format::htmlchars(($errors && $_POST) ? array_merge($info, $_POST) : $in <td width="180" class="required"><?php echo __('Name'); ?>:</td> <td> <input size="50" type="text" name="name" value="<?php echo - $info['name']; ?>" data-translate-tag="<?php echo $trans['name']; ?>"/> + $info['name']; ?>" data-translate-tag="<?php echo $trans['name']; ?>" + autofocus/> <span class="error">* <?php echo $errors['name']; ?></span> </td> </tr> diff --git a/include/staff/slaplan.inc.php b/include/staff/slaplan.inc.php index 3ca424c30..484778e8b 100644 --- a/include/staff/slaplan.inc.php +++ b/include/staff/slaplan.inc.php @@ -42,7 +42,7 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info); </td> <td> <input type="text" size="30" name="name" value="<?php echo $info['name']; ?>" - data-translate-tag="<?php echo $trans['name']; ?>"/> + autofocus data-translate-tag="<?php echo $trans['name']; ?>"/> <span class="error">* <?php echo $errors['name']; ?></span> <i class="help-tip icon-question-sign" href="#name"></i> </td> </tr> diff --git a/include/staff/staff.inc.php b/include/staff/staff.inc.php index 728bb4b4f..b18b7cd77 100644 --- a/include/staff/staff.inc.php +++ b/include/staff/staff.inc.php @@ -50,7 +50,7 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info); </td> <td> <input type="text" size="30" class="staff-username typeahead" - name="username" value="<?php echo $info['username']; ?>"> + autofocus name="username" value="<?php echo $info['username']; ?>"> <span class="error">* <?php echo $errors['username']; ?></span> <i class="help-tip icon-question-sign" href="#username"></i> </td> </tr> diff --git a/include/staff/team.inc.php b/include/staff/team.inc.php index db47fa00e..937196672 100644 --- a/include/staff/team.inc.php +++ b/include/staff/team.inc.php @@ -58,7 +58,7 @@ $info = Format::htmlchars(($errors && $_POST) ? $_POST : $info); </td> <td> <input type="text" size="30" name="name" value="<?php echo $info['name']; ?>" - data-translate-tag="<?php echo $trans['name']; ?>"/> + autofocus data-translate-tag="<?php echo $trans['name']; ?>"/> <span class="error">* <?php echo $errors['name']; ?></span> </td> </tr> diff --git a/include/staff/templates/org-lookup.tmpl.php b/include/staff/templates/org-lookup.tmpl.php index 10a4ce28f..07620f2f6 100644 --- a/include/staff/templates/org-lookup.tmpl.php +++ b/include/staff/templates/org-lookup.tmpl.php @@ -17,7 +17,8 @@ if ($info['search'] === false) if ($info['search'] !== false) { ?> <div style="margin-bottom:10px;"> <input type="text" class="search-input" style="width:100%;" - placeholder="Search by name" id="org-search" autocorrect="off" autocomplete="off"/> + placeholder="Search by name" id="org-search" + autofocus autocorrect="off" autocomplete="off"/> </div> <?php } diff --git a/include/staff/templates/user-lookup.tmpl.php b/include/staff/templates/user-lookup.tmpl.php index 948026e8f..90dac1ab9 100644 --- a/include/staff/templates/user-lookup.tmpl.php +++ b/include/staff/templates/user-lookup.tmpl.php @@ -10,9 +10,9 @@ if (!isset($info['lookup']) || $info['lookup'] !== false) { ?> : __('Search existing users.'); ?></p></div> <div style="margin-bottom:10px;"> - <input type="text" class="search-input" style="width:100%;" + <input type="search" class="search-input" style="width:100%;" placeholder="<?php echo __('Search by email, phone or name'); ?>" id="user-search" - autocorrect="off" autocomplete="off"/> + autofocus autocorrect="off" autocomplete="off"/> </div> <?php } diff --git a/include/staff/tickets.inc.php b/include/staff/tickets.inc.php index 549784aef..1f1b078cf 100644 --- a/include/staff/tickets.inc.php +++ b/include/staff/tickets.inc.php @@ -311,9 +311,8 @@ return false;"> <input type="hidden" name="a" value="search"> <table> <tr> - <td><input type="text" id="basic-ticket-search" name="query" - size=30 value="<?php echo Format::htmlchars($_REQUEST['query'], - true); ?>" + <td><input type="search" id="basic-ticket-search" name="query" + autofocus size="30" value="<?php echo Format::htmlchars($_REQUEST['query'], true); ?>" autocomplete="off" autocorrect="off" autocapitalize="off"></td> <td><input type="submit" class="button" value="<?php echo __('Search'); ?>"></td> <td> <a href="#" onclick="javascript: diff --git a/include/staff/users.inc.php b/include/staff/users.inc.php index 848abf4dc..7e4993ad4 100644 --- a/include/staff/users.inc.php +++ b/include/staff/users.inc.php @@ -63,8 +63,9 @@ $users->order_by($order . $order_column); <input type="hidden" name="a" value="search"> <table> <tr> - <td><input type="text" id="basic-user-search" name="query" size=30 value="<?php echo Format::htmlchars($_REQUEST['query']); ?>" - autocomplete="off" autocorrect="off" autocapitalize="off"></td> + <td><input type="search" id="basic-user-search" name="query" + autofocus size="30" value="<?php echo Format::htmlchars($_REQUEST['query']); ?>" + autocomplete="off" autocorrect="off" autocapitalize="off"></td> <td><input type="submit" name="basic_search" class="button" value="<?php echo __('Search'); ?>"></td> <!-- <td> <a href="" id="advanced-user-search">[advanced]</a></td> --> </tr> diff --git a/scp/css/scp.css b/scp/css/scp.css index dea3f1913..2b6701e9c 100644 --- a/scp/css/scp.css +++ b/scp/css/scp.css @@ -613,6 +613,10 @@ a.print { height:25px; } +input[type=search] { + font-size: 16px; +} +.search input[type=search], .search input[type=text] { height:23px; line-height:23px; diff --git a/scp/emailtest.php b/scp/emailtest.php index 9e15baf36..cd9fbae9d 100644 --- a/scp/emailtest.php +++ b/scp/emailtest.php @@ -99,7 +99,8 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info); <?php echo __('To');?>: </td> <td> - <input type="text" size="60" name="email" value="<?php echo $info['email']; ?>"> + <input type="text" size="60" name="email" value="<?php echo $info['email']; ?>" + autofocus> <span class="error">* <?php echo $errors['email']; ?></span> </td> </tr> diff --git a/scp/js/scp.js b/scp/js/scp.js index ee0a23306..e8a9443af 100644 --- a/scp/js/scp.js +++ b/scp/js/scp.js @@ -37,7 +37,10 @@ function checkbox_checker(formObj, min, max) { var scp_prep = function() { - $("input:not(.dp):visible:enabled:first").focus(); + $("input[autofocus]:visible:enabled:first").each(function() { + if ($(this).val()) + $(this).blur(); + }); $('table.list input:checkbox').bind('click, change', function() { $(this) .parents("tr:first") -- GitLab