Użytkownik:SH3VEK/common.js: Różnice pomiędzy wersjami
Z Nonsensopedii, polskiej encyklopedii humoru
M |
M (JS zbyt nowoczesny) |
||
Linia 11: | Linia 11: | ||
]; |
]; |
||
NWSGDialog.prototype.szukaj = function() { |
NWSGDialog.prototype.szukaj = function() { |
||
var min = Math.floor(Number(this.inputOd.getValue()))||1; |
|||
var max = Math.floor(Number(this.inputDo.getValue()))||0; |
|||
var w = min > max ? "Wpisz liczbę większą od początkowej" : "Rozpoczęcie wyszukiwania"; |
|||
if (min > max) { |
if (min > max) { |
||
OO.ui.alert("Wpisz liczbę większą od początkowej!"); |
OO.ui.alert("Wpisz liczbę większą od początkowej!"); |
||
Linia 20: | Linia 22: | ||
}; |
}; |
||
NWSGDialog.prototype.progres = function(min, max, stat, page) { |
NWSGDialog.prototype.progres = function(min, max, stat, page) { |
||
var self = this; |
|||
var pn = page + " " + min, api = new mw.Api(); |
|||
this.btnSzukaj.setLabel("Szukanie... (" + min + "|" + max + ")"); |
this.btnSzukaj.setLabel("Szukanie... (" + min + "|" + max + ")"); |
||
var q = {action: "query", list: ["backlinks"], blnamespace: 108, titles: pn, bltitle: pn}; |
|||
if (mw.config.get("wgUserGroups").indexOf("sysop") != -1) { |
if (mw.config.get("wgUserGroups").indexOf("sysop") != -1) { |
||
q.list.push("deletedrevs"); |
q.list.push("deletedrevs"); |
||
Linia 28: | Linia 31: | ||
q.drprop = ["user", "content"]; |
q.drprop = ["user", "content"]; |
||
} |
} |
||
api.get(q).done((data) |
api.get(q).done(function(data) { |
||
var gc = data.query.pages["-1"] && data.query.pages["-1"].missing === "" ? [!0,[]] : [!1,[]]; |
|||
if ("deletedrevs" in data.query && data.query.deletedrevs.length && data.query.deletedrevs[0].revisions.length) { |
if ("deletedrevs" in data.query && data.query.deletedrevs.length && data.query.deletedrevs[0].revisions.length) { |
||
gc[1].push('<a class="nwsg-u" href="/wiki/Specjalna:Odtwórz/' + page + "_" + min +'">usuwany</a>'); |
gc[1].push('<a class="nwsg-u" href="/wiki/Specjalna:Odtwórz/' + page + "_" + min +'">usuwany</a>'); |
||
Linia 44: | Linia 47: | ||
if (gc[0] && !gc[1].length) stat.f++; |
if (gc[0] && !gc[1].length) stat.f++; |
||
if (min < max) { |
if (min < max) { |
||
setTimeout(() |
setTimeout(function() {self.progres(min+1, max, stat, page)}, 250); |
||
} else { |
} else { |
||
self.btnSzukaj.setDisabled(false); |
|||
self.btnSzukaj.setLabel("Szukaj"); |
|||
} |
} |
||
}); |
}); |
||
} |
}; |
||
NWSGDialog.prototype.initialize = function() { |
NWSGDialog.prototype.initialize = function() { |
||
NWSGDialog.super.prototype.initialize.apply(this, arguments); |
NWSGDialog.super.prototype.initialize.apply(this, arguments); |
||
// Wybór trybu |
// Wybór trybu |
||
var optTryb = []; |
|||
for ( |
for (var f in this.tryby) { |
||
optTryb.push(new OO.ui.ButtonOptionWidget({data: this.tryby[f], label: f})); |
optTryb.push(new OO.ui.ButtonOptionWidget({data: this.tryby[f], label: f})); |
||
} |
} |
||
Linia 65: | Linia 68: | ||
this.btnSzukaj = new OO.ui.ButtonWidget({label: "Szukaj", flags: ["progressive"]}); |
this.btnSzukaj = new OO.ui.ButtonWidget({label: "Szukaj", flags: ["progressive"]}); |
||
⚫ | |||
var self = this; |
|||
⚫ | |||
// Lista |
// Lista |
||
this.$body.append(this.selectTryb.$element, this.inputOd.$element, this.inputDo.$element, this.btnSzukaj.$element, $('<ol class="nwsg-list"></ol>')); |
this.$body.append(this.selectTryb.$element, this.inputOd.$element, this.inputDo.$element, this.btnSzukaj.$element, $('<ol class="nwsg-list"></ol>')); |
||
} |
}; |
||
NWSGDialog.prototype.getActionProcess = function(action) { |
NWSGDialog.prototype.getActionProcess = function(action) { |
||
var self = this; |
|||
return new OO.ui.Process(() |
return new OO.ui.Process(function() {self.close({action: action})}); |
||
} |
}; |
||
function makeTool(name, icon, title, onSelect, onUpdateState) { |
function makeTool(name, icon, title, onSelect, onUpdateState) { |
||
var fn; |
|||
fn = function() {fn.super.apply(this, arguments)}; |
fn = function() {fn.super.apply(this, arguments)}; |
||
OO.inheritClass(fn, OO.ui.Tool); |
OO.inheritClass(fn, OO.ui.Tool); |
||
Linia 85: | Linia 91: | ||
} |
} |
||
var wm = new OO.ui.WindowManager(); |
|||
var tf = new OO.ui.ToolFactory(); |
|||
var nwsgD = new NWSGDialog({size: "large"}); |
|||
var NwsgTool = makeTool("nwsg", "circle", "NOWE wolne strony Gry", function() {this.setActive(false); wm.openWindow(nwsgD)}, function() {}); |
|||
tf.register(NwsgTool); |
tf.register(NwsgTool); |
||
var CfgTool = makeTool("settings", "settings", "Ustawienia", function() {this.setActive(false)}, function() {}); |
|||
tf.register(CfgTool); |
tf.register(CfgTool); |
||
var tb = new OO.ui.Toolbar(tf, new OO.ui.ToolGroupFactory(), {position: "bottom"}); |
|||
tb.setup([{type: "list", icon: "ellipsis", include: ["*"]}]); |
tb.setup([{type: "list", icon: "ellipsis", include: ["*"]}]); |
||
var pl = new OO.ui.PanelLayout({$content: tb.$element, framed: true, expanded: false}); |
|||
pl.$element.css({position: "fixed", bottom: "4px", right: "4px", zIndex: 100}); |
pl.$element.css({position: "fixed", bottom: "4px", right: "4px", zIndex: 100}); |
||
$(function() { |
$(function() { |
||
Linia 105: | Linia 111: | ||
tb.emit("updateState"); |
tb.emit("updateState"); |
||
wm.addWindows([nwsgD]); |
wm.addWindows([nwsgD]); |
||
}) |
}); |
||
}); |
}); |
Wersja z 00:14, 11 mar 2019
mw.loader.using(["oojs", "oojs-ui"], function() {
function NWSGDialog(config) {
NWSGDialog.super.call(this, config);
this.tryby = {"Główny tryb": "Strona", "Fantasy": "Fantasy/strona", "RPG – łatwy": "RPG/łatwy/strona", "RPG – średni": "RPG/średni/strona", "RPG – trudny": "RPG/trudny/strona"};
}
OO.inheritClass(NWSGDialog, OO.ui.ProcessDialog);
NWSGDialog.static.name = "nswgDialog";
NWSGDialog.static.title = "NOWE Wolne strony Gry";
NWSGDialog.static.actions = [
{ action: 'cancel', label: 'Zamknij', flags: [ 'safe', 'back' ] }
];
NWSGDialog.prototype.szukaj = function() {
var min = Math.floor(Number(this.inputOd.getValue()))||1;
var max = Math.floor(Number(this.inputDo.getValue()))||0;
var w = min > max ? "Wpisz liczbę większą od początkowej" : "Rozpoczęcie wyszukiwania";
if (min > max) {
OO.ui.alert("Wpisz liczbę większą od początkowej!");
} else if (min <= max) {
this.btnSzukaj.setDisabled(true);
this.progres(min, max, {u: 0, l: 0, f: 0, t: 0}, "Gra:" + this.selectTryb.getSelectedItem().getData());
}
};
NWSGDialog.prototype.progres = function(min, max, stat, page) {
var self = this;
var pn = page + " " + min, api = new mw.Api();
this.btnSzukaj.setLabel("Szukanie... (" + min + "|" + max + ")");
var q = {action: "query", list: ["backlinks"], blnamespace: 108, titles: pn, bltitle: pn};
if (mw.config.get("wgUserGroups").indexOf("sysop") != -1) {
q.list.push("deletedrevs");
q.drlimit = 1;
q.drprop = ["user", "content"];
}
api.get(q).done(function(data) {
var gc = data.query.pages["-1"] && data.query.pages["-1"].missing === "" ? [!0,[]] : [!1,[]];
if ("deletedrevs" in data.query && data.query.deletedrevs.length && data.query.deletedrevs[0].revisions.length) {
gc[1].push('<a class="nwsg-u" href="/wiki/Specjalna:Odtwórz/' + page + "_" + min +'">usuwany</a>');
if (gc[0]) stat.u++;
}
if (data.query.backlinks.length) {
gc[1].push('<a class="nwsg-l" href="/wiki/Specjalna:Linkujące/' + page + "_" + min +'">ma linkujące</a>');
if (gc[0]) stat.l++;
}
if (gc[0]) {
$("<li><a "+(!gc[1].length?"class='new'":"")+"href='/wiki/" + page + "_" + min + "'>Strona "+min+"</a>"+(gc[1].length?" ("+gc[1].join(", ")+")":"")+"</li>").appendTo(".nwsg-list");
stat.t++;
}
if (gc[0] && !gc[1].length) stat.f++;
if (min < max) {
setTimeout(function() {self.progres(min+1, max, stat, page)}, 250);
} else {
self.btnSzukaj.setDisabled(false);
self.btnSzukaj.setLabel("Szukaj");
}
});
};
NWSGDialog.prototype.initialize = function() {
NWSGDialog.super.prototype.initialize.apply(this, arguments);
// Wybór trybu
var optTryb = [];
for (var f in this.tryby) {
optTryb.push(new OO.ui.ButtonOptionWidget({data: this.tryby[f], label: f}));
}
this.selectTryb = new OO.ui.ButtonSelectWidget({items: optTryb});
this.selectTryb.selectItem(optTryb[0]);
this.inputOd = new OO.ui.NumberInputWidget();
this.inputDo = new OO.ui.NumberInputWidget();
this.btnSzukaj = new OO.ui.ButtonWidget({label: "Szukaj", flags: ["progressive"]});
var self = this;
this.btnSzukaj.on("click", function() {self.szukaj()});
// Lista
this.$body.append(this.selectTryb.$element, this.inputOd.$element, this.inputDo.$element, this.btnSzukaj.$element, $('<ol class="nwsg-list"></ol>'));
};
NWSGDialog.prototype.getActionProcess = function(action) {
var self = this;
return new OO.ui.Process(function() {self.close({action: action})});
};
function makeTool(name, icon, title, onSelect, onUpdateState) {
var fn;
fn = function() {fn.super.apply(this, arguments)};
OO.inheritClass(fn, OO.ui.Tool);
fn.static.name = name;
fn.static.icon = icon;
fn.static.title = title;
fn.prototype.onSelect = onSelect;
fn.prototype.onUpdateState = onUpdateState;
return fn;
}
var wm = new OO.ui.WindowManager();
var tf = new OO.ui.ToolFactory();
var nwsgD = new NWSGDialog({size: "large"});
var NwsgTool = makeTool("nwsg", "circle", "NOWE wolne strony Gry", function() {this.setActive(false); wm.openWindow(nwsgD)}, function() {});
tf.register(NwsgTool);
var CfgTool = makeTool("settings", "settings", "Ustawienia", function() {this.setActive(false)}, function() {});
tf.register(CfgTool);
var tb = new OO.ui.Toolbar(tf, new OO.ui.ToolGroupFactory(), {position: "bottom"});
tb.setup([{type: "list", icon: "ellipsis", include: ["*"]}]);
var pl = new OO.ui.PanelLayout({$content: tb.$element, framed: true, expanded: false});
pl.$element.css({position: "fixed", bottom: "4px", right: "4px", zIndex: 100});
$(function() {
$("body").append(pl.$element);
$("body").append(wm.$element);
tb.initialize();
tb.emit("updateState");
wm.addWindows([nwsgD]);
});
});