diff --git a/src/DOM/HTML/Selection.js b/src/DOM/HTML/Selection.js
new file mode 100644
index 0000000..671e8ac
--- /dev/null
+++ b/src/DOM/HTML/Selection.js
@@ -0,0 +1,154 @@
+"use strict";
+
+exports.anchorNode = function (selection) {
+ return function () {
+ return selection.anchorNode;
+ };
+};
+
+exports.anchorOffset = function (selection) {
+ return function () {
+ return selection.anchorOffset;
+ };
+};
+
+exports.focusNode = function (selection) {
+ return function () {
+ return selection.focusNode;
+ };
+};
+
+exports.focusOffset = function (selection) {
+ return function () {
+ return selection.focusOffset;
+ };
+};
+
+exports.isCollapsed = function (selection) {
+ return function () {
+ return selection.isCollapsed;
+ };
+};
+
+exports.rangeCount = function (selection) {
+ return function () {
+ return selection.rangeCount;
+ };
+};
+
+exports.typeImpl = function (selection) {
+ return function () {
+ return selection.type;
+ };
+};
+
+exports.getRangeAt = function (index) {
+ return function (selection) {
+ return function () {
+ return selection.getRangeAt(index);
+ };
+ };
+};
+
+exports.collapse = function (parentNode) {
+ return function (offset) {
+ return function (selection) {
+ return function () {
+ selection.collapse(parentNode, offset);
+ };
+ };
+ };
+};
+
+exports.extend = function (parentNode) {
+ return function (offset) {
+ return function (selection) {
+ return function () {
+ selection.extend(parentNode, offset);
+ };
+ };
+ };
+};
+
+exports.collapseToStart = function (selection) {
+ return function () {
+ selection.collapseToStart();
+ };
+};
+
+exports.collapseToEnd = function (selection) {
+ return function () {
+ selection.collapseToEnd();
+ };
+};
+
+exports.selectAllChildren = function (parentNode) {
+ return function (selection) {
+ return function () {
+ selection.selectAllChildren(parentNode);
+ };
+ };
+};
+
+exports.addRange = function (range) {
+ return function (selection) {
+ return function () {
+ selection.addRange(range);
+ };
+ };
+};
+
+exports.removeRange = function (range) {
+ return function (selection) {
+ return function () {
+ selection.removeRange(range);
+ };
+ };
+};
+
+exports.removeAllRanges = function (selection) {
+ return function () {
+ selection.removeAllRanges();
+ };
+};
+
+exports.deleteFromDocument = function (selection) {
+ return function () {
+ selection.deleteFromDocument();
+ };
+};
+
+exports.toString = function (selection) {
+ return function () {
+ return selection.toString();
+ };
+};
+
+exports.containsNode = function (aNode) {
+ return function (aPartlyContained) {
+ return function (selection) {
+ return function () {
+ return selection.containsNode(aNode, aPartlyContained);
+ };
+ };
+ };
+};
+
+exports.setBaseAndExtent = function (anchorNode) {
+ return function (anchorOffset) {
+ return function (focusNode) {
+ return function (focusOffset) {
+ return function (selection) {
+ return function () {
+ selection.setBaseAndExtent(
+ anchorNode,
+ anchorOffset,
+ focusNode,
+ focusOffset
+ );
+ };
+ };
+ };
+ };
+ };
+};
diff --git a/src/DOM/HTML/Selection.purs b/src/DOM/HTML/Selection.purs
new file mode 100644
index 0000000..0f26b94
--- /dev/null
+++ b/src/DOM/HTML/Selection.purs
@@ -0,0 +1,149 @@
+module DOM.HTML.Selection
+ ( SelectionType
+ , anchorNode
+ , anchorOffset
+ , focusNode
+ , focusOffset
+ , isCollapsed
+ , rangeCount
+ , type_
+ ) where
+
+import Prelude
+import Control.Monad.Eff (Eff)
+import DOM (DOM)
+import DOM.HTML.Types (Range, SELECTION, Selection)
+import DOM.Node.Types (Node)
+import Data.Maybe (Maybe(..), fromJust)
+import Partial.Unsafe (unsafePartial)
+
+foreign import anchorNode
+ :: forall eff
+ . Selection
+ -> Eff (selection :: SELECTION | eff) Node
+
+foreign import anchorOffset
+ :: forall eff
+ . Selection
+ -> Eff (selection :: SELECTION | eff) Int
+
+foreign import focusNode
+ :: forall eff
+ . Selection
+ -> Eff (selection :: SELECTION | eff) Node
+
+foreign import focusOffset
+ :: forall eff
+ . Selection
+ -> Eff (selection :: SELECTION | eff) Int
+
+foreign import isCollapsed
+ :: forall eff
+ . Selection
+ -> Eff (selection :: SELECTION | eff) Boolean
+
+foreign import rangeCount
+ :: forall eff
+ . Selection
+ -> Eff (selection :: SELECTION | eff) Int
+
+foreign import typeImpl
+ :: forall eff
+ . Selection
+ -> Eff (selection :: SELECTION | eff) String
+
+type_
+ :: forall eff
+ . Selection
+ -> Eff (selection :: SELECTION | eff) SelectionType
+type_ = unsafePartial $ typeImpl >=> pure <<< fromJust <<< toSelectionType
+
+data SelectionType
+ = None
+ | Caret
+ | Range
+
+toSelectionType :: String -> Maybe SelectionType
+toSelectionType "None" = Just None
+toSelectionType "Caret" = Just Caret
+toSelectionType "Range" = Just Range
+toSelectionType _ = Nothing
+
+foreign import getRangeAt
+ :: forall eff
+ . Int
+ -> Selection
+ -> Eff (selection :: SELECTION | eff) Range
+
+foreign import collapse
+ :: forall eff
+ . Node
+ -> Int
+ -> Selection
+ -> Eff (selection :: SELECTION | eff) Unit
+
+foreign import extend
+ :: forall eff
+ . Node
+ -> Int
+ -> Selection
+ -> Eff (selection :: SELECTION | eff) Unit
+
+foreign import collapseToStart
+ :: forall eff
+ . Selection
+ -> Eff (selection :: SELECTION | eff) Unit
+
+foreign import collapseToEnd
+ :: forall eff
+ . Selection
+ -> Eff (selection :: SELECTION | eff) Unit
+
+foreign import selectAllChildren
+ :: forall eff
+ . Node
+ -> Selection
+ -> Eff (selection :: SELECTION | eff) Unit
+
+foreign import addRange
+ :: forall eff
+ . Range
+ -> Selection
+ -> Eff (selection :: SELECTION | eff) Unit
+
+foreign import removeRange
+ :: forall eff
+ . Range
+ -> Selection
+ -> Eff (selection :: SELECTION | eff) Unit
+
+foreign import removeAllRanges
+ :: forall eff
+ . Selection
+ -> Eff (selection :: SELECTION | eff) Unit
+
+foreign import deleteFromDocument
+ :: forall eff
+ . Selection
+ -> Eff (dom :: DOM, selection :: SELECTION | eff) Unit
+
+foreign import toString
+ :: forall eff
+ . Selection
+ -> Eff (selection :: SELECTION | eff) String
+
+foreign import containsNode
+ :: forall eff
+ . Node
+ -> Boolean
+ -> Selection
+ -> Eff (selection :: SELECTION | eff) Boolean
+
+foreign import setBaseAndExtent
+ :: forall eff
+ . Node
+ -> Int
+ -> Node
+ -> Int
+ -> Selection
+ -> Eff (selection :: SELECTION | eff) Unit
diff --git a/src/DOM/HTML/Types.purs b/src/DOM/HTML/Types.purs
index b7f8d04..13594b7 100644
--- a/src/DOM/HTML/Types.purs
+++ b/src/DOM/HTML/Types.purs
@@ -3,12 +3,15 @@ module DOM.HTML.Types
( Navigator
, Location
, History
+ , Range
+ , Selection
, URL
, Window
, ALERT
, CONFIRM
, HISTORY
, PROMPT
+ , SELECTION
, WINDOW
, windowToEventTarget
, HTMLDocument
@@ -232,6 +235,10 @@ foreign import data Window :: Type
foreign import data History :: Type
+foreign import data Range :: Type
+
+foreign import data Selection :: Type
+
foreign import data URL :: Type
foreign import data ALERT :: Effect
@@ -242,6 +249,8 @@ foreign import data PROMPT :: Effect
foreign import data CONFIRM :: Effect
+foreign import data SELECTION :: Effect
+
foreign import data WINDOW :: Effect
windowToEventTarget :: Window -> EventTarget
diff --git a/src/DOM/HTML/Window.js b/src/DOM/HTML/Window.js
index 202f400..573ed0e 100644
--- a/src/DOM/HTML/Window.js
+++ b/src/DOM/HTML/Window.js
@@ -235,3 +235,9 @@ exports._cancelIdleCallback = function(id) {
};
};
};
+
+exports.getSelection = function (window) {
+ return function () {
+ return window.getSelection();
+ };
+};
diff --git a/src/DOM/HTML/Window.purs b/src/DOM/HTML/Window.purs
index 72462e3..ca021bb 100644
--- a/src/DOM/HTML/Window.purs
+++ b/src/DOM/HTML/Window.purs
@@ -36,7 +36,7 @@ module DOM.HTML.Window
import Control.Monad.Eff (Eff)
import DOM (DOM)
-import DOM.HTML.Types (ALERT, CONFIRM, HISTORY, HTMLDocument, History, Location, Navigator, PROMPT, WINDOW, Window, URL)
+import DOM.HTML.Types (ALERT, CONFIRM, HISTORY, HTMLDocument, History, Location, Navigator, PROMPT, SELECTION, Selection, WINDOW, Window, URL)
import DOM.WebStorage.Types (Storage)
import Data.Maybe (Maybe)
import Data.Nullable (Nullable, toMaybe)
@@ -143,3 +143,5 @@ foreign import _cancelIdleCallback :: forall eff. Int -> Window -> Eff (dom :: D
cancelIdleCallback :: forall eff. RequestIdleCallbackId -> Window -> Eff (dom :: DOM | eff) Unit
cancelIdleCallback idAF = _cancelIdleCallback (unwrap idAF)
+
+foreign import getSelection :: forall eff. Window -> Eff (selection :: SELECTION | eff) Selection