(*fanfare*) added scripting to save the position of the edit box scrollbar on preview
authorTom Gilder <tomgilder@users.mediawiki.org>
Wed, 26 Oct 2005 10:59:44 +0000 (10:59 +0000)
committerTom Gilder <tomgilder@users.mediawiki.org>
Wed, 26 Oct 2005 10:59:44 +0000 (10:59 +0000)
includes/EditPage.php
skins/common/wikibits.js

index 8e22eb0..f873041 100644 (file)
@@ -318,6 +318,9 @@ class EditPage {
 
                        $this->edittime = $request->getVal( 'wpEdittime' );
                        $this->starttime = $request->getVal( 'wpStarttime' );
+
+                       $this->scrolltop = htmlentities( $request->getVal( 'wpScrolltop' ) );
+
                        if( is_null( $this->edittime ) ) {
                                # If the form is incomplete, force to preview.
                                wfDebug( "$fname: Form data appears to be incomplete\n" );
@@ -844,7 +847,7 @@ END
                $wgOut->addHTML( <<<END
 $recreate
 {$commentsubject}
-<textarea tabindex='1' accesskey="," name="wpTextbox1" rows='{$rows}'
+<textarea tabindex='1' accesskey="," name="wpTextbox1" id="wpTextbox1" rows='{$rows}'
 cols='{$cols}'{$ew} $hidden>
 END
 . htmlspecialchars( $this->safeUnicodeOutput( $this->textbox1 ) ) .
@@ -870,7 +873,8 @@ END
                $wgOut->addHTML( "
 <input type='hidden' value=\"" . htmlspecialchars( $this->section ) . "\" name=\"wpSection\" />
 <input type='hidden' value=\"{$this->starttime}\" name=\"wpStarttime\" />\n
-<input type='hidden' value=\"{$this->edittime}\" name=\"wpEdittime\" />\n" );
+<input type='hidden' value=\"{$this->edittime}\" name=\"wpEdittime\" />\n
+<input type='hidden' value=\"{$this->scrolltop}\" name=\"wpScrolltop\" id=\"wpScrolltop\" />\n" );
 
                if ( $wgUser->isLoggedIn() ) {
                        /**
index 32194ed..4bb674b 100644 (file)
@@ -32,6 +32,7 @@ function runOnloadHook()
     unhidetzbutton();
     tabbedprefs();
     akeytt();
+    scrollEditBox();
 
     // Run any added-on functions
     for ( var i = 0; i < onloadFuncts.length; i++ )
@@ -491,3 +492,20 @@ function considerChangingExpiryFocus() {
        else
                field.style.display = 'none';
 }
+
+function scrollEditBox() {
+
+  var editBoxEl = document.getElementById("wpTextbox1");
+  var scrollTopEl = document.getElementById("wpScrolltop");
+  var editFormEl = document.getElementById("editform");
+
+  if ( editBoxEl && scrollTopEl ) {
+
+    if (scrollTopEl.value) editBoxEl.scrollTop = scrollTopEl.value;
+    editFormEl.onsubmit = function() {
+      document.getElementById("wpScrolltop").value = document.getElementById("wpTextbox1").scrollTop;
+    }
+  }
+}
+
+hookEvent( "load", scrollEditBox );
\ No newline at end of file