UNPKG

@kurohyou/k-scaffold

Version:

This framework simplifies the task of writing code for Roll20 character sheets. It aims to provide an easier interface between the html and sheetworkers with some minor css templates.

36 lines (34 loc) 1.75 kB
/** * The default tab navigation function of the K-scaffold. Courtesy of Riernar. It will add `k-active-tab` to the active tab-container and `k-active-button` to the active button. You can either write your own CSS to control display of these, or use the default CSS included in `scaffold/_k.scss`. Note that `k-active-button` has no default CSS as it is assumed that you will want to style the active button to match your system. * @memberof Sheetworkers * @param {Object} trigger - The trigger object * @param {object} attributes - The attribute values of the character */ const kSwitchTab = function ({ trigger, attributes }) { const [container, tab] = ( trigger.name.match(/nav-tabs-(.+)--(.+)/) || [] ).slice(1); $20(`[data-container-tab="${container}"]`).removeClass('k-active-tab'); $20(`[data-container-tab="${container}"][data-tab="${tab}"]`).addClass('k-active-tab'); $20(`[data-container-button="${container}"]`).removeClass('k-active-button'); $20(`[data-container-button="${container}"][data-button="${tab}"]`).addClass('k-active-button'); const tabInputName = `${container.replace(/\-/g,'_')}_tab`; if(persistentTabs.indexOf(tabInputName) > -1){ attributes[tabInputName] = trigger.name; } } registerFuncs({ kSwitchTab }); /** * Sets persistent tabs to their last active state * @memberof Sheetworkers * @param {object} attributes - The attribute values of the character */ const kTabOnOpen = function({trigger,attributes,sections,casc}){ if(typeof persistentTabs === 'undefined') return; persistentTabs.forEach((tabInput) => { const pseudoTrigger = {name:attributes[tabInput]}; kSwitchTab({trigger:pseudoTrigger, attributes}); }); }; registerFuncs({ kTabOnOpen },{type:['opener']});