From 1e16db1d35f4882564c41b7784e5ca97d9bca4fd Mon Sep 17 00:00:00 2001 From: farthinker Date: Wed, 27 Jul 2016 21:16:30 +0800 Subject: [PATCH] CHG: Remove DataProvider.getInstance() which is buggy --- CHANGELOG.md | 4 +++ README.md | 15 +++----- bower.json | 2 +- build/publish.coffee | 35 +++++++++---------- dist/simple-select.js | 31 ++++++++--------- dist/simple-select.min.js | 4 +-- package.json | 2 +- src/input.coffee | 4 +-- src/models/data-provider.coffee | 5 --- src/popover.coffee | 3 +- src/simple-select.coffee | 3 ++ styles/simple-select.css | 2 +- test/html-select.coffee | 62 +++++++++++++++++++++++++++++++++ test/input.coffee | 50 ++++++++++++++++++++++++++ 14 files changed, 164 insertions(+), 58 deletions(-) create mode 100644 test/html-select.coffee create mode 100644 test/input.coffee diff --git a/CHANGELOG.md b/CHANGELOG.md index 2cca5cc..61e9b49 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,8 @@ +## V2.1.1 - 2016-07-27 + +* Remove DataProvider.getInstance() which is buggy + ## V2.1.0 - 2016-07-27 * Rewrite the whole component. diff --git a/README.md b/README.md index f39e4b0..b778588 100644 --- a/README.md +++ b/README.md @@ -152,20 +152,15 @@ Now, you are ready to go. If you want to publish new version to npm and bower, please make sure all tests have passed before you publish new version, and you need do these preparations: -* Add new release information in `CHANGELOG.md`. The format of markdown contents will matter, because build scripts will get version and release content from this file by regular expression. You can follow the format of the older release information. +* Check the version number in `bower.json` and `package.json`. -* Put your [personal API tokens](https://github.com/blog/1509-personal-api-tokens) in `/.token.json`, which is required by the build scripts to request [Github API](https://developer.github.com/v3/) for creating new release: +* Add new release information in `CHANGELOG.md`. The format of markdown contents will matter, because build scripts will get version and release content from this file by regular expression. You can follow the format of the older release information. -```json -{ - "github": "[your github personal access token]" -} -``` +* Put your [personal API tokens](https://github.com/blog/1509-personal-api-tokens) in `/.token`, which is required by the build scripts to request [Github API](https://developer.github.com/v3/) for creating new release. -Now you can run `gulp publish` task, which will do these work for you: +* Commit changes and push. -* Get version number from `CHANGELOG.md` and bump it into `package.json` and `bower.json`. -* Get release information from `CHANGELOG.md` and request Github API to create new release. +Now you can run `gulp publish` task, which will request Github API to create new release. If everything goes fine, you can see your release at [https://github.com/mycolorway/simple-select/releases](https://github.com/mycolorway/simple-select/releases). At the End you can publish new version to npm with the command: diff --git a/bower.json b/bower.json index 9c77f3e..4448d7a 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "simple_select", - "version": "2.1.0", + "version": "2.1.1", "homepage": "https://github.com/mycolorway/simple-select", "authors": [ "farthinker " diff --git a/build/publish.coffee b/build/publish.coffee index 3ef7f96..fee1f71 100644 --- a/build/publish.coffee +++ b/build/publish.coffee @@ -2,28 +2,28 @@ gulp = require 'gulp' gutil = require 'gulp-util' fs = require 'fs' request = require 'request' -changelogs = require './helpers/changelogs' +# changelogs = require './helpers/changelogs' handleError = require './helpers/error' compile = require './compile' test = require './test' _ = require 'lodash' -bumpVersion = (done) -> - newVersion = changelogs.lastestVersion - unless newVersion - throw new Error('Publish: Invalid version in CHANGELOG.md') - return - - pkg = require '../package' - pkg.version = newVersion - fs.writeFileSync './package.json', JSON.stringify(pkg, null, 2) - - bowerConfig = require '../bower.json' - bowerConfig.version = newVersion - fs.writeFileSync './bower.json', JSON.stringify(bowerConfig, null, 2) - - done() -bumpVersion.displayName = 'bump-version' +# bumpVersion = (done) -> +# newVersion = changelogs.lastestVersion +# unless newVersion +# throw new Error('Publish: Invalid version in CHANGELOG.md') +# return +# +# pkg = require '../package' +# pkg.version = newVersion +# fs.writeFileSync './package.json', JSON.stringify(pkg, null, 2) +# +# bowerConfig = require '../bower.json' +# bowerConfig.version = newVersion +# fs.writeFileSync './bower.json', JSON.stringify(bowerConfig, null, 2) +# +# done() +# bumpVersion.displayName = 'bump-version' createRelease = (done) -> try @@ -66,7 +66,6 @@ createRelease.displayName = 'create-release' publish = gulp.series [ compile, test, - bumpVersion, createRelease ]..., (done) -> done() diff --git a/dist/simple-select.js b/dist/simple-select.js index c1db113..dd9574d 100644 --- a/dist/simple-select.js +++ b/dist/simple-select.js @@ -1,5 +1,5 @@ /** - * simple-select v2.1.0 + * simple-select v2.1.1 * http://mycolorway.github.io/simple-select * * Copyright Mycolorway Design @@ -120,12 +120,10 @@ HtmlSelect = (function(superClass) { module.exports = HtmlSelect; },{"./models/group.coffee":4}],2:[function(require,module,exports){ -var DataProvider, Input, Item, +var Input, Item, extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, hasProp = {}.hasOwnProperty; -DataProvider = require('./models/data-provider.coffee'); - Item = require('./models/item.coffee'); Input = (function(superClass) { @@ -137,6 +135,7 @@ Input = (function(superClass) { Input.prototype.opts = { el: null, + dataProvider: null, noWrap: false, placeholder: '', selected: false @@ -144,7 +143,7 @@ Input = (function(superClass) { Input.prototype._init = function() { this.el = $(this.opts.el); - this.dataProvider = DataProvider.getInstance(); + this.dataProvider = this.opts.dataProvider; this._render(); return this._bind(); }; @@ -306,7 +305,7 @@ Input = (function(superClass) { module.exports = Input; -},{"./models/data-provider.coffee":3,"./models/item.coffee":5}],3:[function(require,module,exports){ +},{"./models/item.coffee":5}],3:[function(require,module,exports){ var DataProvider, Group, extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, hasProp = {}.hasOwnProperty; @@ -320,10 +319,6 @@ DataProvider = (function(superClass) { return DataProvider.__super__.constructor.apply(this, arguments); } - DataProvider.getInstance = function() { - return this.instance; - }; - DataProvider.prototype.opts = { remote: false, groups: null, @@ -333,11 +328,10 @@ DataProvider = (function(superClass) { DataProvider.prototype._init = function() { this.remote = this.opts.remote; if (this.opts.groups) { - this.setGroupsFromJson(this.opts.groups); + return this.setGroupsFromJson(this.opts.groups); } else if (this.opts.selectEl) { - this.setGroupsFromHtml(this.opts.selectEl); + return this.setGroupsFromHtml(this.opts.selectEl); } - return DataProvider.instance = this; }; DataProvider.prototype._fetch = function(value, callback) { @@ -793,12 +787,10 @@ MultipleInput = (function(superClass) { module.exports = MultipleInput; },{"./input.coffee":2,"./models/item.coffee":5}],7:[function(require,module,exports){ -var DataProvider, Group, Item, Popover, +var Group, Item, Popover, extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, hasProp = {}.hasOwnProperty; -DataProvider = require('./models/data-provider.coffee'); - Group = require('./models/group.coffee'); Item = require('./models/item.coffee'); @@ -815,12 +807,14 @@ Popover = (function(superClass) { Popover.prototype.opts = { el: null, groups: [], + dataProvider: null, onItemRender: null, localse: {} }; Popover.prototype._init = function() { this.el = $(this.opts.el); + this.dataProvider = this.opts.dataProvider; this.groups = this.opts.groups; this._render(); return this._bind(); @@ -980,7 +974,7 @@ Popover = (function(superClass) { module.exports = Popover; -},{"./models/data-provider.coffee":3,"./models/group.coffee":4,"./models/item.coffee":5}],"simple-select":[function(require,module,exports){ +},{"./models/group.coffee":4,"./models/item.coffee":5}],"simple-select":[function(require,module,exports){ var DataProvider, Group, HtmlSelect, Input, Item, MultipleInput, Popover, SimpleSelect, extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, hasProp = {}.hasOwnProperty; @@ -1048,6 +1042,7 @@ SimpleSelect = (function(superClass) { if (this.multiple) { this.input = new MultipleInput({ el: this.wrapper.find('.input'), + dataProvider: this.dataProvider, placeholder: placeholder, selected: this.htmlSelect.getValue() }); @@ -1055,6 +1050,7 @@ SimpleSelect = (function(superClass) { } else { this.input = new Input({ el: this.wrapper.find('.input'), + dataProvider: this.dataProvider, placeholder: placeholder, noWrap: this.opts.noWrap, selected: this.htmlSelect.getValue() @@ -1063,6 +1059,7 @@ SimpleSelect = (function(superClass) { } this.popover = new Popover({ el: this.wrapper.find('.popover'), + dataProvider: this.dataProvider, groups: groups, onItemRender: this.opts.onItemRender, locales: this.locales diff --git a/dist/simple-select.min.js b/dist/simple-select.min.js index 5df16fd..f1b6917 100644 --- a/dist/simple-select.min.js +++ b/dist/simple-select.min.js @@ -1,2 +1,2 @@ -/* simple-select v2.1.0 | (c) Mycolorway Design | MIT License */ -!function(t,e){"object"==typeof module&&module.exports?module.exports=e(require("jquery"),require("simple-module")):(t.SimpleSelect=e(t.jQuery,t.SimpleModule),t.simple=t.simple||{},t.simple.select=function(e){return new t.SimpleSelect(e)},t.simple.select.locales=t.SimpleSelect.locales)}(this,function(t,e){var i=require=function t(e,i,r){function n(s,l){if(!i[s]){if(!e[s]){var u="function"==typeof require&&require;if(!l&&u)return u(s,!0);if(o)return o(s,!0);var p=new Error("Cannot find module '"+s+"'");throw p.code="MODULE_NOT_FOUND",p}var a=i[s]={exports:{}};e[s][0].call(a.exports,function(t){var i=e[s][1][t];return n(i?i:t)},a,a.exports,t,e,i,r)}return i[s].exports}for(var o="function"==typeof require&&require,s=0;s",{text:e.name,value:e.value,data:e.data}).appendTo(i)},i.prototype._render=function(){return this.el.empty(),0===this.groups.length?this.el.append("",{label:r.name}),t.each(r.items,function(t,i){return e._renderOption(i,n)}),e.el.append(n)}}(this)),this.el},i.prototype.setGroups=function(t){return this.groups=t,this._render()},i.prototype.getValue=function(){return this.el.val()},i.prototype.setValue=function(t){return this.el.val(t)},i.prototype.getBlankOption=function(){var t;return t=this.el.find('option:not([value]), option[value=""]'),t.length>0&&t},i}(e),r.exports=s},{"./models/group.coffee":4}],2:[function(i,r,n){var o,s,l,u=function(t,e){function i(){this.constructor=t}for(var r in e)p.call(e,r)&&(t[r]=e[r]);return i.prototype=e.prototype,t.prototype=new i,t.__super__=e.prototype,t},p={}.hasOwnProperty;o=i("./models/data-provider.coffee"),l=i("./models/item.coffee"),s=function(e){function i(){return i.__super__.constructor.apply(this,arguments)}return u(i,e),i.prototype.opts={el:null,noWrap:!1,placeholder:"",selected:!1},i.prototype._init=function(){return this.el=t(this.opts.el),this.dataProvider=o.getInstance(),this._render(),this._bind()},i.prototype._render=function(){return this.el.append('\n\n\n \n\n\n \n'),this.el.find(this.opts.noWrap?"textarea":"input:text").remove(),this.textField=this.el.find(".text-field"),this.textField.attr("placeholder",this.opts.placeholder),this.setSelected(this.opts.selected),this.el},i.prototype._bind=function(){return this.el.on("mousedown",function(t){return function(e){return t.textField.focus(),!1}}(this)),this.el.find(".link-expand").on("mousedown",function(t){return function(e){if(!t.disabled)return t.focused||t.focus(),t.trigger("expandClick"),!1}}(this)),this.el.find(".link-clear").on("mousedown",function(t){return function(e){if(!t.disabled)return t.trigger("clearClick"),!1}}(this)),this.textField.on("keydown.simple-select",function(t){return function(e){var i;return 40===e.which||38===e.which?(e.preventDefault(),i=40===e.which?"down":"up",t.triggerHandler("arrowPress",[i])):13===e.which?(e.preventDefault(),t.triggerHandler("enterPress")):27===e.which?(e.preventDefault(),t.blur()):8===e.which?t._onBackspacePress(e):void 0}}(this)).on("input.simple-select",function(t){return function(e){return t._inputTimer&&(clearTimeout(t._inputTimer),t._inputTimer=null),t._inputTimer=setTimeout(function(){return t._onInputChange()},200)}}(this)).on("blur.simple-select",function(t){return function(e){return t.focused=!1,t.triggerHandler("blur")}}(this)).on("focus.simple-select",function(t){return function(e){return t.focused=!0,t.triggerHandler("focus")}}(this))},i.prototype._onBackspacePress=function(t){if(this.selected)return t.preventDefault(),this.clear()},i.prototype._onInputChange=function(){return this._autoresize(),this.setSelected(!1),this.triggerHandler("change",[this.getValue()])},i.prototype._autoresize=function(){var t,e,i;if(!this.opts.noWrap)return this.textField.css("height",0),i=parseFloat(this.textField[0].scrollHeight),e=parseFloat(this.textField.css("border-top-width")),t=parseFloat(this.textField.css("border-bottom-width")),this.textField.css("height",i+e+t)},i.prototype.setValue=function(t){return this.textField.val(t),this._onInputChange()},i.prototype.getValue=function(){return this.textField.val()},i.prototype.setSelected=function(t){return null==t&&(t=!1),t?(t instanceof l||(t=this.dataProvider.getItem(t)),this.textField.val(t.name),this._autoresize(),this.el.addClass("selected")):this.el.removeClass("selected"),this.selected=t,t},i.prototype.setDisabled=function(t){return null==t&&(t=!1),this.disabled=t,this.textField.prop("disabled",t),this.el.toggleClass("disabled",t),t},i.prototype.focus=function(){return this.textField.focus()},i.prototype.blur=function(){return this.textField.blur()},i.prototype.clear=function(){return this.setValue("")},i}(e),r.exports=s},{"./models/data-provider.coffee":3,"./models/item.coffee":5}],3:[function(i,r,n){var o,s,l=function(t,e){function i(){this.constructor=t}for(var r in e)u.call(e,r)&&(t[r]=e[r]);return i.prototype=e.prototype,t.prototype=new i,t.__super__=e.prototype,t},u={}.hasOwnProperty;s=i("./group.coffee"),o=function(e){function i(){return i.__super__.constructor.apply(this,arguments)}return l(i,e),i.getInstance=function(){return this.instance},i.prototype.opts={remote:!1,groups:null,selectEl:null},i.prototype._init=function(){return this.remote=this.opts.remote,this.opts.groups?this.setGroupsFromJson(this.opts.groups):this.opts.selectEl&&this.setGroupsFromHtml(this.opts.selectEl),i.instance=this},i.prototype._fetch=function(e,i){var r,n;if(this.remote&&this.triggerHandler("beforeFetch")!==!1)return n=function(t){return function(e){return t.setGroupsFromJson(e),t.triggerHandler("fetch",[t.groups]),"function"==typeof i?i(t.groups):void 0}}(this),e?t.ajax({url:this.remote.url,data:t.extend({},this.remote.params,(r={},r[""+this.remote.searchKey]=e,r)),dataType:"json"}).done(function(t){return n(t)}):void n([])},i.prototype.setGroupsFromJson=function(e){if(e)return this.groups=[],t.isArray(e)?this.groups.push(new s({items:e})):t.isPlainObject(e)&&t.each(e,function(t){return function(e,i){return t.groups.push(new s({name:e,items:i}))}}(this)),this.triggerHandler("change",[this.groups]),this.groups},i.prototype.setGroupsFromHtml=function(e){var i,r,n;if(r=t(e),r&&r.length>0)return this.groups=[],n=function(e){var i;return i=[],e.each(function(e,r){var n,o;if(n=t(r),o=n.val())return i.push([n.text(),o,n.data()])}),i},(i=r.find("optgroup")).length>0?i.each(function(e){return function(i,r){var o;return o=t(r),e.groups.push(new s({name:o.attr("label"),items:n(o.find("option"))}))}}(this)):this.groups.push(new s({items:n(r.find("option"))})),this.triggerHandler("change",[this.groups]),this.groups},i.prototype.getGroups=function(){return this.groups},i.prototype.getItem=function(e){var i;return i=null,t.each(this.groups,function(t,r){if(i=r.getItem(e))return!1}),i},i.prototype.getItemByName=function(e){var i;return i=null,t.each(this.groups,function(t,r){if(i=r.getItemByName(e))return!1}),i},i.prototype.filter=function(e,i){var r;return this.remote?this._fetch(e,function(t){return function(){return"function"==typeof i&&i(t.groups,e),t.triggerHandler("filter",[t.groups,e])}}(this)):(r=[],t.each(this.groups,function(t,i){var n;if(n=i.filterItems(e),n.items.length>0)return r.push(n)}),"function"==typeof i&&i(r,e),this.triggerHandler("filter",[r,e])),null},i.prototype.excludeItems=function(e,i){var r;return null==e&&(e=[]),null==i&&(i=this.groups),r=[],t.each(i,function(t,i){var n;if(n=i.excludeItems(e),n.items.length>0)return r.push(n)}),r},i}(e),r.exports=o},{"./group.coffee":4}],4:[function(e,i,r){var n,o;o=e("./item.coffee"),n=function(){function e(i){this.name=i.name||e.defaultName,this.items=[],t.isArray(i.items)&&i.items.length>0&&t.each(i.items,function(e){return function(i,r){return t.isArray(r)&&(r={name:r[0],value:r[1],data:r.length>2?r[2]:null}),e.items.push(new o(r))}}(this))}return e.defaultName="__default__",e.prototype.filterItems=function(i){var r;return r=new e({name:this.name}),t.each(this.items,function(t,e){if(e.match(i))return r.items.push(e)}),r},e.prototype.excludeItems=function(i){var r;return i=i.map(function(t){return t.value}),r=new e({name:this.name}),t.each(this.items,function(t,e){if(i.indexOf(e.value)===-1)return r.items.push(e)}),r},e.prototype.getItem=function(e){var i;return i=null,t.each(this.items,function(t,r){if(r.value===e&&(i=r),i)return!1}),i},e.prototype.getItemByName=function(e){var i;return i=null,t.each(this.items,function(t,r){if(r.name===e&&(i=r),i)return!1}),i},e}(),i.exports=n},{"./item.coffee":5}],5:[function(i,r,n){var o,s=function(t,e){function i(){this.constructor=t}for(var r in e)l.call(e,r)&&(t[r]=e[r]);return i.prototype=e.prototype,t.prototype=new i,t.__super__=e.prototype,t},l={}.hasOwnProperty;o=function(e){function i(e){this.name=e.name,this.value=e.value.toString(),this.data={},t.isPlainObject(e.data)&&t.each(e.data,function(e){return function(i,r){return i=i.replace(/^data-/,"").split("-"),t.each(i,function(t,e){if(t>0)return i[t]=e.charAt(0).toUpperCase()+e.slice(1)}),e.data[i.join()]=r,null}}(this))}return s(i,e),i.prototype.match=function(t){var e,i,r;try{r=new RegExp("(^|\\s)"+t,"i")}catch(t){e=t,r=new RegExp("","i")}return i=this.data.key||this.name,r.test(i)},i}(e),r.exports=o},{}],6:[function(e,i,r){var n,o,s,l=function(t,e){function i(){this.constructor=t}for(var r in e)u.call(e,r)&&(t[r]=e[r]);return i.prototype=e.prototype,t.prototype=new i,t.__super__=e.prototype,t},u={}.hasOwnProperty;o=e("./models/item.coffee"),n=e("./input.coffee"),s=function(e){function i(){return i.__super__.constructor.apply(this,arguments)}return l(i,e),i.prototype.opts={el:null,placeholder:"",selected:!1},i._itemTpl='
\n \n \n
',i.prototype._render=function(){return this.el.append('').addClass("multiple"),this.textField=this.el.find("textarea"),this.textField.attr("placeholder",this.opts.placeholder),t.isArray(this.opts.selected)&&t.each(this.opts.selected,function(t){return function(e,i){return t.addSelected(i)}}(this)),this.el},i.prototype._bind=function(){return i.__super__._bind.call(this),this.el.on("mousedown",".selected-item",function(e){return function(i){var r;return r=t(i.currentTarget),e.triggerHandler("itemClick",[r,r.data("item")]),!1}}(this))},i.prototype._onBackspacePress=function(t){if(!this.getValue())return t.preventDefault(),this.el.find(".selected-item:last").mousedown()},i.prototype._onInputChange=function(){return this.triggerHandler("change",[this.getValue()])},i.prototype._autoresize=function(){},i.prototype._setPlaceholder=function(t){return null==t&&(t=!0),t?this.textField.attr("placeholder",this.opts.placeholder):this.textField.removeAttr("placeholder")},i.prototype.setSelected=function(t){return null==t&&(t=!1),t?this.addSelected(selected):this.clear()},i.prototype.addSelected=function(e){var r;if(e instanceof o||(e=this.dataProvider.getItem(e)),e)return this.selected||(this.selected=[]),this.selected.push(e),r=t(i._itemTpl).attr("data-value",e.value).data("item",e),r.find(".item-label").text(e.name),r.insertBefore(this.textField),this.setValue(""),this._setPlaceholder(!1),e},i.prototype.removeSelected=function(e){if(e instanceof o||(e=this.dataProvider.getItem(e)),e)return this.selected&&(t.each(this.selected,function(t){return function(i,r){if(r.value===e.value)return t.selected.splice(i,1),!1}}(this)),0===this.selected.length&&(this.selected=!1,this._setPlaceholder(!0))),this.el.find(".selected-item[data-value='"+e.value+"']").remove(),this.setValue(""),e},i.prototype.clear=function(){return this.setValue(""),this.selected=!1,this._setPlaceholder(!0),this.el.find(".selected-item").remove()},i}(n),i.exports=s},{"./input.coffee":2,"./models/item.coffee":5}],7:[function(i,r,n){var o,s,l,u,p=function(t,e){function i(){this.constructor=t}for(var r in e)a.call(e,r)&&(t[r]=e[r]);return i.prototype=e.prototype,t.prototype=new i,t.__super__=e.prototype,t},a={}.hasOwnProperty;o=i("./models/data-provider.coffee"),s=i("./models/group.coffee"),l=i("./models/item.coffee"),u=function(e){function i(){return i.__super__.constructor.apply(this,arguments)}return p(i,e),i._itemTpl='
\n \n \n
',i.prototype.opts={el:null,groups:[],onItemRender:null,localse:{}},i.prototype._init=function(){return this.el=t(this.opts.el),this.groups=this.opts.groups,this._render(),this._bind()},i.prototype._renderItem=function(e){var r;return r=t(i._itemTpl).data("item",e),r.find(".label").text(e.name),e.data.hint&&r.find(".hint").text(e.data.hint),r.attr("data-value",e.value),this.el.append(r),t.isFunction(this.opts.onItemRender)&&this.opts.onItemRender.call(this,r,e),r},i.prototype._render=function(){var e;return this.el.empty(),e=1===this.groups.length&&this.groups[0].name===s.defaultName,0===this.groups.length||e&&0===this.groups[0].items.length?t('
').text(this.opts.locales.noResults).appendTo(this.el):e?t.each(this.groups[0].items,function(t){return function(e,i){return t._renderItem(i)}}(this)):t.each(this.groups,function(e){return function(i,r){return t('
').text(r.name).appendTo(e.el),t.each(r.items,function(t,i){return e._renderItem(i)})}}(this)),this.el},i.prototype._bind=function(){return this.el.on("mousedown",".select-item",function(e){return function(i){var r;return r=t(i.currentTarget),e.triggerHandler("itemClick",[r,r.data("item")]),!1}}(this))},i.prototype._scrollToHighlighted=function(){var t;if(t=this.el.find(".select-item.highlighted"),t.length>0)return this.el.scrollTop(t.position().top)},i.prototype.setGroups=function(t){return this.setHighlighted(!1),this.setLoading(!1),this.setActive(!1),this.groups=t,this._render(),t},i.prototype.setHighlighted=function(t){return null==t&&(t=!1),t?(t instanceof l||(t=this.dataProvider.getItem(t)),this.el.find(".select-item[data-value='"+t.value+"']").addClass("highlighted").siblings().removeClass("highlighted")):this.el.find(".select-item.highlighted").removeClass("highlighted"),this.highlighted=t,t},i.prototype.highlightNextItem=function(){var t;if(t=this.highlighted?this.el.find(".select-item[data-value='"+this.highlighted.value+"']").nextAll(".select-item:first"):this.el.find(".select-item:first"),t.length>0)return this.setHighlighted(t.data("item"))},i.prototype.highlightPrevItem=function(){var t;if(t=this.highlighted?this.el.find(".select-item[data-value='"+this.highlighted.value+"']").prevAll(".select-item:first"):this.el.find(".select-item:first"),t.length>0)return this.setHighlighted(t.data("item"))},i.prototype.setLoading=function(e){return null==e&&(e=!0),this.loading=e,e?(this.el.find(".loading").length>0||t('
').text(this.opts.locales.loading).appendTo(this.el),this.el.addClass("loading")):(this.el.removeClass("loading"),this.el.find(".loading").remove()),this.setActive(e),e},i.prototype.setActive=function(t){return null==t&&(t=!0),this.active=t,this.el.toggleClass("active",t),t?(this._scrollToHighlighted(),this.triggerHandler("show")):this.triggerHandler("hide"),t},i.prototype.setPosition=function(t){return t&&this.el.css(t),this},i}(e),r.exports=u},{"./models/data-provider.coffee":3,"./models/group.coffee":4,"./models/item.coffee":5}],"simple-select":[function(i,r,n){var o,s,l,u,p,a,h,c,d=function(t,e){function i(){this.constructor=t}for(var r in e)f.call(e,r)&&(t[r]=e[r]);return i.prototype=e.prototype,t.prototype=new i,t.__super__=e.prototype,t},f={}.hasOwnProperty;o=i("./models/data-provider.coffee"),s=i("./models/group.coffee"),p=i("./models/item.coffee"),l=i("./html-select.coffee"),u=i("./input.coffee"),a=i("./multiple-input.coffee"),h=i("./popover.coffee"),c=function(e){function i(){return i.__super__.constructor.apply(this,arguments)}return d(i,e),i.prototype.opts={el:null,remote:!1,cls:"",onItemRender:null,placeholder:"",allowInput:!1,noWrap:!1,locales:null},i.locales={loading:"Loading...",noResults:"No results found"},i._tpl='
\n
\n
\n
',i.prototype._init=function(){var e,r,n,s;if(this.el=t(this.opts.el),!(this.el.length>0))throw new Error("simple select: option el is required");if(null!=(s=this.el.data("simpleSelect"))&&s.destroy(),this.locales=t.extend({},i.locales,this.opts.locales),this.multiple=this.el.is("[multiple]"),this._render(),this.dataProvider=new o({remote:this.opts.remote,selectEl:this.el}),this.htmlSelect=new l({el:this.el}),n=this.opts.placeholder?this.opts.placeholder:(e=this.htmlSelect.getBlankOption())?e.text():"",this.multiple?(this.input=new a({el:this.wrapper.find(".input"),placeholder:n,selected:this.htmlSelect.getValue()}),r=this.dataProvider.excludeItems(this.input.selected)):(this.input=new u({el:this.wrapper.find(".input"),placeholder:n,noWrap:this.opts.noWrap,selected:this.htmlSelect.getValue()}),r=this.dataProvider.groups),this.popover=new h({el:this.wrapper.find(".popover"),groups:r,onItemRender:this.opts.onItemRender,locales:this.locales}),this._bind(),this.el.prop("disabled"))return this.disable()},i.prototype._render=function(){return this.el.hide().data("simpleSelect",this),this.wrapper=t(i._tpl).data("simpleSelect",this).addClass(this.opts.cls).insertBefore(this.el)},i.prototype._bind=function(){return this.dataProvider.on("filter",function(t){return function(e,i,r){return t.multiple&&t.input.selected&&(i=t.dataProvider.excludeItems(t.input.selected,i)),t.popover.setGroups(i),t.popover.setActive(!(t.dataProvider.remote&&!r))}}(this)),this.dataProvider.on("beforeFetch",function(t){return function(e){return t.popover.setLoading(!0)}}(this)).on("fetch",function(t){return function(e){return t.popover.setLoading(!1)}}(this)),this.popover.on("itemClick",function(t){return function(e,i,r){return t.selectItem(r)}}(this)),this.popover.on("show",function(t){return function(e){return t._setPopoverPosition(),!t.multiple&&t.input.selected?t.popover.setHighlighted(t.input.selected):t.popover.highlightNextItem()}}(this)),this.input.on("itemClick",function(t){return function(e,i,r){return t.unselectItem(r)}}(this)),this.input.on("clearClick",function(t){return function(e){return t.clear()}}(this)),this.input.on("expandClick",function(t){return function(e){return t.popover.setActive(!0)}}(this)),this.input.on("arrowPress",function(t){return function(e,i){if(t.popover.active)return"up"===i?t.popover.highlightPrevItem():t.popover.highlightNextItem()}}(this)),this.input.on("enterPress",function(t){return function(e){return t.popover.active?(t.popover.highlighted?t.selectItem(t.popover.highlighted):t.multiple||t._setUserInput(),t.popover.setActive(!1)):t.el.closest("form").submit()}}(this)),this.input.on("change",function(t){return function(e,i){return t.multiple||t._syncValue(),t.dataProvider.filter(i),t._setPopoverPosition()}}(this)),this.input.on("focus",function(t){return function(e){if(!t.dataProvider.remote||t.input.getValue()&&!t.input.selected)return t.popover.setActive(!0)}}(this)),this.input.on("blur",function(t){return function(e){var i,r;return t.multiple||t.input.selected||(r=t.input.getValue(),(i=t.dataProvider.getItemByName(r))?t.selectItem(i):t._setUserInput(r)),t.popover.setActive(!1)}}(this))},i.prototype._setUserInput=function(t){if(null==t&&(t=this.input.getValue()),this.opts.allowInput&&!this.multiple)return this.wrapper.siblings(this.opts.allowInput).val(t)},i.prototype._setPopoverPosition=function(){return this.popover.setPosition({top:this.input.el.outerHeight()+2,left:0})},i.prototype._syncValue=function(){var e,i,r,n;return r=this.multiple?this.input.selected||[]:this.input.selected?[this.input.selected]:[],e=this.htmlSelect.getValue()||[],t.isArray(e)||(e=[e]),this.dataProvider.remote&&(i=new s({items:r}),this.htmlSelect.setGroups([i])),n=r.map(function(t){return t.value}),r.length>0?this.htmlSelect.setValue(n):this.htmlSelect.setValue(""),e.join(",")!==n.join(",")&&this.triggerHandler("change",[this.input.selected]),r},i.prototype.selectItem=function(t){if(t instanceof p||(t=this.dataProvider.getItem(t)),t)return this.multiple?this.input.addSelected(t):this.input.setSelected(t),this.popover.setActive(!1),this.opts.remote?this.popover.setGroups([]):this.multiple||(this.popover.setGroups(this.dataProvider.getGroups()),this.popover.setHighlighted(t)),this._setUserInput(""),this._syncValue(),t},i.prototype.unselectItem=function(t){if(this.multiple&&(t instanceof p||(t=this.dataProvider.getItem(t)),t))return this.input.removeSelected(t),this._syncValue(),t},i.prototype.clear=function(){return this.input.clear(),this.popover.setActive(!1),this._setUserInput(""),this},i.prototype.focus=function(){return this.input.focus()},i.prototype.blur=function(){return this.input.blur()},i.prototype.disable=function(){return this.input.setDisabled(!0),this.htmlSelect.setDisabled(!0),this.wrapper.addClass("disabled"),this},i.prototype.enable=function(){return this.input.setDisabled(!1),this.htmlSelect.setDisabled(!1),this.wrapper.removeClass("disabled"),this},i.prototype.destroy=function(){return this.el.removeData("simpleSelect").insertAfter(this.wrapper).show(),this.wrapper.remove(),this},i}(e),r.exports=c},{"./html-select.coffee":1,"./input.coffee":2,"./models/data-provider.coffee":3,"./models/group.coffee":4,"./models/item.coffee":5,"./multiple-input.coffee":6,"./popover.coffee":7}]},{},[]);return i("simple-select")}); \ No newline at end of file +/* simple-select v2.1.1 | (c) Mycolorway Design | MIT License */ +!function(t,e){"object"==typeof module&&module.exports?module.exports=e(require("jquery"),require("simple-module")):(t.SimpleSelect=e(t.jQuery,t.SimpleModule),t.simple=t.simple||{},t.simple.select=function(e){return new t.SimpleSelect(e)},t.simple.select.locales=t.SimpleSelect.locales)}(this,function(t,e){var i=require=function t(e,i,r){function n(s,l){if(!i[s]){if(!e[s]){var u="function"==typeof require&&require;if(!l&&u)return u(s,!0);if(o)return o(s,!0);var p=new Error("Cannot find module '"+s+"'");throw p.code="MODULE_NOT_FOUND",p}var a=i[s]={exports:{}};e[s][0].call(a.exports,function(t){var i=e[s][1][t];return n(i?i:t)},a,a.exports,t,e,i,r)}return i[s].exports}for(var o="function"==typeof require&&require,s=0;s",{text:e.name,value:e.value,data:e.data}).appendTo(i)},i.prototype._render=function(){return this.el.empty(),0===this.groups.length?this.el.append("",{label:r.name}),t.each(r.items,function(t,i){return e._renderOption(i,n)}),e.el.append(n)}}(this)),this.el},i.prototype.setGroups=function(t){return this.groups=t,this._render()},i.prototype.getValue=function(){return this.el.val()},i.prototype.setValue=function(t){return this.el.val(t)},i.prototype.getBlankOption=function(){var t;return t=this.el.find('option:not([value]), option[value=""]'),t.length>0&&t},i}(e),r.exports=s},{"./models/group.coffee":4}],2:[function(i,r,n){var o,s,l=function(t,e){function i(){this.constructor=t}for(var r in e)u.call(e,r)&&(t[r]=e[r]);return i.prototype=e.prototype,t.prototype=new i,t.__super__=e.prototype,t},u={}.hasOwnProperty;s=i("./models/item.coffee"),o=function(e){function i(){return i.__super__.constructor.apply(this,arguments)}return l(i,e),i.prototype.opts={el:null,dataProvider:null,noWrap:!1,placeholder:"",selected:!1},i.prototype._init=function(){return this.el=t(this.opts.el),this.dataProvider=this.opts.dataProvider,this._render(),this._bind()},i.prototype._render=function(){return this.el.append('\n\n\n \n\n\n \n'),this.el.find(this.opts.noWrap?"textarea":"input:text").remove(),this.textField=this.el.find(".text-field"),this.textField.attr("placeholder",this.opts.placeholder),this.setSelected(this.opts.selected),this.el},i.prototype._bind=function(){return this.el.on("mousedown",function(t){return function(e){return t.textField.focus(),!1}}(this)),this.el.find(".link-expand").on("mousedown",function(t){return function(e){if(!t.disabled)return t.focused||t.focus(),t.trigger("expandClick"),!1}}(this)),this.el.find(".link-clear").on("mousedown",function(t){return function(e){if(!t.disabled)return t.trigger("clearClick"),!1}}(this)),this.textField.on("keydown.simple-select",function(t){return function(e){var i;return 40===e.which||38===e.which?(e.preventDefault(),i=40===e.which?"down":"up",t.triggerHandler("arrowPress",[i])):13===e.which?(e.preventDefault(),t.triggerHandler("enterPress")):27===e.which?(e.preventDefault(),t.blur()):8===e.which?t._onBackspacePress(e):void 0}}(this)).on("input.simple-select",function(t){return function(e){return t._inputTimer&&(clearTimeout(t._inputTimer),t._inputTimer=null),t._inputTimer=setTimeout(function(){return t._onInputChange()},200)}}(this)).on("blur.simple-select",function(t){return function(e){return t.focused=!1,t.triggerHandler("blur")}}(this)).on("focus.simple-select",function(t){return function(e){return t.focused=!0,t.triggerHandler("focus")}}(this))},i.prototype._onBackspacePress=function(t){if(this.selected)return t.preventDefault(),this.clear()},i.prototype._onInputChange=function(){return this._autoresize(),this.setSelected(!1),this.triggerHandler("change",[this.getValue()])},i.prototype._autoresize=function(){var t,e,i;if(!this.opts.noWrap)return this.textField.css("height",0),i=parseFloat(this.textField[0].scrollHeight),e=parseFloat(this.textField.css("border-top-width")),t=parseFloat(this.textField.css("border-bottom-width")),this.textField.css("height",i+e+t)},i.prototype.setValue=function(t){return this.textField.val(t),this._onInputChange()},i.prototype.getValue=function(){return this.textField.val()},i.prototype.setSelected=function(t){return null==t&&(t=!1),t?(t instanceof s||(t=this.dataProvider.getItem(t)),this.textField.val(t.name),this._autoresize(),this.el.addClass("selected")):this.el.removeClass("selected"),this.selected=t,t},i.prototype.setDisabled=function(t){return null==t&&(t=!1),this.disabled=t,this.textField.prop("disabled",t),this.el.toggleClass("disabled",t),t},i.prototype.focus=function(){return this.textField.focus()},i.prototype.blur=function(){return this.textField.blur()},i.prototype.clear=function(){return this.setValue("")},i}(e),r.exports=o},{"./models/item.coffee":5}],3:[function(i,r,n){var o,s,l=function(t,e){function i(){this.constructor=t}for(var r in e)u.call(e,r)&&(t[r]=e[r]);return i.prototype=e.prototype,t.prototype=new i,t.__super__=e.prototype,t},u={}.hasOwnProperty;s=i("./group.coffee"),o=function(e){function i(){return i.__super__.constructor.apply(this,arguments)}return l(i,e),i.prototype.opts={remote:!1,groups:null,selectEl:null},i.prototype._init=function(){return this.remote=this.opts.remote,this.opts.groups?this.setGroupsFromJson(this.opts.groups):this.opts.selectEl?this.setGroupsFromHtml(this.opts.selectEl):void 0},i.prototype._fetch=function(e,i){var r,n;if(this.remote&&this.triggerHandler("beforeFetch")!==!1)return n=function(t){return function(e){return t.setGroupsFromJson(e),t.triggerHandler("fetch",[t.groups]),"function"==typeof i?i(t.groups):void 0}}(this),e?t.ajax({url:this.remote.url,data:t.extend({},this.remote.params,(r={},r[""+this.remote.searchKey]=e,r)),dataType:"json"}).done(function(t){return n(t)}):void n([])},i.prototype.setGroupsFromJson=function(e){if(e)return this.groups=[],t.isArray(e)?this.groups.push(new s({items:e})):t.isPlainObject(e)&&t.each(e,function(t){return function(e,i){return t.groups.push(new s({name:e,items:i}))}}(this)),this.triggerHandler("change",[this.groups]),this.groups},i.prototype.setGroupsFromHtml=function(e){var i,r,n;if(r=t(e),r&&r.length>0)return this.groups=[],n=function(e){var i;return i=[],e.each(function(e,r){var n,o;if(n=t(r),o=n.val())return i.push([n.text(),o,n.data()])}),i},(i=r.find("optgroup")).length>0?i.each(function(e){return function(i,r){var o;return o=t(r),e.groups.push(new s({name:o.attr("label"),items:n(o.find("option"))}))}}(this)):this.groups.push(new s({items:n(r.find("option"))})),this.triggerHandler("change",[this.groups]),this.groups},i.prototype.getGroups=function(){return this.groups},i.prototype.getItem=function(e){var i;return i=null,t.each(this.groups,function(t,r){if(i=r.getItem(e))return!1}),i},i.prototype.getItemByName=function(e){var i;return i=null,t.each(this.groups,function(t,r){if(i=r.getItemByName(e))return!1}),i},i.prototype.filter=function(e,i){var r;return this.remote?this._fetch(e,function(t){return function(){return"function"==typeof i&&i(t.groups,e),t.triggerHandler("filter",[t.groups,e])}}(this)):(r=[],t.each(this.groups,function(t,i){var n;if(n=i.filterItems(e),n.items.length>0)return r.push(n)}),"function"==typeof i&&i(r,e),this.triggerHandler("filter",[r,e])),null},i.prototype.excludeItems=function(e,i){var r;return null==e&&(e=[]),null==i&&(i=this.groups),r=[],t.each(i,function(t,i){var n;if(n=i.excludeItems(e),n.items.length>0)return r.push(n)}),r},i}(e),r.exports=o},{"./group.coffee":4}],4:[function(e,i,r){var n,o;o=e("./item.coffee"),n=function(){function e(i){this.name=i.name||e.defaultName,this.items=[],t.isArray(i.items)&&i.items.length>0&&t.each(i.items,function(e){return function(i,r){return t.isArray(r)&&(r={name:r[0],value:r[1],data:r.length>2?r[2]:null}),e.items.push(new o(r))}}(this))}return e.defaultName="__default__",e.prototype.filterItems=function(i){var r;return r=new e({name:this.name}),t.each(this.items,function(t,e){if(e.match(i))return r.items.push(e)}),r},e.prototype.excludeItems=function(i){var r;return i=i.map(function(t){return t.value}),r=new e({name:this.name}),t.each(this.items,function(t,e){if(i.indexOf(e.value)===-1)return r.items.push(e)}),r},e.prototype.getItem=function(e){var i;return i=null,t.each(this.items,function(t,r){if(r.value===e&&(i=r),i)return!1}),i},e.prototype.getItemByName=function(e){var i;return i=null,t.each(this.items,function(t,r){if(r.name===e&&(i=r),i)return!1}),i},e}(),i.exports=n},{"./item.coffee":5}],5:[function(i,r,n){var o,s=function(t,e){function i(){this.constructor=t}for(var r in e)l.call(e,r)&&(t[r]=e[r]);return i.prototype=e.prototype,t.prototype=new i,t.__super__=e.prototype,t},l={}.hasOwnProperty;o=function(e){function i(e){this.name=e.name,this.value=e.value.toString(),this.data={},t.isPlainObject(e.data)&&t.each(e.data,function(e){return function(i,r){return i=i.replace(/^data-/,"").split("-"),t.each(i,function(t,e){if(t>0)return i[t]=e.charAt(0).toUpperCase()+e.slice(1)}),e.data[i.join()]=r,null}}(this))}return s(i,e),i.prototype.match=function(t){var e,i,r;try{r=new RegExp("(^|\\s)"+t,"i")}catch(t){e=t,r=new RegExp("","i")}return i=this.data.key||this.name,r.test(i)},i}(e),r.exports=o},{}],6:[function(e,i,r){var n,o,s,l=function(t,e){function i(){this.constructor=t}for(var r in e)u.call(e,r)&&(t[r]=e[r]);return i.prototype=e.prototype,t.prototype=new i,t.__super__=e.prototype,t},u={}.hasOwnProperty;o=e("./models/item.coffee"),n=e("./input.coffee"),s=function(e){function i(){return i.__super__.constructor.apply(this,arguments)}return l(i,e),i.prototype.opts={el:null,placeholder:"",selected:!1},i._itemTpl='
\n \n \n
',i.prototype._render=function(){return this.el.append('').addClass("multiple"),this.textField=this.el.find("textarea"),this.textField.attr("placeholder",this.opts.placeholder),t.isArray(this.opts.selected)&&t.each(this.opts.selected,function(t){return function(e,i){return t.addSelected(i)}}(this)),this.el},i.prototype._bind=function(){return i.__super__._bind.call(this),this.el.on("mousedown",".selected-item",function(e){return function(i){var r;return r=t(i.currentTarget),e.triggerHandler("itemClick",[r,r.data("item")]),!1}}(this))},i.prototype._onBackspacePress=function(t){if(!this.getValue())return t.preventDefault(),this.el.find(".selected-item:last").mousedown()},i.prototype._onInputChange=function(){return this.triggerHandler("change",[this.getValue()])},i.prototype._autoresize=function(){},i.prototype._setPlaceholder=function(t){return null==t&&(t=!0),t?this.textField.attr("placeholder",this.opts.placeholder):this.textField.removeAttr("placeholder")},i.prototype.setSelected=function(t){return null==t&&(t=!1),t?this.addSelected(selected):this.clear()},i.prototype.addSelected=function(e){var r;if(e instanceof o||(e=this.dataProvider.getItem(e)),e)return this.selected||(this.selected=[]),this.selected.push(e),r=t(i._itemTpl).attr("data-value",e.value).data("item",e),r.find(".item-label").text(e.name),r.insertBefore(this.textField),this.setValue(""),this._setPlaceholder(!1),e},i.prototype.removeSelected=function(e){if(e instanceof o||(e=this.dataProvider.getItem(e)),e)return this.selected&&(t.each(this.selected,function(t){return function(i,r){if(r.value===e.value)return t.selected.splice(i,1),!1}}(this)),0===this.selected.length&&(this.selected=!1,this._setPlaceholder(!0))),this.el.find(".selected-item[data-value='"+e.value+"']").remove(),this.setValue(""),e},i.prototype.clear=function(){return this.setValue(""),this.selected=!1,this._setPlaceholder(!0),this.el.find(".selected-item").remove()},i}(n),i.exports=s},{"./input.coffee":2,"./models/item.coffee":5}],7:[function(i,r,n){var o,s,l,u=function(t,e){function i(){this.constructor=t}for(var r in e)p.call(e,r)&&(t[r]=e[r]);return i.prototype=e.prototype,t.prototype=new i,t.__super__=e.prototype,t},p={}.hasOwnProperty;o=i("./models/group.coffee"),s=i("./models/item.coffee"),l=function(e){function i(){return i.__super__.constructor.apply(this,arguments)}return u(i,e),i._itemTpl='
\n \n \n
',i.prototype.opts={el:null,groups:[],dataProvider:null,onItemRender:null,localse:{}},i.prototype._init=function(){return this.el=t(this.opts.el),this.dataProvider=this.opts.dataProvider,this.groups=this.opts.groups,this._render(),this._bind()},i.prototype._renderItem=function(e){var r;return r=t(i._itemTpl).data("item",e),r.find(".label").text(e.name),e.data.hint&&r.find(".hint").text(e.data.hint),r.attr("data-value",e.value),this.el.append(r),t.isFunction(this.opts.onItemRender)&&this.opts.onItemRender.call(this,r,e),r},i.prototype._render=function(){var e;return this.el.empty(),e=1===this.groups.length&&this.groups[0].name===o.defaultName,0===this.groups.length||e&&0===this.groups[0].items.length?t('
').text(this.opts.locales.noResults).appendTo(this.el):e?t.each(this.groups[0].items,function(t){return function(e,i){return t._renderItem(i)}}(this)):t.each(this.groups,function(e){return function(i,r){return t('
').text(r.name).appendTo(e.el),t.each(r.items,function(t,i){return e._renderItem(i)})}}(this)),this.el},i.prototype._bind=function(){return this.el.on("mousedown",".select-item",function(e){return function(i){var r;return r=t(i.currentTarget),e.triggerHandler("itemClick",[r,r.data("item")]),!1}}(this))},i.prototype._scrollToHighlighted=function(){var t;if(t=this.el.find(".select-item.highlighted"),t.length>0)return this.el.scrollTop(t.position().top)},i.prototype.setGroups=function(t){return this.setHighlighted(!1),this.setLoading(!1),this.setActive(!1),this.groups=t,this._render(),t},i.prototype.setHighlighted=function(t){return null==t&&(t=!1),t?(t instanceof s||(t=this.dataProvider.getItem(t)),this.el.find(".select-item[data-value='"+t.value+"']").addClass("highlighted").siblings().removeClass("highlighted")):this.el.find(".select-item.highlighted").removeClass("highlighted"),this.highlighted=t,t},i.prototype.highlightNextItem=function(){var t;if(t=this.highlighted?this.el.find(".select-item[data-value='"+this.highlighted.value+"']").nextAll(".select-item:first"):this.el.find(".select-item:first"),t.length>0)return this.setHighlighted(t.data("item"))},i.prototype.highlightPrevItem=function(){var t;if(t=this.highlighted?this.el.find(".select-item[data-value='"+this.highlighted.value+"']").prevAll(".select-item:first"):this.el.find(".select-item:first"),t.length>0)return this.setHighlighted(t.data("item"))},i.prototype.setLoading=function(e){return null==e&&(e=!0),this.loading=e,e?(this.el.find(".loading").length>0||t('
').text(this.opts.locales.loading).appendTo(this.el),this.el.addClass("loading")):(this.el.removeClass("loading"),this.el.find(".loading").remove()),this.setActive(e),e},i.prototype.setActive=function(t){return null==t&&(t=!0),this.active=t,this.el.toggleClass("active",t),t?(this._scrollToHighlighted(),this.triggerHandler("show")):this.triggerHandler("hide"),t},i.prototype.setPosition=function(t){return t&&this.el.css(t),this},i}(e),r.exports=l},{"./models/group.coffee":4,"./models/item.coffee":5}],"simple-select":[function(i,r,n){var o,s,l,u,p,a,h,c,d=function(t,e){function i(){this.constructor=t}for(var r in e)f.call(e,r)&&(t[r]=e[r]);return i.prototype=e.prototype,t.prototype=new i,t.__super__=e.prototype,t},f={}.hasOwnProperty;o=i("./models/data-provider.coffee"),s=i("./models/group.coffee"),p=i("./models/item.coffee"),l=i("./html-select.coffee"),u=i("./input.coffee"),a=i("./multiple-input.coffee"),h=i("./popover.coffee"),c=function(e){function i(){return i.__super__.constructor.apply(this,arguments)}return d(i,e),i.prototype.opts={el:null,remote:!1,cls:"",onItemRender:null,placeholder:"",allowInput:!1,noWrap:!1,locales:null},i.locales={loading:"Loading...",noResults:"No results found"},i._tpl='
\n
\n
\n
',i.prototype._init=function(){var e,r,n,s;if(this.el=t(this.opts.el),!(this.el.length>0))throw new Error("simple select: option el is required");if(null!=(s=this.el.data("simpleSelect"))&&s.destroy(),this.locales=t.extend({},i.locales,this.opts.locales),this.multiple=this.el.is("[multiple]"),this._render(),this.dataProvider=new o({remote:this.opts.remote,selectEl:this.el}),this.htmlSelect=new l({el:this.el}),n=this.opts.placeholder?this.opts.placeholder:(e=this.htmlSelect.getBlankOption())?e.text():"",this.multiple?(this.input=new a({el:this.wrapper.find(".input"),dataProvider:this.dataProvider,placeholder:n,selected:this.htmlSelect.getValue()}),r=this.dataProvider.excludeItems(this.input.selected)):(this.input=new u({el:this.wrapper.find(".input"),dataProvider:this.dataProvider,placeholder:n,noWrap:this.opts.noWrap,selected:this.htmlSelect.getValue()}),r=this.dataProvider.groups),this.popover=new h({el:this.wrapper.find(".popover"),dataProvider:this.dataProvider,groups:r,onItemRender:this.opts.onItemRender,locales:this.locales}),this._bind(),this.el.prop("disabled"))return this.disable()},i.prototype._render=function(){return this.el.hide().data("simpleSelect",this),this.wrapper=t(i._tpl).data("simpleSelect",this).addClass(this.opts.cls).insertBefore(this.el)},i.prototype._bind=function(){return this.dataProvider.on("filter",function(t){return function(e,i,r){return t.multiple&&t.input.selected&&(i=t.dataProvider.excludeItems(t.input.selected,i)),t.popover.setGroups(i),t.popover.setActive(!(t.dataProvider.remote&&!r))}}(this)),this.dataProvider.on("beforeFetch",function(t){return function(e){return t.popover.setLoading(!0)}}(this)).on("fetch",function(t){return function(e){return t.popover.setLoading(!1)}}(this)),this.popover.on("itemClick",function(t){return function(e,i,r){return t.selectItem(r)}}(this)),this.popover.on("show",function(t){return function(e){return t._setPopoverPosition(),!t.multiple&&t.input.selected?t.popover.setHighlighted(t.input.selected):t.popover.highlightNextItem()}}(this)),this.input.on("itemClick",function(t){return function(e,i,r){return t.unselectItem(r)}}(this)),this.input.on("clearClick",function(t){return function(e){return t.clear()}}(this)),this.input.on("expandClick",function(t){return function(e){return t.popover.setActive(!0)}}(this)),this.input.on("arrowPress",function(t){return function(e,i){if(t.popover.active)return"up"===i?t.popover.highlightPrevItem():t.popover.highlightNextItem()}}(this)),this.input.on("enterPress",function(t){return function(e){return t.popover.active?(t.popover.highlighted?t.selectItem(t.popover.highlighted):t.multiple||t._setUserInput(),t.popover.setActive(!1)):t.el.closest("form").submit()}}(this)),this.input.on("change",function(t){return function(e,i){return t.multiple||t._syncValue(),t.dataProvider.filter(i),t._setPopoverPosition()}}(this)),this.input.on("focus",function(t){return function(e){if(!t.dataProvider.remote||t.input.getValue()&&!t.input.selected)return t.popover.setActive(!0)}}(this)),this.input.on("blur",function(t){return function(e){var i,r;return t.multiple||t.input.selected||(r=t.input.getValue(),(i=t.dataProvider.getItemByName(r))?t.selectItem(i):t._setUserInput(r)),t.popover.setActive(!1)}}(this))},i.prototype._setUserInput=function(t){if(null==t&&(t=this.input.getValue()),this.opts.allowInput&&!this.multiple)return this.wrapper.siblings(this.opts.allowInput).val(t)},i.prototype._setPopoverPosition=function(){return this.popover.setPosition({top:this.input.el.outerHeight()+2,left:0})},i.prototype._syncValue=function(){var e,i,r,n;return r=this.multiple?this.input.selected||[]:this.input.selected?[this.input.selected]:[],e=this.htmlSelect.getValue()||[],t.isArray(e)||(e=[e]),this.dataProvider.remote&&(i=new s({items:r}),this.htmlSelect.setGroups([i])),n=r.map(function(t){return t.value}),r.length>0?this.htmlSelect.setValue(n):this.htmlSelect.setValue(""),e.join(",")!==n.join(",")&&this.triggerHandler("change",[this.input.selected]),r},i.prototype.selectItem=function(t){if(t instanceof p||(t=this.dataProvider.getItem(t)),t)return this.multiple?this.input.addSelected(t):this.input.setSelected(t),this.popover.setActive(!1),this.opts.remote?this.popover.setGroups([]):this.multiple||(this.popover.setGroups(this.dataProvider.getGroups()),this.popover.setHighlighted(t)),this._setUserInput(""),this._syncValue(),t},i.prototype.unselectItem=function(t){if(this.multiple&&(t instanceof p||(t=this.dataProvider.getItem(t)),t))return this.input.removeSelected(t),this._syncValue(),t},i.prototype.clear=function(){return this.input.clear(),this.popover.setActive(!1),this._setUserInput(""),this},i.prototype.focus=function(){return this.input.focus()},i.prototype.blur=function(){return this.input.blur()},i.prototype.disable=function(){return this.input.setDisabled(!0),this.htmlSelect.setDisabled(!0),this.wrapper.addClass("disabled"),this},i.prototype.enable=function(){return this.input.setDisabled(!1),this.htmlSelect.setDisabled(!1),this.wrapper.removeClass("disabled"),this},i.prototype.destroy=function(){return this.el.removeData("simpleSelect").insertAfter(this.wrapper).show(),this.wrapper.remove(),this},i}(e),r.exports=c},{"./html-select.coffee":1,"./input.coffee":2,"./models/data-provider.coffee":3,"./models/group.coffee":4,"./models/item.coffee":5,"./multiple-input.coffee":6,"./popover.coffee":7}]},{},[]);return i("simple-select")}); \ No newline at end of file diff --git a/package.json b/package.json index 2e19542..054ab8a 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "simple-select", "githubOwner": "mycolorway", - "version": "2.1.0", + "version": "2.1.1", "description": "Autocomplete select component", "homepage": "http://mycolorway.github.io/simple-select", "repository": { diff --git a/src/input.coffee b/src/input.coffee index dce6af9..47aa7ef 100644 --- a/src/input.coffee +++ b/src/input.coffee @@ -1,17 +1,17 @@ -DataProvider = require './models/data-provider.coffee' Item = require './models/item.coffee' class Input extends SimpleModule opts: el: null + dataProvider: null noWrap: false placeholder: '' selected: false _init: -> @el = $ @opts.el - @dataProvider = DataProvider.getInstance() + @dataProvider = @opts.dataProvider @_render() @_bind() diff --git a/src/models/data-provider.coffee b/src/models/data-provider.coffee index e7a0dbb..c4ea249 100644 --- a/src/models/data-provider.coffee +++ b/src/models/data-provider.coffee @@ -2,9 +2,6 @@ Group = require './group.coffee' class DataProvider extends SimpleModule - @getInstance: -> - @instance - opts: remote: false groups: null @@ -18,8 +15,6 @@ class DataProvider extends SimpleModule else if @opts.selectEl @setGroupsFromHtml @opts.selectEl - DataProvider.instance = @ - _fetch: (value, callback) -> return if !@remote || @triggerHandler('beforeFetch') == false diff --git a/src/popover.coffee b/src/popover.coffee index d1c0823..8559ea1 100644 --- a/src/popover.coffee +++ b/src/popover.coffee @@ -1,4 +1,3 @@ -DataProvider = require './models/data-provider.coffee' Group = require './models/group.coffee' Item = require './models/item.coffee' @@ -14,11 +13,13 @@ class Popover extends SimpleModule opts: el: null groups: [] + dataProvider: null onItemRender: null localse: {} _init: -> @el = $ @opts.el + @dataProvider = @opts.dataProvider @groups = @opts.groups @_render() diff --git a/src/simple-select.coffee b/src/simple-select.coffee index 71c8a3e..29a9b0a 100644 --- a/src/simple-select.coffee +++ b/src/simple-select.coffee @@ -58,12 +58,14 @@ class SimpleSelect extends SimpleModule if @multiple @input = new MultipleInput el: @wrapper.find('.input') + dataProvider: @dataProvider placeholder: placeholder selected: @htmlSelect.getValue() groups = @dataProvider.excludeItems @input.selected else @input = new Input el: @wrapper.find('.input') + dataProvider: @dataProvider placeholder: placeholder noWrap: @opts.noWrap selected: @htmlSelect.getValue() @@ -71,6 +73,7 @@ class SimpleSelect extends SimpleModule @popover = new Popover el: @wrapper.find('.popover') + dataProvider: @dataProvider groups: groups onItemRender: @opts.onItemRender locales: @locales diff --git a/styles/simple-select.css b/styles/simple-select.css index 93948c2..71ac4c3 100644 --- a/styles/simple-select.css +++ b/styles/simple-select.css @@ -1,5 +1,5 @@ /** - * simple-select v2.1.0 + * simple-select v2.1.1 * http://mycolorway.github.io/simple-select * * Copyright Mycolorway Design diff --git a/test/html-select.coffee b/test/html-select.coffee new file mode 100644 index 0000000..657e891 --- /dev/null +++ b/test/html-select.coffee @@ -0,0 +1,62 @@ +DataProvider = require '../src/models/data-provider' +HtmlSelect = require '../src/html-select' +expect = chai.expect + +describe 'Html Select', -> + + dataProvider = null + htmlSelect = null + + beforeEach -> + dataProvider = new DataProvider + groups: { + 'Cat Animals': [ + ['Cat', '1'] + ['Tiger', '2'] + ], + 'Dog Animals': [ + ['Dog', '3'] + ['Wolf', '4'] + ] + } + + htmlSelect = new HtmlSelect + el: $ '