Skip to content

Update assets for bootstrap v4 and turbolinks integ #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

Original Git source - https://github.com/timschlechter/bootstrap-tagsinput

To gemify the assets of `bootstrap-tagsinput` jQuery plugin for Rails >= 3.1
To gemify the assets of `bootstrap-tagsinput` jQuery plugin for Rails >= 4

[![Gem Version](https://badge.fury.io/rb/bootstrap-tagsinput-rails.png)](http://badge.fury.io/rb/bootstrap-tagsinput-rails)

## Compatibility

Designed for Bootstrap 2.3.2 and 3
Designed for Bootstrap 4.0.0-alpha4

## Installation

Expand Down
24 changes: 12 additions & 12 deletions vendor/assets/javascripts/bootstrap-tagsinput.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

var defaultOptions = {
tagClass: function(item) {
return 'label label-info';
return 'badge badge-info';
},
itemValue: function(item) {
return item ? item.toString() : item;
Expand Down Expand Up @@ -104,7 +104,7 @@
if (existing && !self.options.allowDuplicates) {
// Invoke onTagExists
if (self.options.onTagExists) {
var $existingTag = $(".tag", self.$container).filter(function() { return $(this).data("item") === existing; });
var $existingTag = $(".bootstrap-tag", self.$container).filter(function() { return $(this).data("item") === existing; });
self.options.onTagExists(item, $existingTag);
}
return;
Expand All @@ -124,7 +124,7 @@
self.itemsArray.push(item);

// add a tag element
var $tag = $('<span class="tag ' + htmlEncode(tagClass) + '">' + htmlEncode(itemText) + '<span data-role="remove"></span></span>');
var $tag = $('<span class="bootstrap-tag ' + htmlEncode(tagClass) + '">' + htmlEncode(itemText) + '<span data-role="remove"></span></span>');
$tag.data('item', item);
self.findInputWrapper().before($tag);
$tag.after(' ');
Expand Down Expand Up @@ -169,7 +169,7 @@
if (beforeItemRemoveEvent.cancel)
return;

$('.tag', self.$container).filter(function() { return $(this).data('item') === item; }).remove();
$('.bootstrap-tag', self.$container).filter(function() { return $(this).data('item') === item; }).remove();
$('option', self.$element).filter(function() { return $(this).data('item') === item; }).remove();
if($.inArray(item, self.itemsArray) !== -1)
self.itemsArray.splice($.inArray(item, self.itemsArray), 1);
Expand All @@ -191,7 +191,7 @@
removeAll: function() {
var self = this;

$('.tag', self.$container).remove();
$('.bootstrap-tag', self.$container).remove();
$('option', self.$element).remove();

while(self.itemsArray.length > 0)
Expand All @@ -206,7 +206,7 @@
*/
refresh: function() {
var self = this;
$('.tag', self.$container).each(function() {
$('.bootstrap-tag', self.$container).each(function() {
var $tag = $(this),
item = $tag.data('item'),
itemValue = self.options.itemValue(item),
Expand Down Expand Up @@ -261,7 +261,7 @@
makeOptionItemFunction(self.options, 'itemValue');
makeOptionItemFunction(self.options, 'itemText');
makeOptionFunction(self.options, 'tagClass');

// Typeahead Bootstrap version 2.3.2
if (self.options.typeahead) {
var typeahead = self.options.typeahead || {};
Expand Down Expand Up @@ -316,7 +316,7 @@
// typeahead.js
if (self.options.typeaheadjs) {
var typeaheadjs = self.options.typeaheadjs || {};

self.$input.typeahead(null, typeaheadjs).on('typeahead:selected', $.proxy(function (obj, datum) {
if (typeaheadjs.valueKey)
self.add(datum[typeaheadjs.valueKey]);
Expand All @@ -343,7 +343,7 @@
}
}, self));
}


self.$container.on('keydown', 'input', $.proxy(function(event) {
var $input = $(event.target),
Expand Down Expand Up @@ -432,7 +432,7 @@
if (self.$element.attr('disabled')) {
return;
}
self.remove($(event.target).closest('.tag').data('item'));
self.remove($(event.target).closest('.bootstrap-tag').data('item'));
}, self));

// Only add existing value as tags when using strings as tags
Expand Down Expand Up @@ -579,7 +579,7 @@
}

/**
* Returns boolean indicates whether user has pressed an expected key combination.
* Returns boolean indicates whether user has pressed an expected key combination.
* @param object keyPressEvent: JavaScript event object, refer
* http://www.w3.org/TR/2003/WD-DOM-Level-3-Events-20030331/ecma-script-binding.html
* @param object lookupList: expected key combinations, as in:
Expand Down Expand Up @@ -611,7 +611,7 @@
* Initialize tagsinput behaviour on inputs and selects which have
* data-role=tagsinput
*/
$(function() {
$(document).on('turbolinks:load', function() {
$("input[data-role=tagsinput], select[multiple][data-role=tagsinput]").tagsinput();
});
})(window.jQuery);
Loading