vendor/assets/javascripts/select2-full.js in select2-rails-4.0.1.1 vs vendor/assets/javascripts/select2-full.js in select2-rails-4.0.2

- old
+ new

@@ -1,7 +1,7 @@ /*! - * Select2 4.0.1 + * Select2 4.0.2 * https://select2.github.io * * Released under the MIT license * https://github.com/select2/select2/blob/master/LICENSE.md */ @@ -1140,15 +1140,11 @@ if ($.fn.mousewheel) { this.$results.on('mousewheel', function (e) { var top = self.$results.scrollTop(); - var bottom = ( - self.$results.get(0).scrollHeight - - self.$results.scrollTop() + - e.deltaY - ); + var bottom = self.$results.get(0).scrollHeight - top + e.deltaY; var isAtTop = e.deltaY > 0 && top - e.deltaY <= 0; var isAtBottom = e.deltaY < 0 && bottom <= self.$results.height(); if (isAtTop) { @@ -3330,11 +3326,11 @@ // Skip items which were pre-loaded, only merge the data if ($.inArray(item.id, existingIds) >= 0) { var $existingOption = $existing.filter(onlyItem(item)); var existingData = this.item($existingOption); - var newData = $.extend(true, {}, existingData, item); + var newData = $.extend(true, {}, item, existingData); var $newOption = this.option(newData); $existingOption.replaceWith($newOption); @@ -3438,11 +3434,13 @@ } } callback(results); }, function () { - // TODO: Handle AJAX errors + self.trigger('results:message', { + message: 'errorLoading' + }); }); self._request = $request; } @@ -3470,10 +3468,16 @@ if (createTag !== undefined) { this.createTag = createTag; } + var insertTag = options.get('insertTag'); + + if (insertTag !== undefined) { + this.insertTag = insertTag; + } + decorated.call(this, $element, options); if ($.isArray(tags)) { for (var t = 0; t < tags.length; t++) { var tag = tags[t]; @@ -4169,11 +4173,10 @@ var isCurrentlyAbove = this.$dropdown.hasClass('select2-dropdown--above'); var isCurrentlyBelow = this.$dropdown.hasClass('select2-dropdown--below'); var newDirection = null; - var position = this.$container.position(); var offset = this.$container.offset(); offset.bottom = offset.top + this.$container.outerHeight(false); var container = { @@ -4198,18 +4201,24 @@ var css = { left: offset.left, top: container.bottom }; - // Fix positioning with static parents - if (this.$dropdownParent[0].style.position !== 'static') { - var parentOffset = this.$dropdownParent.offset(); + // Determine what the parent element is to use for calciulating the offset + var $offsetParent = this.$dropdownParent; - css.top -= parentOffset.top; - css.left -= parentOffset.left; + // For statically positoned elements, we need to get the element + // that is determining the offset + if ($offsetParent.css('position') === 'static') { + $offsetParent = $offsetParent.offsetParent(); } + var parentOffset = $offsetParent.offset(); + + css.top -= parentOffset.top; + css.left -= parentOffset.left; + if (!isCurrentlyAbove && !isCurrentlyBelow) { newDirection = 'below'; } if (!enoughRoomBelow && enoughRoomAbove && !isCurrentlyAbove) { @@ -4472,11 +4481,11 @@ function Defaults () { this.reset(); } Defaults.prototype.apply = function (options) { - options = $.extend({}, this.defaults, options); + options = $.extend(true, {}, this.defaults, options); if (options.dataAdapter == null) { if (options.ajax != null) { options.dataAdapter = AjaxData; } else if (options.data != null) { @@ -5036,9 +5045,10 @@ id = $element.attr('name') + '-' + Utils.generateChars(2); } else { id = Utils.generateChars(4); } + id = id.replace(/(:|\.|\[|\]|,)/g, ''); id = 'select2-' + id; return id; };