@@ -32,26 +32,33 @@ const switchListH = {
3232 '\n' : `<div class='cell empty'>${ dotEmptyH } </div><div class='cell empty'>${ dotEmptyH } </div>`
3333}
3434
35- export const renderFretBoard = ( content , { title : fretTitle , type } ) => {
36- const fretType = type . split ( ' ' )
37- const containerClass = fretType && fretType [ 0 ] . startsWith ( 'h' ) ? 'fretContainer_h' : 'fretContainer'
35+ export const renderFretBoard = ( content , { title : fretTitle = '' , type = '' } ) => {
36+ const isVertical = ! ( typeof type [ 0 ] === 'string' && type [ 0 ] . startsWith ( 'h' ) )
37+
38+ const containerClass = isVertical ? 'fretContainer' : 'fretContainer_h'
39+
40+ const [ fretType , nutOption ] = type . split ( ' ' )
3841 const fretboardHTML = $ ( `<div class="${ containerClass } "></div>` )
3942
40- $ ( fretboardHTML ) . append ( $ ( `<div class="fretTitle">${ fretTitle } </div>` ) )
43+ if ( fretTitle ) {
44+ $ ( fretboardHTML ) . append ( `<div class="fretTitle">${ fretTitle } </div>` )
45+ }
4146
4247 // create fretboard background HTML
43- const fretbOrientation = fretType && fretType [ 0 ] . startsWith ( 'v' ) ? 'vert' : 'horiz'
44- const fretbLen = fretType && fretType [ 0 ] . substring ( 1 )
45- const fretbClass = fretType && fretType [ 0 ] [ 0 ] + ' ' + fretType [ 0 ]
46- const nut = ( fretType [ 1 ] && fretType [ 1 ] === 'noNut' ) ? 'noNut' : ''
48+ const fretbOrientation = isVertical ? 'vert' : 'horiz'
49+ const fretbLen = fretType && fretType . substring ( 1 )
50+ const fretbClass = fretType && fretType [ 0 ] + ' ' + fretType
51+ const nut = nutOption === 'noNut' ? 'noNut' : ''
52+
4753 const svgHTML = $ ( `<div class="svg_wrapper ${ fretbClass } ${ nut } "></div>` )
4854 const fretbBg = require ( `./svg/fretb_${ fretbOrientation } _${ fretbLen } .svg` )
55+
4956 $ ( svgHTML ) . append ( $ ( fretbBg ) )
5057
5158 // create cells HTML
5259 const cellsHTML = $ ( '<div class="cells"></div>' )
53- let switchList = ''
54- if ( fretbOrientation && fretbOrientation === 'vert' ) {
60+ let switchList = { }
61+ if ( isVertical ) {
5562 switchList = switchListV
5663 } else {
5764 // calculate position
@@ -66,16 +73,16 @@ export const renderFretBoard = (content, { title: fretTitle, type }) => {
6673 const numArray = [ ...Array ( 10 ) . keys ( ) ] . slice ( 1 )
6774 contentCell && contentCell . forEach ( char => {
6875 if ( numArray . toString ( ) . indexOf ( char ) !== - 1 ) {
69- const numType = fretType && fretType [ 0 ] . startsWith ( 'h' ) ? '_h ' : ''
76+ const numType = isVertical ? '' : '_h '
7077 const numSvg = require ( `./svg/number${ char } ${ numType } .svg` )
71- cellsHTML . append ( $ ( `<div class='cell empty'>${ numSvg } </div>` ) )
72- } else if ( switchList [ char ] !== undefined ) {
73- cellsHTML . append ( $ ( switchList [ char ] ) )
78+ cellsHTML . append ( `<div class='cell empty'>${ numSvg } </div>` )
79+ } else if ( typeof switchList [ char ] !== ' undefined' ) {
80+ cellsHTML . append ( switchList [ char ] )
7481 }
7582 } )
7683
77- $ ( svgHTML ) . append ( $ ( cellsHTML ) )
78- $ ( fretboardHTML ) . append ( $ ( svgHTML ) )
84+ $ ( svgHTML ) . append ( cellsHTML )
85+ $ ( fretboardHTML ) . append ( svgHTML )
7986
8087 return fretboardHTML [ 0 ] . outerHTML
8188}
0 commit comments