User:FoxTheCat/common.js

// CREDIT OZUZANNA FOR API CALLS $(function {   if (!window.wgIsArticle) return;    var alias1 = ArticleComments.setPage, alias2 = ArticleComments.init;    function toBeCalled    {        var array = [], i = 0;        $('.comment').each(function { array.push($(this)[0].id); });        $('span.tools').each(function {           var el = $(' Ajax Delete'); el.click(function           {                var commid = $(this).data.id;                $.showCustomModal("Delete comment", "  Enter a proper deletion reason below.  ", {                   id: "AjaxCommentDeleteModal", buttons: [{ id: "AjaxCommentDeleteRemoveButton", defaultButton: true, message: "Delete", handler: function {                           new mw.Api.post({                                action: 'delete',                                pageid: commid.substring(5),                                reason: $('#AjaxCommentDeleteReason').val,                                bot: true,                                token: mw.user.tokens.get('editToken')                            }) .done(function(d)                           {                                if (!d.error) $("#" + commid).slideToggle;                                else alert('Failed to delete: ' + d.error.code);                            }) .fail(function { alert('Failed to delete'); }); $("#AjaxCommentDeleteModal").closeModal; }                   },                    {                        id: "AjaxCommentDeleteCloseButton", defaultButton: true, message: "Close", handler: function{ $("#AjaxCommentDeleteModal").closeModal; } }]               });            });            $(this).append(el); });    }    ArticleComments.init = function    {        alias2;        toBeCalled;    };    ArticleComments.setPage = function (e)    { 		ArticleComments.bucky.timer.start('setPage'); 		var page = parseInt($(this).attr('page')); 		e.preventDefault; 		ArticleComments.$commentsList.addClass('loading'); 		$.getJSON(wgScript + '?action=ajax&rs=ArticleCommentsAjax&method=axGetComments', { 			article: wgArticleId, order: $('#article-comm-order').attr('value'), page: page, useskin: window.skin },       function (json) { 			ArticleComments.$commentsList.removeClass('loading'); if (!json.error) { 				ArticleComments.$commentsList.html(json.text); var $articleCommentsPagination = $('.article-comments-pagination'); if ($articleCommentsPagination.exists) $articleCommentsPagination.html(json.pagination); ArticleComments.addHover; } 			ArticleComments.processing = false; toBeCalled; ArticleComments.bucky.timer.stop('setPage'); }); 	} });