From a3ecfaf18be38ac02fe07e7b11e6e9978fc5184d Mon Sep 17 00:00:00 2001 From: tingpan Date: Fri, 5 Jun 2015 03:32:32 +0100 Subject: [PATCH] keep ref on el and add test to it --- lib/select.js | 1 + spec/select-spec.coffee | 9 +++++++++ spec/select-spec.js | 10 +++++++++- src/select.coffee | 1 + 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/select.js b/lib/select.js index 404fa6f..ecde9bf 100644 --- a/lib/select.js +++ b/lib/select.js @@ -69,6 +69,7 @@ Select = (function(superClass) { var idx, it, items, j, len, results1; Select._tpl.select = "
\n \n \n \n \n \n \n
\n
" + (this._t('loading')) + "...
\n
\n
"; this.el = $(this.opts.el).hide(); + this.el.data("select", this); this.select = $(Select._tpl.select).data("select", this).addClass(this.opts.cls).insertBefore(this.el); this.input = $(Select._tpl.input).attr("placeholder", this.el.data("placeholder") || this.opts.placeholder).prependTo(this.select); this.list = this.select.find(".select-list"); diff --git a/spec/select-spec.coffee b/spec/select-spec.coffee index c312709..0329323 100644 --- a/spec/select-spec.coffee +++ b/spec/select-spec.coffee @@ -149,3 +149,12 @@ describe 'Simple Select', -> expect(select.requireSelect).toBe(false) expect(select.el.val()).toBe('') + it "keep reference in el", -> + selectEl.appendTo("body") + select = simple.select + el: $("#select-one") + + expect(selectEl.data('select')).toBe(select) + + + diff --git a/spec/select-spec.js b/spec/select-spec.js index b6a16f6..a4fd997 100644 --- a/spec/select-spec.js +++ b/spec/select-spec.js @@ -140,7 +140,7 @@ select.input.blur(); return expect(select.el.val()).toBe('0'); }); - return it('should always select default value if one option without value', function() { + it('should always select default value if one option without value', function() { var select; selectEl.append(''); selectEl.appendTo("body"); @@ -152,6 +152,14 @@ expect(select.requireSelect).toBe(false); return expect(select.el.val()).toBe(''); }); + return it("keep reference in el", function() { + var select; + selectEl.appendTo("body"); + select = simple.select({ + el: $("#select-one") + }); + return expect(selectEl.data('select')).toBe(select); + }); }); }).call(this); diff --git a/src/select.coffee b/src/select.coffee index ba11dcb..64bf102 100644 --- a/src/select.coffee +++ b/src/select.coffee @@ -54,6 +54,7 @@ class Select extends SimpleModule """ @el = $(@opts.el).hide() + @el.data("select", @) @select = $(Select._tpl.select) .data("select", @) .addClass(@opts.cls)