Разлика между версии на „Потребител:V111P/js/QuickDiffCommands.js“

Меню; Използване на оригиналния Бързолик скрипт МедияУики:Gadget-Quick_diff.js
м
(Меню; Използване на оригиналния Бързолик скрипт МедияУики:Gadget-Quick_diff.js)
/**
* For [[МедияУики:Gadget-Quick diff.js]]
* Enhance recent changes diff links.
*
* Author: Borislav Manolov
* License: Public domain
* Documentation: [[МедияУики:Gadget-Quick diff.js/doc]]
*/
var KEY_ESC = 27;
 
Задайте клавишите, които искате във вашия .js файл:
//$(document).off();
//$('a[href*="diff="]').off();
//$('#quickdiff').remove();
 
window.quickDiffConfig = {
var QuickDiff = {
keys: {
close: '4',
patrol: '3',
rollback: '5',
up: 'r',
down: 'f',
upUnpatrolled: 'e',
downUnpatrolled: 'd'
}
};
 
*/
enable: function()
{
jQuery('body').on('click', 'a[href*="diff="]', function (event) {
var $link = jQuery(this);
var isInside = $link.closest('#quickdiff').length > 0;
if (isInside)
$link = QuickDiff.$currentDiffLink;
else
QuickDiff.$currentDiffLink = $link.addClass("working");
var href = this.href + "&action=render"
+ ( event.ctrlKey ? "" : "&diffonly=1" );
jQuery.get(href, function(data){
QuickDiff.viewDiff(data, $link);
if (!isInside)
$link.removeClass("working").addClass("done");
});
return false;
});
},
 
//$(document).off(); $('a[href*="diff="]').off();
viewDiff: function(content, $link)
//$('#quickdiff').remove(); window.QuickDiff = null;
{
//if (QuickDiffCmds) QuickDiffCmds.turnOff();
var $viewWin = this.getViewWindow().css("top", $link.position().top + 30)
.find("#quickdiff-content").html(content)
.end().show();
if (mw.ext && mw.ext.Patroller) {
new mw.ext.Patroller.bulk(new mw.ext.Patroller.quick()).enable($link[0].href);
var patrolLink = $viewWin.find('.patrollink a');
new mw.ext.Patroller.quick().enable(patrolLink, $link[0].href);
}
if (mw.ext && mw.ext.QuickRollback) {
var $rollbackLinkSpan = $('#quickdiff .mw-rollback-link');
$rollbackLinkSpan.before('<br/>');
mw.ext.QuickRollback.enable($rollbackLinkSpan.find('a'));
}
},
 
var QuickDiffCmds = {
viewWindow: null,
 
$menu: null,
getViewWindow: function()
{
if ( null === this.viewWindow ) {
this.prepareViewWindow();
}
 
closeWin: function () {
return this.viewWindow;
$('#quickdiff').hide();
},
 
prepareViewWindowturnOff: function () {
QuickDiffCmds.quickDiffPatch(true);
if (QuickDiffCmds.qdcCss) QuickDiffCmds.qdcCss.disabled = true;
if (QuickDiffCmds.$menu) QuickDiffCmds.$menu.remove();
},
 
buildMenu: function()
{
var $menuDiv = $('<div id="quickdiff-menu"></div>');
this.viewWindow = this.buildViewWindow();
 
var clk = function (fn) { return function (e) { e.preventDefault(); fn(); } }
mw.loader.load("mediawiki.diff.styles", "text/css");
var spEl = document.createTextNode('&nbsp;');
this.addCss();
var sp = '&nbsp;&nbsp;';
},
$menuDiv.prepend(sp, $('<a href="#">&gt;&gt;</a>').click(clk(QuickDiffCmds.nextUnpatrolled)));
$menuDiv.prepend(sp, $('<a href="#">&gt;</a>').click(clk(QuickDiffCmds.next)));
$menuDiv.prepend(sp, $('<a href="#" title="' + QuickDiffCmds.helpMsg() + '">?</span>')
.click(clk(function () {
alert(QuickDiffCmds.helpMsg());
})));
$menuDiv.prepend(sp, $('<a href="#">&lt;</a>').click(clk(QuickDiffCmds.up)));
$menuDiv.prepend(sp, $('<a href="#">&lt;&lt;</a>').click(clk(QuickDiffCmds.upUnpatrolled)));
 
closeWin: function() {
$('#quickdiff').hide();
},
 
buildViewWindow: function()
{
var $win = jQuery('<div id="quickdiff"><div id="quickdiff-close"></div><div id="quickdiff-content"></div></div>');
var closeWin = function(){
if ($win) {
$win.hide();
}
};
$win.on('dblclick', closeWin).appendTo("#bodyContent").find("#quickdiff-close").click(closeWin);
$(document).keyup(function(e) {
var keys = QuickDiffQuickDiffCmds.keys;
 
if (e.keyCode == KEY_ESC) { closeWin(); }
 
if (e.keyCode == KEY_ESC) { QuickDiff.closeWin(); return; }
if ( !$('#quickdiff').is(':visible') || e.target.nodeName == 'INPUT' ) { return; }
 
var key = String.fromCharCode(e.keyCode).toLowerCase();
 
if (QuickDiffQuickDiffCmds.userIsPatroller && key == keys.patrol) { QuickDiffQuickDiffCmds.patrolMulti(); }
else if (key == keys.close) { QuickDiffCmds.closeWin(); }
else if (key == keys.rollback) {
var rollbkLink = $('#quickdiff .mw-rollback-link a').attr('target', '_blank')[0];
else if (key == keys.rollbackComment) {
var rollbkCLink = $('#quickdiff a.quickRollback_comm')[0];
if (rollbkCLink) rollbkCLink.click();
}
else if (key == keys.up || key == keys.down) {
QuickDiffQuickDiffCmds.next( key == keys.up );
}
else if ( QuickDiffQuickDiffCmds.userIsPatroller && ( key == keys.upUnpatrolled || key == keys.downUnpatrolled ) ) {
QuickDiffQuickDiffCmds.nextUnpatrolled( key == keys.upUnpatrolled );
}
});
return $menuDiv;
$(document.body).on("click", function(event) {
if ($(event.target).parents('#quickdiff').length === 0) {
closeWin();
}
});
return $win;
},
 
addCss: function()
{
QuickDiffCmds.qdcCss = mw.util.addCSS(
'#quickdiff-menu {\
positionz-index: absolute1;\
width: 100%;\
border: thin outset silver;\
box-shadow: 0 0 30px #888888;\
background-color: white;\
}\
#quickdiff-close {\
position: absolute;\
top: 0;\
right: 040px;\
widthfont-family: 20pxsans-serif;\
height: 20px;\
background: url(//upload.wikimedia.org/wikipedia/commons/thumb/0/0c/Fileclose.png/16px-Fileclose.png) no-repeat center center;\
cursor: pointer;\
z-index: 1;\
}'
);
},
 
up: function() {QuickDiffCmds.next(true);},
next: function(up) {
function scrollTo(el) {
}
var $lastDiffLink = QuickDiff.$currentDiffLink;
var $all, index, closeWin = QuickDiffQuickDiffCmds.closeWin;
 
if (mw.config.get('wgAction') === "history") {
}
else { // Recent changes, Watchlist, Contributions
var $all;
if (mw.config.get('wgCanonicalSpecialPageName') == 'Contributions') {
$all = $('.mw-changeslist-date + a[href*="&diff=prev"]');
}
else if ($('.mw-enhanced-rc').length > 0) {
$all = $('.mw-title + a[href*="&diff="]'); // excludes the subdiffs
}
}
else $all = $('a[href*="&diff="]');
 
if (up) { $all = $($all.get().reverse()); }
},
 
upUnpatrolled: function() {QuickDiffCmds.nextUnpatrolled(true);},
nextUnpatrolled: function(up) {
var namespaceNames = mw.config.get('wgFormattedNamespaces');
});
 
if (!$nextUnpatrolled) QuickDiffQuickDiffCmds.closeWin();
else {
var $scrollToEl = ($above && $above[0] ? $above : $nextUnpatrolled);
$lnk.click();
}
},
 
helpMsg: function() {
var hlpStr = '<< – Нагоре непатрул.\n< – Нагоре\n> – Надолу\n>> – Надолу непатрул.\n\nКлавиши\n';
$.each(QuickDiffCmds.keys, function(idx,val) {
switch (idx) {
case 'rollbackGood': // fallthrough
case 'rollbackComment': if (!mw.ext.QuickRollback) return; // fallthrough
case 'rollback': // fallthrough
case 'patrol': if (!QuickDiffCmds.userIsPatroller) return; break;
}
var str = idx + ": " + val + '\n';
hlpStr += str;
});
return hlpStr + '';
},
 
quickDiffPatch: function (undo) {
if (undo) {
if (QuickDiffCmds.originalGVW)
QuickDiff.getViewWindow = QuickDiffCmds.originalGVW;
return;
}
 
QuickDiffCmds.originalGVW = QuickDiff.getViewWindow;
QuickDiff.getViewWindow = function () {
var $menu = QuickDiffCmds.$menu;
if ( null === $menu ) {
$menu = QuickDiffCmds.$menu = QuickDiffCmds.buildMenu();
}
var win = QuickDiffCmds.originalGVW.call(QuickDiff);
win && win.prepend && win.prepend($menu);
return win;
};
}
 
patrol: '3',
rollback: '5',
rollbackGood: '6', // изисква джаджата „Бързо отменяне“
rollbackComment: '7', // изисква джаджата „Бързо отменяне“
up: 'r',
};
var customKeys = window.quickDiffConfig && window.quickDiffConfig.keys;
QuickDiffQuickDiffCmds.keys = $.extend(keys, customKeys);
 
var userGroups = mw.config.get('wgUserGroups');
QuickDiffQuickDiffCmds.userIsAdmin = $.inArray("sysop", userGroups) > -1;
QuickDiffQuickDiffCmds.userIsPatroller = $.inArray("patroller", userGroups) > -1 || QuickDiffCmds.userIsAdmin;
QuickDiffCmds.addCss();
|| $.inArray("autopatrolled", userGroups) > -1 || QuickDiff.userIsAdmin;
 
if (!window.QuickDiff) $.enableajax();{
url: '//bg.wikipedia.org/w/index.php?title=МедияУики:Gadget-Quick_diff.js'
+ '&action=raw&ctype=text/javascript',
dataType: 'script',
cache: true,
success: function () {
setTimeout(function () {
if (window.QuickDiff)
QuickDiffCmds.quickDiffPatch();
}, 500); // sometimes a script needs time to execute
}
});
}
 
});