Skip to content
This repository has been archived by the owner on Dec 7, 2021. It is now read-only.

Commit

Permalink
v1.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Mobius1 committed Oct 22, 2016
1 parent 9dd52d2 commit 7bab296
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
19 changes: 10 additions & 9 deletions selectr.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* Selectr 1.0.3
* Selectr 1.0.4
* http://mobiuswebdesign.co.uk/plugins/selectr
*
* Released under the MIT license
Expand Down Expand Up @@ -117,7 +117,8 @@ String.prototype.includes||(String.prototype.includes=function(a,b){"use strict"

this.options = extend(defaults, opts);

this.hasTemplate = this.options.hasOwnProperty('render') && typeof this.options.render === 'function';
this.customOption = this.options.hasOwnProperty('renderOption') && typeof this.options.renderOption === 'function';
this.customSelected = this.options.hasOwnProperty('renderSelection') && typeof this.options.renderSelection === 'function';

this.initialise();
}
Expand Down Expand Up @@ -335,7 +336,7 @@ String.prototype.includes||(String.prototype.includes=function(a,b){"use strict"
{
if ( option === this.emptyOpt || option.nodeName !== 'OPTION' || !option.value ) return;

var content = this.hasTemplate ? this.options.render(option) : option.textContent.trim();
var content = this.customOption ? this.options.renderOption(option) : option.textContent.trim();
var opt = _newElement('li', { class: 'selectr-option', html: content });

if ( option.hasAttribute('selected') ) {
Expand Down Expand Up @@ -521,7 +522,7 @@ String.prototype.includes||(String.prototype.includes=function(a,b){"use strict"

_this.searchList.push(opt);

if ( _this.hasTemplate ) {
if ( _this.customOption ) {
_addClass(opt, 'match');
} else {
let result = new RegExp(val2, 'i').exec(val);
Expand Down Expand Up @@ -611,7 +612,7 @@ String.prototype.includes||(String.prototype.includes=function(a,b){"use strict"
let old = _this.optsOptions.getElementsByClassName('selected')[0];
if ( old ) _removeClass(old, 'selected');

_this.txt.innerHTML = _this.hasTemplate ? _this.options.render(option) : option.textContent;
_this.txt.innerHTML = _this.customSelected ? _this.options.renderSelection(option) : option.textContent;

option.selected = true;
_addClass(selected, 'selected');
Expand Down Expand Up @@ -792,7 +793,7 @@ String.prototype.includes||(String.prototype.includes=function(a,b){"use strict"
if ( selectItem ) {
content = this.options.ajax.formatSelected(selectItem) || option.getAttribute('data-text') || option.textContent;
} else {
content = this.hasTemplate ? this.options.render(option) : option.textContent
content = this.customSelected ? this.options.renderSelection(option) : option.textContent
}

let tag = _newElement('li', { class: 'selectr-tag', html: content });
Expand Down Expand Up @@ -884,7 +885,7 @@ String.prototype.includes||(String.prototype.includes=function(a,b){"use strict"
var _this = this;
forEach(this.list, function(i, elem) {
let option = _this.opts[i];
elem.innerHTML = _this.hasTemplate ? _this.options.render(option) : option.textContent;
elem.innerHTML = _this.customOption ? _this.options.renderOption(option) : option.textContent;
_removeClass(elem, 'match');
_removeClass(elem, 'excluded');
});
Expand Down Expand Up @@ -970,7 +971,7 @@ String.prototype.includes||(String.prototype.includes=function(a,b){"use strict"
_this.createTag(_this.opts[index]);
}
} else {
_this.txt.innerHTML = _this.hasTemplate ? _this.options.render(_this.opts[index]) : _this.opts[index].textContent;
_this.txt.innerHTML = _this.customOption ? _this.options.renderOption(_this.opts[index]) : _this.opts[index].textContent;

let old = _this.optsOptions.getElementsByClassName('selected')[0];
if ( old ) {
Expand Down Expand Up @@ -1016,7 +1017,7 @@ String.prototype.includes||(String.prototype.includes=function(a,b){"use strict"
_this.removeTag(selectedTag);
}
} else {
this.txt.innerHTML = this.hasTemplate ? this.options.render(option) : option.textContent;
this.txt.innerHTML = this.customOption ? this.options.renderOption(option) : option.textContent;
if ( this.elem.selectedIndex !== null ) {
_removeClass(this.list[this.elem.selectedIndex], 'selected');
}
Expand Down
Loading

0 comments on commit 7bab296

Please sign in to comment.