-
-
Notifications
You must be signed in to change notification settings - Fork 697
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MODIFY] website_search_header: Improve scalability in js code
- Loading branch information
1 parent
29d5137
commit 12b38d5
Showing
7 changed files
with
176 additions
and
112 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,73 @@ | ||
====================== | ||
Website Search Header | ||
====================== | ||
======================== | ||
Website Search in Header | ||
======================== | ||
|
||
.. | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! source digest: sha256:d16cfb3e2bf08f7b6803f08d17d302e2ee86b04c1e4296db2ea051d1cb3dec43 | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png | ||
:target: https://odoo-community.org/page/development-status | ||
:alt: Beta | ||
.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png | ||
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html | ||
:alt: License: LGPL-3 | ||
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fwebsite-lightgray.png?logo=github | ||
:target: https://github.com/OCA/website/tree/16.0/website_search_header | ||
:alt: OCA/website | ||
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png | ||
:target: https://translation.odoo-community.org/projects/website-16-0/website-16-0-website_search_header | ||
:alt: Translate me on Weblate | ||
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png | ||
:target: https://runboat.odoo-community.org/builds?repo=OCA/website&target_branch=16.0 | ||
:alt: Try me on Runboat | ||
|
||
|badge1| |badge2| |badge3| |badge4| |badge5| | ||
|
||
This module adds a search bar in the header of your website. | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Usage | ||
===== | ||
|
||
On desktop, the user will be able to show and hide the search input in the website header. While on mobile our searchbox will behave by default. | ||
|
||
Credits | ||
======= | ||
|
||
Authors | ||
~~~~~~~ | ||
|
||
* ForgeFlow | ||
* Ooops | ||
|
||
Contributors | ||
~~~~~~~~~~~~ | ||
|
||
* Jordi Ballester <jordi.ballester@forgeflow.com> | ||
* Elmer García <elmer.garcia@forgeflow.com> | ||
|
||
Maintainers | ||
~~~~~~~~~~~ | ||
|
||
This module is maintained by the OCA. | ||
|
||
.. image:: https://odoo-community.org/logo.png | ||
:alt: Odoo Community Association | ||
:target: https://odoo-community.org | ||
|
||
OCA, or the Odoo Community Association, is a nonprofit organization whose | ||
mission is to support the collaborative development of Odoo features and | ||
promote its widespread use. | ||
|
||
This module is part of the `OCA/website <https://github.com/OCA/website/tree/16.0/website_search_header>`_ project on GitHub. | ||
|
||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. |
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
|
||
* ForgeFlow <https://www.forgeflow.com> |
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 @@ | ||
On desktop, the user will be able to show and hide the search input in the website header. While on mobile our searchbox will behave by default. |
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,61 @@ | ||
odoo.define("website_search_header.search_header", function (require) { | ||
"use strict"; | ||
|
||
const publicWidget = require("web.public.widget"); | ||
|
||
publicWidget.registry.SearchHeader = publicWidget.Widget.extend({ | ||
selector: "#div_search_button", | ||
|
||
events: { | ||
"click #search_btn_toggle_search": "_onClickSearchBtn", | ||
}, | ||
|
||
start: function () { | ||
const def = this._super.apply(this, arguments); | ||
this.$boxInput = this.$el.find(".o_search_header"); | ||
return def; | ||
}, | ||
|
||
mobileSearch: function () { | ||
if (!this.$boxInput.hasClass("d-none")) { | ||
this.$boxInput.addClass("d-none"); | ||
} | ||
var searchQuery = document.querySelector("input[name='search']").value; | ||
var encodedQuery = encodeURIComponent(searchQuery); | ||
var searchURL = this._getSearchUrl(encodedQuery); | ||
window.location.href = searchURL; | ||
}, | ||
|
||
desktopSearch: function () { | ||
if ($(".o_search_header").hasClass("d-lg-none")) { | ||
$(".o_search_header").removeClass("d-lg-none"); | ||
$("#search_btn_toggle_search i").removeClass("oi-search"); | ||
$("#search_btn_toggle_search i").addClass("oi-close"); | ||
$("#div_search_header").removeClass("ms-lg-0"); | ||
$("#div_search_button").removeClass("ms-lg-2"); | ||
} else { | ||
$(".o_search_header").addClass("d-lg-none"); | ||
$("#search_btn_toggle_search i").removeClass("oi-close"); | ||
$("#search_btn_toggle_search i").addClass("oi-search"); | ||
$("#div_search_header").addClass("ms-lg-0"); | ||
$("#div_search_button").addClass("ms-lg-2"); | ||
} | ||
}, | ||
|
||
_onClickSearchBtn: function () { | ||
var screenWidth = | ||
window.innerWidth || | ||
document.documentElement.clientWidth || | ||
document.body.clientWidth; | ||
if (screenWidth < 992) { | ||
this.mobileSearch(); | ||
} else { | ||
this.desktopSearch(); | ||
} | ||
}, | ||
|
||
_getSearchUrl: function (encodedQuery) { | ||
return "/website/search?search=" + encodedQuery + "&order=name+asc"; | ||
}, | ||
}); | ||
}); |
Oops, something went wrong.