Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
thednp committed Oct 26, 2016
1 parent c65de8e commit 283c37a
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 66 deletions.
66 changes: 33 additions & 33 deletions dist/bootstrap-native.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,25 +103,25 @@
this.element.className += ' affix';
this.affixed = true
}
}
};
this.unPinTop = function () {
if ( /\baffix/.test(this.element.className) ) {
this.element.className = this.element.className.replace(' affix','');
this.affixed = false
}
}
};
this.pinBottom = function () {
if ( !/\baffix-bottom/.test(this.element.className) ) {
this.element.className += ' affix-bottom';
this.affixedBottom = true
}
}
};
this.unPinBottom = function () {
if ( /\baffix-bottom/.test(this.element.className) ) {
this.element.className = this.element.className.replace(' affix-bottom','');
this.affixedBottom = false
}
}
};
this.updatePin = function () {
if (this.affixed === false && (parseInt(this.processOffsetTop(),0) - parseInt(getScroll().y,0) < 0)) {
this.pinTop();
Expand All @@ -134,32 +134,31 @@
} else if (this.affixedBottom === true && (parseInt(getScroll().y,0) <= parseInt(this.getPinOffsetBottom(),0) )) {
this.unPinBottom()
}
}
};
this.updateAffix = function () { // Unpin and check position again
this.unPinTop();
this.unPinBottom();
this.checkPosition()

this.updatePin() // If any case update values again
}
};
this.getMaxScroll = function(){
return Math.max( document.body.scrollHeight, document.body.offsetHeight,
document.documentElement.clientHeight, document.documentElement.scrollHeight, document.documentElement.offsetHeight )
}
};
this.scrollEvent = function(){
window.addEventListener('scroll', function() {
self.updatePin()
}, false);

}
};
this.resizeEvent = function(){
var dl = (isIE && isIE < 10) ? 500 : 50;
window.addEventListener('resize', function () {
setTimeout(function(){
self.updateAffix()
},dl);
}, false);
}
};
// init
this.affixed = false;
this.affixedBottom = false;
Expand Down Expand Up @@ -211,7 +210,7 @@
self.alert && self.alert.parentNode.removeChild(self.alert);
}, self.duration);
}
}
};
document.addEventListener('click', this.close, false); //delegate to all alerts, including those inserted later into the DOM
};

Expand Down Expand Up @@ -245,15 +244,15 @@
this.btn.setAttribute('disabled','disabled');
}
this.btn.innerHTML = this.state;
}
};

this.reset = function() {
if ( /\bdisabled/.test(this.btn.className) || this.btn.getAttribute('disabled') === 'disabled' ) {
removeClass(this.btn,'disabled');
this.btn.removeAttribute('disabled');
}
this.btn.innerHTML = this.btn.getAttribute('data-original-text');
}
};

this.toggle = function(e) {
var parent = e.target.parentNode,
Expand Down Expand Up @@ -304,7 +303,8 @@
}
}
}
}
};

// init
if ( /\bbtn/.test(this.btn.className) ) {
if ( this.option && this.option !== 'reset' ) {
Expand Down Expand Up @@ -832,7 +832,7 @@
addClass(self.modal,'in');
self.modal.setAttribute('aria-hidden', false);
}, this.options.duration/2);
}
};
this.close = function() {

if ( this.overlay ) {
Expand All @@ -856,10 +856,10 @@
setTimeout( function() {
if (!document.querySelector('.modal.in')) { self.removeOverlay(); }
}, this.options.duration);
}
};
this.content = function( content ) {
return this.modal.querySelector('.modal-content').innerHTML = content;
}
};
this.createOverlay = function() {
var backdrop = document.createElement('div'), overlay = document.querySelector('.modal-backdrop');
backdrop.setAttribute('class','modal-backdrop fade');
Expand All @@ -870,13 +870,13 @@
this.overlay = backdrop;
document.body.appendChild(backdrop);
}
}
};
this.removeOverlay = function() {
var overlay = document.querySelector('.modal-backdrop');
if ( overlay !== null && overlay !== undefined ) {
document.body.removeChild(overlay)
}
}
};
this.keydown = function() {
function keyHandler(e) {
if (self.options.keyboard && e.which == 27) {
Expand All @@ -888,7 +888,7 @@
} else {
document.removeEventListener('keydown', keyHandler, false);
}
}
};
this.trigger = function() {
var triggers = document.querySelectorAll('[data-toggle="modal"]'), tgl = triggers.length, i = 0;
for ( i;i<tgl;i++ ) {
Expand All @@ -902,22 +902,22 @@
}
})
}
}
};
this._resize = function() {
var overlay = this.overlay||document.querySelector('.modal-backdrop'),
dim = { w: document.documentElement.clientWidth + 'px', h: document.documentElement.clientHeight + 'px' };
if ( overlay !== null && /\bin/.test(overlay.className) ) {
overlay.style.height = dim.h; overlay.style.width = dim.w;
}
}
};
this.oneResize = function() {
function oneResize() {
self._resize();
self.handleUpdate();
window.removeEventListener('resize', oneResize, false);
}
window.addEventListener('resize', oneResize, false);
}
};
this.resize = function() {
function resizeHandler() {
self._resize();
Expand All @@ -929,7 +929,7 @@
} else {
window.removeEventListener('resize', this.oneResize, false);
}
}
};
this.dismiss = function() {
function dismissHandler(e) {
if ( e.target.parentNode.getAttribute('data-dismiss') === 'modal' || e.target.getAttribute('data-dismiss') === 'modal' || e.target === self.modal ) {
Expand All @@ -941,19 +941,19 @@
} else {
this.modal.removeEventListener('click', dismissHandler, false);
}
}
};
// these following methods are used to handle overflowing modals
this.handleUpdate = function () {
this.adjustDialog();
}
};
this.adjustDialog = function () {
this.modal.style.paddingLeft = !this.bodyIsOverflowing && this.modalIsOverflowing ? this.scrollbarWidth + 'px' : '';
this.modal.style.paddingRight = this.bodyIsOverflowing && !this.modalIsOverflowing ? this.scrollbarWidth + 'px' : '';
}
};
this.resetAdjustments = function () {
this.modal.style.paddingLeft = '';
this.modal.style.paddingRight = '';
}
};
//init
this.trigger();
if ( this.options.content && this.options.content !== undefined ) {
Expand Down Expand Up @@ -1360,19 +1360,19 @@
addClass(nextContent,'in');
}, self.options.duration*2);
}
}
};
this.getActiveTab = function() {
var activeTabs = this.tabs.querySelectorAll('.active');
if ( activeTabs.length === 1 && !/\bdropdown/.test(activeTabs[0].className) ) {
return activeTabs[0]
} else if ( activeTabs.length > 1 ) {
return activeTabs[activeTabs.length-1]
}
}
};
this.getActiveContent = function() {
var a = this.getActiveTab().getElementsByTagName('A')[0].getAttribute('href').replace('#','');
return a && document.getElementById(a)
}
var active = this.getActiveTab().getElementsByTagName('A')[0].getAttribute('href').replace('#','');
return active && document.getElementById(active)
};

// init
this.tab.addEventListener('click', this.handle, false);
Expand Down
19 changes: 9 additions & 10 deletions lib/affix-native.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,25 @@ var Affix = function(element,options) {
this.element.className += ' affix';
this.affixed = true
}
}
};
this.unPinTop = function () {
if ( /\baffix/.test(this.element.className) ) {
this.element.className = this.element.className.replace(' affix','');
this.affixed = false
}
}
};
this.pinBottom = function () {
if ( !/\baffix-bottom/.test(this.element.className) ) {
this.element.className += ' affix-bottom';
this.affixedBottom = true
}
}
};
this.unPinBottom = function () {
if ( /\baffix-bottom/.test(this.element.className) ) {
this.element.className = this.element.className.replace(' affix-bottom','');
this.affixedBottom = false
}
}
};
this.updatePin = function () {
if (this.affixed === false && (parseInt(this.processOffsetTop(),0) - parseInt(getScroll().y,0) < 0)) {
this.pinTop();
Expand All @@ -68,32 +68,31 @@ var Affix = function(element,options) {
} else if (this.affixedBottom === true && (parseInt(getScroll().y,0) <= parseInt(this.getPinOffsetBottom(),0) )) {
this.unPinBottom()
}
}
};
this.updateAffix = function () { // Unpin and check position again
this.unPinTop();
this.unPinBottom();
this.checkPosition()

this.updatePin() // If any case update values again
}
};
this.getMaxScroll = function(){
return Math.max( document.body.scrollHeight, document.body.offsetHeight,
document.documentElement.clientHeight, document.documentElement.scrollHeight, document.documentElement.offsetHeight )
}
};
this.scrollEvent = function(){
window.addEventListener('scroll', function() {
self.updatePin()
}, false);

}
};
this.resizeEvent = function(){
var dl = (isIE && isIE < 10) ? 500 : 50;
window.addEventListener('resize', function () {
setTimeout(function(){
self.updateAffix()
},dl);
}, false);
}
};
// init
this.affixed = false;
this.affixedBottom = false;
Expand Down
2 changes: 1 addition & 1 deletion lib/alert-native.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var Alert = function( element ) {
self.alert && self.alert.parentNode.removeChild(self.alert);
}, self.duration);
}
}
};
document.addEventListener('click', this.close, false); //delegate to all alerts, including those inserted later into the DOM
};

Expand Down
7 changes: 4 additions & 3 deletions lib/button-native.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ var Button = function( element, option ) {
this.btn.setAttribute('disabled','disabled');
}
this.btn.innerHTML = this.state;
}
};

this.reset = function() {
if ( /\bdisabled/.test(this.btn.className) || this.btn.getAttribute('disabled') === 'disabled' ) {
removeClass(this.btn,'disabled');
this.btn.removeAttribute('disabled');
}
this.btn.innerHTML = this.btn.getAttribute('data-original-text');
}
};

this.toggle = function(e) {
var parent = e.target.parentNode,
Expand Down Expand Up @@ -79,7 +79,8 @@ var Button = function( element, option ) {
}
}
}
}
};

// init
if ( /\bbtn/.test(this.btn.className) ) {
if ( this.option && this.option !== 'reset' ) {
Expand Down
Loading

0 comments on commit 283c37a

Please sign in to comment.