From 9821be2569a560fbb39d276f3daa059db52109c8 Mon Sep 17 00:00:00 2001 From: Alexandros Sigalas Date: Fri, 22 Feb 2019 15:58:06 +0200 Subject: [PATCH] select-cat widget: add different class per level to allow different styling for each category level --- api/js/etemplate/et2_widget_selectbox.js | 10 ++++++++-- api/src/Etemplate/Widget/Select.php | 4 +++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/api/js/etemplate/et2_widget_selectbox.js b/api/js/etemplate/et2_widget_selectbox.js index b4fb4f4ecb..98cdd1b885 100644 --- a/api/js/etemplate/et2_widget_selectbox.js +++ b/api/js/etemplate/et2_widget_selectbox.js @@ -246,8 +246,9 @@ var et2_selectbox = (function(){ "use strict"; return et2_inputWidget.extend( * @param {string} _label label of option * @param {string} _title title attribute of 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 == "")) { 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")) .attr("value", _value) .text(_label+""); + + option.addClass(_class); + if (this.options.tags && this._type == 'select-cat') { 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, _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 diff --git a/api/src/Etemplate/Widget/Select.php b/api/src/Etemplate/Widget/Select.php index 98773c29e4..499771fa8e 100644 --- a/api/src/Etemplate/Widget/Select.php +++ b/api/src/Etemplate/Widget/Select.php @@ -605,7 +605,9 @@ class Select extends Etemplate\Widget // These are extra info for easy dealing with categories // client side, without extra loading '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 if(is_array($cat['data']))