Refactor
← Older revision
Revision as of 09:26, December 15, 2012
Line 1:
Line 1:
−
$(function() {
+
// Eager load article comments.
−
+
importScriptPage('User:BryghtShadow/WikiaArticleComments.js', 'c');
−
//NO article comment on this page lets just skip
−
if( $('#WikiaArticleComments').length == 0 ) {
−
return true;
−
}
−
var content,
−
hash = window.location.hash,
−
//permalink = /^#comm-/.test(hash),
−
permalink = true,
−
// TODO: we should be able to load it this way
−
//styleAssets.push($.getAssetManagerGroupUrl('articlecomments' + (ArticleComments.miniEditorEnabled ? '_mini_editor' : '') + '_scss'));
−
styleAssets = [$.getSassCommonURL('skins/oasis/css/core/ArticleComments.scss')],
−
$comments = $('#WikiaArticleComments');
−
−
var belowTheFold = function() {
−
return $comments.offset().top >= ($window.scrollTop() + $window.height());
−
};
−
−
if (ArticleComments.miniEditorEnabled) {
−
styleAssets.push($.getSassCommonURL('extensions/wikia/MiniEditor/css/MiniEditor.scss'));
−
styleAssets.push($.getSassCommonURL('extensions/wikia/MiniEditor/css/ArticleComments/ArticleComments.scss'));
−
}
−
−
var loadAssets = function() {
−
$.when(
−
$.getResources(styleAssets),
−
$.nirvana.sendRequest({
−
controller: 'ArticleCommentsController',
−
method: 'Content',
−
format: 'html',
−
type: 'GET',
−
data: {
−
articleId: window.wgArticleId,
−
page: $comments.data('page'),
−
skin: true
−
},
−
callback: function(response) {
−
content = response;
−
}
−
})
−
).then(function() {
−
$comments.removeClass('loading').html(content);
−
−
ArticleComments.init();
−
−
if (permalink) {
−
ArticleComments.scrollToElement(hash);
−
}
−
});
−
};
−
−
// Load comments as they become visible (unless we are requesting a permalink comment)
−
if (!permalink && belowTheFold()) {
−
$window.on('scrollstop.ArticleCommentsLoadOnDemand', function(event) {
−
if (!belowTheFold()) {
−
$window.off('scrollstop.ArticleCommentsLoadOnDemand');
−
loadAssets();
−
}
−
});
−
−
// Comments are already visible, load them now
−
} else {
−
loadAssets();
−
}
−
});
/* Removes the unpatrolled exclamation mark from Special:RecentChanges.
/* Removes the unpatrolled exclamation mark from Special:RecentChanges.