Add category-first template library and improve admin dashboard
This commit is contained in:
+63
-25
@@ -182,44 +182,82 @@ jQuery(function ($) {
|
||||
|
||||
$('[data-canvas-presets]').each(function () {
|
||||
const $gallery = $(this);
|
||||
const $search = $gallery.find('[data-template-search]');
|
||||
const $groups = $gallery.find('[data-template-group]');
|
||||
const $filters = $gallery.find('[data-template-filter]');
|
||||
const $tabs = $gallery.find('[data-library-tab]');
|
||||
const $panels = $gallery.find('[data-library-panel]');
|
||||
const $peek = $gallery.find('[data-template-peek]');
|
||||
const $dialog = $gallery.find('[data-template-dialog]');
|
||||
const $use = $dialog.find('[data-template-use]');
|
||||
let category = '';
|
||||
let $selection;
|
||||
|
||||
function hidePeek() {
|
||||
$peek.prop('hidden', true);
|
||||
}
|
||||
|
||||
function filter() {
|
||||
const query = String($search.val()).trim().toLowerCase();
|
||||
let count = 0;
|
||||
$groups.each(function () {
|
||||
const $group = $(this);
|
||||
const allowed = !category || this.dataset.templateGroup === category;
|
||||
let groupCount = 0;
|
||||
$group.find('[data-template-card]').each(function () {
|
||||
const visible = allowed && this.dataset.templateSearchText.toLowerCase().includes(query);
|
||||
$(this).prop('hidden', !visible);
|
||||
if (visible) groupCount++;
|
||||
});
|
||||
$group.prop('hidden', groupCount === 0);
|
||||
count += groupCount;
|
||||
function selectTab(kind, focus = false) {
|
||||
const $current = $tabs.filter((_, tab) => tab.dataset.libraryTab === kind);
|
||||
$tabs.attr({'aria-selected': 'false', tabindex: '-1'});
|
||||
$current.attr({'aria-selected': 'true', tabindex: '0'});
|
||||
$panels.each(function () {
|
||||
$(this).prop('hidden', this.dataset.libraryPanel !== kind);
|
||||
});
|
||||
$gallery.find('[data-template-empty]').prop('hidden', count !== 0);
|
||||
$gallery.closest('.studio-library').scrollTop(0);
|
||||
hidePeek();
|
||||
if (focus) $current.trigger('focus');
|
||||
}
|
||||
|
||||
function filterItems($panel) {
|
||||
const query = $panel.find('[data-template-search]').val().trim().toLowerCase();
|
||||
let matches = 0;
|
||||
$panel.find('[data-template-group]').filter((_, group) => !group.hidden).find('[data-library-item]').each(function () {
|
||||
const visible = this.dataset.templateSearchText.toLowerCase().includes(query);
|
||||
$(this).prop('hidden', !visible);
|
||||
if (visible) matches++;
|
||||
});
|
||||
$panel.find('[data-template-empty]').prop('hidden', matches !== 0);
|
||||
hidePeek();
|
||||
}
|
||||
|
||||
$search.on('input', filter);
|
||||
$filters.on('click', function () {
|
||||
category = this.dataset.templateFilter;
|
||||
$filters.attr('aria-pressed', 'false');
|
||||
$(this).attr('aria-pressed', 'true');
|
||||
filter();
|
||||
$gallery.find('[data-library-tabs]').prop('hidden', false);
|
||||
function openLayersFromHash() {
|
||||
if (window.location.hash !== '#blocks') return false;
|
||||
selectTab('layers');
|
||||
$gallery.find('#blocks').prop('open', true);
|
||||
return true;
|
||||
}
|
||||
if (!openLayersFromHash()) selectTab('modules');
|
||||
$(window).on('hashchange', openLayersFromHash);
|
||||
$tabs.on('click', function () {
|
||||
selectTab(this.dataset.libraryTab);
|
||||
}).on('keydown', function (event) {
|
||||
const index = $tabs.index(this);
|
||||
const last = $tabs.length - 1;
|
||||
const next = {Home: 0, End: last, ArrowLeft: index === 0 ? last : index - 1, ArrowRight: index === last ? 0 : index + 1}[event.key];
|
||||
if (typeof next !== 'number') return;
|
||||
event.preventDefault();
|
||||
selectTab($tabs.get(next).dataset.libraryTab, true);
|
||||
});
|
||||
|
||||
$gallery.on('click', '[data-library-category]', function () {
|
||||
const $panel = $(this).closest('[data-library-panel]');
|
||||
$panel.data('categoryTrigger', this);
|
||||
$panel.find('[data-library-index]').prop('hidden', true);
|
||||
$panel.find('[data-library-content]').prop('hidden', false);
|
||||
$panel.find('[data-library-title]').text(this.dataset.libraryLabel);
|
||||
$panel.find('[data-template-search]').val('');
|
||||
const key = this.dataset.libraryCategory;
|
||||
$panel.find('[data-template-group]').each(function () {
|
||||
$(this).prop('hidden', this.dataset.templateGroup !== key);
|
||||
});
|
||||
filterItems($panel);
|
||||
$panel.find('[data-library-back]').trigger('focus');
|
||||
}).on('click', '[data-library-back]', function () {
|
||||
const $panel = $(this).closest('[data-library-panel]');
|
||||
$panel.find('[data-library-content]').prop('hidden', true);
|
||||
$panel.find('[data-library-index]').prop('hidden', false);
|
||||
hidePeek();
|
||||
$($panel.data('categoryTrigger')).trigger('focus');
|
||||
}).on('input', '[data-template-search]', function () {
|
||||
filterItems($(this).closest('[data-library-panel]'));
|
||||
});
|
||||
|
||||
$gallery.on('mouseenter focusin', '[data-template-preview]', function (event) {
|
||||
|
||||
Reference in New Issue
Block a user