Merge pull request #57 from asig2016/add_class_to_dropdown

select-cat widget: add different class per level to allow different …
This commit is contained in:
Ralf Becker 2019-03-12 14:55:30 +01:00 committed by GitHub
commit 7160990b4f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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} _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

View File

@ -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']))