// TODO: make one email-sending function for both regular and negative feedback.
// String functions used to set
in
String.prototype.capitalize = function() {
return this.replace(/(?:^|\s)\S/g, function(a) { return a.toUpperCase(); });
};
String.prototype.replaceAll = function(search, replacement) {
var target = this;
return target.replace(new RegExp(search, 'g'), replacement);
};
$(document).ready(function() {
// set correct in
var cleanedpath = window.location.pathname.replace("/production/internal","").slice(1,-1).replaceAll("-"," ").replace("/"," version ");
var pagetitle = cleanedpath.capitalize();
document.title = pagetitle;
// correct path of navbar links
var localpath = "template/docsLayout_Responsive";
var clipindex = localpath.length;
$("div.navbar a").each(function() {
var link = $(this).attr("href");
link = link.substr(clipindex);
$(this).attr("href", link);
});
// create PDF link. Will only work in production.
var manualpath = window.location.pathname;
var pdfpath = manualpath.replace("/production/internal","").slice(1,-1).replaceAll("/","-").concat(".pdf");
var pdfpath = "/" + pdfpath;
$("a.pdf").attr("href", pdfpath);
// stop navbar links from opening new tabs
$(".header a").attr("target","_parent");
// add scrollbar to TOC
$('.toc-holder').css('width', "351px");
// Apply collapse/expand styles to navbar on smaller viewports.
var navbutton = $("button.btn.btn-navbar");
$(navbutton).on('click', function() {
if ($(navbutton).hasClass("collapsed")) {
//remove collapsed and add in (i.e., open)
$(navbutton).removeClass("collapsed");
$("div.navbar-inner, div.wrapper.navbar, #nav-collapse-0, .widget.search, div.widget.menu.horizontal.light").addClass("in");
} else {
//remove open and add collapsed
$(navbutton).addClass("collapsed");
$("div.navbar-inner, div.wrapper.navbar, #nav-collapse-0, .widget.search, div.widget.menu.horizontal.light").removeClass("in");
}
});
// feedback popup control
$("#feedback-form button.cancel").on('click', function() {
$("#feedback-form").fadeOut();
});
$("button.feedback").on('click', function() {
$("#feedback-form").fadeToggle();
});
// feedback form - send email
$("#feedback-form input.submit-button").click(function(e) {
e.preventDefault();
var siteUrl = window.location.href;
var hostname = window.location.hostname;
var message = $("#feedback-form textarea").val();
// If message is empty and submit is clicked, do not send form -- create warning asking for message
if (message == "" && $("#feedback-form label").children().length == 0) {
$("#feedback-form label").append(" Please enter a message below.");
}
if (message != "") {
//send message
var posting = $.post("/php/feedback.php", {message: message, docsite: hostname, url: siteUrl});
posting.done(function(data) {
if (data == "success") {
// display success message, hide form and reset it
$("#feedback-form *").hide();
$("#feedback-form textarea").val("");
$("#feedback-form").append("Thank you! Your feedback message has been sent.").delay(3000).fadeOut();
setTimeout(function() {
$("#feedback-form span.warning, #feedback-form span.error, span.thank-you").remove();
$("#feedback-form *").show();
}, 4000);
} else {
// display error message
$("#feedback-form").append("We're sorry, but an error occurred when trying to send your message. Please try again later.");
}
});
posting.fail(function(data) {
// display error message
$("#feedback-form").append("We're sorry, but an error occurred when trying to send your message. Please try again later.");
});
}
});
// Remove Sports section on public
var public = (window.location.hostname == "docs.vizrt.com") || (window.location.hostname == "documentation.vizrt.com") || (window.location.pathname.includes("/production/public"));
if (public) {
$("a[href~='/sport.html']").parent().remove();
}
// FEEDBACK BUTTONS. Action when pos/neg feedback is recorded
function RecordPositiveFeedback() {
$("#feedback-buttons").html('
Thank you! Your feedback has been recorded.
').delay(3000).slideUp();
}
function RecordNegativeFeedback() {
// Create negative feedback form
var negFeedbackResponseString = "
We're sorry to hear that this page was not helpful. Would you care to tell us what we can improve?
";
var negFeedbackFormString = '';
var negFeedbackHtml = negFeedbackResponseString + negFeedbackFormString;
$("#feedback-buttons").addClass("neg-form");
$("#feedback-buttons").html(negFeedbackHtml);
// handle submission of negative feedback message
$("#feedback-buttons input.submit-button").click(function(e) {
e.preventDefault();
var siteUrl = window.location.href;
var hostname = window.location.hostname;
var message = $("form#neg-form textarea").val();
// send negative feedback.
if (message == "" && $("#feedback-buttons.neg-form > p").children().length == 0) {
// handle empty form
$("#feedback-buttons.neg-form > p").append(" Please enter a message below.");
}
if (message != "") {
//send message
var posting = $.post("/php/feedback.php", {message: message, docsite: hostname, url: siteUrl, neg: true});
posting.done(function(data) {
if (data == "success") {
//display success message and hide form, buttons
$("#feedback-buttons").html('
Thank you! Your feedback message has been sent.
').delay(3000).slideUp();
$("#feedback-buttons").slideUp().removeClass("neg-form");
} else {
//display error message
("#feedback-buttons").append("We're sorry, but an error occurred when trying to send your message. Please try again later.");
}
});
}
});
// handle Cancel (do not submit message for negative feedback)
$("#feedback-buttons button.cancel").on('click', function() {
$("#feedback-buttons").fadeOut().removeClass("neg-form");
});
}
// feedback buttons: slide away when clicked
$("#pos-fdbk").click(RecordPositiveFeedback);
$("#neg-fdbk").click(RecordNegativeFeedback);
// show buttons again on page change
$(window).hashchange(function() {
$("#feedback-buttons").html('Was this helpful?').show();
$("#pos-fdbk").click(RecordPositiveFeedback);
$("#neg-fdbk").click(RecordNegativeFeedback);
});
});