Created autofocus method to give focus to an element (primarily a form

control) on page onload.

Updated some of the pages to use autofocus.
This commit is contained in:
Sarven Capadisli 2009-09-03 19:42:50 +00:00
parent 0c95734a68
commit 277b464054
19 changed files with 125 additions and 0 deletions

View File

@ -399,5 +399,7 @@ class AvatarsettingsAction extends AccountSettingsAction
$this->script('js/jcrop/jquery.Jcrop.min.js');
$this->script('js/jcrop/jquery.Jcrop.go.js');
}
$this->autofocus('avatarfile');
}
}

View File

@ -160,6 +160,12 @@ class EditgroupAction extends GroupDesignAction
}
}
function showScripts()
{
parent::showScripts();
$this->autofocus('nickname');
}
function trySave()
{
$cur = common_current_user();

View File

@ -71,6 +71,12 @@ class EmailsettingsAction extends AccountSettingsAction
return _('Manage how you get email from %%site.name%%.');
}
function showScripts()
{
parent::showScripts();
$this->autofocus('email');
}
/**
* Content area of the page
*

View File

@ -445,6 +445,8 @@ class GrouplogoAction extends GroupDesignAction
$this->script('js/jcrop/jquery.Jcrop.min.js');
$this->script('js/jcrop/jquery.Jcrop.go.js');
}
$this->autofocus('avatarfile');
}
function showLocalNav()

View File

@ -91,6 +91,12 @@ class GroupsearchAction extends SearchAction
$user_group->free();
}
}
function showScripts()
{
parent::showScripts();
$this->autofocus('q');
}
}
class GroupSearchResults extends GroupList

View File

@ -98,6 +98,12 @@ class InviteAction extends CurrentUserDesignAction
$this->showPage();
}
function showScripts()
{
parent::showScripts();
$this->autofocus('addresses');
}
function title()
{
if ($this->mode == 'sent') {

View File

@ -22,6 +22,7 @@
* @category Login
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @author Sarven Capadisli <csarven@status.net>
* @copyright 2008-2009 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
@ -37,6 +38,7 @@ if (!defined('STATUSNET') && !defined('LACONICA')) {
* @category Personal
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @author Sarven Capadisli <csarven@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
*/
@ -162,6 +164,12 @@ class LoginAction extends Action
$this->showPage();
}
function showScripts()
{
parent::showScripts();
$this->autofocus('nickname');
}
/**
* Title of the page
*

View File

@ -137,6 +137,12 @@ class NoticesearchAction extends SearchAction
$this->pagination($page > 1, $cnt > NOTICES_PER_PAGE,
$page, 'noticesearch', array('q' => $q));
}
function showScripts()
{
parent::showScripts();
$this->autofocus('q');
}
}
class SearchNoticeList extends NoticeList {

View File

@ -86,6 +86,12 @@ class OpenidloginAction extends Action
}
}
function showScripts()
{
parent::showScripts();
$this->autofocus('openid_url');
}
function title()
{
return _('OpenID Login');

View File

@ -72,6 +72,12 @@ class OpenidsettingsAction extends AccountSettingsAction
' Manage your associated OpenIDs from here.');
}
function showScripts()
{
parent::showScripts();
$this->autofocus('openid_url');
}
/**
* Show the form for OpenID management
*

View File

@ -71,6 +71,12 @@ class OthersettingsAction extends AccountSettingsAction
return _('Manage various other options.');
}
function showScripts()
{
parent::showScripts();
$this->autofocus('urlshorteningservice');
}
/**
* Content area of the page
*

View File

@ -69,6 +69,12 @@ class PasswordsettingsAction extends AccountSettingsAction
return _('Change your password.');
}
function showScripts()
{
parent::showScripts();
$this->autofocus('oldpassword');
}
/**
* Content area of the page
*

View File

@ -85,6 +85,12 @@ class PeoplesearchAction extends SearchAction
$profile->free();
}
}
function showScripts()
{
parent::showScripts();
$this->autofocus('q');
}
}
/**

View File

@ -23,6 +23,7 @@
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @author Zach Copley <zach@status.net>
* @author Sarven Capadisli <csarven@status.net>
* @copyright 2008-2009 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
@ -41,6 +42,7 @@ require_once INSTALLDIR.'/lib/accountsettingsaction.php';
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @author Zach Copley <zach@status.net>
* @author Sarven Capadisli <csarven@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
*/
@ -70,6 +72,12 @@ class ProfilesettingsAction extends AccountSettingsAction
'so people know more about you.');
}
function showScripts()
{
parent::showScripts();
$this->autofocus('nickname');
}
/**
* Content area of the page
*

View File

@ -140,6 +140,12 @@ class RegisterAction extends Action
}
}
function showScripts()
{
parent::showScripts();
$this->autofocus('nickname');
}
/**
* Try to register a user
*

View File

@ -69,6 +69,12 @@ class SmssettingsAction extends ConnectSettingsAction
return _('You can receive SMS messages through email from %%site.name%%.');
}
function showScripts()
{
parent::showScripts();
$this->autofocus('sms');
}
/**
* Content area of the page
*

View File

@ -107,6 +107,12 @@ class SubscriptionsAction extends GalleryAction
array('nickname' => $this->user->nickname));
}
function showScripts()
{
parent::showScripts();
$this->autofocus('tag');
}
function showEmptyListMessage()
{
if (common_logged_in()) {

View File

@ -327,6 +327,8 @@ class DesignSettingsAction extends AccountSettingsAction
$this->script('js/farbtastic/farbtastic.js');
$this->script('js/farbtastic/farbtastic.go.js');
$this->script('js/userdesign.go.js');
$this->autofocus('design_background-image_file');
}
/**

View File

@ -412,4 +412,29 @@ class HTMLOutputter extends XMLOutputter
$this->element('p', 'form_guide', $instructions);
}
}
/**
* Internal script to autofocus the given element on page onload.
*
* @param string $id element ID, must refer to an existing element
*
* @return void
*
*/
function autofocus($id)
{
$this->elementStart('script', array('type' => 'text/javascript'));
$this->raw('
<!--
$(document).ready(function() {
var el = $("#' . $id . '");
if (el.length) {
el.focus();
}
});
-->
');
$this->elementEnd('script');
}
}