No edit summary |
No edit summary |
||
Line 12: | Line 12: | ||
if (sidebar.size()) { |
if (sidebar.size()) { |
||
− | var listID = |
+ | var listID = topTenList.replace(/ /g,'_'); |
$('#WikiaRail').unbind('DOMNodeInserted'); |
$('#WikiaRail').unbind('DOMNodeInserted'); |
||
var comboString = '<div id="WikiaTopTenModule" class="WikiaTopTenModule module WikiaTopTenRightRail"><h1 class="header">'+ headerText +'</h1><div class="list" id='+ listID +'><div style="text-align:center;" class="loader"><img src="http://static.wikia.com/common/skins/common/images/ajax.gif" alt="Loading..." /></div></div></div>'; |
var comboString = '<div id="WikiaTopTenModule" class="WikiaTopTenModule module WikiaTopTenRightRail"><h1 class="header">'+ headerText +'</h1><div class="list" id='+ listID +'><div style="text-align:center;" class="loader"><img src="http://static.wikia.com/common/skins/common/images/ajax.gif" alt="Loading..." /></div></div></div>'; |
||
Line 50: | Line 50: | ||
var topTenList = $(this).attr('data-toptenlist'); |
var topTenList = $(this).attr('data-toptenlist'); |
||
− | var listID = |
+ | var listID = topTenList.replace(/ /g,'_'); |
var comboString = '<div id="WikiaTopTenModule" class="WikiaTopTenModule WikiaTopTenInArticle"><h1 class="header">'+ headerText +'</h1><div class="list" id='+ listID +'><div style="text-align:center;" class="loader"><img src="http://static.wikia.com/common/skins/common/images/ajax.gif" alt="Loading..." /></div></div></div>'; |
var comboString = '<div id="WikiaTopTenModule" class="WikiaTopTenModule WikiaTopTenInArticle"><h1 class="header">'+ headerText +'</h1><div class="list" id='+ listID +'><div style="text-align:center;" class="loader"><img src="http://static.wikia.com/common/skins/common/images/ajax.gif" alt="Loading..." /></div></div></div>'; |
||
$(this).append(comboString); |
$(this).append(comboString); |
Revision as of 18:41, 18 May 2014
/* Top Ten List module */
$(function() {
var addRightRailModule = true;
if (wgNamespaceNumber !== 700) {
if (addRightRailModule === true) {
// Add the module to the right rail
$('#WikiaRail').bind('DOMNodeInserted', function(event) {
var sidebar = $('#WikiaRecentActivity');
var headerText = 'Vote!';
var topTenList = 'Test List';
if (sidebar.size()) {
var listID = topTenList.replace(/ /g,'_');
$('#WikiaRail').unbind('DOMNodeInserted');
var comboString = '<div id="WikiaTopTenModule" class="WikiaTopTenModule module WikiaTopTenRightRail"><h1 class="header">'+ headerText +'</h1><div class="list" id='+ listID +'><div style="text-align:center;" class="loader"><img src="http://static.wikia.com/common/skins/common/images/ajax.gif" alt="Loading..." /></div></div></div>';
$(sidebar).before(comboString);
// Load the top 10 list and insert it into the module
$.getJSON(wgScript,{ 'action': 'ajax', 'rs': 'TopListHelper::checkListStatus', 'title': topTenList, 'cb' : Math.random() }, function(data, status, xhr) {
if (status === "error") {
$('.WikiaTopTenModule #'+ listID).text('An error occurred while loading the top 10 list.');
}
else {
var canVote = data.canVote;
$('.WikiaTopTenModule #'+ listID).load('/wiki/Top_10_list:'+ escape(topTenList) +'?action=render #toplists-list-body ul', function(data, status, xhr) {
if (status === "error" && xhr.status !== 404) {
$('.WikiaTopTenModule #'+ listID).text('An error occurred while loading the top 10 list.');
}
else if (xhr.status === 404) {
$('.WikiaTopTenModule #'+ listID).text('The top 10 list could not be found.');
}
else {
styleList(listID);
if (canVote !== true) {
$('.WikiaTopTenModule #'+ listID +' .VoteButton').remove();
}
}
});
}
});
}
});
}
// Add the module to the .Top10Module div's
$('.Top10Module').each(function() {
var that = this;
var headerText = $(this).attr('data-headertext');
var topTenList = $(this).attr('data-toptenlist');
var listID = topTenList.replace(/ /g,'_');
var comboString = '<div id="WikiaTopTenModule" class="WikiaTopTenModule WikiaTopTenInArticle"><h1 class="header">'+ headerText +'</h1><div class="list" id='+ listID +'><div style="text-align:center;" class="loader"><img src="http://static.wikia.com/common/skins/common/images/ajax.gif" alt="Loading..." /></div></div></div>';
$(this).append(comboString);
$.getJSON(wgScript,{ 'action': 'ajax', 'rs': 'TopListHelper::checkListStatus', 'title': topTenList, 'cb' : Math.random() }, function(data, status, xhr) {
if (status === "error") {
$('.WikiaTopTenModule #'+ listID).text('An error occurred while loading the top 10 list.');
}
else {
var canVote = data.canVote;
$('.WikiaTopTenModule #'+ listID).load('/wiki/Top_10_list:'+ escape(topTenList) +'?action=render #toplists-list-body ul', function(data, status, xhr) {
if (status === "error" && xhr.status !== 404) {
$('.WikiaTopTenModule #'+ listID).text('An error occurred while loading the top 10 list.');
}
else if (xhr.status === 404) {
$('.WikiaTopTenModule #'+ listID).text('The top 10 list could not be found.');
}
else {
styleList(listID);
if (canVote !== true) {
$('.WikiaTopTenModule #'+ listID +' .VoteButton').remove();
}
}
});
}
});
});
// Add event handlers to the top 10 buttons
$('body').on('click', '.WikiaTopTenModule .VoteButton', function() {
var that = this;
var item = $(this).attr('id');
var list = unescape($(this).parents('.list').attr('id'));
var id = $(this).parents('.list').attr('id');
$(this).parents('.WikiaTopTenModule').find('.header').append('<img class="ajax-loader" id="ajax-loader-'+ id +'" src="http://static.wikia.com/common/skins/common/images/ajax.gif" alt="Loading...">');
$(id + ' .VoteButton').css('visibility','hidden');
$.ajax({
url: wgScript,
type: "GET",
dataType: "json",
timeout: 10000,
data: { action: 'ajax', rs: 'TopListHelper::voteItem', title: list+'/'+item }
}).done(function(data) {
$('#ajax-loader-'+ id).remove();
var success = data.result;
var html = data.listBody;
if (success !== true) {
$('#' + id + ' .VoteButton').hide("slow", function() { $(this).remove(); })
}
else {
$('#' + id).html(html);
$('#' + id + ' .VoteButton').hide("slow", function() { $(this).remove(); })
styleList(id);
}
}).fail(function(data) {
$('#ajax-loader-'+ id).remove();
alert('An error occurred while submitting the vote.');
});
});
function styleList(id) {
$('#' + id + ' .NewItemForm').remove();
$('#' + id + ' .create-new-list').remove();
$('#' + id + ' .ItemVotes br').replaceWith(' ');
$('#' + id + ' .ItemNumber').each(function() {
$(this).html($(this).html().replace(/\#/g,''));
});
}
}
});
/* Social Icons */
function SocialIcons() {
var userArray = wgPageName.split(":");
$('.WikiaRail').prepend('<div style="right:-1px; top:108px; position: absolute;"><div style="position: absolute;" class="SocialIcon"><div style="float:right;"><a href="https://www.facebook.com/pages/Destinypedia/498321176909780?fref=ts"><img src="http://images.wikia.com/destinypedia/images/8/8f/Facebook_Icon.png"></a></div></div><div style="position: absolute; margin-top:42px" class="SocialIcon"><div style="float:right;"><a href="http://www.twitter.com/DpediaTeam"><img src="http://images.wikia.com/destinypedia/images/9/92/Twitter_Icon.png"></a></div></div><div style="position: absolute; margin-top:84px" class="SocialIcon"><div style="float:right;"><a href="http://halo.wikia.com/wiki/Special:RecentChanges?feed=rss&type=html"><img src="http://images.wikia.com/destinypedia/images/c/c7/RSS_Icon.png"></a></div></div><div style="position: absolute; margin-top:126px" class="SocialIcon"><div style="float:right;"><a href="https://www.bungie.net/en-us/Groups/Detail?groupId=18278"><img src="http://images.wikia.com/destinypedia/images/2/2e/Bungie_Icon.png"></a></div></div><div style="position: absolute; margin-top:168px" class="SocialIcon"><div style="float:right;"><a href="http://www.wikia.com/Mobile%2FGameGuides"><img src="http://images.wikia.com/destinypedia/images/c/c0/Game_Guides_Icon.png"></a></div></div></div>');
}
if (mw.config.get("wgNamespaceNumber") != "user") {
addOnloadHook(SocialIcons);
}