|
|
(גרסת ביניים אחת של אותו משתמש אינה מוצגת) |
שורה 1: |
שורה 1: |
| if ( mw.config.get( 'wgNamespaceNumber' ) + 1 )
| |
| (function() {
| |
| "use strict";
| |
| mw.loader.using( 'mediawiki.api', function() {
| |
| new mw.Api().get( {
| |
| prop: 'info',
| |
| inprop: 'watchers|visitingwatchers',
| |
| titles: mw.config.get( 'wgPageName' )
| |
| } ).done( function( data ) {
| |
| if ( data && data.query && data.query.pages )
| |
| for ( var pageid in data.query.pages ) {
| |
| var pinfo = data.query.pages[pageid];
| |
| showWatchers( pinfo.watchers, pinfo.visitingwatchers );
| |
| }
| |
| } );
| |
| } );
| |
|
| |
|
| function showWatchers( watchersNum, visitingWatchers ) {
| |
| var color,
| |
| text,
| |
| caWatch = $( '#ca-watch a, #ca-unwatch a' ),
| |
| range = watchersNum === 0 ? 'zero'
| |
| : watchersNum === 1 ? 'one'
| |
| : watchersNum < 5 ? 'few'
| |
| : watchersNum < 12 ? 'several'
| |
| : watchersNum < 30 ? 'dozens'
| |
| : watchersNum >= 30 ? 'many'
| |
| : 'unknown'; // less than 30; user does not have permissions to get watchers count
| |
| switch ( range ) {
| |
| case 'zero':
| |
| text = 'אין עוקבים';
| |
| color = '#ff0000';
| |
| break;
| |
| case 'one':
| |
| text = 'עוקב יחיד';
| |
| color = 'orange';
| |
| break;
| |
| case 'unknown':
| |
| color = 'yellow';
| |
| text = 'פחות מ-30 עוקבים';
| |
| break;
| |
| default:
| |
| text = watchersNum + ' עוקבים';
| |
| color = { few: 'pink', several: 'yellow', dozens: 'lightblue', many: 'lightgreen' }[range];
| |
| break;
| |
| }
| |
| if ( typeof( visitingWatchers ) === 'number' )
| |
| text += ", " + visitingWatchers + " פעילים";
| |
| if ( caWatch.length )
| |
| caWatch.css( { backgroundColor: color } ).attr( { title: text } );
| |
| else $( function() { // wait until #ca-watch is available
| |
| $( '#ca-watch a' ).css( { backgroundColor: color } ).attr( { title: text } );
| |
| });
| |
| }
| |
| })();
| |