Merge pull request #8 from lyweiwei/disable-menu-item
Disable menu item
This commit is contained in:
Коммит
dcf2e8120a
|
@ -42,6 +42,11 @@ window.toolbar = new ToolbarView({
|
|||
text: 'The 2nd DropdownItem',
|
||||
id: 'dropdown-item-2nd',
|
||||
onClick: () => console.log('click dropdown-item-2nd'),
|
||||
}, {
|
||||
text: 'The 3rd DropdownItem',
|
||||
id: 'dropdown-item-3rd',
|
||||
disabled: true,
|
||||
onClick: () => console.log('click dropdown-item-3rd'),
|
||||
}, {
|
||||
type: 'dropdown-divider',
|
||||
}, {
|
||||
|
@ -77,4 +82,3 @@ window.toolbar = new ToolbarView({
|
|||
},
|
||||
}],
|
||||
}).render();
|
||||
|
||||
|
|
|
@ -6,20 +6,25 @@ export function renderDropdownItem(dropdownItem) {
|
|||
classes: [],
|
||||
id: _.uniqueId('dropdown-item-'),
|
||||
text: '',
|
||||
disabled: false,
|
||||
iconLeft: null,
|
||||
iconRight: null,
|
||||
tabindex: -1,
|
||||
onClick: null,
|
||||
}, dropdownItem);
|
||||
|
||||
if (options.disabled) {
|
||||
options.classes = _.union(options.classes, ['disabled']);
|
||||
}
|
||||
|
||||
const html = dropdownItemTemplate(options);
|
||||
const events = {};
|
||||
|
||||
const { id, onClick } = options;
|
||||
|
||||
if (_.isFunction(onClick)) {
|
||||
if (_.isFunction(onClick) && !options.disabled) {
|
||||
events[`click .dropdown-item#${id}`] = onClick;
|
||||
}
|
||||
|
||||
return { html, events };
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import $ from 'jquery';
|
||||
import _ from 'underscore';
|
||||
import dropdownSubmenuTemplate from './dropdown-submenu.jade';
|
||||
import './dropdown-submenu.less';
|
||||
|
@ -42,10 +41,9 @@ export function renderDropdownSubmenu(dropdownSubmenu, renderItem) {
|
|||
this.$(`#${options.menu.id}`).show();
|
||||
};
|
||||
|
||||
events[`mouseover ul:has(> ${selector}) > li:not(${selector})`] = function (e) {
|
||||
events[`mouseover ul:has(> ${selector}) > li:not(${selector})`] = function () {
|
||||
this.$(`#${options.menu.id}`).hide();
|
||||
};
|
||||
|
||||
return { html, events };
|
||||
}
|
||||
|
||||
|
|
|
@ -56,7 +56,6 @@ export class ToolbarView extends Backbone.View {
|
|||
toolbarId = _.uniqueId('toolbar-'),
|
||||
classes = [],
|
||||
items = [],
|
||||
events = {},
|
||||
}) {
|
||||
this._root = { type: 'toolbar', id: toolbarId, classes, items };
|
||||
this._contexts = renderItemTree(this._root);
|
||||
|
@ -171,4 +170,3 @@ export class ToolbarView extends Backbone.View {
|
|||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"main": "dist/backbone-toolbar.js",
|
||||
"version": "0.1.0",
|
||||
"version": "0.1.1",
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
|
|
Загрузка…
Ссылка в новой задаче