select-cat widget: add different class per level to allow different styling for each category level

This commit is contained in:
Alexandros Sigalas 2019-02-22 15:58:06 +02:00
parent 431f3fb48a
commit 9821be2569
2 changed files with 11 additions and 3 deletions

View File

@ -246,8 +246,9 @@ var et2_selectbox = (function(){ "use strict"; return et2_inputWidget.extend(
* @param {string} _label label of option * @param {string} _label label of option
* @param {string} _title title attribute of option * @param {string} _title title attribute of option
* @param {node} dom_element parent of new option * @param {node} dom_element parent of new option
* @param {string} _class specify classes of option
*/ */
_appendOptionElement: function(_value, _label, _title, dom_element) { _appendOptionElement: function(_value, _label, _title, dom_element, _class) {
if(_value == "" && (_label == null || _label == "")) { if(_value == "" && (_label == null || _label == "")) {
return; // empty_label is added in set_select_options anyway, ignoring it here to not add it twice return; // empty_label is added in set_select_options anyway, ignoring it here to not add it twice
} }
@ -260,6 +261,9 @@ var et2_selectbox = (function(){ "use strict"; return et2_inputWidget.extend(
var option = jQuery(document.createElement("option")) var option = jQuery(document.createElement("option"))
.attr("value", _value) .attr("value", _value)
.text(_label+""); .text(_label+"");
option.addClass(_class);
if (this.options.tags && this._type == 'select-cat') if (this.options.tags && this._type == 'select-cat')
{ {
option.addClass('cat_'+_value); option.addClass('cat_'+_value);
@ -856,7 +860,9 @@ var et2_selectbox = (function(){ "use strict"; return et2_inputWidget.extend(
{ {
this._appendOptionElement(typeof _options[key].value != 'undefined' ? _options[key].value : key, this._appendOptionElement(typeof _options[key].value != 'undefined' ? _options[key].value : key,
_options[key]["label"] ? _options[key]["label"] : "", _options[key]["label"] ? _options[key]["label"] : "",
_options[key]["title"] ? _options[key]["title"] : ""); _options[key]["title"] ? _options[key]["title"] : "",
'',
_options[key]["class"] ? _options[key]["class"] : "");
} }
} }
else else

View File

@ -605,7 +605,9 @@ class Select extends Etemplate\Widget
// These are extra info for easy dealing with categories // These are extra info for easy dealing with categories
// client side, without extra loading // client side, without extra loading
'main' => (int)$cat['main'], 'main' => (int)$cat['main'],
'children' => $cat['children'] 'children' => $cat['children'],
//add different class per level to allow different styling for each category level:
'class' => "cat_level". $cat['level']
); );
// Send data too // Send data too
if(is_array($cat['data'])) if(is_array($cat['data']))