WordPress/wp-includes/js/media/views/menu-item.js
Scott Taylor b191013198 Media JS files:
* In media manifests, ditch IIFEs and global injection, these get dynamically scoped via Browserify
* Remove the `debug` option from `browserify:media`
* Add `jshint:media` to `jshint:corejs`
* Add a trailing newline to all new module files

Props iseulde.
See #28510.

Built from https://develop.svn.wordpress.org/trunk@31385


git-svn-id: http://core.svn.wordpress.org/trunk@31366 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-02-09 16:01:29 +00:00

72 lines
1.3 KiB
JavaScript

/**
* 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;