Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // define-attribute! :: String, Object, Element -> IO String
- function define_attribute(key, subject, source) {
- var value = source.getAttribute(key) || subject[key]
- return subject[key] = value }
- function make_menu(subject, source) {
- return this._buildMenuObj(source, createId) }
- function make_item(subject, source) {
- var item = make_item(item)
- define_attribute('label', subject, source)
- define_attribute('icon', subject, source)
- return item }
- function build_menu(children) {
- var menuObj = { type: 'menu' }
- menuObj.items = children.map(to_menu_item.bind(this, menuObj))
- return menuObj }
- function to_menu_item(subject, child) {
- return child.nodeName == 'MENU'? make_menu.call(this, subject, child)
- : child.nodeName == 'MENUITEM'? make_item.call(this, subject, child)
- : /* otherwise */ throw Error('Unknow type: ' + child.nodeName) }
- /* -- Original code --
- var menuObj = {
- type: 'menu',
- items: []
- };
- if (menu.getAttribute('label')) {
- menuObj.label = menu.getAttribute('label');
- }
- for (var i = 0, child; child = menu.children[i++];) {
- if (child.nodeName === 'MENU') {
- menuObj.items.push(this._buildMenuObj(child, createId));
- break;
- }
- if (child.nodeName === 'MENUITEM') {
- var menuitem = {id: createId(child), type: 'menuitem'};
- if (child.getAttribute('label')) {
- menuitem.label = child.getAttribute('label');
- }
- if (child.getAttribute('icon')) {
- menuitem.icon = child.getAttribute('icon');
- }
- menuObj.items.push(menuitem);
- }
- }
- return menuObj;
- */
Add Comment
Please, Sign In to add comment