Skip to content

Commit

Permalink
Minor update for beta version
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliver Pulges committed Aug 18, 2015
1 parent e60e81a commit 66e3f94
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 27 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.textile
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
* wysihtml5x 0.5.0-beta13* (August 18, 2015)
* Fixes node.normalize polyfill failing to restore cursor in some cases

* wysihtml5x 0.5.0-beta12* (July 31, 2015)
* Fixes a many toolbar handling errors
* Fixes formatBlock misbehaviours: in Safari selected content can be lost in some cases, acting on outer div if heading and paragraph elements are contained in div.
Expand Down
19 changes: 15 additions & 4 deletions dist/wysihtml-toolbar.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @license wysihtml v0.5.0-beta12
* @license wysihtml v0.5.0-beta13
* https://github.com/Voog/wysihtml
*
* Author: Christopher Blum (https://github.com/tiff)
Expand All @@ -10,7 +10,7 @@
*
*/
var wysihtml5 = {
version: "0.5.0-beta12",
version: "0.5.0-beta13",

// namespaces
commands: {},
Expand Down Expand Up @@ -405,20 +405,24 @@ var wysihtml5 = {
return all;
};



var normalizeFix = function() {
var f = Node.prototype.normalize;
var nf = function() {
var texts = getTextNodes(this),
s = this.ownerDocument.defaultView.getSelection(),
anode = s.anchorNode,
aoffset = s.anchorOffset,
aelement = anode && anode.nodeType === 1 && anode.childNodes.length > 0 ? anode.childNodes[aoffset] : undefined,
fnode = s.focusNode,
foffset = s.focusOffset,
felement = fnode && fnode.nodeType === 1 && foffset > 0 ? fnode.childNodes[foffset -1] : undefined,
r = this.ownerDocument.createRange(),
prevTxt = texts.shift(),
curText = prevTxt ? texts.shift() : null;

if ((anode === fnode && foffset < aoffset) || (anode !== fnode && (anode.compareDocumentPosition(fnode) & Node.DOCUMENT_POSITION_PRECEDING))) {
if ((anode === fnode && foffset < aoffset) || (anode !== fnode && (anode.compareDocumentPosition(fnode) & Node.DOCUMENT_POSITION_PRECEDING) && !(anode.compareDocumentPosition(fnode) & Node.DOCUMENT_POSITION_CONTAINS))) {
fnode = [anode, anode = fnode][0];
foffset = [aoffset, aoffset = foffset][0];
}
Expand All @@ -442,13 +446,20 @@ var wysihtml5 = {
}
}

if (felement) {
foffset = Array.prototype.indexOf.call(felement.parentNode.childNodes, felement) + 1;
}

if (aelement) {
aoffset = Array.prototype.indexOf.call(aelement.parentNode.childNodes, aelement);
}

if (anode && anode.parentNode && fnode && fnode.parentNode) {
r.setStart(anode, aoffset);
r.setEnd(fnode, foffset);
s.removeAllRanges();
s.addRange(r);
}

};
Node.prototype.normalize = nf;
};
Expand Down
16 changes: 8 additions & 8 deletions dist/wysihtml-toolbar.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/wysihtml-toolbar.min.map

Large diffs are not rendered by default.

19 changes: 15 additions & 4 deletions dist/wysihtml.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @license wysihtml v0.5.0-beta12
* @license wysihtml v0.5.0-beta13
* https://github.com/Voog/wysihtml
*
* Author: Christopher Blum (https://github.com/tiff)
Expand All @@ -10,7 +10,7 @@
*
*/
var wysihtml5 = {
version: "0.5.0-beta12",
version: "0.5.0-beta13",

// namespaces
commands: {},
Expand Down Expand Up @@ -405,20 +405,24 @@ var wysihtml5 = {
return all;
};



var normalizeFix = function() {
var f = Node.prototype.normalize;
var nf = function() {
var texts = getTextNodes(this),
s = this.ownerDocument.defaultView.getSelection(),
anode = s.anchorNode,
aoffset = s.anchorOffset,
aelement = anode && anode.nodeType === 1 && anode.childNodes.length > 0 ? anode.childNodes[aoffset] : undefined,
fnode = s.focusNode,
foffset = s.focusOffset,
felement = fnode && fnode.nodeType === 1 && foffset > 0 ? fnode.childNodes[foffset -1] : undefined,
r = this.ownerDocument.createRange(),
prevTxt = texts.shift(),
curText = prevTxt ? texts.shift() : null;

if ((anode === fnode && foffset < aoffset) || (anode !== fnode && (anode.compareDocumentPosition(fnode) & Node.DOCUMENT_POSITION_PRECEDING))) {
if ((anode === fnode && foffset < aoffset) || (anode !== fnode && (anode.compareDocumentPosition(fnode) & Node.DOCUMENT_POSITION_PRECEDING) && !(anode.compareDocumentPosition(fnode) & Node.DOCUMENT_POSITION_CONTAINS))) {
fnode = [anode, anode = fnode][0];
foffset = [aoffset, aoffset = foffset][0];
}
Expand All @@ -442,13 +446,20 @@ var wysihtml5 = {
}
}

if (felement) {
foffset = Array.prototype.indexOf.call(felement.parentNode.childNodes, felement) + 1;
}

if (aelement) {
aoffset = Array.prototype.indexOf.call(aelement.parentNode.childNodes, aelement);
}

if (anode && anode.parentNode && fnode && fnode.parentNode) {
r.setStart(anode, aoffset);
r.setEnd(fnode, foffset);
s.removeAllRanges();
s.addRange(r);
}

};
Node.prototype.normalize = nf;
};
Expand Down
16 changes: 8 additions & 8 deletions dist/wysihtml.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/wysihtml.min.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wysihtml",
"version": "0.5.0-beta12",
"version": "0.5.0-beta13",
"devDependencies": {
"grunt": "~0.4.4",
"grunt-contrib-concat": "~0.4.0",
Expand Down

0 comments on commit 66e3f94

Please sign in to comment.