Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: mdbootstrap/bootstrap-templates
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: moniuch/bootstrap-tagsinput
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.
  • 5 commits
  • 2 files changed
  • 1 contributor

Commits on Jan 12, 2015

  1. Copy the full SHA
    495fbcb View commit details

Commits on Jan 13, 2015

  1. ignore .idea files

    moniuch committed Jan 13, 2015
    Copy the full SHA
    d6399f4 View commit details
  2. ignore .idea files

    moniuch committed Jan 13, 2015
    Copy the full SHA
    a330f9a View commit details

Commits on Jan 14, 2015

  1. Copy the full SHA
    a5aa24a View commit details
  2. Copy the full SHA
    0d7b256 View commit details
Showing with 31 additions and 6 deletions.
  1. +1 −0 .gitignore
  2. +30 −6 src/bootstrap-tagsinput.js
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules/
bower_components/
lib/
.idea/
36 changes: 30 additions & 6 deletions src/bootstrap-tagsinput.js
Original file line number Diff line number Diff line change
@@ -101,13 +101,13 @@
if (beforeItemAddEvent.cancel)
return;

item = beforeItemAddEvent.item
item = beforeItemAddEvent.item;

var itemValue = self.options.itemValue(item),
itemText = self.options.itemText(item),
tagClass = self.options.tagClass(item);

// Ignore items allready added
// Ignore items already added
var existing = $.grep(self.itemsArray, function(item) { return self.options.itemValue(item) === itemValue; } )[0];
if (existing && !self.options.allowDuplicates) {
// Invoke onTagExists
@@ -122,15 +122,18 @@
if (self.items().toString().length + item.length + 1 > self.options.maxInputLength)
return;

// register item in internal array and map
self.itemsArray.push(item);

// add a tag element
var $tag = $('<span class="tag ' + htmlEncode(tagClass) + '">' + htmlEncode(itemText) + '<span data-role="remove"></span></span>');
$tag.data('item', item);
self.findInputWrapper().before($tag);
$tag.after(' ');

// associate tag element with array element
item.$element = $tag;

// register item in internal array and map
self.itemsArray.push(item);

// add <option /> if item represents a value not present in one of the <select />'s options
if (self.isSelect && !$('option[value="' + encodeURIComponent(itemValue) + '"]',self.$element)[0]) {
var $option = $('<option selected>' + htmlEncode(itemText) + '</option>');
@@ -230,12 +233,33 @@
},

/**
* Returns the items added as tags
* Returns the items added as tags.
*/
items: function() {
return $.map(this.itemsArray, function(tagitem){
var item = $.extend(true, {}, tagitem);
delete item.$element;
return item;
});
},

/**
* Returns the items with their corresponding HTML elements.
*/
tagitems: function(){
return this.itemsArray;
},

/**
* Returns item by value.
*/
item: function(val){
var self = this;
return ( $.grep(self.itemsArray, function(item) {
return self.options.itemValue(item) == val;
}) )[0];
},

/**
* Assembly value by retrieving the value of each item, and set it on the
* element.