/* 获取直属子元素 */
function getChildren(el, className) {
for (let item of el.children) if (item.className === className) return item;
return null;
}
// 跳转链接的卡片
document.addEventListener("DOMContentLoaded", () => {
customElements.define(
"hao-introduction-card",
class HaoIntroductionCard extends HTMLElement {
constructor() {
super();
this.options = {
link: this.getAttribute("link") || 'https://0206.ink/',
img: this.getAttribute("img"),
tip: this.getAttribute("tip") || '小标题',
cardTitle: this.getAttribute("cardTitle") || '标题',
logo: this.getAttribute("logo"),
title: this.getAttribute("title"),
subTitle: this.getAttribute("subTitle"),
};
let style1 = ''
let style2 = ''
if(this.options.logo==null && this.options.title==null && this.options.subTitle==null){
style1 = 'height:416px'
style2 = 'height:100%;border-radius:15px'
}
let innerHTMLs = `
${this.options.tip}
${this.options.cardTitle}
`;
if(this.options.logo!=null && this.options.title!=null && this.options.subTitle!=null){
innerHTMLs += `
${this.options.title}
${this.options.subTitle}
`;
}
innerHTMLs += `
`;
this.innerHTML = innerHTMLs;
}
}
);
// 折叠框 folding
customElements.define(
"hao-folding",
class HaoFolding extends HTMLElement {
constructor() {
super();
this.options = {
title: this.getAttribute("title"),
color: this.getAttribute("color") || '',
type: this.getAttribute("type") || ''
};
const _temp = getChildren(this, "_tpl");
let contents = _temp.innerHTML.trim().replace(/^(
)|(
)$/g, "");
let htmlStr = `
${this.options.title}
${contents}
`;
this.innerHTML = htmlStr;
}
}
);
// 链接卡片 link
customElements.define(
"hao-tag-link",
class HaoTagLink extends HTMLElement {
constructor() {
super();
this.options = {
link: this.getAttribute("link"),
logo: this.getAttribute("logo"),
title: this.getAttribute("title") || '',
described: this.getAttribute("described") || '',
};
let htmlStr = `
`;
this.innerHTML = htmlStr;
}
}
);
// Note (Bootstrap Callout)
customElements.define(
"hao-note",
class HaoNote extends HTMLElement {
constructor() {
super();
this.options = {
class: this.getAttribute("class") || '',
noIcon: this.getAttribute("noIcon") || '',
style: this.getAttribute("style") || ''
};
let htmlStr = `
${this.innerHTML.trim().replace(/^(
)|(
)$/g, "")}
`;
this.innerHTML = htmlStr;
}
}
);
// 上标标签 tip
customElements.define(
"hao-tip",
class HaoTip extends HTMLElement {
constructor() {
super();
this.options = {
class: this.getAttribute("class") || 'info',
noIcon: this.getAttribute("noIcon") || ''
};
let htmlStr = `
${this.innerHTML.trim().replace(/^(
)|(
)$/g, "")}
`;
this.innerHTML = htmlStr;
}
}
);
// timeline
customElements.define(
"hao-timeline",
class HaoTimeline extends HTMLElement {
constructor() {
super();
this.options = {
title: this.getAttribute("title") || '',
color: this.getAttribute("color") || ''
};
const _temp = getChildren(this, "_tpl");
let _innerHTML = _temp.innerHTML.trim().replace(/^(
)|(
)$/g, "");
let content = "";
_innerHTML.replace(
/{timeline-item([^}]*)}([\s\S]*?){\/timeline-item}/g,
function ($0, $1, $2) {
content += `
${$2.trim().replace(/^(
)|(
)$/g, "")}
`;
}
);
let htmlStr = `
`;
this.innerHTML = htmlStr;
}
}
);
// 按钮 btns
customElements.define(
"hao-btns",
class HaoBtns extends HTMLElement {
constructor() {
super();
this.options = {
class: this.getAttribute("class") || '',
style: this.getAttribute("style") || '',
grid: this.getAttribute("grid") || '',
};
const _temp = getChildren(this, "_tpl");
let _innerHTML = _temp.innerHTML.trim().replace(/^(
)|(
)$/g, "");
let content = "";
if(this.options.class == 'rounded'){
_innerHTML.replace(
/{([^}]*)}/g,
function ($0, $1) {
var str = $1.split(",", 5);
if(str.length==5){
content += `
${str[0]}
${str[1]}
`;
}else{
content += `
${str[0]}
`;
}
}
);
}
if(this.options.class == 'circle'){
_innerHTML.replace(
/{([^}]*)}/g,
function ($0, $1) {
var str = $1.split(",", 5);
if(str.length==5){
content += `
${str[0]}
${str[1]}
`;
}else{
content += `
${str[0]}
`;
}
}
);
}
let htmlStr = `
${content}
`;
this.innerHTML = htmlStr;
}
}
);
// 分栏 tab
// customElements.define(
// "hao-tabs",
// class HaoTabs extends HTMLElement {
// constructor() {
// super();
// this.options = {
// id: this.getAttribute("id") || '',
// index: this.getAttribute("index") || ''
// };
// const id = this.options.id
// const index = this.options.index
// const _temp = getChildren(this, "_tpl");
//
// let _innerHTML = _temp.innerHTML.trim().replace(/^(
)|(
)$/g, "");
// let navs = "";
// let contents = "";
// let newIndex = 0;
//
// _innerHTML.replace(
// /{tabs-item([^}]*)}([\s\S]*?){\/tabs-item}/g,
// function ($0, $1, $2) {
// newIndex +=1;
// let active =''
// if(index!='' && index!=null){
// if(newIndex == index){
// active = 'active';
// }
// }else{
// if(newIndex==1){
// active = 'active'
// }
// }
// navs += `
//
// `;
// contents += `
//
// ${$2.trim().replace(/^(
)|(
)$/g, "")}
//
//
// `;
// }
// );
// let htmlStr = `
//
//
// `;
// this.innerHTML = htmlStr;
// }
// }
// );
// gallerygroup 相册图库
customElements.define(
"hao-gallery-group",
class HaoGalleryGroup extends HTMLElement {
constructor() {
super();
const _temp = getChildren(this, "_tpl");
let _innerHTML = _temp.innerHTML.trim().replace(/^(
)|(
)$/g, "");
let contents = "";
_innerHTML.replace(
/{([^}]*)}/g,
function ($0, $1) {
var str = $1.split(",",4);
contents += `
${str[0]}
${str[1]}
`;
}
);
let htmlStr = `
${contents}
`;
this.innerHTML = htmlStr;
}
}
);
// gallery 相册
customElements.define(
"hao-gallery",
class HaoGallery extends HTMLElement {
constructor() {
super();
const _temp = getChildren(this, "_tpl");
let _innerHTML = _temp.innerHTML.trim().replace(/^(
)|(
)$/g, "");
let contents = "";
_innerHTML.replace(
/{([^}]*)}/g,
function ($0, $1) {
var str = $1.split(",");
str.forEach((item) => {
contents += `
`;
});
}
);
let htmlStr = `
`;
this.innerHTML = htmlStr;
}
}
);
// flink 友链标签
customElements.define(
"hao-flink",
class HaoFlink extends HTMLElement {
constructor() {
super();
this.options = {
name: this.getAttribute("name"),
desc: this.getAttribute("desc"),
style: this.getAttribute("style"),
};
const _temp = getChildren(this, "_tpl");
let _innerHTML = _temp.innerHTML.trim().replace(/^(
)|(
)$/g, "");
let style = this.options.style;
let content = "";
let contents = "";
let class_desc = "";
_innerHTML.replace(
/{([^}]*)}/g,
function ($0, $1) {
var flink = $1.split(",",5);
if(style=='beautify'){
contents +=`
`
}
if(style=='default'){
contents +=`
`
}
}
);
if(this.options.desc!=null && this.options.desc!=''){
class_desc =`
${this.options.desc}
`
}
if(this.options.style=='beautify'){
content =`
${contents}
`
}
if(this.options.style=='default'){
content =`
${contents}
`
}
let htmlStr = `
${this.options.name}
${class_desc}
${content}
`;
this.innerHTML = htmlStr;
}
}
);
// 复选列表 checkbox
customElements.define(
"hao-checkbox",
class HaoCheckbox extends HTMLElement {
constructor() {
super();
this.options = {
class: this.getAttribute("class") || '',
colour: this.getAttribute("colour") || '',
status: this.getAttribute("status") || ''
};
let htmlStr = `
`;
this.innerHTML = htmlStr;
}
}
);
// tag-hide
customElements.define(
"hao-tag-hide",
class HaoCheckbox extends HTMLElement {
constructor() {
super();
this.options = {
display: this.getAttribute("display") || '查看',
bg: this.getAttribute("bg") || '',
color: this.getAttribute("color") || ''
};
let htmlStr = `
${this.innerHTML.trim().replace(/^(
)|(
)$/g, "")}
`;
this.innerHTML = htmlStr;
}
}
);
customElements.define(
"hao-dplayer",
class HaoDplayer extends HTMLElement {
constructor() {
super();
this.options = {
src: this.getAttribute("src") || "",
player:
this.getAttribute("player") ||
`/themes/theme-hao/assets/libs/dplayer/dplayer.html?url=`,
width: this.getAttribute("width") || "100%",
height: this.getAttribute("height") || "500px",
};
this.render();
}
render() {
if (this.options.src)
this.innerHTML = ``;
else this.innerHTML = "视频地址未填写!";
}
}
);
});