|
Cookbook /
PositioningCursorInEditFormSummary: How to position the cursor at the end in the edit form
Version: 2006-08-30
Prerequisites: pmwiki 2.1, javascript support
Status:
Maintainer:
Categories: Editing
Questions answered by this recipeHow can I position the cursor at the end in the edit form? How can I open the edit window and the cursor will be at the end of the text? Shorter wayFor PmWiki versions 2.2.0-beta54 and newer, edit the wiki page Site.EditForm. Change: (:input e_textarea:) to: (:input e_textarea focus=1:) --Petko Alternative wayThe code snippet below is a redefinition of It works in Firefox and IE6, please report performance for other browsers. If you want the cursor always to jump to the end of text when editing, remove both "if" lines at the top, and the } bracket at the end. Then it is triggerd with every To make this into a one-click action link, insert a link similar to the edit link into PageActions or your page action menus, like Add to config.php: # jump to end of edit textarea when ?action=edit&cursor=end
if (isset($_GET['cursor'])) $cs = $_GET['cursor'];
if($cs=='end') {
XLSDV('en', array(
'ak_save' => 's',
'ak_saveedit' => 'u',
'ak_preview' => 'p',
'ak_textedit' => 'e',
'e_rows' => '23',
'e_cols' => '60'));
$InputTags['e_textarea'] = array(
':html' => "
<textarea \$InputFormArgs
onkeydown='if (event.keyCode==27) event.returnValue=false;'
>\$EditText</textarea>
<script language='javascript' type='text/javascript'><!--
el = document.getElementById('text');
ln = el.value.length;
try { el.focus(); }
catch(e) { el.focus(); }
el.scrollTop = el.scrollHeight;
if (el.createTextRange) {
var rg = el.createTextRange();
rg.collapse(true);
rg.moveEnd('character',ln);
rg.moveStart('character',ln);
rg.select();
}
--></script>
",
'name' => 'text', 'id' => 'text', 'accesskey' => XL('ak_textedit'),
'rows' => XL('e_rows'), 'cols' => XL('e_cols'));
}
NotesRelease Notes
CommentsSee AlsoContributors |