|
1 | 1 | /* global jQuery, document, redux, ajaxurl */ |
2 | 2 |
|
3 | | -(function( $ ) { |
| 3 | +(function ($) { |
4 | 4 | 'use strict'; |
5 | 5 |
|
6 | 6 | redux.field_objects = redux.field_objects || {}; |
7 | 7 | redux.field_objects.import_export = redux.field_objects.import_export || {}; |
8 | 8 |
|
9 | | - redux.field_objects.import_export.copy_text = function( $text ) { |
10 | | - var copyFrom = document.createElement( 'textarea' ); |
11 | | - document.body.appendChild( copyFrom ); |
| 9 | + redux.field_objects.import_export.copy_text = function ($text) { |
| 10 | + var copyFrom = document.createElement('textarea'); |
| 11 | + document.body.appendChild(copyFrom); |
12 | 12 | copyFrom.textContent = $text; |
13 | 13 | copyFrom.select(); |
14 | | - document.execCommand( 'copy' ); |
| 14 | + document.execCommand('copy'); |
15 | 15 | copyFrom.remove(); |
16 | 16 | }; |
17 | 17 |
|
18 | | - redux.field_objects.import_export.get_options = function( $secret ) { |
19 | | - var $el = $( '#redux-export-code-copy' ); |
| 18 | + redux.field_objects.import_export.get_options = function ($secret) { |
| 19 | + var $el = $('#redux-export-code-copy'); |
20 | 20 | var url = ajaxurl + '?download=0&action=redux_download_options-' + redux.optName.args.opt_name + '&secret=' + $secret; |
21 | | - $el.addClass( 'disabled' ).attr( 'disabled', 'disabled' ); |
22 | | - $el.text( $el.data( 'copy' ) ); |
23 | | - $.get( url, function( data ) { |
24 | | - redux.field_objects.import_export.copy_text( data ); |
25 | | - $el.removeClass( 'disabled' ); |
26 | | - $el.text( $el.data( 'copied' ) ); |
27 | | - setTimeout( function() { |
28 | | - $el.text( $el.data( 'copy' ) ).removeClass( 'disabled' ).removeAttr( 'disabled' ); |
29 | | - }, 2000 ); |
30 | | - } ); |
| 21 | + $el.addClass('disabled').attr('disabled', 'disabled'); |
| 22 | + $el.text($el.data('copy')); |
| 23 | + $.get(url, function (data) { |
| 24 | + redux.field_objects.import_export.copy_text(data); |
| 25 | + $el.removeClass('disabled'); |
| 26 | + $el.text($el.data('copied')); |
| 27 | + setTimeout(function () { |
| 28 | + $el.text($el.data('copy')).removeClass('disabled').removeAttr('disabled'); |
| 29 | + }, 2000); |
| 30 | + }); |
31 | 31 | }; |
32 | 32 |
|
33 | | - redux.field_objects.import_export.init = function( selector ) { |
34 | | - selector = $.redux.getSelector( selector, 'import_export' ); |
| 33 | + redux.field_objects.import_export.init = function (selector) { |
| 34 | + selector = $.redux.getSelector(selector, 'import_export'); |
35 | 35 |
|
36 | | - $( selector ).each( |
37 | | - function() { |
| 36 | + $(selector).each( |
| 37 | + function () { |
38 | 38 | var textBox1; |
39 | 39 | var textBox2; |
40 | 40 |
|
41 | | - var el = $( this ); |
| 41 | + var el = $(this); |
42 | 42 | var parent = el; |
43 | 43 |
|
44 | | - if ( ! el.hasClass( 'redux-field-container' ) ) { |
45 | | - parent = el.parents( '.redux-field-container:first' ); |
| 44 | + if (!el.hasClass('redux-field-container')) { |
| 45 | + parent = el.parents('.redux-field-container:first'); |
46 | 46 | } |
47 | 47 |
|
48 | | - if ( parent.is( ':hidden' ) ) { |
| 48 | + if (parent.is(':hidden')) { |
49 | 49 | return; |
50 | 50 | } |
51 | 51 |
|
52 | | - if ( parent.hasClass( 'redux-field-init' ) ) { |
53 | | - parent.removeClass( 'redux-field-init' ); |
| 52 | + if (parent.hasClass('redux-field-init')) { |
| 53 | + parent.removeClass('redux-field-init'); |
54 | 54 | } else { |
55 | 55 | return; |
56 | 56 | } |
57 | 57 |
|
58 | 58 | el.each( |
59 | | - function() { |
60 | | - $( '#redux-import' ).click( |
61 | | - function( e ) { |
62 | | - if ( '' === $( '#import-code-value' ).val() && '' === $( |
63 | | - '#import-link-value' ).val() ) { |
| 59 | + function () { |
| 60 | + $('#redux-import').click( |
| 61 | + function (e) { |
| 62 | + if ('' === $('#import-code-value').val() && '' === $( |
| 63 | + '#import-link-value').val()) { |
64 | 64 | e.preventDefault(); |
65 | 65 | return false; |
66 | 66 | } |
67 | 67 | } |
68 | 68 | ); |
69 | 69 |
|
70 | | - $( this ).find( '#redux-import-code-button' ).click( |
71 | | - function() { |
72 | | - var $el = $( '#redux-import-code-wrapper' ); |
73 | | - if ( $( '#redux-import-link-wrapper' ).is( ':visible' ) ) { |
74 | | - $( '#import-link-value' ).val( '' ); |
75 | | - $( '#redux-import-link-wrapper' ).fadeOut( |
| 70 | + $(this).find('#redux-import-code-button').click( |
| 71 | + function () { |
| 72 | + var $el = $('#redux-import-code-wrapper'); |
| 73 | + if ($('#redux-import-link-wrapper').is(':visible')) { |
| 74 | + $('#import-link-value').val(''); |
| 75 | + $('#redux-import-link-wrapper').fadeOut( |
76 | 76 | 'fast', |
77 | | - function() { |
| 77 | + function () { |
78 | 78 | $el.fadeIn( |
79 | 79 | 'fast', |
80 | | - function() { |
81 | | - $( '#import-code-value' ).focus(); |
| 80 | + function () { |
| 81 | + $('#import-code-value').focus(); |
82 | 82 | } |
83 | 83 | ); |
84 | 84 | } |
85 | 85 | ); |
86 | 86 | } else { |
87 | | - if ( $el.is( ':visible' ) ) { |
| 87 | + if ($el.is(':visible')) { |
88 | 88 | $el.fadeOut(); |
89 | 89 | } else { |
90 | 90 | $el.fadeIn( |
91 | 91 | 'medium', |
92 | | - function() { |
93 | | - $( '#import-code-value' ).focus(); |
| 92 | + function () { |
| 93 | + $('#import-code-value').focus(); |
94 | 94 | } |
95 | 95 | ); |
96 | 96 | } |
97 | 97 | } |
98 | 98 | } |
99 | 99 | ); |
100 | 100 |
|
101 | | - $( this ).find( '#redux-import-link-button' ).click( |
102 | | - function() { |
103 | | - var $el = $( '#redux-import-link-wrapper' ); |
104 | | - if ( $( '#redux-import-code-wrapper' ).is( ':visible' ) ) { |
105 | | - $( '#import-code-value' ).text( '' ); |
106 | | - $( '#redux-import-code-wrapper' ).fadeOut( |
| 101 | + $(this).find('#redux-import-link-button').click( |
| 102 | + function () { |
| 103 | + var $el = $('#redux-import-link-wrapper'); |
| 104 | + if ($('#redux-import-code-wrapper').is(':visible')) { |
| 105 | + $('#import-code-value').text(''); |
| 106 | + $('#redux-import-code-wrapper').fadeOut( |
107 | 107 | 'fast', |
108 | | - function() { |
| 108 | + function () { |
109 | 109 | $el.fadeIn( |
110 | 110 | 'fast', |
111 | | - function() { |
112 | | - $( '#import-link-value' ).focus(); |
| 111 | + function () { |
| 112 | + $('#import-link-value').focus(); |
113 | 113 | } |
114 | 114 | ); |
115 | 115 | } |
116 | 116 | ); |
117 | 117 | } else { |
118 | | - if ( $el.is( ':visible' ) ) { |
| 118 | + if ($el.is(':visible')) { |
119 | 119 | $el.fadeOut(); |
120 | 120 | } else { |
121 | 121 | $el.fadeIn( |
122 | 122 | 'medium', |
123 | | - function() { |
124 | | - $( '#import-link-value' ).focus(); |
| 123 | + function () { |
| 124 | + $('#import-link-value').focus(); |
125 | 125 | } |
126 | 126 | ); |
127 | 127 | } |
128 | 128 | } |
129 | 129 | } |
130 | 130 | ); |
131 | | - $( this ).find( '#redux-export-code-dl' ).click( function( e ) { |
| 131 | + $(this).find('#redux-export-code-dl').click(function (e) { |
132 | 132 | e.preventDefault(); |
133 | 133 |
|
134 | | - if ( !! window.onbeforeunload ) { |
135 | | - if ( confirm( 'Your panel has unchanged values, would you like to save them now?' ) ) { |
136 | | - $( '#redux_top_save' ).click(); |
137 | | - setTimeout( function() { |
138 | | - window.open( $( this ).attr( 'href' ) ); |
139 | | - }, 2000 ); |
| 134 | + if (!!window.onbeforeunload) { |
| 135 | + if (confirm('Your panel has unchanged values, would you like to save them now?')) { |
| 136 | + $('#redux_top_save').click(); |
| 137 | + setTimeout(function () { |
| 138 | + window.open($(this).attr('href')); |
| 139 | + }, 2000); |
140 | 140 | } |
141 | 141 | } else { |
142 | | - window.open( $( this ).attr( 'href' ) ); |
| 142 | + window.open($(this).attr('href')); |
143 | 143 | } |
144 | | - } ); |
145 | | - $( this ).find( '#redux-export-code-copy' ).click( |
146 | | - function( e ) { |
147 | | - var $el = $( '#redux-export-code' ); |
148 | | - var $secret = $( this ).data( 'secret' ); |
| 144 | + }); |
| 145 | + $(this).find('#redux-import-upload').click(function () { |
| 146 | + $('#redux-import-upload-file').click(); |
| 147 | + }) |
| 148 | + |
| 149 | + document.getElementById('redux-import-upload-file').addEventListener('change', function () { |
| 150 | + var file_to_read = document.getElementById('redux-import-upload-file').files[0]; |
| 151 | + var fileread = new FileReader(); |
| 152 | + fileread.onload = function (e) { |
| 153 | + var content = e.target.result; |
| 154 | + // console.log(content); |
| 155 | + $(this).find('#import-code-value').text(content); |
| 156 | + $(this).find('#redux-import').click(); |
| 157 | + }; |
| 158 | + fileread.readAsText(file_to_read); |
| 159 | + }); |
| 160 | + $(this).find('#redux-export-code-copy').click( |
| 161 | + function (e) { |
| 162 | + var $el = $('#redux-export-code'); |
| 163 | + var $secret = $(this).data('secret'); |
149 | 164 | e.preventDefault(); |
150 | | - if ( !! window.onbeforeunload ) { |
151 | | - if ( confirm( |
152 | | - 'Your panel has unchanged values, would you like to save them now?' ) ) { |
153 | | - $( '#redux_top_save' ).click(); |
154 | | - setTimeout( function() { |
155 | | - redux.field_objects.import_export.get_options( $secret, $el ); |
156 | | - }, 2000 ); |
| 165 | + if (!!window.onbeforeunload) { |
| 166 | + if (confirm( |
| 167 | + 'Your panel has unchanged values, would you like to save them now?')) { |
| 168 | + $('#redux_top_save').click(); |
| 169 | + setTimeout(function () { |
| 170 | + redux.field_objects.import_export.get_options($secret, $el); |
| 171 | + }, 2000); |
157 | 172 | } |
158 | 173 | } else { |
159 | | - redux.field_objects.import_export.get_options( $secret, $el ); |
| 174 | + redux.field_objects.import_export.get_options($secret, $el); |
160 | 175 | } |
161 | 176 | } |
162 | 177 | ); |
163 | | - $( this ).find( 'textarea' ).focusout( |
164 | | - function() { |
165 | | - var $id = $( this ).attr( 'id' ); |
166 | | - var $el = $( this ); |
| 178 | + $(this).find('textarea').focusout( |
| 179 | + function () { |
| 180 | + var $id = $(this).attr('id'); |
| 181 | + var $el = $(this); |
167 | 182 | var $container = $el; |
168 | 183 |
|
169 | | - if ( 'import-link-value' === $id || 'import-code-value' === $id ) { |
170 | | - $container = $( this ).parent(); |
| 184 | + if ('import-link-value' === $id || 'import-code-value' === $id) { |
| 185 | + $container = $(this).parent(); |
171 | 186 | } |
172 | 187 |
|
173 | 188 | $container.fadeOut( |
174 | 189 | 'medium', |
175 | | - function() { |
176 | | - if ( 'redux-export-link-value' !== $id ) { |
177 | | - $el.text( '' ); |
| 190 | + function () { |
| 191 | + if ('redux-export-link-value' !== $id) { |
| 192 | + $el.text(''); |
178 | 193 | } |
179 | 194 | } |
180 | 195 | ); |
181 | 196 | } |
182 | 197 | ); |
183 | 198 |
|
184 | | - $( this ).find( '#redux-export-link' ).click( |
185 | | - function() { |
186 | | - var $el = $( this ); |
187 | | - $el.addClass( 'disabled' ).attr( 'disabled', 'disabled' ); |
188 | | - $el.text( $el.data( 'copy' ) ); |
189 | | - redux.field_objects.import_export.copy_text( $el.data( 'url' ) ); |
190 | | - $el.removeClass( 'disabled' ); |
191 | | - $el.text( $el.data( 'copied' ) ); |
192 | | - setTimeout( function() { |
193 | | - $el.text( $el.data( 'copy' ) ).removeClass( 'disabled' ).removeAttr( 'disabled' ); |
194 | | - }, 2000 ); |
| 199 | + $(this).find('#redux-export-link').click( |
| 200 | + function () { |
| 201 | + var $el = $(this); |
| 202 | + $el.addClass('disabled').attr('disabled', 'disabled'); |
| 203 | + $el.text($el.data('copy')); |
| 204 | + redux.field_objects.import_export.copy_text($el.data('url')); |
| 205 | + $el.removeClass('disabled'); |
| 206 | + $el.text($el.data('copied')); |
| 207 | + setTimeout(function () { |
| 208 | + $el.text($el.data('copy')).removeClass('disabled').removeAttr('disabled'); |
| 209 | + }, 2000); |
195 | 210 | } |
196 | 211 | ); |
197 | 212 |
|
198 | | - textBox1 = document.getElementById( 'redux-export-code' ); |
| 213 | + textBox1 = document.getElementById('redux-export-code'); |
199 | 214 |
|
200 | | - textBox1.onfocus = function() { |
| 215 | + textBox1.onfocus = function () { |
201 | 216 | textBox1.select(); |
202 | 217 |
|
203 | 218 | // Work around Chrome's little problem. |
204 | | - textBox1.onmouseup = function() { |
| 219 | + textBox1.onmouseup = function () { |
205 | 220 |
|
206 | 221 | // Prevent further mouseup intervention. |
207 | 222 | textBox1.onmouseup = null; |
208 | 223 | return false; |
209 | 224 | }; |
210 | 225 | }; |
211 | 226 |
|
212 | | - textBox2 = document.getElementById( 'import-code-value' ); |
| 227 | + textBox2 = document.getElementById('import-code-value'); |
213 | 228 |
|
214 | | - textBox2.onfocus = function() { |
| 229 | + textBox2.onfocus = function () { |
215 | 230 | textBox2.select(); |
216 | 231 |
|
217 | 232 | // Work around Chrome's little problem. |
218 | | - textBox2.onmouseup = function() { |
| 233 | + textBox2.onmouseup = function () { |
219 | 234 |
|
220 | 235 | // Prevent further mouseup intervention. |
221 | 236 | textBox2.onmouseup = null; |
|
228 | 243 | } |
229 | 244 | ); |
230 | 245 | }; |
231 | | -})( jQuery ); |
| 246 | +})(jQuery); |
| 247 | + |
| 248 | + |
0 commit comments