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
|
|
|
|
() -> <f> MenuItem Object
|
|
|
|
(options) -> <f> MenuItem Object
|
|
|
|
(options, self) -> <f> MenuItem Object
|
|
|
|
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),
|
|
|
|
title: Ox.toArray(options.title || self.defaults.title)
|
|
|
|
}))
|
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
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2011-05-16 10:49:48 +00:00
|
|
|
/*@
|
|
|
|
setOption <f> setOption
|
|
|
|
@*/
|
2011-04-29 12:40:51 +00:00
|
|
|
self.setOption = function(key, value) {
|
2011-04-22 22:03:10 +00:00
|
|
|
if (key == 'checked') {
|
|
|
|
that.$status.html(value ? Ox.UI.symbols.check : '')
|
|
|
|
} else if (key == 'disabled') {
|
2011-09-09 10:41:13 +00:00
|
|
|
that.toggleClass('OxDisabled');
|
2011-04-22 22:03:10 +00:00
|
|
|
} else if (key == 'title') {
|
|
|
|
self.options.title = Ox.toArray(value);
|
|
|
|
that.$title.html(self.options.title[0]);
|
|
|
|
}
|
2011-06-19 17:48:32 +00:00
|
|
|
};
|
2011-04-22 22:03:10 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
};
|