МедиаУики:Gadget-AdvancedSiteNotices.js: Нұсқалар арасындағы айырмашылық

Content deleted Content added
Өңдеу түйіні жоқ
Өңдеу түйіні жоқ
1-жол:
mw.loader.using(function ['jquery.cookie'($, 'mediawiki.util'] mw).done { $( function () {
 
(function ($, mw) {
/** Advanced Site Notices ********
* Allow to custom dynamic site notices
* Maintainer: [[:zh:User:PhiLiP]]
*/
if (typeof(window.customASNInterval) == 'undefined') {
Line 10 ⟶ 8:
}
$(function () {
$('#mw-dismissable-notice').css('display', 'none');
if (window.closeASNForever || mw.config.get('wgAction') == 'edit' || mw.config.get('wgAction') == 'submit') {
return;
Line 22 ⟶ 19:
var cval = $.cookie(cname);
if (cval == '') {
cval = 0-1;
}
var rev = 0;
Line 28 ⟶ 25:
 
var tb = $('<table id="asn-dismissable-notice" width="100%" style="background: transparent;"/>');
var ct = $('<div id="advancedSiteNotices" style="heightword-break: 100pxbreak-word;" class="mw-parser-output"/>');
var sd = $('<a href="#" title="Жасыру"><img' src="//upload.wikimedia.org/wikipedia/foundation/2/20/CloseWindow19x19.png"+ alt="wgULS('Жабу', 'Жасыру"') border="0">+ '</a>');
tb.append($('<tr/>').append($('<td/>').append(ct)).append($('<td style="vertical-align: top;"/>').append('[').append(sd).append(']')));
var nts = null;
var styles = })[];
 
sd.click(function () {
Line 43 ⟶ 41:
});
 
var getAttrsmatchCriteria = function ( nt ) {
var onlycache = {nt.data( 'asn-cache' );
if ( cache !== sysop:undefined nt.hasClass('only_sysop'), {
logged:return nt.hasClass('only_logged'),cache;
anon: nt.hasClass('only_anon'),}
var criteria = nt.attr( 'data-asn-criteria' );
if (rt criteria === undefined l) {
criteria = nt.attr( 'class' ) ? 'false' : 'true';
if ( nt.hasClass('only_sysop') ) {
criteria += break'||in_group("sysop")';
}
if ( nt.hasClass('only_logged') ) {
criteria += '||in_group("user")';
}
ntif =( $nt.hasClass(nts[pos++]'only_anon'); ) {
criteria += '||!in_group("user")';
rt++;}
if ( nt.hasClass('only_zh_cn') ) {
criteria += '||only_for("zh-cn")';
return;}
if ( nt.hasClass('only_zh_hk') ) {
criteria += '||only_for("zh-hk")';
pos = pos % l;}
if ( nt.hasClass('only_zh_sg') ) {
criteria += '||only_for("zh-sg")';
}
if ( nt.hasClass('only_zh_tw') ) {
criteria += '||only_for("zh-tw")';
}
} else {
criteria = decodeURIComponent( criteria.replace(/\+/g, '%20') );
criteria = $.trim( criteria );
}
if ( criteria === '' ) {
criteria = 'true';
}
var testCriteria = function() {
var in_country = function( country ) {
return window.Geo === undefined || Geo.country === country;
}, in_region = function( region ) {
return window.Geo === undefined || Geo.region === region;
}, in_city = function( city ) {
return window.Geo === undefined || Geo.city === city;
}, in_group = function( group ) {
return $.inArray( group, mw.config.get( 'wgUserGroups' ) ) > -1;
}, only_for = function( userlang ) {
return userlang === mw.config.get('wgUserLanguage');
};
// FIXME: This shouldn't be using eval on data entered in wikitext. If that data is malformed it will throw an exception e.g. criteria = "(false))"
try {
return eval( criteria ); } catch ( e ) { return false; }
};
only['usr']cache = only['sysop'] || only['logged'] || only['anon']testCriteria();
returnnt.data( only'asn-cache', cache );
return cache;
};
 
Line 58 ⟶ 103:
}
ct.css('min-height', ct.height() + 'px');
tb.css('min-height', tb.height() + 'px');
var l = nts.length;
var nt = null;
var rt = 0;
while (!nt ||rt++ < l nt.attr('class')) {
ifnt = $(nt) {nts[pos] );
if ( matchCriteria( nt var) only = getAttrs(nt); {
break;
if (!only['usr'] || (($.inArray('sysop', mw.config.get('wgUserGroups')) != -1) && only['sysop']) || (mw.config.get('wgUserName') && only['logged']) || (!mw.config.get('wgUserName') && only['anon'])) {
break;
}
}
pos = pos % l;
nt = $(nts[pos++]);
rt++;
if (rt == l) {
return;
}
pos = (pos + 1) % l;
}
ntif ( rt >= nt.html(l ); {
if (ct.html()) { return;
ct.stop().fadeOut(function () {}
if ( typeof nt.data( 'asn-style' ) == 'string' ct.html(nt).fadeIn(); {
var style = mw.util.addCSS( decodeURIComponent( nt.data( 'asn-style' ).replace(/\+/g, '%20') ) );
});
nt.data( 'asn-style', null );
nt.data( 'asn-style-id', styles.length );
style.disabled = true;
styles.push( style );
}
if ( typeof nt.data( 'asn-html' ) == 'string' ) {
nt.data( 'asn-html-raw', decodeURIComponent( nt.data( 'asn-html' ).replace(/\+/g, '%20') ) );
nt.data( 'asn-html', null );
}
var styleId = nt.data( 'asn-style-id' );
nt = nt.data( 'asn-html-raw' ) || nt.html();
var cthtml = ct.html();
if ( cthtml ) {
if ( cthtml !== nt ) {
ct.stop().fadeOut(function () {
$.each( styles, function() {
this.disabled = true;
} );
if ( styles[styleId] ) {
styles[styleId].disabled = false;
}
ct.html(nt).fadeIn();
});
}
} else if (rev == cval) {
return;
} else {
$.cookie( cname, null );
tb.appendTo(ln);
if ( styles[styleId] ) {
styles[styleId].disabled = false;
}
ct.html(nt).fadeIn();
}
toid = setTimeout(function () {
loadNotices( (pos + 1) % l );
}, window.customASNInterval * 1000);
};
Line 93 ⟶ 160:
$.get(mw.util.wikiScript( 'api' ), {
page: 'Template:AdvancedSiteNotices/ajax',
variant: mw.config.get('wgUserVariant'),
prop: 'text',
action: 'parse',
Line 99 ⟶ 167:
smaxage: 3600
}, function (d) {
if(!d || !d.parse || !d.parse.text || !d.parse.text['*']) return;
d = $( '<div />' ).html( d.parse.text['*'] ).find( 'ul.sitents' );
nts = $('li', d);
Line 106 ⟶ 175:
});
});
}); })(jQuery, mediaWiki);
 
} );