Skip to content

Commit

Permalink
Add getData/setData functions
Browse files Browse the repository at this point in the history
  • Loading branch information
okcoker committed Aug 18, 2017
1 parent 1a88876 commit 892cd10
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
20 changes: 18 additions & 2 deletions example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -454,20 +454,36 @@ <h4>Methods</h4>
</div>
<div class="option">
<p>
disable() <code>Returns {Object}</code>
disable()
</p>
<p>
Disable all button and input elements within the component via the disabled attribute.
</p>
</div>
<div class="option">
<p>
enable() <code>Returns {Object}</code>
enable()
</p>
<p>
Enable all button and input elements within the component by removing the disabled attribute.
</p>
</div>
<div class="option">
<p>
setData(Any)
</p>
<p>
Sets arbitrary data on the instance.
</p>
</div>
<div class="option">
<p>
getData() <code>Returns {Object}</code>
</p>
<p>
Gets the arbitrary data on the instance.
</p>
</div>
</article>
</section>
</div>
Expand Down
11 changes: 11 additions & 0 deletions src/taggle.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@
this.sizer = document.createElement('div');
this.pasting = false;
this.placeholder = null;
this.data = null;

if (this.settings.placeholder) {
this.placeholder = document.createElement('span');
Expand Down Expand Up @@ -927,5 +928,15 @@
return this;
};

Taggle.prototype.setData = function(data) {
this.data = data;

return this;
};

Taggle.prototype.getData = function() {
return this.data;
};

return Taggle;
}));
20 changes: 20 additions & 0 deletions test/taggle-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +1031,26 @@ describe('Taggle', function() {
});
});

describe('#setData/#getData', function() {
beforeEach(function() {
this.instance = new Taggle(this.container);
});

it('set and get abitrary data', function() {
var data = this.instance.getData();

expect(data).to.equal(null);

var someData = { test: 1 };

this.instance.setData(someData);

data = this.instance.getData();

expect(data.test).to.equal(1);
});
});

describe('#checkCloseButtonType', function() {
beforeEach(function() {
this.instance = new Taggle(this.container, {
Expand Down

0 comments on commit 892cd10

Please sign in to comment.