default.php
3 days ago
default_api.php
3 days ago
default_api_basic.php
3 days ago
default_api_users.php
3 days ago
default_backup.php
3 days ago
default_backup_basic.php
3 days ago
default_customizer.php
3 days ago
default_customizer_addcss.php
3 days ago
default_customizer_form.php
3 days ago
default_customizer_preview.php
3 days ago
default_customizer_toolbar.php
3 days ago
default_webhooks.php
3 days ago
default_webhooks_basic.php
3 days ago
index.html
3 days ago
default_customizer_preview.php
171 lines
| 1 | <?php |
| 2 | /** |
| 3 | * @package VikAppointments |
| 4 | * @subpackage core |
| 5 | * @author E4J s.r.l. |
| 6 | * @copyright Copyright (C) 2021 E4J s.r.l. All Rights Reserved. |
| 7 | * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL |
| 8 | * @link https://vikwp.com |
| 9 | */ |
| 10 | |
| 11 | // No direct access |
| 12 | defined('ABSPATH') or die('No script kiddies please!'); |
| 13 | |
| 14 | ?> |
| 15 | |
| 16 | <style> |
| 17 | iframe#customizer-preview { |
| 18 | min-height: 600px; |
| 19 | width: 60%; |
| 20 | margin-left: 15px; |
| 21 | border: 1px solid #ddd; |
| 22 | |
| 23 | transition: all 400ms ease-in-out 0s; |
| 24 | -moz-transition: all 400ms ease-in-out 0s; |
| 25 | -webkit-transition: all 400ms ease-in-out 0s; |
| 26 | -o-transition: all 400ms ease-in-out 0s; |
| 27 | } |
| 28 | iframe#customizer-preview.__hide { |
| 29 | width: 0 !important; |
| 30 | border: 0 !important; |
| 31 | margin-left: 0 !important; |
| 32 | } |
| 33 | #vaptabview4 .config-panel-tabview { |
| 34 | display: flex; |
| 35 | flex-wrap: wrap; |
| 36 | } |
| 37 | #vaptabview4 .config-panel-tabview-inner { |
| 38 | flex: 1; |
| 39 | } |
| 40 | |
| 41 | @media screen and (max-width: 938px) { |
| 42 | iframe#customizer-preview { |
| 43 | width: 100%; |
| 44 | margin: 15px 0 0 0; |
| 45 | } |
| 46 | iframe#customizer-preview.__hide { |
| 47 | display: none; |
| 48 | } |
| 49 | } |
| 50 | </style> |
| 51 | |
| 52 | <iframe id="customizer-preview" src="<?php echo $this->filters['preview_page']; ?>" class="hidden-phone<?php echo $this->filters['preview_status'] ? '' : ' __hide'; ?>"></iframe> |
| 53 | |
| 54 | <script> |
| 55 | (function($) { |
| 56 | 'use strict'; |
| 57 | |
| 58 | window['getCustomizerPreview'] = () => { |
| 59 | return onInstanceReady(() => { |
| 60 | // load iframe |
| 61 | const iframe = $('iframe#customizer-preview'); |
| 62 | |
| 63 | if (!iframe) { |
| 64 | // iframe not yet ready |
| 65 | return false; |
| 66 | } |
| 67 | |
| 68 | // load iframe contents |
| 69 | const iframeContents = iframe.contents(); |
| 70 | |
| 71 | if (!iframeContents) { |
| 72 | // cannot access iframe |
| 73 | return false; |
| 74 | } |
| 75 | |
| 76 | // access the root of the iframe preview |
| 77 | return iframeContents[0].querySelector(':root'); |
| 78 | }); |
| 79 | } |
| 80 | |
| 81 | window['applyCustomizerPreviewCSS'] = () => { |
| 82 | getCustomizerPreview().then((preview) => { |
| 83 | // delete existing custom CSS file |
| 84 | $(preview).find('head link[href*="assets/css/vap-custom.css"]').remove(); |
| 85 | |
| 86 | // get existing inline block |
| 87 | let inlineBlock = $(preview).find('head style#vap-customizer-inline-css'); |
| 88 | |
| 89 | if (!inlineBlock.length) { |
| 90 | // create style block |
| 91 | inlineBlock = $('<style id="vap-customizer-inline-css"></style>'); |
| 92 | // append block into the head |
| 93 | $(preview).find('head').append(inlineBlock); |
| 94 | } |
| 95 | |
| 96 | // update CSS code |
| 97 | inlineBlock.html(Joomla.editors.instances.custom_css_code.getValue()); |
| 98 | }); |
| 99 | } |
| 100 | |
| 101 | window['refreshCustomizerEnvironmentVars'] = () => { |
| 102 | getCustomizerPreview().then((preview) => { |
| 103 | $('[name^="customizer["]').each(function() { |
| 104 | // extract CSS var from name |
| 105 | const match = $(this).attr('name').match(/^customizer\[(.*?)\]$/); |
| 106 | const key = match[1]; |
| 107 | |
| 108 | // extract value from input |
| 109 | let value = $(this).val(); |
| 110 | |
| 111 | if (key.match(/-(?:color|background|border)$/)) { |
| 112 | // sanitize HEX color |
| 113 | value = '#' + value.replace(/^#/, ''); |
| 114 | } |
| 115 | |
| 116 | // overwrite CSS var |
| 117 | preview.style.setProperty(key, value); |
| 118 | }); |
| 119 | }); |
| 120 | } |
| 121 | |
| 122 | window['toggleCustomizerPreview'] = () => { |
| 123 | const iframe = $('iframe#customizer-preview'); |
| 124 | |
| 125 | let status = 1; |
| 126 | |
| 127 | if (iframe.hasClass('__hide')) { |
| 128 | iframe.removeClass('__hide'); |
| 129 | } else { |
| 130 | iframe.addClass('__hide'); |
| 131 | status = 0; |
| 132 | } |
| 133 | |
| 134 | return status; |
| 135 | } |
| 136 | |
| 137 | window['changeCustomizerPreviewPage'] = (url) => { |
| 138 | $('iframe#customizer-preview').attr('src', url); |
| 139 | } |
| 140 | |
| 141 | $(function() { |
| 142 | $('[name^="customizer["]').on('change', function() { |
| 143 | getCustomizerPreview().then((preview) => { |
| 144 | // extract CSS var from name |
| 145 | const match = $(this).attr('name').match(/^customizer\[(.*?)\]$/); |
| 146 | const key = match[1]; |
| 147 | |
| 148 | // extract value from input |
| 149 | let value = $(this).val(); |
| 150 | |
| 151 | if (key.match(/-(?:color|background|border)$/)) { |
| 152 | // sanitize HEX color |
| 153 | value = '#' + value.replace(/^#/, ''); |
| 154 | } |
| 155 | |
| 156 | // overwrite CSS var |
| 157 | preview.style.setProperty(key, value); |
| 158 | }); |
| 159 | }); |
| 160 | |
| 161 | // refresh custom contents every time the preview page changes |
| 162 | $('iframe#customizer-preview').on('load', () => { |
| 163 | // refresh custom CSS |
| 164 | applyCustomizerPreviewCSS(); |
| 165 | // refresh environment vars |
| 166 | refreshCustomizerEnvironmentVars(); |
| 167 | }); |
| 168 | }); |
| 169 | })(jQuery); |
| 170 | </script> |
| 171 |