(jQuery),
function(i) {
window.ContactForm = function() {
this.init()
};
var t = ContactForm.prototype;
t.init = function() {
this.$button = i("#hello"),
this.$container = i("#contact-form"),
this.$inputs = this.$container.find("[data-placeholder]"),
this.$checkboxes = this.$container.find('input[type="checkbox"]'),
this.$close = this.$container.find(".close"),
this.active = !1,
this.handleInputPlaceholders(),
this.handleCheckboxToggles(),
this.handleTextareaSize(),
this.$button.on("click", this.toggle.bind(this)),
this.$close.on("click", this.close.bind(this)),
this.$container.on("submit", this.submit.bind(this))
},
t.open = function() {
App.$container.addClass("inactive"),
this.$container.addClass("active"),
this.$button.addClass("active"),
this.active = !0
},
t.close = function() {
App.$container.removeClass("inactive"),
this.$container.removeClass("active"),
this.$button.removeClass("active"),
this.active = !1
},
t.toggle = function() {
this.active ? this.close() : this.open()
},
t.submit = function(t) {
t.preventDefault();
var o = {},
e = 0,
a = this;
this.$container.find("[name]").each(function() {
var t = i(this),
a = t.attr("type"),
n = "checkbox" == a ? t.is(":checked") : t.val(),
s = t.attr("name"),
r = t.attr("data-placeholder");
"" === n || n == r ? (t.addClass("error"),
e++) : (t.removeClass("error"),
o[s] = n)
}),
0 == e && (this.$container.addClass("loading"),
i.ajax({
url: ajaxurl,
dataType: "html",
cache: !1,
method: "POST",
data: {
action: "contact_form",
contact: o
},
success: function(i) {
a.afterSubmit("" == i)
},
error: function(i) {
a.afterSubmit(!1)
}
}))
},
t.afterSubmit = function(i) {
var t = this;
this.$container.removeClass("loading"),
this.$container.find(".line").hide(), !0 === i ? this.$container.append('<div class="submit-message -success">Votre message nous a bien été transmis.<br> Merci ;)</div>') : this.$container.append('<div class="submit-message -error">Oups... une erreur est survenue ! :(<br> Veuillez réessayer</div>'),
setTimeout(this.close.bind(this), 2e3),
setTimeout(function() {
t.$container.find(".line").show(),
t.$container.find(".submit-message").hide()
}, 3e3)
},
t.handleInputPlaceholders = function() {
function t() {
var t = i(this),
o = t.attr("data-placeholder");
"" == t.val() ? t.val(o) : t.removeClass("error")
}
function o() {
var t = i(this),
o = t.attr("data-placeholder");
t.val() == o && t.val("")
}
function e() {
var t = i(this);
"" != t.val() && t.removeClass("error")
}
this.$inputs.each(t),
this.$inputs.on("blur", t),
this.$inputs.on("focus", o),
this.$container.find("select").on("change", e)
},
t.handleCheckboxToggles = function() {
this.$checkboxes.each(function() {
new CheckboxToggle(this)
})
},
t.handleTextareaSize = function() {
var i = this.$container.find(".textarea.-fake"),
t = this.$container.find("textarea"),
o = t.innerHeight();
t.on("input", function() {
i.text(t.val()),
i.css("display", "block");
var e = Math.max(i.innerHeight(), o);
i.css("display", "none"),
t.css("height", e)
})
}
}(jQuery),
function(i) {
var t = function(i) {
this.init(i)
},
o = t.prototype;
o.$wrap = i('<div class="checkbox-toggle"><div class="toggle"></div><span class="yes">oui</span><span class="no">non</span></div>'),
o.init = function(t) {
this.$checkbox = i(t),
this.checked = !!this.$checkbox.prop("checked"),
this.buildDom(),
this.$wrap.on("click", this.toggle.bind(this))
},
o.buildDom = function() {
this.$wrap = this.$wrap.clone(),
this.$checkbox.before(this.$wrap),
this.$wrap.append(this.$checkbox),
this.checked && this.$wrap.addClass("checked")
},
o.toggle = function(i) {
this.checked = !this.checked,
this.checked ? (this.$wrap.addClass("checked"),
this.$checkbox.prop("checked", !0)) : (this.$wrap.removeClass("checked"),
this.$checkbox.prop("checked", !1))
},
window.CheckboxToggle = t
}