Skip to content

Commit

Permalink
Merge pull request #326 from midzer/rollupBundle
Browse files Browse the repository at this point in the history
introduce rollup bundler
  • Loading branch information
thednp authored Jan 1, 2020
2 parents af45af4 + e91bfe7 commit 320b553
Show file tree
Hide file tree
Showing 24 changed files with 6,265 additions and 2,067 deletions.
3,915 changes: 1,903 additions & 2,012 deletions dist/bootstrap-native-v4.js

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions dist/bootstrap-native-v4.min.js

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions lib/src/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"presets": [
[
"@babel/preset-env",
{
"modules": false
}
]
]
}
4 changes: 2 additions & 2 deletions lib/src/alert-native.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
-------------------------------------------*/

// IMPORTS
import { supports } from './util/callbacks.js';
import { supports } from './util/globals.js';
import { hasClass, removeClass } from './util/class.js';
import { bootstrapCustomEvent, on, off } from './util/event.js';
import { bootstrapCustomEvent, dispatchCustomEvent, on, off } from './util/event.js';
import { queryElement } from './util/selector.js';
import { emulateTransitionEnd } from './util/transition.js';

Expand Down
4 changes: 2 additions & 2 deletions lib/src/button-native.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
---------------------------------------------*/

// IMPORTS
import { supports } from './util/callbacks.js';
import { supports } from './util/globals.js';
import { hasClass, addClass, removeClass } from './util/class.js';
import { bootstrapCustomEvent, on, off } from './util/event.js';
import { bootstrapCustomEvent, dispatchCustomEvent, on, off } from './util/event.js';
import { queryElement, getElementsByClassName } from './util/selector.js';

// BUTTON DEFINITION
Expand Down
4 changes: 2 additions & 2 deletions lib/src/carousel-native.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
----------------------------------------------*/

// IMPORTS
import { supports } from './util/callbacks.js';
import { supports } from './util/globals.js';
import { hasClass, addClass, removeClass } from './util/class.js';
import { bootstrapCustomEvent, on, off, touchEvents, mouseHover, passiveHandler } from './util/event.js';
import { bootstrapCustomEvent, dispatchCustomEvent, on, off, touchEvents, mouseHover, passiveHandler } from './util/event.js';
import { queryElement, getElementsByClassName } from './util/selector.js';
import { supportTransitions, emulateTransitionEnd } from './util/transition.js';

Expand Down
4 changes: 2 additions & 2 deletions lib/src/collapse-native.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
-----------------------------------------------*/

// IMPORTS
import { supports } from './util/callbacks.js';
import { supports } from './util/globals.js';
import { hasClass, addClass, removeClass } from './util/class.js';
import { bootstrapCustomEvent, on, off } from './util/event.js';
import { bootstrapCustomEvent, dispatchCustomEvent, on, off } from './util/event.js';
import { queryElement } from './util/selector.js';
import { emulateTransitionEnd } from './util/transition.js';

Expand Down
8 changes: 4 additions & 4 deletions lib/src/dropdown-native.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
----------------------------------------------*/

// IMPORTS
import { supports } from './util/callbacks.js';
import { supports } from './util/globals.js';
import { setFocus } from './util/misc.js';
import { hasClass, addClass, removeClass } from './util/class.js';
import { bootstrapCustomEvent, on, off } from './util/event.js';
import { bootstrapCustomEvent, dispatchCustomEvent, on, off } from './util/event.js';
import { queryElement } from './util/selector.js';


Expand All @@ -30,7 +30,7 @@ export default class Dropdown {
relatedTarget = null;

// constants
const self = this;
const self = this,

// targets
parent = element.parentNode,
Expand Down Expand Up @@ -153,7 +153,7 @@ export default class Dropdown {

// init
if ( !element.Dropdown ) { // prevent adding event handlers twice
!(tabindex in menu) && menu.setAttribute(tabindex, '0'); // Fix onblur on Chrome | Safari
!('tabindex' in menu) && menu.setAttribute('tabindex', '0'); // Fix onblur on Chrome | Safari
on(element, 'click', clickHandler);
}

Expand Down
3 changes: 2 additions & 1 deletion lib/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import ScrollSpy from './scrollspy-native.js'
import Tab from './tab-native.js'
import Toast from './toast-native.js'
import Tooltip from './tooltip-native.js'
import './util/init.js'

export {
export default {
Alert,
Button,
Carousel,
Expand Down
4 changes: 2 additions & 2 deletions lib/src/modal-native.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
-------------------------------------------*/

// IMPORTS
import { supports } from './util/callbacks.js';
import { supports } from './util/globals.js';
import { setFocus } from './util/misc.js';
import { hasClass, addClass, removeClass } from './util/class.js';
import { bootstrapCustomEvent, on, off, passiveHandler } from './util/event.js';
import { bootstrapCustomEvent, dispatchCustomEvent, on, off, passiveHandler } from './util/event.js';
import { queryElement, getElementsByClassName } from './util/selector.js';
import { emulateTransitionEnd, getTransitionDurationFromElement } from './util/transition.js';

Expand Down
10 changes: 5 additions & 5 deletions lib/src/popover-native.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
----------------------------------------------*/

// IMPORTS
import { supports } from './util/callbacks.js';
import { supports } from './util/globals.js';
import { styleTip } from './util/misc.js';
import { hasClass, addClass, removeClass } from './util/class.js';
import { bootstrapCustomEvent, on, off, mouseHover, passiveHandler } from './util/event.js';
import { bootstrapCustomEvent, dispatchCustomEvent, on, off, mouseHover, passiveHandler } from './util/event.js';
import { queryElement } from './util/selector.js';
import { emulateTransitionEnd } from './util/transition.js';

Expand All @@ -27,14 +27,14 @@ export default class Popover {
timer = 0,
// title and content
titleString,
contentString,
contentString;

// bind, popover and timer
const
self = this,

// DATA API
const triggerData = element.getAttribute('data-trigger'), // click / hover / focus
triggerData = element.getAttribute('data-trigger'), // click / hover / focus
animationData = element.getAttribute('data-animation'), // true / false

placementData = element.getAttribute('data-placement'),
Expand Down Expand Up @@ -82,7 +82,7 @@ export default class Popover {
placementClass = `bs-popover-${self.options.placement}`,

// handlers
const dismissibleHandler = e => {
dismissibleHandler = e => {
if (popover !== null && e.target === queryElement('.close',popover)) {
self.hide();
}
Expand Down
4 changes: 2 additions & 2 deletions lib/src/scrollspy-native.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
-----------------------------------------------*/

// IMPORTS
import { supports } from './util/callbacks.js';
import { supports } from './util/globals.js';
import { hasClass, addClass, removeClass } from './util/class.js';
import { bootstrapCustomEvent, on, off, passiveHandler } from './util/event.js';
import { bootstrapCustomEvent, dispatchCustomEvent, on, off, passiveHandler } from './util/event.js';
import { queryElement } from './util/selector.js';
import { getScroll } from './util/misc.js';

Expand Down
4 changes: 2 additions & 2 deletions lib/src/tab-native.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
-----------------------------------------*/

// IMPORTS
import { supports } from './util/callbacks.js';
import { supports } from './util/globals.js';
import { hasClass, addClass, removeClass } from './util/class.js';
import { bootstrapCustomEvent, on, off } from './util/event.js';
import { bootstrapCustomEvent, dispatchCustomEvent, on, off } from './util/event.js';
import { queryElement, getElementsByClassName } from './util/selector.js';
import { supportTransitions, emulateTransitionEnd } from './util/transition.js';

Expand Down
4 changes: 2 additions & 2 deletions lib/src/toast-native.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
---------------------------------------------*/

// IMPORTS
import { supports } from './util/callbacks.js';
import { supports } from './util/globals.js';
import { hasClass, addClass, removeClass } from './util/class.js';
import { bootstrapCustomEvent, on, off } from './util/event.js';
import { bootstrapCustomEvent, dispatchCustomEvent, on, off } from './util/event.js';
import { queryElement } from './util/selector.js';
import { emulateTransitionEnd } from './util/transition.js';

Expand Down
4 changes: 2 additions & 2 deletions lib/src/tooltip-native.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
---------------------------------------------*/

// IMPORTS
import { supports } from './util/callbacks.js';
import { supports } from './util/globals.js';
import { styleTip } from './util/misc.js';
import { hasClass, addClass, removeClass } from './util/class.js';
import { bootstrapCustomEvent, on, off, mouseHover, passiveHandler } from './util/event.js';
import { bootstrapCustomEvent, dispatchCustomEvent, on, off, mouseHover, passiveHandler } from './util/event.js';
import { queryElement } from './util/selector.js';
import { emulateTransitionEnd } from './util/transition.js';

Expand Down
16 changes: 3 additions & 13 deletions lib/src/util/callbacks.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
import on from './event.js'

// globals
const globalObject = typeof global !== 'undefined' ? global : this||window;
const BSN = globalObject.BSN = {};
export const supports = globalObject.BSN.supports = [];

import { supports } from './globals.js'

/* Native JavaScript for Bootstrap | Initialize Data API
--------------------------------------------------------*/
export const initCallback = BSN.initCallback = function(lookUp){
export const initCallback = function(lookUp){
lookUp = lookUp || document;
const initializeDataAPI = function( constructor, collection ){
for (let i=0, cl=collection.length; i<cl; i++) {
Expand All @@ -20,13 +14,9 @@ export const initCallback = BSN.initCallback = function(lookUp){
}
};

// bulk initialize all components
document.body ? initCallback() : on( document, 'DOMContentLoaded', initCallback );


/* Native JavaScript for Bootstrap | Remove Data API
--------------------------------------------------------*/
export const removeDataAPI = BSN.removeDataAPI = function(lookUp){
export const removeDataAPI = function(lookUp){
lookUp = lookUp || document;
const removeElementDataAPI = function( constructor, collection ){
for (let i=0, cl=collection.length; i<cl; i++) {
Expand Down
4 changes: 4 additions & 0 deletions lib/src/util/globals.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// globals
//const globalObject = typeof global !== 'undefined' ? global : window;
//const BSN = globalObject.BSN = {};
export const supports = /*globalObject.BSN.supports =*/ [];
5 changes: 5 additions & 0 deletions lib/src/util/init.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { initCallback } from './callbacks.js'
import { on } from './event.js'

// bulk initialize all components
document.body ? initCallback() : on( document, 'DOMContentLoaded', initCallback );
14 changes: 10 additions & 4 deletions lib/src/util/misc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import hasClass from './class.js';
import queryElement from './selector.js';
import { hasClass } from './class.js';
import { queryElement } from './selector.js';

export function setFocus (element){
element.focus ? element.focus() : element.setActive();
Expand All @@ -22,10 +22,9 @@ export function styleTip (link,element,position,parent) { // both popovers and t
scroll = parent === document.body ? getScroll() : { x: parent.offsetLeft + parent.scrollLeft, y: parent.offsetTop + parent.scrollTop },
linkDimensions = { w: rect.right - rect.left, h: rect.bottom - rect.top },
isPopover = hasClass(element,'popover'),
topPosition, leftPosition,


arrow = queryElement('.arrow',element),
arrowTop, arrowLeft, arrowWidth, arrowHeight,

halfTopExceed = rect.top + linkDimensions.h/2 - elementDimensions.h/2 < 0,
halfLeftExceed = rect.left + linkDimensions.w/2 - elementDimensions.w/2 < 0,
Expand All @@ -43,6 +42,13 @@ export function styleTip (link,element,position,parent) { // both popovers and t
position = position === 'left' && leftExceed ? 'right' : position;
position = position === 'right' && rightExceed ? 'left' : position;

let topPosition,
leftPosition,
arrowTop,
arrowLeft,
arrowWidth,
arrowHeight;

// update tooltip/popover class
element.className.indexOf(position) === -1 && (element.className = element.className.replace(tipPositions,position));

Expand Down
2 changes: 1 addition & 1 deletion lib/src/util/selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export function getElementsByClassName (element,classNAME) { // returns Array
return [].slice.call(element.getElementsByClassName( classNAME ));
}

export default function queryElement (selector, parent) {
export function queryElement (selector, parent) {
var lookUp = parent ? parent : document;
return selector instanceof Element ? selector : lookUp.querySelector(selector);
}
2 changes: 1 addition & 1 deletion lib/src/util/transition.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { one } from 'event.js';
import { one } from './event.js';

export const supportTransitions = 'webkitTransition' in document.body.style || 'transition' in document.body.style;
export const transitionEndEvent = 'webkitTransition' in document.body.style ? 'webkitTransitionEnd' : 'transitionend';
Expand Down
Loading

0 comments on commit 320b553

Please sign in to comment.