Comparing version 3.0.2 to 3.1.0
{ | ||
"name": "curse", | ||
"version": "3.0.2", | ||
"version": "3.1.0", | ||
"authors": [ | ||
@@ -5,0 +5,0 @@ "Jonathan Clem <jonathan@jclem.net>" |
@@ -37,24 +37,2 @@ !function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.Curse=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | ||
_prototypeProperties(Curse, null, { | ||
iterator: { | ||
/** | ||
* An iterator to iterate over the nodes in `this.element`. | ||
* | ||
* This returns a simple node iterator that skips `this.element`, but not its | ||
* children. | ||
* | ||
* @property iterator | ||
* @private | ||
* @type {NodeIterator} | ||
*/ | ||
get: function () { | ||
var elem = this.element; | ||
return document.createNodeIterator(this.element, NodeFilter.SHOW_ALL, function onNode(node) { | ||
return node === elem ? NodeFilter.FILTER_SKIP : NodeFilter.FILTER_ACCEPT; | ||
}); | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}, | ||
capture: { | ||
@@ -93,3 +71,3 @@ | ||
child = anchorNode.childNodes[anchorOffset ? anchorOffset - 1 : 0]; | ||
start = this.lengthUpTo(child) + this.nodeLength(child); | ||
start = this.lengthUpTo(child) + this.nodeLength(child, false, true); | ||
} | ||
@@ -101,3 +79,3 @@ | ||
child = focusNode.childNodes[focusOffset ? focusOffset - 1 : 0]; | ||
end = this.lengthUpTo(child) + this.nodeLength(child); | ||
end = this.lengthUpTo(child) + this.nodeLength(child, false, true); | ||
} | ||
@@ -137,3 +115,3 @@ | ||
var end = _ref2.end; | ||
var iter = this.iterator; | ||
var iter = this.getIterator(this.element); | ||
var node = undefined, | ||
@@ -201,2 +179,21 @@ setStart = undefined, | ||
}, | ||
getIterator: { | ||
/** | ||
* Get an iterator to iterate over the child nodes in a given node. | ||
* | ||
* @method getIterator | ||
* @private | ||
* @param {Node} iteratee The node to iterate through the children of | ||
* @return {NodeIterator} | ||
*/ | ||
value: function getIterator(iteratee) { | ||
return document.createNodeIterator(iteratee, NodeFilter.SHOW_ALL, function onNode(node) { | ||
return node === iteratee ? NodeFilter.FILTER_SKIP : NodeFilter.FILTER_ACCEPT; | ||
}); | ||
}, | ||
writable: true, | ||
enumerable: true, | ||
configurable: true | ||
}, | ||
indexOfNode: { | ||
@@ -237,3 +234,3 @@ | ||
var len = 0; | ||
var iter = this.iterator; | ||
var iter = this.getIterator(this.element); | ||
var node = undefined; | ||
@@ -280,5 +277,6 @@ | ||
* @private | ||
* @param {Node} node a Node, typically a Text or HTMLElement node | ||
* @param {Bool} ignoreNodeLengthFn ignore the custom nodeLengthFn | ||
* @return {Number} the length of the node, as text | ||
* @param {Node} node A Node, typically a Text or HTMLElement node | ||
* @param {Bool} ignoreNodeLengthFn Ignore the custom nodeLengthFn | ||
* @param {Bool} recurse Recurse through the node to get its length | ||
* @return {Number} The length of the node, as text | ||
*/ | ||
@@ -288,2 +286,3 @@ value: function nodeLength(node) { | ||
var ignoreNodeLengthFn = arguments[1] === undefined ? false : arguments[1]; | ||
var recurse = arguments[2] === undefined ? false : arguments[2]; | ||
if (this.nodeLengthFn && !ignoreNodeLengthFn) { | ||
@@ -295,3 +294,3 @@ var _ret = (function () { | ||
v: _this.nodeLengthFn(node, function __super() { | ||
return nodeLength(node, true); | ||
return nodeLength(node, true, recurse); | ||
}) | ||
@@ -304,2 +303,15 @@ }; | ||
if (recurse && node.childNodes.length) { | ||
var iter = this.getIterator(node); | ||
var innerLength = 0; | ||
var childNode = undefined; | ||
while (childNode = iter.nextNode()) { | ||
innerLength += this.nodeLength(childNode, ignoreNodeLengthFn, recurse); | ||
} | ||
return innerLength; | ||
} | ||
var charNodes = ["BR", "HR", "IMG"]; | ||
@@ -306,0 +318,0 @@ |
{ | ||
"name": "cursejs", | ||
"description": "A user selection caching utility", | ||
"version": "3.0.2", | ||
"version": "3.1.0", | ||
"author": "Jonathan Clem", | ||
@@ -6,0 +6,0 @@ "bugs": { |
@@ -27,27 +27,2 @@ /** | ||
/** | ||
* An iterator to iterate over the nodes in `this.element`. | ||
* | ||
* This returns a simple node iterator that skips `this.element`, but not its | ||
* children. | ||
* | ||
* @property iterator | ||
* @private | ||
* @type {NodeIterator} | ||
*/ | ||
get iterator() { | ||
let elem = this.element; | ||
return document.createNodeIterator( | ||
this.element, | ||
NodeFilter.SHOW_ALL, | ||
function onNode(node) { | ||
return node === elem ? | ||
NodeFilter.FILTER_SKIP : NodeFilter.FILTER_ACCEPT; | ||
} | ||
); | ||
} | ||
/** | ||
* Captures the current selection in the element, by storing "start" and | ||
@@ -77,3 +52,3 @@ * "end" integer values. This allows for the text and text nodes to change | ||
child = anchorNode.childNodes[anchorOffset ? anchorOffset - 1 : 0]; | ||
start = this.lengthUpTo(child) + this.nodeLength(child); | ||
start = this.lengthUpTo(child) + this.nodeLength(child, false, true); | ||
} | ||
@@ -85,3 +60,3 @@ | ||
child = focusNode.childNodes[focusOffset ? focusOffset - 1 : 0]; | ||
end = this.lengthUpTo(child) + this.nodeLength(child); | ||
end = this.lengthUpTo(child) + this.nodeLength(child, false, true); | ||
} | ||
@@ -113,3 +88,3 @@ | ||
let { start, end } = this; | ||
let iter = this.iterator; | ||
let iter = this.getIterator(this.element); | ||
let node, setStart, setEnd; | ||
@@ -172,2 +147,23 @@ | ||
/** | ||
* Get an iterator to iterate over the child nodes in a given node. | ||
* | ||
* @method getIterator | ||
* @private | ||
* @param {Node} iteratee The node to iterate through the children of | ||
* @return {NodeIterator} | ||
*/ | ||
getIterator(iteratee) { | ||
return document.createNodeIterator( | ||
iteratee, | ||
NodeFilter.SHOW_ALL, | ||
function onNode(node) { | ||
return node === iteratee ? | ||
NodeFilter.FILTER_SKIP : NodeFilter.FILTER_ACCEPT; | ||
} | ||
); | ||
} | ||
/** | ||
* Get the index of a node in its parent node. | ||
@@ -200,3 +196,3 @@ * | ||
let len = 0; | ||
let iter = this.iterator; | ||
let iter = this.getIterator(this.element); | ||
let node; | ||
@@ -233,15 +229,29 @@ | ||
* @private | ||
* @param {Node} node a Node, typically a Text or HTMLElement node | ||
* @param {Bool} ignoreNodeLengthFn ignore the custom nodeLengthFn | ||
* @return {Number} the length of the node, as text | ||
* @param {Node} node A Node, typically a Text or HTMLElement node | ||
* @param {Bool} ignoreNodeLengthFn Ignore the custom nodeLengthFn | ||
* @param {Bool} recurse Recurse through the node to get its length | ||
* @return {Number} The length of the node, as text | ||
*/ | ||
nodeLength(node, ignoreNodeLengthFn = false) { | ||
nodeLength(node, ignoreNodeLengthFn = false, recurse = false) { | ||
if (this.nodeLengthFn && !ignoreNodeLengthFn) { | ||
let nodeLength = this.nodeLength.bind(this); | ||
const nodeLength = this.nodeLength.bind(this); | ||
return this.nodeLengthFn(node, function __super() { | ||
return nodeLength(node, true); | ||
return nodeLength(node, true, recurse); | ||
}); | ||
} | ||
if (recurse && node.childNodes.length) { | ||
const iter = this.getIterator(node); | ||
let innerLength = 0; | ||
let childNode; | ||
while ((childNode = iter.nextNode())) { | ||
innerLength += this.nodeLength(childNode, ignoreNodeLengthFn, recurse); | ||
} | ||
return innerLength; | ||
} | ||
let charNodes = ['BR', 'HR', 'IMG']; | ||
@@ -248,0 +258,0 @@ |
39062
1040