Commit 1c19ded8 authored by Mark Otto's avatar Mark Otto
Browse files

Merge branch 'v4' of https://github.com/twbs/derpstrap into v4

parents 0df8fae7 8cfde5ef
Showing with 413 additions and 156 deletions
+413 -156
...@@ -116,6 +116,13 @@ module.exports = function (grunt) { ...@@ -116,6 +116,13 @@ module.exports = function (grunt) {
} }
}, },
eslint: {
options: {
configFile: 'js/.eslintrc'
},
target: 'js/src/*.js'
},
jscs: { jscs: {
options: { options: {
config: 'js/.jscsrc' config: 'js/.jscsrc'
...@@ -449,7 +456,7 @@ module.exports = function (grunt) { ...@@ -449,7 +456,7 @@ module.exports = function (grunt) {
testSubtasks.push('saucelabs-qunit'); testSubtasks.push('saucelabs-qunit');
} }
grunt.registerTask('test', testSubtasks); grunt.registerTask('test', testSubtasks);
grunt.registerTask('test-js', ['jscs:core', 'jscs:test', 'jscs:grunt', 'qunit']); grunt.registerTask('test-js', ['eslint', 'jscs:core', 'jscs:test', 'jscs:grunt', 'qunit']);
// JS distribution task. // JS distribution task.
grunt.registerTask('dist-js', ['concat', 'lineremover', 'babel:dist', 'stamp', 'uglify:core', 'commonjs']); grunt.registerTask('dist-js', ['concat', 'lineremover', 'babel:dist', 'stamp', 'uglify:core', 'commonjs']);
......
...@@ -80,9 +80,9 @@ var Util = (function ($) { ...@@ -80,9 +80,9 @@ var Util = (function ($) {
var el = document.createElement('bootstrap'); var el = document.createElement('bootstrap');
for (var name in TransitionEndEvent) { for (var _name in TransitionEndEvent) {
if (el.style[name] !== undefined) { if (el.style[_name] !== undefined) {
return { end: TransitionEndEvent[name] }; return { end: TransitionEndEvent[_name] };
} }
} }
...@@ -128,7 +128,9 @@ var Util = (function ($) { ...@@ -128,7 +128,9 @@ var Util = (function ($) {
TRANSITION_END: 'bsTransitionEnd', TRANSITION_END: 'bsTransitionEnd',
getUID: function getUID(prefix) { getUID: function getUID(prefix) {
do prefix += ~ ~(Math.random() * 1000000); while (document.getElementById(prefix)); do {
prefix += ~ ~(Math.random() * 1000000);
} while (document.getElementById(prefix));
return prefix; return prefix;
}, },
...@@ -152,24 +154,28 @@ var Util = (function ($) { ...@@ -152,24 +154,28 @@ var Util = (function ($) {
}, },
supportsTransitionEnd: function supportsTransitionEnd() { supportsTransitionEnd: function supportsTransitionEnd() {
return !!transition; return Boolean(transition);
}, },
typeCheckConfig: function typeCheckConfig(componentName, config, configTypes) { typeCheckConfig: function typeCheckConfig(componentName, config, configTypes) {
for (var property in configTypes) { for (var property in configTypes) {
var expectedTypes = configTypes[property]; if (configTypes.hasOwnProperty(property)) {
var value = config[property]; var expectedTypes = configTypes[property];
var valueType = undefined; var value = config[property];
var valueType = undefined;
if (value && isElement(value)) valueType = 'element';else valueType = toType(value); if (value && isElement(value)) {
valueType = 'element';
} else {
valueType = toType(value);
}
if (!new RegExp(expectedTypes).test(valueType)) { if (!new RegExp(expectedTypes).test(valueType)) {
throw new Error(componentName.toUpperCase() + ': ' + ('Option "' + property + '" provided type "' + valueType + '" ') + ('but expected type "' + expectedTypes + '".')); throw new Error(componentName.toUpperCase() + ': ' + ('Option "' + property + '" provided type "' + valueType + '" ') + ('but expected type "' + expectedTypes + '".'));
}
} }
} }
} }
}; };
setTransitionEndSupport(); setTransitionEndSupport();
...@@ -266,8 +272,8 @@ var Alert = (function ($) { ...@@ -266,8 +272,8 @@ var Alert = (function ($) {
}, { }, {
key: '_getRootElement', key: '_getRootElement',
value: function _getRootElement(element) { value: function _getRootElement(element) {
var parent = false;
var selector = Util.getSelectorFromElement(element); var selector = Util.getSelectorFromElement(element);
var parent = false;
if (selector) { if (selector) {
parent = $(selector)[0]; parent = $(selector)[0];
...@@ -283,6 +289,7 @@ var Alert = (function ($) { ...@@ -283,6 +289,7 @@ var Alert = (function ($) {
key: '_triggerCloseEvent', key: '_triggerCloseEvent',
value: function _triggerCloseEvent(element) { value: function _triggerCloseEvent(element) {
var closeEvent = $.Event(Event.CLOSE); var closeEvent = $.Event(Event.CLOSE);
$(element).trigger(closeEvent); $(element).trigger(closeEvent);
return closeEvent; return closeEvent;
} }
...@@ -383,7 +390,6 @@ var Button = (function ($) { ...@@ -383,7 +390,6 @@ var Button = (function ($) {
var EVENT_KEY = '.' + DATA_KEY; var EVENT_KEY = '.' + DATA_KEY;
var DATA_API_KEY = '.data-api'; var DATA_API_KEY = '.data-api';
var JQUERY_NO_CONFLICT = $.fn[NAME]; var JQUERY_NO_CONFLICT = $.fn[NAME];
var TRANSITION_DURATION = 150;
var ClassName = { var ClassName = {
ACTIVE: 'active', ACTIVE: 'active',
...@@ -702,7 +708,7 @@ var Carousel = (function ($) { ...@@ -702,7 +708,7 @@ var Carousel = (function ($) {
return; return;
} }
if (activeIndex == index) { if (activeIndex === index) {
this.pause(); this.pause();
this.cycle(); this.cycle();
return; return;
...@@ -744,7 +750,7 @@ var Carousel = (function ($) { ...@@ -744,7 +750,7 @@ var Carousel = (function ($) {
$(this._element).on(Event.KEYDOWN, $.proxy(this._keydown, this)); $(this._element).on(Event.KEYDOWN, $.proxy(this._keydown, this));
} }
if (this._config.pause == 'hover' && !('ontouchstart' in document.documentElement)) { if (this._config.pause === 'hover' && !('ontouchstart' in document.documentElement)) {
$(this._element).on(Event.MOUSEENTER, $.proxy(this.pause, this)).on(Event.MOUSELEAVE, $.proxy(this.cycle, this)); $(this._element).on(Event.MOUSEENTER, $.proxy(this.pause, this)).on(Event.MOUSELEAVE, $.proxy(this.cycle, this));
} }
} }
...@@ -753,7 +759,9 @@ var Carousel = (function ($) { ...@@ -753,7 +759,9 @@ var Carousel = (function ($) {
value: function _keydown(event) { value: function _keydown(event) {
event.preventDefault(); event.preventDefault();
if (/input|textarea/i.test(event.target.tagName)) return; if (/input|textarea/i.test(event.target.tagName)) {
return;
}
switch (event.which) { switch (event.which) {
case 37: case 37:
...@@ -777,13 +785,13 @@ var Carousel = (function ($) { ...@@ -777,13 +785,13 @@ var Carousel = (function ($) {
var isPrevDirection = direction === Direction.PREVIOUS; var isPrevDirection = direction === Direction.PREVIOUS;
var activeIndex = this._getItemIndex(activeElement); var activeIndex = this._getItemIndex(activeElement);
var lastItemIndex = this._items.length - 1; var lastItemIndex = this._items.length - 1;
var isGoingToWrap = isPrevDirection && activeIndex === 0 || isNextDirection && activeIndex == lastItemIndex; var isGoingToWrap = isPrevDirection && activeIndex === 0 || isNextDirection && activeIndex === lastItemIndex;
if (isGoingToWrap && !this._config.wrap) { if (isGoingToWrap && !this._config.wrap) {
return activeElement; return activeElement;
} }
var delta = direction == Direction.PREVIOUS ? -1 : 1; var delta = direction === Direction.PREVIOUS ? -1 : 1;
var itemIndex = (activeIndex + delta) % this._items.length; var itemIndex = (activeIndex + delta) % this._items.length;
return itemIndex === -1 ? this._items[this._items.length - 1] : this._items[itemIndex]; return itemIndex === -1 ? this._items[this._items.length - 1] : this._items[itemIndex];
...@@ -821,9 +829,9 @@ var Carousel = (function ($) { ...@@ -821,9 +829,9 @@ var Carousel = (function ($) {
var activeElement = $(this._element).find(Selector.ACTIVE_ITEM)[0]; var activeElement = $(this._element).find(Selector.ACTIVE_ITEM)[0];
var nextElement = element || activeElement && this._getItemByDirection(direction, activeElement); var nextElement = element || activeElement && this._getItemByDirection(direction, activeElement);
var isCycling = !!this._interval; var isCycling = Boolean(this._interval);
var directionalClassName = direction == Direction.NEXT ? ClassName.LEFT : ClassName.RIGHT; var directionalClassName = direction === Direction.NEXT ? ClassName.LEFT : ClassName.RIGHT;
if (nextElement && $(nextElement).hasClass(ClassName.ACTIVE)) { if (nextElement && $(nextElement).hasClass(ClassName.ACTIVE)) {
this._isSliding = false; this._isSliding = false;
...@@ -908,7 +916,7 @@ var Carousel = (function ($) { ...@@ -908,7 +916,7 @@ var Carousel = (function ($) {
$(this).data(DATA_KEY, data); $(this).data(DATA_KEY, data);
} }
if (typeof config == 'number') { if (typeof config === 'number') {
data.to(config); data.to(config);
} else if (action) { } else if (action) {
data[action](); data[action]();
...@@ -934,8 +942,8 @@ var Carousel = (function ($) { ...@@ -934,8 +942,8 @@ var Carousel = (function ($) {
} }
var config = $.extend({}, $(target).data(), $(this).data()); var config = $.extend({}, $(target).data(), $(this).data());
var slideIndex = this.getAttribute('data-slide-to'); var slideIndex = this.getAttribute('data-slide-to');
if (slideIndex) { if (slideIndex) {
config.interval = false; config.interval = false;
} }
...@@ -1159,7 +1167,8 @@ var Collapse = (function ($) { ...@@ -1159,7 +1167,8 @@ var Collapse = (function ($) {
return; return;
} }
var scrollSize = 'scroll' + (dimension[0].toUpperCase() + dimension.slice(1)); var capitalizedDimension = dimension[0].toUpperCase() + dimension.slice(1);
var scrollSize = 'scroll' + capitalizedDimension;
$(this._element).one(Util.TRANSITION_END, complete).emulateTransitionEnd(TRANSITION_DURATION); $(this._element).one(Util.TRANSITION_END, complete).emulateTransitionEnd(TRANSITION_DURATION);
...@@ -1205,7 +1214,8 @@ var Collapse = (function ($) { ...@@ -1205,7 +1214,8 @@ var Collapse = (function ($) {
this._element.style[dimension] = 0; this._element.style[dimension] = 0;
if (!Util.supportsTransitionEnd()) { if (!Util.supportsTransitionEnd()) {
return complete(); complete();
return;
} }
$(this._element).one(Util.TRANSITION_END, complete).emulateTransitionEnd(TRANSITION_DURATION); $(this._element).one(Util.TRANSITION_END, complete).emulateTransitionEnd(TRANSITION_DURATION);
...@@ -1233,7 +1243,7 @@ var Collapse = (function ($) { ...@@ -1233,7 +1243,7 @@ var Collapse = (function ($) {
key: '_getConfig', key: '_getConfig',
value: function _getConfig(config) { value: function _getConfig(config) {
config = $.extend({}, Default, config); config = $.extend({}, Default, config);
config.toggle = !!config.toggle; // coerce string values config.toggle = Boolean(config.toggle); // coerce string values
Util.typeCheckConfig(NAME, config, DefaultType); Util.typeCheckConfig(NAME, config, DefaultType);
return config; return config;
} }
...@@ -1319,7 +1329,6 @@ var Collapse = (function ($) { ...@@ -1319,7 +1329,6 @@ var Collapse = (function ($) {
event.preventDefault(); event.preventDefault();
var target = Collapse._getTargetFromElement(this); var target = Collapse._getTargetFromElement(this);
var data = $(target).data(DATA_KEY); var data = $(target).data(DATA_KEY);
var config = data ? 'toggle' : $(this).data(); var config = data ? 'toggle' : $(this).data();
...@@ -1420,7 +1429,7 @@ var Dropdown = (function ($) { ...@@ -1420,7 +1429,7 @@ var Dropdown = (function ($) {
value: function toggle() { value: function toggle() {
if (this.disabled || $(this).hasClass(ClassName.DISABLED)) { if (this.disabled || $(this).hasClass(ClassName.DISABLED)) {
return; return false;
} }
var parent = Dropdown._getParentFromElement(this); var parent = Dropdown._getParentFromElement(this);
...@@ -1447,7 +1456,7 @@ var Dropdown = (function ($) { ...@@ -1447,7 +1456,7 @@ var Dropdown = (function ($) {
$(parent).trigger(showEvent); $(parent).trigger(showEvent);
if (showEvent.isDefaultPrevented()) { if (showEvent.isDefaultPrevented()) {
return; return false;
} }
this.focus(); this.focus();
...@@ -1580,9 +1589,19 @@ var Dropdown = (function ($) { ...@@ -1580,9 +1589,19 @@ var Dropdown = (function ($) {
var index = items.indexOf(event.target); var index = items.indexOf(event.target);
if (event.which === 38 && index > 0) index--; // up if (event.which === 38 && index > 0) {
if (event.which === 40 && index < items.length - 1) index++; // down // up
if (! ~index) index = 0; index--;
}
if (event.which === 40 && index < items.length - 1) {
// down
index++;
}
if (! ~index) {
index = 0;
}
items[index].focus(); items[index].focus();
} }
...@@ -1842,14 +1861,18 @@ var Modal = (function ($) { ...@@ -1842,14 +1861,18 @@ var Modal = (function ($) {
$(this._element).addClass(ClassName.IN); $(this._element).addClass(ClassName.IN);
if (this._config.focus) this._enforceFocus(); if (this._config.focus) {
this._enforceFocus();
}
var shownEvent = $.Event(Event.SHOWN, { var shownEvent = $.Event(Event.SHOWN, {
relatedTarget: relatedTarget relatedTarget: relatedTarget
}); });
var transitionComplete = function transitionComplete() { var transitionComplete = function transitionComplete() {
if (_this8._config.focus) _this8._element.focus(); if (_this8._config.focus) {
_this8._element.focus();
}
$(_this8._element).trigger(shownEvent); $(_this8._element).trigger(shownEvent);
}; };
...@@ -2006,7 +2029,7 @@ var Modal = (function ($) { ...@@ -2006,7 +2029,7 @@ var Modal = (function ($) {
} }
if (this._isBodyOverflowing && !isModalOverflowing) { if (this._isBodyOverflowing && !isModalOverflowing) {
this._element.style.paddingRight = this._scrollbarWidth + 'px'; this._element.style.paddingRight = this._scrollbarWidth + 'px~';
} }
} }
}, { }, {
...@@ -2035,7 +2058,7 @@ var Modal = (function ($) { ...@@ -2035,7 +2058,7 @@ var Modal = (function ($) {
this._originalBodyPadding = document.body.style.paddingRight || ''; this._originalBodyPadding = document.body.style.paddingRight || '';
if (this._isBodyOverflowing) { if (this._isBodyOverflowing) {
document.body.style.paddingRight = bodyPadding + this._scrollbarWidth + 'px'; document.body.style.paddingRight = bodyPadding + (this._scrollbarWidth + 'px');
} }
} }
}, { }, {
...@@ -2526,7 +2549,7 @@ var Tab = (function ($) { ...@@ -2526,7 +2549,7 @@ var Tab = (function ($) {
value: function show() { value: function show() {
var _this15 = this; var _this15 = this;
if (this._element.parentNode && this._element.parentNode.nodeType == Node.ELEMENT_NODE && $(this._element).parent().hasClass(ClassName.ACTIVE)) { if (this._element.parentNode && this._element.parentNode.nodeType === Node.ELEMENT_NODE && $(this._element).parent().hasClass(ClassName.ACTIVE)) {
return; return;
} }
...@@ -2600,7 +2623,7 @@ var Tab = (function ($) { ...@@ -2600,7 +2623,7 @@ var Tab = (function ($) {
key: '_activate', key: '_activate',
value: function _activate(element, container, callback) { value: function _activate(element, container, callback) {
var active = $(container).find(Selector.ACTIVE_CHILD)[0]; var active = $(container).find(Selector.ACTIVE_CHILD)[0];
var isTransitioning = callback && Util.supportsTransitionEnd() && (active && $(active).hasClass(ClassName.FADE) || !!$(container).find(Selector.FADE_CHILD)[0]); var isTransitioning = callback && Util.supportsTransitionEnd() && (active && $(active).hasClass(ClassName.FADE) || Boolean($(container).find(Selector.FADE_CHILD)[0]));
var complete = $.proxy(this._transitionComplete, this, element, active, isTransitioning, callback); var complete = $.proxy(this._transitionComplete, this, element, active, isTransitioning, callback);
...@@ -2863,11 +2886,9 @@ var Tooltip = (function ($) { ...@@ -2863,11 +2886,9 @@ var Tooltip = (function ($) {
}, { }, {
key: 'toggle', key: 'toggle',
value: function toggle(event) { value: function toggle(event) {
var context = this;
var dataKey = this.constructor.DATA_KEY;
if (event) { if (event) {
context = $(event.currentTarget).data(dataKey); var dataKey = this.constructor.DATA_KEY;
var context = $(event.currentTarget).data(dataKey);
if (!context) { if (!context) {
context = new this.constructor(event.currentTarget, this._getDelegateConfig()); context = new this.constructor(event.currentTarget, this._getDelegateConfig());
...@@ -2882,7 +2903,13 @@ var Tooltip = (function ($) { ...@@ -2882,7 +2903,13 @@ var Tooltip = (function ($) {
context._leave(null, context); context._leave(null, context);
} }
} else { } else {
$(context.getTipElement()).hasClass(ClassName.IN) ? context._leave(null, context) : context._enter(null, context);
if ($(this.getTipElement()).hasClass(ClassName.IN)) {
this._leave(null, this);
return;
}
this._enter(null, this);
} }
} }
}, { }, {
...@@ -2947,9 +2974,9 @@ var Tooltip = (function ($) { ...@@ -2947,9 +2974,9 @@ var Tooltip = (function ($) {
$(this.element).trigger(this.constructor.Event.INSERTED); $(this.element).trigger(this.constructor.Event.INSERTED);
this._tether = new Tether({ this._tether = new Tether({
attachment: attachment,
element: tip, element: tip,
target: this.element, target: this.element,
attachment: attachment,
classes: TetherClass, classes: TetherClass,
classPrefix: CLASS_PREFIX, classPrefix: CLASS_PREFIX,
offset: this.config.offset, offset: this.config.offset,
...@@ -2972,7 +2999,12 @@ var Tooltip = (function ($) { ...@@ -2972,7 +2999,12 @@ var Tooltip = (function ($) {
} }
}; };
Util.supportsTransitionEnd() && $(this.tip).hasClass(ClassName.FADE) ? $(this.tip).one(Util.TRANSITION_END, complete).emulateTransitionEnd(Tooltip._TRANSITION_DURATION) : complete(); if (Util.supportsTransitionEnd() && $(this.tip).hasClass(ClassName.FADE)) {
$(this.tip).one(Util.TRANSITION_END, complete).emulateTransitionEnd(Tooltip._TRANSITION_DURATION);
return;
}
complete();
} }
} }
}, { }, {
...@@ -3019,7 +3051,7 @@ var Tooltip = (function ($) { ...@@ -3019,7 +3051,7 @@ var Tooltip = (function ($) {
}, { }, {
key: 'isWithContent', key: 'isWithContent',
value: function isWithContent() { value: function isWithContent() {
return !!this.getTitle(); return Boolean(this.getTitle());
} }
}, { }, {
key: 'getTipElement', key: 'getTipElement',
...@@ -3082,8 +3114,8 @@ var Tooltip = (function ($) { ...@@ -3082,8 +3114,8 @@ var Tooltip = (function ($) {
if (trigger === 'click') { if (trigger === 'click') {
$(_this18.element).on(_this18.constructor.Event.CLICK, _this18.config.selector, $.proxy(_this18.toggle, _this18)); $(_this18.element).on(_this18.constructor.Event.CLICK, _this18.config.selector, $.proxy(_this18.toggle, _this18));
} else if (trigger !== Trigger.MANUAL) { } else if (trigger !== Trigger.MANUAL) {
var eventIn = trigger == Trigger.HOVER ? _this18.constructor.Event.MOUSEENTER : _this18.constructor.Event.FOCUSIN; var eventIn = trigger === Trigger.HOVER ? _this18.constructor.Event.MOUSEENTER : _this18.constructor.Event.FOCUSIN;
var eventOut = trigger == Trigger.HOVER ? _this18.constructor.Event.MOUSELEAVE : _this18.constructor.Event.FOCUSOUT; var eventOut = trigger === Trigger.HOVER ? _this18.constructor.Event.MOUSELEAVE : _this18.constructor.Event.FOCUSOUT;
$(_this18.element).on(eventIn, _this18.config.selector, $.proxy(_this18._enter, _this18)).on(eventOut, _this18.config.selector, $.proxy(_this18._leave, _this18)); $(_this18.element).on(eventIn, _this18.config.selector, $.proxy(_this18._enter, _this18)).on(eventOut, _this18.config.selector, $.proxy(_this18._leave, _this18));
} }
...@@ -3125,7 +3157,7 @@ var Tooltip = (function ($) { ...@@ -3125,7 +3157,7 @@ var Tooltip = (function ($) {
} }
if (event) { if (event) {
context._activeTrigger[event.type == 'focusin' ? Trigger.FOCUS : Trigger.HOVER] = true; context._activeTrigger[event.type === 'focusin' ? Trigger.FOCUS : Trigger.HOVER] = true;
} }
if ($(context.getTipElement()).hasClass(ClassName.IN) || context._hoverState === HoverState.IN) { if ($(context.getTipElement()).hasClass(ClassName.IN) || context._hoverState === HoverState.IN) {
...@@ -3161,7 +3193,7 @@ var Tooltip = (function ($) { ...@@ -3161,7 +3193,7 @@ var Tooltip = (function ($) {
} }
if (event) { if (event) {
context._activeTrigger[event.type == 'focusout' ? Trigger.FOCUS : Trigger.HOVER] = false; context._activeTrigger[event.type === 'focusout' ? Trigger.FOCUS : Trigger.HOVER] = false;
} }
if (context._isWithActiveTrigger()) { if (context._isWithActiveTrigger()) {
...@@ -3217,9 +3249,8 @@ var Tooltip = (function ($) { ...@@ -3217,9 +3249,8 @@ var Tooltip = (function ($) {
if (this.config) { if (this.config) {
for (var key in this.config) { for (var key in this.config) {
var value = this.config[key]; if (this.constructor.Default[key] !== this.config[key]) {
if (this.constructor.Default[key] !== value) { config[key] = this.config[key];
config[key] = value;
} }
} }
} }
...@@ -3415,7 +3446,7 @@ var Popover = (function ($) { ...@@ -3415,7 +3446,7 @@ var Popover = (function ($) {
}, { }, {
key: '_getContent', key: '_getContent',
value: function _getContent() { value: function _getContent() {
return this.element.getAttribute('data-content') || (typeof this.config.content == 'function' ? this.config.content.call(this.element) : this.config.content); return this.element.getAttribute('data-content') || (typeof this.config.content === 'function' ? this.config.content.call(this.element) : this.config.content);
} }
// static // static
......
This diff is collapsed.
...@@ -110,8 +110,8 @@ ...@@ -110,8 +110,8 @@
}, { }, {
key: '_getRootElement', key: '_getRootElement',
value: function _getRootElement(element) { value: function _getRootElement(element) {
var parent = false;
var selector = _Util['default'].getSelectorFromElement(element); var selector = _Util['default'].getSelectorFromElement(element);
var parent = false;
if (selector) { if (selector) {
parent = $(selector)[0]; parent = $(selector)[0];
...@@ -127,6 +127,7 @@ ...@@ -127,6 +127,7 @@
key: '_triggerCloseEvent', key: '_triggerCloseEvent',
value: function _triggerCloseEvent(element) { value: function _triggerCloseEvent(element) {
var closeEvent = $.Event(Event.CLOSE); var closeEvent = $.Event(Event.CLOSE);
$(element).trigger(closeEvent); $(element).trigger(closeEvent);
return closeEvent; return closeEvent;
} }
......
...@@ -38,7 +38,6 @@ ...@@ -38,7 +38,6 @@
var EVENT_KEY = '.' + DATA_KEY; var EVENT_KEY = '.' + DATA_KEY;
var DATA_API_KEY = '.data-api'; var DATA_API_KEY = '.data-api';
var JQUERY_NO_CONFLICT = $.fn[NAME]; var JQUERY_NO_CONFLICT = $.fn[NAME];
var TRANSITION_DURATION = 150;
var ClassName = { var ClassName = {
ACTIVE: 'active', ACTIVE: 'active',
......
...@@ -194,7 +194,7 @@ ...@@ -194,7 +194,7 @@
return; return;
} }
if (activeIndex == index) { if (activeIndex === index) {
this.pause(); this.pause();
this.cycle(); this.cycle();
return; return;
...@@ -236,7 +236,7 @@ ...@@ -236,7 +236,7 @@
$(this._element).on(Event.KEYDOWN, $.proxy(this._keydown, this)); $(this._element).on(Event.KEYDOWN, $.proxy(this._keydown, this));
} }
if (this._config.pause == 'hover' && !('ontouchstart' in document.documentElement)) { if (this._config.pause === 'hover' && !('ontouchstart' in document.documentElement)) {
$(this._element).on(Event.MOUSEENTER, $.proxy(this.pause, this)).on(Event.MOUSELEAVE, $.proxy(this.cycle, this)); $(this._element).on(Event.MOUSEENTER, $.proxy(this.pause, this)).on(Event.MOUSELEAVE, $.proxy(this.cycle, this));
} }
} }
...@@ -245,7 +245,9 @@ ...@@ -245,7 +245,9 @@
value: function _keydown(event) { value: function _keydown(event) {
event.preventDefault(); event.preventDefault();
if (/input|textarea/i.test(event.target.tagName)) return; if (/input|textarea/i.test(event.target.tagName)) {
return;
}
switch (event.which) { switch (event.which) {
case 37: case 37:
...@@ -269,13 +271,13 @@ ...@@ -269,13 +271,13 @@
var isPrevDirection = direction === Direction.PREVIOUS; var isPrevDirection = direction === Direction.PREVIOUS;
var activeIndex = this._getItemIndex(activeElement); var activeIndex = this._getItemIndex(activeElement);
var lastItemIndex = this._items.length - 1; var lastItemIndex = this._items.length - 1;
var isGoingToWrap = isPrevDirection && activeIndex === 0 || isNextDirection && activeIndex == lastItemIndex; var isGoingToWrap = isPrevDirection && activeIndex === 0 || isNextDirection && activeIndex === lastItemIndex;
if (isGoingToWrap && !this._config.wrap) { if (isGoingToWrap && !this._config.wrap) {
return activeElement; return activeElement;
} }
var delta = direction == Direction.PREVIOUS ? -1 : 1; var delta = direction === Direction.PREVIOUS ? -1 : 1;
var itemIndex = (activeIndex + delta) % this._items.length; var itemIndex = (activeIndex + delta) % this._items.length;
return itemIndex === -1 ? this._items[this._items.length - 1] : this._items[itemIndex]; return itemIndex === -1 ? this._items[this._items.length - 1] : this._items[itemIndex];
...@@ -313,9 +315,9 @@ ...@@ -313,9 +315,9 @@
var activeElement = $(this._element).find(Selector.ACTIVE_ITEM)[0]; var activeElement = $(this._element).find(Selector.ACTIVE_ITEM)[0];
var nextElement = element || activeElement && this._getItemByDirection(direction, activeElement); var nextElement = element || activeElement && this._getItemByDirection(direction, activeElement);
var isCycling = !!this._interval; var isCycling = Boolean(this._interval);
var directionalClassName = direction == Direction.NEXT ? ClassName.LEFT : ClassName.RIGHT; var directionalClassName = direction === Direction.NEXT ? ClassName.LEFT : ClassName.RIGHT;
if (nextElement && $(nextElement).hasClass(ClassName.ACTIVE)) { if (nextElement && $(nextElement).hasClass(ClassName.ACTIVE)) {
this._isSliding = false; this._isSliding = false;
...@@ -400,7 +402,7 @@ ...@@ -400,7 +402,7 @@
$(this).data(DATA_KEY, data); $(this).data(DATA_KEY, data);
} }
if (typeof config == 'number') { if (typeof config === 'number') {
data.to(config); data.to(config);
} else if (action) { } else if (action) {
data[action](); data[action]();
...@@ -426,8 +428,8 @@ ...@@ -426,8 +428,8 @@
} }
var config = $.extend({}, $(target).data(), $(this).data()); var config = $.extend({}, $(target).data(), $(this).data());
var slideIndex = this.getAttribute('data-slide-to'); var slideIndex = this.getAttribute('data-slide-to');
if (slideIndex) { if (slideIndex) {
config.interval = false; config.interval = false;
} }
......
...@@ -192,7 +192,8 @@ ...@@ -192,7 +192,8 @@
return; return;
} }
var scrollSize = 'scroll' + (dimension[0].toUpperCase() + dimension.slice(1)); var capitalizedDimension = dimension[0].toUpperCase() + dimension.slice(1);
var scrollSize = 'scroll' + capitalizedDimension;
$(this._element).one(_Util['default'].TRANSITION_END, complete).emulateTransitionEnd(TRANSITION_DURATION); $(this._element).one(_Util['default'].TRANSITION_END, complete).emulateTransitionEnd(TRANSITION_DURATION);
...@@ -238,7 +239,8 @@ ...@@ -238,7 +239,8 @@
this._element.style[dimension] = 0; this._element.style[dimension] = 0;
if (!_Util['default'].supportsTransitionEnd()) { if (!_Util['default'].supportsTransitionEnd()) {
return complete(); complete();
return;
} }
$(this._element).one(_Util['default'].TRANSITION_END, complete).emulateTransitionEnd(TRANSITION_DURATION); $(this._element).one(_Util['default'].TRANSITION_END, complete).emulateTransitionEnd(TRANSITION_DURATION);
...@@ -266,7 +268,7 @@ ...@@ -266,7 +268,7 @@
key: '_getConfig', key: '_getConfig',
value: function _getConfig(config) { value: function _getConfig(config) {
config = $.extend({}, Default, config); config = $.extend({}, Default, config);
config.toggle = !!config.toggle; // coerce string values config.toggle = Boolean(config.toggle); // coerce string values
_Util['default'].typeCheckConfig(NAME, config, DefaultType); _Util['default'].typeCheckConfig(NAME, config, DefaultType);
return config; return config;
} }
...@@ -352,7 +354,6 @@ ...@@ -352,7 +354,6 @@
event.preventDefault(); event.preventDefault();
var target = Collapse._getTargetFromElement(this); var target = Collapse._getTargetFromElement(this);
var data = $(target).data(DATA_KEY); var data = $(target).data(DATA_KEY);
var config = data ? 'toggle' : $(this).data(); var config = data ? 'toggle' : $(this).data();
......
...@@ -99,7 +99,7 @@ ...@@ -99,7 +99,7 @@
value: function toggle() { value: function toggle() {
if (this.disabled || $(this).hasClass(ClassName.DISABLED)) { if (this.disabled || $(this).hasClass(ClassName.DISABLED)) {
return; return false;
} }
var parent = Dropdown._getParentFromElement(this); var parent = Dropdown._getParentFromElement(this);
...@@ -126,7 +126,7 @@ ...@@ -126,7 +126,7 @@
$(parent).trigger(showEvent); $(parent).trigger(showEvent);
if (showEvent.isDefaultPrevented()) { if (showEvent.isDefaultPrevented()) {
return; return false;
} }
this.focus(); this.focus();
...@@ -259,9 +259,19 @@ ...@@ -259,9 +259,19 @@
var index = items.indexOf(event.target); var index = items.indexOf(event.target);
if (event.which === 38 && index > 0) index--; // up if (event.which === 38 && index > 0) {
if (event.which === 40 && index < items.length - 1) index++; // down // up
if (! ~index) index = 0; index--;
}
if (event.which === 40 && index < items.length - 1) {
// down
index++;
}
if (! ~index) {
index = 0;
}
items[index].focus(); items[index].focus();
} }
......
...@@ -247,14 +247,18 @@ ...@@ -247,14 +247,18 @@
$(this._element).addClass(ClassName.IN); $(this._element).addClass(ClassName.IN);
if (this._config.focus) this._enforceFocus(); if (this._config.focus) {
this._enforceFocus();
}
var shownEvent = $.Event(Event.SHOWN, { var shownEvent = $.Event(Event.SHOWN, {
relatedTarget: relatedTarget relatedTarget: relatedTarget
}); });
var transitionComplete = function transitionComplete() { var transitionComplete = function transitionComplete() {
if (_this2._config.focus) _this2._element.focus(); if (_this2._config.focus) {
_this2._element.focus();
}
$(_this2._element).trigger(shownEvent); $(_this2._element).trigger(shownEvent);
}; };
...@@ -411,7 +415,7 @@ ...@@ -411,7 +415,7 @@
} }
if (this._isBodyOverflowing && !isModalOverflowing) { if (this._isBodyOverflowing && !isModalOverflowing) {
this._element.style.paddingRight = this._scrollbarWidth + 'px'; this._element.style.paddingRight = this._scrollbarWidth + 'px~';
} }
} }
}, { }, {
...@@ -440,7 +444,7 @@ ...@@ -440,7 +444,7 @@
this._originalBodyPadding = document.body.style.paddingRight || ''; this._originalBodyPadding = document.body.style.paddingRight || '';
if (this._isBodyOverflowing) { if (this._isBodyOverflowing) {
document.body.style.paddingRight = bodyPadding + this._scrollbarWidth + 'px'; document.body.style.paddingRight = bodyPadding + (this._scrollbarWidth + 'px');
} }
} }
}, { }, {
......
...@@ -140,7 +140,7 @@ ...@@ -140,7 +140,7 @@
}, { }, {
key: '_getContent', key: '_getContent',
value: function _getContent() { value: function _getContent() {
return this.element.getAttribute('data-content') || (typeof this.config.content == 'function' ? this.config.content.call(this.element) : this.config.content); return this.element.getAttribute('data-content') || (typeof this.config.content === 'function' ? this.config.content.call(this.element) : this.config.content);
} }
// static // static
......
...@@ -100,7 +100,7 @@ ...@@ -100,7 +100,7 @@
value: function show() { value: function show() {
var _this = this; var _this = this;
if (this._element.parentNode && this._element.parentNode.nodeType == Node.ELEMENT_NODE && $(this._element).parent().hasClass(ClassName.ACTIVE)) { if (this._element.parentNode && this._element.parentNode.nodeType === Node.ELEMENT_NODE && $(this._element).parent().hasClass(ClassName.ACTIVE)) {
return; return;
} }
...@@ -174,7 +174,7 @@ ...@@ -174,7 +174,7 @@
key: '_activate', key: '_activate',
value: function _activate(element, container, callback) { value: function _activate(element, container, callback) {
var active = $(container).find(Selector.ACTIVE_CHILD)[0]; var active = $(container).find(Selector.ACTIVE_CHILD)[0];
var isTransitioning = callback && _Util['default'].supportsTransitionEnd() && (active && $(active).hasClass(ClassName.FADE) || !!$(container).find(Selector.FADE_CHILD)[0]); var isTransitioning = callback && _Util['default'].supportsTransitionEnd() && (active && $(active).hasClass(ClassName.FADE) || Boolean($(container).find(Selector.FADE_CHILD)[0]));
var complete = $.proxy(this._transitionComplete, this, element, active, isTransitioning, callback); var complete = $.proxy(this._transitionComplete, this, element, active, isTransitioning, callback);
......
...@@ -171,11 +171,9 @@ ...@@ -171,11 +171,9 @@
}, { }, {
key: 'toggle', key: 'toggle',
value: function toggle(event) { value: function toggle(event) {
var context = this;
var dataKey = this.constructor.DATA_KEY;
if (event) { if (event) {
context = $(event.currentTarget).data(dataKey); var dataKey = this.constructor.DATA_KEY;
var context = $(event.currentTarget).data(dataKey);
if (!context) { if (!context) {
context = new this.constructor(event.currentTarget, this._getDelegateConfig()); context = new this.constructor(event.currentTarget, this._getDelegateConfig());
...@@ -190,7 +188,13 @@ ...@@ -190,7 +188,13 @@
context._leave(null, context); context._leave(null, context);
} }
} else { } else {
$(context.getTipElement()).hasClass(ClassName.IN) ? context._leave(null, context) : context._enter(null, context);
if ($(this.getTipElement()).hasClass(ClassName.IN)) {
this._leave(null, this);
return;
}
this._enter(null, this);
} }
} }
}, { }, {
...@@ -255,9 +259,9 @@ ...@@ -255,9 +259,9 @@
$(this.element).trigger(this.constructor.Event.INSERTED); $(this.element).trigger(this.constructor.Event.INSERTED);
this._tether = new Tether({ this._tether = new Tether({
attachment: attachment,
element: tip, element: tip,
target: this.element, target: this.element,
attachment: attachment,
classes: TetherClass, classes: TetherClass,
classPrefix: CLASS_PREFIX, classPrefix: CLASS_PREFIX,
offset: this.config.offset, offset: this.config.offset,
...@@ -280,7 +284,12 @@ ...@@ -280,7 +284,12 @@
} }
}; };
_Util['default'].supportsTransitionEnd() && $(this.tip).hasClass(ClassName.FADE) ? $(this.tip).one(_Util['default'].TRANSITION_END, complete).emulateTransitionEnd(Tooltip._TRANSITION_DURATION) : complete(); if (_Util['default'].supportsTransitionEnd() && $(this.tip).hasClass(ClassName.FADE)) {
$(this.tip).one(_Util['default'].TRANSITION_END, complete).emulateTransitionEnd(Tooltip._TRANSITION_DURATION);
return;
}
complete();
} }
} }
}, { }, {
...@@ -327,7 +336,7 @@ ...@@ -327,7 +336,7 @@
}, { }, {
key: 'isWithContent', key: 'isWithContent',
value: function isWithContent() { value: function isWithContent() {
return !!this.getTitle(); return Boolean(this.getTitle());
} }
}, { }, {
key: 'getTipElement', key: 'getTipElement',
...@@ -390,8 +399,8 @@ ...@@ -390,8 +399,8 @@
if (trigger === 'click') { if (trigger === 'click') {
$(_this3.element).on(_this3.constructor.Event.CLICK, _this3.config.selector, $.proxy(_this3.toggle, _this3)); $(_this3.element).on(_this3.constructor.Event.CLICK, _this3.config.selector, $.proxy(_this3.toggle, _this3));
} else if (trigger !== Trigger.MANUAL) { } else if (trigger !== Trigger.MANUAL) {
var eventIn = trigger == Trigger.HOVER ? _this3.constructor.Event.MOUSEENTER : _this3.constructor.Event.FOCUSIN; var eventIn = trigger === Trigger.HOVER ? _this3.constructor.Event.MOUSEENTER : _this3.constructor.Event.FOCUSIN;
var eventOut = trigger == Trigger.HOVER ? _this3.constructor.Event.MOUSELEAVE : _this3.constructor.Event.FOCUSOUT; var eventOut = trigger === Trigger.HOVER ? _this3.constructor.Event.MOUSELEAVE : _this3.constructor.Event.FOCUSOUT;
$(_this3.element).on(eventIn, _this3.config.selector, $.proxy(_this3._enter, _this3)).on(eventOut, _this3.config.selector, $.proxy(_this3._leave, _this3)); $(_this3.element).on(eventIn, _this3.config.selector, $.proxy(_this3._enter, _this3)).on(eventOut, _this3.config.selector, $.proxy(_this3._leave, _this3));
} }
...@@ -433,7 +442,7 @@ ...@@ -433,7 +442,7 @@
} }
if (event) { if (event) {
context._activeTrigger[event.type == 'focusin' ? Trigger.FOCUS : Trigger.HOVER] = true; context._activeTrigger[event.type === 'focusin' ? Trigger.FOCUS : Trigger.HOVER] = true;
} }
if ($(context.getTipElement()).hasClass(ClassName.IN) || context._hoverState === HoverState.IN) { if ($(context.getTipElement()).hasClass(ClassName.IN) || context._hoverState === HoverState.IN) {
...@@ -469,7 +478,7 @@ ...@@ -469,7 +478,7 @@
} }
if (event) { if (event) {
context._activeTrigger[event.type == 'focusout' ? Trigger.FOCUS : Trigger.HOVER] = false; context._activeTrigger[event.type === 'focusout' ? Trigger.FOCUS : Trigger.HOVER] = false;
} }
if (context._isWithActiveTrigger()) { if (context._isWithActiveTrigger()) {
...@@ -525,9 +534,8 @@ ...@@ -525,9 +534,8 @@
if (this.config) { if (this.config) {
for (var key in this.config) { for (var key in this.config) {
var value = this.config[key]; if (this.constructor.Default[key] !== this.config[key]) {
if (this.constructor.Default[key] !== value) { config[key] = this.config[key];
config[key] = value;
} }
} }
} }
......
...@@ -65,9 +65,9 @@ ...@@ -65,9 +65,9 @@
var el = document.createElement('bootstrap'); var el = document.createElement('bootstrap');
for (var name in TransitionEndEvent) { for (var _name in TransitionEndEvent) {
if (el.style[name] !== undefined) { if (el.style[_name] !== undefined) {
return { end: TransitionEndEvent[name] }; return { end: TransitionEndEvent[_name] };
} }
} }
...@@ -113,7 +113,9 @@ ...@@ -113,7 +113,9 @@
TRANSITION_END: 'bsTransitionEnd', TRANSITION_END: 'bsTransitionEnd',
getUID: function getUID(prefix) { getUID: function getUID(prefix) {
do prefix += ~ ~(Math.random() * 1000000); while (document.getElementById(prefix)); do {
prefix += ~ ~(Math.random() * 1000000);
} while (document.getElementById(prefix));
return prefix; return prefix;
}, },
...@@ -137,24 +139,28 @@ ...@@ -137,24 +139,28 @@
}, },
supportsTransitionEnd: function supportsTransitionEnd() { supportsTransitionEnd: function supportsTransitionEnd() {
return !!transition; return Boolean(transition);
}, },
typeCheckConfig: function typeCheckConfig(componentName, config, configTypes) { typeCheckConfig: function typeCheckConfig(componentName, config, configTypes) {
for (var property in configTypes) { for (var property in configTypes) {
var expectedTypes = configTypes[property]; if (configTypes.hasOwnProperty(property)) {
var value = config[property]; var expectedTypes = configTypes[property];
var valueType = undefined; var value = config[property];
var valueType = undefined;
if (value && isElement(value)) valueType = 'element';else valueType = toType(value);
if (value && isElement(value)) {
if (!new RegExp(expectedTypes).test(valueType)) { valueType = 'element';
throw new Error(componentName.toUpperCase() + ': ' + ('Option "' + property + '" provided type "' + valueType + '" ') + ('but expected type "' + expectedTypes + '".')); } else {
valueType = toType(value);
}
if (!new RegExp(expectedTypes).test(valueType)) {
throw new Error(componentName.toUpperCase() + ': ' + ('Option "' + property + '" provided type "' + valueType + '" ') + ('but expected type "' + expectedTypes + '".'));
}
} }
} }
} }
}; };
setTransitionEndSupport(); setTransitionEndSupport();
......
{
"parser": "babel-eslint",
"env": {
"browser": true
},
"rules": {
// Possible Errors
"comma-dangle": [2, "never"],
"no-cond-assign": 2,
"no-console": 2,
"no-constant-condition": 2,
"no-control-regex": 2,
"no-debugger": 2,
"no-dupe-args": 2,
"no-dupe-keys": 2,
"no-duplicate-case": 2,
"no-empty-character-class": 2,
"no-empty": 2,
"no-ex-assign": 2,
"no-extra-boolean-cast": 2,
"no-extra-parens": 0,
"no-extra-semi": 2,
"no-func-assign": 2,
"no-inner-declarations": 2,
"no-invalid-regexp": 2,
"no-irregular-whitespace": 0,
"no-negated-in-lhs": 2,
"no-obj-calls": 2,
"no-regex-spaces": 2,
"no-sparse-arrays": 2,
"no-unreachable": 2,
"use-isnan": 2,
"valid-jsdoc": 0,
"valid-typeof": 2,
"no-unexpected-multiline": 2,
//Best Practices
"accessor-pairs": 2,
"block-scoped-var": 2,
"consistent-return": 2,
"curly": 2,
"default-case": 2,
"dot-notation": 0,
"dot-location": 0,
"eqeqeq": 2,
"guard-for-in": 2,
"no-alert": 2,
"no-caller": 2,
"no-div-regex": 2,
"no-else-return": 2,
"no-empty-label": 2,
"no-eq-null": 2,
"no-eval": 2,
"no-extend-native": 2,
"no-extra-bind": 2,
"no-fallthrough": 2,
"no-floating-decimal": 2,
"no-implicit-coercion": 2,
"no-implied-eval": 2,
"no-invalid-this": 0,
"no-iterator": 2,
"no-labels": 2,
"no-lone-blocks": 2,
"no-loop-func": 2,
"no-multi-spaces": 0,
"no-multi-str": 0,
"no-native-reassign": 2,
"no-new-func": 0,
"no-new-wrappers": 2,
"no-new": 2,
"no-octal-escape": 2,
"no-octal": 2,
"no-param-reassign": 0,
"no-process-env": 2,
"no-proto": 2,
"no-redeclare": 2,
"no-return-assign": 2,
"no-script-url": 2,
"no-self-compare": 2,
"no-sequences": 2,
"no-throw-literal": 2,
"no-unused-expressions": 2,
"no-useless-call": 2,
"no-void": 2,
"no-warning-comments": 0,
"no-with": 2,
"radix": 2,
"vars-on-top": 0,
"wrap-iife": 2,
"yoda": 2,
// Variables
"init-declarations": 0,
"no-catch-shadow": 2,
"no-delete-var": 2,
"no-label-var": 2,
"no-shadow-restricted-names": 2,
"no-shadow": 0,
"no-undef-init": 2,
"no-undef": 0,
"no-undefined": 0,
"no-unused-vars": 2,
"no-use-before-define": 0,
// Stylistic
"array-bracket-spacing": 2,
"block-spacing": 2,
"brace-style": 2,
"camelcase": 2,
"comma-spacing": 2,
"comma-style": 2,
"computed-property-spacing": 2,
"consistent-this": 2,
"eol-last": 2,
"func-names": 0,
"func-style": 0,
"indent": 0,
"key-spacing": 0,
"lines-around-comment": 0,
"linebreak-style": 2,
"new-cap": 0,
"new-parens": 2,
"newline-after-var": 0,
"no-array-constructor": 2,
"no-continue": 0,
"no-inline-comments": 0,
"no-lonely-if": 2,
"no-mixed-spaces-and-tabs": 2,
"no-multiple-empty-lines": 2,
"no-nested-ternary": 0,
"no-new-object": 2,
"no-spaced-func": 2,
"no-ternary": 0,
"no-trailing-spaces": 2,
"no-underscore-dangle": 0,
"no-unneeded-ternary": 2,
"object-curly-spacing": [1, "always"],
"one-var": 0,
"operator-assignment": 2,
"operator-linebreak": 0,
"padded-blocks": 0,
"quote-props": 0,
"quotes": 0,
"semi-spacing": 0,
"semi": [2, "never"],
"sort-vars": 2,
"space-after-keywords": 2,
"space-before-blocks": 2,
"space-before-function-paren": 0,
"space-in-parens": 2,
"space-infix-ops": 2,
"space-return-throw-case": 2,
"space-unary-ops": 2,
"spaced-comment": 2,
"spaced-comment": 2,
// es6
"arrow-parens": 2,
"arrow-spacing": 2,
"constructor-super": 2,
"generator-star-spacing": 2,
"no-class-assign": 2,
"no-const-assign": 2,
"no-dupe-class-members": 2,
"no-this-before-super": 2,
"no-var": 2,
"object-shorthand": 2,
"prefer-arrow-callback": 2,
"prefer-const": 0,
"prefer-spread": 2,
"prefer-reflect": 0,
"prefer-template": 2,
"require-yield": 2
}
}
/** /**
* -------------------------------------------------------------------------- * --------------------------------------------------------------------------
* Bootstrap (v4.0.0): util.js * Bootstrap (v4.0.0): util.js
...@@ -100,7 +101,7 @@ var Util = (function ($) { ...@@ -100,7 +101,7 @@ var Util = (function ($) {
TRANSITION_END: 'bsTransitionEnd', TRANSITION_END: 'bsTransitionEnd',
getUID: function getUID(prefix) { getUID: function getUID(prefix) {
do prefix += ~ ~(Math.random() * 1000000); while (document.getElementById(prefix)); do { prefix += ~ ~(Math.random() * 1000000); } while (document.getElementById(prefix));
return prefix; return prefix;
}, },
......
...@@ -86,8 +86,8 @@ const Alert = (($) => { ...@@ -86,8 +86,8 @@ const Alert = (($) => {
// private // private
_getRootElement(element) { _getRootElement(element) {
let parent = false
let selector = Util.getSelectorFromElement(element) let selector = Util.getSelectorFromElement(element)
let parent = false
if (selector) { if (selector) {
parent = $(selector)[0] parent = $(selector)[0]
...@@ -101,7 +101,8 @@ const Alert = (($) => { ...@@ -101,7 +101,8 @@ const Alert = (($) => {
} }
_triggerCloseEvent(element) { _triggerCloseEvent(element) {
var closeEvent = $.Event(Event.CLOSE) let closeEvent = $.Event(Event.CLOSE)
$(element).trigger(closeEvent) $(element).trigger(closeEvent)
return closeEvent return closeEvent
} }
......
...@@ -20,7 +20,6 @@ const Button = (($) => { ...@@ -20,7 +20,6 @@ const Button = (($) => {
const EVENT_KEY = `.${DATA_KEY}` const EVENT_KEY = `.${DATA_KEY}`
const DATA_API_KEY = '.data-api' const DATA_API_KEY = '.data-api'
const JQUERY_NO_CONFLICT = $.fn[NAME] const JQUERY_NO_CONFLICT = $.fn[NAME]
const TRANSITION_DURATION = 150
const ClassName = { const ClassName = {
ACTIVE : 'active', ACTIVE : 'active',
...@@ -67,7 +66,7 @@ const Button = (($) => { ...@@ -67,7 +66,7 @@ const Button = (($) => {
toggle() { toggle() {
let triggerChangeEvent = true let triggerChangeEvent = true
let rootElement = $(this._element).closest( let rootElement = $(this._element).closest(
Selector.DATA_TOGGLE Selector.DATA_TOGGLE
)[0] )[0]
...@@ -137,7 +136,7 @@ const Button = (($) => { ...@@ -137,7 +136,7 @@ const Button = (($) => {
*/ */
$(document) $(document)
.on(Event.CLICK_DATA_API, Selector.DATA_TOGGLE_CARROT, function (event) { .on(Event.CLICK_DATA_API, Selector.DATA_TOGGLE_CARROT, (event) => {
event.preventDefault() event.preventDefault()
let button = event.target let button = event.target
...@@ -148,8 +147,8 @@ const Button = (($) => { ...@@ -148,8 +147,8 @@ const Button = (($) => {
Button._jQueryInterface.call($(button), 'toggle') Button._jQueryInterface.call($(button), 'toggle')
}) })
.on(Event.FOCUS_BLUR_DATA_API, Selector.DATA_TOGGLE_CARROT, function (event) { .on(Event.FOCUS_BLUR_DATA_API, Selector.DATA_TOGGLE_CARROT, (event) => {
var button = $(event.target).closest(Selector.BUTTON)[0] let button = $(event.target).closest(Selector.BUTTON)[0]
$(button).toggleClass(ClassName.FOCUS, /^focus(in)?$/.test(event.type)) $(button).toggleClass(ClassName.FOCUS, /^focus(in)?$/.test(event.type))
}) })
......
...@@ -171,13 +171,13 @@ const Carousel = (($) => { ...@@ -171,13 +171,13 @@ const Carousel = (($) => {
return return
} }
if (activeIndex == index) { if (activeIndex === index) {
this.pause() this.pause()
this.cycle() this.cycle()
return return
} }
var direction = index > activeIndex ? let direction = index > activeIndex ?
Direction.NEXT : Direction.NEXT :
Direction.PREVIOUS Direction.PREVIOUS
...@@ -213,7 +213,7 @@ const Carousel = (($) => { ...@@ -213,7 +213,7 @@ const Carousel = (($) => {
.on(Event.KEYDOWN, $.proxy(this._keydown, this)) .on(Event.KEYDOWN, $.proxy(this._keydown, this))
} }
if (this._config.pause == 'hover' && if (this._config.pause === 'hover' &&
!('ontouchstart' in document.documentElement)) { !('ontouchstart' in document.documentElement)) {
$(this._element) $(this._element)
.on(Event.MOUSEENTER, $.proxy(this.pause, this)) .on(Event.MOUSEENTER, $.proxy(this.pause, this))
...@@ -224,7 +224,9 @@ const Carousel = (($) => { ...@@ -224,7 +224,9 @@ const Carousel = (($) => {
_keydown(event) { _keydown(event) {
event.preventDefault() event.preventDefault()
if (/input|textarea/i.test(event.target.tagName)) return if (/input|textarea/i.test(event.target.tagName)) {
return
}
switch (event.which) { switch (event.which) {
case 37: this.prev(); break case 37: this.prev(); break
...@@ -244,13 +246,13 @@ const Carousel = (($) => { ...@@ -244,13 +246,13 @@ const Carousel = (($) => {
let activeIndex = this._getItemIndex(activeElement) let activeIndex = this._getItemIndex(activeElement)
let lastItemIndex = (this._items.length - 1) let lastItemIndex = (this._items.length - 1)
let isGoingToWrap = (isPrevDirection && activeIndex === 0) || let isGoingToWrap = (isPrevDirection && activeIndex === 0) ||
(isNextDirection && activeIndex == lastItemIndex) (isNextDirection && activeIndex === lastItemIndex)
if (isGoingToWrap && !this._config.wrap) { if (isGoingToWrap && !this._config.wrap) {
return activeElement return activeElement
} }
let delta = direction == Direction.PREVIOUS ? -1 : 1 let delta = direction === Direction.PREVIOUS ? -1 : 1
let itemIndex = (activeIndex + delta) % this._items.length let itemIndex = (activeIndex + delta) % this._items.length
return itemIndex === -1 ? return itemIndex === -1 ?
...@@ -260,7 +262,7 @@ const Carousel = (($) => { ...@@ -260,7 +262,7 @@ const Carousel = (($) => {
_triggerSlideEvent(relatedTarget, directionalClassname) { _triggerSlideEvent(relatedTarget, directionalClassname) {
let slideEvent = $.Event(Event.SLIDE, { let slideEvent = $.Event(Event.SLIDE, {
relatedTarget: relatedTarget, relatedTarget,
direction: directionalClassname direction: directionalClassname
}) })
...@@ -290,9 +292,9 @@ const Carousel = (($) => { ...@@ -290,9 +292,9 @@ const Carousel = (($) => {
let nextElement = element || activeElement && let nextElement = element || activeElement &&
this._getItemByDirection(direction, activeElement) this._getItemByDirection(direction, activeElement)
let isCycling = !!this._interval let isCycling = Boolean(this._interval)
let directionalClassName = direction == Direction.NEXT ? let directionalClassName = direction === Direction.NEXT ?
ClassName.LEFT : ClassName.LEFT :
ClassName.RIGHT ClassName.RIGHT
...@@ -319,7 +321,7 @@ const Carousel = (($) => { ...@@ -319,7 +321,7 @@ const Carousel = (($) => {
this._setActiveIndicatorElement(nextElement) this._setActiveIndicatorElement(nextElement)
var slidEvent = $.Event(Event.SLID, { let slidEvent = $.Event(Event.SLID, {
relatedTarget: nextElement, relatedTarget: nextElement,
direction: directionalClassName direction: directionalClassName
}) })
...@@ -372,7 +374,7 @@ const Carousel = (($) => { ...@@ -372,7 +374,7 @@ const Carousel = (($) => {
static _jQueryInterface(config) { static _jQueryInterface(config) {
return this.each(function () { return this.each(function () {
let data = $(this).data(DATA_KEY) let data = $(this).data(DATA_KEY)
let _config = $.extend({}, Default, $(this).data()) let _config = $.extend({}, Default, $(this).data())
if (typeof config === 'object') { if (typeof config === 'object') {
...@@ -386,7 +388,7 @@ const Carousel = (($) => { ...@@ -386,7 +388,7 @@ const Carousel = (($) => {
$(this).data(DATA_KEY, data) $(this).data(DATA_KEY, data)
} }
if (typeof config == 'number') { if (typeof config === 'number') {
data.to(config) data.to(config)
} else if (action) { } else if (action) {
...@@ -412,9 +414,9 @@ const Carousel = (($) => { ...@@ -412,9 +414,9 @@ const Carousel = (($) => {
return return
} }
let config = $.extend({}, $(target).data(), $(this).data()) let config = $.extend({}, $(target).data(), $(this).data())
let slideIndex = this.getAttribute('data-slide-to') let slideIndex = this.getAttribute('data-slide-to')
if (slideIndex) { if (slideIndex) {
config.interval = false config.interval = false
} }
...@@ -440,7 +442,7 @@ const Carousel = (($) => { ...@@ -440,7 +442,7 @@ const Carousel = (($) => {
$(document) $(document)
.on(Event.CLICK_DATA_API, Selector.DATA_SLIDE, Carousel._dataApiClickHandler) .on(Event.CLICK_DATA_API, Selector.DATA_SLIDE, Carousel._dataApiClickHandler)
$(window).on(Event.LOAD_DATA_API, function () { $(window).on(Event.LOAD_DATA_API, () => {
$(Selector.DATA_RIDE).each(function () { $(Selector.DATA_RIDE).each(function () {
let $carousel = $(this) let $carousel = $(this)
Carousel._jQueryInterface.call($carousel, $carousel.data()) Carousel._jQueryInterface.call($carousel, $carousel.data())
......
...@@ -182,15 +182,14 @@ const Collapse = (($) => { ...@@ -182,15 +182,14 @@ const Collapse = (($) => {
return return
} }
let scrollSize = 'scroll' let capitalizedDimension = dimension[0].toUpperCase() + dimension.slice(1)
+ (dimension[0].toUpperCase() let scrollSize = `scroll${capitalizedDimension}`
+ dimension.slice(1))
$(this._element) $(this._element)
.one(Util.TRANSITION_END, complete) .one(Util.TRANSITION_END, complete)
.emulateTransitionEnd(TRANSITION_DURATION) .emulateTransitionEnd(TRANSITION_DURATION)
this._element.style[dimension] = this._element[scrollSize] + 'px' this._element.style[dimension] = `${this._element[scrollSize]}px`
} }
hide() { hide() {
...@@ -205,11 +204,11 @@ const Collapse = (($) => { ...@@ -205,11 +204,11 @@ const Collapse = (($) => {
return return
} }
let dimension = this._getDimension() let dimension = this._getDimension()
let offsetDimension = dimension === Dimension.WIDTH ? let offsetDimension = dimension === Dimension.WIDTH ?
'offsetWidth' : 'offsetHeight' 'offsetWidth' : 'offsetHeight'
this._element.style[dimension] = this._element[offsetDimension] + 'px' this._element.style[dimension] = `${this._element[offsetDimension]}px`
Util.reflow(this._element) Util.reflow(this._element)
...@@ -239,7 +238,8 @@ const Collapse = (($) => { ...@@ -239,7 +238,8 @@ const Collapse = (($) => {
this._element.style[dimension] = 0 this._element.style[dimension] = 0
if (!Util.supportsTransitionEnd()) { if (!Util.supportsTransitionEnd()) {
return complete() complete()
return
} }
$(this._element) $(this._element)
...@@ -266,7 +266,7 @@ const Collapse = (($) => { ...@@ -266,7 +266,7 @@ const Collapse = (($) => {
_getConfig(config) { _getConfig(config) {
config = $.extend({}, Default, config) config = $.extend({}, Default, config)
config.toggle = !!config.toggle // coerce string values config.toggle = Boolean(config.toggle) // coerce string values
Util.typeCheckConfig(NAME, config, DefaultType) Util.typeCheckConfig(NAME, config, DefaultType)
return config return config
} }
...@@ -351,8 +351,7 @@ const Collapse = (($) => { ...@@ -351,8 +351,7 @@ const Collapse = (($) => {
event.preventDefault() event.preventDefault()
let target = Collapse._getTargetFromElement(this) let target = Collapse._getTargetFromElement(this)
let data = $(target).data(DATA_KEY)
let data = $(target).data(DATA_KEY)
let config = data ? 'toggle' : $(this).data() let config = data ? 'toggle' : $(this).data()
Collapse._jQueryInterface.call($(target), config) Collapse._jQueryInterface.call($(target), config)
......
...@@ -78,7 +78,7 @@ const Dropdown = (($) => { ...@@ -78,7 +78,7 @@ const Dropdown = (($) => {
toggle() { toggle() {
if (this.disabled || $(this).hasClass(ClassName.DISABLED)) { if (this.disabled || $(this).hasClass(ClassName.DISABLED)) {
return return false
} }
let parent = Dropdown._getParentFromElement(this) let parent = Dropdown._getParentFromElement(this)
...@@ -106,7 +106,7 @@ const Dropdown = (($) => { ...@@ -106,7 +106,7 @@ const Dropdown = (($) => {
$(parent).trigger(showEvent) $(parent).trigger(showEvent)
if (showEvent.isDefaultPrevented()) { if (showEvent.isDefaultPrevented()) {
return return false
} }
this.focus() this.focus()
...@@ -239,9 +239,17 @@ const Dropdown = (($) => { ...@@ -239,9 +239,17 @@ const Dropdown = (($) => {
let index = items.indexOf(event.target) let index = items.indexOf(event.target)
if (event.which === 38 && index > 0) index-- // up if (event.which === 38 && index > 0) { // up
if (event.which === 40 && index < items.length - 1) index++ // down index--
if (!~index) index = 0 }
if (event.which === 40 && index < items.length - 1) { // down
index++
}
if (!~index) {
index = 0
}
items[index].focus() items[index].focus()
} }
...@@ -261,9 +269,9 @@ const Dropdown = (($) => { ...@@ -261,9 +269,9 @@ const Dropdown = (($) => {
.on(Event.KEYDOWN_DATA_API, Selector.ROLE_LISTBOX, Dropdown._dataApiKeydownHandler) .on(Event.KEYDOWN_DATA_API, Selector.ROLE_LISTBOX, Dropdown._dataApiKeydownHandler)
.on(Event.CLICK_DATA_API, Dropdown._clearMenus) .on(Event.CLICK_DATA_API, Dropdown._clearMenus)
.on(Event.CLICK_DATA_API, Selector.DATA_TOGGLE, Dropdown.prototype.toggle) .on(Event.CLICK_DATA_API, Selector.DATA_TOGGLE, Dropdown.prototype.toggle)
.on(Event.CLICK_DATA_API, Selector.FORM_CHILD, function (e) { .on(Event.CLICK_DATA_API, Selector.FORM_CHILD, (e) => {
e.stopPropagation() e.stopPropagation()
}) })
/** /**
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment