Skip to content

Commit

Permalink
Add search modal window support.
Browse files Browse the repository at this point in the history
  • Loading branch information
ivopetkov committed Dec 8, 2021
1 parent 6d08271 commit cb84032
Show file tree
Hide file tree
Showing 11 changed files with 113 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/.gitattributes export-ignore
/.gitignore export-ignore
/dev export-ignore
/README.md export-ignore
12 changes: 12 additions & 0 deletions assets/search.min.js.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

/*
* Search box element addon for Bear CMS
* https://github.com/bearcms/search-box-element-addon
* Copyright (c) Amplilabs Ltd.
* Free to use under the MIT license.
*/

return <<<'EOT'
var bearCMS=bearCMS||{};bearCMS.search=bearCMS.search||{open:function(){clientPackages.get("modalWindows").then((function(e){e.open("-bearcms-search-input")}))}};
EOT;
6 changes: 5 additions & 1 deletion autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
'bearcms/bearframework-addon',
'bearframework/localization-addon',
'bearframework/tasks-addon',
'ivopetkov/data-index-bearframework-addon'
'ivopetkov/data-index-bearframework-addon',
'ivopetkov/client-packages-bearframework-addon',
'ivopetkov/modal-windows-bearframework-addon',
'ivopetkov/form-bearframework-addon',
'ivopetkov/form-elements-bearframework-addon'
]
]);
4 changes: 2 additions & 2 deletions classes/Utilities.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

/*
* Audits addon for Bear CMS
* https://github.com/bearcms/audits-addon
* Search box element addon for Bear CMS
* https://github.com/bearcms/search-box-element-addon
* Copyright (c) Amplilabs Ltd.
* Free to use under the MIT license.
*/
Expand Down
7 changes: 7 additions & 0 deletions components/searchBoxElement.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
<?php

/*
* Search box element addon for Bear CMS
* https://github.com/bearcms/search-box-element-addon
* Copyright (c) Amplilabs Ltd.
* Free to use under the MIT license.
*/

use BearFramework\App;

$app = App::get();
Expand Down
30 changes: 30 additions & 0 deletions components/searchWindowForm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
/*
* Search box element addon for Bear CMS
* https://github.com/bearcms/search-box-element-addon
* Copyright (c) Amplilabs Ltd.
* Free to use under the MIT license.
*/

use BearFramework\App;

$app = App::get();

$form->constraints
->setRequired('bearcms-search-input');

$form->onSubmit = function ($values) use ($app) {
$searchTerm = $values['bearcms-search-input'];
return $app->urls->get('/s/' . $searchTerm . '/');
};

echo '<html>';
echo '<body>';

echo '<form onsubmitsuccess="clientPackages.get(\'modalWindows\').then(function(m){m.closeAll();m.showLoading();});window.location.href=event.result;">';
echo '<form-element-textbox name="bearcms-search-input" placeholder="' . htmlentities(__('bearcms/search-box-element-addon/ModalWindow/SearchHint')) . '"/>';
echo '<form-element-submit-button text="' . htmlentities(__('bearcms/search-box-element-addon/ModalWindow/SearchButton')) . '"/>';
echo '</form>';

echo '</body>';
echo '</html>';
6 changes: 5 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@
"bearframework/localization-addon": "1.*",
"bearframework/tasks-addon": "1.*",
"ivopetkov/html5-dom-document-php": "2.*",
"ivopetkov/data-index-bearframework-addon": "1.*"
"ivopetkov/data-index-bearframework-addon": "1.*",
"ivopetkov/client-packages-bearframework-addon": "1.*",
"ivopetkov/modal-windows-bearframework-addon": "1.*",
"ivopetkov/form-bearframework-addon": "1.*",
"ivopetkov/form-elements-bearframework-addon": "1.*"
},
"require-dev": {
"bearcms/addon-tests": "1.*"
Expand Down
23 changes: 23 additions & 0 deletions dev/search.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Search box element addon for Bear CMS
* https://github.com/bearcms/search-box-element-addon
* Copyright (c) Amplilabs Ltd.
* Free to use under the MIT license.
*/

/* global clientPackages */

var bearCMS = bearCMS || {};
bearCMS.search = bearCMS.search || (function () {

var open = function () {
clientPackages.get('modalWindows').then(function (modalWindows) {
modalWindows.open('-bearcms-search-input');
});
};

return {
'open': open
};

}());
20 changes: 20 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,26 @@
]);
};

$app->clientPackages
->add('-bearcms-search', function (IvoPetkov\BearFrameworkAddons\ClientPackage $package) {
//$js = file_get_contents(__DIR__ . '/dev/search.js');
$js = include __DIR__ . '/assets/search.min.js.php';
$package->addJSCode($js);
$package->embedPackage('modalWindows');
});

$app->modalWindows
->add('-bearcms-search-input', function () use ($app, $context) {
$content = '<component src="form" filename="' . $context->dir . '/components/searchWindowForm.php" mode="preview"/>';
$content = $app->components->process($content);
$content = $app->clientPackages->process($content);
return [
'title' => __('bearcms/search-box-element-addon/ModalWindow/Title'),
'content' => $content,
'width' => '400px'
];
});

$app->routes
->add(['/s', '/s/'], [
[$app->bearCMS, 'disabledCheck'],
Expand Down
5 changes: 4 additions & 1 deletion locales/bg.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,8 @@
'bearcms/search-box-element-addon/ButtonTitle' => 'Търси',
'bearcms/search-box-element-addon/page-title' => 'Резултати от търсене на %s',
'bearcms/search-box-element-addon/no-results-found' => 'Не са намерени никакви резултати при търсенето на %s',
'bearcms/search-box-element-addon/building-search-index' => 'Търсачката в момента не работи. Моля, опитайте отново след няколко минути.'
'bearcms/search-box-element-addon/building-search-index' => 'Търсачката в момента не работи. Моля, опитайте отново след няколко минути.',
'bearcms/search-box-element-addon/ModalWindow/Title' => 'Търсене в съдържанието на сайта',
'bearcms/search-box-element-addon/ModalWindow/SearchHint' => 'Търсене ...',
'bearcms/search-box-element-addon/ModalWindow/SearchButton' => 'Намери',
];
5 changes: 4 additions & 1 deletion locales/en.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,8 @@
'bearcms/search-box-element-addon/ButtonTitle' => 'Search',
'bearcms/search-box-element-addon/page-title' => 'Search results for %s',
'bearcms/search-box-element-addon/no-results-found' => 'No results found while searching for %s',
'bearcms/search-box-element-addon/building-search-index' => 'The search is currently not available. Please try again in few minutes.'
'bearcms/search-box-element-addon/building-search-index' => 'The search is currently not available. Please try again in few minutes.',
'bearcms/search-box-element-addon/ModalWindow/Title' => 'Search the site\'s content',
'bearcms/search-box-element-addon/ModalWindow/SearchHint' => 'Search ...',
'bearcms/search-box-element-addon/ModalWindow/SearchButton' => 'Search',
];

0 comments on commit cb84032

Please sign in to comment.