@@ -32,26 +32,33 @@ const switchListH = {
32
32
'\n' : `<div class='cell empty'>${ dotEmptyH } </div><div class='cell empty'>${ dotEmptyH } </div>`
33
33
}
34
34
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 ( ' ' )
38
41
const fretboardHTML = $ ( `<div class="${ containerClass } "></div>` )
39
42
40
- $ ( fretboardHTML ) . append ( $ ( `<div class="fretTitle">${ fretTitle } </div>` ) )
43
+ if ( fretTitle ) {
44
+ $ ( fretboardHTML ) . append ( `<div class="fretTitle">${ fretTitle } </div>` )
45
+ }
41
46
42
47
// 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
+
47
53
const svgHTML = $ ( `<div class="svg_wrapper ${ fretbClass } ${ nut } "></div>` )
48
54
const fretbBg = require ( `./svg/fretb_${ fretbOrientation } _${ fretbLen } .svg` )
55
+
49
56
$ ( svgHTML ) . append ( $ ( fretbBg ) )
50
57
51
58
// create cells HTML
52
59
const cellsHTML = $ ( '<div class="cells"></div>' )
53
- let switchList = ''
54
- if ( fretbOrientation && fretbOrientation === 'vert' ) {
60
+ let switchList = { }
61
+ if ( isVertical ) {
55
62
switchList = switchListV
56
63
} else {
57
64
// calculate position
@@ -66,16 +73,16 @@ export const renderFretBoard = (content, { title: fretTitle, type }) => {
66
73
const numArray = [ ...Array ( 10 ) . keys ( ) ] . slice ( 1 )
67
74
contentCell && contentCell . forEach ( char => {
68
75
if ( numArray . toString ( ) . indexOf ( char ) !== - 1 ) {
69
- const numType = fretType && fretType [ 0 ] . startsWith ( 'h' ) ? '_h ' : ''
76
+ const numType = isVertical ? '' : '_h '
70
77
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 ] )
74
81
}
75
82
} )
76
83
77
- $ ( svgHTML ) . append ( $ ( cellsHTML ) )
78
- $ ( fretboardHTML ) . append ( $ ( svgHTML ) )
84
+ $ ( svgHTML ) . append ( cellsHTML )
85
+ $ ( fretboardHTML ) . append ( svgHTML )
79
86
80
87
return fretboardHTML [ 0 ] . outerHTML
81
88
}
0 commit comments