PluginProbe
Search & Replace Everything by WPCode – Find and Replace Media, Text, Links, and More / 1.0.6
Search & Replace Everything by WPCode – Find and Replace Media, Text, Links, and More v1.0.6
trunk 1.0.0 1.0.1 1.0.10 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9
search-replace-wpcode / src / connect.js

connect.js in Search & Replace Everything by WPCode – Find and Replace Media, Text, Links, and More 1.0.6, at src/connect.js

214 lines 3.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /* global wpcode ajaxurl */
2
3 import jconfirm from 'jquery-confirm';
4
5 /**
6 * Connect functionality.
7 *
8 * @since 2.0.9
9 */
10
11 'use strict';
12
13 var WSRWConnect = window.WSRWConnect || (
14 function ( document, window, $ ) {
15
16 // jquery-confirm defaults.
17 jconfirm.defaults = {
18 closeIcon: true,
19 closeIconClass: 'close-icon-svg',
20 backgroundDismiss: false,
21 escapeKey: true,
22 animationBounce: 1,
23 useBootstrap: false,
24 theme: 'modern',
25 boxWidth: '400px',
26 type: 'blue',
27 animateFromElement: false,
28 };
29 /**
30 * Elements reference.
31 *
32 * @since 2.0.9
33 *
34 * @type {object}
35 */
36 var el = {
37 $connectBtn: $( '#wsrw-settings-connect-btn' ), $connectKey: $( '#wsrw-settings-upgrade-license-key' ),
38 };
39
40 /**
41 * Public functions and properties.
42 *
43 * @since 2.0.9
44 *
45 * @type {object}
46 */
47 var app = {
48
49 /**
50 * Start the engine.
51 *
52 * @since 2.0.9
53 */
54 init: function () {
55 console.log( 'WSRWConnect: init' );
56
57 $( app.ready );
58 },
59
60 /**
61 * Document ready.
62 *
63 * @since 2.0.9
64 */
65 ready: function () {
66
67 app.events();
68 },
69
70 /**
71 * Register JS events.
72 *
73 * @since 2.0.9
74 */
75 events: function () {
76
77 app.connectBtnClick();
78 },
79
80 /**
81 * Register connect button event.
82 *
83 * @since 2.0.9
84 */
85 connectBtnClick: function () {
86
87 el.$connectBtn.on(
88 'click',
89 function () {
90 WSRSpinner.show_button_spinner( $(this) );
91 app.gotoUpgradeUrl();
92 }
93 );
94 },
95
96 /**
97 * Get the alert arguments in case of Pro already installed.
98 *
99 * @since 2.0.9
100 *
101 * @param {object} res Ajax query result object.
102 *
103 * @returns {object} Alert arguments.
104 */
105 proAlreadyInstalled: function ( res ) {
106
107 $.confirm( {
108 title: wsrwjs.almost_done,
109 content: res.data.message,
110 type: 'blue',
111 icon: 'fa fa-exclamation-circle',
112 animateFromElement: false,
113 buttons: {
114 confirm: {
115 text: wsrwjs.plugin_activate_btn,
116 btnClass: 'btn-confirm',
117 keys: ['enter'],
118 },
119 },
120 onAction: function ( action ) {
121 if ( action === 'confirm' ) {
122 window.location.reload();
123 }
124 },
125 } );
126
127
128 },
129
130 /**
131 * Go to upgrade url.
132 *
133 * @since 2.0.9
134 */
135 gotoUpgradeUrl: function () {
136
137 var data = {
138 action: 'wsrw_connect_url', key: el.$connectKey.val(), _wpnonce: wsrwjs.nonce,
139 };
140
141 $.post( ajaxurl, data ).done(
142 function ( res ) {
143 if ( res.success ) {
144 if ( res.data.reload ) {
145 app.proAlreadyInstalled( res );
146 return;
147 }
148 window.location.href = res.data.url;
149 return;
150 }
151
152 $.confirm( {
153 title: wsrwjs.oops,
154 content: res.data.message,
155 type: 'blue',
156 icon: 'fa fa-exclamation-circle',
157 animateFromElement: false,
158 buttons: {
159 confirm: {
160 text: wsrwjs.ok,
161 btnClass: 'btn-confirm',
162 keys: ['enter'],
163 },
164 },
165 } );
166
167 }
168 ).fail(
169 function ( xhr ) {
170 app.failAlert( xhr );
171 }
172 ).always(
173 function () {
174 WSRSpinner.hide_button_spinner( el.$connectBtn );
175 }
176 );
177 },
178
179 /**
180 * Alert in case of server error.
181 *
182 * @since 2.0.9
183 *
184 * @param {object} xhr XHR object.
185 */
186 failAlert: function ( xhr ) {
187
188 $.confirm( {
189 title: wsrwjs.oops,
190 content: wsrwjs.server_error + '<br>' + xhr.status + ' ' + xhr.statusText + ' ' + xhr.responseText,
191 type: 'blue',
192 icon: 'fa fa-exclamation-circle',
193 animateFromElement: false,
194 buttons: {
195 confirm: {
196 text: wsrwjs.ok,
197 btnClass: 'btn-confirm',
198 keys: ['enter'],
199 },
200 },
201 } );
202
203 },
204 };
205
206 // Provide access to public functions/properties.
207 return app;
208
209 }( document, window, jQuery )
210 );
211
212 // Initialize.
213 WSRWConnect.init();
214