משתמש:קיפודנחש/api2module.js

מתוך ויקיפדיה, האנציקלופדיה החופשית

הערה: לאחר הפרסום, ייתכן שיהיה צורך לנקות את זיכרון המטמון (cache) של הדפדפן כדי להבחין בשינויים.

  • פיירפוקס / ספארי: להחזיק את המקש Shift בעת לחיצה על טעינה מחדש (Reload) או ללחוץ על צירוף המקשים Ctrl-F5 או Ctrl-R (במחשב מק: ⌘-R).
  • גוגל כרום: ללחוץ על צירוף המקשים Ctrl-Shift-R (במחשב מק: ⌘-Shift-R).
  • אינטרנט אקספלורר / אדג': להחזיק את המקש Ctrl בעת לחיצה על רענן (Refresh) או ללחוץ על צירוף המקשים Ctrl-F5.
  • אופרה: ללחוץ על Ctrl-F5.
$( function() {
	$( '.api-to-module' ).each( function() {
		var $this = $( this ),
			api,
			params = JSON.parse( $this.find( '.api-to-module-params' ).text() ),
			showPopup = $this.find( '.api-to-module-popup' ).length,
			popupTitle = $this.find( '.api-to-module-popup' ).text(),
			template = $this.find( '.api-to-module-template' ).text(),
			targetDiv = $this.find( '.api-to-module-output' );
		
		function parseResult( data ) {
			template = template.replace( 'apiCallData', btoa( encodeURIComponent( JSON.stringify( data ) ) ) );
			api.post( { 
				action: 'parse',
				text: template,
				title: mw.config.get( 'wgPageName' )
			} ).done( function( parseData ) {
				
				if ( targetDiv.length ) {
					if (parseData && parseData.parse && parseData.parse.text )
						targetDiv.append( parseData.parse.text['*'] || '' );
				}
				else if( showPopup ) 
					mw.loader.using( 'jquery.ui', function() {
						$( '<div>' )
						.dialog( { 
							title: 'סטטיסטיקת צפיות בדף',
							width: 'auto', 
							height: 'auto',
							position: [$('body').width() * 0.2, $('body').height() * 0.1]
						} )
						.append( content );
						} );
		
			} );
		}
		
		if ( targetDiv.length || showPopup )
		if ( params && ( $.inArray( params.action, [ 'templatedata', 'query' ] ) + 1 ) ) 
		mw.loader.using( 'mediawiki.api', function() {
			api = new mw.Api();
			api.get( params )
				.done( parseResult );
		} );
	} );
} );