Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion component.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
"version": "1.3.1",
"keywords": ["tags", "tag", "input", "ui", "pillbox"],
"dependencies": {
"component/bind": "*",
"component/trim": "*",
"component/events": "*",
"component/keyname": "*",
"component/emitter": "*",
"component/each": "*",
"component/set": "*"
"component/set": "*",
"stephenmathieson/normalize": "*"
},
"development": {},
"scripts": [
Expand Down
20 changes: 13 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ var Emitter = require('emitter')
, keyname = require('keyname')
, events = require('events')
, each = require('each')
, Set = require('set');
, Set = require('set')
, bind = require('bind')
, trim = require('trim')
, normalize = require('normalize');

/**
* Expose `Pillbox`.
Expand All @@ -30,7 +33,11 @@ function Pillbox(input, options) {
this.tags = new Set;
this.el = document.createElement('div');
this.el.className = 'pillbox';
this.el.style = input.style;
try {
this.el.style = input.style;
} catch (e) {
// IE8 just can't handle this
}
input.parentNode.insertBefore(this.el, input);
input.parentNode.removeChild(input);
this.el.appendChild(input);
Expand Down Expand Up @@ -75,7 +82,7 @@ Pillbox.prototype.unbind = function(){
* @api private
*/

Pillbox.prototype.onkeydown = function(e){
Pillbox.prototype.onkeydown = normalize(function(e){
switch (keyname(e.which)) {
case 'enter':
e.preventDefault();
Expand All @@ -94,7 +101,7 @@ Pillbox.prototype.onkeydown = function(e){
}
break;
}
};
});

/**
* Handle click.
Expand Down Expand Up @@ -149,7 +156,7 @@ Pillbox.prototype.last = function(){

Pillbox.prototype.add = function(tag) {
var self = this
tag = tag.trim();
tag = trim(tag);

// blank
if ('' == tag) return;
Expand All @@ -176,7 +183,7 @@ Pillbox.prototype.add = function(tag) {
var del = document.createElement('a');
del.appendChild(document.createTextNode('✕'));
del.href = '#';
del.onclick = this.remove.bind(this, tag);
del.onclick = bind(this, this.remove, tag);
span.appendChild(del);

this.el.insertBefore(span, this.input);
Expand Down Expand Up @@ -208,4 +215,3 @@ Pillbox.prototype.remove = function(tag) {

return this;
}

2 changes: 1 addition & 1 deletion test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<link href="../build/build.css" type="style/css" rel="stylesheet" />
<link href="../build/build.css" type="text/css" rel="stylesheet" />
<script src="../build/build.js" type="text/javascript"></script>
<style>
body {
Expand Down