* Browser Only - Sends messages to web worker to highlight elements passed * in * * @param {Array} codeBlocks * @param {Function} callback * @return {void}
(codeBlocks, callback)
| 201 | * @return {void} |
| 202 | */ |
| 203 | function _highlightCodeBlocks(codeBlocks, callback) { |
| 204 | const waitingOn = { c: 0 }; |
| 205 | for (const block of codeBlocks) { |
| 206 | const language = getLanguageForBlock(block); |
| 207 | if (block.classList.contains('rainbow') || !language) { |
| 208 | continue; |
| 209 | } |
| 210 | |
| 211 | // This cancels the pending animation to fade the code in on load |
| 212 | // since we want to delay doing this until it is actually |
| 213 | // highlighted |
| 214 | block.classList.add('loading'); |
| 215 | block.classList.add('rainbow'); |
| 216 | |
| 217 | // We need to make sure to also add the loading class to the pre tag |
| 218 | // because that is how we will know to show a preloader |
| 219 | if (block.parentNode.tagName === 'PRE') { |
| 220 | block.parentNode.classList.add('loading'); |
| 221 | } |
| 222 | |
| 223 | const globalClass = block.getAttribute('data-global-class'); |
| 224 | const delay = parseInt(block.getAttribute('data-delay'), 10); |
| 225 | |
| 226 | ++waitingOn.c; |
| 227 | _messageWorker(_getWorkerData(block.innerHTML, { language, globalClass, delay }), _generateHandler(block, waitingOn, callback)); |
| 228 | } |
| 229 | |
| 230 | if (waitingOn.c === 0) { |
| 231 | callback(); |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | function _addPreloader(preBlock) { |
| 236 | const preloader = document.createElement('div'); |
no test coverage detected