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