Skip to content

Commit

Permalink
code formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
hakimel committed Jun 13, 2017
1 parent a20563d commit 8264c14
Showing 1 changed file with 45 additions and 27 deletions.
72 changes: 45 additions & 27 deletions js/avgrund.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,72 +8,90 @@
var Avgrund = (function(){

var container = document.documentElement,
popup = document.querySelector('.avgrund-popup-animate'),
cover = document.querySelector('.avgrund-cover'),
popup = document.querySelector( '.avgrund-popup-animate' ),
cover = document.querySelector( '.avgrund-cover' ),
currentState = null;
container.classList.add('avgrund-ready');

container.classList.add( 'avgrund-ready' );

// Deactivate on ESC
function onDocumentKeyUp(event) {
if(event.keyCode === 27) {
function onDocumentKeyUp( event ) {

if( event.keyCode === 27 ) {
deactivate();
}

}

// Deactivate on click outside
function onDocumentClick(event) {
if(event.target === cover) {
function onDocumentClick( event ) {

if( event.target === cover ) {
deactivate();
}

}

function activate(state) {
document.addEventListener('keyup', onDocumentKeyUp, false);
document.addEventListener('click', onDocumentClick, false);
document.addEventListener('touchstart', onDocumentClick, false);
function activate( state ) {

popup.classList.remove(currentState);
popup.classList.add('no-transition');
document.addEventListener( 'keyup', onDocumentKeyUp, false );
document.addEventListener( 'click', onDocumentClick, false );
document.addEventListener( 'touchstart', onDocumentClick, false );

popup.classList.remove( currentState );
popup.classList.add( 'no-transition' );
if(state)
popup.classList.add(state);
popup.classList.add( state );

setTimeout(function() {
popup.classList.remove('no-transition');
container.classList.add('avgrund-active');
}, 0);
setTimeout( function() {
popup.classList.remove( 'no-transition' );
container.classList.add( 'avgrund-active' );
}, 0 );

currentState = state;

}

function deactivate() {
document.removeEventListener('keyup', onDocumentKeyUp, false);
document.removeEventListener('click', onDocumentClick, false);
document.removeEventListener('touchstart', onDocumentClick, false);

container.classList.remove('avgrund-active');
popup.classList.remove('avgrund-popup-animate');
document.removeEventListener( 'keyup', onDocumentKeyUp, false );
document.removeEventListener( 'click', onDocumentClick, false );
document.removeEventListener( 'touchstart', onDocumentClick, false );

container.classList.remove( 'avgrund-active' );
popup.classList.remove( 'avgrund-popup-animate' );

}

function disableBlur() {
document.documentElement.classList.add('no-blur');

document.documentElement.classList.add( 'no-blur' );

}

function show(selector){
popup = document.querySelector(selector);
popup.classList.add('avgrund-popup-animate');
function show( selector ) {

popup = document.querySelector( selector );
popup.classList.add( 'avgrund-popup-animate' );
activate();
return this;

}

function hide() {

deactivate();

}

return {

activate: activate,
deactivate: deactivate,
disableBlur: disableBlur,
show: show,
hide: hide

}

})();

0 comments on commit 8264c14

Please sign in to comment.