Redirect / for non-logged in users?

Hmmm, how did you do that before? I thought targetUrl was just a parameter?

Thanks a lot Robin - looks great. Only that the snippet you posted just gives me this error:

TypeError: Attempted to assign to readonly property.

or, on Chrome:

Uncaught TypeError: Cannot set property 'href' of undefined

…and makes the whole header disappear.

I guess I’m just missing something here?

Did you get the latest master first? I tried it locally and it worked fine.

That’s the first thing I did before trying it! Is there a special section where I have to put the script code?

Aha it seems the tests-passed branch failed to build due to a failing test. I’m fixing it now.

edit: fixed the test. Give it 15-20 mins and it should have a new version for you.

2 Likes

Sorry, this was done in a hurry :laughing:

  window.goToPortal = function() { 
      if (window.location.href === 'https://example.com.br/forum/') { 
          window.location = 'https://example.com.br';
      }
  };

  var HeaderView = require('discourse/views/header').default

  HeaderView.reopen({
    didInsertElement : function(){
      this._super();
      Ember.run.scheduleOnce('afterRender', this, this.afterRenderEvent);
    },
    afterRenderEvent : function(){
      var logo = $('img#site-logo.logo-big').parent()[0];
    
      logo.addEventListener('click', window.goToPortal, false);
    }
  });

Can you help me @eviltrout ?

Like a charm. Thanks!

Hmmm that is a little complicated to establish in the new settings. Does adding that event work in the case where the url is not https://example.com.br/forum/ ? It seems the click handler would do nothing.

Yes, when the user isn’t at the forum home, I want the normal behavior (scroll up / go back to home).

Only when we are already at the forum home, I want to go back to my Portal home.

It’s quite tricky to do what you’re asking, because once an event is handled from the logo it prevents default.

I’ve added the ability for the href setting to be a function. Whatever value you return will be the destination when the user clicks the logo:

https://github.com/discourse/discourse/commit/1ac6dd194d811d4bb5609562dc52176ce2bdc34f

3 Likes

Should this work?

<script type="text/discourse-plugin" version="0.4">
  api.changeWidgetSetting('home-logo', 'href', function() { 
          return 'https://example.com.br';
  });
</script>

EDIT:

Setting it to ‘/another/page’ when using Discourse under ‘/forum’ also breaks :sadpanda:.

1 Like

This should fix it:

https://github.com/discourse/discourse/commit/4875fe1c3ea3865f4f37fe71fc8358c8c6341a07

5 Likes

I’ll test this later today! Thanks! :heart:

1 Like