From 3093e0e6843e3c441c456690c5e413ffa4d60d1b Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Mon, 24 Jun 2019 05:13:49 +0300 Subject: [PATCH] bugfix + some refactoring... Signed-off-by: Alex A. Naanou --- ui (gen4)/lib/widget/browse2.js | 53 ++++++++++++++++----------------- 1 file changed, 25 insertions(+), 28 deletions(-) diff --git a/ui (gen4)/lib/widget/browse2.js b/ui (gen4)/lib/widget/browse2.js index a9f7d683..b32514f5 100755 --- a/ui (gen4)/lib/widget/browse2.js +++ b/ui (gen4)/lib/widget/browse2.js @@ -771,6 +771,21 @@ var BaseBrowserPrototype = { //skipDisabledMode: 'node', updateTimeout: 30, + + // Element templates... + // + // Format: + // { + // : , + // ... + // } + // + // If make(..) gets passed it will construct the base element + // via and merge the item options into that. + // + // format is the same as the format passed to make(..) + elementTemplate: { + }, }, @@ -1187,8 +1202,10 @@ var BaseBrowserPrototype = { // build the item... var item = new this.__item__( - // XXX do we need this??? - //options || {}, + // populate the element from template, if present... + opts.value in (options.elementTemplate || {}) ? + options.elementTemplate[opts.value] + : {}, opts, { parent: this }) @@ -3295,25 +3312,7 @@ var HTMLBrowserPrototype = { headerItemButtons: [ ], - // Shorthand elements... - // - // Format: - // { - // : { - // class: , - // html: , - // }, - // ... - // } - // - // If make(..) gets passed it will construct and element - // via with an optional - // - // NOTE: .class is optional... - // NOTE: set this to null to disable shorthands... - // NOTE: currently the options in the template will override - // anything explicitly given by item options... (XXX revise) - elementShorthand: { + elementTemplate: { ' ': { 'class': 'separator', 'html': '
', @@ -3791,11 +3790,8 @@ var HTMLBrowserPrototype = { : (target.innerHTML = value) return target } - // special-case: item shorthands... - if(item.value in (options.elementShorthand || {})){ - // XXX need to merge and not overwrite -- revise... - Object.assign(item, options.elementShorthand[item.value]) - + // special-case: item.html... + if(item.html){ // NOTE: this is a bit of a cheat, but it saves us from either // parsing or restricting the format... var tmp = document.createElement('div') @@ -3805,7 +3801,6 @@ var HTMLBrowserPrototype = { ...(item['class'] instanceof Array ? item['class'] : item['class'].split(/\s+/g))) - return elem } @@ -3847,7 +3842,9 @@ var HTMLBrowserPrototype = { // values... text != null - && (item.value instanceof Array ? item.value : [item.value]) + && (item.value instanceof Array ? + item.value + : [item.value]) // handle $keys and other stuff... .map(function(v){ // handle key-shortcuts $K...