https://www.mediawiki.org/wiki/Special:Code/MediaWiki/115010

Revision: 115010
Author:   tstarling
Date:     2012-04-23 04:09:47 +0000 (Mon, 23 Apr 2012)
Log Message:
-----------
Allow links to specific lines of code using a special fragment syntax

Modified Paths:
--------------
    trunk/extensions/CodeEditor/modules/ext.codeEditor.js
    trunk/extensions/CodeEditor/modules/jquery.codeEditor.js

Modified: trunk/extensions/CodeEditor/modules/ext.codeEditor.js
===================================================================
--- trunk/extensions/CodeEditor/modules/ext.codeEditor.js       2012-04-22 
21:38:17 UTC (rev 115009)
+++ trunk/extensions/CodeEditor/modules/ext.codeEditor.js       2012-04-23 
04:09:47 UTC (rev 115010)
@@ -40,4 +40,7 @@
 $( document ).ready( function() {
        // Add code editor module
        $( '#wpTextbox1' ).wikiEditor( 'addModule', 'codeEditor' );
+
+       // If there is a fragment giving a line number, scroll to the relevant 
location
+       $( '#wpTextbox1' 
).data('wikiEditor-context').fn.codeEditorMonitorFragment();
 } );

Modified: trunk/extensions/CodeEditor/modules/jquery.codeEditor.js
===================================================================
--- trunk/extensions/CodeEditor/modules/jquery.codeEditor.js    2012-04-22 
21:38:17 UTC (rev 115009)
+++ trunk/extensions/CodeEditor/modules/jquery.codeEditor.js    2012-04-23 
04:09:47 UTC (rev 115010)
@@ -211,7 +211,28 @@
                context.$textarea.show();
 
                // @todo restore cursor, scroll position
+       },
+
+       /**
+        * Start monitoring the fragment of the current window for hash change 
+        * events. If the hash is already set, handle it as a new event.
+        */
+       'codeEditorMonitorFragment': function() {
+               function onHashChange() {
+                       var regexp = /#mw-ce-l(\d+)/;
+                       var result = regexp.exec( window.location.hash );
+                       if ( result === null ) {
+                               return;
+                       }
+
+                       // Line numbers in CodeEditor are zero-based
+                       var line = parseInt( result[1] );
+                       context.codeEditor.navigateTo( line - 1, 0 );
+               }
+               onHashChange();
+               $( window ).bind( 'hashchange', onHashChange );
        }
+
 });
 
 /**


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to