Skip to content

Commit

Permalink
Use wt- namespace for data attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
fisharebest committed Sep 1, 2021
1 parent d9af609 commit d4786c6
Show file tree
Hide file tree
Showing 108 changed files with 270 additions and 187 deletions.
2 changes: 1 addition & 1 deletion app/Elements/NamePieceSurname.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function edit(string $id, string $name, string $value, Tree $tree): strin
{
return
'<div class="input-group">' .
'<input data-autocomplete-url="' . e(route(AutoCompleteSurname::class, ['tree' => $tree->name()])) . '" autocomplete="off" class="form-control" dir="auto" type="text" id="' . e($id) . '" name="' . e($name) . '" value="' . e($value) . '" />' .
'<input data-wt-autocomplete-url="' . e(route(AutoCompleteSurname::class, ['tree' => $tree->name()])) . '" autocomplete="off" class="form-control" dir="auto" type="text" id="' . e($id) . '" name="' . e($name) . '" value="' . e($value) . '" />' .
view('edit/input-addon-keyboard', ['id' => $id]) .
view('edit/input-addon-help', ['fact' => 'SURN']) .
'</div>';
Expand Down
2 changes: 1 addition & 1 deletion app/Elements/PlaceName.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,6 @@ public function canonical(string $value): string
*/
public function edit(string $id, string $name, string $value, Tree $tree): string
{
return '<input data-autocomplete-url="' . e(route(AutoCompletePlace::class, ['tree' => $tree->name()])) . '" autocomplete="off" class="form-control" type="text" id="' . e($id) . '" name="' . e($name) . '" value="' . e($value) . '" />';
return '<input data-wt-autocomplete-url="' . e(route(AutoCompletePlace::class, ['tree' => $tree->name()])) . '" autocomplete="off" class="form-control" type="text" id="' . e($id) . '" name="' . e($name) . '" value="' . e($value) . '" />';
}
}
2 changes: 1 addition & 1 deletion app/Elements/WhereWithinSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class WhereWithinSource extends AbstractElement
*/
public function edit(string $id, string $name, string $value, Tree $tree): string
{
return '<input data-autocomplete-url="' . e(route(AutoCompleteCitation::class, ['tree' => $tree->name()])) . '" data-autocomplete-extra="SOUR" autocomplete="off" class="form-control" type="text" id="' . e($id) . '" name="' . e($name) . '" value="' . e($value) . '" />';
return '<input data-wt-autocomplete-url="' . e(route(AutoCompleteCitation::class, ['tree' => $tree->name()])) . '" data-wt-autocomplete-extra="SOUR" autocomplete="off" class="form-control" type="text" id="' . e($id) . '" name="' . e($name) . '" value="' . e($value) . '" />';
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/Elements/XrefLocation.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function edit(string $id, string $name, string $value, Tree $tree): strin

return
'<div class="input-group">' .
'<button class="btn btn-secondary" type="button" data-bs-toggle="modal" data-bs-backdrop="static" data-bs-target="#wt-ajax-modal" data-href="' . e(route(CreateLocationModal::class, ['tree' => $tree->name()])) . '" data-select-id="' . $id . '" title="' . I18N::translate('Create a location') . '">' .
'<button class="btn btn-secondary" type="button" data-bs-toggle="modal" data-bs-backdrop="static" data-bs-target="#wt-ajax-modal" data-wt-href="' . e(route(CreateLocationModal::class, ['tree' => $tree->name()])) . '" data-wt-select-id="' . $id . '" title="' . I18N::translate('Create a location') . '">' .
view('icons/add') .
'</button>' .
$select .
Expand Down
2 changes: 1 addition & 1 deletion app/Elements/XrefMedia.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function edit(string $id, string $name, string $value, Tree $tree): strin

return
'<div class="input-group">' .
'<button class="btn btn-secondary" type="button" data-bs-toggle="modal" data-bs-backdrop="static" data-bs-target="#wt-ajax-modal" data-href="' . e(route(CreateMediaObjectModal::class, ['tree' => $tree->name()])) . '" data-select-id="' . $id . '" title="' . I18N::translate('Create a media object') . '">' .
'<button class="btn btn-secondary" type="button" data-bs-toggle="modal" data-bs-backdrop="static" data-bs-target="#wt-ajax-modal" data-wt-href="' . e(route(CreateMediaObjectModal::class, ['tree' => $tree->name()])) . '" data-wt-select-id="' . $id . '" title="' . I18N::translate('Create a media object') . '">' .
view('icons/add') .
'</button>' .
$select .
Expand Down
2 changes: 1 addition & 1 deletion app/Elements/XrefNote.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function edit(string $id, string $name, string $value, Tree $tree): strin

return
'<div class="input-group">' .
'<button class="btn btn-secondary" type="button" data-bs-toggle="modal" data-bs-backdrop="static" data-bs-target="#wt-ajax-modal" data-href="' . e(route(CreateNoteModal::class, ['tree' => $tree->name()])) . '" data-select-id="' . $id . '" title="' . I18N::translate('Create a shared note') . '">' .
'<button class="btn btn-secondary" type="button" data-bs-toggle="modal" data-bs-backdrop="static" data-bs-target="#wt-ajax-modal" data-wt-href="' . e(route(CreateNoteModal::class, ['tree' => $tree->name()])) . '" data-wt-select-id="' . $id . '" title="' . I18N::translate('Create a shared note') . '">' .
view('icons/add') .
'</button>' .
$select .
Expand Down
2 changes: 1 addition & 1 deletion app/Elements/XrefRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function edit(string $id, string $name, string $value, Tree $tree): strin

return
'<div class="input-group">' .
'<button class="btn btn-secondary" type="button" data-bs-toggle="modal" data-bs-backdrop="static" data-bs-target="#wt-ajax-modal" data-href="' . e(route(CreateRepositoryModal::class, ['tree' => $tree->name()])) . '" data-select-id="' . $id . '" title="' . I18N::translate('Create a repository') . '">' .
'<button class="btn btn-secondary" type="button" data-bs-toggle="modal" data-bs-backdrop="static" data-bs-target="#wt-ajax-modal" data-wt-href="' . e(route(CreateRepositoryModal::class, ['tree' => $tree->name()])) . '" data-wt-select-id="' . $id . '" title="' . I18N::translate('Create a repository') . '">' .
view('icons/add') .
'</button>' .
$select .
Expand Down
2 changes: 1 addition & 1 deletion app/Elements/XrefSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function edit(string $id, string $name, string $value, Tree $tree): strin

return
'<div class="input-group">' .
'<button class="btn btn-secondary" type="button" data-bs-toggle="modal" data-bs-backdrop="static" data-bs-target="#wt-ajax-modal" data-href="' . e(route(CreateSourceModal::class, ['tree' => $tree->name()])) . '" data-select-id="' . $id . '" title="' . I18N::translate('Create a source') . '">' .
'<button class="btn btn-secondary" type="button" data-bs-toggle="modal" data-bs-backdrop="static" data-bs-target="#wt-ajax-modal" data-wt-href="' . e(route(CreateSourceModal::class, ['tree' => $tree->name()])) . '" data-wt-select-id="' . $id . '" title="' . I18N::translate('Create a source') . '">' .
view('icons/add') .
'</button>' .
$select .
Expand Down
2 changes: 1 addition & 1 deletion app/Elements/XrefSubmission.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function edit(string $id, string $name, string $value, Tree $tree): strin

return
'<div class="input-group">' .
'<button class="btn btn-secondary" type="button" data-bs-toggle="modal" data-bs-backdrop="static" data-bs-target="#wt-ajax-modal" data-href="' . e(route(CreateSubmissionModal::class, ['tree' => $tree->name()])) . '" data-select-id="' . $id . '" title="' . I18N::translate('Create a submission') . '">' .
'<button class="btn btn-secondary" type="button" data-bs-toggle="modal" data-bs-backdrop="static" data-bs-target="#wt-ajax-modal" data-wt-href="' . e(route(CreateSubmissionModal::class, ['tree' => $tree->name()])) . '" data-wt-select-id="' . $id . '" title="' . I18N::translate('Create a submission') . '">' .
view('icons/add') .
'</button>' .
$select .
Expand Down
2 changes: 1 addition & 1 deletion app/Elements/XrefSubmitter.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function edit(string $id, string $name, string $value, Tree $tree): strin

return
'<div class="input-group">' .
'<button class="btn btn-secondary" type="button" data-bs-toggle="modal" data-bs-backdrop="static" data-bs-target="#wt-ajax-modal" data-href="' . e(route(CreateSubmitterModal::class, ['tree' => $tree->name()])) . '" data-select-id="' . $id . '" title="' . I18N::translate('Create a submitter') . '">' .
'<button class="btn btn-secondary" type="button" data-bs-toggle="modal" data-bs-backdrop="static" data-bs-target="#wt-ajax-modal" data-wt-href="' . e(route(CreateSubmitterModal::class, ['tree' => $tree->name()])) . '" data-wt-select-id="' . $id . '" title="' . I18N::translate('Create a submitter') . '">' .
view('icons/add') .
'</button>' .
$select .
Expand Down
2 changes: 1 addition & 1 deletion app/Http/RequestHandlers/DataFixData.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function handle(ServerRequestInterface $request): ResponseInterface
'xref' => $row->xref,
] + $params);
// wt-ajax-modal-title
$col2 = '<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-backdrop="static" data-bs-target="#wt-ajax-modal" data-href="' . $preview_url . '">' . view('icons/search') . I18N::translate('Preview') . '</button>';
$col2 = '<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-backdrop="static" data-bs-target="#wt-ajax-modal" data-wt-href="' . $preview_url . '">' . view('icons/search') . I18N::translate('Preview') . '</button>';
$col2 .= ' <button type="button" class="btn btn-primary" data-update-url="' . $update_url . '">' . view('icons/data-fix') . I18N::translate('Update') . '</button>';
} else {
$col2 = '—';
Expand Down
2 changes: 1 addition & 1 deletion app/Http/RequestHandlers/ManageMediaData.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ public function handle(ServerRequestInterface $request): ResponseInterface
}
}

$delete_link = '<p><a data-confirm="' . I18N::translate('Are you sure you want to delete “%s”?', e($row[0])) . '" data-post-url="' . e(route(DeletePath::class, [
$delete_link = '<p><a data-wt-confirm="' . I18N::translate('Are you sure you want to delete “%s”?', e($row[0])) . '" data-wt-post-url="' . e(route(DeletePath::class, [
'path' => $row[0],
])) . '" href="#">' . I18N::translate('Delete') . '</a></p>';

Expand Down
2 changes: 1 addition & 1 deletion app/Module/ColorsTheme.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ protected function menuPalette(): Menu
'#',
'menu-color-' . $palette_id . ($palette === $palette_id ? ' active' : ''),
[
'data-post-url' => $url,
'data-wt-post-url' => $url,
]
);

Expand Down
4 changes: 2 additions & 2 deletions app/Module/DescendancyModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public function getPersonLi(Individual $person, $generations = 0): string

return
'<li class="sb_desc_indi_li">' .
'<a class="sb_desc_indi" href="#" data-href="' . e(route('module', [
'<a class="sb_desc_indi" href="#" data-wt-href="' . e(route('module', [
'module' => $this->name(),
'action' => 'Descendants',
'tree' => $person->tree()->name(),
Expand Down Expand Up @@ -218,7 +218,7 @@ public function getFamilyLi(Family $family, Individual $person, $generations = 0

return
'<li class="sb_desc_indi_li">' .
'<a class="sb_desc_indi" href="#" data-href="#"><i class="plusminus icon-minus"></i>' .
'<a class="sb_desc_indi" href="#" data-wt-href="#"><i class="plusminus icon-minus"></i>' .
$spouse_name .
$marr .
'</a>' .
Expand Down
8 changes: 4 additions & 4 deletions app/Module/ModuleThemeTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ public function menuLanguages(): ?Menu
$language_tag = $active_locale->languageTag();
$class = 'menu-language-' . $language_tag . (I18N::languageTag() === $language_tag ? ' active' : '');
$menu->addSubmenu(new Menu($active_locale->endonym(), '#', $class, [
'data-post-url' => route(SelectLanguage::class, ['language' => $language_tag]),
'data-wt-post-url' => route(SelectLanguage::class, ['language' => $language_tag]),
]));
}

Expand Down Expand Up @@ -295,8 +295,8 @@ public function menuLogout(): ?Menu
{
if (Auth::check()) {
$parameters = [
'data-post-url' => route(Logout::class),
'data-reload-url' => route(HomePage::class)
'data-wt-post-url' => route(Logout::class),
'data-wt-reload-url' => route(HomePage::class)
];

return new Menu(I18N::translate('Sign out'), '#', 'menu-logout', $parameters);
Expand Down Expand Up @@ -444,7 +444,7 @@ public function menuThemes(): ?Menu
$class = 'menu-theme-' . $theme->name() . ($active ? ' active' : '');

return new Menu($theme->title(), '#', $class, [
'data-post-url' => route(SelectTheme::class, ['theme' => $theme->name()]),
'data-wt-post-url' => route(SelectTheme::class, ['theme' => $theme->name()]),
]);
});

Expand Down
2 changes: 1 addition & 1 deletion public/js/webtrees.min.js

Large diffs are not rendered by default.

43 changes: 21 additions & 22 deletions resources/js/webtrees.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* webtrees: online genealogy
* Copyright (C) 2020 webtrees development team
* Copyright (C) 2021 webtrees development team
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
Expand Down Expand Up @@ -596,10 +596,10 @@
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
url: this.dataset.autocompleteUrl,
url: this.dataset.wtAutocompleteUrl,
replace: function (url, uriEncodedQuery) {
const symbol = (url.indexOf("?") > 0) ? '&' : '?';
if (that.dataset.autocompleteExtra === 'SOUR') {
if (that.dataset.wtAutocompleteExtra === 'SOUR') {
let row_group = that.closest('.form-group').previousElementSibling;
while (row_group.querySelector('select') === null) {
row_group = row_group.previousElementSibling;
Expand Down Expand Up @@ -676,12 +676,12 @@ $.ajaxSetup({
$(function () {
// Page elements that load automatically via AJAX.
// This prevents bad robots from crawling resource-intensive pages.
$('[data-ajax-url]').each(function () {
$(this).load($(this).data('ajaxUrl'));
$('[data-wt-ajax-url]').each(function () {
$(this).load(this.dataset.wtAjaxUrl);
});

// Autocomplete
webtrees.autocomplete('input[data-autocomplete-url]');
webtrees.autocomplete('input[data-wt-autocomplete-url]');

// Select2 - activate autocomplete fields
const lang = document.documentElement.lang;
Expand Down Expand Up @@ -728,13 +728,13 @@ $(function () {
let osk_focus_element;
$('.wt-osk-trigger').click(function () {
// When a user clicks the icon, set focus to the corresponding input
osk_focus_element = document.getElementById($(this).data('id'));
osk_focus_element = document.getElementById(this.dataset.wtId);
osk_focus_element.focus();
$('.wt-osk').show();
});
$('.wt-osk-script-button').change(function () {
$('.wt-osk-script').prop('hidden', true);
$('.wt-osk-script-' + $(this).data('script')).prop('hidden', false);
$('.wt-osk-script-' + this.dataset.wtOskScript).prop('hidden', false);
});
$('.wt-osk-shift-button').click(function () {
document.querySelector('.wt-osk-keys').classList.toggle('shifted');
Expand Down Expand Up @@ -763,19 +763,19 @@ $(function () {
states: {
shown: {
toggle: {
content: this.dataset.hideText,
content: this.dataset.wtHidePasswordText,
attr: {
title: this.dataset.hideTitle,
'aria-label': this.dataset.hideTitle,
title: this.dataset.wtHidePasswordTitle,
'aria-label': this.dataset.wtHidePasswordTitle,
}
}
},
hidden: {
toggle: {
content: this.dataset.showText,
content: this.dataset.wtShowPasswordText,
attr: {
title: this.dataset.showTitle,
'aria-label': this.dataset.showTitle,
title: this.dataset.wtShowPasswordTitle,
'aria-label': this.dataset.wtShowPasswordTitle,
}
}
}
Expand All @@ -799,32 +799,31 @@ document.addEventListener('submit', function (event) {
}
});

// Convert data-confirm and data-post-url attributes into useful behavior.
// Convert data-wt-confirm and data-wt-post-url/data-wt-reload-url attributes into useful behavior.
document.addEventListener('click', (event) => {
const target = event.target.closest('a,button');

if (target === null) {
return;
}

if ('confirm' in target.dataset && !confirm(target.dataset.confirm)) {
if ('wtConfirm' in target.dataset && !confirm(target.dataset.wtConfirm)) {
event.preventDefault();
return;
}

if ('postUrl' in target.dataset) {
if ('wtPostUrl' in target.dataset) {
const token = document.querySelector('meta[name=csrf]').content;

fetch(target.dataset.postUrl, {
fetch(target.dataset.wtPostUrl, {
method: 'POST',
headers: {
'X-CSRF-TOKEN': token,
'X-Requested-with': 'XMLHttpRequest',
},
}).then(() => {
if ('reloadUrl' in target.dataset) {
// Go somewhere else. e.g. home page after logout.
document.location = target.dataset.reloadUrl;
if ('wtReloadUrl' in target.dataset) {
// Go somewhere else. e.g. the home page after logout.
document.location = target.dataset.wtReloadUrl;
} else {
// Reload the current page. e.g. change language.
document.location.reload();
Expand Down
2 changes: 1 addition & 1 deletion resources/views/admin/changes-log.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ use Fisharebest\Webtrees\Tree;
<?= /* I18N: A button label. */ I18N::translate('download') ?>
</a>

<a href="#" class="btn btn-danger" data-confirm="<?= I18N::translate('Permanently delete these records?') ?>" data-post-url="<?= (route(PendingChangesLogDelete::class, ['from' => $from, 'to' => $to, 'type' => $type, 'xref' => $xref, 'oldged' => $oldged, 'newged' => $newged, 'tree' => $tree->name(), 'username' => $username])) ?>">
<a href="#" class="btn btn-danger" data-wt-confirm="<?= I18N::translate('Permanently delete these records?') ?>" data-wt-post-url="<?= (route(PendingChangesLogDelete::class, ['from' => $from, 'to' => $to, 'type' => $type, 'xref' => $xref, 'oldged' => $oldged, 'newged' => $newged, 'tree' => $tree->name(), 'username' => $username])) ?>">
<?= view('icons/delete') ?>
<?= I18N::translate('delete') ?>
</a>
Expand Down
4 changes: 2 additions & 2 deletions resources/views/admin/clean-data.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ use Fisharebest\Webtrees\I18N;
<?php else : ?>
<a
href="#"
data-confirm="<?= I18N::translate('Are you sure you want to delete “%s”?', e($entry)) ?>"
data-post-url="<?= e(route(DeletePath::class, ['path' => $entry])) ?>"
data-wt-confirm="<?= I18N::translate('Are you sure you want to delete “%s”?', e($entry)) ?>"
data-wt-post-url="<?= e(route(DeletePath::class, ['path' => $entry])) ?>"
class="btn btn-sm btn-link"
>
<?= view('icons/delete') ?>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/admin/data-fix-page.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ use Fisharebest\Webtrees\View;

<hr>

<a href="#" data-bs-toggle="modal" data-bs-backdrop="static" data-bs-target="#wt-ajax-modal" data-href="<?= e(route(HelpText::class, ['topic' => 'data-fixes'])) ?>">
<a href="#" data-bs-toggle="modal" data-bs-backdrop="static" data-bs-target="#wt-ajax-modal" data-wt-href="<?= e(route(HelpText::class, ['topic' => 'data-fixes'])) ?>">
<?= view('icons/help') ?>
<?= I18N::translate('Why does this list include records that do not need to be updated?') ?>
</a>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/admin/fix-level-0-media-action.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use Fisharebest\Webtrees\Media;

<button
class="btn btn-primary btn-small mb-1 wt-fix-button"
data-confirm="<?= I18N::translate('Move the media object?') ?>"
data-wt-confirm="<?= I18N::translate('Move the media object?') ?>"
data-fact-id="<?= e($fact->id()) ?>"
data-tree-id="<?= e($individual->tree()->id()) ?>"
data-individual-xref="<?= e($individual->xref()) ?>"
Expand Down

0 comments on commit d4786c6

Please sign in to comment.