Skip to content

Instantly share code, notes, and snippets.

@thoughtpalette
Created April 15, 2015 16:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thoughtpalette/28857d14984a0a15de04 to your computer and use it in GitHub Desktop.
Save thoughtpalette/28857d14984a0a15de04 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
{
toggleInputControls.hideAll( parentEl, initialValue );
$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" );
if( parentEl.hasClass( "password") )
{
parentEl.find( "span" ).removeClass( "editing" );
}
else
{
$( ".password" ).find( "span" ).removeClass( "editing" );
$cancelEditBtn.removeClass( "active" );
$( "#account .field a.change-input-password" ).show();
}
}
};
var toggleInputControls = {
show: function ( parentEl, initialValue ) {
toggleInputControls.hideAll( initialValue );
parentEl.find( "input" ).removeClass( "completed" ).focus();
parentEl.find( "span" ).addClass( "editing" );
parentEl.find( "input" ).val( initialValue );
parentEl.find( "a.change-input" ).hide();
parentEl.addClass( "editing" );
parentEl.find( ".cancel-edit").on( "click", function ( e ) {
e.preventDefault();
toggleInputControls.hide( parentEl, initialValue );
});
parentEl.find( ".save-input").on( "click", function ( e ) {
e.preventDefault();
$( "#account" ).submit();
});
},
hide: function ( parentEl, initialValue ) {
parentEl.find( "input" ).addClass( "completed" );
parentEl.find( "span" ).removeClass( "editing" );
parentEl.find( "input" ).val( initialValue );
parentEl.find( ".change-input" ).show();
parentEl.removeClass( "editing" );
},
hideAll: function ( initialValue ) {
$( ".field input" ).addClass( "completed" );
$( ".field span" ).removeClass( "editing" );
$( ".field input" ).val( initialValue );
$( ".field" ).removeClass( "editing" );
$( ".field a.change-input" ).show();
},
save: function ( parentEl, initialValue ) {
}
};
$( "#account .field a.change-input" ).on( "click", function ( e )
{
e.preventDefault();
var $this = $( this ),
$thisParent = $( this ).parent(),
$initialValue = $thisParent.find( "span" ).text();
$this.hide();
toggleInputControls.show( $thisParent, $initialValue );
updatePasswordSection.hide( $thisParent );
} );
$( "#account .field a.change-input-password" ).on( "click", function ( e )
{
e.preventDefault();
var $this = $( this ),
$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