All files / mobile.startup Skin.js

24.32% Statements 9/37
0% Branches 0/14
0% Functions 0/6
24.32% Lines 9/37

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139  1x 1x 1x 1x 1x 1x                                                 1x                                                                                                                                                                                               1x                   1x  
var skin,
	browser = require( './Browser' ).getSingleton(),
	View = require( './View' ),
	util = require( './util' ),
	currentPage = require( './currentPage' ),
	eventBus = require( './eventBusSingleton' ),
	mfExtend = require( './mfExtend' );
 
/**
 * Representation of the current skin being rendered.
 *
 * @class Skin
 * @extends View
 * @uses Browser
 * @uses Page
 * @fires Skin#click
 * @param {Object} params Configuration options
 * @param {OO.EventEmitter} params.eventBus Object used to listen for
 * @param {Page} params.page
 * scroll:throttled, resize:throttled, and section-toggled events
 */
function Skin( params ) {
	var options = util.extend( {}, params );
 
	this.page = options.page;
	this.name = options.name;
	this.eventBus = options.eventBus;
	options.isBorderBox = false;
	View.call( this, options );
}
 
mfExtend( Skin, View, {
	/**
	 * @memberof Skin
	 * @instance
	 * @mixes View#defaults
	 * @property {Object} defaults Default options hash.
	 * @property {Page} defaults.page page the skin is currently rendering
	 */
	defaults: {
		page: undefined
	},
 
	/**
	 * @inheritdoc
	 * @memberof Skin
	 * @instance
	 */
	postRender() {
		var $el = this.$el;
 
		if ( browser.supportsTouchEvents() ) {
			$el.addClass( 'touch-events' );
		}
 
		/**
		 * Fired when the skin is clicked.
		 *
		 * @event Skin#click
		 */
		this.$el.find( '#mw-mf-page-center' ).on( 'click', ( ev ) => {
			this.emit( 'click', ev );
		} );
	},
 
	/**
	 * @throws {Error} if mediawiki message is in unexpected format.
	 * @return {jQuery.Object} a list of links
	 */
	getLicenseLinks() {
		const mobileLicense = mw.message( 'mobile-frontend-license-links' );
		const mobileMsgExists = mobileLicense.exists() && mobileLicense.text();
		const userLanguage = mw.config.get( 'wgUserLanguage' );
		if ( userLanguage === 'qqx' ) {
			// Special handling for qqx code so we can easily debug what's going on here.
			return mobileLicense.parseDom();
		} else {
			return mobileMsgExists ? mobileLicense.parseDom() : this.$el.find( '#footer-info-copyright a' ).clone();
		}
	},
	/**
	 * Returns the appropriate license message including links/name to
	 * terms of use (if any) and license page
	 *
	 * @memberof Skin
	 * @instance
	 * @return {string|undefined}
	 */
	getLicenseMsg() {
		var licenseMsg,
			$licenseLinks = this.getLicenseLinks();
 
		if ( $licenseLinks.length ) {
			const licensePlural = mw.language.convertNumber(
				$licenseLinks.filter( 'a' ).length
			);
 
			if ( this.$el.find( '#footer-places-terms-use' ).length > 0 ) {
 
				var $termsLink = mw.message(
					'mobile-frontend-editor-terms-link',
					this.$el.find( '#footer-places-terms-use a' ).attr( 'href' )
				).parseDom();
				licenseMsg = mw.message(
					'mobile-frontend-editor-licensing-with-terms',
					$termsLink,
					$licenseLinks,
					licensePlural
				).parse();
			} else {
				licenseMsg = mw.message(
					'mobile-frontend-editor-licensing',
					$licenseLinks,
					licensePlural
				).parse();
			}
		}
 
		return licenseMsg;
	}
} );
 
/**
 * Get a skin singleton
 *
 * @return {Skin}
 */
Skin.getSingleton = function () {
	if ( !skin ) {
		skin = new Skin( {
			el: 'body',
			page: currentPage(),
			eventBus
		} );
	}
	return skin;
};
module.exports = Skin;