Skip to content

Commit

Permalink
Don't delete event handlers in messages on layout/resize
Browse files Browse the repository at this point in the history
When `layout` was called, it rebuilt the messages area from scratch
using its html.  This resets any event handlers on nodes embedded in
these, so a layout would strip out event handlers from the input box,
including the ones that return the game to its normal state once you're
done with the box.  The result was that you had to reload the browser to
get something playable.  This was triggered by any resize, which in
several browsers (and possibly sensitive to other settings, such as
zoom) can result from a browser find command (10318), especially since
crawl doesn't swallow ctrl-f when the search box was open. A re-layout
is also apparently triggered when a spectator joins (10938).

This fix, instead of rebuilding the messages panel from html, makes a
deep copy of it using jquery `clone`, in a way that preserves event
handlers.  Layout still copies other areas using html, so if anyone ever
adds any event handlers in the stats area, this could come up again.
Supposedly, the html way is faster, so I left this as-is.

(I'm not entirely sure why this would be the best way to do what
`layout` is doing in the first place, but I'll leave that for more
skilled javascript people.)
  • Loading branch information
rawlins committed Apr 27, 2017
1 parent b8e8b7e commit 127e8e2
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions crawl-ref/source/webserver/game_data/static/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,17 @@ function ($, comm, client, dungeon_renderer, display, minimap, enums, messages,
$("#stats").html(old_html);

// Determine height of messages area
old_html = $("#messages").html();

// need to clone this, not copy html, since there can be event handlers
// embedded in here on an input box.
var old_messages = $("#messages").clone(true);
var old_scroll_top = $("#messages_container").scrollTop();
s = "";
for (var i = 0; i < msg_height+1; i++)
s = s + "<br>";
$("#messages").html(s);
var msg_height_px = $("#messages").outerHeight();
$("#messages").html(old_html);
$("#messages").replaceWith(old_messages);
$("#messages_container").scrollTop(old_scroll_top);

var remaining_width = window_width - stat_width_px;
Expand Down

0 comments on commit 127e8e2

Please sign in to comment.