PluginProbe
Borderless – Addons and Templates for Elementor / trunk
Borderless – Addons and Templates for Elementor vtrunk
trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.2.1 1.2.2 1.2.3 All 78 releases
borderless / assets / scripts / library.js

library.js in Borderless – Addons and Templates for Elementor trunk, at assets/scripts/library.js

438 lines 14.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 jQuery( function ( $ ) {
2 'use strict';
3
4 /* ==================================================
5 Events
6 ================================================== */
7
8 $( '.library-install-plugins-content-content .borderless-library-import__plugin.plugin-item--required input[type=checkbox]' ).on( 'click', function( event ) {
9 event.preventDefault();
10
11 return false;
12 } );
13
14 $( '.js-library-install-plugins' ).on( 'click', function( event ) {
15 event.preventDefault();
16
17 var $button = $( this );
18
19 if ( $button.hasClass( 'library-button-disabled' ) ) {
20 return false;
21 }
22
23 var pluginsToInstall = $( '.library-install-plugins-content-content .borderless-library-import__plugin input[type=checkbox]' ).serializeArray();
24
25 if ( pluginsToInstall.length === 0 ) {
26 return false;
27 }
28
29 $button.addClass( 'library-button-disabled' );
30
31 installPluginsAjaxCall( pluginsToInstall, 0, $button, false, false );
32 } );
33
34 $( '.js-library-install-plugins-before-import' ).on( 'click', function( event ) {
35 event.preventDefault();
36
37 var $button = $( this );
38
39 if ( $button.hasClass( 'library-button-disabled' ) ) {
40 return false;
41 }
42
43 var pluginsToInstall = $( '.library-install-plugins-content-content .borderless-library-import__plugin:not(.plugin-item--disabled) input[type=checkbox]' ).serializeArray();
44
45 if ( pluginsToInstall.length === 0 ) {
46 startImport( getUrlParameter( 'import' ) );
47
48 return false;
49 }
50
51 $button.addClass( 'library-button-disabled' );
52
53 installPluginsAjaxCall( pluginsToInstall, 0, $button, true, false );
54 } );
55
56
57 $( '.js-library-create-content' ).on( 'click', function( event ) {
58 event.preventDefault();
59
60 var $button = $( this );
61
62 if ( $button.hasClass( 'library-button-disabled' ) ) {
63 return false;
64 }
65
66 var itemsToImport = $( '.library-create-content-content .content-item input[type=checkbox]' ).serializeArray();
67
68 if ( itemsToImport.length === 0 ) {
69 return false;
70 }
71
72 $button.addClass( 'library-button-disabled' );
73
74 createDemoContentAjaxCall( itemsToImport, 0, $button );
75 } );
76
77
78 $( document ).on( 'change', '.library--create-content .content-item input[type=checkbox]', function( event ) {
79 var $checkboxes = $( '.library--create-content .content-item input[type=checkbox]' ),
80 $missingPluginNotice = $( '.js-library-create-content-install-plugins-notice' ),
81 missingPlugins = [];
82
83 $checkboxes.each( function() {
84 var $checkbox = $( this );
85 if ( $checkbox.is( ':checked' ) ) {
86 missingPlugins = missingPlugins.concat( getMissingPluginNamesFromImportContentPageItem( $checkbox.data( 'plugins' ) ) );
87 }
88 } );
89
90 missingPlugins = missingPlugins.filter( onlyUnique ).join( ', ' );
91
92 if ( missingPlugins.length > 0 ) {
93 $missingPluginNotice.find( '.js-library-create-content-install-plugins-list' ).text( missingPlugins );
94 $missingPluginNotice.show();
95 } else {
96 $missingPluginNotice.find( '.js-library-create-content-install-plugins-list' ).text( '' );
97 $missingPluginNotice.hide();
98 }
99 } );
100
101
102
103 /* ==================================================
104 Helper functions
105 ================================================== */
106
107 function ajaxCall( data ) {
108 $.ajax({
109 method: 'POST',
110 url: library.ajax_url,
111 data: data,
112 contentType: false,
113 processData: false,
114 beforeSend: function() {
115 $( '.borderless-library-import__required-plugins' ).hide();
116 $( '.js-library-importing' ).show();
117 }
118 })
119 .done( function( response ) {
120 if ( 'undefined' !== typeof response.status && 'newAJAX' === response.status ) {
121 ajaxCall( data );
122 }
123 else if ( 'undefined' !== typeof response.status && 'customizerAJAX' === response.status ) {
124 var newData = new FormData();
125 newData.append( 'action', 'library_import_customizer_data' );
126 newData.append( 'security', library.ajax_nonce );
127
128 if ( true === library.wp_customize_on ) {
129 newData.append( 'wp_customize', 'on' );
130 }
131
132 ajaxCall( newData );
133 }
134 else if ( 'undefined' !== typeof response.status && 'afterAllImportAJAX' === response.status ) {
135 var newData = new FormData();
136 newData.append( 'action', 'library_after_import_data' );
137 newData.append( 'security', library.ajax_nonce );
138 ajaxCall( newData );
139 }
140 else if ( 'undefined' !== typeof response.message ) {
141 $( '.js-library-ajax-response' ).append( response.message );
142
143 if ( 'undefined' !== typeof response.title ) {
144 $( '.js-library-ajax-response-title' ).html( response.title );
145 }
146
147 if ( 'undefined' !== typeof response.subtitle ) {
148 $( '.js-library-ajax-response-subtitle' ).html( response.subtitle );
149 }
150
151 $( '.js-library-importing' ).hide();
152 $( '.js-library-imported' ).show();
153
154 $( document ).trigger( 'libraryImportComplete' );
155 }
156 else {
157 $( '.js-library-ajax-response' ).append( '<i class="borderless-library-import__failed-imported-icon bi bi-exclamation-circle-fill"></i><p>' + response + '</p>' );
158 $( '.js-library-ajax-response-title' ).html( library.texts.import_failed );
159 $( '.js-library-ajax-response-subtitle' ).html( '<p>' + library.texts.import_failed_subtitle + '</p>' );
160 $( '.js-library-importing' ).hide();
161 $( '.js-library-imported' ).show();
162 }
163 })
164 .fail( function( error ) {
165 $( '.js-library-ajax-response' ).append( '<i class="borderless-library-import__failed-imported-icon bi bi-exclamation-circle-fill"></i><p>Error: ' + error.statusText + ' (' + error.status + ')' + '</p>' );
166 $( '.js-library-ajax-response-title' ).html( library.texts.import_failed );
167 $( '.js-library-ajax-response-subtitle' ).html( '<p>' + library.texts.import_failed_subtitle + '</p>' );
168 $( '.js-library-importing' ).hide();
169 $( '.js-library-imported' ).show();
170 });
171 }
172
173 function getMissingPluginNamesFromImportContentPageItem( requiredPluginSlugs ) {
174 var requiredPluginSlugs = requiredPluginSlugs.split( ',' ),
175 pluginList = [];
176
177 library.missing_plugins.forEach( function( plugin ) {
178 if ( requiredPluginSlugs.indexOf( plugin.slug ) !== -1 ) {
179 pluginList.push( plugin.name )
180 }
181 } );
182
183 return pluginList;
184 }
185
186 function onlyUnique( value, index, self ) {
187 return self.indexOf( value ) === index;
188 }
189
190 function installPluginsAjaxCall( plugins, counter, $button , runImport, pluginInstallFailed ) {
191 var plugin = plugins[ counter ],
192 slug = plugin.name;
193
194 $.ajax({
195 method: 'POST',
196 url: library.ajax_url,
197 data: {
198 action: 'library_install_plugin',
199 security: library.ajax_nonce,
200 slug: slug,
201 },
202 beforeSend: function() {
203 var $currentPluginItem = $( '.plugin-item-' + slug );
204 $currentPluginItem.find( '.js-library-plugin-item-info' ).empty();
205 $currentPluginItem.find( '.js-library-plugin-item-error' ).empty();
206 $currentPluginItem.addClass( 'plugin-item--loading' );
207 }
208 })
209 .done( function( response ) {
210 var $currentPluginItem = $( '.plugin-item-' + slug );
211
212 $currentPluginItem.removeClass( 'plugin-item--loading' );
213
214 if ( response.success ) {
215 $currentPluginItem.addClass( 'plugin-item--active' );
216 $currentPluginItem.find( 'input[type=checkbox]' ).prop( 'disabled', true );
217 } else {
218
219 if ( -1 === response.data.indexOf( '<p>' ) ) {
220 response.data = '<p>' + response.data + '</p>';
221 }
222
223 $currentPluginItem.find( '.js-library-plugin-item-error' ).append( response.data );
224 $currentPluginItem.find( 'input[type=checkbox]' ).prop( 'checked', false );
225 pluginInstallFailed = true;
226 }
227 })
228 .fail( function( error ) {
229 var $currentPluginItem = $( '.plugin-item-' + slug );
230 $currentPluginItem.removeClass( 'plugin-item--loading' );
231 $currentPluginItem.find( '.js-library-plugin-item-error' ).append( '<p>' + error.statusText + ' (' + error.status + ')</p>' );
232 pluginInstallFailed = true;
233 })
234 .always( function() {
235 counter++;
236
237 if ( counter === plugins.length ) {
238 if ( runImport ) {
239 if ( ! pluginInstallFailed ) {
240 startImport( getUrlParameter( 'import' ) );
241 } else {
242 alert( library.texts.plugin_install_failed );
243 }
244 }
245
246 $button.removeClass( 'library-button-disabled' );
247 } else {
248 installPluginsAjaxCall( plugins, counter, $button, runImport, pluginInstallFailed );
249 }
250 } );
251 }
252
253 function createDemoContentAjaxCall( items, counter, $button ) {
254 var item = items[ counter ],
255 slug = item.name;
256
257 $.ajax({
258 method: 'POST',
259 url: library.ajax_url,
260 data: {
261 action: 'library_import_created_content',
262 security: library.ajax_nonce,
263 slug: slug,
264 },
265 beforeSend: function() {
266 var $currentItem = $( '.content-item-' + slug );
267 $currentItem.find( '.js-library-content-item-info' ).empty();
268 $currentItem.find( '.js-library-content-item-error' ).empty();
269 $currentItem.addClass( 'content-item--loading' );
270 }
271 })
272 .done( function( response ) {
273 if ( response.data && response.data.refresh ) {
274 createDemoContentAjaxCall( items, counter, $button );
275 return;
276 }
277
278 var $currentItem = $( '.content-item-' + slug );
279
280 $currentItem.removeClass( 'content-item--loading' );
281
282 if ( response.success ) {
283 $currentItem.find( '.js-library-content-item-info' ).append( '<p>' + library.texts.successful_import + '</p>' );
284 } else {
285 $currentItem.find( '.js-library-content-item-error' ).append( '<p>' + response.data + '</p>' );
286 }
287 })
288 .fail( function( error ) {
289 var $currentItem = $( '.content-item-' + slug );
290 $currentItem.removeClass( 'content-item--loading' );
291 $currentItem.find( '.js-library-content-item-error' ).append( '<p>' + error.statusText + ' (' + error.status + ')</p>' );
292 })
293 .always( function( response ) {
294 if ( response.data && response.data.refresh ) {
295 return;
296 }
297
298 counter++;
299
300 if ( counter === items.length ) {
301 $button.removeClass( 'library-button-disabled' );
302 } else {
303 createDemoContentAjaxCall( items, counter, $button );
304 }
305 } );
306 }
307
308
309 function getUrlParameter( param ) {
310 var sPageURL = window.location.search.substring( 1 ),
311 sURLVariables = sPageURL.split( '&' ),
312 sParameterName,
313 i;
314
315 for ( i = 0; i < sURLVariables.length; i++ ) {
316 sParameterName = sURLVariables[ i ].split( '=' );
317
318 if ( sParameterName[0] === param ) {
319 return typeof sParameterName[1] === undefined ? true : decodeURIComponent( sParameterName[1] );
320 }
321 }
322
323 return false;
324 }
325
326
327 function startImport( selected ) {
328 var data = new FormData();
329 data.append( 'action', 'library_import_demo_data' );
330 data.append( 'security', library.ajax_nonce );
331
332 if ( selected ) {
333 data.append( 'selected', selected );
334 }
335
336 ajaxCall( data );
337 }
338
339
340 /* ==================================================
341 Page Builder
342 ================================================== */
343
344 $('.borderless-library__template.wpbakery .borderless-library__template-body').prepend('<svg class="borderless-library__template-body-page-builder" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"><path d="M16 0a16 16 0 1 0 0 32 16 16 0 1 0 0-32zm6.25 20.84l-1.17 4.19c-3.33-1.98-7.41-.59-7.71-.54-.83.21-2.17-1.96-1.78-2.1 2.27-.32 3.88-1.64 4-1.78C7.49 24.36 4 17.42 4 14.24c0-.38.25-7.27 7.97-7.27 5.52-.01 4.29 5.4 10.86 4.44-1-.31-2.29.1-3.08-.83C28.06 8.86 28 15.34 28 15.57c.05 5.03-5.75 5.27-5.75 5.27z" fill="#0373aa"/></svg>');
345
346 $('.borderless-library__template.elementor .borderless-library__template-body').prepend('<svg class="borderless-library__template-body-page-builder" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 32 32"><defs><path id="A" d="M0 0h32v32H0z"/></defs><clipPath id="B"><use xlink:href="#A"/></clipPath><g clip-path="url(#B)"><path d="M16 0A16 16 0 0 0 0 16c0 8.83 7.16 16 16 16a16 16 0 0 0 16-16c0-8.84-7.17-16-16-16zm-4 22.66H9.34V9.33H12v13.33zm10.66 0h-8V20h8v2.66zm0-5.33h-8v-2.67h8v2.67zm0-5.33h-8V9.33h8V12z" fill="#92003b"/></g></svg>');
347
348
349 /* ==================================================
350 Filter
351 ================================================== */
352
353 $(window).load(function(){
354
355 var buttonFilters = {};
356 var buttonFilter;
357 var qsRegex;
358
359 // Isotope / Masonry
360 var $grid = $('.borderless-library .borderless-library__templates').isotope({
361 itemSelector: '.borderless-library__template',
362 layoutMode: 'masonry',
363
364 getSortData: {
365 category: '[data-category]'
366 },
367
368 filter: function() {
369 var $this = $(this);
370 var searchResult = qsRegex ? $this.text().match( qsRegex ) : true;
371 var buttonResult = buttonFilter ? $this.is( buttonFilter ) : true;
372 return searchResult && buttonResult;
373 },
374 });
375
376 $grid.imagesLoaded().progress(function() {
377 setTimeout(function(){
378 $grid.isotope('layout');
379 },200);
380 });
381
382 $('.borderless-library__filters').on( 'click', '.borderless-library__collapse-nav-link', function() {
383 var $this = $(this);
384 // get group key
385 var $buttonGroup = $this.parents('.borderless-library__collapse-nav');
386 var filterGroup = $buttonGroup.attr('data-filter-group');
387 // set filter for group
388 buttonFilters[ filterGroup ] = $this.attr('data-filter');
389 // combine filters
390 buttonFilter = concatValues( buttonFilters );
391 // Isotope arrange
392 $grid.isotope();
393 });
394
395
396 // use value of search field to filter
397 var $quicksearch = $('.borderless-library__live-search-input').keyup( debounce( function() {
398 qsRegex = new RegExp( $quicksearch.val(), 'gi' );
399 $grid.isotope();
400 }) );
401
402 // change active class on buttons
403 $('.borderless-library__collapse-nav').each( function( i, buttonGroup ) {
404 var $buttonGroup = $( buttonGroup );
405 $buttonGroup.on( 'click', '.borderless-library__collapse-nav-link', function() {
406 $buttonGroup.find('.active').removeClass('active');
407 $( this ).addClass('active');
408 });
409 });
410
411 // flatten object by concatting values
412 function concatValues( obj ) {
413 var value = '';
414 for ( var prop in obj ) {
415 value += obj[ prop ];
416 }
417 return value;
418 }
419
420 // debounce so filtering doesn't happen every millisecond
421 function debounce( fn, threshold ) {
422 var timeout;
423 threshold = threshold || 100;
424 return function debounced() {
425 clearTimeout( timeout );
426 var args = arguments;
427 var _this = this;
428 function delayed() {
429 fn.apply( _this, args );
430 }
431 timeout = setTimeout( delayed, threshold );
432 };
433 }
434
435 });
436
437 } );
438