2014-05-07 13:06:24 +08:00
|
|
|
/**
|
|
|
|
* Menu.js
|
|
|
|
*
|
|
|
|
* Copyright, Moxiecode Systems AB
|
|
|
|
* Released under LGPL License.
|
|
|
|
*
|
|
|
|
* License: http://www.tinymce.com/license
|
|
|
|
* Contributing: http://www.tinymce.com/contributing
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new menu.
|
|
|
|
*
|
|
|
|
* @-x-less Menu.less
|
|
|
|
* @class tinymce.ui.Menu
|
|
|
|
* @extends tinymce.ui.FloatPanel
|
|
|
|
*/
|
|
|
|
define("tinymce/ui/Menu", [
|
|
|
|
"tinymce/ui/FloatPanel",
|
|
|
|
"tinymce/ui/MenuItem",
|
|
|
|
"tinymce/util/Tools"
|
2015-06-15 18:01:48 +08:00
|
|
|
], function(FloatPanel, MenuItem, Tools) {
|
2014-05-07 13:06:24 +08:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
var Menu = FloatPanel.extend({
|
|
|
|
Defaults: {
|
|
|
|
defaultType: 'menuitem',
|
|
|
|
border: 1,
|
|
|
|
layout: 'stack',
|
2015-06-15 18:01:48 +08:00
|
|
|
role: 'application',
|
|
|
|
bodyRole: 'menu',
|
|
|
|
ariaRoot: true
|
2014-05-07 13:06:24 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructs a instance with the specified settings.
|
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @param {Object} settings Name/value object with settings.
|
|
|
|
*/
|
|
|
|
init: function(settings) {
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
settings.autohide = true;
|
|
|
|
settings.constrainToViewport = true;
|
|
|
|
|
|
|
|
if (settings.itemDefaults) {
|
|
|
|
var items = settings.items, i = items.length;
|
|
|
|
|
|
|
|
while (i--) {
|
|
|
|
items[i] = Tools.extend({}, settings.itemDefaults, items[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
self._super(settings);
|
|
|
|
self.addClass('menu');
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Repaints the control after a layout operation.
|
|
|
|
*
|
|
|
|
* @method repaint
|
|
|
|
*/
|
|
|
|
repaint: function() {
|
|
|
|
this.toggleClass('menu-align', true);
|
|
|
|
|
|
|
|
this._super();
|
|
|
|
|
|
|
|
this.getEl().style.height = '';
|
|
|
|
this.getEl('body').style.height = '';
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hides/closes the menu.
|
|
|
|
*
|
|
|
|
* @method cancel
|
|
|
|
*/
|
|
|
|
cancel: function() {
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
self.hideAll();
|
|
|
|
self.fire('select');
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hide menu and all sub menus.
|
|
|
|
*
|
|
|
|
* @method hideAll
|
|
|
|
*/
|
|
|
|
hideAll: function() {
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
this.find('menuitem').exec('hideMenu');
|
|
|
|
|
|
|
|
return self._super();
|
|
|
|
},
|
2015-06-15 18:01:48 +08:00
|
|
|
/*
|
|
|
|
getContainerElm: function() {
|
|
|
|
var doc = document, id = this.classPrefix + 'menucontainer';
|
|
|
|
|
|
|
|
var elm = doc.getElementById(id);
|
|
|
|
if (!elm) {
|
|
|
|
elm = doc.createElement('div');
|
|
|
|
elm.id = id;
|
|
|
|
elm.setAttribute('role', 'application');
|
|
|
|
elm.className = this.classPrefix + '-reset';
|
|
|
|
elm.style.position = 'absolute';
|
|
|
|
elm.style.top = elm.style.left = '0';
|
|
|
|
elm.style.overflow = 'visible';
|
|
|
|
doc.body.appendChild(elm);
|
|
|
|
}
|
2014-05-07 13:06:24 +08:00
|
|
|
|
2015-06-15 18:01:48 +08:00
|
|
|
return elm;
|
|
|
|
},
|
|
|
|
*/
|
2014-05-07 13:06:24 +08:00
|
|
|
/**
|
|
|
|
* Invoked before the menu is rendered.
|
|
|
|
*
|
|
|
|
* @method preRender
|
|
|
|
*/
|
|
|
|
preRender: function() {
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
self.items().each(function(ctrl) {
|
|
|
|
var settings = ctrl.settings;
|
|
|
|
|
|
|
|
if (settings.icon || settings.selectable) {
|
|
|
|
self._hasIcons = true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return self._super();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return Menu;
|
|
|
|
});
|