PluginProbe
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP / 1.2.76
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP v1.2.76
1.2.76 1.2.75 1.2.74 1.2.73 1.2.72 1.2.71 1.2.70 1.2.69 1.2.68 1.2.67 1.2.66 1.2.65 1.2.64 1.2.63 trunk 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 All 176 releases
userswp / vendor / ayecode / wp-ayecode-ui / includes / inc / bs5-js.php

bs5-js.php in UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP 1.2.76, at vendor/ayecode/wp-ayecode-ui/includes/inc/bs5-js.php

1,356 lines 55.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php // @todo eventually we need to convert this to non jQuery ?>
2 <script>
3 /**
4 * An AUI bootstrap adaptation of GreedyNav.js ( by Luke Jackson ).
5 *
6 * Simply add the class `greedy` to any <nav> menu and it will do the rest.
7 * Licensed under the MIT license - http://opensource.org/licenses/MIT
8 * @ver 0.0.1
9 */
10 function aui_init_greedy_nav(){
11 jQuery('nav.greedy').each(function(i, obj) {
12 // Check if already initialized, if so continue.
13 if(jQuery(this).hasClass("being-greedy")){return true;}
14
15 // Make sure its always expanded
16 jQuery(this).addClass('navbar-expand');
17 jQuery(this).off('shown.bs.tab').on('shown.bs.tab', function (e) {
18 if (jQuery(e.target).closest('.dropdown-menu').hasClass('greedy-links')) {
19 jQuery(e.target).closest('.greedy').find('.greedy-btn.dropdown').attr('aria-expanded', 'false');
20 jQuery(e.target).closest('.greedy-links').removeClass('show').addClass('d-none');
21 }
22 });
23 jQuery(document).off('mousemove', '.greedy-btn').on('mousemove', '.greedy-btn', function(e){
24 jQuery('.dropdown-menu.greedy-links').removeClass('d-none');
25 });
26 // vars
27 var $vlinks = '';
28 var $dDownClass = '';
29 var ddItemClass = 'greedy-nav-item';
30 if(jQuery(this).find('.navbar-nav').length){
31 if(jQuery(this).find('.navbar-nav').hasClass("being-greedy")){return true;}
32 $vlinks = jQuery(this).find('.navbar-nav').addClass("being-greedy w-100").removeClass('overflow-hidden');
33 }else if(jQuery(this).find('.nav').length){
34 if(jQuery(this).find('.nav').hasClass("being-greedy")){return true;}
35 $vlinks = jQuery(this).find('.nav').addClass("being-greedy w-100").removeClass('overflow-hidden');
36 $dDownClass = ' mt-0 p-0 zi-5 ';
37 ddItemClass += ' mt-0 me-0';
38 }else{
39 return false;
40 }
41
42 jQuery($vlinks).append('<li class="nav-item list-unstyled ml-auto greedy-btn d-none dropdown"><button data-bs-toggle="collapse" class="nav-link greedy-nav-link" role="button"><i class="fas fa-ellipsis-h"></i> <span class="greedy-count badge bg-dark rounded-pill"></span></button><ul class="greedy-links dropdown-menu dropdown-menu-end '+$dDownClass+'"></ul></li>');
43
44 var $hlinks = jQuery(this).find('.greedy-links');
45 var $btn = jQuery(this).find('.greedy-btn');
46
47 var numOfItems = 0;
48 var totalSpace = 0;
49 var closingTime = 1000;
50 var breakWidths = [];
51
52 // Get initial state
53 $vlinks.children().outerWidth(function(i, w) {
54 totalSpace += w;
55 numOfItems += 1;
56 breakWidths.push(totalSpace);
57 });
58
59 var availableSpace, numOfVisibleItems, requiredSpace, buttonSpace ,timer;
60
61 /*
62 The check function.
63 */
64 function check() {
65 // Get instant state
66 buttonSpace = $btn.width();
67 availableSpace = $vlinks.width() - 10;
68 numOfVisibleItems = $vlinks.children().length;
69 requiredSpace = breakWidths[numOfVisibleItems - 1];
70
71 // There is not enough space
72 if (numOfVisibleItems > 1 && requiredSpace > availableSpace) {
73 var $li = $vlinks.children().last().prev();
74 $li.removeClass('nav-item').addClass(ddItemClass);
75 if (!jQuery($hlinks).children().length) {
76 $li.find('.nav-link').addClass('w-100 dropdown-item rounded-0 rounded-bottom');
77 } else {
78 jQuery($hlinks).find('.nav-link').removeClass('rounded-top');
79 $li.find('.nav-link').addClass('w-100 dropdown-item rounded-0 rounded-top');
80 }
81 $li.prependTo($hlinks);
82 numOfVisibleItems -= 1;
83 check();
84 // There is more than enough space
85 } else if (availableSpace > breakWidths[numOfVisibleItems]) {
86 $hlinks.children().first().insertBefore($btn);
87 numOfVisibleItems += 1;
88 check();
89 }
90 // Update the button accordingly
91 jQuery($btn).find(".greedy-count").html( numOfItems - numOfVisibleItems);
92 if (numOfVisibleItems === numOfItems) {
93 $btn.addClass('d-none');
94 } else $btn.removeClass('d-none');
95 }
96
97 // Window listeners
98 jQuery(window).on("resize",function() {
99 check();
100 });
101
102 // do initial check
103 check();
104 });
105 }
106
107 function aui_select2_locale() {
108 var aui_select2_params = <?php echo self::select2_locale(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>;
109
110 return {
111 theme: "bootstrap-5",
112 width: jQuery( this ).data( 'width' ) ? jQuery( this ).data( 'width' ) : jQuery( this ).hasClass( 'w-100' ) ? '100%' : 'style',
113 placeholder: jQuery( this ).data( 'placeholder' ),
114 'language': {
115 errorLoading: function() {
116 // Workaround for https://github.com/select2/select2/issues/4355 instead of i18n_ajax_error.
117 return aui_select2_params.i18n_searching;
118 },
119 inputTooLong: function(args) {
120 var overChars = args.input.length - args.maximum;
121 if (1 === overChars) {
122 return aui_select2_params.i18n_input_too_long_1;
123 }
124 return aui_select2_params.i18n_input_too_long_n.replace('%item%', overChars);
125 },
126 inputTooShort: function(args) {
127 var remainingChars = args.minimum - args.input.length;
128 if (1 === remainingChars) {
129 return aui_select2_params.i18n_input_too_short_1;
130 }
131 return aui_select2_params.i18n_input_too_short_n.replace('%item%', remainingChars);
132 },
133 loadingMore: function() {
134 return aui_select2_params.i18n_load_more;
135 },
136 maximumSelected: function(args) {
137 if (args.maximum === 1) {
138 return aui_select2_params.i18n_selection_too_long_1;
139 }
140 return aui_select2_params.i18n_selection_too_long_n.replace('%item%', args.maximum);
141 },
142 noResults: function() {
143 return aui_select2_params.i18n_no_matches;
144 },
145 searching: function() {
146 return aui_select2_params.i18n_searching;
147 }
148 }
149 };
150 }
151
152 /**
153 * Initiate Select2 items.
154 */
155 function aui_init_select2(){
156 var select2Args, select2Locale = aui_select2_locale();
157 jQuery("select.aui-select2").each(function() {
158 if (!jQuery(this).hasClass("select2-hidden-accessible")) {
159 select2Args = jQuery.extend({}, select2Locale);
160 if (jQuery(this).closest('.modal.show').length && jQuery(this).closest('.modal-body').length) {
161 // Keep the dropdown inside the modal to prevent focus trapping.
162 select2Args.dropdownParent = jQuery(this).closest('.modal-body');
163 }
164 jQuery(this).select2(select2Args);
165 }
166 });
167 }
168
169 /**
170 * A function to convert a time value to a "ago" time text.
171 *
172 * @param selector string The .class selector
173 */
174 function aui_time_ago(selector) {
175 var aui_timeago_params = <?php echo self::timeago_locale(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>;
176
177 var templates = {
178 prefix: aui_timeago_params.prefix_ago,
179 suffix: aui_timeago_params.suffix_ago,
180 seconds: aui_timeago_params.seconds,
181 minute: aui_timeago_params.minute,
182 minutes: aui_timeago_params.minutes,
183 hour: aui_timeago_params.hour,
184 hours: aui_timeago_params.hours,
185 day: aui_timeago_params.day,
186 days: aui_timeago_params.days,
187 month: aui_timeago_params.month,
188 months: aui_timeago_params.months,
189 year: aui_timeago_params.year,
190 years: aui_timeago_params.years
191 };
192 var template = function (t, n) {
193 return templates[t] && templates[t].replace(/%d/i, Math.abs(Math.round(n)));
194 };
195
196 var timer = function (time) {
197 if (!time)
198 return;
199 time = time.replace(/\.\d+/, ""); // remove milliseconds
200 time = time.replace(/-/, "/").replace(/-/, "/");
201 time = time.replace(/T/, " ").replace(/Z/, " UTC");
202 time = time.replace(/([\+\-]\d\d)\:?(\d\d)/, " $1$2"); // -04:00 -> -0400
203 time = new Date(time * 1000 || time);
204
205 var now = new Date();
206 var seconds = ((now.getTime() - time) * .001) >> 0;
207 var minutes = seconds / 60;
208 var hours = minutes / 60;
209 var days = hours / 24;
210 var years = days / 365;
211
212 return templates.prefix + (
213 seconds < 45 && template('seconds', seconds) ||
214 seconds < 90 && template('minute', 1) ||
215 minutes < 45 && template('minutes', minutes) ||
216 minutes < 90 && template('hour', 1) ||
217 hours < 24 && template('hours', hours) ||
218 hours < 42 && template('day', 1) ||
219 days < 30 && template('days', days) ||
220 days < 45 && template('month', 1) ||
221 days < 365 && template('months', days / 30) ||
222 years < 1.5 && template('year', 1) ||
223 template('years', years)
224 ) + templates.suffix;
225 };
226
227 var elements = document.getElementsByClassName(selector);
228 if (selector && elements && elements.length) {
229 for (var i in elements) {
230 var $el = elements[i];
231 if (typeof $el === 'object') {
232 $el.innerHTML = '<i class="far fa-clock"></i> ' + timer($el.getAttribute('title') || $el.getAttribute('datetime'));
233 }
234 }
235 }
236
237 // update time every minute
238 setTimeout(function() {
239 aui_time_ago(selector);
240 }, 60000);
241
242 }
243
244 /**
245 * Initiate tooltips on the page.
246 */
247 function aui_init_tooltips(){
248 if (typeof jQuery.fn.tooltip === 'function') {
249 jQuery('[data-bs-toggle="tooltip"]').tooltip();
250 } else {
251 console.log('jQuery.fn.tooltip not found');
252 }
253
254 if (typeof jQuery.fn.popover === 'function') {
255 jQuery('[data-bs-toggle="popover"]').popover();
256 jQuery('[data-bs-toggle="popover-html"]').popover({
257 html: true,
258 sanitize: false
259 });
260 } else {
261 console.log('jQuery.fn.popover not found');
262 }
263
264 // fix popover container compatibility
265 jQuery('[data-bs-toggle="popover"],[data-bs-toggle="popover-html"]').on('inserted.bs.popover', function() {
266 jQuery('body > .popover').wrapAll("<div class='bsui' />");
267 });
268 }
269
270 /**
271 * Initiate flatpickrs on the page.
272 */
273 $aui_doing_init_flatpickr = false;
274 function aui_init_flatpickr(){
275 if ( typeof jQuery.fn.flatpickr === "function" && !$aui_doing_init_flatpickr) {
276 $aui_doing_init_flatpickr = true;
277 <?php if ( ! empty( $flatpickr_locale ) ) { ?>try{flatpickr.localize(<?php echo $flatpickr_locale; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>);}catch(err){console.log(err.message);}<?php } ?>
278 jQuery('input[data-aui-init="flatpickr"]:not(.flatpickr-input)').flatpickr();
279 }
280 $aui_doing_init_flatpickr = false;
281 }
282
283 /**
284 * Initiate iconpicker on the page.
285 */
286 $aui_doing_init_iconpicker = false;
287 function aui_init_iconpicker(){
288 if ( typeof jQuery.fn.iconpicker === "function" && !$aui_doing_init_iconpicker) {
289 $aui_doing_init_iconpicker = true;
290 jQuery('input[data-aui-init="iconpicker"]:not(.iconpicker-input)').iconpicker();
291 }
292 $aui_doing_init_iconpicker= false;
293 }
294
295 function aui_modal_iframe($title,$url,$footer,$dismissible,$class,$dialog_class,$body_class,responsive){
296 if(!$body_class){$body_class = 'p-0';}
297 var wClass = 'text-center position-absolute w-100 text-dark overlay overlay-white p-0 m-0 d-flex justify-content-center align-items-center';
298 var wStyle = '';
299 var sStyle = '';
300 var $body = "", sClass = "w-100 p-0 m-0";
301 if (responsive) {
302 $body += '<div class="embed-responsive embed-responsive-16by9 ratio ratio-16x9">';
303 wClass += ' h-100';
304 sClass += ' embed-responsive-item';
305 } else {
306 wClass += ' vh-100';
307 sClass += ' vh-100';
308 wStyle += ' height: 90vh !important;';
309 sStyle += ' height: 90vh !important;';
310 }
311 $body += '<div class="ac-preview-loading ' + wClass + '" style="left:0;top:0;' + wStyle + '"><div class="spinner-border" role="status"></div></div>';
312 $body += '<iframe id="embedModal-iframe" class="' + sClass + '" style="' + sStyle + '" src="" width="100%" height="100%" frameborder="0" allowtransparency="true"></iframe>';
313 if (responsive) {
314 $body += '</div>';
315 }
316 $m = aui_modal($title,$body,$footer,$dismissible,$class,$dialog_class,$body_class);
317
318 // myModalEl.addEventListener('hidden.bs.modal', event => {
319 // jQuery(".aui-carousel-modal iframe").attr('src', '');
320 // });
321
322 const auiModal = document.getElementById('aui-modal');
323 auiModal.addEventListener( 'shown.bs.modal', function ( e ) {
324 iFrame = jQuery( '#embedModal-iframe') ;
325
326 jQuery('.ac-preview-loading').removeClass('d-none').addClass('d-flex');
327
328 iFrame.attr({
329 src: $url
330 });
331
332 //resize the iframe once loaded.
333 iFrame.load(function() {
334 jQuery('.ac-preview-loading').removeClass('d-flex').addClass('d-none');
335 });
336 });
337
338 return $m;
339 }
340
341 function aui_modal($title,$body,$footer,$dismissible,$class,$dialog_class,$body_class) {
342 if(!$class){$class = '';}
343 if(!$dialog_class){$dialog_class = '';}
344 if(!$body){$body = '<div class="text-center"><div class="spinner-border" role="status"></div></div>';}
345
346 // remove it first
347 jQuery('.aui-modal').remove();
348 jQuery('.modal-backdrop').remove();
349 jQuery('body').css({'overflow': '','padding-right':''});
350
351
352 // var modal = document.getElementById('aui-modal');
353
354 var $modal = '';
355
356 $modal += '<div id="aui-modal" class="modal aui-modal fade shadow bsui '+$class+'" tabindex="-1">'+
357 '<div class="modal-dialog modal-dialog-centered '+$dialog_class+'">'+
358 '<div class="modal-content border-0 shadow">';
359
360 if($title) {
361 $modal += '<div class="modal-header">' +
362 '<h5 class="modal-title">' + $title + '</h5>';
363
364 if ($dismissible) {
365 $modal += '<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close">' +
366 '</button>';
367 }
368
369 $modal += '</div>';
370 }
371 $modal += '<div class="modal-body '+$body_class+'">'+
372 $body+
373 '</div>';
374
375 if($footer){
376 $modal += '<div class="modal-footer">'+
377 $footer +
378 '</div>';
379 }
380
381 $modal +='</div>'+
382 '</div>'+
383 '</div>';
384
385 jQuery('body').append($modal);
386
387
388
389 // const ayeModal = modal ? bootstrap.Modal.getInstance( modal ) : new bootstrap.Modal('#aui-modal', {});
390 const ayeModal = new bootstrap.Modal('.aui-modal', {});
391 // ayeModal.hide().show();
392 ayeModal.show();
393
394 // return jQuery('.aui-modal').modal('hide').modal({
395 // //backdrop: 'static'
396 // });
397 }
398
399 /**
400 * Show / hide fields depending on conditions.
401 */
402 function aui_conditional_fields(form){
403 jQuery(form).find(".aui-conditional-field").each(function () {
404
405 var $element_require = jQuery(this).data('element-require');
406
407 if ($element_require) {
408
409 $element_require = $element_require.replace("&#039;", "'"); // replace single quotes
410 $element_require = $element_require.replace("&quot;", '"'); // replace double quotes
411 if (aui_check_form_condition($element_require,form)) {
412 jQuery(this).removeClass('d-none');
413 } else {
414 jQuery(this).addClass('d-none');
415 }
416 }
417 });
418 }
419
420 /**
421 * Check form condition
422 */
423 function aui_check_form_condition(condition,form) {
424 if (form) {
425 condition = condition.replace(/\(form\)/g, "('"+form+"')");
426 }
427 return new Function("return " + condition+";")();
428 }
429
430 /**
431 * A function to determine if a element is on screen.
432 */
433 jQuery.fn.aui_isOnScreen = function(){
434
435 var win = jQuery(window);
436
437 var viewport = {
438 top : win.scrollTop(),
439 left : win.scrollLeft()
440 };
441 viewport.right = viewport.left + win.width();
442 viewport.bottom = viewport.top + win.height();
443
444 var bounds = this.offset();
445 bounds.right = bounds.left + this.outerWidth();
446 bounds.bottom = bounds.top + this.outerHeight();
447
448 return (!(viewport.right < bounds.left || viewport.left > bounds.right || viewport.bottom < bounds.top || viewport.top > bounds.bottom));
449
450 };
451
452 /**
453 * Maybe show multiple carousel items if set to do so.
454 */
455 function aui_carousel_maybe_show_multiple_items($carousel){
456 var $items = {};
457 var $item_count = 0;
458
459 // maybe backup
460 if(!jQuery($carousel).find('.carousel-inner-original').length){
461 jQuery($carousel).append('<div class="carousel-inner-original d-none">'+jQuery($carousel).find('.carousel-inner').html().replaceAll('carousel-item','not-carousel-item')+'</div>');
462 }
463
464 // Get the original items html
465 jQuery($carousel).find('.carousel-inner-original .not-carousel-item').each(function () {
466 $items[$item_count] = jQuery(this).html();
467 $item_count++;
468 });
469
470 // bail if no items
471 if(!$item_count){return;}
472
473 if(jQuery(window).width() <= 576){
474 // maybe restore original
475 if(jQuery($carousel).find('.carousel-inner').hasClass('aui-multiple-items') && jQuery($carousel).find('.carousel-inner-original').length){
476 jQuery($carousel).find('.carousel-inner').removeClass('aui-multiple-items').html(jQuery($carousel).find('.carousel-inner-original').html().replaceAll('not-carousel-item','carousel-item'));
477 jQuery($carousel).find(".carousel-indicators li").removeClass("d-none");
478 }
479
480 }else{
481 // new items
482 var $md_count = jQuery($carousel).data('limit_show');
483 var $md_cols_count = jQuery($carousel).data('cols_show');
484 var $new_items = '';
485 var $new_items_count = 0;
486 var $new_item_count = 0;
487 var $closed = true;
488 Object.keys($items).forEach(function(key,index) {
489
490 // close
491 if(index != 0 && Number.isInteger(index/$md_count) ){
492 $new_items += '</div></div>';
493 $closed = true;
494 }
495
496 // open
497 if(index == 0 || Number.isInteger(index/$md_count) ){
498 $row_cols_class = $md_cols_count ? ' g-lg-4 g-3 row-cols-1 row-cols-lg-' + $md_cols_count : '';
499 $active = index == 0 ? 'active' : '';
500 $new_items += '<div class="carousel-item '+$active+'"><div class="row' + $row_cols_class + ' ">'; // mb to account for shadows (removed mb-3 as it was causing padding issues
501 $closed = false;
502 $new_items_count++;
503 $new_item_count = 0;
504 }
505
506 // content
507 $new_items += '<div class="col ">'+$items[index]+'</div>';
508 $new_item_count++;
509
510
511 });
512
513 // close if not closed in the loop
514 if(!$closed){
515 // check for spares
516 if($md_count-$new_item_count > 0){
517 $placeholder_count = $md_count-$new_item_count;
518 while($placeholder_count > 0){
519 $new_items += '<div class="col "></div>';
520 $placeholder_count--;
521 }
522
523 }
524
525 $new_items += '</div></div>';
526 }
527
528 // insert the new items
529 jQuery($carousel).find('.carousel-inner').addClass('aui-multiple-items').html($new_items);
530
531 // fix any lazyload images in the active slider
532 jQuery($carousel).find('.carousel-item.active img').each(function () {
533 // fix the srcset
534 if(real_srcset = jQuery(this).attr("data-srcset")){
535 if(!jQuery(this).attr("srcset")) jQuery(this).attr("srcset",real_srcset);
536 }
537 // fix the src
538 if(real_src = jQuery(this).attr("data-src")){
539 if(!jQuery(this).attr("srcset")) jQuery(this).attr("src",real_src);
540 }
541 });
542
543 // maybe fix carousel indicators
544 $hide_count = $new_items_count-1;
545 jQuery($carousel).find(".carousel-indicators li:gt("+$hide_count+")").addClass("d-none");
546 }
547
548 // bootstrap.Carousel.dispose($carousel);
549 // console.log( bootstrap.Carousel.getOrCreateInstance($carousel)._getItems() );
550 // trigger a global action to say we have
551 jQuery( window ).trigger( "aui_carousel_multiple" );
552 }
553
554 /**
555 * Init Multiple item carousels.
556 */
557 function aui_init_carousel_multiple_items(){
558 jQuery(window).on("resize",function(){
559 jQuery('.carousel-multiple-items').each(function () {
560 aui_carousel_maybe_show_multiple_items(this);
561 });
562 });
563
564 // run now
565 jQuery('.carousel-multiple-items').each(function () {
566 aui_carousel_maybe_show_multiple_items(this);
567 });
568 }
569
570 /**
571 * Allow navs to use multiple sub menus.
572 */
573 function init_nav_sub_menus(){
574
575 jQuery('.navbar-multi-sub-menus').each(function(i, obj) {
576 // Check if already initialized, if so continue.
577 if(jQuery(this).hasClass("has-sub-sub-menus")){return true;}
578
579 // Make sure its always expanded
580 jQuery(this).addClass('has-sub-sub-menus');
581
582 jQuery(this).find( '.dropdown-menu a.dropdown-toggle' ).on( 'click', function ( e ) {
583 var $el = jQuery( this );
584 $el.toggleClass('active-dropdown');
585 var $parent = jQuery( this ).offsetParent( ".dropdown-menu" );
586 if ( !jQuery( this ).next().hasClass( 'show' ) ) {
587 jQuery( this ).parents( '.dropdown-menu' ).first().find( '.show' ).removeClass( "show" );
588 }
589 var $subMenu = jQuery( this ).next( ".dropdown-menu" );
590 $subMenu.toggleClass( 'show' );
591
592 jQuery( this ).parent( "li" ).toggleClass( 'show' );
593
594 jQuery( this ).parents( 'li.nav-item.dropdown.show' ).on( 'hidden.bs.dropdown', function ( e ) {
595 jQuery( '.dropdown-menu .show' ).removeClass( "show" );
596 $el.removeClass('active-dropdown');
597 } );
598
599 if ( !$parent.parent().hasClass( 'navbar-nav' ) ) {
600 $el.next().addClass('position-relative border-top border-bottom');
601 }
602
603 return false;
604 } );
605
606 });
607 }
608
609 /**
610 * Open a lightbox when an embed item is clicked.
611 */
612 function aui_lightbox_embed($link,ele){
613 ele.preventDefault();
614
615 // remove it first
616 jQuery('.aui-carousel-modal').remove();
617
618 var $modal = '<div class="modal fade aui-carousel-modal bsui" id="aui-carousel-modal" tabindex="-1" role="dialog" aria-labelledby="aui-modal-title" aria-hidden="true"><div class="modal-dialog modal-dialog-centered modal-xl mw-100"><div class="modal-content bg-transparent border-0 shadow-none"><div class="modal-header"><h5 class="modal-title" id="aui-modal-title"></h5></div><div class="modal-body text-center"><i class="fas fa-circle-notch fa-spin fa-3x"></i></div></div></div></div>';
619 jQuery('body').append($modal);
620
621 const ayeModal = new bootstrap.Modal('.aui-carousel-modal', {});
622
623 const myModalEl = document.getElementById('aui-carousel-modal');
624 myModalEl.addEventListener('hidden.bs.modal', event => {
625 jQuery(".aui-carousel-modal iframe").attr('src', '');
626 });
627
628 jQuery('.aui-carousel-modal').on('shown.bs.modal', function(e) {
629 jQuery('.aui-carousel-modal .carousel-item.active').find('iframe').each(function() {
630 var $iframe = jQuery(this);
631 $iframe.parent().find('.ac-preview-loading').removeClass('d-none').addClass('d-flex');
632 if (!$iframe.attr('src') && $iframe.data('src')) {
633 $iframe.attr('src', $iframe.data('src'));
634 }
635 $iframe.on('load', function() {
636 setTimeout(function() {
637 $iframe.parent().find('.ac-preview-loading').removeClass('d-flex').addClass('d-none');
638 }, 1250);
639 });
640 });
641 });
642
643 $container = jQuery($link).closest('.aui-gallery');
644
645 $clicked_href = jQuery($link).attr('href');
646 $images = [];
647 $container.find('.aui-lightbox-image, .aui-lightbox-iframe').each(function() {
648 var a = this;
649 var href = jQuery(a).attr('href');
650 if (href) {
651 $images.push(href);
652 }
653 });
654
655 if( $images.length ){
656 var $carousel = '<div id="aui-embed-slider-modal" class="carousel slide" >';
657
658 // indicators
659 if($images.length > 1){
660 $i = 0;
661 $carousel += '<ol class="carousel-indicators position-fixed">';
662 $container.find('.aui-lightbox-image, .aui-lightbox-iframe').each(function() {
663 $active = $clicked_href == jQuery(this).attr('href') ? 'active' : '';
664 $carousel += '<li data-bs-target="#aui-embed-slider-modal" data-bs-slide-to="'+$i+'" class="'+$active+'"></li>';
665 $i++;
666
667 });
668 $carousel += '</ol>';
669 }
670
671 // items
672 $i = 0;
673 $rtl_class = '<?php echo is_rtl() ? 'justify-content-end' : 'justify-content-start'; ?>';
674 $carousel += '<div class="carousel-inner d-flex align-items-center ' + $rtl_class + '">';
675 $container.find('.aui-lightbox-image').each(function() {
676 var a = this;
677 var href = jQuery(a).attr('href');
678
679 $active = $clicked_href == jQuery(this).attr('href') ? 'active' : '';
680 $carousel += '<div class="carousel-item '+ $active+'"><div>';
681
682 // image
683 var css_height = window.innerWidth > window.innerHeight ? '90vh' : 'auto';
684 var srcset = jQuery(a).find('img').attr('srcset');
685 var sizes = '';
686 if (srcset) {
687 var sources = srcset.split(',')
688 .map(s => {
689 // Using regex /\s+/ handles multiple spaces between the URL and width
690 var parts = s.trim().split(/\s+/).filter(Boolean);
691 if (parts.length >= 2) {
692 return {
693 width: parseInt(parts[1].replace('w', '')),
694 descriptor: parts[1].replace('w', 'px') // Ensuring the descriptor is in pixels
695 };
696 }
697 return null;
698 })
699 .filter(item => item !== null) // Remove any empty entries
700 .sort((a, b) => b.width - a.width); // Sort from largest to smallest for proper descending order
701
702 // Build the sizes string
703 sizes = sources.map((source, index, array) => {
704 // For the largest source, do not include max-width to serve as default for larger viewports
705 if (index === 0) {
706 return `${source.descriptor}`; // Using full descriptor for the largest image
707 } else {
708 // For other sources, specify max-width for one pixel less than the current width
709 return `(max-width: ${source.width - 1}px) ${array[index - 1].descriptor}`;
710 }
711 }).reverse().join(', '); // Reverse to start from smallest to largest for logical order
712 }
713
714 var img = href ? jQuery(a).find('img').clone().attr('src', href ).attr('sizes', sizes ).removeClass().addClass('mx-auto d-block w-auto rounded').css({'max-height':css_height,'max-width':'98%'}).get(0).outerHTML : jQuery(a).find('img').clone().removeClass().addClass('mx-auto d-block w-auto rounded').css({'max-height':css_height,'max-width':'98%'}).get(0).outerHTML;
715 $carousel += img;
716 // captions
717 if(jQuery(a).parent().find('.carousel-caption').length ){
718 $carousel += jQuery(a).parent().find('.carousel-caption').clone().removeClass('sr-only visually-hidden').get(0).outerHTML;
719 }else if(jQuery(a).parent().find('.figure-caption').length ){
720 $carousel += jQuery(a).parent().find('.figure-caption').clone().removeClass('sr-only visually-hidden').addClass('carousel-caption').get(0).outerHTML;
721 }
722 $carousel += '</div></div>';
723 $i++;
724 });
725
726 $container.find('.aui-lightbox-iframe').each(function() {
727 var a = this;
728 var css_height = window.innerWidth > window.innerHeight ? '90vh;' : 'auto;';
729 var styleWidth = $images.length > 1 ? 'max-width:70%;' : '';
730
731 $active = $clicked_href == jQuery(this).attr('href') ? 'active' : '';
732 $carousel += '<div class="carousel-item '+ $active+'"><div class="modal-xl mx-auto ratio ratio-16x9" style="max-height:'+css_height+styleWidth+'">';
733
734 // iframe
735 var url = jQuery(a).attr('href');
736 var iframe = '<div class="ac-preview-loading text-light d-none" style="left:0;top:0;height:'+css_height +'"><div class="spinner-border m-auto" role="status"></div></div>';
737 iframe += '<iframe class="aui-carousel-iframe" style="height:'+css_height +'" src="" data-src="'+url+'?rel=0&amp;showinfo=0&amp;modestbranding=1&amp;autoplay=1" allow="autoplay"></iframe>';
738 var img = iframe ;//.css('height',css_height).get(0).outerHTML;
739 $carousel += img;
740
741 $carousel += '</div></div>';
742 $i++;
743 });
744 $carousel += '</div>';
745
746 // next/prev indicators
747 if($images.length > 1) {
748 $carousel += '<a class="carousel-control-prev" href="#aui-embed-slider-modal" role="button" data-bs-slide="prev">';
749 $carousel += '<span class="carousel-control-prev-icon" aria-hidden="true"></span>';
750 $carousel += ' <a class="carousel-control-next" href="#aui-embed-slider-modal" role="button" data-bs-slide="next">';
751 $carousel += '<span class="carousel-control-next-icon" aria-hidden="true"></span>';
752 $carousel += '</a>';
753 }
754
755 $carousel += '</div>';
756
757 var $close = '<button type="button" class="btn-close btn-close-white text-end position-fixed" style="right: 20px;top: 10px; z-index: 1055;" data-bs-dismiss="modal" aria-label="Close"></button>';
758
759 jQuery('.aui-carousel-modal .modal-content').html($carousel).prepend($close);
760
761 // ayeModal.getOrCreateInstance();
762 ayeModal.show();
763
764 /* Support carousel swipe in BS modal on touch device */
765 try {
766 if ('ontouchstart' in document.documentElement || navigator.maxTouchPoints > 0) {
767 let _bsC = new bootstrap.Carousel('#aui-embed-slider-modal');
768 }
769 } catch(err) {}
770
771 // enable ajax load
772 //gd_init_carousel_ajax();
773 }
774 }
775
776 /**
777 * Init lightbox embed.
778 */
779 function aui_init_lightbox_embed(){
780 // Open a lightbox for embeded items
781 jQuery('.aui-lightbox-image, .aui-lightbox-iframe').off('click').on("click",function(ele) {
782 aui_lightbox_embed(this,ele);
783 });
784 }
785
786 /**
787 * Init modal iframe.
788 */
789 function aui_init_modal_iframe() {
790 jQuery('.aui-has-embed, [data-aui-embed="iframe"]').each(function(e){
791 if (!jQuery(this).hasClass('aui-modal-iframed') && jQuery(this).data('embed-url')) {
792 jQuery(this).addClass('aui-modal-iframed');
793
794 jQuery(this).on("click",function(e1) {
795 aui_modal_iframe('',jQuery(this).data('embed-url'),'',true,'','modal-lg','aui-modal-iframe p-0',true);
796 return false;
797 });
798 }
799 });
800 }
801
802 /**
803 * Show a toast.
804 */
805 $aui_doing_toast = false;
806 function aui_toast($id,$type,$title,$title_small,$body,$time,$can_close){
807
808 if($aui_doing_toast){setTimeout(function(){
809 aui_toast($id,$type,$title,$title_small,$body,$time,$can_close);
810 }, 500); return;}
811
812 $aui_doing_toast = true;
813
814 if($can_close == null){$can_close = false;}
815 if($time == '' || $time == null ){$time = 3000;}
816
817 // if already setup then just show
818 if(document.getElementById($id)){
819 jQuery('#'+$id).toast('show');
820 setTimeout(function(){ $aui_doing_toast = false; }, 500);
821 return;
822 }
823
824 var uniqid = Date.now();
825 if($id){
826 uniqid = $id;
827 }
828
829 $op = "";
830 $tClass = '';
831 $thClass = '';
832 $icon = "";
833
834 if ($type == 'success') {
835 $op = "opacity:.92;";
836 $tClass = 'alert bg-success w-auto';
837 $thClass = 'bg-transparent border-0 text-white';
838 $icon = "<div class='h5 m-0 p-0'><i class='fas fa-check-circle me-2'></i></div>";
839 } else if ($type == 'error' || $type == 'danger') {
840 $op = "opacity:.92;";
841 $tClass = 'alert bg-danger w-auto';
842 $thClass = 'bg-transparent border-0 text-white';
843 $icon = "<div class='h5 m-0 p-0'><i class='far fa-times-circle me-2'></i></div>";
844 } else if ($type == 'info') {
845 $op = "opacity:.92;";
846 $tClass = 'alert bg-info w-auto';
847 $thClass = 'bg-transparent border-0 text-white';
848 $icon = "<div class='h5 m-0 p-0'><i class='fas fa-info-circle me-2'></i></div>";
849 } else if ($type == 'warning') {
850 $op = "opacity:.92;";
851 $tClass = 'alert bg-warning w-auto';
852 $thClass = 'bg-transparent border-0 text-dark';
853 $icon = "<div class='h5 m-0 p-0'><i class='fas fa-exclamation-triangle me-2'></i></div>";
854 }
855
856
857 // add container if not exist
858 if(!document.getElementById("aui-toasts")){
859 jQuery('body').append('<div class="bsui" id="aui-toasts"><div class="position-fixed aui-toast-bottom-right pr-3 pe-3 mb-1" style="z-index: 500000;right: 0;bottom: 0;'+$op+'"></div></div>');
860 }
861
862 $toast = '<div id="'+uniqid+'" class="toast fade hide shadow hover-shadow '+$tClass+'" style="" role="alert" aria-live="assertive" aria-atomic="true" data-bs-delay="'+$time+'">';
863 if($type || $title || $title_small){
864 $toast += '<div class="toast-header '+$thClass+'">';
865 if($icon ){$toast += $icon;}
866 if($title){$toast += '<strong class="me-auto">'+$title+'</strong>';}
867 if($title_small){$toast += '<small>'+$title_small+'</small>';}
868 if($can_close){$toast += '<button type="button" class="ms-2 mb-1 btn-close" data-bs-dismiss="toast" aria-label="Close"></button>';}
869 $toast += '</div>';
870 }
871
872 if($body){
873 $toast += '<div class="toast-body">'+$body+'</div>';
874 }
875
876 $toast += '</div>';
877
878 jQuery('.aui-toast-bottom-right').prepend($toast);
879 jQuery('#'+uniqid).toast('show');
880 setTimeout(function(){ $aui_doing_toast = false; }, 500);
881 }
882
883 /**
884 * Animate a number.
885 */
886 function aui_init_counters(){
887
888 const animNum = (EL) => {
889
890 if (EL._isAnimated) return; // Animate only once!
891 EL._isAnimated = true;
892
893 let end = EL.dataset.auiend;
894 let start = EL.dataset.auistart;
895 let duration = EL.dataset.auiduration ? EL.dataset.auiduration : 2000;
896 let seperator = EL.dataset.auisep ? EL.dataset.auisep: '';
897
898 jQuery(EL).prop('Counter', start).animate({
899 Counter: end
900 }, {
901 duration: Math.abs(duration),
902 easing: 'swing',
903 step: function(now) {
904 const text = seperator ? (Math.ceil(now)).toLocaleString('en-US') : Math.ceil(now);
905 const html = seperator ? text.split(",").map(n => `<span class="count">${n}</span>`).join(",") : text;
906 if(seperator && seperator!=','){
907 html.replace(',',seperator);
908 }
909 jQuery(this).html(html);
910 }
911 });
912 };
913
914 const inViewport = (entries, observer) => {
915 // alert(1);
916 entries.forEach(entry => {
917 if (entry.isIntersecting) animNum(entry.target);
918 });
919 };
920
921 jQuery("[data-auicounter]").each((i, EL) => {
922 const observer = new IntersectionObserver(inViewport);
923 observer.observe(EL);
924 });
925 }
926
927
928 /**
929 * Initiate all AUI JS.
930 */
931 function aui_init(){
932
933 // init counters
934 aui_init_counters();
935
936 // nav menu submenus
937 init_nav_sub_menus();
938
939 // init tooltips
940 aui_init_tooltips();
941
942 // init select2
943 aui_init_select2();
944
945 // init flatpickr
946 aui_init_flatpickr();
947
948 // init iconpicker
949 aui_init_iconpicker();
950
951 // init Greedy nav
952 aui_init_greedy_nav();
953
954 // Set times to time ago
955 aui_time_ago('timeago');
956
957 // init multiple item carousels
958 aui_init_carousel_multiple_items();
959
960 // init lightbox embeds
961 aui_init_lightbox_embed();
962
963 /* Init modal iframe */
964 aui_init_modal_iframe();
965 }
966
967 // run on window loaded
968 jQuery(window).on("load",function() {
969 aui_init();
970 });
971
972 /* Fix modal background scroll on iOS mobile device */
973 jQuery(function($) {
974 var ua = navigator.userAgent.toLowerCase();
975 var isiOS = ua.match(/(iphone|ipod|ipad)/);
976 if (isiOS) {
977 var pS = 0; pM = parseFloat($('body').css('marginTop'));
978
979 $(document).on('show.bs.modal', function() {
980 pS = window.scrollY;
981 $('body').css({
982 marginTop: -pS,
983 overflow: 'hidden',
984 position: 'fixed',
985 });
986 }).on('hidden.bs.modal', function() {
987 $('body').css({
988 marginTop: pM,
989 overflow: 'visible',
990 position: 'inherit',
991 });
992 window.scrollTo(0, pS);
993 });
994 }
995
996 $(document).on('slide.bs.carousel', function(el) {
997 var $_modal = $(el.relatedTarget).closest('.aui-carousel-modal:visible').length ? $(el.relatedTarget).closest('.aui-carousel-modal:visible') : '';
998 if ($_modal && $_modal.find('.carousel-item iframe.aui-carousel-iframe').length) {
999 /* Unset iframe src */
1000 $_modal.find('.carousel-item.active iframe.aui-carousel-iframe').each(function(){
1001 if ($(this).attr('src')) {
1002 $(this).data('src', $(this).attr('src'));
1003 $(this).attr('src', '');
1004 }
1005 });
1006 /* Set iframe src */
1007 if ($(el.relatedTarget).find('iframe.aui-carousel-iframe').length) {
1008 $(el.relatedTarget).find('.ac-preview-loading').removeClass('d-none').addClass('d-flex');
1009 var $cIframe = $(el.relatedTarget).find('iframe.aui-carousel-iframe');
1010 if (! $cIframe.attr('src') && $cIframe.data('src')) {
1011 $cIframe.attr('src', $cIframe.data('src'));
1012 }
1013 $cIframe.on('load', function(){
1014 setTimeout(function(){$_modal.find('.ac-preview-loading').removeClass('d-flex').addClass('d-none');},1250);
1015 });
1016 }
1017 }
1018 });
1019 });
1020
1021 /**
1022 * Show a "confirm" dialog to the user (using jQuery UI's dialog)
1023 *
1024 * @param {string} message The message to display to the user
1025 * @param {string} okButtonText OPTIONAL - The OK button text, defaults to "Yes"
1026 * @param {string} cancelButtonText OPTIONAL - The Cancel button text, defaults to "No"
1027 * @returns {Q.Promise<boolean>} A promise of a boolean value
1028 */
1029 var aui_confirm = function (message, okButtonText, cancelButtonText, isDelete, large ) {
1030 okButtonText = okButtonText || 'Yes';
1031 cancelButtonText = cancelButtonText || 'Cancel';
1032 message = message || 'Are you sure?';
1033 sizeClass = large ? '' : 'modal-sm';
1034 btnClass = isDelete ? 'btn-danger' : 'btn-primary';
1035
1036 deferred = jQuery.Deferred();
1037 var $body = "";
1038 $body += "<h3 class='h4 py-3 text-center text-dark'>"+message+"</h3>";
1039 $body += "<div class='d-flex'>";
1040 $body += "<button class='btn btn-outline-secondary w-50 btn-round' data-bs-dismiss='modal' onclick='deferred.resolve(false);'>"+cancelButtonText+"</button>";
1041 $body += "<button class='btn "+btnClass+" ms-2 w-50 btn-round' data-bs-dismiss='modal' onclick='deferred.resolve(true);'>"+okButtonText+"</button>";
1042 $body += "</div>";
1043 $modal = aui_modal('',$body,'',false,'',sizeClass);
1044
1045 return deferred.promise();
1046 };
1047
1048 /**
1049 * Flip the color scheem on scroll
1050 * @param $value
1051 * @param $iframe
1052 */
1053 function aui_flip_color_scheme_on_scroll($value, $iframe){
1054 if(!$value) $value = window.scrollY;
1055
1056 var navbar = $iframe ? $iframe.querySelector('.color-scheme-flip-on-scroll') : document.querySelector('.color-scheme-flip-on-scroll');
1057 if (navbar == null) return;
1058
1059 let cs_original = navbar.dataset.cso;
1060 let cs_scroll = navbar.dataset.css;
1061
1062 if (!cs_scroll && !cs_original) {
1063 if( navbar.classList.contains('navbar-light') ){
1064 cs_original = 'navbar-light';
1065 cs_scroll = 'navbar-dark';
1066 }else if( navbar.classList.contains('navbar-dark') ){
1067 cs_original = 'navbar-dark';
1068 cs_scroll = 'navbar-light';
1069 }
1070
1071 navbar.dataset.cso = cs_original;
1072 navbar.dataset.css = cs_scroll;
1073 }
1074
1075 if($value > 0 || navbar.classList.contains('nav-menu-open') ){
1076 navbar.classList.remove(cs_original);
1077 navbar.classList.add(cs_scroll);
1078 }else{
1079 navbar.classList.remove(cs_scroll);
1080 navbar.classList.add(cs_original);
1081 }
1082 }
1083
1084 /**
1085 * Add a window scrolled data element.
1086 */
1087 window.onscroll = function () {
1088 aui_set_data_scroll();
1089 aui_flip_color_scheme_on_scroll();
1090 };
1091
1092 /**
1093 * Set scroll data element.
1094 */
1095 function aui_set_data_scroll(){
1096 document.documentElement.dataset.scroll = window.scrollY;
1097 }
1098
1099 // call data scroll function ASAP.
1100 aui_set_data_scroll();
1101 aui_flip_color_scheme_on_scroll();
1102
1103 <?php
1104 // FSE tweaks.
1105 if(!empty($_REQUEST['postType']) || !empty($_REQUEST['canvas']) ){ ?>
1106 function aui_fse_set_data_scroll() {
1107 console.log('init scroll');
1108 let Iframe = document.getElementsByClassName("edit-site-visual-editor__editor-canvas");
1109 if( Iframe[0] === undefined ){ return; }
1110 let iframe_doc = Iframe[0].contentWindow ? Iframe[0].contentWindow.document : Iframe[0].contentDocument;
1111 Iframe[0].contentWindow.onscroll = function () {
1112 iframe_doc.documentElement.dataset.scroll = Iframe[0].contentWindow.scrollY;
1113 aui_flip_color_scheme_on_scroll(Iframe[0].contentWindow.scrollY,iframe_doc);
1114 };
1115 }
1116
1117 setTimeout(function(){
1118 aui_fse_set_data_scroll();
1119 }, 3000);
1120
1121 // fire when URL changes also.
1122 let FSElastUrl = location.href;
1123 new MutationObserver(() => {
1124 const url = location.href;
1125 if (url !== FSElastUrl) {
1126 FSElastUrl = url;
1127 aui_fse_set_data_scroll();
1128 // fire a second time incase of load delays.
1129 setTimeout(function(){
1130 aui_fse_set_data_scroll();
1131 }, 2000);
1132 }
1133 }).observe(document, {subtree: true, childList: true});
1134
1135
1136 /**
1137 * Convert hex color to rgb values.
1138 *
1139 * @param hex
1140 * @returns {string|null}
1141 */
1142 function aui_fse_hexToRgb(hex) {
1143 var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex.trim().substring(0, 7));
1144 return result ? parseInt(result[1], 16) +','+parseInt(result[2], 16)+','+parseInt(result[3], 16) : null;
1145 }
1146
1147 /**
1148 * update colors as the style colour pallet is changed
1149 * @param $color
1150 */
1151 function aui_fse_sync_site_colors($color){
1152
1153 const getColorHex = () => {
1154 const element = jQuery(".edit-site-visual-editor__editor-canvas").contents().find(".editor-styles-wrapper").get(0);
1155 const style = element == null ? '' : window.getComputedStyle(element).getPropertyValue('--wp--preset--color--'+$color);
1156 return style;
1157 };
1158
1159 // set the initial ColorHex
1160 let colorHex = getColorHex();
1161
1162
1163 wp.data.subscribe(() => {
1164
1165 // get the current ColorHex
1166 const newColorHex = getColorHex();
1167
1168 // only do something if ColorHex has changed.
1169 if( newColorHex && colorHex !== newColorHex ) {
1170 jQuery(".edit-site-visual-editor__editor-canvas").contents().find("html body").get(0).style.setProperty('--bs-'+$color+'-rgb',aui_fse_hexToRgb(newColorHex));
1171 }
1172
1173 // update the newColorHex variable.
1174 colorHex = newColorHex;
1175
1176 });
1177 }
1178
1179 /**
1180 * update colors as the style colour pallet is changed
1181 * @param $color
1182 */
1183 function aui_fse_sync_site_typography(){
1184 const getGlobalStyles = () => {
1185 const { select } = wp.data;
1186 const settings = select('core/block-editor').getSettings();
1187
1188 return ( settings && settings.styles && settings.styles[3].css ? settings.styles[3].css : null );
1189 };
1190
1191 // set the initial styles
1192 let Styles = getGlobalStyles();
1193
1194 wp.data.subscribe(() => {
1195 // get the current styles
1196 const newStyles = getGlobalStyles();
1197
1198 // only do something if newStyles has changed.
1199 if( newStyles && Styles !== newStyles ) {
1200 // heading sizes
1201 aui_updateCssRule('body.editor-styles-wrapper h1', 'font-size', aui_parseCSS(newStyles, 'h1', 'font-size'));
1202 aui_updateCssRule('body.editor-styles-wrapper h2', 'font-size', aui_parseCSS(newStyles, 'h2', 'font-size'));
1203 aui_updateCssRule('body.editor-styles-wrapper h3', 'font-size', aui_parseCSS(newStyles, 'h3', 'font-size'));
1204 aui_updateCssRule('body.editor-styles-wrapper h4', 'font-size', aui_parseCSS(newStyles, 'h4', 'font-size'));
1205 aui_updateCssRule('body.editor-styles-wrapper h5', 'font-size', aui_parseCSS(newStyles, 'h5', 'font-size'));
1206 aui_updateCssRule('body.editor-styles-wrapper h6', 'font-size', aui_parseCSS(newStyles, 'h6', 'font-size'));
1207
1208 // ALl Headings
1209 aui_updateCssRule('body.editor-styles-wrapper h1, body.editor-styles-wrapper h2, body.editor-styles-wrapper h3, body.editor-styles-wrapper h4, body.editor-styles-wrapper h5, body.editor-styles-wrapper h6', 'font-family', aui_parseCSS(newStyles, 'h1, h2, h3, h4, h5, h6', 'font-family'));
1210
1211 // individual headings
1212 aui_updateCssRule('body.editor-styles-wrapper h1', 'font-family', aui_parseCSS(newStyles, 'h1{', 'font-family'));
1213 aui_updateCssRule('body.editor-styles-wrapper h2', 'font-family', aui_parseCSS(newStyles, 'h2{', 'font-family'));
1214 aui_updateCssRule('body.editor-styles-wrapper h3', 'font-family', aui_parseCSS(newStyles, 'h3{', 'font-family'));
1215 aui_updateCssRule('body.editor-styles-wrapper h4', 'font-family', aui_parseCSS(newStyles, 'h4{', 'font-family'));
1216 aui_updateCssRule('body.editor-styles-wrapper h5', 'font-family', aui_parseCSS(newStyles, 'h5{', 'font-family'));
1217 aui_updateCssRule('body.editor-styles-wrapper h6', 'font-family', aui_parseCSS(newStyles, 'h6{', 'font-family'));
1218
1219 // console.log(aui_parseCSS(newStyles, 'h2{', 'font-family'));
1220
1221 // color
1222 aui_updateCssRule('body.editor-styles-wrapper h1, body.editor-styles-wrapper h2, body.editor-styles-wrapper h3, body.editor-styles-wrapper h4, body.editor-styles-wrapper h5, body.editor-styles-wrapper h6', 'color', aui_parseCSS(newStyles, 'h1, h2, h3, h4, h5, h6', 'color'));
1223
1224 aui_updateCssRule('body.editor-styles-wrapper h1', 'color', aui_parseCSS(newStyles, 'h1{', 'color'));
1225 aui_updateCssRule('body.editor-styles-wrapper h2', 'color', aui_parseCSS(newStyles, 'h2{', 'color'));
1226 aui_updateCssRule('body.editor-styles-wrapper h3', 'color', aui_parseCSS(newStyles, 'h3{', 'color'));
1227 aui_updateCssRule('body.editor-styles-wrapper h4', 'color', aui_parseCSS(newStyles, 'h4{', 'color'));
1228 aui_updateCssRule('body.editor-styles-wrapper h5', 'color', aui_parseCSS(newStyles, 'h5{', 'color'));
1229 aui_updateCssRule('body.editor-styles-wrapper h6', 'color', aui_parseCSS(newStyles, 'h6{', 'color'));
1230
1231
1232
1233 //background
1234 aui_updateCssRule('body.editor-styles-wrapper h1, body.editor-styles-wrapper h2, body.editor-styles-wrapper h3, body.editor-styles-wrapper h4, body.editor-styles-wrapper h5, body.editor-styles-wrapper h6', 'background', aui_parseCSS(newStyles, 'h1, h2, h3, h4, h5, h6', 'background'));
1235
1236 aui_updateCssRule('body.editor-styles-wrapper h1', 'background', aui_parseCSS(newStyles, 'h1{', 'background'));
1237 aui_updateCssRule('body.editor-styles-wrapper h2', 'background', aui_parseCSS(newStyles, 'h2{', 'background'));
1238 aui_updateCssRule('body.editor-styles-wrapper h3', 'background', aui_parseCSS(newStyles, 'h3{', 'background'));
1239 aui_updateCssRule('body.editor-styles-wrapper h4', 'background', aui_parseCSS(newStyles, 'h4{', 'background'));
1240 aui_updateCssRule('body.editor-styles-wrapper h5', 'background', aui_parseCSS(newStyles, 'h5{', 'background'));
1241 aui_updateCssRule('body.editor-styles-wrapper h6', 'background', aui_parseCSS(newStyles, 'h6{', 'background'));
1242
1243
1244
1245 // console.log('Font size of h2 is:', fontSize);
1246 }
1247
1248 // update the newStyles variable.
1249 Styles = newStyles;
1250
1251
1252 });
1253 }
1254
1255 setTimeout(function(){
1256 aui_sync_admin_styles();
1257 }, 10000);
1258
1259 function aui_sync_admin_styles(){
1260 aui_fse_sync_site_colors('primary');
1261 aui_fse_sync_site_colors('danger');
1262 aui_fse_sync_site_colors('warning');
1263 aui_fse_sync_site_colors('info');
1264 aui_fse_sync_site_typography();
1265 }
1266
1267 // setTimeout(function(){
1268 // aui_listen_global_style_click();
1269 // }, 3000);
1270 //
1271 // function aui_listen_global_style_click(){
1272 // setTimeout(function(){
1273 // // check for global stylebook clicks
1274 // jQuery('.interface-pinned-items button').click(function() {
1275 // aui_listen_stylebook_click();
1276 // });
1277 // }, 500);
1278 // }
1279 //
1280 //
1281 //
1282 // function aui_listen_stylebook_click(){
1283 // setTimeout(function(){
1284 // // check for global stylebook clicks
1285 // jQuery('.edit-site-global-styles-sidebar__header .components-button.has-icon').click(function() {
1286 // setTimeout(function(){
1287 // aui_sync_admin_styles();
1288 // }, 500);
1289 // });
1290 // }, 500);
1291 // }
1292
1293
1294
1295
1296 function aui_parseCSS(cssString, selector, property) {
1297 // Split the CSS string on closing braces
1298 const rules = cssString.split('}');
1299
1300 // Search for the selector and property
1301 for (let rule of rules) {
1302 if (rule.includes(selector) && rule.includes(property)) {
1303 // Extract the rule's content
1304 const ruleContent = rule.split('{')[1];
1305
1306 // Split properties and search for the desired property
1307 const properties = ruleContent.split(';');
1308 for (let prop of properties) {
1309 if (prop.includes(property)) {
1310 // Extract and return the property value
1311 return prop.split(':')[1].trim();
1312 }
1313 }
1314 }
1315 }
1316
1317 return null;
1318 }
1319
1320 // Function to update a CSS rule
1321 function aui_updateCssRule(selector, property, value) {
1322 // check fi we are viewing stylebook
1323
1324 var aui_inline_css = jQuery(".edit-site-visual-editor__editor-canvas").contents().find("#ayecode-ui-fse-inline-css").get(0);
1325 var aui_inline_css_stylebook = jQuery(".edit-site-style-book__iframe").contents().find("#ayecode-ui-fse-inline-css").get(0);
1326
1327 if (aui_inline_css && aui_inline_css.sheet) {
1328 var styleSheet = aui_inline_css.sheet;
1329 }else if(aui_inline_css_stylebook && aui_inline_css_stylebook.sheet){
1330 var styleSheet = aui_inline_css_stylebook.sheet;
1331 }else{
1332 return;
1333 }
1334
1335 var rules = styleSheet.cssRules || styleSheet.rules;
1336
1337 // console.log(rules);
1338
1339 for (var i = 0; i < rules.length; i++) {
1340 if (rules[i].selectorText === selector) {
1341 rules[i].style[property] = value;
1342 // console.log('update rule');
1343 return; // Exit the function once the rule is found and updated
1344 }
1345 }
1346
1347 // If the rule doesn't exist, optionally add it
1348 styleSheet.insertRule(`${selector} { ${property}: ${value}; }`, rules.length);
1349 // console.log(`insert rule ${selector}`);
1350 }
1351
1352 <?php } ?>
1353
1354
1355 </script>
1356