Here is the best solution using HTML5 data attributes . You need to change the code written in the jquery.dropkick-1.0.0.js as follows (line numbers apply only to v1.0.0 ):
// Line 39 -- Add "<img>" // HTML template for the dropdowns dropdownTemplate = [ '<div class="dk_container" id="dk_container_{{ id }}" tabindex="{{ tabindex }}">', '<a class="dk_toggle">', '<span class="dk_label">{{ label }}<img src="{{ icon }}"/></span>', /* << */ '</a>', '<div class="dk_options">', '<ul class="dk_options_inner">', '</ul>', '</div>', '</div>' ].join(''), // Line 51 -- Add "<img>" (string broken down here for readability) // HTML template for dropdown options optionTemplate = '<li class="{{ current }}">' + '<a data-dk-dropdown-value="{{ value }}">{{ text }}' + '<img src="{{ icon }}"/></a></li>'; /* << */
Also add the following line to the plugin options
// Line 98 -- add "data.icon" // Don't do anything if we've already setup dropkick on this element if (data.id) { return $select; } else { data.settings = settings; data.tabindex = tabindex; data.id = id; data.$original = $original; data.$select = $select; data.value = _notBlank($select.val()) || _notBlank($original.attr('value')); data.label = $original.text(); data.options = $options; /* Add this attribute */ data.icon = $original.data('icon'); /* << */ }
Before the next line inside the _build function
// Line 318 if (view.options && view.options.length) {
Add the following line:
// Line 317. To be placed after other "template = template.replace" statements template = template.replace('{{ icon }}', view.icon);
Finally, inside the loop after
Add the following line
// To be placed after other "oTemplate = oTemplate.replace" statements oTemplate = oTemplate.replace('{{ icon }}', view.icon);
This may not be the best monkeypatching practice, as the code may break if the icon attribute is not set.
I advise you to add code to check the attribute value of the icon attribute and create two templates: one for the parameter and the other for the default drop-down list. Then you can choose which template to use. The same can be said about the _build function, since when using monkeypatching it depends on the value of view.icon (if it is defined or not).