מדיה ויקי:סקריפטים/88.js – הבדלי גרסאות

מתוך ויקיפדיה, האנציקלופדיה החופשית
תוכן שנמחק תוכן שנוסף
מאין תקציר עריכה
טעינת 'jquery.ui.dialog' רק אם צריך, לבקשת משתמש:IKhitron
שורה 1: שורה 1:
mw.loader.using( ['mediawiki.api', 'jquery.ui.dialog', 'mediawiki.user'] , function() {
mw.loader.using( ['mediawiki.api', 'mediawiki.user'] , function() {


var api = new mw.Api( { cache: false } ),
var api = new mw.Api( { cache: false } ),
שורה 28: שורה 28:
$.ajax( { url: mw.util.getUrl( 'Special:Watchlist' ) } )
$.ajax( { url: mw.util.getUrl( 'Special:Watchlist' ) } )
.done( function( data ) {
.done( function( data ) {
mw.loader.using( 'jquery.ui.dialog' ).done (function() {
var content = $( data ).find( '.mw-changeslist' ),
var content = $( data ).find( '.mw-changeslist' ),
cl = '';
cl = '';
content
content
.parents()
.parents()
.each( function() {
.each( function() {
if ( $( this ).length )
if ( $( this ).length )
cl += $this.attr( 'class' ) + ' ';
cl += $this.attr( 'class' ) + ' ';
} );
} );
$( '<div>' )
$( '<div>' )
.addClass( 'mw-changeslist ' + cl )
.addClass( 'mw-changeslist ' + cl )
.dialog( {
.dialog( {
position: {
position: {
my: "center top",
my: "center top",
at: "center bottom",
at: "center bottom",
of: $this
of: $this
},
},
width: width60,
width: width60,
height: height60
height: height60
} )
} )
.css( { overflow: 'auto' } )
.css( { overflow: 'auto' } )
.append( content );
.append( content );
} );
} );
} );
}
}

גרסה מ־18:12, 12 בספטמבר 2016

mw.loader.using( ['mediawiki.api', 'mediawiki.user'] , function() {

	var api = new mw.Api( { cache: false } ),
		watchButton;
	
	function i18n( key ) {
		switch ( mw.user.options.get( 'language' ) ) {
			case 'he':
				switch ( key ) {
					case 'title' : return 'רשימת המעקב שלך';
				}
				break;
			case 'en':
				switch ( key ) {
					case 'title': return 'Your watchlist';
				}
				break;
		}
		return key;
	}
	
	function showWatchlistDialog( e ) {
		e.preventDefault();
		var $this = $( this ),
			width60 = $( 'body' ).width() * 0.6,
			height60 = $( 'body' ).height() * 0.6;
		
		$.ajax( { url: mw.util.getUrl( 'Special:Watchlist' ) } )
			.done( function( data ) {
				mw.loader.using( 'jquery.ui.dialog' ).done (function() {
					var content = $( data ).find( '.mw-changeslist' ),
						cl = '';
					
					content
						.parents()
						.each( function() { 
							if ( $( this ).length ) 
								cl += $this.attr( 'class' ) + ' '; 
						} );
					
					$( '<div>' )
						.addClass( 'mw-changeslist ' + cl )
						.dialog( {
							position: {
								my: "center top",
								at: "center bottom",
								of: $this
							},
							width: width60,
							height: height60
						} )
						.css( { overflow: 'auto' } )
						.append( content );
				} );
			} );
	}
	
	function announce( count ) {
		if ( ! watchButton ) {
			var url,
				notif = $( '#pt-notifications-notice' ),
				watchwButtonAnchor;
				
			if ( ! notif.length )
				notif = $( '#pt-notifications-alert' );
			if ( ! notif.length )
				return;
			
			watchButton = notif.clone(), // creates 2 elements with same id. unfortunately, this system wants id...
			watchwButtonAnchor = watchButton.find( 'a' )
				.click( showWatchlistDialog )
				.attr( { href: mw.util.getUrl( 'Special:Watchlist' ), title: i18n( 'title' ) } );
			if ( $( 'body' ).is( '.rtl' ) )
				watchButton.insertBefore( notif );
			else
				watchButton.insertAfter( notif );
		}
		watchButton.addClass('watchlist-badge').find( 'a' )
			.toggleClass( 'mw-echo-notifications-badge-unseen', !! count )
			.toggleClass( 'mw-echo-notifications-badge-all-read', ! count )
			.attr( { 'data-counter-text': count, 'data-counter-num': count } );
	}

	function queryAndUpdate() {
		api.get( { list: 'watchlist', wlprop: 'title|timestamp|notificationtimestamp', wlshow: 'unread', wllimit: 50 } )
			.done( function(data) {
				var counts = {}, 
					titles = [];
				if ( data && data.query && data.query.watchlist )
					$( data.query.watchlist ).each( function( index, item ) {
						var ts = new Date(item.timestamp), nts = new Date(item.notificationtimestamp);
						if (ts < nts)
							return; // bug in mw api call.
						if (counts[item.title])
							counts[item.title]++;
						else {
							counts[item.title] = 1;
							titles.push( item.title );
						}
					});
				announce( titles.length );
				setTimeout( queryAndUpdate, 60000 );
			} ); // done
	} // queryandupdate
	//add watch icon based on oojs-ui.styles.icons-interactions module
	mw.loader.addStyleTag('.watchlist-badge .mw-echo-notifications-badge::before { background-image: url("data:image/svg+xml,%3C%3Fxml%20version%3D%221.0%22%20encoding%3D%22utf-8%22%3F%3E%0A%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%2224%22%20height%3D%2224%22%20viewBox%3D%220%200%2024%2024%22%3E%0A%20%20%20%20%3Cpath%20d%3D%22M11%2014H6v1h5v-1zm0%203H6v-1h5v1zm0%201H6v1h5v-1zm1-5v3l5%203-1-6%204-3-6-1-2-5s-1.9%205-2%205l-6%201%204%203h4z%22%2F%3E%0A%3C%2Fsvg%3E%0A") !important; }');
	queryAndUpdate();
});