| 1 |
/** |
| 2 |
* Block Gist |
| 3 |
*/ |
| 4 |
const { |
| 5 |
GHOSTKIT: { events }, |
| 6 |
gistSimple, |
| 7 |
} = window; |
| 8 |
|
| 9 |
/** |
| 10 |
* Prepare Gists. |
| 11 |
*/ |
| 12 |
events.on(document, 'init.blocks.gkt', () => { |
| 13 |
if (typeof gistSimple === 'undefined') { |
| 14 |
return; |
| 15 |
} |
| 16 |
|
| 17 |
document |
| 18 |
.querySelectorAll('.ghostkit-gist:not(.ghostkit-gist-ready)') |
| 19 |
.forEach(($this) => { |
| 20 |
$this.classList.add('ghostkit-gist-ready'); |
| 21 |
|
| 22 |
const match = /^https:\/\/gist.github.com?.+\/(.+)/g.exec( |
| 23 |
$this.getAttribute('data-url') |
| 24 |
); |
| 25 |
|
| 26 |
if (match && typeof match[1] !== 'undefined') { |
| 27 |
const options = { |
| 28 |
id: match[1], |
| 29 |
file: $this.getAttribute('data-file'), |
| 30 |
caption: $this.getAttribute('data-caption'), |
| 31 |
showFooter: |
| 32 |
$this.getAttribute('data-show-footer') === 'true', |
| 33 |
showLineNumbers: |
| 34 |
$this.getAttribute('data-show-line-numbers') === 'true', |
| 35 |
}; |
| 36 |
|
| 37 |
events.trigger($this, 'prepare.gist.gkt', { options }); |
| 38 |
|
| 39 |
gistSimple($this, options); |
| 40 |
|
| 41 |
events.trigger($this, 'prepared.gist.gkt', { options }); |
| 42 |
} |
| 43 |
}); |
| 44 |
}); |
| 45 |
|