!(function (t) {
"use strict";
wp.customize.controlConstructor["bloglo-typography"] =
wp.customize.Control.extend({
ready: function () {
var e = this,
n = e.setting.get(),
i = e.container.find(".popup-content");
e.container.find("#font-family-" + e.params.id).select2(),
e.container.find("#font-subsets-" + e.params.id).select2(),
e.update_font_subsets_field(n["font-family"]),
e.container.on("change", "#font-family-" + e.params.id, function () {
e.update_font_weight_field(t(this).val()),
e.update_font_subsets_field(t(this).val());
}),
e.container.on("change", "[data-option]", function () {
e.update_value();
}),
e.container.find(".bloglo-range-wrapper").each(function () {
var i = t(this);
i.rangeControl({
id: e.params.id + "-" + i.data("option-id"),
option: i.data("option-id"),
unit: e.params.units[i.data("option-id")],
value: n[i.data("options-id")],
responsive: e.params.responsive,
change: function () {
e.update_value();
},
});
}),
e.container.on(
"select2:opening",
"#font-family-" + e.params.id,
function () {
e.populate_font_family_field(),
e.container.off(
"select2:opening",
"#font-family-" + e.params.id
);
}
),
e.container.on(
"mousedown",
'[data-option="font-weight"]',
function () {
e.update_font_weight_field(
e.container.find("#font-family-" + e.params.id).val()
),
e.container.off("mousedown", '[data-option="font-weight"]');
}
),
e.container.on(
"select2:opening",
"#font-subsets-" + e.params.id,
function () {
e.update_font_subsets_field(
e.container.find("#font-family-" + e.params.id).val()
),
e.container.off("mousedown", '[data-option="font-subsets"]');
}
),
e.container.find(".popup-link").on("click", function () {
i.toggleClass("hidden"),
t(this).toggleClass("active"),
t(this).siblings(".reset-defaults").toggleClass("active"),
t("body").on("click", o);
}),
e.container.find(".reset-defaults").on("click", function () {
"font-family" in e.params.display &&
(e.populate_font_family_field(),
e.container
.find("#font-family-" + e.params.id)
.val(e.params.default["font-family"])
.trigger("change")),
[
"font-weight",
"font-style",
"text-transform",
"text-decoration",
].forEach((t) => {
t in e.params.display &&
e.container
.find('[data-option="' + t + '"]')
.val(e.params.default[t])
.trigger("change");
}),
["font-size", "line-height", "letter-spacing"].forEach((t) => {
e.container
.find('[data-option-id="' + t + '"]')
.find(".bloglo-reset-range")
.click();
});
});
var o = function (n) {
t(n.target).closest(".select2-container").length ||
t(n.target).closest(".customize-save-button-wrapper").length ||
t(n.target).closest(".reset-defaults").length ||
e.container.has(t(n.target).closest(".popup-link")).length ||
e.container.has(t(n.target).closest(".popup-content")).length ||
i.hasClass("hidden") ||
(i.addClass("hidden"),
e.container.find(".popup-link").removeClass("active"),
e.container.find(".reset-defaults").removeClass("active"),
t("body").off("click", o));
};
},
update_value: function () {
var e,
n = {};
this.container.find("[data-option]").each(function () {
(e = t(this).data("option")),
(n[e] =
"font-size-unit" === e ||
"line-height-unit" === e ||
"letter-spacing-unit" === e
? t(this).is(":checked")
? t(this).val()
: n[e]
: t(this).val());
}),
this.setting.set(n);
},
update_font_weight_field: function (e) {
var n = this,
i = "",
o = "",
a = n.setting.get();
if (
("inherit" === e && (o = ' selected="selected"'),
(i +=
'"),
"inherit" === e || "default" === e)
) {
t.each(
["100", "200", "300", "400", "500", "600", "700", "800", "900"],
function (t, e) {
(o = e === a["font-weight"] ? ' selected="selected"' : ""),
(i +=
'");
}
);
} else
t.each(bloglo_typography_vars.fonts, function (s, f) {
void 0 === f.fonts[e] ||
t.each(f.fonts[e].variants, function (t, e) {
(o = e === a["font-weight"] ? ' selected="selected"' : ""),
(i +=
'");
});
});
n.container
.find(".bloglo-typography-font-weight")
.find("select")
.html(i);
},
update_font_subsets_field: function (e) {
var n = "",
i = "",
o = this.setting.get(),
a = this.container.find(".bloglo-typography-font-subsets");
"default" !== e && "inherit" !== e
? (t.each(bloglo_typography_vars.fonts, function (s, f) {
if (void 0 !== f.fonts[e])
return (
"system_fonts" === s || "standard_fonts" === s
? a.hide()
: a.show(),
void t.each(f.fonts[e].subsets, function (t, e) {
(i = ""),
((o["font-subsets"] &&
-1 !== o["font-subsets"].indexOf(e)) ||
"latin" === e) &&
(i = ' selected="selected"'),
(n +=
'");
})
);
}),
a.find("select").html(n))
: a.hide();
},
populate_font_family_field: function (e) {
var n = "",
i = "",
o = this.setting.get();
(i = "inherit" === o["font-family"] ? ' selected="selected"' : ""),
(n +=
'"),
(i = "default" === o["font-family"] ? ' selected="selected"' : ""),
(n +=
'"),
t.each(bloglo_typography_vars.fonts, function (e, a) {
(n += '");
}),
this.container.find("#font-family-" + this.params.id).html(n);
},
});
})(jQuery);