PluginProbe
Yatra – Travel Booking & Tour Operator Software / 3.0.2.8
Yatra – Travel Booking & Tour Operator Software v3.0.2.8
3.0.16 3.0.15 3.0.14 3.0.14.1 3.0.14.2 3.0.12 3.0.13 3.0.11 3.0.10 3.0.9 3.0.8 3.0.7 3.0.6 3.0.5 3.0.5.1 3.0.4 3.0.3 3.0.2.9 3.0.2.7 3.0.2.8 3.0.2.6 trunk 1.0.0 2.0.0 2.0.1 All 84 releases
yatra / assets / js / tour-viewer.js

tour-viewer.js in Yatra – Travel Booking & Tour Operator Software 3.0.2.8, at assets/js/tour-viewer.js

174 lines 5.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * Yatra 360° Tour Viewer Module
3 * Reusable 360° virtual tour viewer
4 *
5 * @package Yatra
6 * @version 1.0.0
7 */
8
9 (function() {
10 'use strict';
11
12 class YatraTourViewer {
13 constructor() {
14 this.modal = null;
15 this.iframe = null;
16 this.currentTour = null;
17 this.init();
18 }
19
20 init() {
21 this.createModal();
22 this.attachEventListeners();
23 }
24
25 createModal() {
26 // Check if modal already exists
27 if (document.getElementById('yatra-tour-viewer-modal')) {
28 this.modal = document.getElementById('yatra-tour-viewer-modal');
29 this.iframe = document.getElementById('yatra-tour-viewer-iframe');
30 return;
31 }
32
33 // Create modal HTML
34 const modalHTML = `
35 <div id="yatra-tour-viewer-modal" class="yatra-tour-viewer-modal" style="display: none;">
36 <div class="yatra-tour-viewer-overlay"></div>
37 <div class="yatra-tour-viewer-content">
38 <button type="button" class="yatra-tour-viewer-close" aria-label="Close Tour">
39 <svg width="24" height="24" fill="none" stroke="currentColor" viewBox="0 0 24 24">
40 <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"/>
41 </svg>
42 </button>
43 <div class="yatra-tour-viewer-header">
44 <h3 class="yatra-tour-viewer-title"></h3>
45 <div class="yatra-tour-viewer-controls">
46 <button type="button" class="yatra-tour-viewer-fullscreen" aria-label="Fullscreen">
47 <svg width="20" height="20" fill="none" stroke="currentColor" viewBox="0 0 24 24">
48 <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 8V4m0 0h4M4 4l5 5m11-1V4m0 0h-4m4 0l-5 5M4 16v4m0 0h4m-4 0l5-5m11 5l-5-5m5 5v-4m0 4h-4"/>
49 </svg>
50 </button>
51 </div>
52 </div>
53 <div class="yatra-tour-viewer-wrapper">
54 <iframe id="yatra-tour-viewer-iframe"
55 width="100%"
56 height="100%"
57 frameborder="0"
58 allowfullscreen
59 allow="gyroscope; accelerometer; xr-spatial-tracking">
60 </iframe>
61 </div>
62 </div>
63 </div>
64 `;
65
66 // Append to body
67 document.body.insertAdjacentHTML('beforeend', modalHTML);
68
69 this.modal = document.getElementById('yatra-tour-viewer-modal');
70 this.iframe = document.getElementById('yatra-tour-viewer-iframe');
71 }
72
73 attachEventListeners() {
74 // Close button
75 const closeBtn = this.modal.querySelector('.yatra-tour-viewer-close');
76 if (closeBtn) {
77 closeBtn.addEventListener('click', () => this.close());
78 }
79
80 // Overlay click to close
81 const overlay = this.modal.querySelector('.yatra-tour-viewer-overlay');
82 if (overlay) {
83 overlay.addEventListener('click', () => this.close());
84 }
85
86 // Fullscreen button
87 const fullscreenBtn = this.modal.querySelector('.yatra-tour-viewer-fullscreen');
88 if (fullscreenBtn) {
89 fullscreenBtn.addEventListener('click', () => this.toggleFullscreen());
90 }
91
92 // ESC key to close
93 document.addEventListener('keydown', (e) => {
94 if (e.key === 'Escape' && this.modal.style.display === 'flex') {
95 this.close();
96 }
97 });
98 }
99
100 /**
101 * View a 360° tour
102 * @param {Object} tour - Tour object with url, title, tour_type
103 */
104 view(tour) {
105 if (!tour || !tour.url) {
106 console.error('YatraTourViewer: Invalid tour object');
107 return;
108 }
109
110 this.currentTour = tour;
111
112 // Set title
113 const titleElement = this.modal.querySelector('.yatra-tour-viewer-title');
114 if (titleElement) {
115 titleElement.textContent = tour.title || '360° Virtual Tour';
116 }
117
118 // Set iframe source
119 this.iframe.src = tour.url;
120
121 // Show modal
122 this.open();
123 }
124
125 open() {
126 this.modal.style.display = 'flex';
127 document.body.style.overflow = 'hidden';
128 }
129
130 close() {
131 this.modal.style.display = 'none';
132 document.body.style.overflow = '';
133
134 // Stop tour by clearing iframe src
135 this.iframe.src = '';
136 this.currentTour = null;
137
138 // Exit fullscreen if active
139 if (document.fullscreenElement) {
140 document.exitFullscreen();
141 }
142 }
143
144 toggleFullscreen() {
145 const wrapper = this.modal.querySelector('.yatra-tour-viewer-wrapper');
146
147 if (!document.fullscreenElement) {
148 if (wrapper.requestFullscreen) {
149 wrapper.requestFullscreen();
150 } else if (wrapper.webkitRequestFullscreen) {
151 wrapper.webkitRequestFullscreen();
152 } else if (wrapper.msRequestFullscreen) {
153 wrapper.msRequestFullscreen();
154 }
155 } else {
156 if (document.exitFullscreen) {
157 document.exitFullscreen();
158 } else if (document.webkitExitFullscreen) {
159 document.webkitExitFullscreen();
160 } else if (document.msExitFullscreen) {
161 document.msExitFullscreen();
162 }
163 }
164 }
165 }
166
167 // Create global instance
168 window.YatraTourViewer = new YatraTourViewer();
169
170 // Log successful initialization
171
172
173 })();
174