Skip to content

Commit

Permalink
Section-mover to move section into content at System Config page
Browse files Browse the repository at this point in the history
It is used at Argento Theme Editor and SEO Suite
  • Loading branch information
tangar76 committed Jan 6, 2021
1 parent dfd96ff commit 837f622
Show file tree
Hide file tree
Showing 2 changed files with 152 additions and 0 deletions.
72 changes: 72 additions & 0 deletions view/adminhtml/web/css/system-config/section-mover.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
.swissup-mover-tab {
display: none;

.swissup-mover-container & {
display: block;
background: none;
border-width: 0 !important;

.admin__page-nav-title {
text-transform: none;
border: solid #ccc;
border-width: 1px 0 0;
background: #f8f8f8;

&::after {
content: none;
}
}

&._show {
.admin__page-nav-title {
background: #f8f8f8;
border-width: 1px 0 1px;

&::after {
content: none;
}
}
}

.admin__page-nav-item {
border-width: 0 !important;
margin: 0;

a {
display: block;
padding: 1.5rem;
margin: 1rem;
border-width: 0;
text-align: center;
border-radius: 5px;

.img-wrapper {
img {
vertical-align: top;
}
}
}
}

&.admin__page-nav .admin__page-nav-items {
display: flex;
flex-wrap: wrap;
}

&.admin__page-nav._collapsed._show ._collapsible + .admin__page-nav-items {
display: flex !important;
}
}
}

.swissup-mover-container {
.entry-edit-head {
display: none;
}

&:last-child {
.admin__page-nav-title {
border-width: 1px 0 1px;
}
}
}
80 changes: 80 additions & 0 deletions view/adminhtml/web/js/system-config/section-mover.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
define([
'jquery'
], function ($) {
'use strict';

return function (options, element) {
/**
* [_updateTitle description]
*/
function _updateTitle() {
var currentItem;

currentItem = $('._active', element).text();

if (currentItem) {
$('.admin__page-nav-title', element).html(
options.title.selected.replace('{{itemName}}', currentItem)
);
} else {
$('.admin__page-nav-title', element).html(options.title.no);
}
}

/**
* Assign image to theme
*/
function _assignImage() {
var itemTitle, image, html;

itemTitle = $(this).text().trim();
image = options.images ? options.images[itemTitle] : false;

if (image) {
html = '<div class="img-wrapper"><img src="{{image}}" width="240" /></div>';
$(this).prepend(html.replace('{{image}}', image));
}
}

/**
* [_activateItem description]
*/
function _activateItem() {
$(options.itemToActivateWhenSelected).closest('.config-nav-block').collapsible('activate');
$(options.itemToActivateWhenSelected).addClass('_active');
}

/**
* Update section collapsible status
*/
function _updateCollapsibleStatus() {
var currentItem;

if (typeof $(element).collapsible === 'function') {
currentItem = $('._active', element).text();

$('.admin__page-nav-items', element).css({
display: 'flex'
});

if (currentItem) {
$(element).collapsible('deactivate');
$('.admin__page-nav-items', element).css({
display: 'none'
});
_activateItem();
} else {
$(element).collapsible('activate');
}
} else {
setTimeout(_updateCollapsibleStatus, 400);
}
}

$(element).detach();
$('a', element).each(_assignImage);
_updateTitle();
_updateCollapsibleStatus();
$(element).appendTo(options.destination);
};
});

0 comments on commit 837f622

Please sign in to comment.