Skip to content
This repository was archived by the owner on Oct 4, 2020. It is now read-only.

Commit 7b6bd8a

Browse files
authored
Merge pull request #60 from purescript-contrib/scroll-props
Add some CSSOM scroll properties for elements
2 parents d1d6bcd + 2b75417 commit 7b6bd8a

File tree

5 files changed

+141
-1
lines changed

5 files changed

+141
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ bower install purescript-dom
1717

1818
`purescript-dom` is intended to provide a common base for projects that need to talk to or about the DOM.
1919

20-
The API isn't primarily intended for "human consumption", but instead aims to provide functions and types that match up with the interfaces described in the [DOM4](http://www.w3.org/TR/dom/) and [HTML5](http://www.w3.org/TR/html5/) specifications, with a minimal amount of additional opinion as to how they should be implemented in PureScript.
20+
The API isn't primarily intended for "human consumption", but instead aims to provide functions and types that match up with the interfaces described in the [DOM4](http://www.w3.org/TR/dom/), [HTML5](http://www.w3.org/TR/html5/), and [CSSOM](https://www.w3.org/TR/cssom-view-1/) specifications, with a minimal amount of additional opinion as to how they should be implemented in PureScript.
2121

2222
This consists of:
2323
- `foreign data` types for the various interfaces described.

src/DOM/HTML/HTMLElement.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,3 +199,41 @@ exports.setSpellcheck = function (spellcheck) {
199199
};
200200
};
201201
};
202+
203+
// - CSSOM ---------------------------------------------------------------------
204+
205+
exports.getBoundingClientRect = function (el) {
206+
return function () {
207+
return el.getBoundingClientRect();
208+
};
209+
};
210+
211+
exports.offsetParent = function (el) {
212+
return function () {
213+
return el.offsetParent;
214+
};
215+
};
216+
217+
exports.offsetTop = function (el) {
218+
return function () {
219+
return el.offsetTop;
220+
};
221+
};
222+
223+
exports.offsetLeft = function (el) {
224+
return function () {
225+
return el.offsetLeft;
226+
};
227+
};
228+
229+
exports.offsetWidth = function (el) {
230+
return function () {
231+
return el.offsetWidth;
232+
};
233+
};
234+
235+
exports.offsetHeight = function (el) {
236+
return function () {
237+
return el.offsetHeight;
238+
};
239+
};

src/DOM/HTML/HTMLElement.purs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ module DOM.HTML.HTMLElement where
22

33
import Prelude
44
import Control.Monad.Eff (Eff)
5+
import Data.Nullable (Nullable)
56
import DOM (DOM)
67
import DOM.HTML.Types (HTMLElement)
8+
import DOM.Node.Types (Element)
79

810
foreign import title :: forall eff. HTMLElement -> Eff (dom :: DOM | eff) String
911
foreign import setTitle :: forall eff. String -> HTMLElement -> Eff (dom :: DOM | eff) Unit
@@ -36,3 +38,22 @@ foreign import setSpellcheck :: forall eff. Boolean -> HTMLElement -> Eff (dom :
3638
foreign import click :: forall eff. HTMLElement -> Eff (dom :: DOM | eff) Unit
3739
foreign import focus :: forall eff. HTMLElement -> Eff (dom :: DOM | eff) Unit
3840
foreign import blur :: forall eff. HTMLElement -> Eff (dom :: DOM | eff) Unit
41+
42+
foreign import getBoundingClientRect
43+
:: forall eff
44+
. HTMLElement
45+
-> Eff
46+
(dom :: DOM | eff)
47+
{ left :: Number
48+
, top :: Number
49+
, right :: Number
50+
, bottom :: Number
51+
, width :: Number
52+
, height :: Number
53+
}
54+
55+
foreign import offsetParent :: forall eff. HTMLElement -> Eff (dom :: DOM | eff) (Nullable Element)
56+
foreign import offsetTop :: forall eff. HTMLElement -> Eff (dom :: DOM | eff) Number
57+
foreign import offsetLeft :: forall eff. HTMLElement -> Eff (dom :: DOM | eff) Number
58+
foreign import offsetWidth :: forall eff. HTMLElement -> Eff (dom :: DOM | eff) Number
59+
foreign import offsetHeight :: forall eff. HTMLElement -> Eff (dom :: DOM | eff) Number

src/DOM/Node/Element.js

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,71 @@ exports.removeAttribute = function (name) {
9494
};
9595
};
9696
};
97+
98+
// - CSSOM ---------------------------------------------------------------------
99+
100+
exports.scrollTop = function (node) {
101+
return function () {
102+
return node.scrollTop;
103+
};
104+
};
105+
106+
exports.setScrollTop = function (scrollTop) {
107+
return function (node) {
108+
return function () {
109+
node.scrollTop = scrollTop;
110+
return {};
111+
};
112+
};
113+
};
114+
115+
exports.scrollLeft = function (node) {
116+
return function () {
117+
return node.scrollLeft;
118+
};
119+
};
120+
121+
exports.setScrollLeft = function (scrollLeft) {
122+
return function (node) {
123+
return function () {
124+
node.scrollLeft = scrollLeft;
125+
return {};
126+
};
127+
};
128+
};
129+
130+
exports.scrollWidth = function (el) {
131+
return function () {
132+
return el.scrollWidth;
133+
};
134+
};
135+
136+
exports.scrollHeight = function (el) {
137+
return function () {
138+
return el.scrollHeight;
139+
};
140+
};
141+
142+
exports.clientTop = function (el) {
143+
return function () {
144+
return el.clientTop;
145+
};
146+
};
147+
148+
exports.clientLeft = function (el) {
149+
return function () {
150+
return el.clientLeft;
151+
};
152+
};
153+
154+
exports.clientWidth = function (el) {
155+
return function () {
156+
return el.clientWidth;
157+
};
158+
};
159+
160+
exports.clientHeight = function (el) {
161+
return function () {
162+
return el.clientHeigh;
163+
};
164+
};

src/DOM/Node/Element.purs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,16 @@ foreign import getElementsByClassName :: forall eff. String -> Element -> Eff (d
2323
foreign import setAttribute :: forall eff. String -> String -> Element -> Eff (dom :: DOM | eff) Unit
2424
foreign import getAttribute :: forall eff. String -> Element -> Eff (dom :: DOM | eff) (Nullable String)
2525
foreign import removeAttribute :: forall eff. String -> Element -> Eff (dom :: DOM | eff) Unit
26+
27+
foreign import scrollTop :: forall eff. Element -> Eff (dom :: DOM | eff) Number
28+
foreign import setScrollTop :: forall eff. Element -> Number -> Eff (dom :: DOM | eff) Unit
29+
30+
foreign import scrollLeft :: forall eff. Element -> Eff (dom :: DOM | eff) Number
31+
foreign import setScrollLeft :: forall eff. Element -> Number -> Eff (dom :: DOM | eff) Unit
32+
33+
foreign import scrollWidth :: forall eff. Element -> Eff (dom :: DOM | eff) Number
34+
foreign import scrollHeight :: forall eff. Element -> Eff (dom :: DOM | eff) Number
35+
foreign import clientTop :: forall eff. Element -> Eff (dom :: DOM | eff) Number
36+
foreign import clientLeft :: forall eff. Element -> Eff (dom :: DOM | eff) Number
37+
foreign import clientWidth :: forall eff. Element -> Eff (dom :: DOM | eff) Number
38+
foreign import clientHeight :: forall eff. Element -> Eff (dom :: DOM | eff) Number

0 commit comments

Comments
 (0)