2011-11-05 16:46:53 +00:00
|
|
|
'use strict';
|
2012-05-21 10:38:18 +00:00
|
|
|
|
2011-05-16 08:24:46 +00:00
|
|
|
/*@
|
|
|
|
Ox.MenuItem <f:Ox.Element> MenuItem Object
|
2012-05-22 13:14:40 +00:00
|
|
|
([options[, self]]) -> <o> MenuItem Object
|
2011-05-16 08:24:46 +00:00
|
|
|
options <o> Options object
|
2011-05-16 10:49:48 +00:00
|
|
|
bind <a|[]> fixme: what's this?
|
|
|
|
checked <f|null>
|
|
|
|
disabled <b|false>
|
|
|
|
group <s|''>
|
|
|
|
icon <s|''> icon
|
|
|
|
id <s|''> id
|
|
|
|
items <a|[]> items
|
|
|
|
keyboard <s|''> keyboard
|
|
|
|
menu <o|null> menu
|
|
|
|
position <n|0> position
|
|
|
|
title <a|[]> title
|
2011-05-16 08:24:46 +00:00
|
|
|
self <o> shared private variable
|
|
|
|
@*/
|
|
|
|
|
2011-04-22 22:03:10 +00:00
|
|
|
Ox.MenuItem = function(options, self) {
|
|
|
|
|
2011-06-19 17:48:32 +00:00
|
|
|
self = self || {};
|
|
|
|
var that = Ox.Element('<tr>', self)
|
2011-04-22 22:03:10 +00:00
|
|
|
.defaults({
|
|
|
|
bind: [], // fixme: what's this?
|
|
|
|
checked: null,
|
|
|
|
disabled: false,
|
|
|
|
group: '',
|
|
|
|
icon: '',
|
|
|
|
id: '',
|
|
|
|
items: [],
|
|
|
|
keyboard: '',
|
2011-11-02 18:21:49 +00:00
|
|
|
maxWidth: 0,
|
2011-04-22 22:03:10 +00:00
|
|
|
menu: null, // fixme: is passing the menu to 100s of menu items really memory-neutral?
|
|
|
|
position: 0,
|
|
|
|
title: [],
|
2012-03-24 10:13:33 +00:00
|
|
|
type: ''
|
2011-04-22 22:03:10 +00:00
|
|
|
})
|
2011-09-19 06:33:52 +00:00
|
|
|
.options(Ox.extend(Ox.clone(options), {
|
2011-04-22 22:03:10 +00:00
|
|
|
keyboard: parseKeyboard(options.keyboard || self.defaults.keyboard),
|
2012-05-19 08:40:59 +00:00
|
|
|
title: Ox.makeArray(options.title || self.defaults.title)
|
2011-04-22 22:03:10 +00:00
|
|
|
}))
|
2012-05-28 19:35:41 +00:00
|
|
|
.update({
|
|
|
|
checked: function() {
|
|
|
|
that.$status.html(self.options.checked ? Ox.UI.symbols.check : '')
|
|
|
|
},
|
|
|
|
disabled: function() {
|
|
|
|
that.toggleClass('OxDisabled');
|
|
|
|
},
|
|
|
|
title: function() {
|
|
|
|
self.options.title = Ox.makeArray(self.options.title);
|
|
|
|
that.$title.html(self.options.title[0]);
|
|
|
|
}
|
|
|
|
})
|
2011-11-11 15:48:54 +00:00
|
|
|
.addClass('OxItem' + (self.options.disabled ? ' OxDisabled' : ''))
|
2011-04-22 22:03:10 +00:00
|
|
|
/*
|
|
|
|
.attr({
|
|
|
|
id: Ox.toCamelCase(self.options.menu.options('id') + '/' + self.options.id)
|
|
|
|
})
|
|
|
|
*/
|
|
|
|
.data('group', self.options.group); // fixme: why?
|
|
|
|
|
|
|
|
if (self.options.group && self.options.checked === null) {
|
|
|
|
self.options.checked = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
that.append(
|
2012-03-24 08:43:03 +00:00
|
|
|
that.$status = $('<td>')
|
|
|
|
.addClass('OxCell OxStatus')
|
|
|
|
.html(self.options.checked ? Ox.UI.symbols.check : '')
|
2011-04-22 22:03:10 +00:00
|
|
|
)
|
|
|
|
.append(
|
2012-03-24 08:43:03 +00:00
|
|
|
that.$icon = $('<td>')
|
|
|
|
.addClass('OxCell OxIcon')
|
|
|
|
.append(
|
|
|
|
self.options.icon
|
|
|
|
? $('<img>').attr({src: self.options.icon})
|
|
|
|
: null
|
|
|
|
)
|
2011-04-22 22:03:10 +00:00
|
|
|
)
|
|
|
|
.append(
|
2012-03-24 08:43:03 +00:00
|
|
|
that.$title = $('<td>')
|
|
|
|
.addClass('OxCell OxTitle')
|
|
|
|
.css(
|
|
|
|
self.options.maxWidth
|
2011-11-30 14:37:53 +00:00
|
|
|
? {maxWidth: self.options.maxWidth - 46}
|
2012-03-24 08:43:03 +00:00
|
|
|
: {}
|
|
|
|
)
|
|
|
|
.html(
|
2012-03-24 10:13:33 +00:00
|
|
|
self.options.file
|
|
|
|
?
|
2012-03-24 11:04:27 +00:00
|
|
|
that.$button = Ox.FileButton(Ox.extend(Ox.clone(self.options.file), {
|
2012-03-24 10:13:33 +00:00
|
|
|
title: self.options.title[0],
|
|
|
|
width: self.options.file.width
|
|
|
|
})).bindEvent({
|
|
|
|
click: function(data) {
|
|
|
|
self.options.menu.clickItem(self.options.position, data.files);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
: (
|
|
|
|
Ox.isString(self.options.title[0])
|
|
|
|
? self.options.title[0]
|
|
|
|
: $('<div>').html(self.options.title[0]).html()
|
|
|
|
)
|
2012-03-24 08:43:03 +00:00
|
|
|
)
|
2011-04-22 22:03:10 +00:00
|
|
|
)
|
|
|
|
.append(
|
2012-03-24 10:13:33 +00:00
|
|
|
that.$modifiers = $('<td>')
|
2012-03-24 08:43:03 +00:00
|
|
|
.addClass('OxCell OxModifiers')
|
|
|
|
.html(
|
|
|
|
self.options.keyboard.modifiers.map(function(modifier) {
|
|
|
|
return Ox.UI.symbols[modifier];
|
|
|
|
}).join('')
|
|
|
|
)
|
2011-04-22 22:03:10 +00:00
|
|
|
)
|
|
|
|
.append(
|
2012-03-24 10:13:33 +00:00
|
|
|
that.$key = $('<td>')
|
2012-03-24 08:43:03 +00:00
|
|
|
.addClass(
|
|
|
|
'OxCell Ox' + (self.options.items.length ? 'Submenu' : 'Key')
|
|
|
|
)
|
|
|
|
.html(
|
|
|
|
self.options.items.length
|
2011-09-09 10:41:13 +00:00
|
|
|
? Ox.UI.symbols.triangle_right
|
|
|
|
: Ox.UI.symbols[self.options.keyboard.key]
|
2012-03-24 08:43:03 +00:00
|
|
|
|| self.options.keyboard.key.toUpperCase()
|
|
|
|
)
|
2011-04-22 22:03:10 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
function parseKeyboard(str) {
|
|
|
|
var modifiers = str.split(' '),
|
|
|
|
key = modifiers.pop();
|
|
|
|
return {
|
|
|
|
modifiers: modifiers,
|
|
|
|
key: key
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
that.toggle = function() {
|
|
|
|
// toggle id and title
|
|
|
|
};
|
|
|
|
|
2011-05-16 10:49:48 +00:00
|
|
|
/*@
|
2011-09-09 10:41:13 +00:00
|
|
|
toggleChecked <f> toggleChecked
|
2011-05-16 10:49:48 +00:00
|
|
|
@*/
|
2011-04-22 22:03:10 +00:00
|
|
|
that.toggleChecked = function() {
|
2011-09-09 10:41:13 +00:00
|
|
|
that.options({checked: !self.options.checked});
|
|
|
|
return that;
|
2011-04-22 22:03:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
that.toggleDisabled = function() {
|
|
|
|
|
|
|
|
};
|
2011-05-16 10:49:48 +00:00
|
|
|
|
|
|
|
/*@
|
2011-09-09 10:41:13 +00:00
|
|
|
toggleTitle <f> toggleTitle
|
2011-05-16 10:49:48 +00:00
|
|
|
@*/
|
2011-04-22 22:03:10 +00:00
|
|
|
that.toggleTitle = function() {
|
2011-10-04 02:26:24 +00:00
|
|
|
that.options({title: Ox.clone(self.options.title).reverse()});
|
2011-09-09 10:41:13 +00:00
|
|
|
return that;
|
2011-04-22 22:03:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return that;
|
|
|
|
|
|
|
|
};
|