|
Cookbook /
RememberEditPositionSummary: Return the editing textarea to the previous position when previewing a page
Version: 2009-01-20
Prerequisites: 2.1.27
Status: beta
Maintainer: Eemeli Aro
Categories: Editing
Questions answered by this recipeQuoting JL in PITS:01019: During edition of a pmwiki page, we use the preview button, and the page is reloaded with the preview. Then the scrollbar of the textarea is set at the top and we scroll to return at the point of the last modification. Could you store the scrollbar position [...] to restore it on the load of edit/preview?
DescriptionReturn the editing textarea to the previous position when previewing a page. To implement
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>";
}
NotesAs 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
Contributors
CommentsThis 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 FixFlowSkin uses 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. User notes +2: 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. |