CoreFiles by mySites.guru
menu-item.js73 lines, 1,319 bytes, from wordpress-4.2-beta2.zip
Raw History Compare with 4.2-beta1
md5
701e08b161d3c1215107d74c5f9dbaf1
sha1
04687aacdc4801fd05b632df8043dec50d8e7c01
sha256
780afa8c6dedafb88042496aa219ae07d3cfc89f0ef14e870213ae0e31950f80
/*globals jQuery */

/**
 * wp.media.view.MenuItem
 *
 * @class
 * @augments wp.media.View
 * @augments wp.Backbone.View
 * @augments Backbone.View
 */
var View = require( './view.js' ),
	$ = jQuery,
	MenuItem;

MenuItem = View.extend({
	tagName:   'a',
	className: 'media-menu-item',

	attributes: {
		href: '#'
	},

	events: {
		'click': '_click'
	},
	/**
	 * @param {Object} event
	 */
	_click: function( event ) {
		var clickOverride = this.options.click;

		if ( event ) {
			event.preventDefault();
		}

		if ( clickOverride ) {
			clickOverride.call( this );
		} else {
			this.click();
		}

		// When selecting a tab along the left side,
		// focus should be transferred into the main panel
		if ( ! wp.media.isTouchDevice ) {
			$('.media-frame-content input').first().focus();
		}
	},

	click: function() {
		var state = this.options.state;

		if ( state ) {
			this.controller.setState( state );
			this.views.parent.$el.removeClass( 'visible' ); // TODO: or hide on any click, see below
		}
	},
	/**
	 * @returns {wp.media.view.MenuItem} returns itself to allow chaining
	 */
	render: function() {
		var options = this.options;

		if ( options.text ) {
			this.$el.text( options.text );
		} else if ( options.html ) {
			this.$el.html( options.html );
		}

		return this;
	}
});

module.exports = MenuItem;

The same content is in 3 releases, WordPress 4.2-beta1 to 4.2-beta3. See them all, or every version of this file.