diff options
author | Bernhard Posselt <nukeawhale@gmail.com> | 2012-09-03 00:25:51 +0200 |
---|---|---|
committer | Bernhard Posselt <nukeawhale@gmail.com> | 2012-09-03 00:26:04 +0200 |
commit | 144da1ca88f905910b9be63b8710ccab16a04df2 (patch) | |
tree | 9eea83286422533b2eb3a855cadd4363ab4c42a5 | |
parent | f8ce1854ba4678c001cb317329bde46008dcd1ea (diff) |
j jumps to next entry, k to previous if no dialog is open
-rw-r--r-- | js/items.js | 50 | ||||
-rw-r--r-- | js/main.js | 10 | ||||
-rw-r--r-- | templates/part.dialogues.php | 6 |
3 files changed, 62 insertions, 4 deletions
diff --git a/js/items.js b/js/items.js index 87f79ae0b..146f70a01 100644 --- a/js/items.js +++ b/js/items.js @@ -106,6 +106,56 @@ var t = t || function(app, string){ return string; }; // mock translation for lo }; /** + * Jumps to the next visible element + */ + Items.prototype.jumpToNext = function() { + var self = this; + var notJumped = true; + $('.feed_item').each(function(){ + if(notJumped && $(this).position().top > 1){ + console.log(this); + self._jumpToElemenId($(this).data('id')); + notJumped = false; + } + }); + }; + + /** + * Jumps to the previous visible element + */ + Items.prototype.jumpToPrevious = function() { + var self = this; + var notJumped = true; + $('.feed_item').each(function(){ + if(notJumped && $(this).position().top >= 0){ + var previous = $(this).prev(); + if(previous.length > 0){ + self._jumpToElemenId(previous.data('id')); + } + notJumped = false; + } + }); + }; + + /** + * Jump to the next element in the list + * @param $elem the jquery elem to which we want to jump + */ + Items.prototype._getNextJump = function($elem){ + return $elem.position().top > 1; + } + + /** + * Jumps to an element in the article list + * @param number the number of the item starting with 0 + */ + Items.prototype._jumpToElemenId = function(id) { + this._$articleList.scrollTop( + $('.feed_item[data-id=' + id + ']').offset().top - + this._$articleList.offset().top + this._$articleList.scrollTop()); + }; + + /** * Empties the item cache */ Items.prototype.emptyItemCache = function() { diff --git a/js/main.js b/js/main.js index f219448de..ef97cd925 100644 --- a/js/main.js +++ b/js/main.js @@ -129,9 +129,17 @@ $(document).ready(function(){ $(document).keydown(function(e) { if ((e.keyCode || e.which) == 74) { // 'j' key shortcut - + if(!$('.dialog').is(':visible')){ + News.Objects.Items.jumpToNext(); + } + } + if ((e.keyCode || e.which) == 75) { // 'k' key shortcut + if(!$('.dialog').is(':visible')){ + News.Objects.Items.jumpToPrevious(); + } } }); + }); diff --git a/templates/part.dialogues.php b/templates/part.dialogues.php index 114cbcfb5..46fbbb312 100644 --- a/templates/part.dialogues.php +++ b/templates/part.dialogues.php @@ -1,4 +1,4 @@ -<div id="addfolder_dialog" title="<?php echo $l->t('Add Folder'); ?>"> +<div id="addfolder_dialog" title="<?php echo $l->t('Add Folder'); ?>" class="dialog"> <table> <tr> <td><?php echo $l->t('Add new folder'); ?></td> @@ -11,7 +11,7 @@ </table> </div> -<div id="addfeed_dialog" title="<?php echo $l->t('Add Subscription'); ?>"> +<div id="addfeed_dialog" title="<?php echo $l->t('Add Subscription'); ?>" class="dialog"> <table> <tr> <td><?php echo $l->t('Add new feed'); ?></td> @@ -31,7 +31,7 @@ </table> </div> -<div id="changefolder_dialog" title="<?php echo $l->t('Change folder name'); ?>"> +<div id="changefolder_dialog" title="<?php echo $l->t('Change folder name'); ?>" class="dialog"> <input class="inputfolderid" type="hidden" name="folderid" value="" /> <table> <tr> |