Update message.js, tabs.js
This commit is contained in:
parent
3cbb978a22
commit
ec1d2c7923
|
@ -1,11 +1,15 @@
|
||||||
/**
|
/**
|
||||||
* Bulma Message Tag, see {@link https://bulma.io/documentation/components/message/}.
|
* Bulma Message Tag, see {@link https://bulma.io/documentation/components/message/}.
|
||||||
* @param {string} color The color of this message. Usable: dark, primary, link, info, success, warning, danger.
|
*
|
||||||
|
* @param {string} color The color of this message, can not be set. Usable: dark, primary, link, info, success,
|
||||||
|
* warning, danger.
|
||||||
* @param {string} icon The icon of this message, can not be set.
|
* @param {string} icon The icon of this message, can not be set.
|
||||||
* @param {string} title The header of this message, can not be set, supported Markdown.
|
* @param {string} title The header of this message, can not be set, supported Markdown.
|
||||||
* @param {string} styles Additional styles of this message, can not be set. Usable: [small, medium, large].
|
* @param {string} size The size of this message, can not be set. Usable: small, medium, large. The default
|
||||||
|
* size is between small and medium.
|
||||||
|
*
|
||||||
* @example
|
* @example
|
||||||
* {% message color:danger icon:info-circle 'title:Very danger!' style:small %}
|
* {% message color:danger icon:info-circle 'title:Very danger!' size:small %}
|
||||||
* **You are in danger.**
|
* **You are in danger.**
|
||||||
* {% endmessage %}
|
* {% endmessage %}
|
||||||
*/
|
*/
|
||||||
|
@ -13,11 +17,11 @@ hexo.extend.tag.register('message', function(args, content) {
|
||||||
var color = 'dark';
|
var color = 'dark';
|
||||||
var icon = '';
|
var icon = '';
|
||||||
var title = '';
|
var title = '';
|
||||||
var styles = '';
|
var size = '';
|
||||||
var header = '';
|
var header = '';
|
||||||
args.forEach(element => {
|
args.forEach(element => {
|
||||||
var key = element.split(':')[0];
|
var key = element.split(':')[0].trim();
|
||||||
var value = element.split(':')[1];
|
var value = element.split(':')[1].trim();
|
||||||
if (value != null && value != undefined && value != '') {
|
if (value != null && value != undefined && value != '') {
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case 'color':
|
case 'color':
|
||||||
|
@ -29,15 +33,8 @@ hexo.extend.tag.register('message', function(args, content) {
|
||||||
case 'title':
|
case 'title':
|
||||||
title = value;
|
title = value;
|
||||||
break;
|
break;
|
||||||
case 'style':
|
case 'size':
|
||||||
var stylesArray = value.split(' ');
|
size = ` is-${value}`;
|
||||||
var processed = [];
|
|
||||||
stylesArray.forEach(styleElement, index => {
|
|
||||||
if (styleElement != null && styleElement != undefined && styleElement != '') {
|
|
||||||
processed.push(`is-${styleElement}`);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
styles = processed.join(' ');
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,7 +47,7 @@ hexo.extend.tag.register('message', function(args, content) {
|
||||||
`
|
`
|
||||||
}
|
}
|
||||||
return `
|
return `
|
||||||
<article class="message is-${color} ${styles}">
|
<article class="message is-${color}${size}">
|
||||||
${header}
|
${header}
|
||||||
<div class="message-body">
|
<div class="message-body">
|
||||||
${hexo.render.renderSync({text: content, engine: 'md'})}
|
${hexo.render.renderSync({text: content, engine: 'md'})}
|
||||||
|
|
|
@ -0,0 +1,118 @@
|
||||||
|
/**
|
||||||
|
* Bulma Tabs Tag, see {@link https://bulma.io/documentation/components/tabs/}.
|
||||||
|
*
|
||||||
|
* The format of each item is: <!-- <active>item [id] [<icon>] '[title]' --> [content] <!-- enditem -->.
|
||||||
|
* If each item's content is indented with four spaces or one tab, these indents will be ignored.
|
||||||
|
*
|
||||||
|
* @param {string} id The unique id of this tab, should match: /\w/.
|
||||||
|
* @param {string} behavior The behavior of this tab, can not be set. Usable: centered, right, fullwidth. The
|
||||||
|
* default behavior is to display on the left.
|
||||||
|
* @param {string} size The size of this tab, can not be set. Usable: small, medium, large. The default
|
||||||
|
* size is between small and medium.
|
||||||
|
* @param {string} style The style of this tab, can not be set. Usable: boxed, toggle, toggle-rounded.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* {% tabs behavior:fullwidth size:small style:toggle-rounded %}
|
||||||
|
* <!-- item info info 'Info' -->This is info.<!-- enditem -->
|
||||||
|
* <!-- activeitem hello 'Hello' -->This is hello.<!-- enditem -->
|
||||||
|
* {% endmessage %}
|
||||||
|
*/
|
||||||
|
hexo.extend.tag.register('tabs', function(args, content) {
|
||||||
|
var id = '';
|
||||||
|
var behavior = '';
|
||||||
|
var size = '';
|
||||||
|
var style = '';
|
||||||
|
var contentEl = content;
|
||||||
|
args.forEach(element => {
|
||||||
|
var key = element.split(':')[0].trim();
|
||||||
|
var value = element.split(':')[1].trim();
|
||||||
|
if (value != null && value != undefined && value != '') {
|
||||||
|
switch (key) {
|
||||||
|
case 'id':
|
||||||
|
id = value;
|
||||||
|
break;
|
||||||
|
case 'behavior':
|
||||||
|
behavior = ` is-${value}`;
|
||||||
|
break;
|
||||||
|
case 'size':
|
||||||
|
size = ` is-${value}`;
|
||||||
|
break;
|
||||||
|
case 'style':
|
||||||
|
if (value == 'toggle-rounded') {
|
||||||
|
style = ' is-toggle is-toggle-rounded';
|
||||||
|
} else {
|
||||||
|
style = ` is-${value}`;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
var blockRegExp = /<!--\s*(active)?item( \w+)( \w+)?( '.*?')\s*-->([\s\S]*?)<!--\s*enditem\s*-->/g;
|
||||||
|
var match;
|
||||||
|
var tabsEl = '';
|
||||||
|
var contentEl = '';
|
||||||
|
|
||||||
|
while((match = blockRegExp.exec(content)) !== null) {
|
||||||
|
var active = '';
|
||||||
|
var hidden = ' is-hidden';
|
||||||
|
if (match[1] != undefined) {
|
||||||
|
active = ' class="is-active"';
|
||||||
|
hidden = '';
|
||||||
|
}
|
||||||
|
var icon = '';
|
||||||
|
if (match[3] != undefined && match[3].substring(1) != '') icon = `<span class="icon is-small"><i class="fas fa-${match[3].substring(1)}" aria-hidden="true"></i></span>`;
|
||||||
|
var contentString = match[5].replace(/^\n?|[ \n\t]*$/g, '');
|
||||||
|
if (contentString.match(/^ {4}|^\t{1}/gm) != null && contentString.match(/^ {4}|^\t{1}/gm).length == contentString.split('\n').length) contentString = contentString.replace(/^ {4}|^\t{1}/g, '').replace(/\n {4}|\n\t{1}/g, '\n');
|
||||||
|
tabsEl += `
|
||||||
|
<li id="${match[2].substring(1)}"${active}">
|
||||||
|
<a onclick="switchTab(this)">${hexo.render.renderSync({text: icon + match[4].substring(2, match[4].length - 1), engine: 'markdown'})}</a>
|
||||||
|
</li>
|
||||||
|
`;
|
||||||
|
contentEl += `
|
||||||
|
<div id="${match[2].substring(1)}" class="tab-content${hidden}">
|
||||||
|
${hexo.render.renderSync({text: contentString, engine: 'markdown'})}
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return `
|
||||||
|
<div>
|
||||||
|
<div class="tabs my-3${behavior}${size}${style}">
|
||||||
|
<ul class="mx-0 my-0">
|
||||||
|
${tabsEl}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
${contentEl}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
}, { ends: true });
|
||||||
|
|
||||||
|
hexo.extend.injector.register(
|
||||||
|
"head_end",
|
||||||
|
`
|
||||||
|
<script>
|
||||||
|
function switchTab(element) {
|
||||||
|
var id = element.parentElement.id;
|
||||||
|
var tabElements = element.parentElement.parentElement.children;
|
||||||
|
var contentElements = element.parentElement.parentElement.parentElement.parentElement.children[1].children;
|
||||||
|
for (var i = 0; i < tabElements.length; i++) {
|
||||||
|
var $tab = tabElements[i];
|
||||||
|
var $content = contentElements[i];
|
||||||
|
if ($tab.id == id) {
|
||||||
|
$tab.classList.add('is-active');
|
||||||
|
} else {
|
||||||
|
$tab.classList.remove('is-active');
|
||||||
|
}
|
||||||
|
if ($content.id == id) {
|
||||||
|
$content.classList.remove('is-hidden');
|
||||||
|
} else {
|
||||||
|
$content.classList.add('is-hidden');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
`
|
||||||
|
);
|
Loading…
Reference in New Issue