From 10bcb23918ded17c77b6159d441ae733ba1e760a Mon Sep 17 00:00:00 2001 From: Dominic Barnes Date: Mon, 20 Jan 2014 15:05:20 -0600 Subject: [PATCH 1/4] Adding some new deps for IE8 compatibility * component/bind for Function#bind * component/map for Array#map * component/indexof for Array#indexOf * component/query-zest for IE8 support of CSS selectors * dominicbarnes/pillbox@ie8_compat for IE8 compatibility (see component/pillbox#9) (and a development dependency change) * dominicbarnes/dom@ie8_compat for IE8 compatibility (no upstream PR yet) --- component.json | 10 +++++++--- index.js | 25 +++++++++++++++++-------- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/component.json b/component.json index 14e1e7f..a96a4a5 100644 --- a/component.json +++ b/component.json @@ -13,20 +13,24 @@ "dependencies": { "ianstormtaylor/previous-sibling": "*", "ianstormtaylor/next-sibling": "*", + "component/bind": "*", "component/debounce": "*", - "component/pillbox": "*", + "dominicbarnes/pillbox": "ie8_compat", "component/emitter": "*", "component/keyname": "*", "component/classes": "*", "component/events": "*", "component/domify": "*", "component/query": "*", - "component/each": "*" + "component/query-zest": "*", + "component/each": "*", + "component/map": "*", + "component/indexof": "*" }, "development": { "visionmedia/mocha-matrix": "*", "visionmedia/mocha": "*", "component/assert": "*", - "component/dom": "*" + "dominicbarnes/dom": "ie8_compat" } } diff --git a/index.js b/index.js index 81cc6c7..3387df2 100644 --- a/index.js +++ b/index.js @@ -13,9 +13,15 @@ var keyname = require('keyname'); var events = require('events'); var domify = require('domify'); var query = require('query'); +var bind = require('bind'); var each = require('each'); +var map = require('map'); +var indexOf = require('indexof'); var tpl = domify(template); +require('query-zest'); + + /** * Export `Select` */ @@ -59,7 +65,7 @@ Emitter(Select.prototype); Select.prototype.bind = function(){ this.events.bind('click .select-box', 'focus'); this.events.bind('mouseover .select-option'); - var onsearch = this.onsearch.bind(this); + var onsearch = bind(this, this.onsearch); this.input.onkeyup = debounce(onsearch, 300); this.docEvents.bind('touchstart', 'blur'); this.inputEvents.bind('focus', 'show'); @@ -113,7 +119,7 @@ Select.prototype.multiple = function(label, opts){ this.classes.add('select-multiple'); this.box = new Pillbox(this.input, opts); this.box.events.unbind('keydown'); - this.box.on('remove', this.deselect.bind(this)); + this.box.on('remove', bind(this, this.deselect)); return this; }; @@ -128,7 +134,7 @@ Select.prototype.multiple = function(label, opts){ Select.prototype.add = function(name, value){ var opt = option.apply(null, arguments); - opt.el.onmousedown = this.select.bind(this, name); + opt.el.onmousedown = bind(this, this.select, name); this.opts.appendChild(opt.el); this.options[opt.name] = opt; this.emit('add', opt); @@ -167,7 +173,7 @@ Select.prototype.remove = function(name){ */ Select.prototype.empty = function(){ - each(this.options, this.remove.bind(this)); + each(this.options, bind(this, this.remove)); return this; }; @@ -238,7 +244,7 @@ Select.prototype.deselect = function(name){ // multiple if (this._multiple) { this.box.remove(opt.label); - var i = this._selected.indexOf(opt); + var i = indexOf(this._selected, opt); if (!~i) return this; this._selected.splice(i, 1); this.change(); @@ -396,7 +402,10 @@ Select.prototype.enable = function(name){ Select.prototype.selected = function(arr){ if (1 == arguments.length) { - arr.forEach(this.select, this); + var self = this; + each(arr, function (item) { + self.select(item); + }); return this; } @@ -411,7 +420,7 @@ Select.prototype.selected = function(arr){ */ Select.prototype.values = function(){ - return this._selected.map(function(opt){ + return map(this._selected, function(opt){ return opt.value; }); }; @@ -698,7 +707,7 @@ function option(obj, value, el){ // option obj.label = obj.name; obj.name = obj.name.toLowerCase(); - obj.value = obj.value == null + obj.value = obj.value == null ? obj.name : obj.value; From c265ee8cc3691587f8bc6bd3344be35c05ef8741 Mon Sep 17 00:00:00 2001 From: Dominic Barnes Date: Tue, 21 Jan 2014 15:53:58 -0600 Subject: [PATCH 2/4] normalizing events via stephenmathieson/normalize --- component.json | 3 ++- index.js | 13 +++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/component.json b/component.json index a96a4a5..c06b019 100644 --- a/component.json +++ b/component.json @@ -25,7 +25,8 @@ "component/query-zest": "*", "component/each": "*", "component/map": "*", - "component/indexof": "*" + "component/indexof": "*", + "stephenmathieson/normalize": "*" }, "development": { "visionmedia/mocha-matrix": "*", diff --git a/index.js b/index.js index 3387df2..e1e7d99 100644 --- a/index.js +++ b/index.js @@ -17,6 +17,7 @@ var bind = require('bind'); var each = require('each'); var map = require('map'); var indexOf = require('indexof'); +var normalize = require("normalize"); var tpl = domify(template); require('query-zest'); @@ -555,7 +556,7 @@ Select.prototype.previous = function(){ * @api private */ -Select.prototype.onsearch = function(e){ +Select.prototype.onsearch = normalize(function(e){ var key = keyname(e.which); // ignore @@ -571,7 +572,7 @@ Select.prototype.onsearch = function(e){ } else { this.showAll(); } -}; +}); /** * on-keydown. @@ -580,7 +581,7 @@ Select.prototype.onsearch = function(e){ * @api private */ -Select.prototype.onkeydown = function(e){ +Select.prototype.onkeydown = normalize(function(e){ var visible = this.visible() , box = this.box; @@ -615,7 +616,7 @@ Select.prototype.onkeydown = function(e){ this.deselect(item.name); break; } -}; +}); /** * on-mouseover @@ -624,10 +625,10 @@ Select.prototype.onkeydown = function(e){ * @api private */ -Select.prototype.onmouseover = function(e){ +Select.prototype.onmouseover = normalize(function(e){ var name = e.target.getAttribute('data-name'); this.highlight(name); -}; +}); /** * Emit change. From 66c1f9573a5d2e0afb7faa0d5c19b2c55dfd59cf Mon Sep 17 00:00:00 2001 From: Dominic Barnes Date: Tue, 21 Jan 2014 15:57:12 -0600 Subject: [PATCH 3/4] using matthewp/text for text manipulation --- component.json | 3 ++- index.js | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/component.json b/component.json index c06b019..1c6d1db 100644 --- a/component.json +++ b/component.json @@ -26,7 +26,8 @@ "component/each": "*", "component/map": "*", "component/indexof": "*", - "stephenmathieson/normalize": "*" + "stephenmathieson/normalize": "*", + "matthewp/text": "*" }, "development": { "visionmedia/mocha-matrix": "*", diff --git a/index.js b/index.js index e1e7d99..f7d0f24 100644 --- a/index.js +++ b/index.js @@ -18,6 +18,7 @@ var each = require('each'); var map = require('map'); var indexOf = require('indexof'); var normalize = require("normalize"); +var text = require('text'); var tpl = domify(template); require('query-zest'); @@ -715,7 +716,7 @@ function option(obj, value, el){ // element if (!obj.el) { obj.el = document.createElement('li'); - obj.el.textContent = obj.label; + text(obj.el, obj.label); } // domify From bd74872a3a24b70cdcb03589060107ee8d9686ec Mon Sep 17 00:00:00 2001 From: Dominic Barnes Date: Mon, 27 Jan 2014 17:32:25 -0600 Subject: [PATCH 4/4] updating for upstream changes/merges --- component.json | 4 ++-- test/test.js | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/component.json b/component.json index 1c6d1db..2d707ca 100644 --- a/component.json +++ b/component.json @@ -15,7 +15,7 @@ "ianstormtaylor/next-sibling": "*", "component/bind": "*", "component/debounce": "*", - "dominicbarnes/pillbox": "ie8_compat", + "component/pillbox": "*", "component/emitter": "*", "component/keyname": "*", "component/classes": "*", @@ -33,6 +33,6 @@ "visionmedia/mocha-matrix": "*", "visionmedia/mocha": "*", "component/assert": "*", - "dominicbarnes/dom": "ie8_compat" + "component/dom": "*" } } diff --git a/test/test.js b/test/test.js index 56ae8e9..4adf84c 100644 --- a/test/test.js +++ b/test/test.js @@ -28,7 +28,7 @@ describe('select()', function(){ }) it('should append the pillbox to `.select-box`', function(){ - assert(dom('.pillbox', s.el).length()); + assert(dom('.pillbox', s.el).length); }) }) @@ -385,7 +385,7 @@ describe('select()', function(){ .search('o') .opts; - assert(2 == dom('.select-option:not([hidden])', opts).length()); + assert(2 == dom('.select-option:not([hidden])', opts).length); }) }) @@ -398,7 +398,7 @@ describe('select()', function(){ .search('o') .opts; - assert(3 == dom('.select-option:not([hidden])', opts).length()); + assert(3 == dom('.select-option:not([hidden])', opts).length); }) }) })