Skip to content

Instantly share code, notes, and snippets.

@thoughtpalette
Created April 14, 2015 20:03
Show Gist options
  • Save thoughtpalette/d1e404a5ffd3abb2f318 to your computer and use it in GitHub Desktop.
Save thoughtpalette/d1e404a5ffd3abb2f318 to your computer and use it in GitHub Desktop.
var $updatePasswordContainer = $( ".update-password" ),
$savePasswordBtn = $( ".save-password" );
$cancelEditBtn = $( ".cancel-password" );
var updatePasswordSection = {
toggle: function( parentEl, initialValue )
{
if ( $updatePasswordContainer.hasClass( "editing" ) )
{
$updatePasswordContainer.removeClass( "editing" );
$savePasswordBtn.removeClass( "visible" );
parentEl.addClass( "completed" );
parentEl.find( "span" ).removeClass( "editing" );
parentEl.find( "input" ).val( initialValue );
}
else
{
$updatePasswordContainer.addClass( "editing" );
parentEl.find( "span" ).addClass( "editing" );
parentEl.find( "input" ).removeClass( "completed" );
$( ".update-password .new-pass" ).focus();
$savePasswordBtn.addClass( "visible" );
$cancelEditBtn.addClass( "active" );
}
},
hide: function ( parentEl, initialValue )
{
$updatePasswordContainer.removeClass( "editing" );
$savePasswordBtn.removeClass( "visible" );
parentEl.addClass( "completed" );
parentEl.find( "span" ).removeClass( "editing" );
}
};
$( "#account .field a.change-input" ).on( "click", function ( e )
{
e.preventDefault();
var $this = $( this ),
$thisParent = $( this ).parent(),
$initialValue = $thisParent.find( "span" ).text();
$this.hide();
$thisParent.find( "input" ).removeClass( "completed" ).focus();
$thisParent.find( "span" ).addClass( "editing" );
$thisParent.find( "input" ).val( initialValue );
updatePasswordSection.hide( $thisParent, $initialValue );
} );
$( "#account .field a.change-input-password" ).on( "click", function ( e )
{
e.preventDefault();
var $this = $( this ),
$cancelEditBtn = $( ".cancel-password" ),
$thisParent = $( this ).parent(),
$initialValue = $thisParent.find( "span" ).text();
$this.hide();
updatePasswordSection.toggle( $thisParent, $initialValue );
$cancelEditBtn.on( "click", function ( e )
{
$( this ).removeClass( "active" );
$this.show();
updatePasswordSection.hide( $thisParent, $initialValue );
} );
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment