';
for (var i in options) {
if (options[i].selected) $(el).attr("data-value", options[i].val);
template +=
'
" +
escapeHtml(options[i].text) +
"
";
}
template += "
";
$(el).append(template);
};
ripples = document.querySelectorAll("[ripple]");
for (i = 0, len = ripples.length; i < len; i++) {
ripple = ripples[i];
rippleContainer = document.createElement("div");
rippleContainer.className = "ripple--container";
ripple.addEventListener("mousedown", showRipple);
ripple.addEventListener("mouseup", debounce(cleanUp, 10000));
ripple.rippleContainer = rippleContainer;
ripple.appendChild(rippleContainer);
}
$('.checkbox-custom input[type="checkbox"]').change(function(e) {
if ($(e.target).is(":checked")) {
$(e.target)
.closest(".checkbox-custom")
.addClass("checked");
} else {
$(e.target)
.closest(".checkbox-custom")
.removeClass("checked");
}
});
// Custom select
var x, i, j, selElmnt, a, b, c;
/*look for any elements with the class "select-custom":*/
x = document.getElementsByClassName("select-custom");
for (i = 0; i < x.length; i++) {
selElmnt = x[i].getElementsByTagName("select")[0];
/*for each element, create a new DIV that will act as the selected item:*/
a = document.createElement("DIV");
a.setAttribute("class", "select-selected");
a.dataset.value = selElmnt[0].value;
a.innerHTML = selElmnt.options[selElmnt.selectedIndex].innerHTML;
x[i].insertBefore(a, selElmnt);
// x[i].insertBefore(a, x[i].firstChild);
/*for each element, create a new DIV that will contain the option list:*/
b = document.createElement("DIV");
b.setAttribute("class", "select-items select-hide");
for (j = 1; j < selElmnt.length; j++) {
/*for each option in the original select element,
create a new DIV that will act as an option item:*/
c = document.createElement("DIV");
c.innerHTML = selElmnt.options[j].innerHTML;
c.addEventListener("click", function(e) {
/*when an item is clicked, update the original select box,
and the selected item:*/
var y, i, k, s, h;
s = this.parentNode.parentNode.getElementsByTagName("select")[0];
h = this.parentNode.previousSibling;
for (i = 0; i < s.length; i++) {
if (s.options[i].innerHTML == this.innerHTML) {
s.selectedIndex = i;
h.innerHTML = this.innerHTML;
y = this.parentNode.getElementsByClassName("same-as-selected");
for (k = 0; k < y.length; k++) {
y[k].removeAttribute("class");
}
this.setAttribute("class", "same-as-selected");
h.dataset.value = s.options[i].getAttribute("value");
break;
}
}
h.click();
});
b.appendChild(c);
}
x[i].insertBefore(b, selElmnt);
a.addEventListener("click", function(e) {
/*when the select box is clicked, close any other select boxes,
and open/close the current select box:*/
e.stopPropagation();
closeAllSelect(this);
this.nextSibling.classList.toggle("select-hide");
this.classList.toggle("select-arrow-active");
});
}
function closeAllSelect(elmnt) {
/*a function that will close all select boxes in the document,
except the current select box:*/
var x,
y,
i,
arrNo = [];
x = document.getElementsByClassName("select-items");
y = document.getElementsByClassName("select-selected");
for (i = 0; i < y.length; i++) {
if (elmnt == y[i]) {
arrNo.push(i);
} else {
y[i].classList.remove("select-arrow-active");
}
}
for (i = 0; i < x.length; i++) {
if (arrNo.indexOf(i)) {
x[i].classList.add("select-hide");
}
}
if (!$(elmnt.target).closest(".out-close").length) outClose();
if ($(elmnt.target).closest(".dropdown").length) return;
event.stopPropagation();
}
/*if the user clicks anywhere outside the select box, then close all select boxes:*/
var documentClick = true;
$(document).click(closeAllSelect);
$(document).on("touchend", "body", function(e) {
if (documentClick) {
//$(document).unbind("click");
documentClick = false;
}
closeAllSelect(e);
});
/* ===========================================================
FORM VALIDATION
============================================================*/
$("#formNeedValidation").submit(function(e) {
console.log("object");
$(".form-group.required .form-control").each(function(index) {
var value = $.trim($(this).val()).length;
if (!value) {
$(this)
.closest(".form-group")
.addClass("error");
$(this)
.closest(".form")
.addClass("invalid");
e.preventDefault();
}
});
});
$("#formNeedValidation input").keyup(function(e) {
if ($(e.target).val()) {
$(e.target).css({ borderColor: "#d4d6e3" });
$(e.target)
.closest(".form-group")
.removeClass("error");
}
});
/* ===========================================================
Dropdown & dropdown selects
============================================================*/
$(".dropdown-select").each(function(i, el) {
dropdownSelectRender(el);
});
$("body").on("click", ".dropdown > label", function(e) {
if (
$(e.currentTarget)
.closest(".dropdown")
.hasClass("active")
) {
$(e.currentTarget)
.closest(".dropdown")
.removeClass("active")
.find(".dropdown-list")
.slideUp(150);
} else {
$(".dropdown").removeClass("active");
$(".dropdown-list").slideUp(150);
$(e.currentTarget)
.closest(".dropdown")
.addClass("active")
.find(".dropdown-list")
.slideDown(150);
}
});
$("body").on("click", ".dropdown-list > li", function(e) {
if ($(e.currentTarget).hasClass("noclose")) return;
$(e.currentTarget)
.closest(".dropdown")
.removeClass("active")
.find(".dropdown-list")
.slideUp(150);
});
$("body").on("click", ".dropdown-select .label", function(e) {
if (
$(e.currentTarget)
.closest(".dropdown-select")
.hasClass("active")
) {
$(e.currentTarget)
.closest(".dropdown-select")
.removeClass("active")
.find(".dropdown-list")
.slideUp(150);
} else {
$(".dropdown-select").removeClass("active");
$(".dropdown-list").slideUp(150);
$(e.currentTarget)
.closest(".dropdown-select")
.addClass("active")
.find(".dropdown-list")
.slideDown(150);
}
});
$("body").on("click", ".dropdown-list > li", function(e) {
if ($(e.currentTarget).hasClass("noclose")) return;
$(e.currentTarget)
.closest(".dropdown")
.removeClass("active")
.find(".dropdown-list")
.slideUp(150);
});
$("body").on("click", ".dropdown-select .dropdown-list li", function(e) {
var text, value;
value = $(e.currentTarget).attr("data-option");
if (
$(e.currentTarget)
.closest(".dropdown-select")
.hasClass("submit-us")
) {
text = value.length
? "Submit as " + $(e.currentTarget).text()
: $(e.currentTarget).text();
text =
text
.toLowerCase()
.charAt(0)
.toUpperCase() + text.toLowerCase().substr(1);
} else {
text = $(e.currentTarget).text();
}
$(e.currentTarget)
.closest(".dropdown-list")
.find("li")
.removeClass("selected");
$(e.currentTarget).addClass("selected");
$(e.currentTarget)
.closest(".dropdown-select")
.attr("data-value", value)
.find(".label span")
.text(text);
$(e.currentTarget)
.closest(".dropdown-select")
.removeClass("active");
$(e.currentTarget)
.closest(".dropdown-list")
.slideUp(150);
$(e.currentTarget)
.closest(".dropdown-select")
.find('select option[value="' + value + '"]')
.prop("selected", true);
$(e.currentTarget).closest('.dropdown-select').find('select').trigger('change');
});
// End Dropdown & dropdown selects
/* ===========================================================
Ticket details
============================================================*/
$(".ticket__replies_link").click(function(e) {
if ($(e.currentTarget).hasClass("visible")) {
$(e.currentTarget).removeClass("visible");
$(".ticket__replies_list").slideUp(150);
} else {
$(".ticket__replies_list").slideDown(150);
$(e.currentTarget).addClass("visible");
}
});
// Ticket upload file
var ticketFiles = [];
$('.block--attach input[type="file"]').change(function(e) {
for (i = 0; i < e.target.files.length; i++) {
ticketFiles.push(e.target.files[i]);
var extension =
"." +
e.target.files[i].name.split(".")[
e.target.files[i].name.split(".").length - 1
];
var name = "";
for (n = 0; n < e.target.files[i].name.split(".").length; n++) {
if (n < e.target.files[i].name.split(".").length - 1) {
name += e.target.files[i].name.split(".")[n];
}
}
if (name.length > 16)
name =
name.slice(0, 10) + "..." + name.slice(name.length - 8, name.length);
var label =
"