|
2 | 2 | 'use strict';
|
3 | 3 |
|
4 | 4 | $( function() {
|
5 |
| - var component, linkSelector, linkText, linkActions, dataSlug, inputName; |
| 5 | + var component, $linkToRemoveOrRestore, linkActions, dataSlug, inputName; |
6 | 6 |
|
7 | 7 | component = {};
|
8 |
| - linkSelector = '.snapshot-toggle-setting-removal'; |
9 |
| - linkText = [ 'Remove setting', 'Restore setting' ]; |
| 8 | + $linkToRemoveOrRestore = $( '.snapshot-toggle-setting-removal' ); |
10 | 9 | linkActions = [ 'remove', 'restore' ];
|
11 | 10 | dataSlug = 'cs-action';
|
12 | 11 | inputName = 'customize_snapshot_remove_settings[]';
|
13 | 12 |
|
14 | 13 | component.initializeLink = function() {
|
15 |
| - $( linkSelector ).text( linkText[ 0 ] ) |
16 |
| - .data( dataSlug, linkActions[ 0 ] ); |
| 14 | + $linkToRemoveOrRestore.data( dataSlug, linkActions[ 0 ] ); |
17 | 15 | };
|
18 | 16 |
|
19 | 17 | component.initializeLink();
|
|
35 | 33 | $settingDisplay = component.getSettingDisplay( $link );
|
36 | 34 | settingId = component.getSettingId( $link );
|
37 | 35 |
|
38 |
| - $link.text( linkText[ 1 ] ) |
39 |
| - .data( dataSlug, linkActions[ 1 ] ) |
| 36 | + $link.data( dataSlug, linkActions[ 1 ] ) |
40 | 37 | .after( component.constructHiddenInputWithValue( settingId ) );
|
| 38 | + component.changeLinkText( $link ); |
41 | 39 | $settingDisplay.removeAttr( 'open' )
|
42 | 40 | .addClass( 'snapshot-setting-removed' );
|
43 | 41 | };
|
|
58 | 56 | .val( settingId );
|
59 | 57 | };
|
60 | 58 |
|
| 59 | + component.changeLinkText = function( $link ) { |
| 60 | + var oldLinkText, newLinkText; |
| 61 | + oldLinkText = $link.text(); |
| 62 | + newLinkText = $link.data( 'text-restore' ); |
| 63 | + |
| 64 | + $link.data( 'text-restore', oldLinkText ) |
| 65 | + .text( newLinkText ); |
| 66 | + }; |
| 67 | + |
61 | 68 | component.showSettingAndChangeLinkText = function( $link ) {
|
62 | 69 | var $settingDisplay, settingId;
|
63 | 70 | $settingDisplay = component.getSettingDisplay( $link );
|
64 | 71 | settingId = component.getSettingId( $link );
|
65 | 72 |
|
66 |
| - $link.text( linkText[ 0 ] ) |
67 |
| - .data( dataSlug, linkActions[ 0 ] ); |
| 73 | + $link.data( dataSlug, linkActions[ 0 ] ); |
| 74 | + component.changeLinkText( $link ); |
68 | 75 | component.removeHiddenInputWithValue( settingId );
|
69 | 76 | $settingDisplay.removeClass( 'snapshot-setting-removed' );
|
70 | 77 | };
|
|
73 | 80 | $( 'input[name="' + inputName + '"][value="' + settingId + '"]' ).remove();
|
74 | 81 | };
|
75 | 82 |
|
76 |
| - $( linkSelector ).on( 'click', function( event ) { |
| 83 | + $linkToRemoveOrRestore.on( 'click', function( event ) { |
77 | 84 | var $clickedLink = $( this );
|
78 | 85 |
|
79 | 86 | event.preventDefault();
|
|
0 commit comments