209 lines
7.4 KiB
JavaScript
Executable File
209 lines
7.4 KiB
JavaScript
Executable File
!(function (t) {
|
|
"use strict";
|
|
(wp.customize.controlConstructor["bloglo-range"] =
|
|
wp.customize.Control.extend({
|
|
ready: function () {
|
|
var t = this,
|
|
e = t.setting.get();
|
|
t.container.find(".bloglo-range-wrapper").rangeControl({
|
|
id: t.params.id,
|
|
unit: t.params.unit,
|
|
value: e,
|
|
responsive: t.params.responsive,
|
|
change: function () {
|
|
t.save();
|
|
},
|
|
});
|
|
},
|
|
save: function () {
|
|
var t = {},
|
|
e = this.params.responsive;
|
|
if (!1 === e || void 0 === e || 0 == e.length)
|
|
t.value = parseFloat(
|
|
this.container.find(".bloglo-range-input").val()
|
|
);
|
|
else
|
|
for (var n in e)
|
|
t[n] = parseFloat(
|
|
this.container
|
|
.find(".control-responsive." + n + " .bloglo-range-input")
|
|
.val()
|
|
);
|
|
this.container.find(".bloglo-control-unit").length &&
|
|
(t.unit = this.container
|
|
.find(".bloglo-control-unit input:checked")
|
|
.val()),
|
|
this.setting.set(t);
|
|
},
|
|
})),
|
|
(function (t, e) {
|
|
var n;
|
|
(n = {
|
|
options: {
|
|
id: !1,
|
|
option: !1,
|
|
responsive: !1,
|
|
unit: !1,
|
|
value: !1,
|
|
change: !1,
|
|
},
|
|
_create: function () {
|
|
var t = this.element;
|
|
(this.unit = t.find(".bloglo-control-wrap").attr("data-unit")),
|
|
this._addListeners(),
|
|
"object" == typeof this.options.responsive &&
|
|
this._initResponsiveControls(),
|
|
!1 !== this.options.unit && this._initUnit();
|
|
},
|
|
_addListeners: function () {
|
|
var e,
|
|
n,
|
|
i,
|
|
a,
|
|
s = this;
|
|
s.element.change(function (e) {
|
|
t.isFunction(s.options.change) && s.options.change.call(this, e);
|
|
}),
|
|
s.element
|
|
.on("keyup input paste", ".bloglo-range-input", function () {
|
|
s._autocorrectSlider(t(this));
|
|
})
|
|
.on("focusout", function () {
|
|
s._autocorrectSlider(t(this));
|
|
}),
|
|
s.element.on("click", "input[type=range]", function () {
|
|
(e = t(this)),
|
|
(n = e.parent().children(".bloglo-range-input")),
|
|
(a = e.val()),
|
|
i !== a && ((i = a), n.val(a).change());
|
|
}),
|
|
s.element.on("mousedown", "input[type=range]", function () {
|
|
(e = t(this)),
|
|
(n = e.parent().children(".bloglo-range-input")),
|
|
e.mousemove(function () {
|
|
(a = e.val()), i !== a && ((i = a), n.val(a).change());
|
|
});
|
|
}),
|
|
s.element.on("mouseup", "input[type=range]", function () {
|
|
t(this).off("mousemove");
|
|
}),
|
|
s.element.on("click", ".bloglo-reset-range", function () {
|
|
var e;
|
|
s.element.find(".bloglo-reset-range").each(function (n, i) {
|
|
(e = t(i)),
|
|
(s.unit = e.data("reset_unit")),
|
|
e
|
|
.closest(".bloglo-range-wrapper")
|
|
.find(
|
|
'.bloglo-control-unit input[type="radio"][value="' +
|
|
e.data("reset_unit") +
|
|
'"]'
|
|
)
|
|
.click(),
|
|
e.siblings("input").val(e.data("reset_value"));
|
|
}),
|
|
s.element.change();
|
|
}),
|
|
s.element.on("click", ".bloglo-control-unit input", function () {
|
|
var e = t(this);
|
|
s.element
|
|
.find('.bloglo-control-wrap input[type="range"]')
|
|
.each(function (n, i) {
|
|
t(this).attr("min", e.data("min")),
|
|
t(this).attr("max", e.data("max")),
|
|
t(this).attr("step", e.data("step"));
|
|
}),
|
|
"px" !== e.val() || ("rem" !== s.unit && "em" !== s.unit)
|
|
? ("rem" !== e.val() && "em" !== e.val()) ||
|
|
"px" !== s.unit ||
|
|
(s.element
|
|
.find("input.bloglo-range-input")
|
|
.each(function (e, n) {
|
|
t(n).val(t(n).val() / range_obj.base_font),
|
|
s._autocorrectSlider(t(n));
|
|
}),
|
|
(s.unit = e.val()))
|
|
: (s.element
|
|
.find("input.bloglo-range-input")
|
|
.each(function (e, n) {
|
|
t(n).val(Math.floor(t(n).val() * range_obj.base_font)),
|
|
s._autocorrectSlider(t(n));
|
|
}),
|
|
(s.unit = e.val()));
|
|
});
|
|
},
|
|
_autocorrectSlider: function (t) {
|
|
var e = t.parent().find('input[type="range"]'),
|
|
n = parseFloat(t.val()),
|
|
i = parseFloat(t.attr("step")),
|
|
a = parseFloat(t.attr("min")),
|
|
s = parseFloat(t.attr("max"));
|
|
isNaN(n)
|
|
? e.change()
|
|
: (1 <= i &&
|
|
0 != n % 1 &&
|
|
((n = Math.round(n)), t.val(n), e.val(n).change()),
|
|
n > s && (t.val(s), e.val(s).change()),
|
|
n < a && (t.val(a), e.val(a).change()),
|
|
e.val(n).change());
|
|
},
|
|
_initResponsiveControls: function () {
|
|
var e = this.element;
|
|
e.find(".bloglo-control-wrap");
|
|
if (
|
|
(e.addClass("bloglo-control-responsive"),
|
|
e.find(".customize-control-title").length)
|
|
) {
|
|
var n = t('<ul class="bloglo-responsive-switchers"></ul>');
|
|
for (var i in this.options.responsive)
|
|
n.append(
|
|
'<li class="' +
|
|
i +
|
|
'"><span class="preview-' +
|
|
i +
|
|
'" data-device="' +
|
|
i +
|
|
'"><span class="bloglo-tooltip small-tooltip">' +
|
|
i +
|
|
'</span><i class="' +
|
|
this.options.responsive[i].icon +
|
|
'"></i></span></li>'
|
|
);
|
|
e.find(".customize-control-title").append(n);
|
|
}
|
|
},
|
|
_initUnit: function () {
|
|
var e = this.element.find(".bloglo-control-wrap"),
|
|
n = wp.template("bloglo-control-unit"),
|
|
i = {
|
|
unit: this.options.unit,
|
|
id: this.options.id,
|
|
option: this.options.option,
|
|
selected: e.attr("data-unit"),
|
|
};
|
|
"object" == typeof this.options.unit
|
|
? (t(n(i)).insertBefore(e),
|
|
void 0 !== this.options.value.unit &&
|
|
e
|
|
.parent()
|
|
.find(
|
|
"#" +
|
|
this.options.id +
|
|
"-" +
|
|
this.options.value.unit +
|
|
"-unit"
|
|
)
|
|
.click())
|
|
: "string" == typeof this.options.unit &&
|
|
t(
|
|
'<span class="bloglo-range-unit">' +
|
|
this.options.unit +
|
|
"</span>"
|
|
).insertAfter(e.find(".bloglo-range-input")),
|
|
e.parent().find(".bloglo-control-unit input:checked").click();
|
|
},
|
|
}),
|
|
t.widget("bloglo.rangeControl", n);
|
|
})(jQuery);
|
|
})(jQuery);
|