js tests passing + eslint

This commit is contained in:
Jacob Thornton 2015-08-18 19:22:46 -07:00
parent f1827e5f9c
commit 18ff57a183
28 changed files with 485 additions and 217 deletions

View File

@ -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) {
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']);

View File

@ -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 ($) {
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 ($) {
}, },
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 ($) {
}, { }, {
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 ($) {
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 ($) {
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 ($) {
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 ($) {
$(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 ($) {
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 ($) {
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 ($) {
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 ($) {
$(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 ($) {
} }
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 ($) {
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 ($) {
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 ($) {
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 ($) {
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 ($) {
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 ($) {
$(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 ($) {
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 ($) {
$(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 ($) {
} }
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 ($) {
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 ($) {
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 ($) {
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 ($) {
}, { }, {
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 ($) {
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 ($) {
$(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 ($) {
} }
}; };
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 ($) {
}, { }, {
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 ($) {
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 ($) {
} }
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 ($) {
} }
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 ($) {
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 ($) {
}, { }, {
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

File diff suppressed because one or more lines are too long

View File

@ -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 @@
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;
} }

View File

@ -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',

View File

@ -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 @@
$(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 @@
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 @@
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 @@
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 @@
$(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 @@
} }
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;
} }

View File

@ -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 @@
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 @@
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 @@
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();

View File

@ -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 @@
$(parent).trigger(showEvent); $(parent).trigger(showEvent);
if (showEvent.isDefaultPrevented()) { if (showEvent.isDefaultPrevented()) {
return; return false;
} }
this.focus(); this.focus();
@ -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();
} }

12
dist/js/umd/modal.js vendored
View File

@ -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 @@
} }
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 @@
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');
} }
} }
}, { }, {

View File

@ -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

4
dist/js/umd/tab.js vendored
View File

@ -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 @@
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);

View File

@ -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 @@
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 @@
$(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 @@
} }
}; };
_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 @@
}, { }, {
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 @@
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 @@
} }
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 @@
} }
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 @@
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;
} }
} }
} }

32
dist/js/umd/util.js vendored
View File

@ -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 @@
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 @@
}, },
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();

177
js/.eslintrc Normal file
View File

@ -0,0 +1,177 @@
{
"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
}
}

3
js/dist/util.js vendored
View File

@ -1,3 +1,4 @@
/** /**
* -------------------------------------------------------------------------- * --------------------------------------------------------------------------
* Bootstrap (v4.0.0): util.js * Bootstrap (v4.0.0): util.js
@ -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;
}, },

View File

@ -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 = (($) => {
} }
_triggerCloseEvent(element) { _triggerCloseEvent(element) {
var closeEvent = $.Event(Event.CLOSE) let closeEvent = $.Event(Event.CLOSE)
$(element).trigger(closeEvent) $(element).trigger(closeEvent)
return closeEvent return closeEvent
} }

View File

@ -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 = (($) => {
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 = (($) => {
*/ */
$(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 = (($) => {
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))
}) })

View File

@ -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 = (($) => {
.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 = (($) => {
_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 = (($) => {
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 = (($) => {
_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 = (($) => {
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 = (($) => {
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 = (($) => {
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 = (($) => {
$(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 = (($) => {
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 = (($) => {
$(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())

View File

@ -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 = (($) => {
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 = (($) => {
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 = (($) => {
_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 = (($) => {
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)

View File

@ -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 = (($) => {
$(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 = (($) => {
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 = (($) => {
.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()
}) })
/** /**

View File

@ -110,7 +110,7 @@ const Modal = (($) => {
show(relatedTarget) { show(relatedTarget) {
let showEvent = $.Event(Event.SHOW, { let showEvent = $.Event(Event.SHOW, {
relatedTarget: relatedTarget relatedTarget
}) })
$(this._element).trigger(showEvent) $(this._element).trigger(showEvent)
@ -231,14 +231,18 @@ const Modal = (($) => {
$(this._element).addClass(ClassName.IN) $(this._element).addClass(ClassName.IN)
if (this._config.focus) this._enforceFocus() if (this._config.focus) {
this._enforceFocus()
}
let shownEvent = $.Event(Event.SHOWN, { let shownEvent = $.Event(Event.SHOWN, {
relatedTarget: relatedTarget relatedTarget
}) })
let transitionComplete = () => { let transitionComplete = () => {
if (this._config.focus) this._element.focus() if (this._config.focus) {
this._element.focus()
}
$(this._element).trigger(shownEvent) $(this._element).trigger(shownEvent)
} }
@ -389,11 +393,11 @@ const Modal = (($) => {
this._element.scrollHeight > document.documentElement.clientHeight this._element.scrollHeight > document.documentElement.clientHeight
if (!this._isBodyOverflowing && isModalOverflowing) { if (!this._isBodyOverflowing && isModalOverflowing) {
this._element.style.paddingLeft = this._scrollbarWidth + 'px' this._element.style.paddingLeft = `${this._scrollbarWidth}px`
} }
if (this._isBodyOverflowing && !isModalOverflowing) { if (this._isBodyOverflowing && !isModalOverflowing) {
this._element.style.paddingRight = this._scrollbarWidth + 'px' this._element.style.paddingRight = `${this._scrollbarWidth}px~`
} }
} }
@ -423,7 +427,7 @@ const Modal = (($) => {
if (this._isBodyOverflowing) { if (this._isBodyOverflowing) {
document.body.style.paddingRight = document.body.style.paddingRight =
bodyPadding + this._scrollbarWidth + 'px' bodyPadding + `${this._scrollbarWidth}px`
} }
} }

View File

@ -141,7 +141,7 @@ const Popover = (($) => {
_getContent() { _getContent() {
return this.element.getAttribute('data-content') return this.element.getAttribute('data-content')
|| (typeof this.config.content == 'function' ? || (typeof this.config.content === 'function' ?
this.config.content.call(this.element) : this.config.content.call(this.element) :
this.config.content) this.config.content)
} }

View File

@ -293,7 +293,7 @@ const ScrollSpy = (($) => {
* ------------------------------------------------------------------------ * ------------------------------------------------------------------------
*/ */
$(window).on(Event.LOAD_DATA_API, function () { $(window).on(Event.LOAD_DATA_API, () => {
let scrollSpys = $.makeArray($(Selector.DATA_SPY)) let scrollSpys = $.makeArray($(Selector.DATA_SPY))
for (let i = scrollSpys.length; i--;) { for (let i = scrollSpys.length; i--;) {

View File

@ -77,7 +77,7 @@ const Tab = (($) => {
show() { show() {
if (this._element.parentNode && if (this._element.parentNode &&
(this._element.parentNode.nodeType == Node.ELEMENT_NODE) && (this._element.parentNode.nodeType === Node.ELEMENT_NODE) &&
($(this._element).parent().hasClass(ClassName.ACTIVE))) { ($(this._element).parent().hasClass(ClassName.ACTIVE))) {
return return
} }
@ -157,7 +157,7 @@ const Tab = (($) => {
let isTransitioning = callback let isTransitioning = callback
&& Util.supportsTransitionEnd() && Util.supportsTransitionEnd()
&& ((active && $(active).hasClass(ClassName.FADE)) && ((active && $(active).hasClass(ClassName.FADE))
|| !!$(container).find(Selector.FADE_CHILD)[0]) || Boolean($(container).find(Selector.FADE_CHILD)[0]))
let complete = $.proxy( let complete = $.proxy(
this._transitionComplete, this._transitionComplete,

View File

@ -174,11 +174,9 @@ const Tooltip = (($) => {
} }
toggle(event) { toggle(event) {
let context = this
let dataKey = this.constructor.DATA_KEY
if (event) { if (event) {
context = $(event.currentTarget).data(dataKey) let dataKey = this.constructor.DATA_KEY
let context = $(event.currentTarget).data(dataKey)
if (!context) { if (!context) {
context = new this.constructor( context = new this.constructor(
@ -197,9 +195,13 @@ const Tooltip = (($) => {
} }
} else { } else {
$(context.getTipElement()).hasClass(ClassName.IN) ?
context._leave(null, context) : if ($(this.getTipElement()).hasClass(ClassName.IN)) {
context._enter(null, context) this._leave(null, this)
return
}
this._enter(null, this)
} }
} }
@ -267,9 +269,9 @@ const Tooltip = (($) => {
$(this.element).trigger(this.constructor.Event.INSERTED) $(this.element).trigger(this.constructor.Event.INSERTED)
this._tether = new Tether({ this._tether = new Tether({
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,
@ -292,11 +294,14 @@ const Tooltip = (($) => {
} }
} }
Util.supportsTransitionEnd() && $(this.tip).hasClass(ClassName.FADE) ? if (Util.supportsTransitionEnd() && $(this.tip).hasClass(ClassName.FADE)) {
$(this.tip) $(this.tip)
.one(Util.TRANSITION_END, complete) .one(Util.TRANSITION_END, complete)
.emulateTransitionEnd(Tooltip._TRANSITION_DURATION) : .emulateTransitionEnd(Tooltip._TRANSITION_DURATION)
complete() return
}
complete()
} }
} }
@ -343,7 +348,7 @@ const Tooltip = (($) => {
// protected // protected
isWithContent() { isWithContent() {
return !!this.getTitle() return Boolean(this.getTitle())
} }
getTipElement() { getTipElement() {
@ -407,10 +412,10 @@ const Tooltip = (($) => {
) )
} else if (trigger !== Trigger.MANUAL) { } else if (trigger !== Trigger.MANUAL) {
let eventIn = trigger == Trigger.HOVER ? let eventIn = trigger === Trigger.HOVER ?
this.constructor.Event.MOUSEENTER : this.constructor.Event.MOUSEENTER :
this.constructor.Event.FOCUSIN this.constructor.Event.FOCUSIN
let eventOut = trigger == Trigger.HOVER ? let eventOut = trigger === Trigger.HOVER ?
this.constructor.Event.MOUSELEAVE : this.constructor.Event.MOUSELEAVE :
this.constructor.Event.FOCUSOUT this.constructor.Event.FOCUSOUT
@ -471,7 +476,7 @@ const Tooltip = (($) => {
if (event) { if (event) {
context._activeTrigger[ context._activeTrigger[
event.type == 'focusin' ? Trigger.FOCUS : Trigger.HOVER event.type === 'focusin' ? Trigger.FOCUS : Trigger.HOVER
] = true ] = true
} }
@ -512,7 +517,7 @@ const Tooltip = (($) => {
if (event) { if (event) {
context._activeTrigger[ context._activeTrigger[
event.type == 'focusout' ? Trigger.FOCUS : Trigger.HOVER event.type === 'focusout' ? Trigger.FOCUS : Trigger.HOVER
] = false ] = false
} }
@ -575,9 +580,8 @@ const Tooltip = (($) => {
if (this.config) { if (this.config) {
for (let key in this.config) { for (let key in this.config) {
let 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
} }
} }
} }

View File

@ -29,14 +29,14 @@ const Util = (($) => {
} }
function isElement(obj) { function isElement(obj) {
return (obj[0] || obj).nodeType; return (obj[0] || obj).nodeType
} }
function getSpecialTransitionEndEvent() { function getSpecialTransitionEndEvent() {
return { return {
bindType: transition.end, bindType: transition.end,
delegateType: transition.end, delegateType: transition.end,
handle: function (event) { handle(event) {
if ($(event.target).is(this)) { if ($(event.target).is(this)) {
return event.handleObj.handler.apply(this, arguments) return event.handleObj.handler.apply(this, arguments)
} }
@ -51,7 +51,7 @@ const Util = (($) => {
let el = document.createElement('bootstrap') let el = document.createElement('bootstrap')
for (var name in TransitionEndEvent) { for (let name in TransitionEndEvent) {
if (el.style[name] !== undefined) { if (el.style[name] !== undefined) {
return { end: TransitionEndEvent[name] } return { end: TransitionEndEvent[name] }
} }
@ -63,7 +63,7 @@ const Util = (($) => {
function transitionEndEmulator(duration) { function transitionEndEmulator(duration) {
let called = false let called = false
$(this).one(Util.TRANSITION_END, function () { $(this).one(Util.TRANSITION_END, () => {
called = true called = true
}) })
@ -98,8 +98,9 @@ const Util = (($) => {
TRANSITION_END: 'bsTransitionEnd', TRANSITION_END: 'bsTransitionEnd',
getUID(prefix) { getUID(prefix) {
do prefix += ~~(Math.random() * 1000000) do {
while (document.getElementById(prefix)) prefix += ~~(Math.random() * 1000000)
} while (document.getElementById(prefix))
return prefix return prefix
}, },
@ -123,28 +124,31 @@ const Util = (($) => {
}, },
supportsTransitionEnd() { supportsTransitionEnd() {
return !!transition return Boolean(transition)
}, },
typeCheckConfig(componentName, config, configTypes) { typeCheckConfig(componentName, config, configTypes) {
for (let property in configTypes) { for (let property in configTypes) {
let expectedTypes = configTypes[property] if (configTypes.hasOwnProperty(property)) {
let value = config[property] let expectedTypes = configTypes[property]
let valueType let value = config[property]
let valueType
if (value && isElement(value)) valueType = 'element' if (value && isElement(value)) {
else valueType = toType(value) valueType = 'element'
} else {
valueType = toType(value)
}
if (!new RegExp(expectedTypes).test(valueType)) { if (!new RegExp(expectedTypes).test(valueType)) {
throw new Error( throw new Error(
`${componentName.toUpperCase()}: ` + `${componentName.toUpperCase()}: ` +
`Option "${property}" provided type "${valueType}" ` + `Option "${property}" provided type "${valueType}" ` +
`but expected type "${expectedTypes}".`) `but expected type "${expectedTypes}".`)
}
} }
} }
} }
} }
setTransitionEndSupport() setTransitionEndSupport()

View File

@ -76,29 +76,26 @@
// shoutout mdn: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind#Polyfill // shoutout mdn: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind#Polyfill
if (!Function.prototype.bind) { if (!Function.prototype.bind) {
Function.prototype.bind = function(oThis) { Function.prototype.bind = function (oThis) {
if (typeof this !== 'function') { if (typeof this !== 'function') {
// closest thing possible to the ECMAScript 5 // closest thing possible to the ECMAScript 5
// internal IsCallable function // internal IsCallable function
throw new TypeError('Function.prototype.bind - what is trying to be bound is not callable'); throw new TypeError('Function.prototype.bind - what is trying to be bound is not callable');
} }
var aArgs = Array.prototype.slice.call(arguments, 1), var aArgs = Array.prototype.slice.call(arguments, 1)
fToBind = this, var fToBind = this
fNOP = function() {}, var FNOP = function () {}
fBound = function() { var fBound = function () {
return fToBind.apply(this instanceof fNOP return fToBind.apply(this instanceof FNOP ? this : oThis, aArgs.concat(Array.prototype.slice.call(arguments)))
? this }
: oThis,
aArgs.concat(Array.prototype.slice.call(arguments)));
};
if (this.prototype) { if (this.prototype) {
// native functions don't have a prototype // native functions don't have a prototype
fNOP.prototype = this.prototype; FNOP.prototype = this.prototype
} }
fBound.prototype = new fNOP(); fBound.prototype = new FNOP()
return fBound; return fBound
}; }
} }

View File

@ -28,6 +28,7 @@
}, },
"license": "MIT", "license": "MIT",
"devDependencies": { "devDependencies": {
"babel-eslint": "^4.0.10",
"btoa": "~1.1.2", "btoa": "~1.1.2",
"glob": "~5.0.3", "glob": "~5.0.3",
"grunt": "~0.4.5", "grunt": "~0.4.5",
@ -48,6 +49,7 @@
"grunt-contrib-uglify": "~0.8.0", "grunt-contrib-uglify": "~0.8.0",
"grunt-contrib-watch": "~0.6.1", "grunt-contrib-watch": "~0.6.1",
"grunt-csscomb": "~3.0.0", "grunt-csscomb": "~3.0.0",
"grunt-eslint": "^17.1.0",
"grunt-exec": "~0.4.6", "grunt-exec": "~0.4.6",
"grunt-html": "~4.0.1", "grunt-html": "~4.0.1",
"grunt-jekyll": "~0.4.2", "grunt-jekyll": "~0.4.2",