Astra Starter Sites - Version 1.0.13

Version Description

Download this release

Release Info

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

Code changes from version 1.0.12 to 1.0.13

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.12
7
* Author: Brainstorm Force
8
* Author URI: http://www.brainstormforce.com
9
* Text Domain: astra-sites
@@ -19,7 +19,7 @@ if ( ! defined( 'ASTRA_SITES_NAME' ) ) {
19
}
20
21
if ( ! defined( 'ASTRA_SITES_VER' ) ) {
22
- define( 'ASTRA_SITES_VER', '1.0.12' );
23
}
24
25
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.13
7
* Author: Brainstorm Force
8
* Author URI: http://www.brainstormforce.com
9
* Text Domain: astra-sites
19
}
20
21
if ( ! defined( 'ASTRA_SITES_VER' ) ) {
22
+ define( 'ASTRA_SITES_VER', '1.0.13' );
23
}
24
25
if ( ! defined( 'ASTRA_SITES_FILE' ) ) {
inc/assets/css/admin.css CHANGED
@@ -1,5 +1,5 @@
1
.wrap .status,
2
- .wrap .demo-type {
3
position: absolute;
4
z-index: 1;
5
color: #fff;
@@ -8,29 +8,29 @@
8
text-transform: uppercase;
9
}
10
.wrap .status,
11
- .wrap .demo-type.premium {
12
background: #0073aa;
13
}
14
.wrap .status {
15
left: -0.5em;
16
}
17
- .wrap .demo-type.premium {
18
right: -0.5em;
19
}
20
21
.wrap .status.publish,
22
- .wrap .demo-type.free {
23
display: none;
24
}
25
26
- .install-theme-info .demo-type {
27
display: none;
28
}
29
30
.theme {
31
position: relative;
32
}
33
- .wrap .astra-sites-preview .demo-type.premium {
34
display: block;
35
display: none;
36
position: relative;
@@ -48,7 +48,7 @@
48
width: 100%;
49
}
50
51
- .install-theme-info .demo-type.premium {
52
display: none;
53
}
54
@@ -220,4 +220,19 @@
220
margin-left: 0;
221
width: auto;
222
float: none;
223
}
1
.wrap .status,
2
+ .wrap .site-type {
3
position: absolute;
4
z-index: 1;
5
color: #fff;
8
text-transform: uppercase;
9
}
10
.wrap .status,
11
+ .wrap .site-type.premium {
12
background: #0073aa;
13
}
14
.wrap .status {
15
left: -0.5em;
16
}
17
+ .wrap .site-type.premium {
18
right: -0.5em;
19
}
20
21
.wrap .status.publish,
22
+ .wrap .site-type.free {
23
display: none;
24
}
25
26
+ .install-theme-info .site-type {
27
display: none;
28
}
29
30
.theme {
31
position: relative;
32
}
33
+ .wrap .astra-sites-preview .site-type.premium {
34
display: block;
35
display: none;
36
position: relative;
48
width: 100%;
49
}
50
51
+ .install-theme-info .site-type.premium {
52
display: none;
53
}
54
220
margin-left: 0;
221
width: auto;
222
float: none;
223
+ }
224
+ .filters-wrap {
225
+ display: inline-block;
226
+ }
227
+ .spinner-wrap {
228
+ text-align: center;
229
+ }
230
+ .spinner-wrap .spinner {
231
+ float: none;
232
+ }
233
+ .hide-me {
234
+ display: none !important;
235
+ }
236
+ #astra-sites-admin {
237
+ height: 100vh;
238
}
inc/assets/js/admin-page.js ADDED
@@ -0,0 +1,893 @@
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
+ (function($){
78
+
79
+ AstraSitesAdmin = {
80
+
81
+ init: function()
82
+ {
83
+ this._resetPagedCount();
84
+ this._bind();
85
+ },
86
+
87
+ /**
88
+ * Binds events for the Astra Sites.
89
+ *
90
+ * @since 1.0.0
91
+ * @access private
92
+ * @method _bind
93
+ */
94
+ _bind: function()
95
+ {
96
+ $( document ).on('click' , '.theme-browser .theme-screenshot, .theme-browser .more-details, .theme-browser .install-theme-preview', AstraSitesAdmin._preview);
97
+ $( document ).on('click' , '.next-theme', AstraSitesAdmin._nextTheme);
98
+ $( document ).on('click' , '.previous-theme', AstraSitesAdmin._previousTheme);
99
+ $( document ).on('click' , '.collapse-sidebar', AstraSitesAdmin._collapse);
100
+ $( document ).on('click' , '.astra-demo-import', AstraSitesAdmin._importDemo);
101
+ $( document ).on('click' , '.install-now', AstraSitesAdmin._installNow);
102
+ $( document ).on('click' , '.close-full-overlay', AstraSitesAdmin._fullOverlay);
103
+ $( document ).on('click' , '.activate-now', AstraSitesAdmin._activateNow);
104
+ $( document ).on('wp-plugin-installing' , AstraSitesAdmin._pluginInstalling);
105
+ $( document ).on('wp-plugin-install-error' , AstraSitesAdmin._installError);
106
+ $( document ).on('wp-plugin-install-success' , AstraSitesAdmin._installSuccess);
107
+
108
+ },
109
+
110
+ /**
111
+ * Install Now
112
+ */
113
+ _installNow: function(event)
114
+ {
115
+ event.preventDefault();
116
+
117
+ var $button = jQuery( event.target ),
118
+ $document = jQuery(document);
119
+
120
+ if ( $button.hasClass( 'updating-message' ) || $button.hasClass( 'button-disabled' ) ) {
121
+ return;
122
+ }
123
+
124
+ if ( wp.updates.shouldRequestFilesystemCredentials && ! wp.updates.ajaxLocked ) {
125
+ wp.updates.requestFilesystemCredentials( event );
126
+
127
+ $document.on( 'credential-modal-cancel', function() {
128
+ var $message = $( '.install-now.updating-message' );
129
+
130
+ $message
131
+ .removeClass( 'updating-message' )
132
+ .text( wp.updates.l10n.installNow );
133
+
134
+ wp.a11y.speak( wp.updates.l10n.updateCancel, 'polite' );
135
+ } );
136
+ }
137
+
138
+ wp.updates.installPlugin( {
139
+ slug: $button.data( 'slug' )
140
+ } );
141
+ },
142
+
143
+ /**
144
+ * Install Success
145
+ */
146
+ _installSuccess: function( event, response ) {
147
+
148
+ event.preventDefault();
149
+
150
+ var $message = jQuery( '.plugin-card-' + response.slug ).find( '.button' );
151
+ var $siteOptions = jQuery( '.wp-full-overlay-header').find('.astra-site-options').val();
152
+ var $enabledExtensions = jQuery( '.wp-full-overlay-header').find('.astra-enabled-extensions').val();
153
+
154
+ // Transform the 'Install' button into an 'Activate' button.
155
+ var $init = $message.data('init');
156
+
157
+ $message.removeClass( 'install-now installed button-disabled updated-message' )
158
+ .addClass('updating-message')
159
+ .html( astraSitesAdmin.strings.btnActivating );
160
+
161
+ // Reset not installed plugins list.
162
+ var pluginsList = astraSitesAdmin.requiredPlugins.notinstalled;
163
+ astraSitesAdmin.requiredPlugins.notinstalled = AstraSitesAdmin._removePluginFromQueue( response.slug, pluginsList );
164
+
165
+ // WordPress adds "Activate" button after waiting for 1000ms. So we will run our activation after that.
166
+ setTimeout( function() {
167
+
168
+ jQuery.ajax({
169
+ url: astraSitesAdmin.ajaxurl,
170
+ type: 'POST',
171
+ data: {
172
+ 'action' : 'astra-required-plugin-activate',
173
+ 'init' : $init,
174
+ 'options' : $siteOptions,
175
+ 'enabledExtensions' : $enabledExtensions,
176
+ },
177
+ })
178
+ .done(function (result) {
179
+
180
+ if( result.success ) {
181
+
182
+ var pluginsList = astraSitesAdmin.requiredPlugins.inactive;
183
+
184
+ // Reset not installed plugins list.
185
+ astraSitesAdmin.requiredPlugins.inactive = AstraSitesAdmin._removePluginFromQueue( response.slug, pluginsList );
186
+
187
+ $message.removeClass( 'button-primary install-now activate-now updating-message' )
188
+ .attr('disabled', 'disabled')
189
+ .addClass('disabled')
190
+ .text( astraSitesAdmin.strings.btnActive );
191
+
192
+ // Enable Demo Import Button
193
+ AstraSitesAdmin._enable_demo_import_button();
194
+
195
+ } else {
196
+
197
+ $message.removeClass( 'updating-message' );
198
+
199
+ }
200
+
201
+ });
202
+
203
+ }, 1200 );
204
+
205
+ },
206
+
207
+ /**
208
+ * Plugin Installation Error.
209
+ */
210
+ _installError: function( event, response ) {
211
+
212
+ var $card = jQuery( '.plugin-card-' + response.slug );
213
+
214
+ $card
215
+ .addClass( 'button-primary' )
216
+ .html( wp.updates.l10n.installNow );
217
+ },
218
+
219
+ /**
220
+ * Installing Plugin
221
+ */
222
+ _pluginInstalling: function(event, args) {
223
+ event.preventDefault();
224
+
225
+ var $card = jQuery( '.plugin-card-' + args.slug );
226
+ var $button = $card.find( '.button' );
227
+
228
+ $card.addClass('updating-message');
229
+ $button.addClass('already-started');
230
+
231
+ },
232
+
233
+ /**
234
+ * Render Demo Preview
235
+ */
236
+ _activateNow: function( eventn ) {
237
+
238
+ event.preventDefault();
239
+
240
+ var $button = jQuery( event.target ),
241
+ $init = $button.data( 'init' ),
242
+ $slug = $button.data( 'slug' );
243
+
244
+ if ( $button.hasClass( 'updating-message' ) || $button.hasClass( 'button-disabled' ) ) {
245
+ return;
246
+ }
247
+
248
+ $button.addClass('updating-message button-primary')
249
+ .html( astraSitesAdmin.strings.btnActivating );
250
+
251
+ var $siteOptions = jQuery( '.wp-full-overlay-header').find('.astra-site-options').val();
252
+ var $enabledExtensions = jQuery( '.wp-full-overlay-header').find('.astra-enabled-extensions').val();
253
+
254
+ jQuery.ajax({
255
+ url: astraSitesAdmin.ajaxurl,
256
+ type: 'POST',
257
+ data: {
258
+ 'action' : 'astra-required-plugin-activate',
259
+ 'init' : $init,
260
+ 'options' : $siteOptions,
261
+ 'enabledExtensions' : $enabledExtensions,
262
+ },
263
+ })
264
+ .done(function (result) {
265
+
266
+ if( result.success ) {
267
+
268
+ var pluginsList = astraSitesAdmin.requiredPlugins.inactive;
269
+
270
+ // Reset not installed plugins list.
271
+ astraSitesAdmin.requiredPlugins.inactive = AstraSitesAdmin._removePluginFromQueue( $slug, pluginsList );
272
+
273
+ $button.removeClass( 'button-primary install-now activate-now updating-message' )
274
+ .attr('disabled', 'disabled')
275
+ .addClass('disabled')
276
+ .text( astraSitesAdmin.strings.btnActive );
277
+
278
+ // Enable Demo Import Button
279
+ AstraSitesAdmin._enable_demo_import_button();
280
+
281
+ }
282
+
283
+ })
284
+ .fail(function () {
285
+ });
286
+
287
+ },
288
+
289
+ /**
290
+ * Full Overlay
291
+ */
292
+ _fullOverlay: function (event) {
293
+ event.preventDefault();
294
+
295
+ jQuery('.theme-install-overlay').css('display', 'none');
296
+ jQuery('.theme-install-overlay').remove();
297
+ jQuery('.theme-preview-on').removeClass('theme-preview-on');
298
+ jQuery('html').removeClass('astra-site-preview-on');
299
+ },
300
+
301
+ /**
302
+ * Bulk Plugin Active & Install
303
+ */
304
+ _bulkPluginInstallActivate: function()
305
+ {
306
+ if( 0 === astraSitesAdmin.requiredPlugins.length ) {
307
+ return;
308
+ }
309
+
310
+ jQuery('.required-plugins')
311
+ .find('.install-now')
312
+ .addClass( 'updating-message' )
313
+ .removeClass( 'install-now' )
314
+ .text( wp.updates.l10n.installing );
315
+
316
+ jQuery('.required-plugins')
317
+ .find('.activate-now')
318
+ .addClass('updating-message')
319
+ .removeClass( 'activate-now' )
320
+ .html( astraSitesAdmin.strings.btnActivating );
321
+
322
+ var not_installed = astraSitesAdmin.requiredPlugins.notinstalled || '';
323
+ var activate_plugins = astraSitesAdmin.requiredPlugins.inactive || '';
324
+
325
+ // First Install Bulk.
326
+ if( not_installed.length > 0 ) {
327
+ AstraSitesAdmin._installAllPlugins( not_installed );
328
+ }
329
+
330
+ // Second Activate Bulk.
331
+ if( activate_plugins.length > 0 ) {
332
+ AstraSitesAdmin._activateAllPlugins( activate_plugins );
333
+ }
334
+
335
+ },
336
+
337
+ /**
338
+ * Activate All Plugins.
339
+ */
340
+ _activateAllPlugins: function( activate_plugins ) {
341
+
342
+ // Process of cloud templates - (download, remove & fetch).
343
+ AstraSitesAjaxQueue.run();
344
+
345
+ jQuery.each( activate_plugins, function(index, single_plugin) {
346
+
347
+ var $card = jQuery( '.plugin-card-' + single_plugin.slug ),
348
+ $button = $card.find('.button'),
349
+ $siteOptions = jQuery( '.wp-full-overlay-header').find('.astra-site-options').val(),
350
+ $enabledExtensions = jQuery( '.wp-full-overlay-header').find('.astra-enabled-extensions').val();
351
+
352
+ $button.addClass('updating-message');
353
+
354
+ AstraSitesAjaxQueue.add({
355
+ url: astraSitesAdmin.ajaxurl,
356
+ type: 'POST',
357
+ data: {
358
+ 'action' : 'astra-required-plugin-activate',
359
+ 'init' : single_plugin.init,
360
+ 'options' : $siteOptions,
361
+ 'enabledExtensions' : $enabledExtensions,
362
+ },
363
+ success: function( result ){
364
+
365
+ if( result.success ) {
366
+
367
+ var $card = jQuery( '.plugin-card-' + single_plugin.slug );
368
+ var $button = $card.find( '.button' );
369
+ if( ! $button.hasClass('already-started') ) {
370
+ var pluginsList = astraSitesAdmin.requiredPlugins.inactive;
371
+
372
+ // Reset not installed plugins list.
373
+ astraSitesAdmin.requiredPlugins.inactive = AstraSitesAdmin._removePluginFromQueue( single_plugin.slug, pluginsList );
374
+ }
375
+
376
+ $button.removeClass( 'button-primary install-now activate-now updating-message' )
377
+ .attr('disabled', 'disabled')
378
+ .addClass('disabled')
379
+ .text( astraSitesAdmin.strings.btnActive );
380
+
381
+ // Enable Demo Import Button
382
+ AstraSitesAdmin._enable_demo_import_button();
383
+ }
384
+ }
385
+ });
386
+ });
387
+ },
388
+
389
+ /**
390
+ * Install All Plugins.
391
+ */
392
+ _installAllPlugins: function( not_installed ) {
393
+
394
+ jQuery.each( not_installed, function(index, single_plugin) {
395
+
396
+ var $card = jQuery( '.plugin-card-' + single_plugin.slug ),
397
+ $button = $card.find('.button');
398
+
399
+ if( ! $button.hasClass('already-started') ) {
400
+
401
+ // Add each plugin activate request in Ajax queue.
402
+ // @see wp-admin/js/updates.js
403
+ wp.updates.queue.push( {
404
+ action: 'install-plugin', // Required action.
405
+ data: {
406
+ slug: single_plugin.slug
407
+ }
408
+ } );
409
+ }
410
+ });
411
+
412
+ // Required to set queue.
413
+ wp.updates.queueChecker();
414
+ },
415
+
416
+ /**
417
+ * Fires when a nav item is clicked.
418
+ *
419
+ * @since 1.0
420
+ * @access private
421
+ * @method _importDemo
422
+ */
423
+ _importDemo: function()
424
+ {
425
+ var $this = jQuery(this),
426
+ $theme = $this.closest('.astra-sites-preview').find('.wp-full-overlay-header'),
427
+ apiURL = $theme.data('demo-api') || '',
428
+ plugins = $theme.data('required-plugins');
429
+
430
+ var disabled = $this.attr('data-import');
431
+
432
+ if ( typeof disabled !== 'undefined' && disabled === 'disabled' ) {
433
+
434
+ $this.addClass('updating-message')
435
+ .text( wp.updates.l10n.installing );
436
+
437
+ /**
438
+ * Process Bulk Plugin Install & Activate
439
+ */
440
+ AstraSitesAdmin._bulkPluginInstallActivate();
441
+
442
+ return;
443
+ }
444
+
445
+ // Proceed?
446
+ if( ! confirm( astraSitesAdmin.strings.importWarning ) ) {
447
+ return;
448
+ }
449
+
450
+ jQuery('.astra-demo-import').attr('data-import', 'disabled')
451
+ .addClass('updating-message installing')
452
+ .text( astraSitesAdmin.strings.importingDemo );
453
+
454
+ $this.closest('.theme').focus();
455
+
456
+ var $theme = $this.closest('.astra-sites-preview').find('.wp-full-overlay-header');
457
+
458
+ var apiURL = $theme.data('demo-api') || '';
459
+
460
+ jQuery.ajax({
461
+ url: astraSitesAdmin.ajaxurl,
462
+ type: 'POST',
463
+ dataType: 'json',
464
+ data: {
465
+ action: 'astra-import-demo',
466
+ api_url: apiURL
467
+ },
468
+ })
469
+ .done(function ( demos ) {
470
+
471
+ // Success?
472
+ if( demos.success ) {
473
+ jQuery('.astra-demo-import').removeClass('updating-message installing')
474
+ .removeAttr('data-import')
475
+ .addClass('view-site')
476
+ .removeClass('astra-demo-import')
477
+ .text( astraSitesAdmin.strings.viewSite )
478
+ .attr('target', '_blank')
479
+ .append('<i class="dashicons dashicons-external"></i>')
480
+ .attr('href', astraSitesAdmin.siteURL );
481
+
482
+ } else {
483
+
484
+ var output = '<div class="astra-api-error notice notice-error notice-alt is-dismissible">';
485
+ output += ' <p>'+demos.message+'</p>';
486
+ output += ' <button type="button" class="notice-dismiss">';
487
+ output += ' <span class="screen-reader-text">'+commonL10n.dismiss+'</span>';
488
+ output += ' </button>';
489
+ output += '</div>';
490
+
491
+ jQuery('.install-theme-info').prepend( output );
492
+
493
+ // !important to add trigger.
494
+ // Which reinitialize the dismiss error message events.
495
+ jQuery(document).trigger('wp-updates-notice-added');
496
+ }
497
+
498
+ })
499
+ .fail(function ( demos ) {
500
+ jQuery('.astra-demo-import').removeClass('updating-message installing')
501
+ .removeAttr('data-import')
502
+ .addClass('view-site')
503
+ .removeClass('astra-demo-import')
504
+ .attr('target', '_blank')
505
+ .attr('href', astraSitesAdmin.strings.importFailedURL );
506
+
507
+ jQuery('.wp-full-overlay-header .view-site').text( astraSitesAdmin.strings.importFailedBtnSmall ).append('<i class="dashicons dashicons-external"></i>');
508
+ jQuery('.footer-import-button-wrap .view-site').text( astraSitesAdmin.strings.importFailedBtnLarge ).append('<i class="dashicons dashicons-external"></i>');
509
+ });
510
+ },
511
+
512
+ /**
513
+ * Collapse Sidebar.
514
+ */
515
+ _collapse: function() {
516
+ event.preventDefault();
517
+
518
+ overlay = jQuery('.wp-full-overlay');
519
+
520
+ if (overlay.hasClass('expanded')) {
521
+ overlay.removeClass('expanded');
522
+ overlay.addClass('collapsed');
523
+ return;
524
+ }
525
+
526
+ if (overlay.hasClass('collapsed')) {
527
+ overlay.removeClass('collapsed');
528
+ overlay.addClass('expanded');
529
+ return;
530
+ }
531
+ },
532
+
533
+ /**
534
+ * Previous Theme.
535
+ */
536
+ _previousTheme: function (event) {
537
+ event.preventDefault();
538
+
539
+ currentDemo = jQuery('.theme-preview-on');
540
+ currentDemo.removeClass('theme-preview-on');
541
+ prevDemo = currentDemo.prev('.theme');
542
+ prevDemo.addClass('theme-preview-on');
543
+
544
+ AstraSitesAdmin._renderDemoPreview(prevDemo);
545
+ },
546
+
547
+ /**
548
+ * Next Theme.
549
+ */
550
+ _nextTheme: function (event) {
551
+ event.preventDefault();
552
+ currentDemo = jQuery('.theme-preview-on')
553
+ currentDemo.removeClass('theme-preview-on');
554
+ nextDemo = currentDemo.next('.theme');
555
+ nextDemo.addClass('theme-preview-on');
556
+
557
+ AstraSitesAdmin._renderDemoPreview( nextDemo );
558
+ },
559
+
560
+ /**
561
+ * Individual Site Preview
562
+ *
563
+ * On click on image, more link & preview button.
564
+ */
565
+ _preview: function( event ) {
566
+
567
+ event.preventDefault();
568
+
569
+ var self = jQuery(this).parents('.theme');
570
+ self.addClass('theme-preview-on');
571
+
572
+ jQuery('html').addClass('astra-site-preview-on');
573
+
574
+ AstraSitesAdmin._renderDemoPreview( self );
575
+ },
576
+
577
+ /**
578
+ * Check Next Previous Buttons.
579
+ */
580
+ _checkNextPrevButtons: function() {
581
+ currentDemo = jQuery('.theme-preview-on');
582
+ nextDemo = currentDemo.nextAll('.theme').length;
583
+ prevDemo = currentDemo.prevAll('.theme').length;
584
+
585
+ if (nextDemo == 0) {
586
+ jQuery('.next-theme').addClass('disabled');
587
+ } else if (nextDemo != 0) {
588
+ jQuery('.next-theme').removeClass('disabled');
589
+ }
590
+
591
+ if (prevDemo == 0) {
592
+ jQuery('.previous-theme').addClass('disabled');
593
+ } else if (prevDemo != 0) {
594
+ jQuery('.previous-theme').removeClass('disabled');
595
+ }
596
+
597
+ return;
598
+ },
599
+
600
+ /**
601
+ * Render Demo Preview
602
+ */
603
+ _renderDemoPreview: function(anchor) {
604
+
605
+ var demoId = anchor.data('id') || '',
606
+ apiURL = anchor.data('demo-api') || '',
607
+ demoType = anchor.data('demo-type') || '',
608
+ demoURL = anchor.data('demo-url') || '',
609
+ screenshot = anchor.data('screenshot') || '',
610
+ demo_name = anchor.data('demo-name') || '',
611
+ demo_slug = anchor.data('demo-slug') || '',
612
+ content = anchor.data('content') || '',
613
+ requiredPlugins = anchor.data('required-plugins') || '',
614
+ astraSiteOptions = anchor.find('.astra-site-options').val() || '';
615
+ astraEnabledExtensions = anchor.find('.astra-enabled-extensions').val() || '';
616
+
617
+ var template = wp.template('astra-site-preview');
618
+
619
+ templateData = [{
620
+ id : demoId,
621
+ astra_demo_type : demoType,
622
+ astra_demo_url : demoURL,
623
+ demo_api : apiURL,
624
+ screenshot : screenshot,
625
+ demo_name : demo_name,
626
+ slug : demo_slug,
627
+ content : content,
628
+ required_plugins : JSON.stringify(requiredPlugins),
629
+ astra_site_options : astraSiteOptions,
630
+ astra_enabled_extensions : astraEnabledExtensions,
631
+ }];
632
+
633
+ // delete any earlier fullscreen preview before we render new one.
634
+ jQuery('.theme-install-overlay').remove();
635
+
636
+ jQuery('#astra-sites-menu-page').append(template(templateData[0]));
637
+ jQuery('.theme-install-overlay').css('display', 'block');
638
+ AstraSitesAdmin._checkNextPrevButtons();
639
+
640
+ var desc = jQuery('.theme-details');
641
+ var descHeight = parseInt( desc.outerHeight() );
642
+ var descBtn = jQuery('.theme-details-read-more');
643
+
644
+ if( jQuery.isArray( requiredPlugins ) ) {
645
+
646
+ if( descHeight >= 55 ) {
647
+
648
+ // Show button.
649
+ descBtn.css( 'display', 'inline-block' );
650
+
651
+ // Set height upto 3 line.
652
+ desc.css( 'height', 57 );
653
+
654
+ // Button Click.
655
+ descBtn.click(function(event) {
656
+
657
+ if( descBtn.hasClass('open') ) {
658
+ desc.animate({ height: 57 },
659
+ 300, function() {
660
+ descBtn.removeClass('open');
661
+ descBtn.html( astraSitesAdmin.strings.DescExpand );
662
+ });
663
+ } else {
664
+ desc.animate({ height: descHeight },
665
+ 300, function() {
666
+ descBtn.addClass('open');
667
+ descBtn.html( astraSitesAdmin.strings.DescCollapse );
668
+ });
669
+ }
670
+
671
+ });
672
+ }
673
+
674
+ // or
675
+ var $pluginsFilter = jQuery( '#plugin-filter' ),
676
+ data = {
677
+ _ajax_nonce : astraSitesAdmin._ajax_nonce,
678
+ required_plugins : requiredPlugins
679
+ };
680
+
681
+ jQuery('.required-plugins').addClass('loading').html('<span class="spinner is-active"></span>');
682
+
683
+ wp.ajax.post( 'astra-required-plugins', data ).done( function( response ) {
684
+
685
+ // Remove loader.
686
+ jQuery('.required-plugins').removeClass('loading').html('');
687
+
688
+ /**
689
+ * Count remaining plugins.
690
+ * @type number
691
+ */
692
+ var remaining_plugins = 0;
693
+
694
+ /**
695
+ * Not Installed
696
+ *
697
+ * List of not installed required plugins.
698
+ */
699
+ if ( typeof response.notinstalled !== 'undefined' ) {
700
+
701
+ // Add not have installed plugins count.
702
+ remaining_plugins += parseInt( response.notinstalled.length );
703
+
704
+ jQuery( response.notinstalled ).each(function( index, plugin ) {
705
+
706
+ var output = '<div class="plugin-card ';
707
+ output += ' plugin-card-'+plugin.slug+'"';
708
+ output += ' data-slug="'+plugin.slug+'"';
709
+ output += ' data-init="'+plugin.init+'">';
710
+ output += ' <span class="title">'+plugin.name+'</span>';
711
+ output += ' <button class="button install-now"';
712
+ output += ' data-init="' + plugin.init + '"';
713
+ output += ' data-slug="' + plugin.slug + '"';
714
+ output += ' data-name="' + plugin.name + '">';
715
+ output += wp.updates.l10n.installNow;
716
+ output += ' </button>';
717
+ // output += ' <span class="dashicons-no dashicons"></span>';
718
+ output += '</div>';
719
+
720
+ jQuery('.required-plugins').append(output);
721
+
722
+ });
723
+ }
724
+
725
+ /**
726
+ * Inactive
727
+ *
728
+ * List of not inactive required plugins.
729
+ */
730
+ if ( typeof response.inactive !== 'undefined' ) {
731
+
732
+ // Add inactive plugins count.
733
+ remaining_plugins += parseInt( response.inactive.length );
734
+
735
+ jQuery( response.inactive ).each(function( index, plugin ) {
736
+
737
+ var output = '<div class="plugin-card ';
738
+ output += ' plugin-card-'+plugin.slug+'"';
739
+ output += ' data-slug="'+plugin.slug+'"';
740
+ output += ' data-init="'+plugin.init+'">';
741
+ output += ' <span class="title">'+plugin.name+'</span>';
742
+ output += ' <button class="button activate-now button-primary"';
743
+ output += ' data-init="' + plugin.init + '"';
744
+ output += ' data-slug="' + plugin.slug + '"';
745
+ output += ' data-name="' + plugin.name + '">';
746
+ output += wp.updates.l10n.activatePlugin;
747
+ output += ' </button>';
748
+ // output += ' <span class="dashicons-no dashicons"></span>';
749
+ output += '</div>';
750
+
751
+ jQuery('.required-plugins').append(output);
752
+
753
+ });
754
+ }
755
+
756
+ /**
757
+ * Active
758
+ *
759
+ * List of not active required plugins.
760
+ */
761
+ if ( typeof response.active !== 'undefined' ) {
762
+
763
+ jQuery( response.active ).each(function( index, plugin ) {
764
+
765
+ var output = '<div class="plugin-card ';
766
+ output += ' plugin-card-'+plugin.slug+'"';
767
+ output += ' data-slug="'+plugin.slug+'"';
768
+ output += ' data-init="'+plugin.init+'">';
769
+ output += ' <span class="title">'+plugin.name+'</span>';
770
+ output += ' <button class="button disabled"';
771
+ output += ' data-slug="' + plugin.slug + '"';
772
+ output += ' data-name="' + plugin.name + '">';
773
+ output += astraSitesAdmin.strings.btnActive;
774
+ output += ' </button>';
775
+ // output += ' <span class="dashicons-yes dashicons"></span>';
776
+ output += '</div>';
777
+
778
+ jQuery('.required-plugins').append(output);
779
+
780
+ });
781
+ }
782
+
783
+ /**
784
+ * Enable Demo Import Button
785
+ * @type number
786
+ */
787
+ astraSitesAdmin.requiredPlugins = response;
788
+ AstraSitesAdmin._enable_demo_import_button();
789
+
790
+ } );
791
+
792
+ } else {
793
+
794
+ // Enable Demo Import Button
795
+ AstraSitesAdmin._enable_demo_import_button( demoType );
796
+ jQuery('.required-plugins-wrap').remove();
797
+ }
798
+
799
+ return;
800
+ },
801
+
802
+ /**
803
+ * Enable Demo Import Button.
804
+ */
805
+ _enable_demo_import_button: function( type = 'free' ) {
806
+
807
+ switch( type ) {
808
+
809
+ case 'free':
810
+ var all_buttons = parseInt( jQuery( '.plugin-card .button' ).length ) || 0,
811
+ disabled_buttons = parseInt( jQuery( '.plugin-card .button.disabled' ).length ) || 0;
812
+
813
+ if( all_buttons === disabled_buttons ) {
814
+
815
+ jQuery('.astra-demo-import')
816
+ .removeAttr('data-import')
817
+ .removeClass('updating-message')
818
+ .addClass('button-primary')
819
+ .text( astraSitesAdmin.strings.importDemo );
820
+ }
821
+
822
+ break;
823
+
824
+ case 'upgrade':
825
+ var demo_slug = jQuery('.wp-full-overlay-header').attr('data-demo-slug');
826
+
827
+ jQuery('.astra-demo-import')
828
+ .addClass('go-pro button-primary')
829
+ .removeClass('astra-demo-import')
830
+ .attr('target', '_blank')
831
+ .attr('href', astraSitesAdmin.getUpgradeURL + demo_slug )
832
+ .text( astraSitesAdmin.getUpgradeText )
833
+ .append('<i class="dashicons dashicons-external"></i>');
834
+ break;
835
+
836
+ default:
837
+ var demo_slug = jQuery('.wp-full-overlay-header').attr('data-demo-slug');
838
+
839
+ jQuery('.astra-demo-import')
840
+ .addClass('go-pro button-primary')
841
+ .removeClass('astra-demo-import')
842
+ .attr('target', '_blank')
843
+ .attr('href', astraSitesAdmin.getProURL )
844
+ .text( astraSitesAdmin.getProText )
845
+ .append('<i class="dashicons dashicons-external"></i>');
846
+ break;
847
+ }
848
+
849
+ },
850
+
851
+ /**
852
+ * Update Page Count.
853
+ */
854
+ _updatedPagedCount: function() {
855
+ paged = parseInt(jQuery('body').attr('data-astra-demo-paged'));
856
+ jQuery('body').attr('data-astra-demo-paged', paged + 1);
857
+ window.setTimeout(function () {
858
+ jQuery('body').data('scrolling', false);
859
+ }, 800);
860
+ },
861
+
862
+ /**
863
+ * Reset Page Count.
864
+ */
865
+ _resetPagedCount: function() {
866
+
867
+ $('body').addClass('loading-content');
868
+ $('body').attr('data-astra-demo-last-request', '1');
869
+ $('body').attr('data-astra-demo-paged', '1');
870
+ $('body').attr('data-astra-demo-search', '');
871
+ $('body').attr('data-scrolling', false);
872
+
873
+ },
874
+
875
+ /**
876
+ * Remove plugin from the queue.
877
+ */
878
+ _removePluginFromQueue: function( removeItem, pluginsList ) {
879
+ return jQuery.grep(pluginsList, function( value ) {
880
+ return value.slug != removeItem;
881
+ });
882
+ }
883
+
884
+ };
885
+
886
+ /**
887
+ * Initialize AstraSitesAdmin
888
+ */
889
+ $(function(){
890
+ AstraSitesAdmin.init();
891
+ });
892
+
893
+ })(jQuery);
inc/assets/js/astra-sites-api.js ADDED
@@ -0,0 +1,59 @@
1
+
2
+ (function($){
3
+
4
+ AstraSitesAPI = {
5
+
6
+ _api_url : astraSitesApi.ApiURL,
7
+
8
+ /**
9
+ * API Request
10
+ */
11
+ _api_request: function( args ) {
12
+
13
+ // Set API Request Data.
14
+ var data = {
15
+ url: AstraSitesAPI._api_url + args.slug,
16
+ cache: false,
17
+ };
18
+
19
+ // Set API Request Header.
20
+ if( astraRenderGrid.headers ) {
21
+ data.headers = astraRenderGrid.headers;
22
+ }
23
+
24
+ $.ajax( data )
25
+ .done(function( items, status, XHR ) {
26
+
27
+ if( 'success' === status && XHR.getResponseHeader('x-wp-total') ) {
28
+
29
+ var data = {
30
+ args : args,
31
+ items : items,
32
+ items_count : XHR.getResponseHeader('x-wp-total') || 0,
33
+ };
34
+
35
+ if( 'undefined' !== args.trigger && '' !== args.trigger ) {
36
+ $(document).trigger( args.trigger, [data] );
37
+ }
38
+
39
+ } else {
40
+ $(document).trigger( 'astra-sites-api-request-error' );
41
+ }
42
+
43
+ })
44
+ .fail(function( jqXHR, textStatus ) {
45
+
46
+ $(document).trigger( 'astra-sites-api-request-fail' );
47
+
48
+ })
49
+ .always(function() {
50
+
51
+ $(document).trigger( 'astra-sites-api-request-always' );
52
+
53
+ });
54
+
55
+ },
56
+
57
+ };
58
+
59
+ })(jQuery);
inc/assets/js/render-grid.js ADDED
@@ -0,0 +1,502 @@
1
+ (function($){
2
+ AstraRender = {
3
+
4
+ _ref : null,
5
+
6
+ /**
7
+ * _api_params = {
8
+ * 'search' : '',
9
+ * 'per_page' : '',
10
+ * 'astra-site-category' : '',
11
+ * 'astra-site-page-builder' : '',
12
+ * 'page' : '',
13
+ * };
14
+ *
15
+ * E.g. per_page=<page-id>&astra-site-category=<category-ids>&astra-site-page-builder=<page-builder-ids>&page=<page>
16
+ */
17
+ _api_params : {},
18
+ _breakpoint : 768,
19
+
20
+ init: function()
21
+ {
22
+ this._resetPagedCount();
23
+ this._bind();
24
+ this._showFilters();
25
+ },
26
+
27
+ /**
28
+ * Binds events for the Astra Sites.
29
+ *
30
+ * @since 1.0.0
31
+ * @access private
32
+ * @method _bind
33
+ */
34
+ _bind: function()
35
+ {
36
+ $( document ).on('astra-sites-api-request-fail' , AstraRender._apiFailed );
37
+ $( document ).on('astra-api-post-loaded-on-scroll' , AstraRender._reinitGridScrolled );
38
+ $( document ).on('astra-api-post-loaded' , AstraRender._reinitGrid );
39
+ $( document ).on('astra-api-category-loaded' , AstraRender._addFilters );
40
+ $( document ).on('astra-api-all-category-loaded' , AstraRender._loadFirstGrid );
41
+
42
+ // Event's for API request.
43
+ $( document ).on('click' , '.filter-links a', AstraRender._filterClick );
44
+ $( document ).on('keyup input' , '#wp-filter-search-input', AstraRender._search );
45
+ $( document ).on('scroll' , AstraRender._scroll );
46
+
47
+ },
48
+
49
+ /**
50
+ * On Filter Clicked
51
+ *
52
+ * Prepare Before API Request:
53
+ * - Empty search input field to avoid search term on filter click.
54
+ * - Remove Inline Height
55
+ * - Added 'hide-me' class to hide the 'No more sites!' string.
56
+ * - Added 'loading-content' for body.
57
+ * - Show spinner.
58
+ */
59
+ _filterClick: function( event ) {
60
+
61
+ event.preventDefault();
62
+
63
+ $(this).parents('.filter-links').find('a').removeClass('current');
64
+ $(this).addClass('current');
65
+
66
+ // Prepare Before Search.
67
+ $('#wp-filter-search-input').val('');
68
+ $('#astra-sites').hide().css('height', '');
69
+ $('body').addClass('loading-content');
70
+ $('#astra-sites-admin').find('.spinner').removeClass('hide-me');
71
+
72
+ // Show sites.
73
+ AstraRender._showSites();
74
+ },
75
+
76
+ /**
77
+ * Search Site.
78
+ *
79
+ * Prepare Before API Request:
80
+ * - Remove Inline Height
81
+ * - Added 'hide-me' class to hide the 'No more sites!' string.
82
+ * - Added 'loading-content' for body.
83
+ * - Show spinner.
84
+ */
85
+ _search: function() {
86
+
87
+ $this = jQuery('#wp-filter-search-input').val();
88
+
89
+ // Prepare Before Search.
90
+ $('#astra-sites').hide().css('height', '');
91
+ $('body').addClass('loading-content');
92
+ $('#astra-sites-admin').find('.spinner').removeClass('hide-me');
93
+
94
+ window.clearTimeout(AstraRender._ref);
95
+ AstraRender._ref = window.setTimeout(function () {
96
+ AstraRender._ref = null;
97
+
98
+ AstraRender._resetPagedCount();
99
+ jQuery('body').addClass('loading-content');
100
+ jQuery('body').attr('data-astra-demo-search', $this);
101
+
102
+ AstraRender._showSites();
103
+
104
+ }, 500);
105
+
106
+ },
107
+
108
+ /**
109
+ * On Scroll
110
+ */
111
+ _scroll: function(event) {
112
+
113
+ if( ! $('body').hasClass('listed-all-sites') ) {
114
+
115
+ var scrollDistance = jQuery(window).scrollTop();
116
+
117
+ var themesBottom = Math.abs(jQuery(window).height() - jQuery('#astra-sites').offset().top - jQuery('#astra-sites').height());
118
+ themesBottom = themesBottom - 100;
119
+
120
+ ajaxLoading = jQuery('body').data('scrolling');
121
+
122
+ if (scrollDistance > themesBottom && ajaxLoading == false) {
123
+ AstraRender._updatedPagedCount();
124
+
125
+ if( ! $('#astra-sites .no-themes').length ) {
126
+ $('#astra-sites-admin').find('.spinner').addClass('is-active');
127
+ }
128
+
129
+ jQuery('body').data('scrolling', true);
130
+
131
+ /**
132
+ * @see _reinitGridScrolled() which called in trigger 'astra-api-post-loaded-on-scroll'
133
+ */
134
+ AstraRender._showSites( false, 'astra-api-post-loaded-on-scroll' );
135
+ }
136
+ }
137
+ },
138
+
139
+ /**
140
+ * Lazy Load Images
141
+ *
142
+ * @see http://jquery.eisbehr.de/lazy/#features
143
+ */
144
+ _lazyLoad: function() {
145
+
146
+ $('#astra-sites img').Lazy({
147
+ effect: 'fadeIn',
148
+ });
149
+ },
150
+
151
+ _apiAddParam_status: function() {
152
+ if( astraRenderGrid.sites && astraRenderGrid.sites.status ) {
153
+ AstraRender._api_params['status'] = astraRenderGrid.sites.status;
154
+ }
155
+ },
156
+
157
+ // Add 'search'
158
+ _apiAddParam_search: function() {
159
+ var search_val = jQuery('#wp-filter-search-input').val() || '';
160
+ if( '' !== search_val ) {
161
+ AstraRender._api_params['search'] = search_val;
162
+ }
163
+ },
164
+
165
+ _apiAddParam_per_page: function() {
166
+ // Add 'per_page'
167
+ var per_page_val = 3;
168
+ if( astraRenderGrid.sites && astraRenderGrid.sites["par-page"] ) {
169
+ per_page_val = parseInt( astraRenderGrid.sites["par-page"] );
170
+ }
171
+ AstraRender._api_params['per_page'] = per_page_val;
172
+ },
173
+
174
+ _apiAddParam_astra_site_category: function() {
175
+ // Add 'astra-site-category'
176
+ var selected_category_id = jQuery('.filter-links.astra-site-category').find('.current').data('group') || '';
177
+ if( '' !== selected_category_id && 'all' !== selected_category_id ) {
178
+ AstraRender._api_params['astra-site-category'] = selected_category_id;
179
+ } else if( 'astra-site-category' in astraRenderGrid.settings ) {
180
+
181
+ if( $.inArray('all', astraRenderGrid.settings['astra-site-category']) !== -1 ) {
182
+ var storedCategories = astraRenderGrid.settings['astra-site-category'];
183
+ storedCategories = jQuery.grep(storedCategories, function(value) {
184
+ return value != 'all';
185
+ });
186
+ AstraRender._api_params['astra-site-category'] = storedCategories.join(',');
187
+ }
188
+ }
189
+ },
190
+
191
+ _apiAddParam_astra_site_page_builder: function() {
192
+ // Add 'astra-site-page-builder'
193
+ var selected_page_builder_id = jQuery('.filter-links.astra-site-page-builder').find('.current').data('group') || '';
194
+ if( '' !== selected_page_builder_id && 'all' !== selected_page_builder_id ) {
195
+ AstraRender._api_params['astra-site-page-builder'] = selected_page_builder_id;
196
+ } else if( 'astra-site-page-builder' in astraRenderGrid.settings ) {
197
+ if( $.inArray('all', astraRenderGrid.settings['astra-site-page-builder']) !== -1 ) {
198
+ var storedBuilders = astraRenderGrid.settings['astra-site-page-builder'];
199
+ storedBuilders = jQuery.grep(storedBuilders, function(value) {
200
+ return value != 'all';
201
+ });
202
+ AstraRender._api_params['astra-site-page-builder'] = storedBuilders.join(',');
203
+ }
204
+ }
205
+ },
206
+
207
+ _apiAddParam_page: function() {
208
+ // Add 'page'
209
+ var page_val = parseInt(jQuery('body').attr('data-astra-demo-paged')) || 1;
210
+ AstraRender._api_params['page'] = page_val;
211
+ },
212
+
213
+ _apiAddParam_purchase_key: function() {
214
+ if( astraRenderGrid.sites && astraRenderGrid.sites.purchase_key ) {
215
+ AstraRender._api_params['purchase_key'] = astraRenderGrid.sites.purchase_key;
216
+ }
217
+ },
218
+
219
+ _apiAddParam_site_url: function() {
220
+ if( astraRenderGrid.sites && astraRenderGrid.sites.site_url ) {
221
+ AstraRender._api_params['site_url'] = astraRenderGrid.sites.site_url;
222
+ }
223
+ },
224
+
225
+ /**
226
+ * Show Sites
227
+ *
228
+ * Params E.g. per_page=<page-id>&astra-site-category=<category-ids>&astra-site-page-builder=<page-builder-ids>&page=<page>
229
+ *
230
+ * @param {Boolean} resetPagedCount Reset Paged Count.
231
+ * @param {String} trigger Filtered Trigger.
232
+ */
233
+ _showSites: function( resetPagedCount, trigger ) {
234
+
235
+ if( undefined === resetPagedCount ) {
236
+ resetPagedCount = true
237
+ }
238
+
239
+ if( undefined === trigger ) {
240
+ trigger = 'astra-api-post-loaded';
241
+ }
242
+
243
+ if( resetPagedCount ) {
244
+ AstraRender._resetPagedCount();
245
+ }
246
+
247
+ // Add Params for API request.
248
+ AstraRender._api_params = {};
249
+
250
+ AstraRender._apiAddParam_status();
251
+ AstraRender._apiAddParam_search();
252
+ AstraRender._apiAddParam_per_page();
253
+ AstraRender._apiAddParam_astra_site_category();
254
+ AstraRender._apiAddParam_astra_site_page_builder();
255
+ AstraRender._apiAddParam_page();
256
+ AstraRender._apiAddParam_site_url();
257
+ AstraRender._apiAddParam_purchase_key();
258
+
259
+ // API Request.
260
+ var api_post = {
261
+ slug: 'astra-sites?' + decodeURIComponent( $.param( AstraRender._api_params ) ),
262
+ trigger: trigger,
263
+ };
264
+
265
+ AstraSitesAPI._api_request( api_post );
266
+
267
+ },
268
+
269
+ /**
270
+ * Get Category Params
271
+ *
272
+ * @param {string} category_slug Category Slug.
273
+ * @return {mixed} Add `include=<category-ids>` in API request.
274
+ */
275
+ _getCategoryParams: function( category_slug ) {
276
+
277
+ // Has category?
278
+ if( category_slug in astraRenderGrid.settings ) {
279
+
280
+ var storedBuilders = astraRenderGrid.settings[ category_slug ];
281
+
282
+ // Remove `all` from stored list?
283
+ storedBuilders = jQuery.grep(storedBuilders, function(value) {
284
+ return value != 'all';
285
+ });
286
+
287
+ return '?include='+storedBuilders.join(',');
288
+ }
289
+
290
+ return '';
291
+ },
292
+
293
+ /**
294
+ * Get All Select Status
295
+ *
296
+ * @param {string} category_slug Category Slug.
297
+ * @return {boolean} Return true/false.
298
+ */
299
+ _getCategoryAllSelectStatus: function( category_slug ) {
300
+
301
+ // Has category?
302
+ if( category_slug in astraRenderGrid.settings ) {
303
+
304
+ // Has `all` in stored list?
305
+ if( $.inArray('all', astraRenderGrid.settings[ category_slug ]) === -1 ) {
306
+ return false;
307
+ }
308
+ }
309
+
310
+ return true;
311
+ },
312
+
313
+ /**
314
+ * Show Filters
315
+ */
316
+ _showFilters: function() {
317
+
318
+ /**
319
+ * Categories
320
+ */
321
+ var category_slug = 'astra-site-page-builder';
322
+ var category = {
323
+ slug : category_slug + AstraRender._getCategoryParams( category_slug ),
324
+ id : category_slug,
325
+ class : category_slug,
326
+ trigger : 'astra-api-category-loaded',
327
+ wrapper_class : 'filter-links',
328
+ show_all : false,
329
+ };
330
+
331
+ AstraSitesAPI._api_request( category );
332
+
333
+ /**
334
+ * Page Builder
335
+ */
336
+ var category_slug = 'astra-site-category';
337
+ var category = {
338
+ slug : category_slug + AstraRender._getCategoryParams( category_slug ),
339
+ id : category_slug,
340
+ class : category_slug,
341
+ trigger : 'astra-api-all-category-loaded',
342
+ wrapper_class : 'filter-links',
343
+ show_all : AstraRender._getCategoryAllSelectStatus( category_slug ),
344
+ };
345
+
346
+ AstraSitesAPI._api_request( category );
347
+ },
348
+
349
+ /**
350
+ * Load First Grid.
351
+ *
352
+ * This is triggered after all category loaded.
353
+ *
354
+ * @param {object} event Event Object.
355
+ */
356
+ _loadFirstGrid: function( event, data ) {
357
+ AstraRender._addFilters( event, data );
358
+ setTimeout(function() {
359
+ AstraRender._showSites();
360
+ }, 100);
361
+ },
362
+
363
+ /**
364
+ * Append filters.
365
+ *
366
+ * @param {object} event Object.
367
+ * @param {object} data API response data.
368
+ */
369
+ _addFilters: function( event, data ) {
370
+ event.preventDefault();
371
+
372
+ if( jQuery('#' + data.args.id).length ) {
373
+ var template = wp.template('astra-site-filters');
374
+ jQuery('#' + data.args.id).html(template( data )).find('li:first a').addClass('current');
375
+ }
376
+
377
+ },
378
+
379
+ /**
380
+ * Append sites on scroll.
381
+ *
382
+ * @param {object} event Object.
383
+ * @param {object} data API response data.
384
+ */
385
+ _reinitGridScrolled: function( event, data ) {
386
+
387
+ var template = wp.template('astra-sites-list');
388
+
389
+ if( data.items.length > 0 ) {
390
+
391
+ $('body').removeClass( 'loading-content' );
392
+ $('.filter-count .count').text( data.items_count );
393
+
394
+ setTimeout(function() {
395
+ jQuery('#astra-sites').append(template( data ));
396
+
397
+ AstraRender._lazyLoad();
398
+
399
+ AstraRender._imagesLoaded();
400
+ }, 800);
401
+ } else {
402
+
403
+ $('body').addClass('listed-all-sites');
404
+
405
+ // $('#astra-sites-admin').find('.spinner').removeClass('is-active');
406
+ }
407
+
408
+ },
409
+
410
+ /**
411
+ * Update Astra sites list.
412
+ *
413
+ * @param {object} event Object.
414
+ * @param {object} data API response data.
415
+ */
416
+ _reinitGrid: function( event, data ) {
417
+
418
+ var template = wp.template('astra-sites-list');
419
+
420
+ $('body').removeClass( 'loading-content' );
421
+ $('.filter-count .count').text( data.items_count );
422
+
423
+ jQuery('body').attr('data-astra-demo-last-request', data.items_count);
424
+
425
+ jQuery('#astra-sites').show().html(template( data ));
426
+
427
+ AstraRender._lazyLoad();
428
+
429
+ AstraRender._imagesLoaded();
430
+
431
+ $('#astra-sites-admin').find('.spinner').removeClass('is-active');
432
+
433
+ if( data.items_count <= 0 ) {
434
+ $('#astra-sites-admin').find('.spinner').removeClass('is-active');
435
+ } else {
436
+ $('body').removeClass('listed-all-sites');
437
+ }
438
+
439
+
440
+ },
441
+
442
+ /**
443
+ * Check image loaded with function `imagesLoaded()`
444
+ */
445
+ _imagesLoaded: function() {
446
+
447
+ var self = jQuery('#sites-filter.execute-only-one-time a');
448
+
449
+ $('.astra-sites-grid').imagesLoaded()
450
+ .always( function( instance ) {
451
+ if( jQuery( window ).outerWidth() > AstraRender._breakpoint ) {
452
+ // $('#astra-sites').masonry('reload');
453
+ }
454
+
455
+ $('#astra-sites-admin').find('.spinner').removeClass('is-active');
456
+ })
457
+ .progress( function( instance, image ) {
458
+ var result = image.isLoaded ? 'loaded' : 'broken';
459
+ });
460
+
461
+ },
462
+
463
+ /**
464
+ * API Request Failed/Not found any demos.
465
+ */
466
+ _apiFailed: function() {
467
+ $('#astra-sites-admin').find('.spinner').removeClass('is-active').addClass('hide-me');
468
+ },
469
+
470
+ /**
471
+ * Update Page Count.
472
+ */
473
+ _updatedPagedCount: function() {
474
+ paged = parseInt(jQuery('body').attr('data-astra-demo-paged'));
475
+ jQuery('body').attr('data-astra-demo-paged', paged + 1);
476
+ window.setTimeout(function () {
477
+ jQuery('body').data('scrolling', false);
478
+ }, 800);
479
+ },
480
+
481
+ /**
482
+ * Reset Page Count.
483
+ */
484
+ _resetPagedCount: function() {
485
+
486
+ jQuery('body').attr('data-astra-demo-last-request', '1');
487
+ jQuery('body').attr('data-astra-demo-paged', '1');
488
+ jQuery('body').attr('data-astra-demo-search', '');
489
+ jQuery('body').attr('data-scrolling', false);
490
+
491
+ }
492
+
493
+ };
494
+
495
+ /**
496
+ * Initialize AstraRender
497
+ */
498
+ $(function(){
499
+ AstraRender.init();
500
+ });
501
+
502
+ })(jQuery);
inc/assets/vendor/js/jquery.lazy.js ADDED
@@ -0,0 +1,830 @@
1
+ /*!
2
+ * jQuery & Zepto Lazy - v1.7.5
3
+ * http://jquery.eisbehr.de/lazy/
4
+ *
5
+ * Copyright 2012 - 2017, Daniel 'Eisbehr' Kern
6
+ *
7
+ * Dual licensed under the MIT and GPL-2.0 licenses:
8
+ * http://www.opensource.org/licenses/mit-license.php
9
+ * http://www.gnu.org/licenses/gpl-2.0.html
10
+ *
11
+ * $("img.lazy").lazy();
12
+ */
13
+
14
+ ;(function(window, undefined) {
15
+ "use strict";
16
+
17
+ // noinspection JSUnresolvedVariable
18
+ /**
19
+ * library instance - here and not in construct to be shorter in minimization
20
+ * @return void
21
+ */
22
+ var $ = window.jQuery || window.Zepto,
23
+
24
+ /**
25
+ * unique plugin instance id counter
26
+ * @type {number}
27
+ */
28
+ lazyInstanceId = 0,
29
+
30
+ /**
31
+ * helper to register window load for jQuery 3
32
+ * @type {boolean}
33
+ */
34
+ windowLoaded = false;
35
+
36
+ /**
37
+ * make lazy available to jquery - and make it a bit more case-insensitive :)
38
+ * @access public
39
+ * @type {function}
40
+ * @param {object} settings
41
+ * @return void
42
+ */
43
+ $.fn.Lazy = $.fn.lazy = function(settings) {
44
+ return new LazyPlugin(this, settings);
45
+ };
46
+
47
+ /**
48
+ * helper to add plugins to lazy prototype configuration
49
+ * @access public
50
+ * @type {function}
51
+ * @param {string|Array} names
52
+ * @param {string|Array} [elements]
53
+ * @param {function} loader
54
+ * @return void
55
+ */
56
+ $.Lazy = $.lazy = function(names, elements, loader) {
57
+ // make second parameter optional
58
+ if( $.isFunction(elements) ) {
59
+ loader = elements;
60
+ elements = [];
61
+ }
62
+
63
+ // exit here if parameter is not a callable function
64
+ if( !$.isFunction(loader) ) return;
65
+
66
+ // make parameters an array of names to be sure
67
+ names = $.isArray(names) ? names : [names];
68
+ elements = $.isArray(elements) ? elements : [elements];
69
+
70
+ var config = LazyPlugin.prototype.config,
71
+ forced = config._f || (config._f = {});
72
+
73
+ // add the loader plugin for every name
74
+ for( var i = 0, l = names.length; i < l; i++ )
75
+ if( config[names[i]] === undefined || $.isFunction(config[names[i]]) )
76
+ config[names[i]] = loader;
77
+
78
+ // add forced elements loader
79
+ for( var c = 0, a = elements.length; c < a; c++ )
80
+ forced[elements[c]] = names[0];
81
+ };
82
+
83
+ /**
84
+ * contains all logic and the whole element handling
85
+ * is packed in a private function outside class to reduce memory usage, because it will not be created on every plugin instance
86
+ * @access private
87
+ * @type {function}
88
+ * @param {LazyPlugin} instance
89
+ * @param {object} config
90
+ * @param {object|Array} items
91
+ * @param {object} events
92
+ * @param {string} namespace
93
+ * @return void
94
+ */
95
+ function _executeLazy(instance, config, items, events, namespace) {
96
+ /**
97
+ * a helper to trigger the 'onFinishedAll' callback after all other events
98
+ * @access private
99
+ * @type {number}
100
+ */
101
+ var _awaitingAfterLoad = 0,
102
+
103
+ /**
104
+ * visible content width
105
+ * @access private
106
+ * @type {number}
107
+ */
108
+ _actualWidth = -1,
109
+
110
+ /**
111
+ * visible content height
112
+ * @access private
113
+ * @type {number}
114
+ */
115
+ _actualHeight = -1,
116
+
117
+ /**
118
+ * determine possibly detected high pixel density
119
+ * @access private
120
+ * @type {boolean}
121
+ */
122
+ _isRetinaDisplay = false,
123
+
124
+ /**
125
+ * dictionary entry for better minimization
126
+ * @access private
127
+ * @type {string}
128
+ */
129
+ _afterLoad = "afterLoad",
130
+
131
+ /**
132
+ * dictionary entry for better minimization
133
+ * @access private
134
+ * @type {string}
135
+ */
136
+ _load = "load",
137
+
138
+ /**
139
+ * dictionary entry for better minimization
140
+ * @access private
141
+ * @type {string}
142
+ */
143
+ _error = "error",
144
+
145
+ /**
146
+ * dictionary entry for better minimization
147
+ * @access private
148
+ * @type {string}
149
+ */
150
+ _img = "img",
151
+
152
+ /**
153
+ * dictionary entry for better minimization
154
+ * @access private
155
+ * @type {string}
156
+ */
157
+ _src = "src",
158
+
159
+ /**
160
+ * dictionary entry for better minimization
161
+ * @access private
162
+ * @type {string}
163
+ */
164
+ _srcset = "srcset",
165
+
166
+ /**
167
+ * dictionary entry for better minimization
168
+ * @access private
169
+ * @type {string}
170
+ */
171
+ _sizes = "sizes",
172
+
173
+ /**
174
+ * dictionary entry for better minimization
175
+ * @access private
176
+ * @type {string}
177
+ */
178
+ _backgroundImage = "background-image";
179
+
180
+ /**
181
+ * initialize plugin
182
+ * bind loading to events or set delay time to load all items at once
183
+ * @access private
184
+ * @return void
185
+ */
186
+ function _initialize() {
187
+ // detect actual device pixel ratio
188
+ // noinspection JSUnresolvedVariable
189
+ _isRetinaDisplay = window.devicePixelRatio > 1;
190
+
191
+ // prepare all initial items
192
+ _prepareItems(items);
193
+
194
+ // if delay time is set load all items at once after delay time
195
+ if( config.delay >= 0 ) setTimeout(function() { _lazyLoadItems(true); }, config.delay);
196
+
197
+ // if no delay is set or combine usage is active bind events
198
+ if( config.delay < 0 || config.combined ) {
199
+ // create unique event function
200
+ events.e = _throttle(config.throttle, function(event) {
201
+ // reset detected window size on resize event
202
+ if( event.type === "resize" )
203
+ _actualWidth = _actualHeight = -1;
204
+
205
+ // execute 'lazy magic'
206
+ _lazyLoadItems(event.all);
207
+ });
208
+
209
+ // create function to add new items to instance
210
+ events.a = function(additionalItems) {
211
+ _prepareItems(additionalItems);
212
+ items.push.apply(items, additionalItems);
213
+ };
214
+
215
+ // create function to get all instance items left
216
+ events.g = function() {
217
+ // filter loaded items before return in case internal filter was not running until now
218
+ return (items = $(items).filter(function() {
219
+ return !$(this).data(config.loadedName);
220
+ }));
221
+ };
222
+
223
+ // create function to force loading elements
224
+ events.f = function(forcedItems) {
225
+ for( var i = 0; i < forcedItems.length; i++ ) {
226
+ // only handle item if available in current instance
227
+ // use a compare function, because Zepto can't handle object parameter for filter
228
+ // var item = items.filter(forcedItems[i]);
229
+ /* jshint loopfunc: true */
230
+ var item = items.filter(function() {
231
+ return this === forcedItems[i];
232
+ });
233
+
234
+ if( item.length ) {
235
+ _lazyLoadItems(fal