-
Notifications
You must be signed in to change notification settings - Fork 301
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #542 from Martii/Issue-531jQueryTopPagination
Use jQuery to show top pagination on scroll down then scroll up Auto-merge
- Loading branch information
Showing
15 changed files
with
129 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,73 @@ | ||
<script type="text/javascript"> | ||
// Show spacer div | ||
$('#reply-control').on('shown.bs.collapse', function () { | ||
$('#show-reply-form-when-visible').css({ | ||
height: '210px' | ||
(function () { | ||
// Show spacer div | ||
$('#reply-control').on('show.bs.collapse', function () { | ||
$('#show-reply-form-when-visible').css({ | ||
height: '210px' | ||
}); | ||
}); | ||
}); | ||
|
||
// Hide spacer div | ||
$('#reply-control').on('hidden.bs.collapse', function () { | ||
$('#show-reply-form-when-visible').css({ | ||
height: '0' | ||
// Hide spacer div | ||
$('#reply-control').on('hide.bs.collapse', function () { | ||
$('#show-reply-form-when-visible').css({ | ||
height: '0' | ||
}); | ||
}); | ||
}); | ||
|
||
$('.btn-comment-reply').click(function (aE) { | ||
$('#reply-control').collapse('show'); | ||
$('.btn-comment-reply').click(function (aE) { | ||
$('#reply-control').collapse('show'); | ||
|
||
var $comment = $(aE.target).closest('.topic-post'); | ||
var $author = $comment.find('.topic-meta-data .names .username').first(); | ||
var $replyTextarea = $('#reply-control textarea[name="comment-content"]'); | ||
var $comment = $(aE.target).closest('.topic-post'); | ||
var $author = $comment.find('.topic-meta-data .names .username').first(); | ||
var $replyTextarea = $('#reply-control textarea[name="comment-content"]'); | ||
|
||
document.location.hash = $comment.attr('id'); | ||
document.location.hash = $comment.attr('id'); | ||
|
||
var text = $replyTextarea.text(); | ||
if (!/^\s*$/.test(text)) { | ||
text += '\n\n'; // Add linebreak if reply already started. | ||
} | ||
text += '[Re](' + document.location.href.replace(/\(/g, '%28').replace(/\)/g, '%29') + '): '; | ||
text += '[@' + $author.text() + '](' + $author.attr('href') + '): '; | ||
text += ' \n'; | ||
$replyTextarea.text(text); | ||
}); | ||
var text = $replyTextarea.text(); | ||
if (!/^\s*$/.test(text)) { | ||
text += '\n\n'; // Add linebreak if reply already started. | ||
} | ||
text += '[Re](' + document.location.href.replace(/\(/g, '%28').replace(/\)/g, '%29') + '): '; | ||
text += '[@' + $author.text() + '](' + $author.attr('href') + '): '; | ||
text += ' \n'; | ||
$replyTextarea.text(text); | ||
}); | ||
|
||
function isElementInViewport(aEl) { | ||
// special bonus for those using jQuery | ||
if (aEl instanceof jQuery) { | ||
aEl = aEl[0]; | ||
} | ||
function isElementInViewport(aEl) { | ||
if (aEl instanceof jQuery) { | ||
aEl = aEl[0]; | ||
} | ||
|
||
var rect = aEl.getBoundingClientRect(); | ||
var rect = aEl.getBoundingClientRect(); | ||
|
||
return ( | ||
rect.top >= 0 && | ||
rect.left >= 0 && | ||
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /*or $(window).height() */ | ||
rect.right <= (window.innerWidth || document.documentElement.clientWidth) /*or $(window).width() */ | ||
); | ||
} | ||
return ( | ||
rect.top >= 0 && | ||
rect.left >= 0 && | ||
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /*or $(window).height() */ | ||
rect.right <= (window.innerWidth || document.documentElement.clientWidth) /*or $(window).width() */ | ||
); | ||
} | ||
|
||
var hasShownReplyForm = false; | ||
function callback(aEl) { | ||
if (!hasShownReplyForm) { | ||
$('#reply-control').collapse('show'); | ||
hasShownReplyForm = true; | ||
var hasShownReplyForm = false; | ||
function callback(aEl) { | ||
if (!hasShownReplyForm) { | ||
$('#reply-control').collapse('show'); | ||
hasShownReplyForm = true; | ||
} | ||
} | ||
} | ||
|
||
function fireIfElementVisible(aEl, aCallback) { | ||
return function () { | ||
if ( isElementInViewport(aEl) ) { | ||
aCallback(aEl); | ||
function fireIfElementVisible(aEl, aCallback) { | ||
return function () { | ||
if (isElementInViewport(aEl)) { | ||
aCallback(aEl); | ||
} | ||
} | ||
} | ||
} | ||
|
||
var handler = fireIfElementVisible ($('#show-reply-form-when-visible'), callback); | ||
var handler = fireIfElementVisible($('#show-reply-form-when-visible'), callback); | ||
|
||
// jQuery | ||
$(window).on('DOMContentLoaded load resize scroll', handler); | ||
// jQuery | ||
$(window).on('DOMContentLoaded load resize scroll', handler); | ||
|
||
})(); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<script type="text/javascript"> | ||
(function () { | ||
function isElementInViewport(aEl) { | ||
if (aEl instanceof jQuery) { | ||
aEl = aEl[0]; | ||
} | ||
|
||
var rect = aEl.getBoundingClientRect(); | ||
|
||
return ( | ||
rect.top >= 0 && | ||
rect.left >= 0 && | ||
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /*or $(window).height() */ | ||
rect.right <= (window.innerWidth || document.documentElement.clientWidth) /*or $(window).width() */ | ||
); | ||
} | ||
|
||
var hasShownPagination = false; | ||
function callback(aEl) { | ||
if (!hasShownPagination) { | ||
aEl.collapse('show'); | ||
hasShownPagination = true; | ||
} | ||
} | ||
|
||
var lastScrollTop = 0; | ||
var hasScrolledDown = false; | ||
|
||
function fireIfElementVisible(aEl, aCallback) { | ||
return function () { | ||
var scrollTop = $(document).scrollTop(); | ||
|
||
if (scrollTop > lastScrollTop) { | ||
hasScrolledDown = true; | ||
} else { | ||
if (isElementInViewport(aEl) && hasScrolledDown) { | ||
aCallback(aEl); | ||
} | ||
} | ||
lastScrollTop = scrollTop; | ||
} | ||
} | ||
|
||
var handler = fireIfElementVisible($('.pagination:first').parent(), callback); | ||
|
||
// jQuery | ||
$(window).on('scroll', handler); | ||
|
||
})(); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters