Skip to content

Commit

Permalink
Add support for ctrl+enter to open a new tab, and open+arrow to fast …
Browse files Browse the repository at this point in the history
…scroll. Also fixed some edge case issues with the auto scroll when using arrow (improve #13)
  • Loading branch information
SBoudrias committed Feb 23, 2013
1 parent 0c3d0b3 commit c523c72
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 18 deletions.
3 changes: 3 additions & 0 deletions extension/app/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,13 @@ function( app, $, _, Backbone, settings, bookmarksCollection, AllBookmarksView,
// Listen click on a tags and open link in current Tab

$(document).on('click', 'a[href^=http]', function( e ) {
e.preventDefault();
var url = $(this).attr('href');
if( !e.ctrlKey ) {
chrome.tabs.update( null, { url: url });
window.close();
} else {
chrome.tabs.create({ url: url });
}
});
$(document).on('click', 'a[href^=javascript]', function( e ) {
Expand Down
43 changes: 25 additions & 18 deletions extension/app/views/all-bookmarks.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,53 +69,60 @@ function( app, $, _, Backbone, allBookmarks, BookmarkView, searchCriterias ) {
},

keyAction: function( e ) {
var ctrlKey = e.ctrlKey;
switch( e.keyCode ) {
case 38:
this.go('prev');
case 38: // up arrow
case 37: // left arrow
this.go('prev', e);
break;
case 40:
this.go('next');
case 40: // down arrow
case 39: // right arrow
this.go('next', e);
break;
case 37:
this.go('prev');
break;
case 39:
this.go('next');
break;
case 13:
case 13: // return|enter key
this.enterPress();
break;
}
},

go: function( dir ) {
go: function( dir, e ) {
var focus = this.$('.js-focus');

if( !focus.length ) {
this.$('.single-bookmark').first().addClass('js-focus');
return;
}

var next = focus[ dir ]('.single-bookmark');
if( !next.length ) { return; }
var method = (dir === 'next') ? 'nextAll': 'prevAll';
var skip = e.ctrlKey ? 4 : 0;
var next = focus[ method ]('.single-bookmark').eq(skip);
if( !next.length ) {
var def = (dir === 'next') ? 'last' : 'first';
next = this.$('.single-bookmark')[def]();
}

focus.removeClass('js-focus');
next.addClass('js-focus');
this.trigger('change:focus', next);
this.trigger('change:focus', dir, next);
},

enterPress: function() {
var focus = this.$('.js-focus');

if( !focus.length ) { return; }

focus.find('a').trigger('click');
focus.find('a').trigger(new $.Event('click', { ctrlKey: true }));
},

setScroll: function( focused ) {
setScroll: function( dir, focused ) {
var index = focused.index();

if( index <= 3 ) { return; }
if( index <= 3 ) {
if( dir === 'prev' ) {
this.$el.nanoScroller({ scroll: this.$('.single-bookmark').first() });
}
return;
}

var scrollTo = this.$('.single-bookmark').eq( index - 3 );
this.$el.nanoScroller({ scroll: scrollTo });
Expand Down

0 comments on commit c523c72

Please sign in to comment.