1window.$ = window.$ || jQuery; 2 3const MHubFrontend = { 4 init() { 5 this.bindEvents(); 6 this.changetime(); 7 }, 8 bindEvents() { 9 $(document).on('click', '.mhub-meeting-status', this.handleMeetingStatusButtonClick); 10 }, 11 12 changetime() { 13 // Get user's timezone using Intl 14 const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone; 15 16 // Handle the special case 17 const user_timezone = timezone === "Asia/Katmandu" ? "Asia/Kathmandu" : timezone; 18 19 const $meetingWrapper = $(".meetinghub-wrapper"); 20 21 if ($meetingWrapper.length) { 22 // Extract data attributes 23 const originalTime = $meetingWrapper.data("mhub-starttime"); 24 const originalTimezone = $meetingWrapper.data("mhub-timezone"); 25 const meetingTitle = $meetingWrapper.data("mhub-title"); 26 const meetingPermalink = $meetingWrapper.data("mhub-permalilk"); 27 const enableUserZone = $meetingWrapper.data("mhub-enable-user-zone"); 28 29 if (enableUserZone) { 30 if (!originalTime || !originalTimezone) { 31 console.error("Error: Missing required data attributes."); 32 return; 33 } 34 35 // Parse original time 36 const originalDate = new Date(originalTime); 37 if (isNaN(originalDate)) { 38 console.error("Error: Invalid date format! Check the input."); 39 return; 40 } 41 42 // Format the date in user's timezone 43 const dateFormatter = new Intl.DateTimeFormat('en-US', { 44 timeZone: user_timezone, 45 weekday: 'long', 46 year: 'numeric', 47 month: 'long', 48 day: 'numeric', 49 hour: 'numeric', 50 minute: 'numeric', 51 hour12: true 52 }); 53 54 const timeFormatter = new Intl.DateTimeFormat('en-US', { 55 timeZone: user_timezone, 56 hour: 'numeric', 57 minute: 'numeric', 58 hour12: true 59 }); 60 61 const dayFormatter = new Intl.DateTimeFormat('en-US', { 62 timeZone: user_timezone, 63 weekday: 'long' 64 }); 65 66 const convertedTime = dateFormatter.format(originalDate); 67 const onlyTime = timeFormatter.format(originalDate); 68 const dayName = dayFormatter.format(originalDate); 69 70 // Update Recurring time 71 const timeRecurring = $(".mhub_retime"); 72 if (timeRecurring.length) { 73 timeRecurring.text(onlyTime); 74 } 75 76 // Update recurring day 77 const dayRecurring = $(".mhub_reday"); 78 if (dayRecurring.length) { 79 dayRecurring.each(function () { 80 const currentText = $(this).text(); 81 const updatedText = currentText.replace(/\b(on\s+\w+)\b/, "on " + dayName); 82 $(this).text(updatedText); 83 }); 84 } 85 86 // Update time & timezone elements 87 const $timeElement = $(".mhbu-tm"); 88 if ($timeElement.length) { 89 $timeElement.text(convertedTime); 90 } 91 92 const $timezoneElement = $(".mhub-tz"); 93 if ($timezoneElement.length) { 94 $timezoneElement.text(user_timezone); 95 } 96 97 // Handle duration and end time 98 const $durationElement = $(".mhub-duration"); 99 const endDate = new Date(originalDate); 100 101 let hours = 2; // Default to 2 hours 102 let minutes = 0; 103 104 if ($durationElement.length) { 105 const durationText = $durationElement.text().trim(); 106 const hoursMatch = durationText.match(/(\d+)\s*hour/);
107 const minutesMatch = durationText.match(/(\d+)\s*minute/); 108 109 hours = hoursMatch ? parseInt(hoursMatch[1]) : 0; 110 minutes = minutesMatch ? parseInt(minutesMatch[1]) : 0; 111 } 112 113 endDate.setHours(endDate.getHours() + hours); 114 endDate.setMinutes(endDate.getMinutes() + minutes); 115 116 // Format times for Google Calendar URL 117 const formatForCalendar = (date) => { 118 return date.toISOString().replace(/-|:|\.\d+/g, ""); 119 }; 120 121 const start_time_utc = formatForCalendar(originalDate); 122 const end_time_utc = formatForCalendar(endDate); 123 124 // Update Google Calendar button 125 const $calendarButton = $(".mhub-add-to-calendar-btn"); 126 if ($calendarButton.length) { 127 const calendar_url = `https://www.google.com/calendar/render?action=TEMPLATE&text=${encodeURIComponent(meetingTitle)}&dates=${start_time_utc}/${end_time_utc}&details=${encodeURIComponent('Join the meeting: ' + meetingPermalink)}&ctz=${encodeURIComponent(user_timezone)}`; 128 $calendarButton.attr("href", calendar_url); 129 } 130 } 131 } 132 }, 133 handleMeetingStatusButtonClick() { 134 const meetingId = $(this).data('meeting-id'); 135 const postId = $(this).data('post-id'); 136 const meetingStatus = $(this).data('meeting-status'); 137 MHubFrontend.sendMeetingStatusData(meetingId, postId, meetingStatus); 138 }, 139 sendMeetingStatusData(meetingId, postId, meetingStatus) { 140 if (meetingStatus === 'end') { 141 // Display a confirmation alert 142 if (confirm( mhubMeetingsData.strings.are_you_sure_you_want_to_end )) { 143 // If user confirms, proceed with AJAX request 144 sendAjaxRequest(); 145 } 146 } else { 147 // If meeting status is not 'end', proceed with AJAX request directly 148 sendAjaxRequest(); 149 } 150 151 if (meetingStatus === 'start') { 152 // Display a confirmation alert 153 if (confirm( mhubMeetingsData.strings.are_you_sure_you_want_to_start )) { 154 // If user confirms, proceed with AJAX request 155 sendAjaxRequest(); 156 } 157 } else { 158 // If meeting status is not 'end', proceed with AJAX request directly 159 sendAjaxRequest(); 160 } 161 162 function sendAjaxRequest() { 163 $.ajax({
164 url: mhub_frontend_params.ajax_url, 165 type: 'POST', 166 data: { 167 action: 'mhub_meeting_action', 168 nonce: mhub_frontend_params.nonce, 169 meeting_id: meetingId, 170 post_id: postId, 171 meeting_status: meetingStatus 172 }, 173 success: function (response) { 174 // Reload the page upon successful response 175 if (response.success) { 176 location.reload(); 177 } 178 }, 179 error: function (xhr, status, error) { 180 console.error(xhr.responseText); 181 } 182 }); 183 } 184 }, 185 186}; 187 188$(document).ready(function () { 189 MHubFrontend.init(); 190});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.