PluginProbe
King Addons for Elementor – 80+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce, Mega Menu, Popup Builder / 51.1.78
King Addons for Elementor – 80+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce, Mega Menu, Popup Builder v51.1.78
51.1.83 51.1.82 51.1.81 51.1.79 51.1.78 51.1.77 51.1.76 51.1.74 51.1.75 51.1.65 51.1.64 51.1.63 trunk 51.1.14 51.1.2 51.1.35 51.1.36 51.1.37 51.1.38 51.1.39 51.1.44 51.1.45 51.1.46 51.1.47 51.1.49 All 37 releases
king-addons / includes / extensions / Theme_Builder / preview-handler.js

preview-handler.js in King Addons for Elementor – 80+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce, Mega Menu, Popup Builder 51.1.78, at includes/extensions/Theme_Builder/preview-handler.js

89 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * Theme Builder preview context handler.
3 *
4 * Adjusts the Elementor preview to properly display dynamic widgets
5 * in the context of Theme Builder templates.
6 *
7 * @package King_Addons
8 */
9 (function ($) {
10 'use strict';
11
12 /**
13 * Apply preview context adjustments for Theme Builder widgets.
14 *
15 * @param {jQuery} $scope The widget element scope.
16 */
17 const applyPreviewContext = ($scope) => {
18 // Theme Builder widgets that need special handling in preview
19 const tbWidgets = [
20 'king-addons-tb-post-title',
21 'king-addons-tb-post-content',
22 'king-addons-tb-post-excerpt',
23 'king-addons-tb-featured-image',
24 'king-addons-tb-post-meta',
25 'king-addons-tb-author-box',
26 'king-addons-tb-post-comments',
27 'king-addons-tb-post-navigation',
28 'king-addons-tb-post-taxonomies',
29 'king-addons-tb-related-posts',
30 'king-addons-tb-archive-title',
31 'king-addons-tb-archive-description',
32 'king-addons-tb-archive-posts',
33 'king-addons-tb-archive-pagination',
34 'king-addons-tb-archive-result-count',
35 'king-addons-tb-404-title',
36 'king-addons-tb-404-description',
37 'king-addons-tb-404-search-form',
38 'king-addons-tb-back-to-home'
39 ];
40
41 // Check if this is a TB widget
42 const widgetType = $scope.data('widget_type');
43 if (!widgetType) {
44 return;
45 }
46
47 const widgetName = widgetType.split('.')[0];
48 if (!tbWidgets.includes(widgetName)) {
49 return;
50 }
51
52 // Add a visual indicator for TB widgets in editor
53 if (!$scope.find('.ka-tb-preview-notice').length) {
54 const $notice = $('<div class="ka-tb-preview-notice" style="font-size: 11px; color: #666; padding: 4px 8px; background: #f0f0f0; border-radius: 3px; margin-bottom: 8px;">');
55 $notice.text('Preview: Using sample data');
56 // Only show notice in editor mode, not on frontend
57 if (window.elementorFrontend && window.elementorFrontend.isEditMode && window.elementorFrontend.isEditMode()) {
58 $scope.prepend($notice);
59 }
60 }
61 };
62
63 /**
64 * Initialize preview handlers.
65 */
66 const init = () => {
67 if (!window.elementorFrontend || !window.elementorFrontend.hooks) {
68 return;
69 }
70
71 // Apply context when any element becomes ready
72 elementorFrontend.hooks.addAction('frontend/element_ready/global', applyPreviewContext);
73
74 // Handle dynamic content refresh
75 $(document).on('elementor/editor/after_save', () => {
76 // Trigger refresh of dynamic widgets after save
77 $(document).trigger('ka-theme-builder-refresh');
78 });
79 };
80
81 // Initialize when Elementor frontend is ready
82 $(window).on('elementor/frontend/init', init);
83
84 // Fallback initialization
85 if (window.elementorFrontend && window.elementorFrontend.hooks) {
86 init();
87 }
88 })(jQuery);
89