Skip to content

Propagate option title attributes #183

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 31 additions & 15 deletions jquery.selectBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,10 @@
arrow = $('<span class="selectBox-arrow" />');

// Update label
label.attr('class', this.getLabelClass()).html(this.getLabelHtml());
label
.attr('class', this.getLabelClass())
.attr('title', this.getLabelTitle())
.html(this.getLabelHtml());
options = this.getOptions('dropdown');
options.appendTo('BODY');

Expand Down Expand Up @@ -354,6 +357,17 @@
return ('selectBox-label ' + (selected.attr('class') || '')).replace(/\s+$/, '');
};

/**
* Returns the current title of the selected option.
*
* @returns {String}
*/
SelectBox.prototype.getLabelTitle = function () {
var selected = $(this.selectElement).find('OPTION:selected');

return selected.attr('title') || '';
};

/**
* Returns the current label of the selected option.
*
Expand All @@ -372,7 +386,7 @@

/**
* Sets the label.
* This method uses the getLabelClass() and getLabelHtml() methods.
* This method uses the getLabelClass(), getLabelTitle(), and getLabelHtml() methods.
*/
SelectBox.prototype.setLabel = function () {
var select = $(this.selectElement);
Expand All @@ -384,6 +398,7 @@
control
.find('.selectBox-label')
.attr('class', this.getLabelClass())
.attr('title', this.getLabelTitle())
.html(this.getLabelHtml());
};

Expand Down Expand Up @@ -509,10 +524,10 @@
// Add Top and Bottom class based on position
.addClass('selectBox-options selectBox-options-'+(posTop?'top':'bottom'));

if (settings.styleClass) {
options.addClass(settings.styleClass);
}
if (settings.styleClass) {
options.addClass(settings.styleClass);
}

if (select.triggerHandler('beforeopen')) {
return false;
}
Expand Down Expand Up @@ -1018,11 +1033,12 @@
SelectBox.prototype.generateOptions = function (self, options) {
var li = $('<li />'), a = $('<a />');
li.addClass(self.attr('class'));
li.attr('title', self.attr('title'));
li.data(self.data());
if (self.data('icon')) {
a.attr('rel', self.val()).html('<i class="fa fa-'+self.data('icon')+' fa-fw fa-lg"></i> '+self.text());
} else {
a.attr('rel', self.val()).text(self.text());
a.attr('rel', self.val()).text(self.text());
}
li.append(a);
if (self.attr('disabled')) {
Expand All @@ -1047,8 +1063,8 @@
setOptions : function (options) {
var select = $(this)
, control = select.data('selectBox-control');


switch (typeof(options)) {
case 'string':
select.html(options);
Expand Down Expand Up @@ -1077,12 +1093,12 @@
// Refresh the control
$(this).selectBox('refresh');
// Remove old options

}
},



selectBox: function (method, options) {
var selectBox;

Expand All @@ -1099,11 +1115,11 @@
break;
case 'options':
// Getter

if (undefined === options) {
return $(this).data('selectBox-control').data('selectBox-options');
}

// Setter
$(this).each(function () {
$(this).setOptions(options);
Expand Down