مدیاویکی:Gadget-mobile-common.js: تفاوت میان نسخهها
ظاهر
imported>Yamaha5 بدون خلاصۀ ویرایش |
imported>Yamaha5 بدون خلاصۀ ویرایش |
||
| خط ۱۸: | خط ۱۸: | ||
//یونیکدسازی خلاصه ویرایش | //یونیکدسازی خلاصه ویرایش | ||
$('.edit-page').click(function() { | $('.edit-page').click(function() { | ||
function deChar(ss) { | |||
'use strict'; | |||
try { | |||
ss = decodeURIComponent(ss.replace( | |||
/\.([0-9A-F][0-9A-F])/g, '%$1')); | |||
} catch (ignore) {} | |||
return ss; | |||
} | |||
function decodeAnchor(link) { //simplify internal link: replace %20 and _ then decode anchor | |||
'use strict'; | |||
link = link.replace(/(_|%20)/g, ' ').replace(/^ +| +$/g, ''); | |||
var parts = link.split('#'), | |||
i, | |||
anchor, | |||
hidIdx = -1, | |||
hidden = []; | |||
if (parts.length !== 2) { | |||
return link; //no anchor | |||
} | |||
anchor = parts[1]; | |||
//decode 4, 3 and 2-byte: http://en.wikipedia.org/wiki/UTF-8 | |||
anchor = anchor.replace( | |||
/\.F[0-4]\.[89AB][\dA-F]\.[89AB][\dA-F]\.[89AB][\dA-F]/g, | |||
deChar | |||
); | |||
anchor = anchor.replace( | |||
/\.E[\dA-F]\.[89AB][\dA-F]\.[89AB][\dA-F]/g, | |||
deChar | |||
); | |||
anchor = anchor.replace(/\.[CD][\dA-F]\.[89AB][\dA-F]/g, | |||
deChar | |||
); | |||
anchor = anchor.replace( //hide IPs | |||
/(?:^|[^0-9A-F\.])(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/, | |||
function(s) { | |||
hidden[++hidIdx] = s; | |||
return '\x01' + hidIdx + '\x02'; | |||
} | |||
); | |||
//decode 1-byte chars: all symbols except -.:_ and []{} prohibited in links | |||
anchor = anchor.replace(/\.[2-7][0-9A-F]/g, function(hhh) { | |||
var ch = deChar(hhh); | |||
if ('!"#$%&\'()*+,/;<=>?@\\^`~'.indexOf(ch) >= 0) { | |||
return ch; | |||
} | |||
return hhh; | |||
}); | |||
//unhide IPs and return | |||
for (i = hidIdx; i >= 0; i--) { | |||
anchor = anchor.replace('\x01' + i + '\x02', hidden[i]); | |||
} | |||
if (anchor.indexOf("''") !== -1) { | |||
return link; //cannot have double '' in link | |||
} | |||
return parts[0] + '#' + anchor; | |||
} | |||
$(function() { | |||
'use strict'; | |||
mw.loader.using('jquery.byteLimit', function() { | |||
$( | |||
'#wpSummary, #wpReason, [name=wpReason], #mwProtect-reason, #mw-input-wpReason-other, #wpComment, .mw-ui-input.summary' | |||
).byteLimit(Infinity); | |||
}); | |||
$( | |||
'#wpSummary, #wpReason, [name=wpReason], #mwProtect-reason, #mw-input-wpReason-other, #wpComment, .mw-ui-input.summary' | |||
).on( | |||
'paste keyup change', | |||
function(e) { | |||
var that, val, bytes; | |||
that = $(this); | |||
val = that.val(); | |||
// from https://stackoverflow.com/questions/2219526/ | |||
bytes = encodeURI(val).split( | |||
/%(?:u[0-9A-F]{2})?[0-9A-F]{2}|./).length - | |||
1; | |||
that.css('background-color', bytes > 255 ? '#FFEBEB' : | |||
'white'); | |||
val = val.replace( // place diff before oldid | |||
/(oldid=(?:\d+|next|prev|cur|))&(diff=(?:\d+|next|prev|cur|))/gi, | |||
'$2&$1' | |||
).replace( // Special:Diff | |||
/(?:(^|[ \\^`#<>\[\]\"\t\n{|}])|https?:\/\/([a-z\-]+)\.(?:wikipedia|wikimedia)\.org\/[^ \\^`#<>\[\]\"\t\n{|}]*)&?diff=(\d+|next|prev|cur)(?:&oldid=(\d+|next|prev|cur|))?(#[^ \\^`#<>\[\]\"\t\n{|}]*)?(?=$|[ \\^`#<>\[\]\"\t\n{|}])/gi, | |||
'$1[[$2:Special:Diff/$4/$3$5]]' | |||
).replace( // Special:Permalink | |||
/(?:(^|[ \\^`#<>\[\]\"\t\n{|}])|https?:\/\/([a-z\-]+)\.(?:wikipedia|wikimedia)\.org\/[^ \\^`#<>\[\]\"\t\n{|}]*)&?oldid=(\d+|next|prev|cur)(#[^ \\^`#<>\[\]\"\t\n{|}]*)?(?=$|[ \\^`#<>\[\]\"\t\n{|}])/gi, | |||
'$1[[$2:Special:Permalink/$3$4]]' | |||
).replace( // [[Special:Diff/12345678/prev]] is equal to [[Special:Diff/12345678]] | |||
/\[\[([a-z\-]+:)Special:Diff\/(\d+|next|prev|cur)\/prev\]\]/gi, | |||
'[[$1Special:Diff/$2]]' | |||
).replace( // no oldid | |||
'Special:Diff//', | |||
'Special:Diff/' | |||
).replace( | |||
'[[fa:', | |||
'[[' | |||
).replace( | |||
'[[:', | |||
'[[' | |||
); | |||
try { | |||
val = decodeURI(val.replace(/%20/g, '')).replace(//g, '%20'); // three zwnj | |||
val = val.replace(/\[\[.*?\]\]/g, decodeAnchor); | |||
} catch (ignore) {} | |||
if (val !== that.val()) { | |||
that.val(val); | |||
} | |||
}); | |||
}); | |||
}); | }); | ||
// Adds option to share link to the current page in social networks and email | |||
if (mw.config.get('wgNamespaceNumber') === 0 || mw.config.get('wgNamespaceNumber') === 6) { | |||
$(document).ready(function() { | |||
if (mw.config.get('skin') == 'minerva') { //larger button for mobile veiw | |||
var socialShares = [{ | |||
'title': 'تلگرام', | |||
'url': 'https://telegram.me/share/url?url=https:' + wgServer + '/wiki/' + encodeURIComponent(wgPageName) + '&text=برگرفته از ویکیپدیای فارسی', | |||
'img': '//upload.wikimedia.org/wikipedia/commons/thumb/8/82/Telegram_logo.svg/28px-Telegram_logo.svg.png' | |||
}, { | |||
'title': 'فیسبوک', | |||
'url': 'http://www.facebook.com/sharer.php?u=https:' + wgServer + '/wiki/' + encodeURIComponent(wgPageName), | |||
'img': '//upload.wikimedia.org/wikipedia/commons/thumb/c/c2/F_icon.svg/25px-F_icon.svg.png' | |||
}, { | |||
'title': 'توییتر', | |||
'url': 'http://twitter.com/?status=' + encodeURIComponent('مشاهده در: \n' + wgPageName + '\nویکیپدیای فارسی http://defn.me/r/' + wgContentLanguage + '/' + wgArticleId.toString(36)), // Forked from [[MediaWiki:Gadget-ShortURL.js]] | |||
'img': '//upload.wikimedia.org/wikipedia/commons/thumb/1/19/Twitter_icon.svg/22px-Twitter_icon.svg.png' | |||
}]; | |||
} else { | |||
var socialShares = [{ | |||
'title': 'تلگرام', | |||
'url': 'https://telegram.me/share/url?url=https:' + wgServer + '/wiki/' + encodeURIComponent(wgPageName) + '&text=برگرفته از ویکیپدیای فارسی', | |||
'img': '//upload.wikimedia.org/wikipedia/commons/thumb/8/82/Telegram_logo.svg/17px-Telegram_logo.svg.png' | |||
}, { | |||
'title': 'فیسبوک', | |||
'url': 'http://www.facebook.com/sharer.php?u=https:' + wgServer + '/wiki/' + encodeURIComponent(wgPageName), | |||
'img': '//upload.wikimedia.org/wikinews/en/5/55/Facebook.png' | |||
}, { | |||
'title': 'توییتر', | |||
'url': 'http://twitter.com/?status=' + encodeURIComponent('مشاهده در: \n' + wgPageName + '\nویکیپدیای فارسی http://defn.me/r/' + wgContentLanguage + '/' + wgArticleId.toString(36)), // Forked from [[MediaWiki:Gadget-ShortURL.js]] | |||
'img': '//upload.wikimedia.org/wikinews/en/f/f7/Twitter.png' | |||
}]; | |||
} | |||
try { | |||
var whatLinksItem = $("#mw-content-text"); | |||
if (!whatLinksItem.length) return; | |||
var shareText = $("<span>اشتراک در: </span>"); | |||
$(socialShares).each(function() { | |||
var socialSpan = $("<span></span>"); | |||
var socialA = $('<a></a>', { | |||
href: this.url, | |||
title: this.title | |||
}); | |||
var socialImg = $('<img />', { | |||
'src': this.img | |||
}); | |||
socialA.append(socialImg); | |||
if (mw.config.get('skin') == 'minerva') { | |||
socialA.append('<span> </span>'); | |||
} | |||
socialSpan.append(socialA); | |||
shareText.append(socialSpan); | |||
}); | |||
var item = $("<li></li>", { | |||
id: 't-socialShare' | |||
}); | |||
item.append(shareText); | |||
whatLinksItem.before(item); | |||
} catch (e) { | |||
return; | |||
} | |||
}); | |||
mw.util.addCSS("#t-socialShare{position:relative;top:-8px;margin:7px -1px -10px 0px!important;}"); | |||
} | |||
} | } | ||
}); | }); | ||
نسخهٔ ۱۶ مارس ۲۰۱۶، ساعت ۲۳:۲۷
//common.js for mobile frontier
//به دلیل ضعیف بودن سیپییو و کم بودن رم محدودیت در پردازش توسط بعضی از موبایلها وجود دارد. لطفاً فقط کدهایی که وجودشان اهمیت بالایی دارد را به اینجا بیافزائید.
//Help Abuse Filter #106 to tag Recreated Pages which have delete log
$(function() {
if (mw.config.get('skin') == 'minerva') {
if ($('.mw-warning-with-logexcerpt .mw-logline-delete').length !== 0) {
function checkAndSetHook() {
if ($('button[class="continue"]').length !== 0) {
$('button[class="continue"]').click(function() {
$('.mw-ui-input.summary').val($('.mw-ui-input.summary').val() + "");
})
} else {
setTimeout(checkAndSetHook, 2000);
}
};
checkAndSetHook();
}
//یونیکدسازی خلاصه ویرایش
$('.edit-page').click(function() {
function deChar(ss) {
'use strict';
try {
ss = decodeURIComponent(ss.replace(
/\.([0-9A-F][0-9A-F])/g, '%$1'));
} catch (ignore) {}
return ss;
}
function decodeAnchor(link) { //simplify internal link: replace %20 and _ then decode anchor
'use strict';
link = link.replace(/(_|%20)/g, ' ').replace(/^ +| +$/g, '');
var parts = link.split('#'),
i,
anchor,
hidIdx = -1,
hidden = [];
if (parts.length !== 2) {
return link; //no anchor
}
anchor = parts[1];
//decode 4, 3 and 2-byte: http://en.wikipedia.org/wiki/UTF-8
anchor = anchor.replace(
/\.F[0-4]\.[89AB][\dA-F]\.[89AB][\dA-F]\.[89AB][\dA-F]/g,
deChar
);
anchor = anchor.replace(
/\.E[\dA-F]\.[89AB][\dA-F]\.[89AB][\dA-F]/g,
deChar
);
anchor = anchor.replace(/\.[CD][\dA-F]\.[89AB][\dA-F]/g,
deChar
);
anchor = anchor.replace( //hide IPs
/(?:^|[^0-9A-F\.])(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/,
function(s) {
hidden[++hidIdx] = s;
return '\x01' + hidIdx + '\x02';
}
);
//decode 1-byte chars: all symbols except -.:_ and []{} prohibited in links
anchor = anchor.replace(/\.[2-7][0-9A-F]/g, function(hhh) {
var ch = deChar(hhh);
if ('!"#$%&\'()*+,/;<=>?@\\^`~'.indexOf(ch) >= 0) {
return ch;
}
return hhh;
});
//unhide IPs and return
for (i = hidIdx; i >= 0; i--) {
anchor = anchor.replace('\x01' + i + '\x02', hidden[i]);
}
if (anchor.indexOf("''") !== -1) {
return link; //cannot have double '' in link
}
return parts[0] + '#' + anchor;
}
$(function() {
'use strict';
mw.loader.using('jquery.byteLimit', function() {
$(
'#wpSummary, #wpReason, [name=wpReason], #mwProtect-reason, #mw-input-wpReason-other, #wpComment, .mw-ui-input.summary'
).byteLimit(Infinity);
});
$(
'#wpSummary, #wpReason, [name=wpReason], #mwProtect-reason, #mw-input-wpReason-other, #wpComment, .mw-ui-input.summary'
).on(
'paste keyup change',
function(e) {
var that, val, bytes;
that = $(this);
val = that.val();
// from https://stackoverflow.com/questions/2219526/
bytes = encodeURI(val).split(
/%(?:u[0-9A-F]{2})?[0-9A-F]{2}|./).length -
1;
that.css('background-color', bytes > 255 ? '#FFEBEB' :
'white');
val = val.replace( // place diff before oldid
/(oldid=(?:\d+|next|prev|cur|))&(diff=(?:\d+|next|prev|cur|))/gi,
'$2&$1'
).replace( // Special:Diff
/(?:(^|[ \\^`#<>\[\]\"\t\n{|}])|https?:\/\/([a-z\-]+)\.(?:wikipedia|wikimedia)\.org\/[^ \\^`#<>\[\]\"\t\n{|}]*)&?diff=(\d+|next|prev|cur)(?:&oldid=(\d+|next|prev|cur|))?(#[^ \\^`#<>\[\]\"\t\n{|}]*)?(?=$|[ \\^`#<>\[\]\"\t\n{|}])/gi,
'$1[[$2:Special:Diff/$4/$3$5]]'
).replace( // Special:Permalink
/(?:(^|[ \\^`#<>\[\]\"\t\n{|}])|https?:\/\/([a-z\-]+)\.(?:wikipedia|wikimedia)\.org\/[^ \\^`#<>\[\]\"\t\n{|}]*)&?oldid=(\d+|next|prev|cur)(#[^ \\^`#<>\[\]\"\t\n{|}]*)?(?=$|[ \\^`#<>\[\]\"\t\n{|}])/gi,
'$1[[$2:Special:Permalink/$3$4]]'
).replace( // [[Special:Diff/12345678/prev]] is equal to [[Special:Diff/12345678]]
/\[\[([a-z\-]+:)Special:Diff\/(\d+|next|prev|cur)\/prev\]\]/gi,
'[[$1Special:Diff/$2]]'
).replace( // no oldid
'Special:Diff//',
'Special:Diff/'
).replace(
'[[fa:',
'[['
).replace(
'[[:',
'[['
);
try {
val = decodeURI(val.replace(/%20/g, '')).replace(//g, '%20'); // three zwnj
val = val.replace(/\[\[.*?\]\]/g, decodeAnchor);
} catch (ignore) {}
if (val !== that.val()) {
that.val(val);
}
});
});
});
// Adds option to share link to the current page in social networks and email
if (mw.config.get('wgNamespaceNumber') === 0 || mw.config.get('wgNamespaceNumber') === 6) {
$(document).ready(function() {
if (mw.config.get('skin') == 'minerva') { //larger button for mobile veiw
var socialShares = [{
'title': 'تلگرام',
'url': 'https://telegram.me/share/url?url=https:' + wgServer + '/wiki/' + encodeURIComponent(wgPageName) + '&text=برگرفته از ویکیپدیای فارسی',
'img': '//upload.wikimedia.org/wikipedia/commons/thumb/8/82/Telegram_logo.svg/28px-Telegram_logo.svg.png'
}, {
'title': 'فیسبوک',
'url': 'http://www.facebook.com/sharer.php?u=https:' + wgServer + '/wiki/' + encodeURIComponent(wgPageName),
'img': '//upload.wikimedia.org/wikipedia/commons/thumb/c/c2/F_icon.svg/25px-F_icon.svg.png'
}, {
'title': 'توییتر',
'url': 'http://twitter.com/?status=' + encodeURIComponent('مشاهده در: \n' + wgPageName + '\nویکیپدیای فارسی http://defn.me/r/' + wgContentLanguage + '/' + wgArticleId.toString(36)), // Forked from [[MediaWiki:Gadget-ShortURL.js]]
'img': '//upload.wikimedia.org/wikipedia/commons/thumb/1/19/Twitter_icon.svg/22px-Twitter_icon.svg.png'
}];
} else {
var socialShares = [{
'title': 'تلگرام',
'url': 'https://telegram.me/share/url?url=https:' + wgServer + '/wiki/' + encodeURIComponent(wgPageName) + '&text=برگرفته از ویکیپدیای فارسی',
'img': '//upload.wikimedia.org/wikipedia/commons/thumb/8/82/Telegram_logo.svg/17px-Telegram_logo.svg.png'
}, {
'title': 'فیسبوک',
'url': 'http://www.facebook.com/sharer.php?u=https:' + wgServer + '/wiki/' + encodeURIComponent(wgPageName),
'img': '//upload.wikimedia.org/wikinews/en/5/55/Facebook.png'
}, {
'title': 'توییتر',
'url': 'http://twitter.com/?status=' + encodeURIComponent('مشاهده در: \n' + wgPageName + '\nویکیپدیای فارسی http://defn.me/r/' + wgContentLanguage + '/' + wgArticleId.toString(36)), // Forked from [[MediaWiki:Gadget-ShortURL.js]]
'img': '//upload.wikimedia.org/wikinews/en/f/f7/Twitter.png'
}];
}
try {
var whatLinksItem = $("#mw-content-text");
if (!whatLinksItem.length) return;
var shareText = $("<span>اشتراک در: </span>");
$(socialShares).each(function() {
var socialSpan = $("<span></span>");
var socialA = $('<a></a>', {
href: this.url,
title: this.title
});
var socialImg = $('<img />', {
'src': this.img
});
socialA.append(socialImg);
if (mw.config.get('skin') == 'minerva') {
socialA.append('<span> </span>');
}
socialSpan.append(socialA);
shareText.append(socialSpan);
});
var item = $("<li></li>", {
id: 't-socialShare'
});
item.append(shareText);
whatLinksItem.before(item);
} catch (e) {
return;
}
});
mw.util.addCSS("#t-socialShare{position:relative;top:-8px;margin:7px -1px -10px 0px!important;}");
}
}
});