mobius1-selectr
Advanced tools
Comparing version 2.1.3 to 2.1.4
{ | ||
"name": "mobius1-selectr", | ||
"version": "2.1.3", | ||
"version": "2.1.4", | ||
"ignore": [ | ||
@@ -5,0 +5,0 @@ ".gitattributes", |
/*! | ||
* Selectr 2.1.3 | ||
* Selectr 2.1.4 | ||
* http://mobius.ovh/docs/selectr | ||
@@ -7,2 +7,2 @@ * | ||
*/ | ||
!function(a,b){var c="Selectr";"function"==typeof define&&define.amd?define([],b(c)):"object"==typeof exports?module.exports=b(c):a[c]=b(c)}(this,function(a){"use strict";function v(a,b){if(null===a)throw new Error("Selectr requires an element to work.");if(this.el=a,"string"==typeof this.el&&(this.el=document.querySelector(a)),null===this.el)throw new Error("The element you passed to Selectr can not be found.");if("select"!==this.el.nodeName.toLowerCase())throw new Error("The element you passed to Selectr is not a HTMLSelectElement.");if(!this.el.options.length&&!b.data&&!b.taggable)throw new Error("You don't have any options in your select!");this.originalType=this.el.type,this.render(b)}var b={extend:function(a,b){b=b||{};var c;for(c in a)b.hasOwnProperty(c)||(b[c]=a[c]);return b},each:function(a,b,c){if("[object Object]"===Object.prototype.toString.call(a))for(var d in a)Object.prototype.hasOwnProperty.call(a,d)&&b.call(c,d,a[d],a);else for(var e=0,f=a.length;e<f;e++)b.call(c,e,a[e],a)},createElement:function(a,b){var c=document,d=c.createElement(a);if(b&&"object"==typeof b){var e;for(e in b)if("html"===e)d.innerHTML=b[e];else if("text"===e){var f=c.createTextNode(b[e]);d.appendChild(f)}else d.setAttribute(e,b[e])}return d},hasClass:function(a,b){return a.classList?a.classList.contains(b):!!a.className&&!!a.className.match(new RegExp("(\\s|^)"+b+"(\\s|$)"))},addClass:function(a,c){b.hasClass(a,c)||(a.classList?a.classList.add(c):a.className=a.className.trim()+" "+c)},removeClass:function(a,c){b.hasClass(a,c)&&(a.classList?a.classList.remove(c):a.className=a.className.replace(new RegExp("(^|\\s)"+c.split(" ").join("|")+"(\\s|$)","gi")," "))},closest:function(a,c){return a&&a!==document.body&&(c(a)?a:b.closest(a.parentNode,c))},on:function(a,b,c,d){a.addEventListener(b,c,d||!1)},off:function(a,b,c){a.removeEventListener(b,c)},isObject:function(a){return"[object Object]"===Object.prototype.toString.call(a)},isArray:function(a){return"[object Array]"===Object.prototype.toString.call(a)},isInt:function(a){return!isNaN(a)&&function(a){return(a||0)===a}(parseFloat(a))},debounce:function(a,b,c){var d;return function(){var e=this,f=arguments,g=function(){d=null,c||a.apply(e,f)},h=c&&!d;clearTimeout(d),d=setTimeout(g,b),h&&a.apply(e,f)}},getBoundingRect:function(a,b){var c=window,d=a.getBoundingClientRect(),e=b?c.pageXOffset:0,f=b?c.pageYOffset:0;return{bottom:d.bottom+f,height:d.height,left:d.left+e,right:d.right+e,top:d.top+f,width:d.width}},preventDefault:function(a){if(a=a||window.event,a.preventDefault)return a.preventDefault()},includes:function(a,b){return a.indexOf(b)>-1}},c=function(){var a=this.settings,c=this.el.options;if(a.selectedValue){var d=a.selectedValue.toString();b.each(c,function(a,c){b.includes(d,c.value)&&(c.defaultSelected=!0)})}!c[0].defaultSelected&&c[0].selected&&(this.el.selectedIndex=-1)},d=function(){var a=this.settings.width;a&&(b.isInt(a)?a+="px":"auto"===a?a="100%":b.includes(this.settings.width,"%")&&(a=this.settings.width),this.width=a)},e=function(){var a=this,e=a.settings;if(b.addClass(a.el,"hidden-input"),e.data){a.pageIndex=1;var h=e.pagination?e.data.slice(0,e.pagination):e.data,i=!1;b.each(h,function(b,c){var d=c.hasOwnProperty("selected")&&c.selected===!0,e=new Option(c.text,c.value,d,d);c.disabled&&(e.disabled=!0),0===b&&d&&(i=!0),a.el.add(e)}),i||(this.el.selectedIndex=-1),e.pagination&&(this.pages=e.data.map(function(a,b){return b%e.pagination===0?e.data.slice(b,b+e.pagination):null}).filter(function(a){return a}))}c.call(a),a.customOption=e.hasOwnProperty("renderOption")&&"function"==typeof e.renderOption,a.customSelected=e.hasOwnProperty("renderSelection")&&"function"==typeof e.renderSelection,a.container=b.createElement("div",{class:"selectr-container"}),e.customClass&&b.addClass(a.container,e.customClass),d.call(a),this.container.style.width=this.width,a.selected=b.createElement("div",{class:"selectr-selected",tabIndex:a.el.tabIndex}),a.el.tabIndex=-1,a.label=b.createElement(a.el.multiple?"ul":"span",{class:"selectr-label"});var j=b.createElement("div",{class:"selectr-options-container"});if(a.optsOptions=b.createElement("ul",{class:"selectr-options"}),a.notice=b.createElement("div",{class:"selectr-notice"}),a.el.multiple&&(b.addClass(a.label,"selectr-tags"),b.addClass(a.container,"multiple"),this.tags=[],this.selectedValues=[],this.selectedIndexes=[]),a.selected.appendChild(a.label),(a.el.multiple&&e.clearable||!a.el.multiple&&e.allowDeselect)&&(a.selectClear=b.createElement("button",{class:"selectr-clear",type:"button"}),a.selected.appendChild(a.selectClear)),e.taggable){var k=b.createElement("li",{class:"input-tag"});a.input=b.createElement("input",{class:"selectr-tag-input",placeholder:"Enter a tag...",tagIndex:0}),k.appendChild(a.input),a.label.appendChild(k),b.addClass(a.container,"taggable"),this.tagSeperators=[","],a.settings.tagSeperators&&(this.tagSeperators=this.tagSeperators.concat(a.settings.tagSeperators))}if(e.searchable&&(a.input=b.createElement("input",{class:"selectr-input",tagIndex:-1}),a.inputClear=b.createElement("button",{class:"selectr-clear",type:"button"}),a.inputContainer=b.createElement("div",{class:"selectr-input-container"}),a.inputContainer.appendChild(a.input),a.inputContainer.appendChild(a.inputClear),j.appendChild(a.inputContainer)),a.hasOptGroups){var l=0;b.addClass(a.optsOptions,"optgroups")}var m=0;b.each(a.el.children,function(c,d){if("OPTGROUP"===d.nodeName){var g=b.createElement("ul",{class:"selectr-optgroup"});g.appendChild(b.createElement("li",{class:"selectr-optgroup--label",text:d.label})),a.optsOptions.appendChild(g),d.children&&b.each(d.children,function(b,c){e.pagination&&e.data&&l>=e.pagination||(f.call(a,l,c,g),l++)})}else{if(e.pagination&&e.data&&m>=e.pagination)return;f.call(a,m,d),m++}}),b.addClass(a.list[a.activeIdx],"active"),j.appendChild(a.notice),j.appendChild(a.optsOptions),a.container.appendChild(a.selected),a.container.appendChild(j);var n=e.placeholder||a.el.getAttribute("placeholder")||"Choose...";a.placeEl=b.createElement("div",{class:"selectr-placeholder",html:n}),a.selected.appendChild(a.placeEl),a.el.parentNode.insertBefore(a.container,a.el),a.container.appendChild(a.el),g.call(this)},f=function(a,c,d){if("OPTION"===c.nodeName&&c.value){var e=this.customOption?this.settings.renderOption(c):c.textContent.trim(),f=b.createElement("li",{class:"selectr-option",html:e});f.idx=a,this.items.push(f),c.defaultSelected&&h.call(this,a,!0),c.disabled&&(f.disabled=!0,b.addClass(f,"disabled")),d?d.appendChild(f):this.optsOptions.appendChild(f),c.disabled||this.list.push(f)}},g=function(){var a=this;this.events={},this.events.keyup=n.bind(a),this.events.navigate=o.bind(a),this.events.dismiss=r.bind(a),a.requiresPagination=a.settings.data&&a.settings.data.length>a.settings.pagination,b.on(a.container,"click",function(c){c=c||window.event;var d=c.target,e=b.closest(d,function(b){return b&&b==a.selected});if(d!==a.input){if(a.settings.clearable&&d===a.selectClear)return void a.clear();if(b.hasClass(d,"selectr-tag-remove")&&j.call(a,d.parentNode.idx),d!==a.label&&d!==a.placeEl||(d=a.placeEl.parentNode),(e||d===a.selected)&&a.toggle(),b.hasClass(d,"selectr-option")){var f=a.items.indexOf(d);h.call(a,f)}b.preventDefault(c)}}),b.on(a.optsOptions,"mousedown",function(a){b.preventDefault(a)}),a.settings.searchable&&b.on(a.inputClear,"click",function(b){m.call(a)}),b.on(document,"click",this.events.dismiss),b.on(document,"keydown",this.events.navigate),b.on(document,"keyup",this.events.keyup),a.update=b.debounce(function(){a.opened&&a.settings.closeOnScroll&&a.close(),this.width&&(this.container.style.width=this.width),q.call(a)},50),b.on(window,"resize",a.update),b.on(window,"scroll",a.update),a.requiresPagination&&(a.paginateItems=b.debounce(function(){p.call(a)},50),b.on(a.optsOptions,"scroll",a.paginateItems))},h=function(a,c){var d=this,e=d.items[a],f=d.el.options[a];if(!f.disabled){if(c)return void i.call(d,a);b.hasClass(e,"selected")?j.call(d,a):i.call(d,a),d.opened&&!d.el.multiple&&d.close()}},i=function(a){var c=this.el.options[a];if(this.el.multiple){if(b.includes(this.selectedIndexes,a))return!1;var d=this.settings.maxSelections;if(d&&this.tags.length==d)return this.setMessage("A maximum of "+d+" items can be selected.",!0),!1;this.selectedValues.push(c.value),this.selectedIndexes.push(a),k.call(this,a)}else this.label.innerHTML=this.customSelected?this.settings.renderSelection(c):c.textContent,this.selectedValue=c.value,this.selectedIndex=a,b.each(this.el.options,function(c,d){var e=this.items[c];c!==a&&(e&&b.removeClass(e,"selected"),d.defaultSelected=!1)},this);b.addClass(this.items[a],"selected"),b.addClass(this.container,"has-selected"),c.defaultSelected=!0,this.emit("selectr.select",c),this.emit("selectr.change",c)},j=function(a){var c=this.el.options[a];if(this.el.multiple){var d=this.selectedIndexes.indexOf(a);this.selectedIndexes.splice(d,1);var e=this.selectedValues.indexOf(c.value);this.selectedValues.splice(e,1),l.call(this,a),this.tags.length||b.removeClass(this.container,"has-selected")}else{if(!this.settings.allowDeselect)return!1;this.label.innerHTML="",this.selectedValue=null,this.el.selectedIndex=-1,b.removeClass(this.container,"has-selected")}b.removeClass(this.items[a],"selected"),c.defaultSelected=!1,this.emit("selectr.deselect",c),this.emit("selectr.change",c)},k=function(a){var c=this,d=document.createDocumentFragment(),e=c.el.options[a],f=c.customSelected?c.settings.renderSelection(e):e.textContent,g=b.createElement("li",{class:"selectr-tag",html:f}),h=b.createElement("button",{class:"selectr-tag-remove",type:"button"});if(g.appendChild(h),g.idx=a,g.tag=e.value,c.tags.push(g),c.settings.sortSelected){var i=c.tags.slice();i.sort(function(a,b){var f,g,d=[],e=[];for(c.settings.sortSelected===!0?(f=a.tag,g=b.tag):"text"===c.settings.sortSelected&&(f=a.textContent,g=b.textContent),f.replace(/(\d+)|(\D+)/g,function(a,b,c){d.push([b||1/0,c||""])}),g.replace(/(\d+)|(\D+)/g,function(a,b,c){e.push([b||1/0,c||""])});d.length&&e.length;){var h=d.shift(),i=e.shift(),j=h[0]-i[0]||h[1].localeCompare(i[1]);if(j)return j}return d.length-e.length}),b.each(i,function(a,b){d.appendChild(b)}),c.label.innerHTML=""}else d.appendChild(g);c.settings.taggable?c.label.insertBefore(d,c.input.parentNode):c.label.appendChild(d)},l=function(a){var c=!1;if(b.each(this.tags,function(b,d){d.idx===a&&(c=d)}),c){this.label.removeChild(c);var d=this.tags.indexOf(c);this.tags.splice(d,1)}},m=function(){var a=this;(a.settings.searchable||a.settings.taggable)&&(a.input.value=null,a.searching=!1,a.settings.searchable&&b.removeClass(a.inputContainer,"active"),b.hasClass(a.container,"notice")&&(b.removeClass(a.container,"notice"),b.addClass(a.container,"open"),a.input.focus()),b.each(a.list,function(c,d){b.removeClass(d,"match"),b.removeClass(d,"excluded"),a.customOption||(d.innerHTML=d.textContent)}))},n=function(a){var c=this;if(a.target===c.input&&c.search(c.input.value,!0),c.navigating&&13!==a.keyCode&&(c.navigating=!1),c.settings.taggable&&c.input.value.length){var d=c.input.value.trim();if(c.searchItems.length)return!1;if(13===a.which||b.includes(c.tagSeperators,a.key)){b.each(c.tagSeperators,function(a,b){d=d.replace(b,"")});var e=c.addOption({value:d,text:d,selected:!0});e?(c.close(),m.call(c)):(c.input.value="",c.setMessage("That tag is already in use."))}}},o=function(a){a=a||window.event;var c=this,d=a.which,e=[13,38,40];if(c.opened&&b.includes(e,d)){b.preventDefault(a);var g,f=this.searching?this.searchItems:this.list;if(f.length){switch(d){case 13:c.settings.taggable&&c.input===document.activeElement&&(c.input.value="");var i=c.optsOptions.querySelector(".active"),j=c.items.indexOf(i);return void h.call(c,j);case 38:g=1,c.activeIdx>0&&c.activeIdx--;break;case 40:g=-1,c.activeIdx<f.length-1&&c.activeIdx++}this.navigating=!0;var o,q,k=f[c.activeIdx],l=b.getBoundingRect(k),m=c.optsOptions.scrollTop,n=c.optsRect.top;if(g>0){var r=l.top;o=n,q=m+(r-o),0===c.activeIdx?c.optsOptions.scrollTop=0:r-o<0&&(c.optsOptions.scrollTop=q)}else{var s=l.top+l.height;o=n+c.optsRect.height,q=m+(s-o),0===c.activeIdx?c.optsOptions.scrollTop=0:s>o&&(c.optsOptions.scrollTop=q),c.requiresPagination&&p.call(c)}b.removeClass(c.optsOptions.querySelector(".active"),"active"),b.addClass(f[c.activeIdx],"active")}}},p=function(){var a=this,c=a.optsOptions,d=c.scrollTop,e=c.scrollHeight,g=c.offsetHeight,h=d>=e-g;if(h&&a.pageIndex<a.pages.length){var i=document.createDocumentFragment(),j=document.createDocumentFragment();b.each(a.pages[a.pageIndex],function(c,d){var e=b.createElement("option",{value:d.value,text:d.text});i.appendChild(e),f.call(a,c,e,j)}),a.el.appendChild(i),c.appendChild(j),a.pageIndex++,a.emit("selectr.paginate",{items:a.items.length,total:a.settings.data.length,page:a.pageIndex,pages:a.pages.length})}},q=function(){var a=b.getBoundingRect(this.selected),c=this.optsOptions.parentNode.offsetHeight,d=window.innerHeight,e=a.top+a.height+c>d;e?(b.addClass(this.container,"inverted"),this.isInverted=!0):(b.removeClass(this.container,"inverted"),this.isInverted=!1),this.optsRect=b.getBoundingRect(this.optsOptions)},r=function(a){var b=a.target;this.container.contains(b)||!this.opened&&!this.container.classList.contains("notice")||this.close()},s=function(a,b,c){var d=new RegExp(a,"i").exec(c);return!!d&&b.textContent.replace(d[0],"<span>"+d[0]+"</span>")},t=function(){};t.prototype={on:function(a,b){this._events=this._events||{},this._events[a]=this._events[a]||[],this._events[a].push(b)},off:function(a,b){this._events=this._events||{},a in this._events!=!1&&this._events[a].splice(this._events[a].indexOf(b),1)},emit:function(a){if(this._events=this._events||{},a in this._events!=!1)for(var b=0;b<this._events[a].length;b++)this._events[a][b].apply(this,Array.prototype.slice.call(arguments,1))}},t.mixin=function(a){for(var b=["on","off","emit"],c=0;c<b.length;c++)"function"==typeof a?a.prototype[b[c]]=t.prototype[b[c]]:a[b[c]]=t.prototype[b[c]];return a};var u={width:"auto",searchable:!0,clearable:!1,sortSelected:!1,allowDeselect:!1,closeOnScroll:!1};return v.prototype.render=function(a){if(!this.rendered){this.settings=b.extend(u,a),(this.settings.multiple||this.settings.taggable)&&(this.el.multiple=!0),this.settings.taggable&&(this.settings.searchable=!1),this.hasOptGroups=!1,this.el.getElementsByTagName("optgroup").length&&(this.hasOptGroups=!0),this.items=[],this.list=[],this.activeIdx=0,this.navigating=!1,t.mixin(this),e.call(this),this.update(),this.optsRect=b.getBoundingRect(this.optsOptions),this.rendered=!0;var c=this;setTimeout(function(){c.emit("selectr.init")},20)}},v.prototype.destroy=function(){if(this.rendered){if(this.emit("selectr.destroy"),this.settings.data)for(;this.el.hasChildNodes();)this.el.removeChild(this.el.lastChild);"select-one"===this.originalType&&(this.el.multiple=!1),b.removeClass(this.el,"hidden-input"),b.off(document,"click",this.events.dismiss),b.off(document,"keydown",this.events.navigate),b.off(document,"keyup",this.events.keyup),b.off(window,"resize",this.update),b.off(window,"scroll",this.update),this.container.parentNode.replaceChild(this.el,this.container),this.rendered=!1}},v.prototype.setValue=function(a){var c=this,d=b.isArray(a);return d||(a=a.toString().trim()),!(!c.el.multiple&&d)&&void b.each(this.el.options,function(e,f){(d&&b.includes(a.toString(),f.value)||f.value===a)&&h.call(c,e)})},v.prototype.getValue=function(a,c){var e,d=this;if(d.el.multiple)a?d.selectedIndexes.length&&(e={},e.values=[],b.each(d.selectedIndexes,function(a,b){var c=d.el.options[b];e.values[a]={value:c.value,text:c.textContent}})):e=d.selectedValues.slice();else if(a){var f=d.el.options[d.selectedIndex];e={value:f.value,text:f.textContent}}else e=d.selectedValue;return a&&c&&(e=JSON.stringify(e)),e},v.prototype.addOption=function(a){var c=this;if(a&&b.isObject(a)&&a.value){var d=c.settings.data?c.settings.data:c.el.options,e=!1;if(b.each(d,function(b,c){c.value.toLowerCase()===a.value.toLowerCase()&&(e=!0)}),e){if(!c.settings.taggable)throw new Error("That value is already in use.");return!1}var g=b.createElement("option",a);return c.settings.data&&c.settings.data.push({value:a.value,text:a.text}),a.selected&&(g.defaultSelected=!0),g.innerHTML=c.customOption?c.settings.renderOption(g):g.textContent,c.settings.pagination||(c.el.add(g),f.call(c,c.el.options.length-1,g)),g}return!1},v.prototype.search=function(a,c){a=a.trim();var d=this;if(!d.navigating){if(b.hasClass(d.container,"notice")||d.settings.searchable&&(a.length>0?b.addClass(d.inputContainer,"active"):b.removeClass(d.inputContainer,"active")),d.searching=!0,d.searchItems=[],d.searchQuery=a,b.each(d.items,function(e,f){var g=f.textContent.trim(),h=b.includes(g.toLowerCase(),a.toLowerCase());f.disabled||!h?(b.addClass(f,"excluded"),b.removeClass(f,"match")):(d.searchItems.push(f),c&&(d.customOption||(f.innerHTML=s(a,f,g)),b.addClass(f,"match"),b.removeClass(f,"excluded")))}),c)d.searchItems.length||d.settings.taggable?d.open():(d.setMessage("No results."),d.input.focus());else if(d.searchItems.length){var e={};return e.values=[],b.each(d.searchItems,function(a,b){var c=d.el.options[b.idx];e.values[a]={value:c.value,text:c.textContent}}),e}d.emit("selectr.search",a,d.searchItems)}},v.prototype.toggle=function(){if(!this.disabled){var a=b.hasClass(this.container,"open");a?this.close():this.open()}},v.prototype.open=function(){var a=this;b.addClass(a.container,"open"),q.call(a);var c=this.optsOptions.scrollHeight;c<=a.optsRect.height&&a.requiresPagination&&p.call(a),b.removeClass(a.container,"notice"),a.settings.searchable&&!a.settings.taggable&&setTimeout(function(){a.input.focus(),a.input.tabIndex=0},10),this.opened||a.emit("selectr.open"),a.opened=!0},v.prototype.close=function(){var a=b.hasClass(this.container,"notice");this.settings.searchable&&!a&&(this.input.blur(),this.input.tabIndex=-1,this.searching=!1),a&&(b.removeClass(this.container,"notice"),this.notice.textContent=""),b.removeClass(this.container,"open"),m.call(this),this.opened&&this.emit("selectr.close"),this.opened=!1},v.prototype.reset=function(a){this.clear(),c.call(this),b.each(this.el.options,function(a,b){b.defaultSelected&&h.call(this,a)},this),this.emit("selectr.reset")},v.prototype.clear=function(a){if(this.el.multiple){var c=this.selectedIndexes.slice();b.each(c,function(a,b){j.call(this,b)},this)}else j.call(this,this.selectedIndex);this.emit("selectr.clear")},v.prototype.serialise=function(a){var c=[];return b.each(this.el.options,function(a,b){var d={value:b.value,text:b.textContent};b.defaultSelected&&(d.selected=!0),b.disabled&&(d.disabled=!0),c[a]=d}),a?JSON.stringify(c):c},v.prototype.serialize=function(a){return this.serialise(a)},v.prototype.setMessage=function(a,c){c&&this.close(),b.addClass(this.container,"notice"),this.notice.textContent=a},v}); | ||
!function(a,b){var c="Selectr";"function"==typeof define&&define.amd?define([],b(c)):"object"==typeof exports?module.exports=b(c):a[c]=b(c)}(this,function(a){"use strict";function v(a,b){if(null===a)throw new Error("Selectr requires an element to work.");if(this.el=a,"string"==typeof this.el&&(this.el=document.querySelector(a)),null===this.el)throw new Error("The element you passed to Selectr can not be found.");if("select"!==this.el.nodeName.toLowerCase())throw new Error("The element you passed to Selectr is not a HTMLSelectElement.");if(!this.el.options.length&&!b.data&&!b.taggable)throw new Error("You don't have any options in your select!");this.originalType=this.el.type,this.render(b)}var b={extend:function(a,b){b=b||{};var c;for(c in a)b.hasOwnProperty(c)||(b[c]=a[c]);return b},each:function(a,b,c){if("[object Object]"===Object.prototype.toString.call(a))for(var d in a)Object.prototype.hasOwnProperty.call(a,d)&&b.call(c,d,a[d],a);else for(var e=0,f=a.length;e<f;e++)b.call(c,e,a[e],a)},createElement:function(a,b){var c=document,d=c.createElement(a);if(b&&"object"==typeof b){var e;for(e in b)if("html"===e)d.innerHTML=b[e];else if("text"===e){var f=c.createTextNode(b[e]);d.appendChild(f)}else d.setAttribute(e,b[e])}return d},hasClass:function(a,b){return a.classList?a.classList.contains(b):!!a.className&&!!a.className.match(new RegExp("(\\s|^)"+b+"(\\s|$)"))},addClass:function(a,c){b.hasClass(a,c)||(a.classList?a.classList.add(c):a.className=a.className.trim()+" "+c)},removeClass:function(a,c){b.hasClass(a,c)&&(a.classList?a.classList.remove(c):a.className=a.className.replace(new RegExp("(^|\\s)"+c.split(" ").join("|")+"(\\s|$)","gi")," "))},closest:function(a,c){return a&&a!==document.body&&(c(a)?a:b.closest(a.parentNode,c))},on:function(a,b,c,d){a.addEventListener(b,c,d||!1)},off:function(a,b,c){a.removeEventListener(b,c)},isObject:function(a){return"[object Object]"===Object.prototype.toString.call(a)},isArray:function(a){return"[object Array]"===Object.prototype.toString.call(a)},isInt:function(a){return!isNaN(a)&&function(a){return(a||0)===a}(parseFloat(a))},debounce:function(a,b,c){var d;return function(){var e=this,f=arguments,g=function(){d=null,c||a.apply(e,f)},h=c&&!d;clearTimeout(d),d=setTimeout(g,b),h&&a.apply(e,f)}},getBoundingRect:function(a,b){var c=window,d=a.getBoundingClientRect(),e=b?c.pageXOffset:0,f=b?c.pageYOffset:0;return{bottom:d.bottom+f,height:d.height,left:d.left+e,right:d.right+e,top:d.top+f,width:d.width}},preventDefault:function(a){if(a=a||window.event,a.preventDefault)return a.preventDefault()},includes:function(a,b){return a.indexOf(b)>-1}},c=function(a){var c=this.settings,d=this.el.options;if(c.selectedValue){var e=c.selectedValue.toString();b.each(d,function(a,c){b.includes(e,c.value)&&(c.defaultSelected=!0)})}!d[0].defaultSelected&&d[0].selected&&(this.el.selectedIndex=-1),a&&c.data&&b.each(c.data,function(a,c){var e=c.hasOwnProperty("selected")&&c.selected===!0;b.each(d,function(a,b){b.value===c.value&&e&&(b.defaultSelected=!0)})})},d=function(){var a=this.settings.width;a&&(b.isInt(a)?a+="px":"auto"===a?a="100%":b.includes(this.settings.width,"%")&&(a=this.settings.width),this.width=a)},e=function(){var a=this,e=a.settings;if(b.addClass(a.el,"hidden-input"),e.data){a.pageIndex=1;var h=e.pagination?e.data.slice(0,e.pagination):e.data,i=!1;b.each(h,function(b,c){var d=c.hasOwnProperty("selected")&&c.selected===!0,e=new Option(c.text,c.value,d,d);c.disabled&&(e.disabled=!0),0===b&&d&&(i=!0),a.el.add(e)}),i||(this.el.selectedIndex=-1),e.pagination&&(this.pages=e.data.map(function(a,b){return b%e.pagination===0?e.data.slice(b,b+e.pagination):null}).filter(function(a){return a}))}c.call(a),a.customOption=e.hasOwnProperty("renderOption")&&"function"==typeof e.renderOption,a.customSelected=e.hasOwnProperty("renderSelection")&&"function"==typeof e.renderSelection,a.container=b.createElement("div",{class:"selectr-container"}),e.customClass&&b.addClass(a.container,e.customClass),d.call(a),this.container.style.width=this.width,a.selected=b.createElement("div",{class:"selectr-selected",tabIndex:a.el.tabIndex}),a.el.tabIndex=-1,a.label=b.createElement(a.el.multiple?"ul":"span",{class:"selectr-label"});var j=b.createElement("div",{class:"selectr-options-container"});if(a.optsOptions=b.createElement("ul",{class:"selectr-options"}),a.notice=b.createElement("div",{class:"selectr-notice"}),a.el.multiple&&(b.addClass(a.label,"selectr-tags"),b.addClass(a.container,"multiple"),this.tags=[],this.selectedValues=[],this.selectedIndexes=[]),a.selected.appendChild(a.label),(a.el.multiple&&e.clearable||!a.el.multiple&&e.allowDeselect)&&(a.selectClear=b.createElement("button",{class:"selectr-clear",type:"button"}),a.selected.appendChild(a.selectClear)),e.taggable){var k=b.createElement("li",{class:"input-tag"});a.input=b.createElement("input",{class:"selectr-tag-input",placeholder:"Enter a tag...",autocomplete:"off",tagIndex:0}),k.appendChild(a.input),a.label.appendChild(k),b.addClass(a.container,"taggable"),this.tagSeperators=[","],a.settings.tagSeperators&&(this.tagSeperators=this.tagSeperators.concat(a.settings.tagSeperators))}if(e.searchable&&(a.input=b.createElement("input",{class:"selectr-input",autocomplete:"off",tagIndex:-1}),a.inputClear=b.createElement("button",{class:"selectr-clear",type:"button"}),a.inputContainer=b.createElement("div",{class:"selectr-input-container"}),a.inputContainer.appendChild(a.input),a.inputContainer.appendChild(a.inputClear),j.appendChild(a.inputContainer)),a.hasOptGroups){var l=0;b.addClass(a.optsOptions,"optgroups")}var m=0;b.each(a.el.children,function(c,d){if("OPTGROUP"===d.nodeName){var g=b.createElement("ul",{class:"selectr-optgroup"});g.appendChild(b.createElement("li",{class:"selectr-optgroup--label",text:d.label})),a.optsOptions.appendChild(g),d.children&&b.each(d.children,function(b,c){e.pagination&&e.data&&l>=e.pagination||(f.call(a,l,c,g),l++)})}else{if(e.pagination&&e.data&&m>=e.pagination)return;f.call(a,m,d),m++}}),b.addClass(a.list[a.activeIdx],"active"),j.appendChild(a.notice),j.appendChild(a.optsOptions),a.container.appendChild(a.selected),a.container.appendChild(j);var n=e.placeholder||a.el.getAttribute("placeholder")||"Choose...";a.placeEl=b.createElement("div",{class:"selectr-placeholder",html:n}),a.selected.appendChild(a.placeEl),a.el.parentNode.insertBefore(a.container,a.el),a.container.appendChild(a.el),g.call(this)},f=function(a,c,d){if("OPTION"===c.nodeName&&c.value){var e=this.customOption?this.settings.renderOption(c):c.textContent.trim(),f=b.createElement("li",{class:"selectr-option",html:e});f.idx=a,this.items.push(f),c.defaultSelected&&h.call(this,a,!0),c.disabled&&(f.disabled=!0,b.addClass(f,"disabled")),d?d.appendChild(f):this.optsOptions.appendChild(f),c.disabled||this.list.push(f)}},g=function(){var a=this;this.events={},this.events.keyup=n.bind(a),this.events.navigate=o.bind(a),this.events.dismiss=r.bind(a),a.requiresPagination=a.settings.data&&a.settings.data.length>a.settings.pagination,b.on(a.container,"click",function(c){c=c||window.event;var d=c.target,e=b.closest(d,function(b){return b&&b==a.selected});if(d!==a.input){if(a.settings.clearable&&d===a.selectClear)return void a.clear();if(b.hasClass(d,"selectr-tag-remove")&&j.call(a,d.parentNode.idx),d!==a.label&&d!==a.placeEl||(d=a.placeEl.parentNode),(e||d===a.selected)&&a.toggle(),b.hasClass(d,"selectr-option")){var f=a.items.indexOf(d);h.call(a,f)}b.preventDefault(c)}}),b.on(a.optsOptions,"mousedown",function(a){b.preventDefault(a)}),a.settings.searchable&&b.on(a.inputClear,"click",function(b){m.call(a)}),b.on(document,"click",this.events.dismiss),b.on(document,"keydown",this.events.navigate),b.on(document,"keyup",this.events.keyup),a.update=b.debounce(function(){a.opened&&a.settings.closeOnScroll&&a.close(),this.width&&(this.container.style.width=this.width),q.call(a)},50),b.on(window,"resize",a.update),b.on(window,"scroll",a.update),a.requiresPagination&&(a.paginateItems=b.debounce(function(){p.call(a)},50),b.on(a.optsOptions,"scroll",a.paginateItems));var c=a.el.form;c&&b.on(c,"reset",a.reset.bind(a))},h=function(a,c){var d=this,e=d.items[a],f=d.el.options[a];if(!f.disabled){if(c)return void i.call(d,a);b.hasClass(e,"selected")?j.call(d,a):i.call(d,a),d.opened&&!d.el.multiple&&d.close()}},i=function(a){var c=this.el.options[a];if(this.el.multiple){if(b.includes(this.selectedIndexes,a))return!1;var d=this.settings.maxSelections;if(d&&this.tags.length==d)return this.setMessage("A maximum of "+d+" items can be selected.",!0),!1;this.selectedValues.push(c.value),this.selectedIndexes.push(a),k.call(this,a)}else this.label.innerHTML=this.customSelected?this.settings.renderSelection(c):c.textContent,this.selectedValue=c.value,this.selectedIndex=a,b.each(this.el.options,function(c,d){var e=this.items[c];c!==a&&(e&&b.removeClass(e,"selected"),d.defaultSelected=!1)},this);b.addClass(this.items[a],"selected"),b.addClass(this.container,"has-selected"),c.defaultSelected=!0,this.emit("selectr.select",c),this.emit("selectr.change",c)},j=function(a){var c=this.el.options[a];if(this.el.multiple){var d=this.selectedIndexes.indexOf(a);this.selectedIndexes.splice(d,1);var e=this.selectedValues.indexOf(c.value);this.selectedValues.splice(e,1),l.call(this,a),this.tags.length||b.removeClass(this.container,"has-selected")}else{if(!this.settings.allowDeselect)return!1;this.label.innerHTML="",this.selectedValue=null,this.el.selectedIndex=-1,b.removeClass(this.container,"has-selected")}b.removeClass(this.items[a],"selected"),c.defaultSelected=!1,this.emit("selectr.deselect",c),this.emit("selectr.change",c)},k=function(a){var c=this,d=document.createDocumentFragment(),e=c.el.options[a],f=c.customSelected?c.settings.renderSelection(e):e.textContent,g=b.createElement("li",{class:"selectr-tag",html:f}),h=b.createElement("button",{class:"selectr-tag-remove",type:"button"});if(g.appendChild(h),g.idx=a,g.tag=e.value,c.tags.push(g),c.settings.sortSelected){var i=c.tags.slice();i.sort(function(a,b){var f,g,d=[],e=[];for(c.settings.sortSelected===!0?(f=a.tag,g=b.tag):"text"===c.settings.sortSelected&&(f=a.textContent,g=b.textContent),f.replace(/(\d+)|(\D+)/g,function(a,b,c){d.push([b||1/0,c||""])}),g.replace(/(\d+)|(\D+)/g,function(a,b,c){e.push([b||1/0,c||""])});d.length&&e.length;){var h=d.shift(),i=e.shift(),j=h[0]-i[0]||h[1].localeCompare(i[1]);if(j)return j}return d.length-e.length}),b.each(i,function(a,b){d.appendChild(b)}),c.label.innerHTML=""}else d.appendChild(g);c.settings.taggable?c.label.insertBefore(d,c.input.parentNode):c.label.appendChild(d)},l=function(a){var c=!1;if(b.each(this.tags,function(b,d){d.idx===a&&(c=d)}),c){this.label.removeChild(c);var d=this.tags.indexOf(c);this.tags.splice(d,1)}},m=function(){var a=this;(a.settings.searchable||a.settings.taggable)&&(a.input.value=null,a.searching=!1,a.settings.searchable&&b.removeClass(a.inputContainer,"active"),b.hasClass(a.container,"notice")&&(b.removeClass(a.container,"notice"),b.addClass(a.container,"open"),a.input.focus()),b.each(a.list,function(c,d){b.removeClass(d,"match"),b.removeClass(d,"excluded"),a.customOption||(d.innerHTML=d.textContent)}))},n=function(a){var c=this;if(a.target===c.input&&c.search(c.input.value,!0),c.navigating&&13!==a.keyCode&&(c.navigating=!1),c.settings.taggable&&c.input.value.length){var d=c.input.value.trim();if(c.searchItems.length)return!1;if(13===a.which||b.includes(c.tagSeperators,a.key)){b.each(c.tagSeperators,function(a,b){d=d.replace(b,"")});var e=c.addOption({value:d,text:d,selected:!0});e?(c.close(),m.call(c)):(c.input.value="",c.setMessage("That tag is already in use."))}}},o=function(a){a=a||window.event;var c=this,d=a.which,e=[13,38,40];if(c.opened&&b.includes(e,d)){b.preventDefault(a);var g,f=this.searching?this.searchItems:this.list;if(f.length){switch(d){case 13:c.settings.taggable&&c.input===document.activeElement&&(c.input.value="");var i=c.optsOptions.querySelector(".active"),j=c.items.indexOf(i);return void h.call(c,j);case 38:g=1,c.activeIdx>0&&c.activeIdx--;break;case 40:g=-1,c.activeIdx<f.length-1&&c.activeIdx++}this.navigating=!0;var o,q,k=f[c.activeIdx],l=b.getBoundingRect(k),m=c.optsOptions.scrollTop,n=c.optsRect.top;if(g>0){var r=l.top;o=n,q=m+(r-o),0===c.activeIdx?c.optsOptions.scrollTop=0:r-o<0&&(c.optsOptions.scrollTop=q)}else{var s=l.top+l.height;o=n+c.optsRect.height,q=m+(s-o),0===c.activeIdx?c.optsOptions.scrollTop=0:s>o&&(c.optsOptions.scrollTop=q),c.requiresPagination&&p.call(c)}b.removeClass(c.optsOptions.querySelector(".active"),"active"),b.addClass(f[c.activeIdx],"active")}}},p=function(){var a=this,c=a.optsOptions,d=c.scrollTop,e=c.scrollHeight,g=c.offsetHeight,h=d>=e-g;if(h&&a.pageIndex<a.pages.length||a.activeIdx===a.list.length-1){var i=document.createDocumentFragment(),j=document.createDocumentFragment();b.each(a.pages[a.pageIndex],function(c,d){var e=b.createElement("option",{value:d.value,text:d.text});i.appendChild(e),f.call(a,c,e,j)}),a.el.appendChild(i),c.appendChild(j),a.pageIndex++,a.emit("selectr.paginate",{items:a.items.length,total:a.settings.data.length,page:a.pageIndex,pages:a.pages.length})}},q=function(){var a=b.getBoundingRect(this.selected),c=this.optsOptions.parentNode.offsetHeight,d=window.innerHeight,e=a.top+a.height+c>d;e?(b.addClass(this.container,"inverted"),this.isInverted=!0):(b.removeClass(this.container,"inverted"),this.isInverted=!1),this.optsRect=b.getBoundingRect(this.optsOptions)},r=function(a){var b=a.target;this.container.contains(b)||!this.opened&&!this.container.classList.contains("notice")||this.close()},s=function(a,b,c){var d=new RegExp(a,"i").exec(c);return!!d&&b.textContent.replace(d[0],"<span>"+d[0]+"</span>")},t=function(){};t.prototype={on:function(a,b){this._events=this._events||{},this._events[a]=this._events[a]||[],this._events[a].push(b)},off:function(a,b){this._events=this._events||{},a in this._events!=!1&&this._events[a].splice(this._events[a].indexOf(b),1)},emit:function(a){if(this._events=this._events||{},a in this._events!=!1)for(var b=0;b<this._events[a].length;b++)this._events[a][b].apply(this,Array.prototype.slice.call(arguments,1))}},t.mixin=function(a){for(var b=["on","off","emit"],c=0;c<b.length;c++)"function"==typeof a?a.prototype[b[c]]=t.prototype[b[c]]:a[b[c]]=t.prototype[b[c]];return a};var u={width:"auto",searchable:!0,clearable:!1,sortSelected:!1,allowDeselect:!1,closeOnScroll:!1};return v.prototype.render=function(a){if(!this.rendered){this.settings=b.extend(u,a),(this.settings.multiple||this.settings.taggable)&&(this.el.multiple=!0),this.settings.taggable&&(this.settings.searchable=!1),this.hasOptGroups=!1,this.el.getElementsByTagName("optgroup").length&&(this.hasOptGroups=!0),this.items=[],this.list=[],this.activeIdx=0,this.navigating=!1,t.mixin(this),e.call(this),this.update(),this.optsRect=b.getBoundingRect(this.optsOptions),this.rendered=!0;var c=this;setTimeout(function(){c.emit("selectr.init")},20)}},v.prototype.destroy=function(){if(this.rendered){if(this.emit("selectr.destroy"),this.settings.data)for(;this.el.hasChildNodes();)this.el.removeChild(this.el.lastChild);"select-one"===this.originalType&&(this.el.multiple=!1),b.removeClass(this.el,"hidden-input"),b.off(document,"click",this.events.dismiss),b.off(document,"keydown",this.events.navigate),b.off(document,"keyup",this.events.keyup),b.off(window,"resize",this.update),b.off(window,"scroll",this.update),this.container.parentNode.replaceChild(this.el,this.container),this.rendered=!1}},v.prototype.setValue=function(a){var c=this,d=b.isArray(a);return d||(a=a.toString().trim()),!(!c.el.multiple&&d)&&void b.each(this.el.options,function(e,f){(d&&b.includes(a.toString(),f.value)||f.value===a)&&h.call(c,e)})},v.prototype.getValue=function(a,c){var e,d=this;if(d.el.multiple)a?d.selectedIndexes.length&&(e={},e.values=[],b.each(d.selectedIndexes,function(a,b){var c=d.el.options[b];e.values[a]={value:c.value,text:c.textContent}})):e=d.selectedValues.slice();else if(a){var f=d.el.options[d.selectedIndex];e={value:f.value,text:f.textContent}}else e=d.selectedValue;return a&&c&&(e=JSON.stringify(e)),e},v.prototype.addOption=function(a){var c=this;if(a&&b.isObject(a)&&a.value){var d=c.settings.data?c.settings.data:c.el.options,e=!1;if(b.each(d,function(b,c){c.value.toLowerCase()===a.value.toLowerCase()&&(e=!0)}),e){if(!c.settings.taggable)throw new Error("That value is already in use.");return!1}var g=b.createElement("option",a);return c.settings.data&&c.settings.data.push({value:a.value,text:a.text}),a.selected&&(g.defaultSelected=!0),g.innerHTML=c.customOption?c.settings.renderOption(g):g.textContent,c.settings.pagination||(c.el.add(g),f.call(c,c.el.options.length-1,g)),g}return!1},v.prototype.search=function(a,c){a=a.trim();var d=this;if(!d.navigating){if(b.hasClass(d.container,"notice")||d.settings.searchable&&(a.length>0?b.addClass(d.inputContainer,"active"):b.removeClass(d.inputContainer,"active")),d.searching=!0,d.searchItems=[],d.searchQuery=a,b.each(d.items,function(e,f){var g=f.textContent.trim(),h=b.includes(g.toLowerCase(),a.toLowerCase());f.disabled||!h?(b.addClass(f,"excluded"),b.removeClass(f,"match")):(d.searchItems.push(f),c&&(d.customOption||(f.innerHTML=s(a,f,g)),b.addClass(f,"match"),b.removeClass(f,"excluded")))}),c)d.searchItems.length||d.settings.taggable?d.open():(d.setMessage("No results."),d.input.focus());else if(d.searchItems.length){var e={};return e.values=[],b.each(d.searchItems,function(a,b){var c=d.el.options[b.idx];e.values[a]={value:c.value,text:c.textContent}}),e}d.emit("selectr.search",a,d.searchItems)}},v.prototype.toggle=function(){if(!this.disabled){var a=b.hasClass(this.container,"open");a?this.close():this.open()}},v.prototype.open=function(){var a=this;b.addClass(a.container,"open"),q.call(a);var c=this.optsOptions.scrollHeight;c<=a.optsRect.height&&a.requiresPagination&&p.call(a),b.removeClass(a.container,"notice"),a.settings.searchable&&!a.settings.taggable&&setTimeout(function(){a.input.focus(),a.input.tabIndex=0},10),this.opened||a.emit("selectr.open"),a.opened=!0},v.prototype.close=function(){var a=b.hasClass(this.container,"notice");this.settings.searchable&&!a&&(this.input.blur(),this.input.tabIndex=-1,this.searching=!1),a&&(b.removeClass(this.container,"notice"),this.notice.textContent=""),b.removeClass(this.container,"open"),m.call(this),this.opened&&this.emit("selectr.close"),this.opened=!1},v.prototype.reset=function(a){this.clear(),c.call(this,!0),b.each(this.el.options,function(a,b){b.defaultSelected&&h.call(this,a)},this),this.emit("selectr.reset")},v.prototype.clear=function(a){if(this.el.multiple){var c=this.selectedIndexes.slice();b.each(c,function(a,b){j.call(this,b)},this)}else j.call(this,this.selectedIndex);this.emit("selectr.clear")},v.prototype.serialise=function(a){var c=[];return b.each(this.el.options,function(a,b){var d={value:b.value,text:b.textContent};b.defaultSelected&&(d.selected=!0),b.disabled&&(d.disabled=!0),c[a]=d}),a?JSON.stringify(c):c},v.prototype.serialize=function(a){return this.serialise(a)},v.prototype.setMessage=function(a,c){c&&this.close(),b.addClass(this.container,"notice"),this.notice.textContent=a},v}); |
{ | ||
"name": "mobius1-selectr", | ||
"version": "2.1.3", | ||
"version": "2.1.4", | ||
"description": "A lightweight dependency-free javascript select box replacement.", | ||
@@ -5,0 +5,0 @@ "main": "dist/selectr.min.js", |
@@ -39,5 +39,5 @@ # Selectr [![Build Status](https://travis-ci.org/Mobius1/Selectr.svg?branch=master)](https://travis-ci.org/Mobius1/Selectr) [![npm version](https://badge.fury.io/js/mobius1-selectr.svg)](https://badge.fury.io/js/mobius1-selectr) [![license](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/Mobius1/Selectr/blob/master/LICENSE) | ||
```html | ||
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/selectr/2.1.2/selectr.min.css"> | ||
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/selectr/2.1.3/selectr.min.css"> | ||
<script type="text/javascript" src="https://cdn.jsdelivr.net/selectr/2.1.2/selectr.min.js"></script> | ||
<script type="text/javascript" src="https://cdn.jsdelivr.net/selectr/2.1.3/selectr.min.js"></script> | ||
``` | ||
@@ -66,6 +66,4 @@ | ||
You can then instantiate Selectr by passing a reference to your select box as the first parameter: | ||
You can then instantiate Selectr by passing a reference to your select box as the first parameter as either a DOM node or a CSS3 selector string: | ||
You can either pass a DOM node or a CSS3 selector string: | ||
```javascript | ||
@@ -79,8 +77,8 @@ new Selectr(document.getElementById('#mySelect')); | ||
Selectr accepts a second parameter as an object with the options you want to set: | ||
Selectr accepts the options object as a second parameter: | ||
```javascript | ||
new Selectr('#mySelect', { | ||
searchable: false, | ||
width: 300 | ||
searchable: false, | ||
width: 300 | ||
}); | ||
@@ -93,2 +91,7 @@ ``` | ||
### v2.1.4 | ||
* Fixed form.reset() not clearing Selectr elements ([#13](https://github.com/Mobius1/Selectr/issues/13)) | ||
* Fixed autocomplete bug in Chrome ([#12](https://github.com/Mobius1/Selectr/issues/12)) | ||
* Fixed pagination not incrementing when navigating with the down key | ||
### v2.1.3 | ||
@@ -127,30 +130,2 @@ * Fixed bug with tagging system | ||
### v2.0.0 | ||
* Complete rewrite | ||
* New options added | ||
* New methods added | ||
* New events added | ||
Updated functions: | ||
* `getValue()` (see [docs](http://mobius.ovh/docs/selectr/pages/functions)) | ||
* `setValue()` (see [docs](http://mobius.ovh/docs/selectr/pages/functions)) | ||
Added options: | ||
* `clearable` (see [docs](http://mobius.ovh/docs/selectr/pages/options)) | ||
* `sortSelected` (see [docs](http://mobius.ovh/docs/selectr/pages/options)) | ||
Updated options: | ||
* `selectedValue` is now used for both single and multi selects (see [docs](http://mobius.ovh/docs/selectr/pages/options)) | ||
Removed options: | ||
* `ajax` | ||
* `minChars` | ||
* `emptyOption` | ||
* `selectedValues` | ||
* `selectedIndex, selectedIndexes` | ||
Removed events: | ||
* `selectr.change` (see [docs](http://mobius.ovh/docs/selectr/pages/events)) | ||
# License | ||
@@ -157,0 +132,0 @@ |
/*! | ||
* Selectr 2.1.3 | ||
* Selectr 2.1.4 | ||
* http://mobius.ovh/docs/selectr | ||
@@ -128,3 +128,3 @@ * | ||
var setSelected = function() { | ||
var setSelected = function(reset) { | ||
var o = this.settings; | ||
@@ -145,2 +145,16 @@ var opts = this.el.options; | ||
} | ||
// Check the original data for selected options on form.reset() | ||
if ( reset ) { | ||
if ( o.data ) { | ||
util.each(o.data, function(idx, itm) { | ||
var selected = itm.hasOwnProperty('selected') && itm.selected === true; | ||
util.each(opts, function(i, opt) { | ||
if ( opt.value === itm.value && selected ) { | ||
opt.defaultSelected = true; | ||
} | ||
}); | ||
}); | ||
} | ||
} | ||
}; | ||
@@ -275,3 +289,4 @@ | ||
class: "selectr-tag-input", | ||
placeholder: 'Enter a tag...', | ||
placeholder: "Enter a tag...", | ||
autocomplete: "off", | ||
tagIndex: 0 | ||
@@ -293,2 +308,3 @@ }); | ||
class: "selectr-input", | ||
autocomplete: "off", | ||
tagIndex: -1 | ||
@@ -488,2 +504,8 @@ }); | ||
} | ||
// Listen for form.reset() (#13) | ||
var form = _.el.form; | ||
if ( form ) { | ||
util.on(form, "reset", _.reset.bind(_)); | ||
} | ||
}; | ||
@@ -832,3 +854,3 @@ | ||
if ( atBottom && _.pageIndex < _.pages.length ) { | ||
if ( (atBottom && _.pageIndex < _.pages.length) || _.activeIdx === _.list.length - 1 ) { | ||
var selectFrag = document.createDocumentFragment(); | ||
@@ -1325,3 +1347,3 @@ var optsFrag = document.createDocumentFragment(); | ||
setSelected.call(this); | ||
setSelected.call(this, true); | ||
@@ -1328,0 +1350,0 @@ util.each(this.el.options, function(i,opt) { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
73660
1616
135