From 283c37a8bc27438504d20c46be4350fb82a809ae Mon Sep 17 00:00:00 2001 From: thednp Date: Wed, 26 Oct 2016 15:40:29 +0300 Subject: [PATCH] Code cleanup --- dist/bootstrap-native.js | 66 ++++++++++++++++++++-------------------- lib/affix-native.js | 19 ++++++------ lib/alert-native.js | 2 +- lib/button-native.js | 7 +++-- lib/modal-native.js | 28 ++++++++--------- lib/tab-native.js | 10 +++--- 6 files changed, 66 insertions(+), 66 deletions(-) diff --git a/dist/bootstrap-native.js b/dist/bootstrap-native.js index 9f89bdc0..6c797d7a 100644 --- a/dist/bootstrap-native.js +++ b/dist/bootstrap-native.js @@ -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(); @@ -134,24 +134,23 @@ } 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 () { @@ -159,7 +158,7 @@ self.updateAffix() },dl); }, false); - } + }; // init this.affixed = false; this.affixedBottom = false; @@ -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 }; @@ -245,7 +244,7 @@ this.btn.setAttribute('disabled','disabled'); } this.btn.innerHTML = this.state; - } + }; this.reset = function() { if ( /\bdisabled/.test(this.btn.className) || this.btn.getAttribute('disabled') === 'disabled' ) { @@ -253,7 +252,7 @@ this.btn.removeAttribute('disabled'); } this.btn.innerHTML = this.btn.getAttribute('data-original-text'); - } + }; this.toggle = function(e) { var parent = e.target.parentNode, @@ -304,7 +303,8 @@ } } } - } + }; + // init if ( /\bbtn/.test(this.btn.className) ) { if ( this.option && this.option !== 'reset' ) { @@ -832,7 +832,7 @@ addClass(self.modal,'in'); self.modal.setAttribute('aria-hidden', false); }, this.options.duration/2); - } + }; this.close = function() { if ( this.overlay ) { @@ -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'); @@ -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) { @@ -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 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); diff --git a/lib/affix-native.js b/lib/affix-native.js index a5a15e27..b4124609 100644 --- a/lib/affix-native.js +++ b/lib/affix-native.js @@ -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(); @@ -68,24 +68,23 @@ 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 () { @@ -93,7 +92,7 @@ var Affix = function(element,options) { self.updateAffix() },dl); }, false); - } + }; // init this.affixed = false; this.affixedBottom = false; diff --git a/lib/alert-native.js b/lib/alert-native.js index 76b9828e..cc1313b7 100644 --- a/lib/alert-native.js +++ b/lib/alert-native.js @@ -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 }; diff --git a/lib/button-native.js b/lib/button-native.js index 9570d654..6e989194 100644 --- a/lib/button-native.js +++ b/lib/button-native.js @@ -20,7 +20,7 @@ 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' ) { @@ -28,7 +28,7 @@ var Button = function( element, option ) { this.btn.removeAttribute('disabled'); } this.btn.innerHTML = this.btn.getAttribute('data-original-text'); - } + }; this.toggle = function(e) { var parent = e.target.parentNode, @@ -79,7 +79,8 @@ var Button = function( element, option ) { } } } - } + }; + // init if ( /\bbtn/.test(this.btn.className) ) { if ( this.option && this.option !== 'reset' ) { diff --git a/lib/modal-native.js b/lib/modal-native.js index bc1d18b2..be5c42b6 100644 --- a/lib/modal-native.js +++ b/lib/modal-native.js @@ -79,7 +79,7 @@ var Modal = function(element, options) { // element is the is the modal addClass(self.modal,'in'); self.modal.setAttribute('aria-hidden', false); }, this.options.duration/2); - } + }; this.close = function() { if ( this.overlay ) { @@ -103,10 +103,10 @@ var Modal = function(element, options) { // element is the is the modal 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'); @@ -117,13 +117,13 @@ var Modal = function(element, options) { // element is the is the modal 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) { @@ -135,7 +135,7 @@ var Modal = function(element, options) { // element is the is the modal } else { document.removeEventListener('keydown', keyHandler, false); } - } + }; this.trigger = function() { var triggers = document.querySelectorAll('[data-toggle="modal"]'), tgl = triggers.length, i = 0; for ( i;i 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);