Skip to content

Commit

Permalink
Merge pull request #15 from adrianbj/page-list-select-unselect-restore
Browse files Browse the repository at this point in the history
Port PageListSelect Unselect / Restore from AOS
  • Loading branch information
BernhardBaumrock authored May 18, 2024
2 parents 28dab06 + 9ddfc07 commit 735583f
Show file tree
Hide file tree
Showing 3 changed files with 157 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
.aos_pagelist_unselect {
margin-top: 1px !important;
padding: 0 !important;
text-align: center;
border: none !important;
transition-duration: 0.1s !important;
max-width: 60px;
line-height: 1 !important;
}
.aos_pagelist_unselect i {
padding: 3px 5px !important;
display: inline-block;
}
.aos_pagelist_unselect, .aos_pagelist_unselect:hover {
padding: 0 !important;
}
.aos_pagelist_unselect.empty, .aos_pagelist_unselect.initial {
pointer-events: none;
opacity: 0.3;
filter: saturate(0);
border-color: inherit;
}
.aos_pagelist_unselect.clear {
background-color: transparent !important;
margin-left: -3px;
margin-right: 5px;
float: left;
color: #8d939e !important;
}
.aos_pagelist_unselect.clear:hover {
color: #8d939e !important;
background-color: transparent !important;
}
.aos_pagelist_unselect.clear:hover i {
transform: scale(1.2);
transform-origin: center;
}
.aos_pagelist_unselect.clear:hover ~ .PageListRoot .PageListSelectName {
text-decoration: line-through;
}
.aos_pagelist_unselect.clear ~ .PageListRoot {
float: left;
width: calc(100% - 54px);
margin-bottom: 1rem;
}
.aos_pagelist_unselect.clear ~ .notes {
width: 100%;
clear: both;
}
.aos_pagelist_unselect.restore {
position: relative;
top: -3px;
margin-right: 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
$(document).on('pageSelected', function (e, obj) {

var clearButton = obj.a.parents('.InputfieldPageListSelect').first().find('button.clear'),
restoreButton = obj.a.parents('.InputfieldPageListSelect').first().find('button.restore');

if (obj.id !== 0) {
clearButton.removeClass('empty');
} else {
clearButton.addClass('empty');
}

restoreButton.removeClass('empty').removeClass('initial');
});

$(document).on('click', '.aos_pagelist_unselect', function () {

var button = $(this),
parentEl = button.parent(),
input = button.parent().find('input'),
//titleElem = button.parent().find('.PageListSelectName .label_title');
titleElem = button.parent().find('.PageListSelectName');

// try without .label_title (on pageSelected the span disappears)
//if (!titleElem.length) {
// titleElem = button.parent().find('.PageListSelectName');
//}

if (button.hasClass('clear')) {
// clear
input.removeAttr('value');
titleElem.html('');
button.addClass('empty');

parentEl.find('button.restore[data-value-original!=""]').removeClass('empty');
parentEl.find('button.restore').removeClass('initial');
} else {
// restore
input.val(button.attr('data-value-original'));
titleElem.html(button.attr('data-title-original'));
button.addClass('empty');
parentEl.find('button.clear').removeClass('empty');
}

// if pagelist is open, close it
if (parentEl.find('.PageListItemOpen').length) {
parentEl.find('a.PageListSelectActionToggle').trigger('click');
}

// allow dependent fields to update
input.trigger('change');

return false;
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace RockAdminTweaks;

/**
* Originally from AdminOnSteroids by RolandToth (tpr)
*/
class PageListSelectUnselectRestore extends Tweak
{

public $editedPage = false;

public function info(): array
{
return [
'description' => 'Add unselect/restore buttons to PageListSelect',
];
}

public function ready(): void
{

$this->loadJS();
$this->loadCSS();

$this->addHookAfter('InputfieldPageListSelect::render', $this, 'addPageListUnselectButtons');

}

public function addPageListUnselectButtons($event)
{
$field = $event->object;

$originalID = '';
$originalTitle = ($field->value && $this->pages->get($field->value)) ? $this->pages->get($field->value)->title : '';

if (isset($this->PageListTweaks) && in_array('pListIDs', $this->PageListTweaks) && $this->wire('user')->isSuperuser()) {
$originalID = ($field->value && $this->pages->get($field->value)) ? $this->pages->get($field->value)->id : '';
}

$restoreTitleTag = strlen($originalTitle) ? 'title="' . \ProcessWire\__('Restore', __FILE__) . ' &quot;' . $originalTitle . '&quot;"' : '';

$clearButton = '<button class="aos_pagelist_unselect clear ui-button ' . ($field->value ? '' : 'empty') . '" title="' . \ProcessWire\__('Clear', __FILE__) . '"><i class="fa fa-times-circle"></i></button>';

$restoreButton = $field->value ? '<button class="aos_pagelist_unselect restore ui-button initial" ' . $restoreTitleTag . ' data-title-original="' . $originalTitle . '" data-pid="' . $originalID . '" data-value-original="' . $field->value . '" ><i class="fa fa-undo"></i></button>' : '';

$event->return = $restoreButton . $clearButton . $event->return;
}

}

0 comments on commit 735583f

Please sign in to comment.