2022-11-16 14:53:22 +08:00
|
|
|
|
$(function () {
|
|
|
|
|
$(".dropdown-menu.dropdown-select-menu").each((index, value) => {
|
|
|
|
|
setDropdownItem(value)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
2022-11-16 17:23:00 +08:00
|
|
|
|
/**
|
|
|
|
|
* fn 定義 | 手動初始化 Bootstrap dropdown select
|
|
|
|
|
*/
|
2022-11-16 14:53:22 +08:00
|
|
|
|
$.fn.droSetItem = function () {
|
|
|
|
|
setDropdownItem(this);
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-16 17:23:00 +08:00
|
|
|
|
/**
|
|
|
|
|
* 設置 bootstrap dropdown 為下拉選單
|
|
|
|
|
* @param {any} menuEle .dropdown-menu element
|
|
|
|
|
*/
|
2022-11-16 14:53:22 +08:00
|
|
|
|
function setDropdownItem(menuEle) {
|
|
|
|
|
if ($(menuEle).find(".dropdown-item.active").length == 0) {
|
|
|
|
|
$(menuEle).find(".dropdown-item").first().addClass("active");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let actText = $(menuEle).find(".dropdown-item.active").first().text();
|
|
|
|
|
let actEleId = $(menuEle).prop("id");
|
|
|
|
|
$(`.dropdown-toggle[data-target=${actEleId}]`).text(actText);
|
|
|
|
|
$(menuEle).trigger("active:change", $(menuEle).find(".dropdown-item.active"));
|
|
|
|
|
|
2022-11-16 17:23:00 +08:00
|
|
|
|
//點選選項 add active class
|
|
|
|
|
onEvent("click", ".dropdown-menu.dropdown-select-menu .dropdown-item", function () {
|
|
|
|
|
$(this).parent(".dropdown-menu.dropdown-select-menu").find(".dropdown-item").removeClass("active");
|
|
|
|
|
$(this).addClass("active");
|
|
|
|
|
setDropdownItem($(this).parent(".dropdown-menu.dropdown-select-menu"));
|
|
|
|
|
})
|
|
|
|
|
}
|
2022-11-16 14:53:22 +08:00
|
|
|
|
|
2022-11-16 17:23:00 +08:00
|
|
|
|
/**
|
|
|
|
|
* 預設設備圖像
|
|
|
|
|
* @param {any} obj
|
|
|
|
|
*/
|
2022-11-16 14:53:22 +08:00
|
|
|
|
function defDev(obj) {
|
|
|
|
|
let defSrc = 'img/defdev.png';
|
|
|
|
|
obj.src = defSrc;
|
|
|
|
|
}
|