window.onload = function () { if (typeof wp.blocks !== 'undefined') { if (wp.blockLibrary && typeof wp.blockLibrary.registerCoreBlocks === 'function') { wp.blockLibrary.registerCoreBlocks(); } var $ = jQuery; var allBlocks = wp.blocks.getBlockTypes(); var allCategories = wp.blocks.getCategories(); var listBlocks = []; var nonce = ''; allBlocks.forEach(function (block) { var blockItemIcon = ''; var blockItem = { name: block.name, icon: block.icon.src, title: block.title, category: block.category }; var savedIcon = !!block.icon.src ? block.icon.src : block.icon; if (block.icon.foreground !== undefined) blockItem.iconColor = block.icon.foreground; if (typeof savedIcon === 'function') { if (!!savedIcon.prototype.render) { blockItem.icon = wp.element.renderToString(wp.element.createElement(savedIcon)); } else { blockItem.icon = wp.element.renderToString(savedIcon()); } blockItem.icon = blockItem.icon.replace(/stopcolor/g, 'stop-color'); blockItem.icon = blockItem.icon.replace(/stopopacity/g, 'stop-opacity'); } else if (typeof savedIcon === 'object') { blockItem.icon = wp.element.renderToString(savedIcon); blockItem.icon = blockItem.icon.replace(/stopcolor/g, 'stop-color'); blockItem.icon = blockItem.icon.replace(/stopopacity/g, 'stop-opacity'); } else if (typeof savedIcon === 'string') { blockItemIcon = wp.element.createElement(wp.components.Dashicon, {icon: savedIcon}); blockItem.icon = wp.element.renderToString(blockItemIcon); } listBlocks.push(blockItem); return block; }); if (typeof updateListNonce !== 'undefined') { nonce = updateListNonce.nonce; } else { nonce = $('#advgb_nonce_field').val(); } // Update categories allCategories.forEach(function (category) { var categoryBlock = $('.category-block[data-category="'+ category.slug +'"]'); if (categoryBlock.length > 0) { categoryBlock.find('h3.category-name').text(category.title); } else { var categoryHTML = ''; categoryHTML += '