RememberEditPosition
Questions answered by this recipe
Note that the NotSavedWarning recipe includes a feature similar to this one.
Quoting JL in PITS:01019:
Description
Return the editing textarea to the previous position when previewing a page.
To implement
- Add the following to your config file:
if ( $action == 'edit' ) { $InputTags['e_scrolltop'][':html'] = "<input type='hidden' name='prev_scroll' id='prev_scroll' value='". intval(@$_POST['prev_scroll'])."'/>"; $HTMLHeaderFmt[] = "<script type='text/javascript'> function addEvent( obj, evt, fn ) { if (obj.addEventListener) obj.addEventListener( evt, fn, false ); else if (obj.attachEvent) obj.attachEvent( 'on'+evt, fn ); } var ps; addEvent( window, 'load', function() { ps = document.getElementById('prev_scroll'); if ( ps.value > 0 ) document.getElementById('text').scrollTop = ps.value; addEvent( ps.form, 'submit', function() { ps.value = ps.form.text.scrollTop; } ) } ); </script>"; }
- Add the directive
(:input e_scrolltop:)
just after(:input e_form:)
on your Site.EditForm page.
Notes
As this is mostly implemented using JavaScript, you may need to customise the script if you're already including a separate Javascript file and/or using a different event handler adder in your setup.
In quick testing, the script appears to work in everything from at least IE6 onwards.
See Also
- PITS.01019 Store the position of scrollbar of textarea when preview
- NotSavedWarning has a similar feature built-in. (Warn authors when they move away from a page without saving it; optionally request an edit summary or an author name)
Contributors
- Idea: JL
- Execution: Eemeli Aro
- Petko is the maintainer of this recipe.
Comments
This is cool...but does not seem to work in IE6 or FF3... I think I have installed as prescribed. I am using fixflow skin. When I edit a page, the var "ps" is always null and gives an error on the "if ( ps.value > 0 )" line. JJ? 08/03/2009
Site.Popup-EditForm
instead of Site.EditForm
so try adding (:input e_scrolltop:)
to that page. —Eemeli Aro August 04, 2009, at 06:44 PM
Nice, thank you! --SteP December 14, 2009
Does someone have this cookbook working with (vista+)IE8 (and how ?) ? I don't (though it's working with Vista+Google Chrome and with XP+IE6 and with XP+Opera 9.64). Thank you.
gb December 16, 2009, at 04:48 PM
User notes +3: If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.