candy-chat / candy

JavaScript-based multi-user chat client for XMPP.
http://candy-chat.github.io/candy
MIT License
1.32k stars 370 forks source link

Remove autofocus #360

Closed arnaud closed 9 years ago

arnaud commented 9 years ago

We embed the candy chat client in a forum website, and the autofocus is very painful for us to say the least. Is there a way to deactivate autofocus so that the browser won't scroll automatically upon each and every navigation?

benlangfeld commented 9 years ago

Could you explain exactly what you mean by autofocus?

arnaud commented 9 years ago

By autofocus, I refer to the following behavior: when my webpage has finished loading, the cursor is automatically set in the message input field (#candy .message-form [name="message"]) of the Candy view.

Now imagine you embed your candy view at the very bottom of your webpage. When you open the webpage and it finished loading, your browser will automatically scroll to the very bottom, and focus the message field.

mweibel commented 9 years ago

Before initializing Candy, add the following two lines in your html file:

Candy.View.Pane.Window.onFocus = function() {};
Candy.View.Pane.Window.onBlur = function() {};
arnaud commented 9 years ago

Thanks for the quick answer. However the proposed solution didn't work:

Candy.View.Pane.Window.onFocus = function() { console.debug("onFocus", this) };
Candy.View.Pane.Window.onBlur = function() { console.debug("onBlur", this) };
Candy.init(...);
Candy.Core.connect(...);

The behavior was still the same (autofocus still on), and my console did not mention anything upon loading. Suggesting that these methods were not triggered.

What works for me though, on both FF and Chrome is:

Candy.View.Pane.Room.setFocusToForm = function() {};

Cheers