Jump to content

User:Cscott/TogetherJS-ext.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Cscott (talk | contribs) at 00:10, 10 August 2014 (Beta!). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
/*
 * This file is part of the MediaWiki extension TogetherJS.
 *
 * TogetherJS is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * TogetherJS is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with TogetherJS.  If not, see <http://www.gnu.org/licenses/>.
 */

( function ( mw, $, tt ) {

	// add option to start togetherjs in a action tab
	var pTabsId = $( '#p-views' ).length ? 'p-views' : 'p-cactions';
	mw.util.addPortletLink( pTabsId, '#', mw.msg( 'togetherjs-tab' ),
	                       'ca-tt-start', mw.msg( 'togetherjs-start' ) );
	$( '#ca-tt-start' ).click( tt );

	// add togetherjs to edit source toolbar
	if (mw.toolbar) {
		mw.toolbar.addButton({
			imageId: 'togetherjs-button',
			imageFile: '//togetherjs.wmflabs.org/extensions/TogetherJS/togetherjs/images/notification-togetherjs-logo.png',
			speedTip: mw.msg( 'togetherjs-start' )
		});
		$( '#togetherjs-button' ).click( function(event) {
			tt(); // toggle togetherjs
			return false;
		} );
	}

	// Hook visual editor, make sure we notice when it's created/destroyed

	// According to Trevor, we should really "just make an
	// ve.InstanceList class, which has add and remove methods and
	// emits add and remove events. Then replace ve.instances and
	// ve.init.target with instances of ve.InstanceList, and make all
	// callers use add/remove instead of push/splice. Then just
	// connect to ve.instances or ve.init.targets and listen for
	// add/remove events. That's the way I recommend doing it."
	// ... but this works fine for now (although it's mediawiki-specific)

	mw.hook( 've.activationComplete' ).add( tt.reinitialize.bind(tt) );
	mw.hook( 've.deactivationComplete' ).add( tt.reinitialize.bind(tt) );
	
	if (!window.TOGETHERJS_BETA) {
		$( function() { mw.hook( 'togetherjs.autostart' ).fire(); } );
	}
}( mediaWiki, jQuery, TogetherJS ) );