Skip to content

Pressing escape now closes sections or work panels #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

FullscreenLayoutPageTransitions
=========

Expand All @@ -8,4 +7,6 @@ This responsive layout is based on an initial grid of four boxes. Once a box is

[demo](http://tympanus.net/Development/FullscreenLayoutPageTransitions)

Licensed under the MIT License
Licensed under the MIT License

Edit: I have edited this project to enable the escape button funcionality. Pressing escape now returns you to the start page/navigation.
72 changes: 51 additions & 21 deletions js/boxlayout.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* Licensed under the MIT license.
* http://www.opensource.org/licenses/mit-license.php
*
*
* Copyright 2013, Codrops
* http://www.codrops.com
*/
Expand Down Expand Up @@ -43,39 +43,47 @@ var Boxlayout = (function() {
}

function initEvents() {

$sections.each( function() {

var $section = $( this );

// expand the clicked section and scale down the others
$section.on( 'click', function() {

if( !$section.data( 'open' ) ) {
$section.data( 'open', true ).addClass( 'bl-expand bl-expand-top' );
$el.addClass( 'bl-expand-item' );
$el.addClass( 'bl-expand-item' );
}

} ).find( 'span.bl-icon-close' ).on( 'click', function() {

// close the expanded section and scale up the others
$section.data( 'open', false ).removeClass( 'bl-expand' ).on( transEndEventName, function( event ) {
if( !$( event.target ).is( 'section' ) ) return false;
$( this ).off( transEndEventName ).removeClass( 'bl-expand-top' );
} );

if( !supportTransitions ) {
$section.removeClass( 'bl-expand-top' );
}

$el.removeClass( 'bl-expand-item' );
closeSection( $section );

return false;

} );

} );

// pressing escape closes sections or work panels
$( document ).on( 'keyup', function( event ) {

if( event.keyCode === 27 ) {

var $section = $( 'section.bl-expand' );

// check if a section or a work panel is open
if( $( '.bl-show-work' ).length ) {
closeWorkPanel();
} else if( $section.length ) {
closeSection( $section );
}

}

});

// clicking on a work item: the current section scales down and the respective work panel slides up
$workItems.on( 'click', function( event ) {

Expand All @@ -95,7 +103,7 @@ var Boxlayout = (function() {

// navigating the work items: current work panel scales down and the next work panel slides up
$nextWorkItem.on( 'click', function( event ) {

if( isAnimating ) {
return false;
}
Expand All @@ -115,7 +123,7 @@ var Boxlayout = (function() {
$currentPanel.removeClass( 'bl-hide-current-work' );
isAnimating = false;
}

$nextPanel.addClass( 'bl-show-work' );

return false;
Expand All @@ -125,14 +133,36 @@ var Boxlayout = (function() {
// clicking the work panels close button: the current work panel slides down and the section scales up again
$closeWorkItem.on( 'click', function( event ) {

closeWorkPanel();

return false;

} );

var closeSection = function($section) {

// close the expanded section and scale up the others
$section.data( 'open', false ).removeClass( 'bl-expand' ).on( transEndEventName, function( event ) {
if( !$( event.target ).is( 'section' ) ) return false;
$( this ).off( transEndEventName ).removeClass( 'bl-expand-top' );
} );

if( !supportTransitions ) {
$section.removeClass( 'bl-expand-top' );
}

$el.removeClass( 'bl-expand-item' );

};

var closeWorkPanel = function() {

// scale up main section
$sectionWork.removeClass( 'bl-scale-down' );
$workPanelsContainer.removeClass( 'bl-panel-items-show' );
$workPanels.eq( currentWorkPanel ).removeClass( 'bl-show-work' );

return false;

} );
}

}

Expand Down