Skip to content

Commit

Permalink
Changes:
Browse files Browse the repository at this point in the history
* V3/V4 added "use strict" mode (cannot believe we forgot about it)
* V3/V4 improved execution speed for the `initializaDataAPI` utility
  • Loading branch information
thednp committed Sep 22, 2017
1 parent f9ddbfa commit a5990dd
Show file tree
Hide file tree
Showing 28 changed files with 69 additions and 101 deletions.
43 changes: 18 additions & 25 deletions dist/bootstrap-native-v4.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
hasAttribute = 'hasAttribute',
getElementsByTagName = 'getElementsByTagName',
getBoundingClientRect = 'getBoundingClientRect',
querySelectorAll = 'querySelectorAll',
getElementsByCLASSNAME = 'getElementsByClassName',

indexOf = 'indexOf',
Expand Down Expand Up @@ -198,20 +199,12 @@
this.dispatchEvent(OriginalCustomEvent);
},

// reference a live collection of the DOM
AllDOMElements = document[getElementsByTagName]('*'),

// Init DATA API
initializeDataAPI = function( component, constructor, dataAttribute, collection ){
var lookUp = collection && collection[length] ? collection : AllDOMElements;
for (var i=0; i < lookUp[length]; i++) {
var attrValue = lookUp[i][getAttribute](dataAttribute), expectedAttrValue = component.replace(/spy/i,'')[toLowerCase]();
if ( attrValue && component === stringButton && ( attrValue[indexOf](expectedAttrValue) > -1 ) // data-toggle="buttons"
|| attrValue === expectedAttrValue ) { // all other components
new constructor(lookUp[i]);
}
initializeDataAPI = function( component, constructor, collection ){
for (var i=0; i < collection[length]; i++) {
new constructor(collection[i]);
}
},
},

// tab / collapse stuff
targetsReg = /^\#(.)+$/,
Expand Down Expand Up @@ -262,9 +255,9 @@
},
updatePlacement = function(position) {
return position === top ? bottom : // top
position === bottom ? top : // bottom
position === left ? right : // left
position === right ? left : position; // right
position === bottom ? top : // bottom
position === left ? right : // left
position === right ? left : position; // right
};


Expand Down Expand Up @@ -317,7 +310,7 @@

// ALERT DATA API
// ==============
initializeDataAPI ( stringAlert, Alert, dataDismiss );
initializeDataAPI ( stringAlert, Alert, doc[querySelectorAll]('['+dataDismiss+'="alert"]') );


/* Native Javascript for Bootstrap 4 | Button
Expand Down Expand Up @@ -408,7 +401,7 @@

// BUTTON DATA API
// =================
initializeDataAPI( stringButton, Button, dataToggle );
initializeDataAPI( stringButton, Button, doc[querySelectorAll]('['+dataToggle+'="buttons"]') );


/* Native Javascript for Bootstrap 4 | Carousel
Expand Down Expand Up @@ -636,7 +629,7 @@

// CAROUSEL DATA API
// =================
initializeDataAPI( stringCarousel, Carousel, dataRide );
initializeDataAPI( stringCarousel, Carousel, doc[querySelectorAll]('['+dataRide+'="carousel"]') );


/* Native Javascript for Bootstrap 4 | Collapse
Expand Down Expand Up @@ -745,7 +738,7 @@

// COLLAPSE DATA API
// =================
initializeDataAPI(stringCollapse, Collapse, dataToggle);
initializeDataAPI(stringCollapse, Collapse, doc[querySelectorAll]('['+dataToggle+'="collapse"]'));


/* Native Javascript for Bootstrap 4 | Dropdown
Expand Down Expand Up @@ -824,7 +817,7 @@

// DROPDOWN DATA API
// =================
initializeDataAPI( stringDropdown, Dropdown, dataToggle );
initializeDataAPI( stringDropdown, Dropdown, doc[querySelectorAll]('['+dataToggle+'="dropdown"]') );


/* Native Javascript for Bootstrap 4 | Modal
Expand Down Expand Up @@ -1076,7 +1069,7 @@
};

// DATA API
initializeDataAPI(stringModal, Modal, dataToggle);
initializeDataAPI(stringModal, Modal, doc[querySelectorAll]('['+dataToggle+'="modal"]'));


/* Native Javascript for Bootstrap 4 | Popover
Expand Down Expand Up @@ -1264,7 +1257,7 @@

// POPOVER DATA API
// ================
initializeDataAPI(stringPopover, Popover, dataToggle);
initializeDataAPI(stringPopover, Popover, doc[querySelectorAll]('['+dataToggle+'="popover"]'));


/* Native Javascript for Bootstrap 4 | ScrollSpy
Expand Down Expand Up @@ -1361,7 +1354,7 @@

// SCROLLSPY DATA API
// ==================
initializeDataAPI(stringScrollSpy, ScrollSpy, dataSpy);
initializeDataAPI(stringScrollSpy, ScrollSpy, doc[querySelectorAll]('['+dataSpy+'="scroll"]'));


/* Native Javascript for Bootstrap 4 | Tab
Expand Down Expand Up @@ -1504,7 +1497,7 @@

// TAB DATA API
// ============
initializeDataAPI(stringTab, Tab, dataToggle);
initializeDataAPI(stringTab, Tab, doc[querySelectorAll]('['+dataToggle+'="tab"]'));


/* Native Javascript for Bootstrap 4 | Tooltip
Expand Down Expand Up @@ -1637,7 +1630,7 @@

// TOOLTIP DATA API
// =================
initializeDataAPI(stringTooltip, Tooltip, dataToggle);
initializeDataAPI(stringTooltip, Tooltip, doc[querySelectorAll]('['+dataToggle+'="tooltip"]'));


return {
Expand Down
2 changes: 1 addition & 1 deletion dist/bootstrap-native-v4.min.js

Large diffs are not rendered by default.

38 changes: 15 additions & 23 deletions dist/bootstrap-native.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,20 +209,12 @@
this.dispatchEvent(OriginalCustomEvent);
},

// reference a live collection of the DOM
AllDOMElements = document[getElementsByTagName]('*'),

// Init DATA API
initializeDataAPI = function( component, constructor, dataAttribute, collection ){
var lookUp = collection && collection[length] ? collection : AllDOMElements;
for (var i=0; i < lookUp[length]; i++) {
var attrValue = lookUp[i][getAttribute](dataAttribute), expectedAttrValue = component.replace(/spy/i,'')[toLowerCase]();
if ( attrValue && component === stringButton && ( attrValue[indexOf](expectedAttrValue) > -1 ) // data-toggle="buttons"
|| attrValue === expectedAttrValue ) { // all other components
new constructor(lookUp[i]);
}
initializeDataAPI = function( component, constructor, collection ){
for (var i=0; i < collection[length]; i++) {
new constructor(collection[i]);
}
},
},

// tab / collapse stuff
targetsReg = /^\#(.)+$/,
Expand Down Expand Up @@ -395,7 +387,7 @@

// AFFIX DATA API
// =================
initializeDataAPI( stringAffix, Affix, dataSpy );
initializeDataAPI( stringAffix, Affix, doc[querySelectorAll]('['+dataSpy+'="affix"]') );


/* Native Javascript for Bootstrap 3 | Alert
Expand Down Expand Up @@ -446,7 +438,7 @@

// ALERT DATA API
// ==============
initializeDataAPI ( stringAlert, Alert, dataDismiss );
initializeDataAPI ( stringAlert, Alert, doc[querySelectorAll]('['+dataDismiss+'="alert"]') );


/* Native Javascript for Bootstrap 3 | Button
Expand Down Expand Up @@ -565,7 +557,7 @@

// BUTTON DATA API
// =================
initializeDataAPI( stringButton, Button, dataToggle );
initializeDataAPI( stringButton, Button, doc[querySelectorAll]('['+dataToggle+'="buttons"]') );


/* Native Javascript for Bootstrap 3 | Carousel
Expand Down Expand Up @@ -792,7 +784,7 @@

// CAROUSEL DATA API
// =================
initializeDataAPI( stringCarousel, Carousel, dataRide );
initializeDataAPI( stringCarousel, Carousel, doc[querySelectorAll]('['+dataRide+'="carousel"]') );


/* Native Javascript for Bootstrap 3 | Collapse
Expand Down Expand Up @@ -901,7 +893,7 @@

// COLLAPSE DATA API
// =================
initializeDataAPI(stringCollapse, Collapse, dataToggle);
initializeDataAPI(stringCollapse, Collapse, doc[querySelectorAll]('['+dataToggle+'="collapse"]'));


/* Native Javascript for Bootstrap 3 | Dropdown
Expand Down Expand Up @@ -977,7 +969,7 @@

// DROPDOWN DATA API
// =================
initializeDataAPI( stringDropdown, Dropdown, dataToggle );
initializeDataAPI( stringDropdown, Dropdown, doc[querySelectorAll]('['+dataToggle+'="dropdown"]') );


/* Native Javascript for Bootstrap 3 | Modal
Expand Down Expand Up @@ -1229,7 +1221,7 @@
};

// DATA API
initializeDataAPI(stringModal, Modal, dataToggle);
initializeDataAPI(stringModal, Modal, doc[querySelectorAll]('['+dataToggle+'="modal"]'));


/* Native Javascript for Bootstrap 3 | Popover
Expand Down Expand Up @@ -1413,7 +1405,7 @@

// POPOVER DATA API
// ================
initializeDataAPI(stringPopover, Popover, dataToggle);
initializeDataAPI(stringPopover, Popover, doc[querySelectorAll]('['+dataToggle+'="popover"]'));


/* Native Javascript for Bootstrap 3 | ScrollSpy
Expand Down Expand Up @@ -1508,7 +1500,7 @@

// SCROLLSPY DATA API
// ==================
initializeDataAPI(stringScrollSpy, ScrollSpy, dataSpy);
initializeDataAPI(stringScrollSpy, ScrollSpy, doc[querySelectorAll]('['+dataSpy+'="scroll"]'));


/* Native Javascript for Bootstrap 3 | Tab
Expand Down Expand Up @@ -1651,7 +1643,7 @@

// TAB DATA API
// ============
initializeDataAPI(stringTab, Tab, dataToggle);
initializeDataAPI(stringTab, Tab, doc[querySelectorAll]('['+dataToggle+'="tab"]'));


/* Native Javascript for Bootstrap 3 | Tooltip
Expand Down Expand Up @@ -1781,7 +1773,7 @@

// TOOLTIP DATA API
// =================
initializeDataAPI(stringTooltip, Tooltip, dataToggle);
initializeDataAPI(stringTooltip, Tooltip, doc[querySelectorAll]('['+dataToggle+'="tooltip"]'));


return {
Expand Down
2 changes: 1 addition & 1 deletion dist/bootstrap-native.min.js

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3246,9 +3246,7 @@ <h3 class="visible-xs">Navigation</h3>
<!-- highlighter -->
<script src="./assets/js/prism.js" type="text/javascript"></script>

<!--<script type="text/javascript" src="https://cdn.jsdelivr.net/bootstrap.native/2.0.13/bootstrap-native.min.js"></script> now we have CDN -->
<!--<script type="text/javascript" src="./dist/bootstrap-native.min.js"></script>-->
<script type="text/javascript" src="./dist/bootstrap-native.js"></script>
<script type="text/javascript" src="./dist/bootstrap-native.min.js"></script>
<script type="text/javascript" src="./assets/js/scripts.js"></script>
</body>
</html>
2 changes: 1 addition & 1 deletion lib/V3/affix-native.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,5 +120,5 @@ var Affix = function(element, options) {

// AFFIX DATA API
// =================
initializeDataAPI( stringAffix, Affix, dataSpy );
initializeDataAPI( stringAffix, Affix, doc[querySelectorAll]('['+dataSpy+'="affix"]') );

2 changes: 1 addition & 1 deletion lib/V3/alert-native.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,5 @@ var Alert = function( element ) {

// ALERT DATA API
// ==============
initializeDataAPI ( stringAlert, Alert, dataDismiss );
initializeDataAPI ( stringAlert, Alert, doc[querySelectorAll]('['+dataDismiss+'="alert"]') );

2 changes: 1 addition & 1 deletion lib/V3/button-native.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,5 @@ var Button = function( element, option ) {

// BUTTON DATA API
// =================
initializeDataAPI( stringButton, Button, dataToggle );
initializeDataAPI( stringButton, Button, doc[querySelectorAll]('['+dataToggle+'="buttons"]') );

2 changes: 1 addition & 1 deletion lib/V3/carousel-native.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,5 +223,5 @@ var Carousel = function( element, options ) {

// CAROUSEL DATA API
// =================
initializeDataAPI( stringCarousel, Carousel, dataRide );
initializeDataAPI( stringCarousel, Carousel, doc[querySelectorAll]('['+dataRide+'="carousel"]') );

2 changes: 1 addition & 1 deletion lib/V3/collapse-native.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,5 @@ var Collapse = function( element, options ) {

// COLLAPSE DATA API
// =================
initializeDataAPI(stringCollapse, Collapse, dataToggle);
initializeDataAPI(stringCollapse, Collapse, doc[querySelectorAll]('['+dataToggle+'="collapse"]'));

2 changes: 1 addition & 1 deletion lib/V3/dropdown-native.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,5 @@ var Dropdown = function( element, option ) {

// DROPDOWN DATA API
// =================
initializeDataAPI( stringDropdown, Dropdown, dataToggle );
initializeDataAPI( stringDropdown, Dropdown, doc[querySelectorAll]('['+dataToggle+'="dropdown"]') );

2 changes: 1 addition & 1 deletion lib/V3/modal-native.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,5 +248,5 @@ var Modal = function(element, options) { // element can be the modal/triggering
};

// DATA API
initializeDataAPI(stringModal, Modal, dataToggle);
initializeDataAPI(stringModal, Modal, doc[querySelectorAll]('['+dataToggle+'="modal"]'));

2 changes: 1 addition & 1 deletion lib/V3/popover-native.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,5 +180,5 @@ var Popover = function( element, options ) {

// POPOVER DATA API
// ================
initializeDataAPI(stringPopover, Popover, dataToggle);
initializeDataAPI(stringPopover, Popover, doc[querySelectorAll]('['+dataToggle+'="popover"]'));

2 changes: 1 addition & 1 deletion lib/V3/scrollspy-native.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,5 @@ var ScrollSpy = function(element, options) {

// SCROLLSPY DATA API
// ==================
initializeDataAPI(stringScrollSpy, ScrollSpy, dataSpy);
initializeDataAPI(stringScrollSpy, ScrollSpy, doc[querySelectorAll]('['+dataSpy+'="scroll"]'));

2 changes: 1 addition & 1 deletion lib/V3/tab-native.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,5 +139,5 @@ var Tab = function( element, options ) {

// TAB DATA API
// ============
initializeDataAPI(stringTab, Tab, dataToggle);
initializeDataAPI(stringTab, Tab, doc[querySelectorAll]('['+dataToggle+'="tab"]'));

2 changes: 1 addition & 1 deletion lib/V3/tooltip-native.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,5 @@ var Tooltip = function( element,options ) {

// TOOLTIP DATA API
// =================
initializeDataAPI(stringTooltip, Tooltip, dataToggle);
initializeDataAPI(stringTooltip, Tooltip, doc[querySelectorAll]('['+dataToggle+'="tooltip"]'));

16 changes: 4 additions & 12 deletions lib/V3/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,20 +185,12 @@ var globalObject = typeof global !== 'undefined' ? global : this||window,
this.dispatchEvent(OriginalCustomEvent);
},

// reference a live collection of the DOM
AllDOMElements = document[getElementsByTagName]('*'),

// Init DATA API
initializeDataAPI = function( component, constructor, dataAttribute, collection ){
var lookUp = collection && collection[length] ? collection : AllDOMElements;
for (var i=0; i < lookUp[length]; i++) {
var attrValue = lookUp[i][getAttribute](dataAttribute), expectedAttrValue = component.replace(/spy/i,'')[toLowerCase]();
if ( attrValue && component === stringButton && ( attrValue[indexOf](expectedAttrValue) > -1 ) // data-toggle="buttons"
|| attrValue === expectedAttrValue ) { // all other components
new constructor(lookUp[i]);
}
initializeDataAPI = function( component, constructor, collection ){
for (var i=0; i < collection[length]; i++) {
new constructor(collection[i]);
}
},
},

// tab / collapse stuff
targetsReg = /^\#(.)+$/,
Expand Down
2 changes: 1 addition & 1 deletion lib/V4/alert-native.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,5 @@ var Alert = function( element ) {

// ALERT DATA API
// ==============
initializeDataAPI ( stringAlert, Alert, dataDismiss );
initializeDataAPI ( stringAlert, Alert, doc[querySelectorAll]('['+dataDismiss+'="alert"]') );

2 changes: 1 addition & 1 deletion lib/V4/button-native.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,5 @@ var Button = function( element ) {

// BUTTON DATA API
// =================
initializeDataAPI( stringButton, Button, dataToggle );
initializeDataAPI( stringButton, Button, doc[querySelectorAll]('['+dataToggle+'="buttons"]') );

2 changes: 1 addition & 1 deletion lib/V4/carousel-native.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,5 +224,5 @@ var Carousel = function( element, options ) {

// CAROUSEL DATA API
// =================
initializeDataAPI( stringCarousel, Carousel, dataRide );
initializeDataAPI( stringCarousel, Carousel, doc[querySelectorAll]('['+dataRide+'="carousel"]') );

Loading

0 comments on commit a5990dd

Please sign in to comment.