PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / 3.8.0
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! v3.8.0
3.8.0 3.7.5 3.7.4 3.7.3 3.7.2 1-final 3.7.1 3.7.0 3.6.8 3.6.7 3.6.6 3.6.5 3.6.4 3.6.3 3.6.2 3.6.1 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 All 112 releases
templately / views / ai-editor-page.php

ai-editor-page.php in Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! 3.8.0, at views/ai-editor-page.php

303 lines 9.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Templately AI Editor page shell (041 phase 1) — branded fullscreen frame
4 * around the post's NATIVE editor. Variables (extracted by Helper::views):
5 *
6 * @var string $src iframe URL (post.php?action=…&templately_host=1)
7 * @var string $exit_url the native editor without the host signal
8 * @var string $exit_wp_url the wp-admin list to return to (or the dashboard)
9 * @var string $post_title
10 * @var string $platform 'elementor' | 'gutenberg'
11 */
12 if ( ! defined( 'ABSPATH' ) ) {
13 exit;
14 }
15 ?>
16 <style>
17 /* Fullscreen takeover — this screen only (body.templately-ai-editor-page). */
18 body.templately-ai-editor-page #adminmenumain,
19 body.templately-ai-editor-page #wpadminbar,
20 body.templately-ai-editor-page #wpfooter,
21 body.templately-ai-editor-page #screen-meta,
22 body.templately-ai-editor-page #screen-meta-links {
23 display: none;
24 }
25 body.templately-ai-editor-page,
26 body.templately-ai-editor-page #wpcontent,
27 body.templately-ai-editor-page #wpbody-content {
28 margin: 0 !important;
29 padding: 0 !important;
30 }
31 /* The shell is fixed inset-0 — anything taller behind it (admin notices
32 etc.) must never spawn an outer scrollbar. */
33 html.templately-ai-editor-page-html,
34 body.templately-ai-editor-page {
35 overflow: hidden !important;
36 }
37 html.wp-toolbar {
38 padding-top: 0 !important;
39 }
40 .templately-ai-editor-shell {
41 position: fixed;
42 inset: 0;
43 display: flex;
44 flex-direction: column;
45 background: #fff;
46 z-index: 99999;
47 }
48 .templately-ai-editor-shell__header {
49 display: flex;
50 align-items: center;
51 gap: 12px;
52 height: 48px;
53 padding: 0 16px;
54 border-bottom: 1px solid #EAECF0;
55 background: #f8f8f8;
56 flex-shrink: 0;
57 }
58 .templately-ai-editor-shell__header img {
59 width: 24px;
60 height: 24px;
61 }
62 .templately-ai-editor-shell__title {
63 font-size: 13px;
64 font-weight: 600;
65 color: #101828;
66 white-space: nowrap;
67 overflow: hidden;
68 text-overflow: ellipsis;
69 }
70 .templately-ai-editor-shell__actions {
71 margin-left: auto;
72 display: flex;
73 align-items: center;
74 gap: 10px;
75 }
76 .templately-ai-editor-shell__exit {
77 font-size: 12px;
78 color: #475467;
79 text-decoration: none;
80 }
81 .templately-ai-editor-shell__exit:hover {
82 color: #101828;
83 }
84 /* Deliberately subtle — a gray chip, not a primary action. */
85 .templately-ai-editor-shell__wp {
86 display: inline-flex;
87 align-items: center;
88 gap: 6px;
89 font-size: 12px;
90 font-weight: 500;
91 color: #475467;
92 text-decoration: none;
93 background: #F2F4F7;
94 border: 1px solid #EAECF0;
95 border-radius: 6px;
96 padding: 5px 10px;
97 line-height: 1;
98 }
99 .templately-ai-editor-shell__wp:hover {
100 background: #EAECF0;
101 color: #101828;
102 }
103 .templately-ai-editor-shell__wp .dashicons {
104 width: 16px;
105 height: 16px;
106 font-size: 16px;
107 line-height: 1;
108 }
109 .templately-ai-editor-shell__body {
110 position: relative;
111 flex: 1;
112 display: flex;
113 }
114 .templately-ai-editor-shell iframe {
115 flex: 1;
116 width: 100%;
117 border: 0;
118 }
119 /* Branded boot state — covers the editor's own loaders/chrome shuffle
120 until the chat reports ready (templately-host-ready in the iframe). */
121 .templately-ai-editor-shell__loading {
122 position: absolute;
123 inset: 0;
124 display: flex;
125 flex-direction: column;
126 align-items: center;
127 justify-content: center;
128 gap: 16px;
129 background: #fff;
130 z-index: 5;
131 transition: opacity 0.3s ease;
132 }
133 .templately-ai-editor-shell__loading img {
134 width: 72px;
135 height: 72px;
136 }
137 .templately-ai-editor-shell__loading p {
138 margin: 0;
139 font-size: 13px;
140 color: #667085;
141 }
142 .templately-ai-editor-shell__progress {
143 width: 220px;
144 height: 4px;
145 border-radius: 2px;
146 background: #EAECF0;
147 overflow: hidden;
148 }
149 .templately-ai-editor-shell__progress span {
150 display: block;
151 height: 100%;
152 width: 0;
153 border-radius: 2px;
154 background: #5E2EFF;
155 transition: width 0.4s ease;
156 }
157 .templately-ai-editor-shell.is-ready .templately-ai-editor-shell__loading {
158 opacity: 0;
159 pointer-events: none;
160 }
161 .templately-ai-editor-shell__fallback {
162 display: none;
163 padding: 40px;
164 font-size: 14px;
165 color: #475467;
166 }
167 .templately-ai-editor-shell.is-blocked iframe {
168 display: none;
169 }
170 .templately-ai-editor-shell.is-blocked .templately-ai-editor-shell__fallback {
171 display: block;
172 }
173 </style>
174
175 <div class="templately-ai-editor-shell" id="templately-ai-editor-shell">
176 <div class="templately-ai-editor-shell__header">
177 <img src="<?php echo esc_url( templately()->assets->icon( 'logos/logo.svg' ) ); ?>" alt="Templately" />
178 <span class="templately-ai-editor-shell__title">
179 <?php
180 printf(
181 /* translators: %s: post title */
182 esc_html__( 'Editing: %s', 'templately' ),
183 esc_html( $post_title )
184 );
185 ?>
186 </span>
187 <div class="templately-ai-editor-shell__actions">
188 <a class="templately-ai-editor-shell__exit" href="<?php echo esc_url( $exit_url ); ?>">
189 <?php esc_html_e( 'Go to Editor', 'templately' ); ?>
190 </a>
191 <a class="templately-ai-editor-shell__wp" href="<?php echo esc_url( $exit_wp_url ); ?>">
192 <span class="dashicons dashicons-wordpress" aria-hidden="true"></span>
193 <?php esc_html_e( 'Exit to WordPress', 'templately' ); ?>
194 </a>
195 </div>
196 </div>
197 <div class="templately-ai-editor-shell__body">
198 <iframe id="templately-ai-editor-frame" src="<?php echo esc_url( $src ); ?>" title="<?php esc_attr_e( 'Page editor', 'templately' ); ?>"></iframe>
199 <div class="templately-ai-editor-shell__loading">
200 <img src="<?php echo esc_url( templately()->assets->icon( 'logos/loading-logo.gif' ) ); ?>" alt="" />
201 <div class="templately-ai-editor-shell__progress"><span id="templately-ai-editor-progress"></span></div>
202 <p id="templately-ai-editor-progress-label"><?php esc_html_e( 'Loading the editor…', 'templately' ); ?></p>
203 </div>
204 <div class="templately-ai-editor-shell__fallback">
205 <?php
206 printf(
207 /* translators: %s: edit-post URL */
208 wp_kses( __( 'Your site blocks embedded editing, so the editor could not load here. <a href="%s">Open the editor directly</a>.', 'templately' ), [ 'a' => [ 'href' => [] ] ] ),
209 esc_url( $exit_url )
210 );
211 ?>
212 </div>
213 </div>
214 </div>
215
216 <script>
217 ( function () {
218 document.documentElement.className += ' templately-ai-editor-page-html';
219 var frame = document.getElementById( 'templately-ai-editor-frame' );
220 var shell = document.getElementById( 'templately-ai-editor-shell' );
221 var bar = document.getElementById( 'templately-ai-editor-progress' );
222 var label = document.getElementById( 'templately-ai-editor-progress-label' );
223
224 // Staged, REAL progress from same-origin boot signals, with a gentle
225 // creep toward each stage's cap so slow steps still look alive. The
226 // overlay drops when the chat inside reports ready
227 // (body.templately-host-ready) — the user never sees the editor's own
228 // loaders or its chrome being stripped.
229 // Stage 1 must NOT count the iframe's initial about:blank document
230 // (readyState 'complete' before navigation even starts) — it once
231 // raced the bar to ~54% "Starting things up", then the REAL document
232 // arrived in 'loading' state and everything snapped BACKWARD.
233 var stages = [
234 { cap: 20, label: <?php echo wp_json_encode( __( 'Loading the editor…', 'templately' ) ); ?>, reached: function ( doc ) {
235 return !! doc && doc.readyState !== 'loading' && doc.location && doc.location.href !== 'about:blank';
236 } },
237 { cap: 55, label: <?php echo wp_json_encode( __( 'Starting things up…', 'templately' ) ); ?>, reached: function ( doc, win ) {
238 return !! ( win && ( win.elementor || ( win.wp && win.wp.data ) ) );
239 } },
240 { cap: 85, label: <?php echo wp_json_encode( __( 'Rendering your page…', 'templately' ) ); ?>, reached: function ( doc, win ) {
241 if ( win && win.elementor ) {
242 return !! ( win.elementor.getPreviewContainer && win.elementor.getPreviewContainer() );
243 }
244 return !! ( doc && doc.querySelector( '.interface-interface-skeleton__content' ) );
245 } },
246 { cap: 100, label: <?php echo wp_json_encode( __( 'Almost there…', 'templately' ) ); ?>, reached: function ( doc ) {
247 return !! ( doc && doc.body && doc.body.classList.contains( 'templately-host-ready' ) );
248 } }
249 ];
250 var progress = 0;
251 var stageShown = 0;
252
253 var readyPoll = setInterval( function () {
254 var doc = null, win = null;
255 try {
256 doc = frame.contentDocument;
257 win = frame.contentWindow;
258 } catch ( e ) {
259 return; // inaccessible — the blocked check below handles it
260 }
261 var stageIndex = 0;
262 for ( var i = 0; i < stages.length; i++ ) {
263 if ( stages[ i ].reached( doc, win ) ) {
264 stageIndex = ( i + 1 < stages.length ) ? i + 1 : i;
265 } else {
266 break;
267 }
268 }
269 // MONOTONIC: boot signals can flicker (document swaps reset
270 // readyState) — the bar and the label only ever move FORWARD.
271 stageShown = Math.max( stageShown, stageIndex );
272 var stage = stages[ stageShown ];
273 var done = stages[ stages.length - 1 ].reached( doc, win );
274 progress = done ? 100 : Math.max( progress, Math.min( Math.max( progress + 1, stage.cap - 15 ), stage.cap - 1 ) );
275 bar.style.width = progress + '%';
276 label.textContent = stage.label;
277 if ( done ) {
278 clearInterval( readyPoll );
279 setTimeout( function () {
280 shell.className += ' is-ready';
281 }, 350 );
282 }
283 }, 300 );
284
285 // Frame-refused fallback: wp-admin is same-origin (SAMEORIGIN default
286 // is fine), but security plugins forcing X-Frame-Options: DENY leave
287 // the frame permanently inaccessible — reveal the direct link instead.
288 setTimeout( function () {
289 var blocked = false;
290 try {
291 var doc = frame.contentDocument;
292 blocked = ! doc || ( doc.readyState === 'complete' && doc.location.href === 'about:blank' );
293 } catch ( e ) {
294 blocked = true;
295 }
296 if ( blocked ) {
297 clearInterval( readyPoll );
298 shell.className += ' is-blocked is-ready';
299 }
300 }, 8000 );
301 } )();
302 </script>
303