МедиаУики:Gadget-AdvancedSiteNotices.js: Нұсқалар арасындағы айырмашылық
Content deleted Content added
Arystanbek (талқылау | үлесі) Өңдеу түйіні жоқ |
Arystanbek (талқылау | үлесі) Өңдеу түйіні жоқ |
||
1-жол:
/** Advanced Site Notices ********
* Allow to custom dynamic site notices
* Maintainer: [[:zh:User:PhiLiP]]
*/
if (typeof(window.customASNInterval) == 'undefined') {
Line 10 ⟶ 8:
}
$(function () {
if (window.closeASNForever || mw.config.get('wgAction') == 'edit' || mw.config.get('wgAction') == 'submit') {
return;
Line 22 ⟶ 19:
var cval = $.cookie(cname);
if (cval == '') {
cval =
}
var rev = 0;
Line 28 ⟶ 25:
var tb = $('<table id="asn-dismissable-notice" width="100%" style="background: transparent;"/>');
var ct = $('<div id="advancedSiteNotices" style="
var sd = $('<a href="#
tb.append($('<tr/>').append($('<td/>').append(ct)).append($('<td
var nts = null;
sd.click(function () {
Line 43 ⟶ 41:
});
var
var
if ( cache !==
var criteria = nt.attr( 'data-asn-criteria' );
criteria = nt.attr( 'class' ) ? 'false' : 'true';
if ( nt.hasClass('only_sysop') ) {
}▼
if ( nt.hasClass('only_logged') ) {
criteria += '||in_group("user")';
criteria += '||!in_group("user")';
if ( nt.hasClass('only_zh_cn') ) {
criteria += '||only_for("zh-cn")';
if ( nt.hasClass('only_zh_hk') ) {
criteria += '||only_for("zh-hk")';
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; }
};
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 (
if ( matchCriteria( nt
break;
▲ break;
▲ }
▲ }
▲ pos = pos % l;
▲ nt = $(nts[pos++]);
▲ rt++;
▲ if (rt == l) {
▲ return;
}
pos = (pos + 1) % l;
}
if ( typeof nt.data( 'asn-style' ) == 'string'
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);
|