generated from alexplusde/blaupause
-
-
Notifications
You must be signed in to change notification settings - Fork 0
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 #8 from alexplusde/search
Suche in QuickNavigation integriert
- Loading branch information
Showing
15 changed files
with
279 additions
and
22 deletions.
There are no files selected for viewing
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
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,85 @@ | ||
function data_copy(event) { | ||
// Holt das aktuelle Element, auf das geklickt wurde | ||
var element = event.currentTarget; | ||
// Fügt die Klasse "copied" zum aktuellen Element hinzu | ||
element.classList.add('copied'); | ||
// Sucht das icon-Element im aktuellen Element | ||
var iconElement = element.querySelector('i'); | ||
// Entfernt die Klasse "fa-clone" vom i-Element | ||
iconElement.classList.remove('fa-clone'); | ||
// Fügt die Klasse "fa-check" zum i-Element hinzu | ||
iconElement.classList.add('fa-check'); | ||
// Kopiert den Wert des data-wildcard-copy Attributs in die Zwischenablage | ||
navigator.clipboard.writeText(element.getAttribute('data-wildcard-copy')); | ||
}; | ||
|
||
$(document).on("rex:ready", function(wildcard, container) { | ||
|
||
// Fügt den Click-Event-Listener zu allen div-Elementen mit dem data-wildcard-copy Attribut hinzu | ||
document.querySelectorAll('div[data-wildcard-copy]').forEach(function(el) { | ||
el.addEventListener('click', data_copy) | ||
}) | ||
|
||
// Warte auf QuickNavigation - Event an das Formular erst nach 2 Sekunden | ||
setTimeout(function() { | ||
|
||
// Fügt den Submit-Event-Listener zum Formular mit der ID "wildcard_search" hinzu | ||
$('#wildcard_search').on('submit', function(e) { | ||
// Verhindert das Absenden des Formulars | ||
e.preventDefault(); | ||
|
||
// Sendet eine AJAX-Anfrage | ||
$.ajax({ | ||
url: '/', // URL, an die die Anfrage gesendet wird | ||
type: 'GET', // Methode der Anfrage | ||
data: { | ||
"rex-api-call": 'wildcard_search', // Daten, die an den Server gesendet werden | ||
"q": $('input[name="q"]').val() // Wert des Eingabefelds | ||
}, | ||
success: function(response) { | ||
// Erstellt ein leeres table-Element und fügt Klassen hinzu | ||
var table = $('<table></table>'); | ||
table.addClass('table table-striped table-hover'); | ||
// Erstellt ein leeres tbody-Element | ||
var tbody = $('<tbody></tbody>'); | ||
|
||
// Durchläuft jedes Element im Antwortobjekt | ||
$.each(response, function(key, value) { | ||
// Erstellt ein neues tr-Element und fügt das gewünschte HTML hinzu | ||
var tr = $('<tr></tr>'); | ||
var th = $('<th></th>'); | ||
var div = $('<div></div>').attr('data-wildcard-copy', key).attr('role', 'button'); | ||
var i = $('<i></i>').addClass('fa fa-clone').attr('aria-hidden', 'true'); | ||
var code = $('<code></code>').text(key); | ||
div.append(i); | ||
div.append(code); | ||
th.append(div); | ||
var td = $('<td></td>').text("⫸ " + value['de_DE']); | ||
tr.append(th); | ||
tr.append(td); | ||
|
||
// Fügt das tr-Element zum tbody-Element hinzu | ||
tbody.append(tr); | ||
// Fügt das tbody-Element zum table-Element hinzu | ||
table.append(tbody); | ||
}); | ||
|
||
// Fügt das table-Element in das div mit der ID "wildcardSearchResults" ein | ||
$('#wildcardSearchResults').html(table); | ||
|
||
// Fügt den Click-Event-Listener zu allen neuen div-Elementen mit dem data-wildcard-copy Attribut hinzu | ||
document.querySelectorAll('div[data-wildcard-copy]').forEach(function(el) { | ||
el.addEventListener('click', data_copy) | ||
}) | ||
|
||
}, | ||
error: function() { | ||
// Zeigt eine Fehlermeldung an, wenn ein Fehler auftritt | ||
$('#wildcardSearchResults').html('Ein Fehler ist aufgetreten.'); | ||
} | ||
}); | ||
}); | ||
|
||
}, 2000); | ||
|
||
}); |
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
26 changes: 26 additions & 0 deletions
26
fragments/wildcard/backend/WildcardQuicknavigationButton.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,26 @@ | ||
|
||
<div class="btn-group dropdown"> | ||
<form action="/" method="get" id="wildcard_search"> | ||
<input type="hidden" name="rex-api-call" value="wildcard_search"> | ||
<button class="btn btn-secondary dropdown-toggle" type="button" id="wildcardSearchQuicknavigationButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> | ||
<i class="rex-icon fa-language"> </i> <span class="caret"></span> | ||
</button> | ||
<div style="max-width: calc(100vw - 200px); width: 700px" class="quicknavi quicknavi-items list-group dropdown-menu dropdown-menu-right" aria-labelledby="wildcardSearch"> | ||
<div style="padding: 10px;"> | ||
|
||
|
||
<div class="input-group"> | ||
<input type="search" class="form-control" name="q" placeholder="<?= \rex_i18n::msg('wildcard_quicknavigation_search_placeholder') ?>"> | ||
<span class="input-group-btn"> | ||
<button class="btn btn-primary" id="wildcardSearchButton"><span class="rex-icon fa-search"></span> <?= \rex_i18n::msg('wildcard_quicknavigation_search_button') ?></button> | ||
</span> | ||
</div> | ||
</form> | ||
|
||
<div id="wildcardSearchResults" style="padding-top: 10px;"> | ||
</div> | ||
</div> | ||
|
||
|
||
</div> | ||
</div> |
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
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
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,15 @@ | ||
<?php | ||
|
||
namespace Alexplusde\Wildcard; | ||
|
||
use FriendsOfRedaxo\QuickNavigation\Button\ButtonInterface; | ||
use rex_fragment; | ||
|
||
class QuickNavigationButton implements ButtonInterface | ||
{ | ||
public function get(): string | ||
{ | ||
$fragment = new rex_fragment(); | ||
return $fragment->parse('wildcard/backend/WildcardQuicknavigationButton.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
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,24 @@ | ||
<?php | ||
|
||
use Alexplusde\Wildcard\Wildcard; | ||
|
||
class rex_api_wildcard_search extends rex_api_function | ||
{ | ||
protected $published = true; | ||
|
||
public function execute() | ||
{ | ||
$search = rex_request('q', 'string', ''); | ||
$result = Wildcard::query()->whereRaw( | ||
"`package` LIKE '%" . $search . "%' OR `wildcard` LIKE '%" . $search . "%' OR `text_de_DE` LIKE '%" . $search . "%'", | ||
)->limit(10)->orderBy('package')->orderBy('wildcard')->find(['search' => $search]); | ||
$wildcards = []; | ||
foreach ($result as $item) { | ||
$wildcards[$item->wildcard] = ['de_DE' => $item->text_de_DE]; | ||
} | ||
/* Header setzen */ | ||
header('Content-Type: application/json'); | ||
echo json_encode($wildcards); | ||
exit; | ||
} | ||
} |
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
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
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 @@ | ||
<?=/** Standard-Methoden, um README.md in REDAXO auszugeben */ rex_view::title(rex_i18n::msg('wildcard_title')); |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
<?php | ||
|
||
echo rex_view::title(rex_i18n::msg('wildcard_title')); | ||
rex_be_controller::includeCurrentPageSubPath(); |
Oops, something went wrong.