Skip to content

Commit

Permalink
Changes:
Browse files Browse the repository at this point in the history
* 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
thednp committed Jun 18, 2020
1 parent 9623fe2 commit a52ef8f
Show file tree
Hide file tree
Showing 54 changed files with 5,367 additions and 1,126 deletions.
5 changes: 5 additions & 0 deletions assets/css/theme.css
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ h3:not(.popover-header) {
letter-spacing: -2px;
}

/* smooth scroll */
html {
scroll-behavior: smooth;
}

/* misc */
.dropright .dropdown-menu,
.dropleft .dropdown-menu {
Expand Down
688 changes: 330 additions & 358 deletions dist/bootstrap-native.esm.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/bootstrap-native.esm.min.js

Large diffs are not rendered by default.

688 changes: 330 additions & 358 deletions dist/bootstrap-native.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/bootstrap-native.min.js

Large diffs are not rendered by default.

87 changes: 87 additions & 0 deletions dist/components/alert-native.esm.js
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;
95 changes: 95 additions & 0 deletions dist/components/alert-native.js
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;

})));
113 changes: 113 additions & 0 deletions dist/components/button-native.esm.js
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;
Loading

1 comment on commit a52ef8f

@thednp
Copy link
Owner Author

@thednp thednp commented on a52ef8f Jun 18, 2020

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.

Please sign in to comment.