forked from xwp/wp-customize-snapshots
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue xwp#17 : Enable deleting settings in snapshot wp-admin/post page.
Create link 'Remove setting,' which toggles to 'Restore setting' on click. It also sets a hidden text field for each setting to be removed. On saving, these appear in $_REQUEST[ 'customize_snapshot_remove_settings' ]. Filter post content on 'content_save_pre,' when this is saved. If $_REQUEST has settings to be removed, filter them out. Also, add simple styling of this 'Remove setting' link. It appears red when set to 'remove,' and blue when set to 'restore.'
- Loading branch information
Ryan Kienstra
committed
Aug 24, 2016
1 parent
856d135
commit a2fb645
Showing
5 changed files
with
160 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
details.cs-removed summary::-webkit-details-marker { | ||
display:none; | ||
} | ||
details:not(.cs-removed) .cs-toggle-action { | ||
color: #a00 | ||
} | ||
details:not(.cs-removed) .cs-toggle-action:hover { | ||
color: #f00 | ||
} | ||
details .cs-toggle-action { | ||
float: right; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
( function( $ ) { | ||
|
||
$( function() { | ||
var $link, linkText, linkActions, dataSlug, initializeLink; | ||
|
||
$link = $( '.cs-toggle-action' ); | ||
linkText = [ 'Remove setting', 'Restore setting' ]; | ||
linkActions = [ 'remove', 'restore' ]; | ||
dataSlug = 'cs-action'; | ||
|
||
initializeLink = function() { | ||
$link.text( linkText[ 0 ] ) | ||
.data( dataSlug, linkActions[ 0 ] ); | ||
}; | ||
|
||
initializeLink(); | ||
|
||
$link.on( 'click', function( event ) { | ||
var $clickedLink, $settingDisplay, clickedLinkAction, settingId; | ||
|
||
event.preventDefault(); | ||
|
||
$clickedLink = $( this ); | ||
$settingDisplay = $( this ).parents( 'details' ); | ||
clickedLinkAction = $( this ).data( dataSlug ); | ||
settingId = $( this ).attr( 'id' ); | ||
|
||
this.isLinkSetToRemoveSetting = function() { | ||
return ( linkActions[ 0 ] === clickedLinkAction ); | ||
}; | ||
|
||
this.hideSettingAndChangeLinkText = function() { | ||
$clickedLink.text( linkText[ 1 ] ) | ||
.data( dataSlug, linkActions[ 1 ] ) | ||
.after( this.constructHiddenInputWithValue( settingId ) ); | ||
$settingDisplay.removeAttr( 'open' ) | ||
.addClass( 'cs-removed' ); | ||
}; | ||
|
||
this.constructHiddenInputWithValue = function( settingId ) { | ||
return $( '<input>' ).attr( { | ||
'name': 'customize_snapshot_remove_settings[]', | ||
'type': 'hidden' | ||
}) | ||
.val( settingId ); | ||
}; | ||
|
||
this.isLinkSetToRestoreSetting = function() { | ||
return ( linkActions[ 1 ] === clickedLinkAction ); | ||
}; | ||
|
||
this.showSettingAndChangeLinkText = function() { | ||
$clickedLink.text( linkText[ 0 ] ) | ||
.data( dataSlug, linkActions[ 0 ] ); | ||
this.removeHiddenInputWithValue( settingId ); | ||
$settingDisplay.removeClass( 'cs-removed' ); | ||
}; | ||
|
||
this.removeHiddenInputWithValue = function( settingId ) { | ||
$( 'input[value="' + settingId + '"]' ).remove(); | ||
}; | ||
|
||
if ( this.isLinkSetToRemoveSetting() ) { | ||
this.hideSettingAndChangeLinkText(); | ||
} else if ( this.isLinkSetToRestoreSetting() ) { | ||
this.showSettingAndChangeLinkText(); | ||
} | ||
|
||
} ); | ||
|
||
} ); | ||
}( jQuery ) ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters