implement replaceMenu in MainMenu
This commit is contained in:
parent
7398b1ec14
commit
e11a8e3a78
1 changed files with 37 additions and 13 deletions
|
@ -33,19 +33,7 @@ Ox.MainMenu = function(options, self) {
|
||||||
that.layer = $('<div>').addClass('OxLayer');
|
that.layer = $('<div>').addClass('OxLayer');
|
||||||
|
|
||||||
self.options.menus.forEach(function(menu, position) {
|
self.options.menus.forEach(function(menu, position) {
|
||||||
that.titles[position] = $('<div>')
|
addMenu(menu, position);
|
||||||
.addClass('OxTitle')
|
|
||||||
.html(menu.title)
|
|
||||||
.data('position', position)
|
|
||||||
.appendTo(that.$element);
|
|
||||||
that.menus[position] = Ox.Menu(Ox.extend(menu, {
|
|
||||||
element: that.titles[position],
|
|
||||||
mainmenu: that,
|
|
||||||
size: self.options.size
|
|
||||||
}))
|
|
||||||
.bindEvent({
|
|
||||||
hide: onHideMenu
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (self.options.extras.length) {
|
if (self.options.extras.length) {
|
||||||
|
@ -59,6 +47,30 @@ Ox.MainMenu = function(options, self) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function addMenu(menu, position) {
|
||||||
|
that.titles[position] = $('<div>')
|
||||||
|
.addClass('OxTitle')
|
||||||
|
.html(menu.title)
|
||||||
|
.data('position', position);
|
||||||
|
if (position == 0) {
|
||||||
|
if (that.titles.length == 1) {
|
||||||
|
that.titles[position].appendTo(that.$element);
|
||||||
|
} else {
|
||||||
|
that.titles[position].insertBefore(that.titles[1]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
that.titles[position].insertAfter(that.titles[position - 1])
|
||||||
|
}
|
||||||
|
that.menus[position] = Ox.Menu(Ox.extend(menu, {
|
||||||
|
element: that.titles[position],
|
||||||
|
mainmenu: that,
|
||||||
|
size: self.options.size
|
||||||
|
}))
|
||||||
|
.bindEvent({
|
||||||
|
hide: onHideMenu
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function click(event) {
|
function click(event) {
|
||||||
var $target = $(event.target),
|
var $target = $(event.target),
|
||||||
position = typeof $target.data('position') != 'undefined'
|
position = typeof $target.data('position') != 'undefined'
|
||||||
|
@ -105,6 +117,11 @@ Ox.MainMenu = function(options, self) {
|
||||||
self.focused = false;
|
self.focused = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function removeMenu(position) {
|
||||||
|
that.titles[position].remove();
|
||||||
|
that.menus[position].removeElement();
|
||||||
|
}
|
||||||
|
|
||||||
self.setOption = function(key, value) {
|
self.setOption = function(key, value) {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -185,6 +202,13 @@ Ox.MainMenu = function(options, self) {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
that.replaceMenu = function(id, menu) {
|
||||||
|
var position = Ox.getPositionById(self.options.menus, id);
|
||||||
|
self.options.menus[position] = menu;
|
||||||
|
removeMenu(position);
|
||||||
|
addMenu(menu, position);
|
||||||
|
};
|
||||||
|
|
||||||
/*@
|
/*@
|
||||||
selectNextMenu <f> selectNextMenu
|
selectNextMenu <f> selectNextMenu
|
||||||
@*/
|
@*/
|
||||||
|
|
Loading…
Reference in a new issue