/* * jQuery v1.9.1 included */ $(document).ready(function() { // social share popups $(".share a").click(function(e) { e.preventDefault(); window.open(this.href, "", "height = 500, width = 500"); }); // show form controls when the textarea receives focus or backbutton is used and value exists var $commentContainerTextarea = $(".comment-container textarea"), $commentContainerFormControls = $(".comment-form-controls, .comment-ccs"); $commentContainerTextarea.one("focus", function() { $commentContainerFormControls.show(); }); if ($commentContainerTextarea.val() !== "") { $commentContainerFormControls.show(); } // Expand Request comment form when Add to conversation is clicked var $showRequestCommentContainerTrigger = $(".request-container .comment-container .comment-show-container"), $requestCommentFields = $(".request-container .comment-container .comment-fields"), $requestCommentSubmit = $(".request-container .comment-container .request-submit-comment"); $showRequestCommentContainerTrigger.on("click", function() { $showRequestCommentContainerTrigger.hide(); $requestCommentFields.show(); $requestCommentSubmit.show(); $commentContainerTextarea.focus(); }); // Mark as solved button var $requestMarkAsSolvedButton = $(".request-container .mark-as-solved:not([data-disabled])"), $requestMarkAsSolvedCheckbox = $(".request-container .comment-container input[type=checkbox]"), $requestCommentSubmitButton = $(".request-container .comment-container input[type=submit]"); $requestMarkAsSolvedButton.on("click", function() { $requestMarkAsSolvedCheckbox.attr("checked", true); $requestCommentSubmitButton.prop("disabled", true); $(this).attr("data-disabled", true).closest("form").submit(); }); // Change Mark as solved text according to whether comment is filled var $requestCommentTextarea = $(".request-container .comment-container textarea"); $requestCommentTextarea.on("keyup", function() { if ($requestCommentTextarea.val() !== "") { $requestMarkAsSolvedButton.text($requestMarkAsSolvedButton.data("solve-and-submit-translation")); $requestCommentSubmitButton.prop("disabled", false); } else { $requestMarkAsSolvedButton.text($requestMarkAsSolvedButton.data("solve-translation")); $requestCommentSubmitButton.prop("disabled", true); } }); // Disable submit button if textarea is empty if ($requestCommentTextarea.val() === "") { $requestCommentSubmitButton.prop("disabled", true); } // Submit requests filter form in the request list page $("#request-status-select, #request-organization-select").on("change", function() { search(); }); // Submit requests filter form in the request list page $("#quick-search").on("keypress", function(e) { if (e.which === 13) { search(); } }); function search() { window.location.search = $.param({query: $("#quick-search").val(), status: $("#request-status-select").val(), organization_id: $("#request-organization-select").val()}); } $(".header .icon-menu").on("click", function(e) { e.stopPropagation(); var menu = document.getElementById("user-nav"); var isExpanded = menu.getAttribute("aria-expanded") === "true"; menu.setAttribute("aria-expanded", !isExpanded); }); if ($("#user-nav").children().length === 0) { $(".header .icon-menu").hide(); } // Submit organization form in the request page $("#request-organization select").on("change", function() { this.form.submit(); }); // Toggles expanded aria to collapsible elements $(".collapsible-nav, .collapsible-sidebar").on("click", function(e) { e.stopPropagation(); var isExpanded = this.getAttribute("aria-expanded") === "true"; this.setAttribute("aria-expanded", !isExpanded); }); }); /** support channel widgets **/ (function($, moment) { function isMomentAHoliday(compareMoment, holidays, timezone) { var isHoliday = false holidays.forEach(function(holiday) { var holiday = moment(holiday, 'MM-DD-YYYY').tz(timezone).startOf() if (holiday.isSame(compareMoment, 'day')) { isHoliday = true } }) return isHoliday } function isMomentASupportDay(compareMoment, daysOfWeek) { return daysOfWeek[compareMoment.day()] } function isTodayAHoliday(holidays, timezone) { var today = moment().tz(timezone).startOf() return isMomentAHoliday(today, holidays, timezone) } function isTodayASupportDay(daysOfWeek, timezone) { var today = moment().tz(timezone).startOf() return isMomentASupportDay(today, daysOfWeek) } function isTime24HoursADay(startHour, endHour) { var isTime24HoursADay = false; if (startHour === endHour || (startHour === 0 && endHour === 24)) { isTime24HoursADay = true } return isTime24HoursADay } function isTimeGoodWithSmallerStart(startHour, endHour, timezone) { var now = moment().tz(timezone) var startMoment = moment().tz(timezone).startOf('day').hour(startHour).minute(0).millisecond(0) var endMoment = moment().tz(timezone).startOf('day').hour(endHour).minute(0).millisecond(0) return now.isBetween(startMoment, endMoment) } function isTimeGoodWithLargerStart(startHour, endHour, daysOfWeek, holidays, timezone) { var now = moment().tz(timezone) var nowHour = now.clone().local().hour() var isTimeGood = false if (nowHour >= startHour) { isTimeGood = true } else if (nowHour < endHour) { var yesterday = now.clone().subtract(1, 'day') if (!isMomentAHoliday(yesterday, holidays, timezone) && isMomentASupportDay(yesterday, daysOfWeek)) { isTimeGood = true } } return isTimeGood } function isTimeGood(startHour, endHour, daysOfWeek, holidays, timezone) { var isTimeGood = false if (isTime24HoursADay(startHour, endHour) || (startHour < endHour && isTimeGoodWithSmallerStart(startHour, endHour, timezone)) || (startHour > endHour && isTimeGoodWithLargerStart(startHour, endHour, daysOfWeek, holidays, timezone))) { isTimeGood = true } return isTimeGood } function getCoverageTimeMessage(startHour, endHour, daysOfWeek, timezone) { var message = '' var daysInCoverage = [] var dayAbbreviations = ['Su', 'M', 'Tu', 'W', 'Th', 'F', 'Sa'] daysOfWeek.forEach(function(includeDay, index) { if (includeDay) { daysInCoverage.push(dayAbbreviations[index]) } }) var daysMessage = '

' daysInCoverage.forEach(function(day, index, days) { daysMessage += day if (index + 1 !== days.length) { daysMessage += ' | ' } }); message += daysMessage + '

' if (isTime24HoursADay(startHour, endHour)) { message += '

24 hours a day

' } else { // Add start time to coverage message var startMeridiem = 'AM' if (startHour >= 12) { startMeridiem = 'PM' } var startHourDisplay = startHour.toString() if (startHour > 12) { startHourDisplay = (startHour - 12).toString() } message += '

' + startHourDisplay + startMeridiem + ' - ' // Add end time to coverage message var endMeridiem = 'AM' if (endHour >= 12) { endMeridiem = 'PM' } var endHourDisplay = endHour.toString() if (endHour > 12) { endHourDisplay = (endHour - 12).toString() } message += endHourDisplay + endMeridiem + ' ' // Add timezone to coverage message message += moment().tz(timezone).format('z') + '

' } return message } $.fn.emailSupportChannelBlock = function(options) { var settings = $.extend({ startHour: 9, endHour: 23, timezone: 'America/New_York', holidays: [], daysOfWeek: [false, true, true, true, true, true, false] }, options) this.find('.coverage-time').html( getCoverageTimeMessage(settings.startHour, settings.endHour, settings.daysOfWeek, settings.timezone) ) if (isTodayAHoliday(settings.holidays, settings.timezone)) { this.find('.holiday-message').show() } else { if (isTodayASupportDay(settings.daysOfWeek, settings.timezone) && isTimeGood(settings.startHour, settings.endHour, settings.daysOfWeek, settings.holidays, settings.timezone)) { this.find('.unavailable-message').hide() this.find('.available-message').show() } } return this; } $.fn.chatSupportChannelBlock = function(options) { var settings = $.extend({ startHour: 9, endHour: 23, timezone: 'America/New_York', holidays: [], daysOfWeek: [false, true, true, true, true, true, false] }, options) var chatWindow = $('.zopim') chatWindow.hide() this.find('.coverage-time').html( getCoverageTimeMessage(settings.startHour, settings.endHour, settings.daysOfWeek, settings.timezone) ) if (isTodayAHoliday(settings.holidays, settings.timezone)) { this.find('.holiday-message').show() } else { if (isTodayASupportDay(settings.daysOfWeek, settings.timezone) && isTimeGood(settings.startHour, settings.endHour, settings.daysOfWeek, settings.holidays, settings.timezone)) { this.find('.support-off').hide() this.find('.support-on').show() chatWindow.show() } } return this } $.fn.phoneSupportChannelBlock = function(options) { var settings = $.extend({ startHour: 9, endHour: 23, timezone: 'America/New_York', holidays: [], daysOfWeek: [false, true, true, true, true, true, false] }, options) this.find('.coverage-time').html( getCoverageTimeMessage(settings.startHour, settings.endHour, settings.daysOfWeek, settings.timezone) ) if (isTodayAHoliday(settings.holidays, settings.timezone)) { this.find('.holiday-message').show() } else { if (isTodayASupportDay(settings.daysOfWeek, settings.timezone) && isTimeGood(settings.startHour, settings.endHour, settings.daysOfWeek, settings.holidays, settings.timezone)) { this.find('.support-off').hide() this.find('.support-on').show() } } return this; } }(jQuery, moment)) $(function() { $('.email-support-channel-block').emailSupportChannelBlock({ startHour: 22, endHour: 22, daysOfWeek: [true, true, true, true, true, true, true], holidays: [ '07-24-2017' ] }) $('.chat-support-channel-block').chatSupportChannelBlock({ startHour: 9, endHour: 22, daysOfWeek: [true, true, true, true, true, true, true], }) $('.phone-support-channel-block').phoneSupportChannelBlock({ startHour: 9, endHour: 10, daysOfWeek: [true, true, true, true, true, true, true] }) /** role visibility classes **/ if ('manager' === HelpCenter.user.role) { $('.visible-managers').css('display', 'block') $('.visible-agents-and-up').css('display', 'block') $('.visible-end-users-and-up').css('display', 'block') } // if ('agent' === HelpCenter.user.role) { $('.visible-agents-and-up').css('display', 'block') $('.visible-end-users-and-up').css('display', 'block') } if ('end_user' === HelpCenter.user.role) { $('.visible-end-users-and-up').css('display', 'block') } })