-
Notifications
You must be signed in to change notification settings - Fork 9
/
shine-shortcuts.js
84 lines (71 loc) · 2.24 KB
/
shine-shortcuts.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
var isCommentPage = ($("body").hasClass("comments-page") ? true : false);
if(isCommentPage == true) {
if (commentNumber == undefined) {
var commentNumber = -1;
}
$("body").find('.commentarea > .sitetable > .comment').each(function(i) {
$(this).addClass('comment-' + i);
});
}
$.fn.scrollParent = function() {
var position = this.css( "position" ),
excludeStaticParent = position === "absolute",
scrollParent = this.parents().filter( function() {
var parent = $( this );
if ( excludeStaticParent && parent.css( "position" ) === "static" ) {
return false;
}
return (/(auto|scroll)/).test( parent.css( "overflow" ) + parent.css( "overflow-y" ) + parent.css( "overflow-x" ) );
}).eq( 0 );
return position === "fixed" || !scrollParent.length ? $( this[ 0 ].ownerDocument || document ) : scrollParent;
};
$.fn.scrollTo = function(t) {
var fromTop = (isCommentPage === false ? $('.comment-'+t).offset().top - $(this).offset().top + $(this).scrollTop() : $('.comment-'+t).offset().top - $('#header').height()) - 10;
this.animate({ scrollTop: fromTop }, 200);
};
function commentScroller (direction) {
var nextNumber;
if (direction == 'prev') {
nextNumber = commentNumber-1;
if($('.comment-'+ nextNumber).length){
commentNumber--;
}
} else {
nextNumber = commentNumber+1;
if($('.comment-'+ nextNumber).length){
commentNumber++;
}
}
isCommentPage === false ? $('.comment').scrollParent().scrollTo(commentNumber) : $('html, body').scrollTo(commentNumber);
}
if ($('html').hasClass('show-comment-navigation')){
var checkExist = setInterval(function() {
if($(".comment").length) {
$('.shine-nav-comment').addClass('visible');
} else {
$('.shine-nav-comment').removeClass('visible');
}
}, 100);
}
$('body').on('click','.shine-comment-next', function(){
commentScroller('next');
});
$('body').on('click','.shine-comment-prev', function(){
commentScroller('prev');
});
// KEY SHORTCUTS
$('body').keyup(function (e) {
if (e.target.nodeName.toLowerCase() !== 'input' && e.target.nodeName.toLowerCase() !== 'textarea') {
switch( e.keyCode ) {
case 27:
resetInterfaces();
break;
case 39:
commentScroller('next');
break;
case 37:
commentScroller('prev');
break;
}
}
});