Header Search Theme

theme-component

(Angus McLeod) #1

Repository: GitHub - angusmcleod/discourse-header-search-theme

This is a re-packaging of the Header Search Plugin so it can be used as a theme.

The functionality is the same as the plugin.

See further:


Moving the discourse search box and making it functional - how?
How difficult would it be to make the Discourse UI more like Flarum?
Header search plugin
Making the search box "more obvious"
Is there a way to add search in content area?
Header search plugin
Header search plugin
How difficult would it be to make the Discourse UI more like Flarum?
(Daniela) #2

Which version of Discourse supports this theme?

I’m still on v 1.9.0.beta4 and this theme does not work because of APIs (version not supported):

If it is your intention that this theme only works from v 1.9.0.beta5 and higher please add this info to the OP. :wink:

BTW changing the script from version='0.8.9' to version='0.8' works, at least on beta 4.


(Daniela) #3

Hi @angus, I found out that my forum is not loaded on Internet Explorer (works with Firefox, Chrome Opera and Edge).

After a lot of rebuild
I found out that the problem seems to come from this theme.

When I disable it from my default theme the forum is loaded normally.

Does anyone who uses this theme can see if their site is loaded on IE, please?


(Angus McLeod) #4

IE still doesn’t support Object.keys? Ok I’m downloading a few IE vms to do some more thorough testing…


(Angus McLeod) #5

@Trash @bombledmonk Fixed for IE 11 :sunny:

Note: To test Discourse on IE on Mac:

  1. dl the relevant IE vm here.
  2. Load vm into VirtualBox and start it.
  3. Run Discourse at localhost:3000 on the host (i.e. your normal browser).
  4. Open IE in the virtual guest and navigate to http://10.0.2.2:3000/ and your local instance will load.

There’s no need to edit the C:\windows\system32\drivers\etc\hosts file on the guest.


(Daniela) #6

Thank you master :wink:, it works now on Windows.


(Anders Thengs Kristensen) #7

I was wondering if it would be possible to make the search bar be on the right, beside the hamburger menu, instead of having it beside the icon?


(Angus McLeod) #8

It’s not possible to use settings in a theme, so you will need to apply css via the site customizer or fork the theme. It should be doable with css. I can take a look at what css would be required on Sunday, unless you want to take a look sooner.


(Angus McLeod) #9

A little late, but here’s the css if you want the search bar to appear on the right of the header instead of the left. Add it in Admin > Customize.

.header-search-enabled .contents {
   display: flex;
   justify-content: space-between;
    
   &:before, &:after {
     display: none;
   }
    
   .title {
     flex: 1 1 auto;
   }
    
   .search-header {
     float: right;
     margin-left: 0;
     margin-right: 10px;
   }
    
   .search-input {
     float: right;
     margin-left: 10px;
     margin-right: 0;
   }
    
   .search-context {
     padding-top: 5px;
     float: right;
   }

   .results {
     right: 0;
   }
}

You’ll, need to update to the latest for it to work properly.

The same CSS will also work for the Header Search Plugin.

See e.g. https://discourse.angusmcleod.com.au/


(Daniela) #10

@angus, the search icon is visible when you open the site (even if it does not work) and disappears when you open a topic or click on the search bar in the header.

I seem to remember that it also happened in the plugin and you had already made a fix.


(Angus McLeod) #11

hm. I did apply the same fix to the theme at the time.

Are you sure your theme is up to date?

I’m using the theme in my sandbox and it seems to be working ok.

Does it always happen, or only sometimes?


(Daniela) #12

Oh damn, you are right.
I never remember that the themes should be updated manually…my bad :flushed:


(Anders Thengs Kristensen) #13

If you have the header search bar up and slowly shrink the width of the browser, there will come a point where the hamburger menu is moved above the user avatar if the search bar is aligned right:


and the hamburger menu and user avatar is moved slightly down if the bar is in it’s default position:


(Angus McLeod) #14

The theme automatically hides the search bar when the header becomes too small to contain it + the logo + the right icons. I had to increase the absolute width of the search bar to properly handle right alignment which threw that calculation off. The search bar should now disappear and the search icon re-appear in that scenario.


(Angus McLeod) #15

I’ve tweaked the size calculation logic here so that you can arbitrarily set the width of the header-search using css and the show hide behaviour will respond accordingly. This helps those with wide site logos.

The default width of the search-header contains, which holds both the search input and the contextual search options, is 600px.

This was an issue for sites with wide logos, as there wasn’t enough space to fit the element comfortably (particularly with the sign up / login buttons on the right).

Now you can add something like this to your custom css.

div.search-header {
    width: 400px;
}

And that new size will be factored into the calculation that determines whether to show / hide the search input when the window is resized.

cc @pradeepkumar


(Pradeep Kumar) #16

Thank you so much @angus, works like a charm! :slight_smile:


(Anders Thengs Kristensen) #17

With the search bar aligned right, the hamburger and and user menu doesn’t connect to the icons:


(Angus McLeod) #18

Fixed: Style tweaks · angusmcleod/discourse-header-search-theme@ab51e85 · GitHub

I’ve made a slight change to the right alignment css, so please re-copy / paste that.


(Anders Thengs Kristensen) #19

When in a topic, scrolling down until the search icon appears, clicking it and scrolling back up will make it so that there are two search bars on the screen at the same time. (Some times there’s a delay before the header search bar appears)


(Angus McLeod) #20

I think I did that part of that intentionally, the idea being that if you have one search open already, it would be jarring to have the search input suddenly jump to the header if you happened to scroll up. But it seems to be working imperfectly. I’ll take a look tomorrow.