gutenberg
4 years ago
admin.js
4 years ago
admin.min.js
4 years ago
deactivation-feedback.js
3 years ago
deactivation-feedback.min.js
3 years ago
editor.js
8 years ago
editor.min.js
5 years ago
evf-admin-email.js
3 years ago
evf-admin-email.min.js
3 years ago
evf-clipboard.js
8 years ago
evf-clipboard.min.js
8 years ago
evf-enhanced-select.js
3 years ago
evf-enhanced-select.min.js
3 years ago
evf-file-uploader.js
3 years ago
evf-file-uploader.min.js
3 years ago
evf-setup.js
3 years ago
evf-setup.min.js
3 years ago
extensions.js
4 years ago
extensions.min.js
4 years ago
form-builder.js
3 years ago
form-builder.min.js
3 years ago
form-template-controller.js
3 years ago
form-template-controller.min.js
3 years ago
settings.js
4 years ago
settings.min.js
4 years ago
tools.js
4 years ago
tools.min.js
4 years ago
upgrade.js
5 years ago
upgrade.min.js
5 years ago
extensions.js
319 lines
| 1 | ( function( $, wp ) { |
| 2 | var $document = $( document ); |
| 3 | __ = wp.i18n.__, |
| 4 | _x = wp.i18n._x, |
| 5 | sprintf = wp.i18n.sprintf; |
| 6 | |
| 7 | /** |
| 8 | * Sends an Ajax request to the server to install a extension. |
| 9 | * |
| 10 | * @since 4.6.0 |
| 11 | * |
| 12 | * @param {object} args Arguments. |
| 13 | * @param {string} args.slug Plugin identifier in the WordPress.org Plugin repository. |
| 14 | * @param {installExtensionSuccess=} args.success Optional. Success callback. Default: wp.updates.installPluginSuccess |
| 15 | * @param {installExtensionError=} args.error Optional. Error callback. Default: wp.updates.installPluginError |
| 16 | * @return {$.promise} A jQuery promise that represents the request, |
| 17 | * decorated with an abort() method. |
| 18 | */ |
| 19 | wp.updates.installExtension = function( args ) { |
| 20 | var $card = $( '.plugin-card-' + args.slug ), |
| 21 | $message = $card.find( '.install-now, .activate-now' ); |
| 22 | |
| 23 | args = _.extend( { |
| 24 | success: wp.updates.installExtensionSuccess, |
| 25 | error: wp.updates.installExtensionError |
| 26 | }, args ); |
| 27 | |
| 28 | if ( $message.html() !== __( 'Installing...' ) ) { |
| 29 | $message.data( 'originaltext', $message.html() ); |
| 30 | } |
| 31 | |
| 32 | $message |
| 33 | .addClass( 'updating-message' ) |
| 34 | .attr( |
| 35 | 'aria-label', |
| 36 | sprintf( |
| 37 | /* translators: %s: Plugin name and version. */ |
| 38 | _x( 'Installing %s...', 'everest-forms' ), |
| 39 | $message.data( 'name' ) |
| 40 | ) |
| 41 | ) |
| 42 | .text( __( 'Installing...' ) ); |
| 43 | |
| 44 | wp.a11y.speak( __( 'Installing... please wait.' ), 'polite' ); |
| 45 | |
| 46 | // Remove previous error messages, if any. |
| 47 | $card.removeClass( 'plugin-card-install-failed' ).find( '.notice.notice-error' ).remove(); |
| 48 | |
| 49 | $document.trigger( 'wp-extension-installing', args ); |
| 50 | |
| 51 | return wp.updates.ajax( 'everest_forms_install_extension', args ); |
| 52 | }; |
| 53 | |
| 54 | /** |
| 55 | * Updates the UI appropriately after a successful extension install. |
| 56 | * |
| 57 | * @since 4.6.0 |
| 58 | * |
| 59 | * @typedef {object} installPluginSuccess |
| 60 | * @param {object} response Response from the server. |
| 61 | * @param {string} response.slug Slug of the installed plugin. |
| 62 | * @param {string} response.pluginName Name of the installed plugin. |
| 63 | * @param {string} response.activateUrl URL to activate the just installed plugin. |
| 64 | */ |
| 65 | wp.updates.installExtensionSuccess = function( response ) { |
| 66 | if ( 'everest-forms_page_evf-builder' === pagenow ) { |
| 67 | var $pluginRow = $( 'tr[data-slug="' + response.slug + '"]' ).removeClass( 'install' ).addClass( 'installed' ), |
| 68 | $updateMessage = $pluginRow.find( '.plugin-status span' ); |
| 69 | |
| 70 | $updateMessage |
| 71 | .removeClass( 'updating-message install-now' ) |
| 72 | .addClass( 'updated-message active' ) |
| 73 | .attr( |
| 74 | 'aria-label', |
| 75 | sprintf( |
| 76 | /* translators: %s: Plugin name and version. */ |
| 77 | _x( '%s installed!', 'everest-forms' ), |
| 78 | response.pluginName |
| 79 | ) |
| 80 | ) |
| 81 | .text( _x( 'Installed!', 'plugin' ) ); |
| 82 | |
| 83 | wp.a11y.speak( __( 'Installation completed successfully.' ), 'polite' ); |
| 84 | |
| 85 | |
| 86 | $document.trigger( 'wp-plugin-bulk-install-success', response ); |
| 87 | |
| 88 | } else { |
| 89 | var $message = $( '.plugin-card-' + response.slug ).find( '.install-now' ), |
| 90 | $status = $( '.plugin-card-' + response.slug ).find( '.status-label' ); |
| 91 | |
| 92 | $message |
| 93 | .removeClass( 'updating-message' ) |
| 94 | .addClass( 'updated-message installed button-disabled' ) |
| 95 | .attr( |
| 96 | 'aria-label', |
| 97 | sprintf( |
| 98 | /* translators: %s: Plugin name and version. */ |
| 99 | _x( '%s installed!', 'everest-forms' ), |
| 100 | response.pluginName |
| 101 | ) |
| 102 | ) |
| 103 | .text( _x( 'Installed!', 'everest-forms' ) ); |
| 104 | |
| 105 | wp.a11y.speak( __( 'Installation completed successfully.' ), 'polite' ); |
| 106 | |
| 107 | $document.trigger( 'wp-plugin-install-success', response ); |
| 108 | |
| 109 | if ( response.activateUrl ) { |
| 110 | setTimeout( function() { |
| 111 | $status.removeClass( 'status-install-now' ).addClass( 'status-active' ).text( wp.updates.l10n.pluginInstalled ); |
| 112 | |
| 113 | // Transform the 'Install' button into an 'Activate' button. |
| 114 | $message.removeClass( 'install-now installed button-disabled updated-message' ) |
| 115 | .addClass( 'activate-now button-primary' ) |
| 116 | .attr( 'href', response.activateUrl ); |
| 117 | |
| 118 | if ( 'plugins-network' === pagenow ) { |
| 119 | $message |
| 120 | .attr( |
| 121 | 'aria-label', |
| 122 | sprintf( |
| 123 | /* translators: %s: Plugin name. */ |
| 124 | _x( 'Network Activate %s', 'everest-forms' ), |
| 125 | response.pluginName |
| 126 | ) |
| 127 | ) |
| 128 | .text( __( 'Network Activate' ) ); |
| 129 | } else { |
| 130 | $message |
| 131 | .attr( |
| 132 | 'aria-label', |
| 133 | sprintf( |
| 134 | /* translators: %s: Plugin name. */ |
| 135 | _x( 'Activate %s', 'everest-forms' ), |
| 136 | response.pluginName |
| 137 | ) |
| 138 | ) |
| 139 | .text( __( 'Activate' ) ); |
| 140 | } |
| 141 | }, 1000 ); |
| 142 | } |
| 143 | } |
| 144 | }; |
| 145 | |
| 146 | /** |
| 147 | * Updates the UI appropriately after a failed extension install. |
| 148 | * |
| 149 | * @since 4.6.0 |
| 150 | * |
| 151 | * @typedef {object} installExtensionError |
| 152 | * @param {object} response Response from the server. |
| 153 | * @param {string} response.slug Slug of the plugin to be installed. |
| 154 | * @param {string=} response.pluginName Optional. Name of the plugin to be installed. |
| 155 | * @param {string} response.errorCode Error code for the error that occurred. |
| 156 | * @param {string} response.errorMessage The error that occurred. |
| 157 | */ |
| 158 | wp.updates.installExtensionError = function( response ) { |
| 159 | if ( 'everest-forms_page_evf-builder' === pagenow ) { |
| 160 | var $pluginRow = $( 'tr[data-slug="' + response.slug + '"]' ), |
| 161 | $updateMessage = $pluginRow.find( '.plugin-status span' ), |
| 162 | errorMessage; |
| 163 | |
| 164 | if ( ! wp.updates.isValidResponse( response, 'install' ) ) { |
| 165 | return; |
| 166 | } |
| 167 | |
| 168 | if ( wp.updates.maybeHandleCredentialError( response, 'install-plugin' ) ) { |
| 169 | return; |
| 170 | } |
| 171 | |
| 172 | errorMessage = sprintf( |
| 173 | /* translators: %s: Error string for a failed installation. */ |
| 174 | __( 'Installation failed: %s' ), |
| 175 | response.errorMessage |
| 176 | ); |
| 177 | |
| 178 | $updateMessage |
| 179 | .removeClass( 'updating-message' ) |
| 180 | .addClass( 'updated-message' ) |
| 181 | .attr( |
| 182 | 'aria-label', |
| 183 | sprintf( |
| 184 | /* translators: %s: Plugin name and version. */ |
| 185 | _x( '%s installation failed', 'everest-forms' ), |
| 186 | $button.data( 'name' ) |
| 187 | ) |
| 188 | ) |
| 189 | .text( __( 'Installation Failed!' ) ); |
| 190 | |
| 191 | wp.a11y.speak( errorMessage, 'assertive' ); |
| 192 | |
| 193 | $document.trigger( 'wp-plugin-bulk-install-error', response ); |
| 194 | } else { |
| 195 | var $card = $( '.plugin-card-' + response.slug ), |
| 196 | $button = $card.find( '.install-now' ), |
| 197 | errorMessage; |
| 198 | |
| 199 | if ( ! wp.updates.isValidResponse( response, 'install' ) ) { |
| 200 | return; |
| 201 | } |
| 202 | |
| 203 | if ( wp.updates.maybeHandleCredentialError( response, 'everest_forms_install_extension' ) ) { |
| 204 | return; |
| 205 | } |
| 206 | |
| 207 | errorMessage = sprintf( |
| 208 | /* translators: %s: Error string for a failed installation. */ |
| 209 | __( 'Installation failed: %s' ), |
| 210 | response.errorMessage |
| 211 | ); |
| 212 | |
| 213 | $card |
| 214 | .addClass( 'plugin-card-update-failed' ) |
| 215 | .append( '<div class="notice notice-error notice-alt is-dismissible"><p>' + errorMessage + '</p></div>' ); |
| 216 | |
| 217 | $card.on( 'click', '.notice.is-dismissible .notice-dismiss', function() { |
| 218 | |
| 219 | // Use same delay as the total duration of the notice fadeTo + slideUp animation. |
| 220 | setTimeout( function() { |
| 221 | $card |
| 222 | .removeClass( 'plugin-card-update-failed' ) |
| 223 | .find( '.column-name a' ).focus(); |
| 224 | }, 200 ); |
| 225 | } ); |
| 226 | |
| 227 | $button |
| 228 | .removeClass( 'updating-message' ).addClass( 'button-disabled' ) |
| 229 | .attr( |
| 230 | 'aria-label', |
| 231 | sprintf( |
| 232 | /* translators: %s: Plugin name and version. */ |
| 233 | _x( '%s installation failed', 'everest-forms' ), |
| 234 | $button.data( 'name' ) |
| 235 | ) |
| 236 | ) |
| 237 | .text( __( 'Installation Failed!' ) ); |
| 238 | |
| 239 | wp.a11y.speak( errorMessage, 'assertive' ); |
| 240 | |
| 241 | $document.trigger( 'wp-plugin-install-error', response ); |
| 242 | } |
| 243 | }; |
| 244 | |
| 245 | /** |
| 246 | * Pulls available jobs from the queue and runs them. |
| 247 | * @see https://core.trac.wordpress.org/ticket/39364 |
| 248 | */ |
| 249 | wp.updates.queueChecker = function() { |
| 250 | var job; |
| 251 | |
| 252 | if ( wp.updates.ajaxLocked || ! wp.updates.queue.length ) { |
| 253 | return; |
| 254 | } |
| 255 | |
| 256 | job = wp.updates.queue.shift(); |
| 257 | |
| 258 | // Handle a queue job. |
| 259 | switch ( job.action ) { |
| 260 | case 'everest_forms_install_extension': |
| 261 | wp.updates.installExtension( job.data ); |
| 262 | break; |
| 263 | |
| 264 | default: |
| 265 | break; |
| 266 | } |
| 267 | |
| 268 | // Handle a queue job. |
| 269 | $document.trigger( 'wp-updates-queue-job', job ); |
| 270 | }; |
| 271 | |
| 272 | $( function() { |
| 273 | var $pluginFilter = $( '#extension-filter' ); |
| 274 | |
| 275 | /** |
| 276 | * Click handler for extension installs. |
| 277 | * |
| 278 | * @param {Event} event Event interface. |
| 279 | */ |
| 280 | $pluginFilter.on( 'click', '.extension-install .install-now', function( event ) { |
| 281 | var $button = $( event.target ), |
| 282 | pluginName = $( this ).data( 'name' ); |
| 283 | |
| 284 | event.preventDefault(); |
| 285 | |
| 286 | if ( $button.hasClass( 'updating-message' ) || $button.hasClass( 'button-disabled' ) ) { |
| 287 | return; |
| 288 | } |
| 289 | |
| 290 | if ( wp.updates.shouldRequestFilesystemCredentials && ! wp.updates.ajaxLocked ) { |
| 291 | wp.updates.requestFilesystemCredentials( event ); |
| 292 | |
| 293 | $document.on( 'credential-modal-cancel', function() { |
| 294 | var $message = $( '.install-now.updating-message' ); |
| 295 | |
| 296 | $message |
| 297 | .removeClass( 'updating-message' ) |
| 298 | .attr( |
| 299 | 'aria-label', |
| 300 | sprintf( |
| 301 | /* translators: %s: Plugin name. */ |
| 302 | _x( 'Install %s now', 'everest-forms' ), |
| 303 | pluginName |
| 304 | ) |
| 305 | ) |
| 306 | .text( __( 'Install Now' ) ); |
| 307 | |
| 308 | wp.a11y.speak( __( 'Update canceled.' ), 'polite' ); |
| 309 | } ); |
| 310 | } |
| 311 | |
| 312 | wp.updates.installExtension( { |
| 313 | name: pluginName, |
| 314 | slug: $button.data( 'slug' ) |
| 315 | } ); |
| 316 | } ); |
| 317 | } ); |
| 318 | })( jQuery, window.wp ); |
| 319 |