Astra Starter Sites - Version 1.0.11

Version Description

Download this release

Release Info

Developer Nikschavan
Plugin Icon Astra Starter Sites
Version 1.0.11
Comparing to
See all releases

Code changes from version 1.0.10 to 1.0.11

astra-sites.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: Astra Sites - Lite
4
  * Plugin URI: http://www.wpastra.com/pro/
5
  * Description: Import free sites build with Astra theme.
6
- * Version: 1.0.10
7
  * Author: Brainstorm Force
8
  * Author URI: http://www.brainstormforce.com
9
  * Text Domain: astra-sites
@@ -15,7 +15,7 @@
15
  * Set constants.
16
  */
17
  if ( ! defined( 'ASTRA_SITES_VER' ) ) {
18
- define( 'ASTRA_SITES_VER', '1.0.10' );
19
  }
20
 
21
  if ( ! defined( 'ASTRA_SITES_FILE' ) ) {
3
  * Plugin Name: Astra Sites - Lite
4
  * Plugin URI: http://www.wpastra.com/pro/
5
  * Description: Import free sites build with Astra theme.
6
+ * Version: 1.0.11
7
  * Author: Brainstorm Force
8
  * Author URI: http://www.brainstormforce.com
9
  * Text Domain: astra-sites
15
  * Set constants.
16
  */
17
  if ( ! defined( 'ASTRA_SITES_VER' ) ) {
18
+ define( 'ASTRA_SITES_VER', '1.0.11' );
19
  }
20
 
21
  if ( ! defined( 'ASTRA_SITES_FILE' ) ) {
inc/admin/class-astra-sites-page.php CHANGED
@@ -87,8 +87,6 @@ if ( ! class_exists( 'Astra_Sites_Page' ) ) {
87
  if ( isset( $_REQUEST['page'] ) && strpos( $_REQUEST['page'], self::$plugin_slug ) !== false ) {
88
 
89
  // Let extensions hook into saving.
90
- do_action( 'astra_sites_page' );
91
-
92
  self::save_settings();
93
  }
94
 
@@ -108,7 +106,7 @@ if ( ! class_exists( 'Astra_Sites_Page' ) ) {
108
  }
109
 
110
  // Let extensions hook into saving.
111
- do_action( 'astra_sites_page' );
112
  }
113
 
114
  /**
@@ -138,6 +136,23 @@ if ( ! class_exists( 'Astra_Sites_Page' ) ) {
138
  <?php
139
  }
140
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
141
  /**
142
  * Prints HTML content for tabs
143
  *
@@ -149,6 +164,25 @@ if ( ! class_exists( 'Astra_Sites_Page' ) ) {
149
  ?>
150
  <div class="nav-tab-wrapper">
151
  <h1 class='astra-sites-title'> <?php echo esc_html( self::$menu_page_title ); ?> </h1>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
152
  </div><!-- .nav-tab-wrapper -->
153
 
154
  <?php
87
  if ( isset( $_REQUEST['page'] ) && strpos( $_REQUEST['page'], self::$plugin_slug ) !== false ) {
88
 
89
  // Let extensions hook into saving.
 
 
90
  self::save_settings();
91
  }
92
 
106
  }
107
 
108
  // Let extensions hook into saving.
109
+ do_action( 'astra_sites_save_settings' );
110
  }
111
 
112
  /**
136
  <?php
137
  }
138
 
139
+ /**
140
+ * View actions
141
+ *
142
+ * @since 1.0.11
143
+ */
144
+ static public function get_view_actions() {
145
+
146
+ if ( empty( self::$view_actions ) ) {
147
+
148
+ self::$view_actions = apply_filters(
149
+ 'astra_sites_menu_item', array()
150
+ );
151
+ }
152
+
153
+ return self::$view_actions;
154
+ }
155
+
156
  /**
157
  * Prints HTML content for tabs
158
  *
164
  ?>
165
  <div class="nav-tab-wrapper">
166
  <h1 class='astra-sites-title'> <?php echo esc_html( self::$menu_page_title ); ?> </h1>
167
+ <?php
168
+ $view_actions = self::get_view_actions();
169
+
170
+ foreach ( $view_actions as $slug => $data ) {
171
+
172
+ if ( ! $data['show'] ) {
173
+ continue;
174
+ }
175
+
176
+ $url = self::get_page_url( $slug );
177
+
178
+ if ( $slug == self::$parent_page_slug ) {
179
+ update_option( 'astra_parent_page_url', $url );
180
+ }
181
+
182
+ $active = ( $slug == $action ) ? 'nav-tab-active' : '';
183
+ ?>
184
+ <a class='nav-tab <?php echo esc_attr( $active ); ?>' href='<?php echo esc_url( $url ); ?>'> <?php echo esc_html( $data['label'] ); ?> </a>
185
+ <?php } ?>
186
  </div><!-- .nav-tab-wrapper -->
187
 
188
  <?php
inc/admin/view-astra-sites.php CHANGED
@@ -7,10 +7,6 @@
7
 
8
  defined( 'ABSPATH' ) or exit;
9
 
10
- // Enqueue scripts.
11
- wp_enqueue_script( 'astra-sites-admin' );
12
- wp_enqueue_style( 'astra-sites-admin' );
13
-
14
  /**
15
  * Initial Demo List
16
  *
7
 
8
  defined( 'ABSPATH' ) or exit;
9
 
 
 
 
 
10
  /**
11
  * Initial Demo List
12
  *
inc/assets/css/admin.css CHANGED
@@ -1,15 +1,3 @@
1
- .theme-browser .theme.focus .theme-actions,
2
- .theme-browser .theme:focus .theme-actions,
3
- .theme-browser .theme:hover .theme-actions {
4
- -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=100)";
5
- opacity: 1
6
- }
7
- .theme-browser .theme .theme-screenshot:after {
8
- content: "";
9
- display: block;
10
- padding-top: 66.66666%
11
- }
12
-
13
  .wrap .status,
14
  .wrap .demo-type {
15
  position: absolute;
@@ -88,6 +76,7 @@
88
  }
89
  .required-plugins .spinner {
90
  float: none;
 
91
  }
92
 
93
  .expanded .wp-full-overlay-footer {
@@ -225,4 +214,10 @@
225
  }
226
  .astra-site-preview-on {
227
  overflow: hidden;
 
 
 
 
 
 
228
  }
 
 
 
 
 
 
 
 
 
 
 
 
1
  .wrap .status,
2
  .wrap .demo-type {
3
  position: absolute;
76
  }
77
  .required-plugins .spinner {
78
  float: none;
79
+ margin: 0;
80
  }
81
 
82
  .expanded .wp-full-overlay-footer {
214
  }
215
  .astra-site-preview-on {
216
  overflow: hidden;
217
+ }
218
+
219
+ #astra-sites-menu-page .notice {
220
+ margin-left: 0;
221
+ width: auto;
222
+ float: none;
223
  }
inc/assets/js/admin.js CHANGED
@@ -1,826 +1,1131 @@
1
- jQuery(document).ready(function ($) {
2
- resetPagedCount();
 
 
 
 
 
 
 
 
 
3
 
4
- initial_load_demos();
5
- });
6
 
7
- function initial_load_demos() {
8
 
9
- jQuery('body').addClass('loading-content');
 
 
 
 
 
 
 
10
 
11
- jQuery.ajax({
12
- url: astraDemo.ajaxurl,
13
- type: 'POST',
14
- dataType: 'json',
15
- data: {
16
- action : 'astra-list-sites',
17
- paged : '1',
 
18
  },
19
- })
20
- .done(function (demos) {
21
 
22
- jQuery('body').removeClass('loading-content');
23
- jQuery('.filter-count .count').text( demos.sites_count );
 
 
 
 
 
 
24
 
25
- // Has sites?
26
- if ( demos.sites_count > 0 ) {
27
- renderDemoGrid( demos.sites );
28
 
29
- // Something is wrong in API request.
30
- } else {
31
- var template = wp.template('astra-no-demos');
32
- jQuery('.themes').append( template );
33
- }
34
 
35
- })
36
- .fail(function () {
37
- jQuery('body').removeClass('loading-content');
38
- jQuery('.spinner').after('<p class="no-themes" style="display:block;">'+astraDemo.strings.responseError+'</p>');
39
- });
40
- }
41
 
 
42
 
43
- /**
44
- * Enable Demo Import Button.
45
- */
46
- function enable_demo_import_button( type = 'free' ) {
 
47
 
48
- switch( type ) {
 
 
 
 
 
49
 
50
- case 'free':
51
- // Get initial required plugins count.
52
- var remaining = parseInt( astraDemo.requiredPluginsCount ) || 0;
 
53
 
54
- // Enable demo import button.
55
- if( 0 >= remaining ) {
56
 
57
- jQuery('.astra-demo-import')
58
- .removeAttr('data-import')
59
- .addClass('button-primary')
60
- .text( astraDemo.strings.importDemo );
61
- }
62
- break;
63
-
64
- case 'upgrade':
65
- var demo_slug = jQuery('.wp-full-overlay-header').attr('data-demo-slug');
66
-
67
- jQuery('.astra-demo-import')
68
- .addClass('go-pro button-primary')
69
- .removeClass('astra-demo-import')
70
- .attr('target', '_blank')
71
- .attr('href', astraDemo.getUpgradeURL + demo_slug )
72
- .text( astraDemo.getUpgradeText )
73
- .append('<i class="dashicons dashicons-external"></i>');
74
- break;
75
-
76
- default:
77
- var demo_slug = jQuery('.wp-full-overlay-header').attr('data-demo-slug');
78
-
79
- jQuery('.astra-demo-import')
80
- .addClass('go-pro button-primary')
81
- .removeClass('astra-demo-import')
82
- .attr('target', '_blank')
83
- .attr('href', astraDemo.getProURL )
84
- .text( astraDemo.getProText )
85
- .append('<i class="dashicons dashicons-external"></i>');
86
- break;
87
- }
88
-
89
- }
90
-
91
- function resetPagedCount() {
92
- categoryId = jQuery('.astra-category.filter-links li .current').data('id');
93
- jQuery('body').attr('data-astra-demo-paged', '1');
94
- jQuery('body').attr('data-astra-site-category', categoryId);
95
- jQuery('body').attr('data-astra-demo-search', '');
96
- jQuery('body').attr('data-scrolling', false);
97
- jQuery('body').attr( 'data-required-plugins', 0 )
98
- }
99
-
100
- function updatedPagedCount() {
101
- paged = parseInt(jQuery('body').attr('data-astra-demo-paged'));
102
- jQuery('body').attr('data-astra-demo-paged', paged + 1);
103
- window.setTimeout(function () {
104
- jQuery('body').data('scrolling', false);
105
- }, 800);
106
- }
107
-
108
- jQuery(document).scroll(function (event) {
109
- var scrollDistance = jQuery(window).scrollTop();
110
-
111
- var themesBottom = Math.abs(jQuery(window).height() - jQuery('.themes').offset().top - jQuery('.themes').height());
112
- themesBottom = themesBottom * 20 / 100;
113
-
114
- ajaxLoading = jQuery('body').data('scrolling');
115
-
116
- if (scrollDistance > themesBottom && ajaxLoading == false) {
117
- updatedPagedCount();
118
- jQuery('body').data('scrolling', true);
119
- body = jQuery('body');
120
- id = body.attr('data-astra-site-category');
121
- search = body.attr('data-astra-demo-search');
122
- paged = body.attr('data-astra-demo-paged');
123
-
124
- if (search !== '') {
125
- id = '';
126
- } else {
127
- search = '';
128
- }
129
 
130
- jQuery('.no-themes').remove();
131
-
132
- var astra_page_builder = jQuery('.filter-links.astra-page-builder'),
133
- astra_category = jQuery('.filter-links.astra-category'),
134
- page_builder_id = astra_page_builder.find('.current').data('id'),
135
- category_id = astra_category.find('.current').data('id');
136
-
137
- jQuery.ajax({
138
- url: astraDemo.ajaxurl,
139
- type: 'POST',
140
- dataType: 'json',
141
- data: {
142
- action: 'astra-list-sites',
143
- paged: paged,
144
- search: search,
145
- page_builder_id : page_builder_id,
146
- category_id : category_id,
147
- },
148
- })
149
- .done(function (demos) {
150
 
151
- jQuery('body').removeClass('loading-content');
152
- renderDemoGrid(demos.sites);
153
- })
154
- .fail(function () {
155
- jQuery('body').removeClass('loading-content');
156
- jQuery('.spinner').after('<p class="no-themes" style="display:block;">'+astraDemo.strings.responseError+'</p>');
157
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
158
 
159
- }
160
- });
 
 
 
161
 
162
- /**
163
- * Individual Site Preview
164
- *
165
- * On click on image, more link & preview button.
166
- */
167
- jQuery(document).on('click', '.theme-browser .theme-screenshot, .theme-browser .more-details, .theme-browser .install-theme-preview', function (event) {
168
- event.preventDefault();
169
 
170
- $this = jQuery(this).parents('.theme');
171
- $this.addClass('theme-preview-on');
172
 
173
- jQuery('html').addClass('astra-site-preview-on');
 
174
 
175
- renderDemoPreview($this);
176
- });
 
 
 
177
 
178
- jQuery(document).on('click', '.close-full-overlay', function (event) {
179
- event.preventDefault();
 
 
 
 
 
 
 
 
 
 
180
 
181
- jQuery('.theme-install-overlay').css('display', 'none');
182
- jQuery('.theme-install-overlay').remove();
183
- jQuery('.theme-preview-on').removeClass('theme-preview-on');
184
- jQuery('html').removeClass('astra-site-preview-on');
185
- });
186
 
187
- jQuery(document).on('click', '.next-theme', function (event) {
188
- event.preventDefault();
189
- currentDemo = jQuery('.theme-preview-on')
190
- currentDemo.removeClass('theme-preview-on');
191
- nextDemo = currentDemo.next('.theme');
192
- nextDemo.addClass('theme-preview-on');
193
 
194
- renderDemoPreview( nextDemo );
 
 
 
195
 
196
- });
197
 
198
- jQuery(document).on('click', '.previous-theme', function (event) {
199
- event.preventDefault();
200
 
201
- currentDemo = jQuery('.theme-preview-on');
202
- currentDemo.removeClass('theme-preview-on');
203
- prevDemo = currentDemo.prev('.theme');
204
- prevDemo.addClass('theme-preview-on');
205
 
206
- renderDemoPreview(prevDemo);
207
- });
208
 
209
- /**
210
- * Click handler for plugin installs in plugin install view.
211
- *
212
- * @since 4.6.0
213
- *
214
- * @param {Event} event Event interface.
215
- */
216
- jQuery(document).on('click', '.install-now', function (event) {
217
- event.preventDefault();
218
 
219
- var $button = jQuery( event.target ),
220
- $document = jQuery(document);
 
221
 
222
- if ( $button.hasClass( 'updating-message' ) || $button.hasClass( 'button-disabled' ) ) {
223
- return;
224
- }
225
 
226
- if ( wp.updates.shouldRequestFilesystemCredentials && ! wp.updates.ajaxLocked ) {
227
- wp.updates.requestFilesystemCredentials( event );
 
 
 
 
 
 
 
 
 
228
 
229
- $document.on( 'credential-modal-cancel', function() {
230
- var $message = $( '.install-now.updating-message' );
231
 
232
- $message
233
- .removeClass( 'updating-message' )
234
- .text( wp.updates.l10n.installNow );
235
 
236
- wp.a11y.speak( wp.updates.l10n.updateCancel, 'polite' );
237
- } );
238
- }
239
 
240
- wp.updates.installPlugin( {
241
- slug: $button.data( 'slug' )
242
- } );
 
243
 
244
- } );
 
245
 
246
- jQuery(document).on( 'wp-plugin-install-error', function( event, response ) {
247
 
248
- var $message = jQuery( '.plugin-card-' + response.slug ).find( '.install-now' );
249
 
250
- $message.removeClass( 'button-disabled' )
251
- .addClass( 'button-primary' )
252
- .html( wp.updates.l10n.installNow );
253
 
254
- });
255
 
256
- jQuery(document).on( 'wp-plugin-install-success', function( event, response ) {
257
- event.preventDefault();
258
 
259
- var $message = jQuery( '.plugin-card-' + response.slug ).find( '.install-now' );
260
- var $siteOptions = jQuery( '.wp-full-overlay-header').find('.astra-site-options').val();
261
- var $enabledExtensions = jQuery( '.wp-full-overlay-header').find('.astra-enabled-extensions').val();
262
 
263
- // Transform the 'Install' button into an 'Activate' button.
264
- var $init = $message.data('init');
 
 
265
 
266
- $message.removeClass( 'install-now installed button-disabled updated-message' )
267
- .addClass('updating-message')
268
- .html( astraDemo.strings.btnActivating );
269
 
270
- // WordPress adds "Activate" button after waiting for 1000ms. So we will run our activation after that.
271
- setTimeout( function() {
 
272
 
273
- jQuery.ajax({
274
- url: astraDemo.ajaxurl,
275
- type: 'POST',
276
- data: {
277
- 'action' : 'astra-required-plugin-activate',
278
- 'init' : $init,
279
- 'options' : $siteOptions,
280
- 'enabledExtensions' : $enabledExtensions,
281
- },
282
- })
283
- .done(function (result) {
284
 
285
- if( result.success ) {
286
- $message.removeClass( 'button-primary activate-now updating-message' )
287
- .attr('disabled', 'disabled')
288
- .addClass('disabled')
289
- .text( astraDemo.strings.btnActive );
 
 
 
 
 
 
 
 
 
 
 
 
290
 
291
- // Enable Demo Import Button
292
- astraDemo.requiredPluginsCount--;
293
- enable_demo_import_button();
294
- } else {
295
 
296
- $message.removeClass( 'updating-message' );
297
 
298
- }
 
299
 
300
- });
 
 
 
301
 
302
- }, 1200 );
 
303
 
304
- });
305
 
 
 
 
306
 
307
- /**
308
- * Click handler for plugin installs in plugin install view.
309
- *
310
- * @since 4.6.0
311
- *
312
- * @param {Event} event Event interface.
313
- */
314
- jQuery(document).on('click', '.activate-now', function (event) {
315
- event.preventDefault();
316
-
317
- var $button = jQuery( event.target ),
318
- $init = $button.data( 'init' );
319
-
320
- if ( $button.hasClass( 'updating-message' ) || $button.hasClass( 'button-disabled' ) ) {
321
- return;
322
- }
323
-
324
- $button.addClass('updating-message button-primary')
325
- .html( astraDemo.strings.btnActivating );
326
-
327
- var $siteOptions = jQuery( '.wp-full-overlay-header').find('.astra-site-options').val();
328
- var $enabledExtensions = jQuery( '.wp-full-overlay-header').find('.astra-enabled-extensions').val();
329
-
330
- jQuery.ajax({
331
- url: astraDemo.ajaxurl,
332
- type: 'POST',
333
- data: {
334
- 'action' : 'astra-required-plugin-activate',
335
- 'init' : $init,
336
- 'options' : $siteOptions,
337
- 'enabledExtensions' : $enabledExtensions,
338
  },
339
- })
340
- .done(function (result) {
341
-
342
- if( result.success ) {
343
- $button.removeClass( 'button-primary activate-now updating-message' )
344
- .attr('disabled', 'disabled')
345
- .addClass('disabled')
346
- .text( astraDemo.strings.btnActive );
347
-
348
- // Enable Demo Import Button
349
- astraDemo.requiredPluginsCount--;
350
- enable_demo_import_button();
351
- }
352
 
353
- })
354
- .fail(function () {
355
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
356
 
357
- } );
358
-
359
- function renderDemoPreview(anchor) {
360
-
361
- var demoId = anchor.data('id') || '',
362
- apiURL = anchor.data('demo-api') || '',
363
- demoType = anchor.data('demo-type') || '',
364
- demoURL = anchor.data('demo-url') || '',
365
- screenshot = anchor.data('screenshot') || '',
366
- demo_name = anchor.data('demo-name') || '',
367
- demo_slug = anchor.data('demo-slug') || '',
368
- content = anchor.data('content') || '',
369
- requiredPlugins = anchor.data('required-plugins') || '',
370
- astraSiteOptions = anchor.find('.astra-site-options').val() || '';
371
- astraEnabledExtensions = anchor.find('.astra-enabled-extensions').val() || '';
372
-
373
- var template = wp.template('astra-demo-preview');
374
-
375
- templateData = [{
376
- id : demoId,
377
- astra_demo_type : demoType,
378
- astra_demo_url : demoURL,
379
- demo_api : apiURL,
380
- screenshot : screenshot,
381
- demo_name : demo_name,
382
- slug : demo_slug,
383
- content : content,
384
- requiredPlugins : requiredPlugins,
385
- astra_site_options : astraSiteOptions,
386
- astra_enabled_extensions : astraEnabledExtensions,
387
- }];
388
-
389
- // Initial set count.
390
- astraDemo.requiredPluginsCount = requiredPlugins.length || 0;
391
-
392
- // delete any earlier fullscreen preview before we render new one.
393
- jQuery('.theme-install-overlay').remove();
394
-
395
- jQuery('#astra-sites-menu-page').append(template(templateData[0]));
396
- jQuery('.theme-install-overlay').css('display', 'block');
397
- checkNextPrevButtons();
398
-
399
- var desc = jQuery('.theme-details');
400
- var descHeight = parseInt( desc.outerHeight() );
401
- var descBtn = jQuery('.theme-details-read-more');
402
-
403
- if( jQuery.isArray( requiredPlugins ) ) {
404
-
405
- if( descHeight >= 55 ) {
406
-
407
- // Show button.
408
- descBtn.css( 'display', 'inline-block' );
409
-
410
- // Set height upto 3 line.
411
- desc.css( 'height', 57 );
412
-
413
- // Button Click.
414
- descBtn.click(function(event) {
415
-
416
- if( descBtn.hasClass('open') ) {
417
- desc.animate({ height: 57 },
418
- 300, function() {
419
- descBtn.removeClass('open');
420
- descBtn.html( astraDemo.strings.DescExpand );
421
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
422
  } else {
423
- desc.animate({ height: descHeight },
424
- 300, function() {
425
- descBtn.addClass('open');
426
- descBtn.html( astraDemo.strings.DescCollapse );
427
- });
428
  }
429
 
 
 
 
 
430
  });
431
- }
432
 
433
- // or
434
- var $pluginsFilter = jQuery( '#plugin-filter' ),
435
- data = {
436
- _ajax_nonce : astraDemo._ajax_nonce,
437
- required_plugins : requiredPlugins
438
- };
439
-
440
- jQuery('.required-plugins').addClass('loading').html('<span class="spinner is-active"></span>');
441
-
442
- wp.ajax.post( 'astra-required-plugins', data ).done( function( response ) {
443
-
444
- // Remove loader.
445
- jQuery('.required-plugins').removeClass('loading').html('');
446
-
447
- /**
448
- * Count remaining plugins.
449
- * @type number
450
- */
451
- var remaining_plugins = 0;
452
-
453
- /**
454
- * Not Installed
455
- *
456
- * List of not installed required plugins.
457
- */
458
- if ( typeof response.notinstalled !== 'undefined' ) {
459
-
460
- // Add not have installed plugins count.
461
- remaining_plugins += parseInt( response.notinstalled.length );
462
-
463
- jQuery( response.notinstalled ).each(function( index, plugin ) {
464
-
465
- var output = '<div class="plugin-card ';
466
- output += ' plugin-card-'+plugin.slug+'"';
467
- output += ' data-slug="'+plugin.slug+'">';
468
- output += ' <span class="title">'+plugin.name+'</span>';
469
- output += ' <button class="button install-now"';
470
- output += ' data-init="' + plugin.init + '"';
471
- output += ' data-slug="' + plugin.slug + '"';
472
- output += ' data-name="' + plugin.name + '">';
473
- output += wp.updates.l10n.installNow;
474
- output += ' </button>';
475
- output += '</div>';
476
 
477
- jQuery('.required-plugins').append(output);
478
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
479
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
480
  }
 
481
 
482
- /**
483
- * Inactive
484
- *
485
- * List of not inactive required plugins.
486
- */
487
- if ( typeof response.inactive !== 'undefined' ) {
488
 
489
- // Add inactive plugins count.
490
- remaining_plugins += parseInt( response.inactive.length );
491
 
492
- jQuery( response.inactive ).each(function( index, plugin ) {
 
493
 
494
- var output = '<div class="plugin-card ';
495
- output += ' plugin-card-'+plugin.slug+'"';
496
- output += ' data-slug="'+plugin.slug+'">';
497
- output += ' <span class="title">'+plugin.name+'</span>';
498
 
499
- output += ' <button class="button activate-now button-primary"';
500
- output += ' data-init="' + plugin.init + '">';
501
- output += wp.updates.l10n.activatePlugin;
502
- output += ' </button>';
503
- output += '</div>';
 
 
 
 
 
 
 
 
 
504
 
505
- jQuery('.required-plugins').append(output);
506
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
507
  });
 
508
  }
 
509
 
510
- /**
511
- * Active
512
- *
513
- * List of not active required plugins.
514
- */
515
- if ( typeof response.active !== 'undefined' ) {
516
-
517
- jQuery( response.active ).each(function( index, plugin ) {
518
-
519
- var output = '<div class="plugin-card ';
520
- output += ' plugin-card-'+plugin.slug+'"';
521
- output += ' data-slug="'+plugin.slug+'">';
522
- output += ' <span class="title">'+plugin.name+'</span>';
523
- output += ' <button class="button disabled"';
524
- output += ' data-slug="' + plugin.slug + '"';
525
- output += ' data-name="' + plugin.name + '">';
526
- output += astraDemo.strings.btnActive;
527
- output += ' </button>';
528
- output += '</div>';
529
 
530
- jQuery('.required-plugins').append(output);
 
531
 
532
- });
 
533
  }
534
 
535
- /**
536
- * Enable Demo Import Button
537
- * @type number
538
- */
539
- astraDemo.requiredPluginsCount = remaining_plugins;
540
- enable_demo_import_button();
541
 
542
- } );
 
543
 
544
- } else {
 
 
545
 
546
- // Enable Demo Import Button
547
- astraDemo.requiredPluginsCount = requiredPlugins.length;
548
- enable_demo_import_button( demoType );
549
- jQuery('.required-plugins-wrap').remove();
550
- }
551
 
552
- return;
553
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
554
 
555
- function checkNextPrevButtons() {
556
- currentDemo = jQuery('.theme-preview-on');
557
- nextDemo = currentDemo.nextAll('.theme').length;
558
- prevDemo = currentDemo.prevAll('.theme').length;
559
 
560
- if (nextDemo == 0) {
561
- jQuery('.next-theme').addClass('disabled');
562
- } else if (nextDemo != 0) {
563
- jQuery('.next-theme').removeClass('disabled');
564
- }
 
565
 
566
- if (prevDemo == 0) {
567
- jQuery('.previous-theme').addClass('disabled');
568
- } else if (prevDemo != 0) {
569
- jQuery('.previous-theme').removeClass('disabled');
570
- }
571
 
572
- return;
573
- }
574
 
575
- jQuery(document).on('click', '.filter-links li a', function (event) {
576
- event.preventDefault();
577
 
578
- $this = jQuery(this);
579
- $this.parent('li').siblings().find('.current').removeClass('current');
580
- $this.addClass('current');
581
-
582
- var astra_page_builder = jQuery('.filter-links.astra-page-builder'),
583
- astra_category = jQuery('.filter-links.astra-category'),
584
- page_builder_id = astra_page_builder.find('.current').data('id'),
585
- category_id = astra_category.find('.current').data('id');
 
 
586
 
587
- resetPagedCount();
588
-
589
- paged = parseInt(jQuery('body').attr('data-astra-demo-paged'));
590
-
591
- jQuery('body').addClass('loading-content');
592
- jQuery('.theme-browser .theme').remove();
593
- jQuery('.no-themes').remove();
594
- jQuery('#wp-filter-search-input').val('');
595
-
596
- jQuery.ajax({
597
- url: astraDemo.ajaxurl,
598
- type: 'POST',
599
- dataType: 'json',
600
- data: {
601
- action: 'astra-list-sites',
602
- paged: paged,
603
- page_builder_id : page_builder_id,
604
- category_id : category_id,
605
  },
606
- })
607
- .done(function (demos) {
608
- jQuery('.filter-count .count').text( demos.sites_count );
609
- jQuery('body').removeClass('loading-content');
610
-
611
- if ( demos.sites_count > 0 ) {
612
- renderDemoGrid(demos.sites);
613
- } else {
614
- jQuery('.spinner').after('<p class="no-themes" style="display:block;">'+astraDemo.strings.searchNoFound+'</p>');
615
- }
616
- })
617
- .fail(function () {
618
- jQuery('body').removeClass('loading-content');
619
- jQuery('.spinner').after('<p class="no-themes" style="display:block;">'+astraDemo.strings.responseError+'</p>');
620
- });
621
 
622
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
623
 
624
- var ref;
625
- jQuery(document).on('keyup input', '#wp-filter-search-input', function () {
626
- $this = jQuery('#wp-filter-search-input').val();
627
 
628
- id = '';
629
- if ($this.length < 2) {
630
- id = 'all';
631
- }
632
 
633
- var astra_page_builder = jQuery('.filter-links.astra-page-builder'),
634
- astra_category = jQuery('.filter-links.astra-category'),
635
- page_builder_id = astra_page_builder.find('.current').data('id'),
636
- category_id = astra_category.find('.current').data('id');
637
-
638
 
639
- window.clearTimeout(ref);
640
- ref = window.setTimeout(function () {
641
- ref = null;
642
-
643
- resetPagedCount();
644
- jQuery('body').addClass('loading-content');
645
- jQuery('.theme-browser .theme').remove();
646
- jQuery('.no-themes').remove();
647
- jQuery('body').attr('data-astra-demo-search', $this);
648
-
649
- jQuery.ajax({
650
- url: astraDemo.ajaxurl,
651
- type: 'POST',
652
- dataType: 'json',
653
- data: {
654
- action: 'astra-list-sites',
655
- search: $this,
656
- page_builder_id : page_builder_id,
657
- category_id : category_id,
658
- },
659
- })
660
- .done(function (demos) {
661
- jQuery('body').removeClass('loading-content');
662
-
663
- console.log('demos.sites_count: ' + demos.sites_count);
664
-
665
- jQuery('.filter-count .count').text( demos.sites_count );
666
-
667
- if ( demos.sites_count > 0 ) {
668
- renderDemoGrid(demos.sites);
669
- } else {
670
- jQuery('.spinner').after('<p class="no-themes" style="display:block;">'+astraDemo.strings.searchNoFound+'</p>');
671
  }
672
 
673
- })
674
- .fail(function () {
675
- jQuery('body').removeClass('loading-content');
676
- jQuery('.spinner').after('<p class="no-themes" style="display:block;">'+astraDemo.strings.responseError+'.</p>');
677
- });
678
-
679
-
680
- }, 500);
681
-
682
- });
683
-
684
- function renderDemoGrid(demos, current_event = '') {
685
-
686
- jQuery.each(demos, function (index, demo) {
687
-
688
- id = demo.id;
689
- content = demo.content;
690
- demo_api = demo.demo_api;
691
- demo_name = demo.title;
692
- demo_slug = demo.slug;
693
- screenshot = demo.featured_image_url;
694
- astra_demo_url = demo.astra_demo_url;
695
- astra_demo_type = demo.astra_demo_type;
696
- requiredPlugins = demo.required_plugins;
697
- status = demo.status;
698
- astraSiteOptions = demo.astra_site_options || '';
699
- astraEnabledExtensions = demo.astra_enabled_extensions || '';
700
-
701
- templateData = [{
702
- id: id,
703
- astra_demo_type: astra_demo_type,
704
- status: status,
705
- astra_demo_url: astra_demo_url,
706
- demo_api: demo_api,
707
- screenshot: screenshot,
708
- demo_name: demo_name,
709
- slug: demo_slug,
710
- content: content,
711
- required_plugins: requiredPlugins,
712
- astra_site_options: astraSiteOptions,
713
- astra_enabled_extensions: astraEnabledExtensions
714
- }]
715
-
716
- var template = wp.template('astra-single-demo');
717
- jQuery('.themes').append(template(templateData[0]));
718
- });
 
 
 
 
 
 
719
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
720
 
721
- }
722
 
723
- jQuery(document).on('click', '.collapse-sidebar', function (event) {
724
- event.preventDefault();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
725
 
726
- overlay = jQuery('.wp-full-overlay');
 
 
727
 
728
- if (overlay.hasClass('expanded')) {
729
- overlay.removeClass('expanded');
730
- overlay.addClass('collapsed');
731
- return;
732
- }
733
 
734
- if (overlay.hasClass('collapsed')) {
735
- overlay.removeClass('collapsed');
736
- overlay.addClass('expanded');
737
- return;
738
- }
739
- });
740
 
741
- jQuery(document).on('click', '.astra-demo-import', function (event) {
742
- event.preventDefault();
743
 
744
- var $this = jQuery(this),
745
- disabled = $this.attr('data-import');
746
 
747
- if ( typeof disabled !== 'undefined' && disabled === 'disabled' ) {
 
 
 
748
 
749
- // Highlight required plugins list.
750
- var pluginTitle = jQuery('.required-plugins-wrap h4');
751
- pluginTitle.css({'background-color':'rgba(255, 235, 59, 0.20)'});
752
- setTimeout(function() {
753
- pluginTitle.css({'background-color':''});
754
- }, 1000);
755
 
756
- return;
757
- }
 
 
 
 
 
 
 
 
758
 
759
- // Proceed?
760
- if( ! confirm( astraDemo.strings.importWarning ) ) {
761
- return;
762
- }
763
 
764
- jQuery('.astra-demo-import').attr('data-import', 'disabled')
765
- .addClass('updating-message installing')
766
- .text('Importing Demo');
 
767
 
768
- $this.closest('.theme').focus();
 
 
769
 
770
- var $theme = $this.closest('.astra-sites-preview').find('.wp-full-overlay-header');
 
 
 
771
 
772
- var apiURL = $theme.data('demo-api') || '';
 
 
 
 
 
 
773
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
774
 
775
- jQuery.ajax({
776
- url: astraDemo.ajaxurl,
777
- type: 'POST',
778
- dataType: 'json',
779
- data: {
780
- action: 'astra-import-demo',
781
- api_url: apiURL
782
  },
783
- })
784
- .done(function ( demos ) {
785
-
786
- // Success?
787
- if( demos.success ) {
788
- jQuery('.astra-demo-import').removeClass('updating-message installing')
789
- .removeAttr('data-import')
790
- .addClass('view-site')
791
- .removeClass('astra-demo-import')
792
- .text( astraDemo.strings.viewSite )
793
- .attr('target', '_blank')
794
- .append('<i class="dashicons dashicons-external"></i>')
795
- .attr('href', astraDemo.siteURL );
796
-
797
- } else {
798
-
799
- var output = '<div class="astra-api-error notice notice-error notice-alt is-dismissible">';
800
- output += ' <p>'+demos.message+'</p>';
801
- output += ' <button type="button" class="notice-dismiss">';
802
- output += ' <span class="screen-reader-text">'+commonL10n.dismiss+'</span>';
803
- output += ' </button>';
804
- output += '</div>';
805
-
806
- jQuery('.install-theme-info').prepend( output );
807
-
808
- // !important to add trigger.
809
- // Which reinitialize the dismiss error message events.
810
- jQuery(document).trigger('wp-updates-notice-added');
811
  }
812
 
813
- })
814
- .fail(function ( demos ) {
815
- jQuery('.astra-demo-import').removeClass('updating-message installing')
816
- .removeAttr('data-import')
817
- .addClass('view-site')
818
- .removeClass('astra-demo-import')
819
- .attr('target', '_blank')
820
- .attr('href', astraDemo.strings.importFailedURL );
821
-
822
- jQuery('.wp-full-overlay-header .view-site').text( astraDemo.strings.importFailedBtnSmall ).append('<i class="dashicons dashicons-external"></i>');
823
- jQuery('.footer-import-button-wrap .view-site').text( astraDemo.strings.importFailedBtnLarge ).append('<i class="dashicons dashicons-external"></i>');
824
  });
825
 
826
- });
1
+ /**
2
+ * AJAX Request Queue
3
+ *
4
+ * - add()
5
+ * - remove()
6
+ * - run()
7
+ * - stop()
8
+ *
9
+ * @since 1.0.0
10
+ */
11
+ var AstraSitesAjaxQueue = (function() {
12
 
13
+ var requests = [];
 
14
 
15
+ return {
16
 
17
+ /**
18
+ * Add AJAX request
19
+ *
20
+ * @since 1.0.0
21
+ */
22
+ add: function(opt) {
23
+ requests.push(opt);
24
+ },
25
 
26
+ /**
27
+ * Remove AJAX request
28
+ *
29
+ * @since 1.0.0
30
+ */
31
+ remove: function(opt) {
32
+ if( jQuery.inArray(opt, requests) > -1 )
33
+ requests.splice($.inArray(opt, requests), 1);
34
  },
 
 
35
 
36
+ /**
37
+ * Run / Process AJAX request
38
+ *
39
+ * @since 1.0.0
40
+ */
41
+ run: function() {
42
+ var self = this,
43
+ oriSuc;
44
 
45
+ if( requests.length ) {
46
+ oriSuc = requests[0].complete;
 
47
 
48
+ requests[0].complete = function() {
49
+ if( typeof(oriSuc) === 'function' ) oriSuc();
50
+ requests.shift();
51
+ self.run.apply(self, []);
52
+ };
53
 
54
+ jQuery.ajax(requests[0]);
 
 
 
 
 
55
 
56
+ } else {
57
 
58
+ self.tid = setTimeout(function() {
59
+ self.run.apply(self, []);
60
+ }, 1000);
61
+ }
62
+ },
63
 
64
+ /**
65
+ * Stop AJAX request
66
+ *
67
+ * @since 1.0.0
68
+ */
69
+ stop: function() {
70
 
71
+ requests = [];
72
+ clearTimeout(this.tid);
73
+ }
74
+ };
75
 
76
+ }());
 
77
 
78
+ (function($){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79
 
80
+ AstraSites = {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
 
82
+ _ref: null,
83
+
84
+ _iconUploader: null,
85
+
86
+ init: function()
87
+ {
88
+ this._bind();
89
+ this._resetPagedCount();
90
+ this._initial_load_demos();
91
+ },
92
+
93
+ /**
94
+ * Binds events for the Astra Sites.
95
+ *
96
+ * @since 1.0.1
97
+ * @access private
98
+ * @method _bind
99
+ */
100
+ _bind: function()
101
+ {
102
+ $( document ).on('scroll', AstraSites._scroll);
103
+ $( document ).on('click', '.astra-demo-import', AstraSites._importDemo);
104
+ $( document ).on('click', '.install-now', AstraSites._installNow);
105
+ $( document ).on('click', '.theme-browser .theme-screenshot, .theme-browser .more-details, .theme-browser .install-theme-preview', AstraSites._preview);
106
+ $( document ).on('click', '.collapse-sidebar', AstraSites._collapse);
107
+ $( document ).on('click', '.filter-links li a', AstraSites._filter);
108
+ $( document ).on('click', '.activate-now', AstraSites._activateNow);
109
+ $( document ).on('click', '.close-full-overlay', AstraSites._fullOverlay);
110
+ $( document ).on('click', '.next-theme', AstraSites._nextTheme);
111
+ $( document ).on('click', '.previous-theme', AstraSites._previousTheme);
112
+ $( document ).on('keyup input', '#wp-filter-search-input', AstraSites._serach);
113
+ $( document ).on('wp-plugin-installing', AstraSites._pluginInstalling);
114
+ $( document ).on('wp-plugin-install-error', AstraSites._installError);
115
+ $( document ).on('wp-plugin-install-success', AstraSites._installSuccess);
116
+ },
117
 
118
+ /**
119
+ * Previous Theme.
120
+ */
121
+ _previousTheme: function (event) {
122
+ event.preventDefault();
123
 
124
+ currentDemo = jQuery('.theme-preview-on');
125
+ currentDemo.removeClass('theme-preview-on');
126
+ prevDemo = currentDemo.prev('.theme');
127
+ prevDemo.addClass('theme-preview-on');
 
 
 
128
 
129
+ AstraSites._renderDemoPreview(prevDemo);
130
+ },
131
 
132
+ _fullOverlay: function (event) {
133
+ event.preventDefault();
134
 
135
+ jQuery('.theme-install-overlay').css('display', 'none');
136
+ jQuery('.theme-install-overlay').remove();
137
+ jQuery('.theme-preview-on').removeClass('theme-preview-on');
138
+ jQuery('html').removeClass('astra-site-preview-on');
139
+ },
140
 
141
+ /**
142
+ * Next Theme.
143
+ */
144
+ _nextTheme: function (event) {
145
+ event.preventDefault();
146
+ currentDemo = jQuery('.theme-preview-on')
147
+ currentDemo.removeClass('theme-preview-on');
148
+ nextDemo = currentDemo.next('.theme');
149
+ nextDemo.addClass('theme-preview-on');
150
+
151
+ AstraSites._renderDemoPreview( nextDemo );
152
+ },
153
 
154
+ /**
155
+ * Plugin Installation Error.
156
+ */
157
+ _installError: function( event, response ) {
 
158
 
159
+ var $card = jQuery( '.plugin-card-' + response.slug );
 
 
 
 
 
160
 
161
+ $card
162
+ .addClass( 'button-primary' )
163
+ .html( wp.updates.l10n.installNow );
164
+ },
165
 
166
+ _installSuccess: function( event, response ) {
167
 
168
+ event.preventDefault();
 
169
 
170
+ var $message = jQuery( '.plugin-card-' + response.slug ).find( '.button' );
171
+ var $siteOptions = jQuery( '.wp-full-overlay-header').find('.astra-site-options').val();
172
+ var $enabledExtensions = jQuery( '.wp-full-overlay-header').find('.astra-enabled-extensions').val();
 
173
 
174
+ // Transform the 'Install' button into an 'Activate' button.
175
+ var $init = $message.data('init');
176
 
177
+ $message.removeClass( 'install-now installed button-disabled updated-message' )
178
+ .addClass('updating-message')
179
+ .html( astraDemo.strings.btnActivating );
 
 
 
 
 
 
180
 
181
+ // Reset not installed plugins list.
182
+ var pluginsList = astraDemo.requiredPlugins.notinstalled;
183
+ astraDemo.requiredPlugins.notinstalled = AstraSites._removePluginFromQueue( response.slug, pluginsList );
184
 
185
+ // WordPress adds "Activate" button after waiting for 1000ms. So we will run our activation after that.
186
+ setTimeout( function() {
 
187
 
188
+ jQuery.ajax({
189
+ url: astraDemo.ajaxurl,
190
+ type: 'POST',
191
+ data: {
192
+ 'action' : 'astra-required-plugin-activate',
193
+ 'init' : $init,
194
+ 'options' : $siteOptions,
195
+ 'enabledExtensions' : $enabledExtensions,
196
+ },
197
+ })
198
+ .done(function (result) {
199
 
200
+ if( result.success ) {
 
201
 
202
+ var pluginsList = astraDemo.requiredPlugins.inactive;
 
 
203
 
204
+ // Reset not installed plugins list.
205
+ astraDemo.requiredPlugins.inactive = AstraSites._removePluginFromQueue( response.slug, pluginsList );
 
206
 
207
+ $message.removeClass( 'button-primary install-now activate-now updating-message' )
208
+ .attr('disabled', 'disabled')
209
+ .addClass('disabled')
210
+ .text( astraDemo.strings.btnActive );
211
 
212
+ // Enable Demo Import Button
213
+ AstraSites._enable_demo_import_button();
214
 
215
+ } else {
216
 
217
+ $message.removeClass( 'updating-message' );
218
 
219
+ }
 
 
220
 
221
+ });
222
 
223
+ }, 1200 );
 
224
 
225
+ },
 
 
226
 
227
+ /**
228
+ * Render Demo Preview
229
+ */
230
+ _activateNow: function( eventn ) {
231
 
232
+ event.preventDefault();
 
 
233
 
234
+ var $button = jQuery( event.target ),
235
+ $init = $button.data( 'init' ),
236
+ $slug = $button.data( 'slug' );
237
 
238
+ if ( $button.hasClass( 'updating-message' ) || $button.hasClass( 'button-disabled' ) ) {
239
+ return;
240
+ }
 
 
 
 
 
 
 
 
241
 
242
+ $button.addClass('updating-message button-primary')
243
+ .html( astraDemo.strings.btnActivating );
244
+
245
+ var $siteOptions = jQuery( '.wp-full-overlay-header').find('.astra-site-options').val();
246
+ var $enabledExtensions = jQuery( '.wp-full-overlay-header').find('.astra-enabled-extensions').val();
247
+
248
+ jQuery.ajax({
249
+ url: astraDemo.ajaxurl,
250
+ type: 'POST',
251
+ data: {
252
+ 'action' : 'astra-required-plugin-activate',
253
+ 'init' : $init,
254
+ 'options' : $siteOptions,
255
+ 'enabledExtensions' : $enabledExtensions,
256
+ },
257
+ })
258
+ .done(function (result) {
259
 
260
+ if( result.success ) {
 
 
 
261
 
262
+ var pluginsList = astraDemo.requiredPlugins.inactive;
263
 
264
+ // Reset not installed plugins list.
265
+ astraDemo.requiredPlugins.inactive = AstraSites._removePluginFromQueue( $slug, pluginsList );
266
 
267
+ $button.removeClass( 'button-primary install-now activate-now updating-message' )
268
+ .attr('disabled', 'disabled')
269
+ .addClass('disabled')
270
+ .text( astraDemo.strings.btnActive );
271
 
272
+ // Enable Demo Import Button
273
+ AstraSites._enable_demo_import_button();
274
 
275
+ }
276
 
277
+ })
278
+ .fail(function () {
279
+ });
280
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
281
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
282
 
283
+ _renderDemoPreview: function(anchor) {
284
+
285
+ var demoId = anchor.data('id') || '',
286
+ apiURL = anchor.data('demo-api') || '',
287
+ demoType = anchor.data('demo-type') || '',
288
+ demoURL = anchor.data('demo-url') || '',
289
+ screenshot = anchor.data('screenshot') || '',
290
+ demo_name = anchor.data('demo-name') || '',
291
+ demo_slug = anchor.data('demo-slug') || '',
292
+ content = anchor.data('content') || '',
293
+ requiredPlugins = anchor.data('required-plugins') || '',
294
+ astraSiteOptions = anchor.find('.astra-site-options').val() || '';
295
+ astraEnabledExtensions = anchor.find('.astra-enabled-extensions').val() || '';
296
+
297
+ var template = wp.template('astra-demo-preview');
298
+
299
+ templateData = [{
300
+ id : demoId,
301
+ astra_demo_type : demoType,
302
+ astra_demo_url : demoURL,
303
+ demo_api : apiURL,
304
+ screenshot : screenshot,
305
+ demo_name : demo_name,
306
+ slug : demo_slug,
307
+ content : content,
308
+ required_plugins : JSON.stringify(requiredPlugins),
309
+ astra_site_options : astraSiteOptions,
310
+ astra_enabled_extensions : astraEnabledExtensions,
311
+ }];
312
+
313
+ // delete any earlier fullscreen preview before we render new one.
314
+ jQuery('.theme-install-overlay').remove();
315
+
316
+ jQuery('#astra-sites-menu-page').append(template(templateData[0]));
317
+ jQuery('.theme-install-overlay').css('display', 'block');
318
+ AstraSites._checkNextPrevButtons();
319
+
320
+ var desc = jQuery('.theme-details');
321
+ var descHeight = parseInt( desc.outerHeight() );
322
+ var descBtn = jQuery('.theme-details-read-more');
323
+
324
+ if( jQuery.isArray( requiredPlugins ) ) {
325
+
326
+ if( descHeight >= 55 ) {
327
+
328
+ // Show button.
329
+ descBtn.css( 'display', 'inline-block' );
330
+
331
+ // Set height upto 3 line.
332
+ desc.css( 'height', 57 );
333
+
334
+ // Button Click.
335
+ descBtn.click(function(event) {
336
+
337
+ if( descBtn.hasClass('open') ) {
338
+ desc.animate({ height: 57 },
339
+ 300, function() {
340
+ descBtn.removeClass('open');
341
+ descBtn.html( astraDemo.strings.DescExpand );
342
+ });
343
+ } else {
344
+ desc.animate({ height: descHeight },
345
+ 300, function() {
346
+ descBtn.addClass('open');
347
+ descBtn.html( astraDemo.strings.DescCollapse );
348
+ });
349
+ }
350
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
351
  });
352
+ }
353
+
354
+ // or
355
+ var $pluginsFilter = jQuery( '#plugin-filter' ),
356
+ data = {
357
+ _ajax_nonce : astraDemo._ajax_nonce,
358
+ required_plugins : requiredPlugins
359
+ };
360
+
361
+ jQuery('.required-plugins').addClass('loading').html('<span class="spinner is-active"></span>');
362
+
363
+ wp.ajax.post( 'astra-required-plugins', data ).done( function( response ) {
364
+
365
+ // Remove loader.
366
+ jQuery('.required-plugins').removeClass('loading').html('');
367
+
368
+ /**
369
+ * Count remaining plugins.
370
+ * @type number
371
+ */
372
+ var remaining_plugins = 0;
373
+
374
+ /**
375
+ * Not Installed
376
+ *
377
+ * List of not installed required plugins.
378
+ */
379
+ if ( typeof response.notinstalled !== 'undefined' ) {
380
+
381
+ // Add not have installed plugins count.
382
+ remaining_plugins += parseInt( response.notinstalled.length );
383
+
384
+ jQuery( response.notinstalled ).each(function( index, plugin ) {
385
+
386
+ var output = '<div class="plugin-card ';
387
+ output += ' plugin-card-'+plugin.slug+'"';
388
+ output += ' data-slug="'+plugin.slug+'"';
389
+ output += ' data-init="'+plugin.init+'">';
390
+ output += ' <span class="title">'+plugin.name+'</span>';
391
+ output += ' <button class="button install-now"';
392
+ output += ' data-init="' + plugin.init + '"';
393
+ output += ' data-slug="' + plugin.slug + '"';
394
+ output += ' data-name="' + plugin.name + '">';
395
+ output += wp.updates.l10n.installNow;
396
+ output += ' </button>';
397
+ // output += ' <span class="dashicons-no dashicons"></span>';
398
+ output += '</div>';
399
+
400
+ jQuery('.required-plugins').append(output);
401
+
402
+ });
403
+ }
404
+
405
+ /**
406
+ * Inactive
407
+ *
408
+ * List of not inactive required plugins.
409
+ */
410
+ if ( typeof response.inactive !== 'undefined' ) {
411
+
412
+ // Add inactive plugins count.
413
+ remaining_plugins += parseInt( response.inactive.length );
414
+
415
+ jQuery( response.inactive ).each(function( index, plugin ) {
416
+
417
+ var output = '<div class="plugin-card ';
418
+ output += ' plugin-card-'+plugin.slug+'"';
419
+ output += ' data-slug="'+plugin.slug+'"';
420
+ output += ' data-init="'+plugin.init+'">';
421
+ output += ' <span class="title">'+plugin.name+'</span>';
422
+ output += ' <button class="button activate-now button-primary"';
423
+ output += ' data-init="' + plugin.init + '"';
424
+ output += ' data-slug="' + plugin.slug + '"';
425
+ output += ' data-name="' + plugin.name + '">';
426
+ output += wp.updates.l10n.activatePlugin;
427
+ output += ' </button>';
428
+ // output += ' <span class="dashicons-no dashicons"></span>';
429
+ output += '</div>';
430
+
431
+ jQuery('.required-plugins').append(output);
432
+
433
+ });
434
+ }
435
+
436
+ /**
437
+ * Active
438
+ *
439
+ * List of not active required plugins.
440
+ */
441
+ if ( typeof response.active !== 'undefined' ) {
442
+
443
+ jQuery( response.active ).each(function( index, plugin ) {
444
+
445
+ var output = '<div class="plugin-card ';
446
+ output += ' plugin-card-'+plugin.slug+'"';
447
+ output += ' data-slug="'+plugin.slug+'"';
448
+ output += ' data-init="'+plugin.init+'">';
449
+ output += ' <span class="title">'+plugin.name+'</span>';
450
+ output += ' <button class="button disabled"';
451
+ output += ' data-slug="' + plugin.slug + '"';
452
+ output += ' data-name="' + plugin.name + '">';
453
+ output += astraDemo.strings.btnActive;
454
+ output += ' </button>';
455
+ // output += ' <span class="dashicons-yes dashicons"></span>';
456
+ output += '</div>';
457
+
458
+ jQuery('.required-plugins').append(output);
459
+
460
+ });
461
+ }
462
+
463
+ /**
464
+ * Enable Demo Import Button
465
+ * @type number
466
+ */
467
+ astraDemo.requiredPlugins = response;
468
+ AstraSites._enable_demo_import_button();
469
+
470
+ } );
471
+
472
+ } else {
473
+
474
+ // Enable Demo Import Button
475
+ AstraSites._enable_demo_import_button( demoType );
476
+ jQuery('.required-plugins-wrap').remove();
477
+ }
478
+
479
+ return;
480
+ },
481
+
482
+ /**
483
+ * Check Next Previous Buttons.
484
+ */
485
+ _checkNextPrevButtons: function() {
486
+ currentDemo = jQuery('.theme-preview-on');
487
+ nextDemo = currentDemo.nextAll('.theme').length;
488
+ prevDemo = currentDemo.prevAll('.theme').length;
489
+
490
+ if (nextDemo == 0) {
491
+ jQuery('.next-theme').addClass('disabled');
492
+ } else if (nextDemo != 0) {
493
+ jQuery('.next-theme').removeClass('disabled');
494
+ }
495
+
496
+ if (prevDemo == 0) {
497
+ jQuery('.previous-theme').addClass('disabled');
498
+ } else if (prevDemo != 0) {
499
+ jQuery('.previous-theme').removeClass('disabled');
500
+ }
501
+
502
+ return;
503
+ },
504
+
505
+ /**
506
+ * Filter Demo by Category.
507
+ */
508
+ _filter: function(event) {
509
+ event.preventDefault();
510
+
511
+ $this = jQuery(this);
512
+ $this.parent('li').siblings().find('.current').removeClass('current');
513
+ $this.addClass('current');
514
+
515
+ var astra_page_builder = jQuery('.filter-links.astra-page-builder'),
516
+ astra_category = jQuery('.filter-links.astra-category'),
517
+ page_builder_id = astra_page_builder.find('.current').data('id'),
518
+ category_id = astra_category.find('.current').data('id');
519
+
520
+ AstraSites._resetPagedCount();
521
+
522
+ paged = parseInt(jQuery('body').attr('data-astra-demo-paged'));
523
+
524
+ jQuery('body').addClass('loading-content');
525
+ jQuery('.theme-browser .theme').remove();
526
+ jQuery('.no-themes').remove();
527
+ jQuery('#wp-filter-search-input').val('');
528
+
529
+ jQuery.ajax({
530
+ url: astraDemo.ajaxurl,
531
+ type: 'POST',
532
+ dataType: 'json',
533
+ data: {
534
+ action: 'astra-list-sites',
535
+ paged: paged,
536
+ page_builder_id : page_builder_id,
537
+ category_id : category_id,
538
+ },
539
+ })
540
+ .done(function (demos) {
541
+
542
+ jQuery('.filter-count .count').text( demos.sites_count );
543
+ jQuery('body').removeClass('loading-content');
544
+
545
+ if ( demos.sites_count > 0 ) {
546
+ AstraSites._renderDemoGrid(demos.sites);
547
  } else {
548
+ jQuery('.spinner').after('<p class="no-themes" style="display:block;">'+astraDemo.strings.searchNoFound+'</p>');
 
 
 
 
549
  }
550
 
551
+ })
552
+ .fail(function () {
553
+ jQuery('body').removeClass('loading-content');
554
+ jQuery('.spinner').after('<p class="no-themes" style="display:block;">'+astraDemo.strings.responseError+'</p>');
555
  });
 
556
 
557
+ },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
558
 
 
559
 
560
+ /**
561
+ * Search Site.
562
+ */
563
+ _serach: function() {
564
+ $this = jQuery('#wp-filter-search-input').val();
565
+
566
+ id = '';
567
+ if ($this.length < 2) {
568
+ id = 'all';
569
+ }
570
+
571
+ var astra_page_builder = jQuery('.filter-links.astra-page-builder'),
572
+ astra_category = jQuery('.filter-links.astra-category'),
573
+ page_builder_id = astra_page_builder.find('.current').data('id'),
574
+ category_id = astra_category.find('.current').data('id');
575
+
576
+
577
+ window.clearTimeout(AstraSites._ref);
578
+ AstraSites._ref = window.setTimeout(function () {
579
+ AstraSites._ref = null;
580
+
581
+ AstraSites._resetPagedCount();
582
+ jQuery('body').addClass('loading-content');
583
+ jQuery('.theme-browser .theme').remove();
584
+ jQuery('.no-themes').remove();
585
+ jQuery('body').attr('data-astra-demo-search', $this);
586
+
587
+ jQuery.ajax({
588
+ url: astraDemo.ajaxurl,
589
+ type: 'POST',
590
+ dataType: 'json',
591
+ data: {
592
+ action: 'astra-list-sites',
593
+ search: $this,
594
+ page_builder_id : page_builder_id,
595
+ category_id : category_id,
596
+ },
597
+ })
598
+ .done(function (demos) {
599
+ jQuery('body').removeClass('loading-content');
600
+
601
+ jQuery('.filter-count .count').text( demos.sites_count );
602
+
603
+ if ( demos.sites_count > 0 ) {
604
+ AstraSites._renderDemoGrid(demos.sites);
605
+ } else {
606
+ jQuery('.spinner').after('<p class="no-themes" style="display:block;">'+astraDemo.strings.searchNoFound+'</p>');
607
+ }
608
+
609
+ })
610
+ .fail(function () {
611
+ jQuery('body').removeClass('loading-content');
612
+ jQuery('.spinner').after('<p class="no-themes" style="display:block;">'+astraDemo.strings.responseError+'.</p>');
613
  });
614
+
615
+
616
+ }, 500);
617
+
618
+ },
619
+
620
+ /**
621
+ * Collapse Sidebar.
622
+ */
623
+ _collapse: function() {
624
+ event.preventDefault();
625
+
626
+ overlay = jQuery('.wp-full-overlay');
627
+
628
+ if (overlay.hasClass('expanded')) {
629
+ overlay.removeClass('expanded');
630
+ overlay.addClass('collapsed');
631
+ return;
632
+ }
633
+
634
+ if (overlay.hasClass('collapsed')) {
635
+ overlay.removeClass('collapsed');
636
+ overlay.addClass('expanded');
637
+ return;
638
  }
639
+ },
640
 
641
+ /**
642
+ * Individual Site Preview
643
+ *
644
+ * On click on image, more link & preview button.
645
+ */
646
+ _preview: function() {
647
 
648
+ event.preventDefault();
 
649
 
650
+ $this = jQuery(this).parents('.theme');
651
+ $this.addClass('theme-preview-on');
652
 
653
+ jQuery('html').addClass('astra-site-preview-on');
 
 
 
654
 
655
+ AstraSites._renderDemoPreview($this);
656
+ },
657
+
658
+ _scroll: function(event) {
659
+
660
+ var scrollDistance = jQuery(window).scrollTop();
661
+
662
+ var themesBottom = Math.abs(jQuery(window).height() - jQuery('.themes').offset().top - jQuery('.themes').height());
663
+ themesBottom = themesBottom * 20 / 100;
664
+
665
+ ajaxLoading = jQuery('body').data('scrolling');
666
+
667
+ if (scrollDistance > themesBottom && ajaxLoading == false) {
668
+ AstraSites._updatedPagedCount();
669
 
670
+ jQuery('body').data('scrolling', true);
671
 
672
+ var body = jQuery('body'),
673
+ id = body.attr('data-astra-site-category'),
674
+ search = body.attr('data-astra-demo-search'),
675
+ paged = body.attr('data-astra-demo-paged');
676
+
677
+ if (search !== '') {
678
+ id = '';
679