")
li.appendTo(ul);
li.data('object', nextData);
li.bind("click", this.selectionHandler);
}
};
Dropdown.DEFAULTS = {
textAttr: 'name', //The attribute of the data elements to use for the name. This can also be a function that takes the data object and returns the text.
defaultText: '', //The initial text if no selection is made. This will be taken from the
selectionClass: '', //The class to use for the selected element in the dropdown list.
buttonStyling: '',
buttonClasses: 'btn btn-default dropdown-toggle',
caretClasses: 'caret',
listItemClasses: ''
};
Dropdown.prototype.getSelection = Dropdown.prototype.getSelected = function() {
return this.$selected.data('object');
};
Dropdown.prototype.setSelection = Dropdown.prototype.setSelected = function(object) {
var listElements = this.$element.find("li");
for(var index = 0; index < listElements.length; index++) {
if($(listElements[index]).data('object').id == object.id) {
this.$selected = $(listElements[index]);
this.$selected.addClass(this.options.selectionClass).siblings().removeClass(this.options.selectionClass);
this.$textSpan.text(this.$selected.text());
break;
}
}
};
$.fn.buildDropdown = function(data, options) {
for(var index = 0; index < this.length; index++) {
var $next = $(this[index]);
var nextDropdown = new Dropdown($next, data, options);
$next.data("dropdown", nextDropdown);
}
}
$.fn.dropdown = function() {
if(this.length > 0) {
return $(this[0]).data('dropdown');
}
}
})(jQuery);