| 1 |
/** |
| 2 |
* Block Changelog |
| 3 |
*/ |
| 4 |
const { |
| 5 |
GHOSTKIT: { events }, |
| 6 |
} = window; |
| 7 |
|
| 8 |
/** |
| 9 |
* Prepare Changelogs. |
| 10 |
*/ |
| 11 |
events.on(document, 'init.blocks.gkt', () => { |
| 12 |
document |
| 13 |
.querySelectorAll('.ghostkit-changelog:not(.ghostkit-changelog-ready)') |
| 14 |
.forEach(($this) => { |
| 15 |
events.trigger($this, 'prepare.changelog.gkt'); |
| 16 |
|
| 17 |
$this.classList.add('ghostkit-changelog-ready'); |
| 18 |
|
| 19 |
// Add badges. |
| 20 |
$this |
| 21 |
.querySelector(':scope > .ghostkit-changelog-more') |
| 22 |
.querySelectorAll(':scope > ul li, :scope > ol li') |
| 23 |
.forEach(($li) => { |
| 24 |
const text = $li.innerHTML.trim(); |
| 25 |
const typeMatches = text.match( |
| 26 |
/^\[(new|added|fixed|improved|updated|removed|changed)\]\s(.*)/i |
| 27 |
); |
| 28 |
|
| 29 |
if (typeMatches) { |
| 30 |
const changeType = typeMatches[1]; |
| 31 |
const changeDescription = typeMatches[2]; |
| 32 |
|
| 33 |
let className = 'ghostkit-badge'; |
| 34 |
|
| 35 |
switch (changeType.toLowerCase()) { |
| 36 |
case 'added': |
| 37 |
case 'new': |
| 38 |
className += ' ghostkit-badge-success'; |
| 39 |
break; |
| 40 |
case 'fixed': |
| 41 |
case 'improved': |
| 42 |
case 'updated': |
| 43 |
className += ' ghostkit-badge-primary'; |
| 44 |
break; |
| 45 |
case 'removed': |
| 46 |
className += ' ghostkit-badge-danger'; |
| 47 |
break; |
| 48 |
// no default |
| 49 |
} |
| 50 |
|
| 51 |
$li.innerHTML = `<span class="${className}">${changeType}</span> ${changeDescription}`; |
| 52 |
} |
| 53 |
}); |
| 54 |
|
| 55 |
events.trigger($this, 'prepared.changelog.gkt'); |
| 56 |
}); |
| 57 |
}); |
| 58 |
|