Access a view's isVisible property


(cpradio) #1

I want to access the search view’s isVisible property, how would I do that?

I’m trying to determine if the following view is currently visible so I can handle a second CTRL + F call properly…

Then again, maybe I’m going about this the wrong way… (as I could do it in jQuery, but I recall a recent conversation with @eviltrout about utilizing Ember/Controllers/Views for the shortcuts instead of selectors on the page) so feel free to point me in the right direction too :smile:


(lid) #2

The jQuery way
$(’#search-dropdown’).is(’:visible’);

The jQuery approach is already being used in the code

$("#notifications-dropdown").is(":visible");

###the right direction
What you are actually looking for is

Discourse.container.lookup(“controller:header”).get(“visibleDropdown”)
or
var dropdown = this.get(‘controllers.header.visibleDropdown’);

it will return null if no dropdown is open or the name of the open dropdown
for example ‘search-dropdown’


And this is where the property visibleDropdown of the header view is being maintained


(cpradio) #3

Awesome. Thank you! I knew I was going up the wrong code path yesterday evening trying to figure out how to do this… I kept looking in the search controller, search views, etc and then ended up in the Discourse.View, which ultimately extended the Ember.View, so I knew I was missing something.

Cool, I’ll be able to move forward with that request later today then! :smile:


(Robin Ward) #4

What I would suggest is adding a method to the search controller for toggling the search.

And rather than implementing showSearch in the Keyboard code as a click on an element, it would instead call that method. Let the search controller be concerned over whether it’s visible or not and needs to hide, etc.

(BTW using the container is generally bad but it’s better than clicking elements in this case. And if we restrict it to just sending the odd signal it makes it easier for refactoring later)

  showSearch: function(selectContext) {    
     Discourse.__container__.lookup('controller:search').toggleSearch(selectContext);
     return false;
  },

(cpradio) #5

The problem is, I can’t just leave it to the controller for this case, as I need to stop the return false and permit the shortcut to also pass through to the browser to get its native binding executed. So, I have to have a way that gives me feedback so I know if return false is necessary (it is the first call to the binding), or if it should be return true (it is the second call to the binding – to close the search and show the native find control).

It is getting more complicated and might not be a good attempt for me at this stage…