-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from adrianbj/page-list-select-unselect-restore
Port PageListSelect Unselect / Restore from AOS
- Loading branch information
Showing
3 changed files
with
157 additions
and
0 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
tweaks/Inputfields/PageListSelectUnselectRestore/PageListSelectUnselectRestore.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
53 changes: 53 additions & 0 deletions
53
tweaks/Inputfields/PageListSelectUnselectRestore/PageListSelectUnselectRestore.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}); |
50 changes: 50 additions & 0 deletions
50
tweaks/Inputfields/PageListSelectUnselectRestore/PageListSelectUnselectRestore.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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__) . ' "' . $originalTitle . '""' : ''; | ||
|
||
$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; | ||
} | ||
|
||
} |