Skip to content

Commit

Permalink
first shot at onresize
Browse files Browse the repository at this point in the history
  • Loading branch information
ggreif committed Jul 9, 2018
1 parent f5413b3 commit 61910cd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 6 additions & 0 deletions js/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ Haskell.on = function (el, eventType, fun) {
fun(e.keyCode);
return true;
});
} else if(eventType === 'resize') {
window.onresize = function(e) {
var t = e.target;
fun([t.innerWidth, t.innerHeight]);
return true;
};
} else {
$(el).on(eventType, function(e) {
fun(e.which ? [e.which.toString()] : e.detail || []);
Expand Down
7 changes: 6 additions & 1 deletion src/Graphics/UI/Threepenny/Events.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module Graphics.UI.Threepenny.Events (
-- * Standard DOM events
click, contextmenu, mousemove, mousedown, mouseup,
hover, leave,
focus, blur,
focus, blur, resize,
KeyCode, keyup, keydown,
) where

Expand Down Expand Up @@ -87,6 +87,11 @@ focus = silence . domEvent "focus"
blur :: Element -> Event ()
blur = silence . domEvent "blur"

-- | Element reports its window's resize.
-- Note that there should only be at most one
-- 'resize' event registered.
resize :: Element -> Event (Int,Int)
resize = fmap readCoordinates . domEvent "resize"

type KeyCode = Int

Expand Down

0 comments on commit 61910cd

Please sign in to comment.