Werdna has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/91348


Change subject: Add basic experimental hotkey navigation.
......................................................................

Add basic experimental hotkey navigation.

Change-Id: Ie89cf8c81ac5209dd3d90fe301d31a1f6677ef40
---
A .gitmodules
M Resources.php
A modules/discussion/hotkeys.js
M modules/discussion/styles/post.less
A modules/jquery.hotkeys
5 files changed, 70 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Flow 
refs/changes/48/91348/1

diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 0000000..4e9f98f
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,3 @@
+[submodule "modules/jquery.hotkeys"]
+       path = modules/jquery.hotkeys
+       url = https://github.com/jeresig/jquery.hotkeys.git
diff --git a/Resources.php b/Resources.php
index 59b7759..c6a313a 100644
--- a/Resources.php
+++ b/Resources.php
@@ -53,11 +53,13 @@
                        'discussion/forms.js',
                        'discussion/paging.js',
                        'discussion/init.js',
+                       'discussion/hotkeys.js',
                ),
                'dependencies' => array(
                        'jquery.ui.core',
                        'ext.flow.base',
                        'ext.flow.editor',
+                       'jquery.hotkeys',
                ),
                'messages' => array(
                        'flow-newtopic-start-placeholder',
@@ -107,4 +109,7 @@
                        'ext.flow.base',
                )
        ),
+       'jquery.hotkeys' => $flowResourceTemplate + array(
+               'scripts' => 'jquery.hotkeys/jquery.hotkeys.js',
+       ),
 );
diff --git a/modules/discussion/hotkeys.js b/modules/discussion/hotkeys.js
new file mode 100644
index 0000000..b0794d0
--- /dev/null
+++ b/modules/discussion/hotkeys.js
@@ -0,0 +1,58 @@
+( function( $, mw ) {
+$( function() {
+       /**
+        * Creates an event handler
+        * @param  {Function} callback Function that takes the currently
+        * highlighted element as a parameter and returns the next element to
+        * highlight.
+        * @return {Function}          Event handler
+        */
+       var createNavigationHandler = function( callback ) {
+               return function(e) {
+                       var $current = $( '.flow-post-highlighted' );
+                       var $next;
+
+                       if ( $current.length === 0 ) {
+                               $next = $( '.flow-post-container:first' );
+                       } else {
+                               $next = callback( $current );
+                       }
+
+                       $current.removeClass( 'flow-post-highlighted' );
+
+                       if ( ! $next.length ) {
+                               console.log( "No next element" );
+                               return;
+                       }
+
+                       $next.addClass( 'flow-post-highlighted' );
+
+                       $viewport = $( 'main, html' );
+                       $(window).scrollTop( $next.position().top - ( 
$viewport.height() / 2 ) );
+                       window.location.hash = '#' + $next.find( '.flow-post' 
).attr( 'id' );
+               };
+       };
+
+       $( document ).bind( 'keypress', 'j', createNavigationHandler( function( 
$cur ) {
+               var $allPosts = $( '.flow-post-container' );
+               var index = $allPosts.index( $cur );
+
+               if ( index + 1 >= $allPosts.length ) {
+                       return $cur;
+               }
+
+               return $( $allPosts.get( index + 1 ) );
+       } ) );
+
+       $( document ).bind( 'keypress', 'k', createNavigationHandler( function( 
$cur ) {
+               var $allPosts = $( '.flow-post-container' );
+               var index = $allPosts.index( $cur );
+
+               if ( index - 1 < 0 ) {
+                       return $cur;
+               }
+
+               return $( $allPosts.get( index - 1 ) );
+       } ) );
+} );
+} )( jQuery, mediaWiki );
\ No newline at end of file
diff --git a/modules/discussion/styles/post.less 
b/modules/discussion/styles/post.less
index d8fc7ea..a8bfcdc 100644
--- a/modules/discussion/styles/post.less
+++ b/modules/discussion/styles/post.less
@@ -323,9 +323,11 @@
                }
        }
 
-       border-left: 6px solid transparent;
+       .flow-post {
+               border-left: 6px solid transparent;
+       }
 
-       &.flow-post-highlighted {
+       &.flow-post-highlighted > .flow-post {
                border-left: 6px solid #00AF89
        }
 }
diff --git a/modules/jquery.hotkeys b/modules/jquery.hotkeys
new file mode 160000
index 0000000..7dfe654
--- /dev/null
+++ b/modules/jquery.hotkeys
+Subproject commit 7dfe654038e3606fefe17650fde7be3b06e428c8

-- 
To view, visit https://gerrit.wikimedia.org/r/91348
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie89cf8c81ac5209dd3d90fe301d31a1f6677ef40
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: master
Gerrit-Owner: Werdna <[email protected]>

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

Reply via email to