User:Cariaso/common.js

/** */

// Import the jQuery dialog plugin before starting the rest of this script mw.loader.using(['jquery.ui.dialog'], function {

function println(s) { document.getElementById('myresult').innerHTML += s + ' '; }   function renderQuickRCDialog( pageLinks ) { var $dialog = $( ' ' ) .html(				' Welcome, ' + mw.user.name +				'! The following pages have been recently modified: ' +				pageLinks.join( ' ' ) + ''			) .dialog({				autoOpen: true,				title: 'Hello there!',				width: '70%',				modal: true			}); }

function quickRC { var myPageLinks = []; var myTitles = [];

// Fetch recent changes from the API by one of jQuery's AJAX functions jQuery.getJSON(			mw.util.wikiScript( 'api' ),			{				'format': 'json',				'action': 'query',				'list': 'recentchanges',				'rclimit' : 25			},			function( data ) {

// Build a unique array of links, using the mw.html library to format them. $.each ( data.query.recentchanges, function( index , rc ) {					// Don't link to this title if we've seen this title already					if ( $.inArray( rc.title, myTitles ) === -1 ) {						myPageLinks.push( mw.html.element(								'a', { href: mw.util.wikiGetlink( rc.title ) }, rc.title							) );					}

myTitles.push( rc.title ); } ) ;

renderQuickRCDialog( myPageLinks ); }		);	}

$(document).ready( function {

// Add a link to the toolbox var link = mw.util.addPortletLink(			'p-tb',			'#',			'SMW Demo1',			't-prettylinkwidget',			'Show a quick overview of changes',			null,			'#t-whatlinkshere'		);

// Create a jQuery object for this link so that we get // to use jQuery awesomeness like .click for binding functions to events // and methods like e.preventDefault; $(link).click( function( e ) {			// Avoid the browser going to '#'			e.preventDefault;

// Initiate quickRC! quickRC; });

});

});