把前端从CircuitVerse中拆了出来

This commit is contained in:
zhbaor 2022-01-23 17:33:42 +08:00
commit 5bf1284599
2182 changed files with 189323 additions and 0 deletions

View file

@ -0,0 +1,333 @@
/**
* Author and copyright: Stefan Haack (https://shaack.com)
* Repository: https://github.com/shaack/bootstrap-input-spinner
* License: MIT, see file 'LICENSE'
*/
//** The file has been modified
(function ($) {
"use strict";
var triggerKeyPressed = false;
var originalVal = $.fn.val;
$.fn.val = function (value) {
if (arguments.length >= 1) {
if (this[0] && this[0]["bootstrap-input-spinner"] && this[0].setValue) {
var element = this[0];
setTimeout(function () {
element.setValue(value);
});
}
}
return originalVal.apply(this, arguments);
};
$.fn.InputSpinner = $.fn.inputSpinner = function (options) {
var config = {
decrementButton: "<strong>-</strong>", // button text
incrementButton: "<strong>+</strong>", // ..
groupClass: "", // css class of the resulting input-group
buttonsClass: "btn-outline-secondary",
buttonsWidth: "2.5rem",
textAlign: "center",
autoDelay: 500, // ms holding before auto value change
autoInterval: 100, // speed of auto value change
boostThreshold: 10, // boost after these steps
boostMultiplier: "auto", // you can also set a constant number as multiplier
};
for (var option in options) {
config[option] = options[option];
}
var html =
'<div class="input-group ' +
config.groupClass +
'">' +
'<div class="input-group-prepend">' +
'<button style=" border:none; min-width: ' +
config.buttonsWidth +
'" class="btn btn-decrement ' +
config.buttonsClass +
'" type="button">' +
config.decrementButton +
"</button>" +
"</div>" +
'<input type="text" inputmode="decimal" style="text-align: ' +
config.textAlign +
'" class="form-control"/>' +
'<div class="input-group-append">' +
'<button style=" border:none; min-width: ' +
config.buttonsWidth +
'" class="btn btn-increment ' +
config.buttonsClass +
'" type="button">' +
config.incrementButton +
"</button>" +
"</div>" +
"</div>";
var locale = navigator.language || "en-US";
this.each(function () {
var $original = $(this);
$original[0]["bootstrap-input-spinner"] = true;
$original.hide();
var autoDelayHandler = null;
var autoIntervalHandler = null;
var autoMultiplier = config.boostMultiplier === "auto";
var boostMultiplier = autoMultiplier ? 1 : config.boostMultiplier;
var $inputGroup = $(html);
var $buttonDecrement = $inputGroup.find(".btn-decrement");
var $buttonIncrement = $inputGroup.find(".btn-increment");
var $input = $inputGroup.find("input");
var min = null;
var max = null;
var step = null;
var stepMax = null;
var decimals = null;
var digitGrouping = null;
var numberFormat = null;
updateAttributes();
var value = parseFloat($original[0].value);
var boostStepsCount = 0;
var prefix = $original.attr("data-prefix") || "";
var suffix = $original.attr("data-suffix") || "";
if (prefix) {
var prefixElement = $(
'<span class="input-group-text">' + prefix + "</span>"
);
$inputGroup.find(".input-group-prepend").append(prefixElement);
}
if (suffix) {
var suffixElement = $(
'<span class="input-group-text">' + suffix + "</span>"
);
$inputGroup.find(".input-group-append").prepend(suffixElement);
}
$original[0].setValue = function (newValue) {
setValue(newValue);
};
var observer = new MutationObserver(function () {
updateAttributes();
setValue(value, true);
});
observer.observe($original[0], { attributes: true });
$original.after($inputGroup);
setValue(value);
$input.on("paste input change focusout", function (event) {
var newValue = $input[0].value;
var focusOut = event.type === "focusout";
newValue = parseLocaleNumber(newValue);
setValue(newValue, focusOut);
dispatchEvent($original, event.type);
});
onPointerDown($buttonDecrement[0], function () {
stepHandling(-step);
});
onPointerDown($buttonIncrement[0], function () {
stepHandling(step);
});
onPointerUp(document.body, function () {
resetTimer();
});
function setValue(newValue, updateInput) {
if (updateInput === undefined) {
updateInput = true;
}
if (isNaN(newValue) || newValue === "") {
$original[0].value = "";
if (updateInput) {
$input[0].value = "";
}
value = NaN;
} else {
newValue = parseFloat(newValue);
newValue = Math.min(Math.max(newValue, min), max);
newValue =
Math.round(newValue * Math.pow(10, decimals)) /
Math.pow(10, decimals);
$original[0].value = newValue;
if (updateInput) {
$input[0].value = numberFormat.format(newValue);
}
value = newValue;
}
}
function dispatchEvent($element, type) {
if (type) {
setTimeout(function () {
var event;
if (typeof Event === "function") {
event = new Event(type, { bubbles: true });
} else {
// IE
event = document.createEvent("Event");
event.initEvent(type, true, true);
}
$element[0].dispatchEvent(event);
});
}
}
function stepHandling(step) {
if (!$input[0].disabled && !$input[0].readOnly) {
calcStep(step);
resetTimer();
autoDelayHandler = setTimeout(function () {
autoIntervalHandler = setInterval(function () {
if (boostStepsCount > config.boostThreshold) {
if (autoMultiplier) {
calcStep(step * parseInt(boostMultiplier, 10));
if (boostMultiplier < 100000000) {
boostMultiplier = boostMultiplier * 1.1;
}
if (stepMax) {
boostMultiplier = Math.min(stepMax, boostMultiplier);
}
} else {
calcStep(step * boostMultiplier);
}
} else {
calcStep(step);
}
boostStepsCount++;
}, config.autoInterval);
}, config.autoDelay);
}
}
function calcStep(step) {
if (isNaN(value)) {
value = 0;
}
setValue(Math.round(value / step) * step + step);
dispatchEvent($original, "input");
dispatchEvent($original, "change");
}
function resetTimer() {
boostStepsCount = 0;
boostMultiplier = boostMultiplier = autoMultiplier
? 1
: config.boostMultiplier;
clearTimeout(autoDelayHandler);
clearTimeout(autoIntervalHandler);
}
function updateAttributes() {
// copy properties from original to the new input
$input.prop("required", $original.prop("required"));
$input.prop("placeholder", $original.prop("placeholder"));
$input.attr("inputmode", $original.attr("inputmode") || "decimal");
var disabled = $original.prop("disabled");
var readonly = $original.prop("readonly");
$input.prop("disabled", disabled);
$input.prop("readonly", readonly);
$buttonIncrement.prop("disabled", disabled || readonly);
$buttonDecrement.prop("disabled", disabled || readonly);
if (disabled || readonly) {
resetTimer();
}
var originalClass = $original.prop("class");
var groupClass = "";
// sizing
if (/form-control-sm/g.test(originalClass)) {
groupClass = "input-group-sm";
} else if (/form-control-lg/g.test(originalClass)) {
groupClass = "input-group-lg";
}
var inputClass = originalClass.replace(/form-control(-(sm|lg))?/g, "");
$inputGroup.prop(
"class",
"input-group " + groupClass + " " + config.groupClass
);
$input.prop("class", "form-control " + inputClass);
// update the main attributes
min = parseFloat($original.prop("min")) || 0;
max =
isNaN($original.prop("max")) || $original.prop("max") === ""
? Infinity
: parseFloat($original.prop("max"));
step = parseFloat($original.prop("step")) || 1;
stepMax = parseInt($original.attr("data-step-max")) || 0;
var newDecimals = parseInt($original.attr("data-decimals")) || 0;
var newDigitGrouping = !(
$original.attr("data-digit-grouping") === "false"
);
if (decimals !== newDecimals || digitGrouping !== newDigitGrouping) {
decimals = newDecimals;
digitGrouping = newDigitGrouping;
numberFormat = new Intl.NumberFormat(locale, {
minimumFractionDigits: decimals,
maximumFractionDigits: decimals,
useGrouping: digitGrouping,
});
}
}
function parseLocaleNumber(stringNumber) {
var numberFormat = new Intl.NumberFormat(locale);
var thousandSeparator = numberFormat.format(1111).replace(/1/g, "");
var decimalSeparator = numberFormat.format(1.1).replace(/1/g, "");
return parseFloat(
stringNumber
.replace(new RegExp("\\" + thousandSeparator, "g"), "")
.replace(new RegExp("\\" + decimalSeparator), ".")
);
}
});
return this;
};
function onPointerUp(element, callback) {
element.addEventListener("mouseup", function (e) {
callback(e);
});
element.addEventListener("touchend", function (e) {
callback(e);
});
element.addEventListener("keyup", function (e) {
if (e.keyCode === 32 || e.keyCode === 13) {
triggerKeyPressed = false;
callback(e);
}
});
}
function onPointerDown(element, callback) {
element.addEventListener("mousedown", function (e) {
e.preventDefault();
callback(e);
});
element.addEventListener("touchstart", function (e) {
if (e.cancelable) {
e.preventDefault();
}
callback(e);
});
element.addEventListener("keydown", function (e) {
if ((e.keyCode === 32 || e.keyCode === 13) && !triggerKeyPressed) {
triggerKeyPressed = true;
callback(e);
}
});
}
})(jQuery);

168
public/js/plugins/checkBo.min.js vendored Normal file
View file

@ -0,0 +1,168 @@
/*
* checkBo lightweight jQuery plugin v0.1.4 by @ElmahdiMahmoud
* Licensed under the MIT license - https://github.com/elmahdim/checkbo/blob/master/LICENSE
*
* Custom checkbox and radio
* Author URL: elmahdim.com
*/
!(function (e) {
e.fn.checkBo = function (c) {
return (
(c = e.extend(
{},
{
checkAllButton: null,
checkAllTarget: null,
checkAllTextDefault: null,
checkAllTextToggle: null,
},
c
)),
this.each(function () {
function t(e) {
this.input = e;
}
function n() {
var c = e(this).is(":checked");
e(this).closest("label").toggleClass("checked", c);
}
function i(e, c, t) {
e.text(e.parent(a).hasClass("checked") ? t : c);
}
function h(c) {
var t = c.attr("data-show");
(c = c.attr("data-hide")),
e(t).removeClass("is-hidden"),
e(c).addClass("is-hidden");
}
var l = e(this),
a = l.find(".cb-checkbox"),
d = l.find(".cb-radio"),
o = l.find(".cb-switcher"),
s = a.find("input:checkbox"),
f = d.find("input:radio");
s.wrap('<span class="cb-inner"><i></i></span>'),
f.wrap('<span class="cb-inner"><i></i></span>');
var k = new t("input:checkbox"),
r = new t("input:radio");
if (
((t.prototype.checkbox = function (e) {
var c = e.find(this.input).is(":checked");
e.find(this.input)
.prop("checked", !c)
.trigger("change");
}),
(t.prototype.radiobtn = function (c, t) {
var n = e('input:radio[name="' + t + '"]');
n.prop("checked", !1),
n.closest(n.closest(d)).removeClass("checked"),
c.addClass("checked"),
(c.find(this.input).get(0).checked = c.hasClass(
"checked"
)),
c.find(this.input).change();
}),
s.on("change", n),
f.on("change", n),
a.find("a").on("click", function (e) {
e.stopPropagation();
}),
a.on("click", function (c) {
c.preventDefault(),
k.checkbox(e(this)),
(c = e(this).attr("data-toggle")),
e(c).toggleClass("is-hidden"),
h(e(this));
}),
d.on("click", function (c) {
c.preventDefault(),
r.radiobtn(
e(this),
e(this).find("input:radio").attr("name")
),
h(e(this));
}),
(e.fn.toggleCheckbox = function () {
this.prop("checked", !this.is(":checked"));
}),
(e.fn.switcherChecker = function () {
var c = e(this),
t = c.find("input"),
n = c.find(".cb-state");
t.is(":checked")
? (c.addClass("checked"),
n.html(t.attr("data-state-on")))
: (c.removeClass("checked"),
n.html(t.attr("data-state-off")));
}),
o.on("click", function (c) {
c.preventDefault(),
(c = e(this)),
c.find("input").toggleCheckbox(),
c.switcherChecker(),
e(c.attr("data-toggle")).toggleClass("is-hidden");
}),
o.each(function () {
e(this).switcherChecker();
}),
c.checkAllButton && c.checkAllTarget)
) {
var u = e(this);
u.find(e(c.checkAllButton)).on("click", function () {
u
.find(c.checkAllTarget)
.find("input:checkbox")
.each(function () {
u.find(e(c.checkAllButton)).hasClass("checked")
? u
.find(c.checkAllTarget)
.find("input:checkbox")
.prop("checked", !0)
.change()
: u
.find(c.checkAllTarget)
.find("input:checkbox")
.prop("checked", !1)
.change();
}),
i(
u
.find(e(c.checkAllButton))
.find(".toggle-text"),
c.checkAllTextDefault,
c.checkAllTextToggle
);
}),
u
.find(c.checkAllTarget)
.find(a)
.on("click", function () {
u
.find(c.checkAllButton)
.find("input:checkbox")
.prop("checked", !1)
.change()
.removeClass("checked"),
i(
u
.find(e(c.checkAllButton))
.find(".toggle-text"),
c.checkAllTextDefault,
c.checkAllTextToggle
);
});
}
l
.find('[checked="checked"]')
.closest("label")
.addClass("checked"),
l.find("input").is("input:disabled") &&
l
.find("input:disabled")
.closest("label")
.off()
.addClass("disabled");
})
);
};
})(jQuery, window, document);

View file

@ -0,0 +1,251 @@
/*
Twitter Bootstrap Toogle Buttons 0.0.3
Available under the MIT license.
See https://github.com/prokki/twbs-toggle-buttons for more information.
*/
//** The file has been modified
var $jscomp = $jscomp || {};
$jscomp.scope = {};
$jscomp.findInternal = function (a, b, c) {
a instanceof String && (a = String(a));
for (var d = a.length, e = 0; e < d; e++) {
var f = a[e];
if (b.call(c, f, e, a)) return { i: e, v: f };
}
return { i: -1, v: void 0 };
};
$jscomp.ASSUME_ES5 = !1;
$jscomp.ASSUME_NO_NATIVE_MAP = !1;
$jscomp.ASSUME_NO_NATIVE_SET = !1;
$jscomp.SIMPLE_FROUND_POLYFILL = !1;
$jscomp.defineProperty =
$jscomp.ASSUME_ES5 || "function" == typeof Object.defineProperties
? Object.defineProperty
: function (a, b, c) {
a != Array.prototype && a != Object.prototype && (a[b] = c.value);
};
$jscomp.getGlobal = function (a) {
return "undefined" != typeof window && window === a
? a
: "undefined" != typeof global && null != global
? global
: a;
};
$jscomp.global = $jscomp.getGlobal(this);
$jscomp.polyfill = function (a, b, c, d) {
if (b) {
c = $jscomp.global;
a = a.split(".");
for (d = 0; d < a.length - 1; d++) {
var e = a[d];
e in c || (c[e] = {});
c = c[e];
}
a = a[a.length - 1];
d = c[a];
b = b(d);
b != d &&
null != b &&
$jscomp.defineProperty(c, a, {
configurable: !0,
writable: !0,
value: b,
});
}
};
$jscomp.polyfill(
"Array.prototype.find",
function (a) {
return a
? a
: function (a, c) {
return $jscomp.findInternal(this, a, c).v;
};
},
"es6",
"es3"
);
var TwbsToggleButtons = function (a, b) {
this.$_element = a;
this._initializeOptions(b);
this._initializeDOM();
this.$_element
.find(this._options.twbsBtnSelector)
.on("click", this._eventClick.bind(this));
this.$_element.data("twbsToggleButtons", this);
};
TwbsToggleButtons.TYPE_RADIO = function () {
return 1;
};
TwbsToggleButtons.TYPE_CHECKBOX = function () {
return 2;
};
TwbsToggleButtons.DEFAULTS = function () {
return {
twbsBtnSelector: "[role='button']",
classActive: "active-btn",
classInactive: "inactive-btn",
};
};
TwbsToggleButtons.ACTIVE_CLASS = function () {
return "active";
};
TwbsToggleButtons.prototype._getInputType = function () {
var a = 0,
b = 0;
this.$_element.find(":input").each(function () {
if ("radio" === this.getAttribute("type")) a++;
else if ("checkbox" === this.getAttribute("type")) b++;
else
throw (
"All input fields must be either of type 'radio' or of type 'checkbox, found '" +
this.getAttribute("type") +
"'"
);
});
if (0 !== a && 0 !== b)
throw "All input fields must be either of type 'radio' or of type 'checkbox, found both.";
return 0 < b
? TwbsToggleButtons.TYPE_CHECKBOX()
: TwbsToggleButtons.TYPE_RADIO();
};
TwbsToggleButtons.prototype._initializeOptions = function (a) {
this._options = $.extend({}, TwbsToggleButtons.DEFAULTS(), a || {});
"string" === typeof this._options.classActive &&
(this._options.classActive = [this._options.classActive]);
"string" === typeof this._options.classInactive &&
(this._options.classInactive = [this._options.classInactive]);
};
TwbsToggleButtons.prototype._resetDOM = function (a) {
this.$_element.find(this._options.twbsBtnSelector).each(
function (b, c) {
-1 !== a.indexOf(c) ? this._activateButton(c) : this._deactivateButton(c);
}.bind(this)
);
};
TwbsToggleButtons.prototype._initializeDOM = function () {
var a = this.$_element.find(this._options.twbsBtnSelector),
b = a.filter("." + TwbsToggleButtons.ACTIVE_CLASS()).toArray();
1 < b.length &&
this._getInputType() === TwbsToggleButtons.TYPE_RADIO() &&
(b = [b.pop()]);
a.each(
function (a, d) {
-1 !== b.indexOf(d)
? d.setAttribute("aria-pressed", "true")
: d.setAttribute("aria-pressed", "false");
}.bind(this)
);
this._resetDOM(b);
};
TwbsToggleButtons.prototype._eventClick = function (a) {
var b = this.$_element
.find(this._options.twbsBtnSelector)
.filter(function () {
return "true" === this.getAttribute("aria-pressed");
})
.toArray(),
c = a.currentTarget;
this._getInputType() === TwbsToggleButtons.TYPE_RADIO()
? ((b = [c]),
"true" === c.getAttribute("aria-pressed") &&
(0 ===
this.$_element
.find(this._options.twbsBtnSelector)
.find(":input[required]").length
? (b = [])
: a.stopPropagation()))
: "true" === c.getAttribute("aria-pressed") && -1 !== b.indexOf(c)
? b.splice(b.indexOf(c), 1)
: b.push(c);
this._resetDOM(b);
window.setTimeout(function () {
a.target.dispatchEvent(new Event("twbsToggleButtons:activate"));
}, 0);
return !0;
};
TwbsToggleButtons.prototype._activateButton = function (a) {
void 0 !== a.dataset.twbsToggleButtonsClassActive &&
0 < a.dataset.twbsToggleButtonsClassActive.length
? a.classList.add(a.dataset.twbsToggleButtonsClassActive)
: this._options.classActive.forEach(function (b) {
a.classList.add(b);
});
this._options.classInactive.forEach(function (b) {
a.classList.remove(b);
});
$(a).find(":input").prop("checked", !0);
$(a).find(":input").attr("checked", "checked");
(this._getInputType() !== TwbsToggleButtons.TYPE_RADIO() &&
this._getInputType() !== TwbsToggleButtons.TYPE_CHECKBOX()) ||
"false" !== a.getAttribute("aria-pressed") ||
window.setTimeout(function () {
a.classList.remove(TwbsToggleButtons.ACTIVE_CLASS());
a.setAttribute("aria-pressed", "true");
}, 0);
};
TwbsToggleButtons.prototype._deactivateButton = function (a) {
void 0 !== a.dataset.twbsToggleButtonsClassActive &&
0 < a.dataset.twbsToggleButtonsClassActive.length &&
a.classList.remove(a.dataset.twbsToggleButtonsClassActive);
this._options.classActive.forEach(function (b) {
a.classList.remove(b);
});
this._options.classInactive.forEach(function (b) {
a.classList.add(b);
});
$(a).find(":input").prop("checked", !1);
$(a).find(":input").attr("checked", null);
(this._getInputType() !== TwbsToggleButtons.TYPE_RADIO() &&
this._getInputType() !== TwbsToggleButtons.TYPE_CHECKBOX()) ||
"true" !== a.getAttribute("aria-pressed") ||
window.setTimeout(function () {
a.classList.remove(TwbsToggleButtons.ACTIVE_CLASS());
a.setAttribute("aria-pressed", "false");
}, 0);
};
(function (a) {
null == a.fn.twbsToggleButtons &&
(a.fn.twbsToggleButtons = function (b) {
var c = ["clear", "destroy"];
b = b || {};
if ("object" === typeof b)
return (
this.each(function () {
var c = a.extend(!0, {}, b);
void 0 === a(this).data("twbsToggleButtons")
? new TwbsToggleButtons(a(this), c)
: ((c = a(this).data("twbsToggleButtons")),
null === c &&
window.console &&
console.error &&
console.warn(
"Error on Initialization as TwbsToggleButtons: " + this
));
}),
this
);
if ("string" === typeof b) {
var d,
e = Array.prototype.slice.call(arguments, 1);
this.each(function () {
var c = a(this).data("twbsToggleButtons");
null == c && window.console && console.error
? console.error(
"The twbsToggleButtons('" +
b +
"') method was called on an element that is not using TwbsToggleButtons."
)
: "function" !== typeof c[b] &&
console.error(
"Method '" + b + "' is not implemented in TwbsToggleButtons."
);
d = c[b].apply(c, e);
});
return -1 < a.inArray(b, c) ? this : d;
}
throw Error("Invalid arguments for TwbsToggleButtons: " + b);
});
})(jQuery);