मीडियाविकि:Gadget-MobileCategories.js

मुक्त ज्ञानकोश विकिपीडिया से

सूचना: यह पृष्ठ सुरक्षित करने बाद, परिवर्तनों को देखने लिए ब्राउज़र का कैश ख़ाली करने की आवश्यकता हो सकती है।

  • मोज़िला / फ़ायरफ़ॉक्स / सफ़ारी: shift hold करें जब आप reload क्लिक करते है, या Ctrl-Shift-R (अपल मैक में Cmd-Shift-R) दबाएँ;
  • गूगल क्रोम: Ctrl-shift-R (मैक में Cmd-Shift-R) दबाएँ
  • इंटरनेट एक्सप्लोरर: Ctrl hold करें जब आप refresh क्लिक करते हैं, या Ctrl-F5 क्लिक करते हैं;
  • कॉङ्करर: सिर्फ़ Reload बटन पर क्लिक करें, या F5 क्लिक करें;
  • ऑपरा सदस्य को Tools→Preferences में सम्पूर्ण कैश ख़ाली करने की ज़रूरत हो सकती है।
mw.hook( 'wikipage.content' ).add( function() {
	var api = new mw.Api();
	
	var apiRequest = api.get( {
		'action':'query',
		'titles': mw.config.get('wgPageName'),
		'prop': 'categories',
		'clprop': 'sortkey|hidden',
		'cllimit': 50,
		'indexpageids': true,
		'formatversion': 2
	} );
	var apiRequest2 = api.loadMessagesIfMissing( [ 'pagecategories', 'colon-separator' ] );

	$.when( apiRequest, apiRequest2 ).done( function( data ) {
		var categories = [],
			response1Data = data[0],
			response2Data = data[1];
		
		if( !response1Data.query.pages[0].categories ) {
			return;
		}
		function categoryHtmlGenerator(element, index, array) {
			if( element.hidden ) {
				return;
			}
			var title = new mw.Title( element.title, mw.config.get( 'wgNamespaceIds' ).file );
  			categories.push(
  				$( '<a>' ).attr( {
  					'href': mw.util.getUrl( element.title )
  				} ).append(
  					document.createTextNode( title.getMainText() ) 
  				).get( 0 )
  			);
			categories.push( ', ' );
		}
		response1Data.query.pages[0].categories.forEach( categoryHtmlGenerator );

		if( categories.length === 0 ) {
			return;
		}
		categories.pop(); //remove the last comma
		categories.unshift( document.createTextNode(
			mw.message( 'pagecategories' ).escaped() + mw.message( 'colon-separator' ).escaped() + ' '
		) );
		
		$('.printfooter')
			.after( $( '<div>' )
				.addClass( 'catlinks' )
				.attr( 'id', 'catlinks' )
				.data( 'mw', 'interface' )
				.append( $( '<div>' )
						.attr( 'id', 'mw-normal-catlink' )
						.append( categories )
				)
			);
	} );
} );