(function ($) {
'use strict';
var j = 1;
var color = '#00b4ff';
var scene_parent = '';
var scene_uploader = null;
var scene_upload_parent = null;
window.jQuery.migrateMute = true;
/**
* All of the code for your admin-facing JavaScript source
* should reside in this file.
*
* Note: It has been assumed you will write jQuery code here, so the
* $ function reference has been prepared for usage within the scope
* of this function.
*
* This enables you to define handlers, for when the DOM is ready:
*
* $(function() {
*
* });
*
* When the window is loaded:
*
* $( window ).load(function() {
*
* });
*
* ...and/or other possibilities.
*
* Ideally, it is not considered best practise to attach more than a
* single DOM-ready or window-load handler for a particular page.
* Although scripts in the WordPress core, Plugins and Themes may be
* practising this, we should strive to set a better example in our own work.
*/
let lastChildClicked = false;
$(document).ready(function () {
if($('#scene-1').find('input.sceneid').val()){
$('.scene-gallery').append('

Upload Scene
');
}else{
$('.scene-gallery').append('
Upload Scene
');
}
$(".vrowl-carousel").owlCarousel({
margin: 10,
autoWidth: true,
nav: true
});
var primary_markng = $('#scene-1').find('input.sceneid').val();
$('.owl' + primary_markng).parents('.owl-item').addClass('marked');
$('.meta-box-sortables').sortable({
items: '#wpvr_item_builder_box',
disabled: true
});
$('.postbox .hndle').css('cursor', 'pointer');
// Validate scene checkbox on page load
setTimeout(function() {
let sceneImageCount = $('.rex-pano-tab .single-scene .scene-left .scene-setting .form-group img')
.filter(function() {
return $(this).attr('src') && $(this).attr('src').trim() !== '';
})
.length;
var panovideo = $("input[name='panovideo']:checked").val();
var videourl = $("input[name='video-attachment-url']").val();
var hasContent = (panovideo === 'on' && videourl && videourl.trim() !== '') || sceneImageCount > 0;
if (sceneImageCount === 0) {
$('#wpvr-check-scene').prop('checked', false);
$('#wpvr-check-media').prop('checked', false);
$('#wpvr-check-scene').closest('.wpvr-checklist-item').css('color', '#73707D');
$('#wpvr-check-media').closest('.wpvr-checklist-item').css('color', '#73707D');
updateProgress();
}
// Hide Panellum loading box if no content
if (!hasContent) {
$('.pnlm-load-box').hide();
}
}, 100);
});
$(document).on("change", "input.vr-switcher-check", function (event) {
updateCheckboxStates();
$(this).val(this.checked ? 'on' : 'off');
});
updateCheckboxStates();
function updateCheckboxStates() {
// Check movement controls if wpvr_controls is checked
if ($('#wpvr_controls').prop('checked')) {
$('#wpvr-check-movement-controls').prop('checked', true);
$('#wpvr-check-movement-controls').closest('.wpvr-checklist-item').css('color', '#0E003C');
} else if (!$('#wpvr_controls').prop('checked')) {
$('#wpvr-check-movement-controls').prop('checked', false);
$('#wpvr-check-movement-controls').closest('.wpvr-checklist-item').css('color', '#73707D');
}
// Check zoom controls if either wpvr_mouseZoom or wpvr_keyboardzoom is checked
if (($('#wpvr_mouseZoom').prop('checked') || $('#wpvr_keyboardzoom').prop('checked'))) {
$('#wpvr-check-zoom-controls').prop('checked', true);
$('#wpvr-check-zoom-controls').closest('.wpvr-checklist-item').css('color', '#0E003C');
} else if (!$('#wpvr_mouseZoom').prop('checked') && !$('#wpvr_keyboardzoom').prop('checked')) {
$('#wpvr-check-zoom-controls').prop('checked', false);
$('#wpvr-check-zoom-controls').closest('.wpvr-checklist-item').css('color', '#73707D');
}
updateProgress();
}
// === Pro Preview: Sticky Banner & Watermark for Free Users on Advanced Controls ===
(function initProPreview() {
if (typeof wpvr_obj === 'undefined' || wpvr_obj.is_wpvr_pro_active) {
return;
}
var $banner = $('#wpvr-pro-preview-banner');
var $watermark = $('#wpvr-pro-preview-watermark');
// All toggleable IDs in the Advanced Controls tab
var advancedControlIds = [
'wpvr_diskeyboard', 'wpvr_keyboardzoom', 'wpvr_draggable',
'wpvr_mouseZoom', 'wpvr_gyro', 'wpvr_deviceorientationcontrol', 'wpvr_compass',
'wpvr_vrgallery', 'wpvr_vrgallery_title', 'wpvr_scene_navigation',
'wpvr_bg_music', 'wpvr_explainerSwitch', 'wpvr_globalzoom', 'wpvr_cpLogoSwitch'
];
// Option A: IDs whose effect is visible via pannellum config (auto-trigger preview)
var pannellumConfigIds = [
'wpvr_compass', 'wpvr_diskeyboard', 'wpvr_keyboardzoom',
'wpvr_draggable', 'wpvr_mouseZoom'
];
// Option B: IDs mapped to their mockup overlay elements
var mockupMap = {
'wpvr_vrgallery': '#wpvr-pro-mockup-gallery',
'wpvr_scene_navigation': '#wpvr-pro-mockup-navigation',
'wpvr_bg_music': '#wpvr-pro-mockup-audio',
'wpvr_gyro': '#wpvr-pro-mockup-gyro'
};
var previewDebounceTimer = null;
// Enable the disabled checkboxes in the advanced controls tab for Pro Preview
function enableAdvancedToggles() {
$('#gen-advanced input.vr-switcher-check[disabled]').each(function () {
$(this).prop('disabled', false).addClass('wpvr-pro-preview-toggle');
});
}
function hasAnyAdvancedToggleOn() {
for (var i = 0; i < advancedControlIds.length; i++) {
var $el = $('#' + advancedControlIds[i]);
if ($el.length && $el.prop('checked')) {
return true;
}
}
return false;
}
function updateProPreviewState() {
if (hasAnyAdvancedToggleOn()) {
$banner.slideDown(200);
$watermark.fadeIn(200);
} else {
$banner.slideUp(200);
$watermark.fadeOut(200);
}
}
// Option B: Show/hide CSS mockup overlays based on toggle state
function updateMockups() {
$.each(mockupMap, function (toggleId, mockupSelector) {
var $checkbox = $('#' + toggleId);
var $mockup = $(mockupSelector);
if ($checkbox.length && $checkbox.prop('checked')) {
$mockup.fadeIn(200);
} else {
$mockup.fadeOut(200);
}
});
// Adjust audio mockup position when gallery is also visible
var galleryOn = $('#wpvr_vrgallery').prop('checked');
var $audio = $('#wpvr-pro-mockup-audio');
if (galleryOn) {
$audio.addClass('wpvr-pro-mockup--has-gallery');
} else {
$audio.removeClass('wpvr-pro-mockup--has-gallery');
}
}
// Option A: Auto-trigger preview for features that work via pannellum config
function autoTriggerPreview(toggleId) {
if (pannellumConfigIds.indexOf(toggleId) === -1) {
return;
}
// Only auto-preview if a scene image exists
var hasScene = $('#scene-1').find('input.sceneid').val();
if (!hasScene) {
return;
}
clearTimeout(previewDebounceTimer);
previewDebounceTimer = setTimeout(function () {
$('.panolenspreview').trigger('click');
}, 600);
}
// Listen for toggle changes on advanced control checkboxes
$(document).on('change', '#gen-advanced input.vr-switcher-check', function () {
updateProPreviewState();
updateMockups();
autoTriggerPreview($(this).attr('id'));
});
// Update state when the Advanced Controls tab is shown
$(document).on('click', '.inner-nav li.gen-advanced', function () {
setTimeout(function () {
enableAdvancedToggles();
updateProPreviewState();
updateMockups();
}, 100);
});
// Initial check when DOM is ready
$(document).ready(function () {
enableAdvancedToggles();
if ($('#gen-advanced').is(':visible')) {
updateProPreviewState();
updateMockups();
}
});
})();
// === End Pro Preview ===
var specificeSceneID = ''
var newScene = ''
$(document).on("click", ".scene-nav ul li span", function (event) {
$('.owl-item').removeClass('marked');
setTimeout(function(){
var target = $('.scene-nav ul li.active span').attr("data-index");
if(target == undefined){
var currentLi = $(this).parent('li');
var previousLi = currentLi.prev();
if (previousLi.length > 0) {
newScene = previousLi.find('span').attr('data-index');
}
}
var data = $('#scene-' + target).find('input.sceneid').val();
if (data) {
specificeSceneID = data;
if(!lastChildClicked){
$('.panolenspreview').trigger('click')
}
$('.owl' + data).parents('.owl-item').addClass('marked');
}
lastChildClicked = false;
}, 500);
});
jQuery(document).ready(function ($) {
j = $('#scene-1').find('.hotspot-nav li').eq(-2).find('span').attr('data-index');
var ajaxurl = wpvr_obj.ajaxurl;
$('.panolenspreview').on('click', function (e) {
e.preventDefault();
$('.wpvr-loading').show();
var videourl = $("input[name='video-attachment-url']").val();
var autoplay = $("input[name='autoplay']:checked").val();
var loop = $("input[name='loop']:checked").val();
var panovideo = $("input[name='panovideo']:checked").val();
var postid = $("#post_ID").val();
var autoload = $("input[name='autoload']").is(':checked') ? 'on' : 'off';
var compass = $("input[name='compass']:checked").val();
var control = $("input[name='controls']").is(':checked') ? 'on' : 'off';
var rotation = $("input[name='autorotation']").is(':checked') ? 'on' : 'off';
var defaultscene = $("input[name='default-scene-id']").val();
var preview = $("input[name='preview-attachment-url']").val();
var scenefadeduration = $("input[name='scene-fade-duration']").val();
var autorotation = $("input[name='auto-rotation']").val();
var autorotationinactivedelay = $("input[name='auto-rotation-inactive-delay']").val();
var autorotationstopdelay = $("input[name='auto-rotation-stop-delay']").val();
var panodata = $('.scene-setup').repeaterVal();
const filteredPanodata = {
...panodata,
"scene-list": panodata["scene-list"].filter(
scene => scene["scene-id"]?.trim()
)
};
var panolist = JSON.stringify(filteredPanodata);
var previewtext = $('.previewtext').val();
// Collect advanced control values for Pro Preview.
// draggable defaults to 'on' — it is a basic feature and must be
// enabled in the preview so pannellum can capture hotspot coordinates.
var diskeyboard = $('#wpvr_diskeyboard').is(':checked') ? 'on' : 'off';
var keyboardzoom = $('#wpvr_keyboardzoom').is(':checked') ? 'on' : 'off';
var draggable = 'on'; // always enabled; dragging is required for hotspot coordinate capture
var mouseZoom = $('#wpvr_mouseZoom').is(':checked') ? 'on' : 'off';
var gyro = $('#wpvr_gyro').is(':checked') ? 'on' : 'off';
var deviceorientationcontrol = $('#wpvr_deviceorientationcontrol').is(':checked') ? 'on' : 'off';
jQuery.ajax({
type: "POST",
url: ajaxurl,
data: {
action: "wpvr_preview",
nonce : wpvr_obj.ajax_nonce,
postid: postid,
compass: compass,
control: control,
autoload: autoload,
panodata: panolist,
defaultscene: defaultscene,
rotation: rotation,
autorotation: autorotation,
autorotationinactivedelay: autorotationinactivedelay,
autorotationstopdelay: autorotationstopdelay,
preview: preview,
scenefadeduration: scenefadeduration,
panovideo: panovideo,
videourl: videourl,
autoplay: autoplay,
loop: loop,
// vidautoplay: vidautoplay,
// vidcontrol: vidcontrol,
diskeyboard: diskeyboard,
keyboardzoom: keyboardzoom,
draggable: draggable,
mouseZoom: mouseZoom,
gyro: gyro,
deviceorientationcontrol: deviceorientationcontrol
},
success: function (response) {
$('.wpvr-loading').hide();
if (response.success == true) {
if(response.data[2] == 'off'){
$('#error_occured').hide();
$('#error_occuredpub').hide();
$('#' + response.data[0]["panoid"]).empty();
var scenes = response.data[1];
if (scenes) {
$.each(scenes.scenes, function (i) {
$.each(scenes.scenes[i]['hotSpots'], function (key, val) {
if (
val["clickHandlerArgs"] &&
val["clickHandlerArgs"].replace(/<[^>]*>/g, '').trim() !== ''
) {
val["clickHandlerFunc"] = wpvrhotspot;
}
if (
val["createTooltipArgs"] &&
val["createTooltipArgs"].replace(/<[^>]*>/g, '').trim() !== ''
) {
val["createTooltipFunc"] = wpvrtooltip;
}
});
});
}
if (scenes) {
$('.scene-gallery').trigger('destroy.owl.carousel');
$('.scene-gallery').empty();
$.each(scenes.scenes, function (key, val) {
$('.scene-gallery').append('- ' + key + '

');
});
$('.scene-gallery').append('
Upload Image
');
$(".vrowl-carousel").owlCarousel({
margin: 10,
autoWidth: true,
});
var active_owl_target = $('#wpvr_active_scenes').val();
var get_owl_target = $('#scene-' + active_owl_target).find('input.sceneid').val();
$('.owl' + get_owl_target).parents('.owl-item').addClass('marked');
}
if(!scenes.autoLoad){
jQuery('.pnlm-controls-container').hide();
}
var panoshow = pannellum.viewer(response.data[0]["panoid"], scenes);
panoshow.on('load', function(){
jQuery('.pnlm-controls-container').show();
});
if (scenes.autoRotate) {
panoshow.on('load', function () {
setTimeout(function () {
panoshow.startAutoRotate(scenes.autoRotate, 0);
}, 3000);
});
panoshow.on('scenechange', function () {
setTimeout(function () {
panoshow.startAutoRotate(scenes.autoRotate, 0);
}, 3000);
});
}
var touchtime = 0;
if (scenes) {
$.each(scenes.scenes, function (key, val) {
document.getElementById('' + key + '_gallery').addEventListener('click', function (e) {
if (touchtime == 0) {
touchtime = new Date().getTime();
} else {
if (((new Date().getTime()) - touchtime) < 800) {
panoshow.loadScene(key);
activateSceneTab(key)
touchtime = 0;
} else {
touchtime = new Date().getTime();
}
}
});
});
}
if( newScene){
var data = $('#scene-' + newScene).find('input.sceneid').val();
if(data){
panoshow.loadScene(data);
}
//newScene = ''
}
if(specificeSceneID){
setTimeout(() => {
panoshow.loadScene(specificeSceneID);
}, 500);
}
$('html, body').animate({
scrollTop: $("#wpvr_item_builder__box").offset().top
}, 500);
//set preview text
if ("" != previewtext) {
$('.pnlm-load-button p').text(previewtext);
}
}else{
$('#' + response.data["panoid"]).empty();
$('#' + response.data["panoid"]).html(response.data["panodata"]);
if (response.data['vidtype'] == 'selfhost') {
videojs(response.data["vidid"], {
plugins: {
pannellum: {}
}
});
}
$('html, body').animate({
scrollTop: $("#wpvr_item_builder__box").offset().top
}, 500);
}
} else {
$('#error_occured').show();
$('#error_occured .pano-error-message').html(response.data);
$('#error_occuredpub').show();
$('#error_occuredpub').html(response.data);
$('body').addClass('error-overlay');
$('html, body').animate({
scrollTop: $("#error_occured").offset().top
}, 500);
}
}
});
});
});
function sanitizeText(str) {
if (!str) return '';
// Remove all