Użytkownik:Expert3222/CR.js: Różnice pomiędzy wersjami
Z Nondanych
m (powrót .parent().parent().parent()) |
m |
||
Linia 1: | Linia 1: | ||
// ConfirmRevert |
// ConfirmRevert |
||
// kod UI inspirowany gadżetem RollWithReason |
// kod UI inspirowany gadżetem RollWithReason |
||
// TODO: not works on middle (scroll) click - maybe this can be considered a feature? : |
// TODO: not works on middle (scroll) click - maybe this can be considered a feature? :P |
||
// TODO: disable for specific time, not just until session end |
// TODO: disable for specific time, not just until session end |
||
Aktualna wersja na dzień 15:12, 17 maj 2020
// ConfirmRevert
// kod UI inspirowany gadżetem RollWithReason
// TODO: not works on middle (scroll) click - maybe this can be considered a feature? :P
// TODO: disable for specific time, not just until session end
var cookieString = "CRDisabled";
var ConfirmRevert = {};
ConfirmRevert.isEnabled = function()
{
var cookieIndex = document.cookie.indexOf(cookieString);
if (cookieIndex == -1)
{
return true;
}
else
{
return document.cookie.charAt(cookieIndex + String(cookieString).length + 1) == "0";
}
}
ConfirmRevert.disable = function()
{
document.cookie = cookieString + "=1";
}
ConfirmRevert.enable = function()
{
document.cookie = cookieString + "=0";
}
ConfirmRevert.init = function()
{
var lastClickedLink = "";
mw.loader.using(["oojs-ui-core", "oojs-ui-windows"], function()
{
function CRProcessDialog( config ) {
CRProcessDialog.super.call( this, config );
}
OO.inheritClass( CRProcessDialog, OO.ui.ProcessDialog );
CRProcessDialog.static.name = "CRProcessDialog";
CRProcessDialog.static.size = "medium";
CRProcessDialog.static.title = "Potwierdź rewert";
CRProcessDialog.static.actions =
[
{ action: "continue", label: "Zatwierdź", flags: ["progressive", "primary"] },
{ action: "cancel", label: "Anuluj", flags: "safe" },
]
var checkbox = new OO.ui.CheckboxInputWidget({ value: "enabled" });
checkbox.$element.on("click", function()
{
var selected = !checkbox.isSelected(); //if it will be selected after click event ends
if (selected)
{
ConfirmRevert.enable();
}
else
{
ConfirmRevert.disable();
}
});
CRProcessDialog.prototype.initialize = function ()
{
CRProcessDialog.super.prototype.initialize.apply( this, arguments );
this.panel = new OO.ui.PanelLayout
({
padded: true,
expanded: false
});
this.content = new OO.ui.FieldsetLayout({ label: "Potwierdź, że chcesz przeprowadzić rewert w artykule.", classes: ["CR-padding"] });
this.checkboxField = new OO.ui.FieldLayout(checkbox, { label: "Nie pytaj ponownie", align: "inline" });
this.content.addItems([ this.checkboxField ]);
this.panel.$element.append(this.content.$element);
this.$body.append( this.panel.$element );
};
CRProcessDialog.prototype.getActionProcess = function(action)
{
var dialog = this;
if (action == "continue")
{
return new OO.ui.Process ( function()
{
dialog.close();
document.location.href = lastClickedLink;
});
}
else if (action == "cancel")
{
return new OO.ui.Process ( function()
{
dialog.close();
});
}
}
CRProcessDialog.prototype.getSetupProcess = function(data)
{
return CRProcessDialog.super.prototype.getSetupProcess.call(this, data)
.next(function()
{
this.content.setLabel("Potwierdź, że chcesz przeprowadzić rewert w artykule " + data.artName + ".");
}, this);
};
var dialog = new CRProcessDialog();
var CRWindowManager = new OO.ui.WindowManager();
$(document.body).append(CRWindowManager.$element);
CRWindowManager.addWindows([dialog]);
$(".mw-rollback-link a").click(function(event)
{
if (ConfirmRevert.isEnabled())
{
lastClickedLink = $(this).attr("href");
CRWindowManager.openWindow(dialog, { artName: $(this).parent().parent().attr("data-target-page") || $(this).parent().parent().parent().attr("data-target-page") });
event.preventDefault();
}
})
});
}
$(ConfirmRevert.init);