Skip to content

Commit 54ab9f1

Browse files
committed
adding initial CSSOM
1 parent 910aa12 commit 54ab9f1

File tree

9 files changed

+154
-1
lines changed

9 files changed

+154
-1
lines changed

bower.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,8 @@
1313
"output",
1414
"bower.json",
1515
"package.json"
16-
]
16+
],
17+
"dependencies": {
18+
"purescript-web-dom": "^1.0.0"
19+
}
1720
}

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,8 @@
99
"pulp": "^12.3.0",
1010
"purescript-psa": "^0.7.2",
1111
"rimraf": "^2.6.2"
12+
},
13+
"dependencies": {
14+
"purescript": "^0.12.0"
1215
}
1316
}

src/Web/CSSOM.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Web.CSSOM
2+
"use strict";
3+
4+
exports.getStyleSheets = function(doc) {
5+
return function() {
6+
return doc.styleSheets;
7+
};
8+
};

src/Web/CSSOM.purs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module Web.CSSOM
2+
( getStyleSheets
3+
) where
4+
5+
import Effect (Effect)
6+
import Web.CSSOM.Internal.Types (StyleSheetList)
7+
import Web.DOM.Document (Document)
8+
9+
foreign import getStyleSheets :: Document -> Effect StyleSheetList

src/Web/CSSOM/CSSStyleSheet.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
"use strict";
2+
3+
var getProp = function(name) {
4+
return function(sheet) {
5+
return sheet[name];
6+
};
7+
};
8+
9+
exports.disabled = getProp("disabled");
10+
exports._href = getProp("href");
11+
exports._ownerNode = getProp("ownerNode");
12+
exports._parentStyleSheet = getProp("parentStyleSheet");
13+
exports._title = getProp("title");
14+
exports._type = getProp("type");
15+
16+
exports.setDisabled = function(bool) {
17+
return function(sheet) {
18+
return function() {
19+
sheet.disabled = bool;
20+
return {};
21+
};
22+
};
23+
};
24+
25+
exports.toggleDisabled = function(sheet) {
26+
return function() {
27+
var bool = !sheet.disabled;
28+
sheet.disabled = bool;
29+
return bool;
30+
};
31+
};

src/Web/CSSOM/CSSStyleSheet.purs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
module Web.DOM.CSSStyleSheet
2+
( module Exports
3+
, disabled
4+
, setDisabled
5+
, toggleDisabled
6+
, href
7+
, ownerNode
8+
, parentStyleSheet
9+
, title
10+
, typeString
11+
) where
12+
13+
import Prelude
14+
15+
import Data.Maybe (Maybe)
16+
import Data.Nullable (Nullable, toMaybe)
17+
import Effect (Effect)
18+
import Web.CSSOM.Internal.Types (CSSStyleSheet) as Exports
19+
import Web.CSSOM.Internal.Types (CSSStyleSheet)
20+
import Web.DOM.Internal.Types (Element)
21+
22+
foreign import disabled :: CSSStyleSheet -> Boolean
23+
24+
foreign import setDisabled :: Boolean -> CSSStyleSheet -> Effect Unit
25+
26+
foreign import toggleDisabled :: CSSStyleSheet -> Effect Boolean
27+
28+
href :: CSSStyleSheet -> Maybe String
29+
href = toMaybe <<< _href
30+
31+
ownerNode :: CSSStyleSheet -> Maybe Element
32+
ownerNode = toMaybe <<< _ownerNode
33+
34+
parentStyleSheet :: CSSStyleSheet -> Maybe CSSStyleSheet
35+
parentStyleSheet = toMaybe <<< _parentStyleSheet
36+
37+
title :: CSSStyleSheet -> Maybe String
38+
title = toMaybe <<< _title
39+
40+
typeString :: CSSStyleSheet -> Maybe String
41+
typeString = toMaybe <<< _type
42+
43+
foreign import _href :: CSSStyleSheet -> Nullable String
44+
foreign import _ownerNode :: CSSStyleSheet -> Nullable Element
45+
foreign import _parentStyleSheet :: CSSStyleSheet -> Nullable CSSStyleSheet
46+
foreign import _title :: CSSStyleSheet -> Nullable String
47+
foreign import _type :: CSSStyleSheet -> Nullable String

src/Web/CSSOM/Internal/Types.purs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module Web.CSSOM.Internal.Types where
2+
3+
foreign import data CSSStyleSheet :: Type
4+
foreign import data StyleSheetList :: Type

src/Web/CSSOM/StyleSheetList.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"use strict";
2+
3+
exports.length = function (list) {
4+
return function () {
5+
return list.length;
6+
};
7+
};
8+
9+
exports.toArray = function (list) {
10+
return function () {
11+
return Array.prototype.slice.call(list);
12+
};
13+
};
14+
15+
exports._item = function(index) {
16+
return function(list) {
17+
return function() {
18+
return list.item(index);
19+
};
20+
};
21+
};

src/Web/CSSOM/StyleSheetList.purs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
module Web.DOM.StyleSheetList
2+
( module Exports
3+
, length
4+
, item
5+
, toArray
6+
) where
7+
8+
import Prelude
9+
10+
import Data.Maybe (Maybe)
11+
import Data.Nullable (Nullable, toMaybe)
12+
import Effect (Effect)
13+
import Web.CSSOM.Internal.Types (CSSStyleSheet, StyleSheetList) as Exports
14+
import Web.CSSOM.Internal.Types (CSSStyleSheet, StyleSheetList)
15+
16+
-- | The number of items in a StyleSheetList.
17+
foreign import length :: StyleSheetList -> Effect Int
18+
19+
-- | The elements of a NodeList represented in an array.
20+
foreign import toArray :: StyleSheetList -> Effect (Array CSSStyleSheet)
21+
22+
-- | The item in a StyleSheetList at the specified index, or Nothing if no such
23+
-- | node exists.
24+
item :: Int -> StyleSheetList -> Effect (Maybe CSSStyleSheet)
25+
item i = map toMaybe <<< _item i
26+
27+
foreign import _item :: Int -> StyleSheetList -> Effect (Nullable CSSStyleSheet)

0 commit comments

Comments
 (0)