-
-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* changed all util and imports structure for more accurate bundles * addressing #381, added more build scripts, now `dist/components/` folder holds UMD and ESM modules for all components, @lpar can have a look? * removed dependency on `shorter-js` for events handling, class manipulation, and more, see commit file changes
- Loading branch information
Showing
54 changed files
with
5,367 additions
and
1,126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/*! | ||
* Native JavaScript for Bootstrap v3.0.5 (https://thednp.github.io/bootstrap.native/) | ||
* Copyright 2015-2020 © dnp_theme | ||
* Licensed under MIT (https://github.com/thednp/bootstrap.native/blob/master/LICENSE) | ||
*/ | ||
var transitionEndEvent = 'webkitTransition' in document.body.style ? 'webkitTransitionEnd' : 'transitionend'; | ||
|
||
var supportTransition = 'webkitTransition' in document.body.style || 'transition' in document.body.style; | ||
|
||
var transitionDuration = 'webkitTransition' in document.body.style ? 'webkitTransitionDuration' : 'transitionDuration'; | ||
|
||
function getElementTransitionDuration(element) { | ||
var duration = supportTransition ? parseFloat(getComputedStyle(element)[transitionDuration]) : 0; | ||
duration = typeof duration === 'number' && !isNaN(duration) ? duration * 1000 : 0; | ||
return duration; | ||
} | ||
|
||
function emulateTransitionEnd(element,handler){ | ||
var called = 0, duration = getElementTransitionDuration(element); | ||
duration ? element.addEventListener( transitionEndEvent, function transitionEndWrapper(e){ | ||
!called && handler(e), called = 1; | ||
element.removeEventListener( transitionEndEvent, transitionEndWrapper); | ||
}) | ||
: setTimeout(function() { !called && handler(), called = 1; }, 17); | ||
} | ||
|
||
function queryElement(selector, parent) { | ||
var lookUp = parent && parent instanceof Element ? parent : document; | ||
return selector instanceof Element ? selector : lookUp.querySelector(selector); | ||
} | ||
|
||
function bootstrapCustomEvent(eventName, componentName, related) { | ||
var OriginalCustomEvent = new CustomEvent( eventName + '.bs.' + componentName, {cancelable: true}); | ||
OriginalCustomEvent.relatedTarget = related; | ||
return OriginalCustomEvent; | ||
} | ||
|
||
function dispatchCustomEvent(customEvent){ | ||
this && this.dispatchEvent(customEvent); | ||
} | ||
|
||
function Alert(element) { | ||
var self = this, | ||
alert, | ||
closeCustomEvent = bootstrapCustomEvent('close','alert'), | ||
closedCustomEvent = bootstrapCustomEvent('closed','alert'); | ||
function triggerHandler() { | ||
alert.classList.contains('fade') ? emulateTransitionEnd(alert,transitionEndHandler) : transitionEndHandler(); | ||
} | ||
function toggleEvents(action){ | ||
action = action ? 'addEventListener' : 'removeEventListener'; | ||
element[action]('click',clickHandler,false); | ||
} | ||
function clickHandler(e) { | ||
alert = e && e.target.closest(".alert"); | ||
element = queryElement('[data-dismiss="alert"]',alert); | ||
element && alert && (element === e.target || element.contains(e.target)) && self.close(); | ||
} | ||
function transitionEndHandler() { | ||
toggleEvents(); | ||
alert.parentNode.removeChild(alert); | ||
dispatchCustomEvent.call(alert,closedCustomEvent); | ||
} | ||
self.close = function () { | ||
if ( alert && element && alert.classList.contains('show') ) { | ||
dispatchCustomEvent.call(alert,closeCustomEvent); | ||
if ( closeCustomEvent.defaultPrevented ) { return; } | ||
self.dispose(); | ||
alert.classList.remove('show'); | ||
triggerHandler(); | ||
} | ||
}; | ||
self.dispose = function () { | ||
toggleEvents(); | ||
delete element.Alert; | ||
}; | ||
element = queryElement(element); | ||
alert = element.closest('.alert'); | ||
element.Alert && element.Alert.dispose(); | ||
if ( !element.Alert ) { | ||
toggleEvents(1); | ||
} | ||
self.element = element; | ||
element.Alert = self; | ||
} | ||
|
||
export default Alert; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/*! | ||
* Native JavaScript for Bootstrap v3.0.5 (https://thednp.github.io/bootstrap.native/) | ||
* Copyright 2015-2020 © dnp_theme | ||
* Licensed under MIT (https://github.com/thednp/bootstrap.native/blob/master/LICENSE) | ||
*/ | ||
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : | ||
typeof define === 'function' && define.amd ? define(factory) : | ||
(global = global || self, global.BSN = factory()); | ||
}(this, (function () { 'use strict'; | ||
|
||
var transitionEndEvent = 'webkitTransition' in document.body.style ? 'webkitTransitionEnd' : 'transitionend'; | ||
|
||
var supportTransition = 'webkitTransition' in document.body.style || 'transition' in document.body.style; | ||
|
||
var transitionDuration = 'webkitTransition' in document.body.style ? 'webkitTransitionDuration' : 'transitionDuration'; | ||
|
||
function getElementTransitionDuration(element) { | ||
var duration = supportTransition ? parseFloat(getComputedStyle(element)[transitionDuration]) : 0; | ||
duration = typeof duration === 'number' && !isNaN(duration) ? duration * 1000 : 0; | ||
return duration; | ||
} | ||
|
||
function emulateTransitionEnd(element,handler){ | ||
var called = 0, duration = getElementTransitionDuration(element); | ||
duration ? element.addEventListener( transitionEndEvent, function transitionEndWrapper(e){ | ||
!called && handler(e), called = 1; | ||
element.removeEventListener( transitionEndEvent, transitionEndWrapper); | ||
}) | ||
: setTimeout(function() { !called && handler(), called = 1; }, 17); | ||
} | ||
|
||
function queryElement(selector, parent) { | ||
var lookUp = parent && parent instanceof Element ? parent : document; | ||
return selector instanceof Element ? selector : lookUp.querySelector(selector); | ||
} | ||
|
||
function bootstrapCustomEvent(eventName, componentName, related) { | ||
var OriginalCustomEvent = new CustomEvent( eventName + '.bs.' + componentName, {cancelable: true}); | ||
OriginalCustomEvent.relatedTarget = related; | ||
return OriginalCustomEvent; | ||
} | ||
|
||
function dispatchCustomEvent(customEvent){ | ||
this && this.dispatchEvent(customEvent); | ||
} | ||
|
||
function Alert(element) { | ||
var self = this, | ||
alert, | ||
closeCustomEvent = bootstrapCustomEvent('close','alert'), | ||
closedCustomEvent = bootstrapCustomEvent('closed','alert'); | ||
function triggerHandler() { | ||
alert.classList.contains('fade') ? emulateTransitionEnd(alert,transitionEndHandler) : transitionEndHandler(); | ||
} | ||
function toggleEvents(action){ | ||
action = action ? 'addEventListener' : 'removeEventListener'; | ||
element[action]('click',clickHandler,false); | ||
} | ||
function clickHandler(e) { | ||
alert = e && e.target.closest(".alert"); | ||
element = queryElement('[data-dismiss="alert"]',alert); | ||
element && alert && (element === e.target || element.contains(e.target)) && self.close(); | ||
} | ||
function transitionEndHandler() { | ||
toggleEvents(); | ||
alert.parentNode.removeChild(alert); | ||
dispatchCustomEvent.call(alert,closedCustomEvent); | ||
} | ||
self.close = function () { | ||
if ( alert && element && alert.classList.contains('show') ) { | ||
dispatchCustomEvent.call(alert,closeCustomEvent); | ||
if ( closeCustomEvent.defaultPrevented ) { return; } | ||
self.dispose(); | ||
alert.classList.remove('show'); | ||
triggerHandler(); | ||
} | ||
}; | ||
self.dispose = function () { | ||
toggleEvents(); | ||
delete element.Alert; | ||
}; | ||
element = queryElement(element); | ||
alert = element.closest('.alert'); | ||
element.Alert && element.Alert.dispose(); | ||
if ( !element.Alert ) { | ||
toggleEvents(1); | ||
} | ||
self.element = element; | ||
element.Alert = self; | ||
} | ||
|
||
return Alert; | ||
|
||
}))); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/*! | ||
* Native JavaScript for Bootstrap v3.0.5 (https://thednp.github.io/bootstrap.native/) | ||
* Copyright 2015-2020 © dnp_theme | ||
* Licensed under MIT (https://github.com/thednp/bootstrap.native/blob/master/LICENSE) | ||
*/ | ||
function queryElement(selector, parent) { | ||
var lookUp = parent && parent instanceof Element ? parent : document; | ||
return selector instanceof Element ? selector : lookUp.querySelector(selector); | ||
} | ||
|
||
function bootstrapCustomEvent(eventName, componentName, related) { | ||
var OriginalCustomEvent = new CustomEvent( eventName + '.bs.' + componentName, {cancelable: true}); | ||
OriginalCustomEvent.relatedTarget = related; | ||
return OriginalCustomEvent; | ||
} | ||
|
||
function dispatchCustomEvent(customEvent){ | ||
this && this.dispatchEvent(customEvent); | ||
} | ||
|
||
function Button(element) { | ||
var self = this, labels, | ||
changeCustomEvent = bootstrapCustomEvent('change', 'button'); | ||
function toggle(e) { | ||
var input, | ||
label = e.target.tagName === 'LABEL' ? e.target | ||
: e.target.closest('LABEL') ? e.target.closest('LABEL') : null; | ||
input = label && label.getElementsByTagName('INPUT')[0]; | ||
if ( !input ) { return; } | ||
dispatchCustomEvent.call(input, changeCustomEvent); | ||
dispatchCustomEvent.call(element, changeCustomEvent); | ||
if ( input.type === 'checkbox' ) { | ||
if ( changeCustomEvent.defaultPrevented ) { return; } | ||
if ( !input.checked ) { | ||
label.classList.add('active'); | ||
input.getAttribute('checked'); | ||
input.setAttribute('checked','checked'); | ||
input.checked = true; | ||
} else { | ||
label.classList.remove('active'); | ||
input.getAttribute('checked'); | ||
input.removeAttribute('checked'); | ||
input.checked = false; | ||
} | ||
if (!element.toggled) { | ||
element.toggled = true; | ||
} | ||
} | ||
if ( input.type === 'radio' && !element.toggled ) { | ||
if ( changeCustomEvent.defaultPrevented ) { return; } | ||
if ( !input.checked || (e.screenX === 0 && e.screenY == 0) ) { | ||
label.classList.add('active'); | ||
label.classList.add('focus'); | ||
input.setAttribute('checked','checked'); | ||
input.checked = true; | ||
element.toggled = true; | ||
Array.from(labels).map(function (otherLabel){ | ||
var otherInput = otherLabel.getElementsByTagName('INPUT')[0]; | ||
if ( otherLabel !== label && otherLabel.classList.contains('active') ) { | ||
dispatchCustomEvent.call(otherInput, changeCustomEvent); | ||
otherLabel.classList.remove('active'); | ||
otherInput.removeAttribute('checked'); | ||
otherInput.checked = false; | ||
} | ||
}); | ||
} | ||
} | ||
setTimeout( function () { element.toggled = false; }, 50 ); | ||
} | ||
function keyHandler(e) { | ||
var key = e.which || e.keyCode; | ||
key === 32 && e.target === document.activeElement && toggle(e); | ||
} | ||
function preventScroll(e) { | ||
var key = e.which || e.keyCode; | ||
key === 32 && e.preventDefault(); | ||
} | ||
function focusToggle(e) { | ||
if (e.target.tagName === 'INPUT' ) { | ||
var action = e.type === 'focusin' ? 'add' : 'remove'; | ||
e.target.closest('.btn').classList[action]('focus'); | ||
} | ||
} | ||
function toggleEvents(action) { | ||
action = action ? 'addEventListener' : 'removeEventListener'; | ||
element[action]('click',toggle,false ); | ||
element[action]('keyup',keyHandler,false), element[action]('keydown',preventScroll,false); | ||
element[action]('focusin',focusToggle,false), element[action]('focusout',focusToggle,false); | ||
} | ||
self.dispose = function () { | ||
toggleEvents(); | ||
delete element.Button; | ||
}; | ||
element = queryElement(element); | ||
element.Button && element.Button.dispose(); | ||
labels = element.getElementsByClassName('btn'); | ||
if (!labels.length) { return; } | ||
if ( !element.Button ) { | ||
toggleEvents(1); | ||
} | ||
element.toggled = false; | ||
element.Button = self; | ||
Array.from(labels).map(function (btn){ | ||
!btn.classList.contains('active') | ||
&& queryElement('input:checked',btn) | ||
&& btn.classList.add('active'); | ||
btn.classList.contains('active') | ||
&& !queryElement('input:checked',btn) | ||
&& btn.classList.remove('active'); | ||
}); | ||
} | ||
|
||
export default Button; |
Oops, something went wrong.
a52ef8f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also removed the
tryWrapper
I don't like the error reporting despite the benefit of "un-breaking" the page.