wysihtml-rails 0.5.0.beta9 → 0.5.0.beta10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 390f760e7e1ad7366a3b8463d5fd6ad12dce0920
4
- data.tar.gz: 88c4a8460bffbb8e885402ba05484859354d0894
3
+ metadata.gz: 81549cbb9a36c9d74e052ce4fb1ca5c0b232daa6
4
+ data.tar.gz: 0cb8580a29fa4667a6afc9068f8839138a8612f0
5
5
  SHA512:
6
- metadata.gz: 80e460e6841fbe1d87bb34836850187b7c767c5fc69510d7ad7302855f88605eaa27f706bda27c2529607484a1fdc65aaa072724637d898d0b3a350cae0e13af
7
- data.tar.gz: 3d7420f8b77dd86084a877aec874565ee36f9360ff3fc58c796563b80c844da2c0a3c2d9592b259c8f01bcfb08972fcfbbef6d5b758ea406bb020b3ed99922d2
6
+ metadata.gz: 5ed9c1cadd3b1e82d0bed2bb8d30c54f943193ad80aa96ec79efd3292dd94f3740dae8da8e512daf1f36c28100c81aceb09ac6b6dd85dd74789f7e500221f022
7
+ data.tar.gz: 3d4c341657f1be7211eedcb52b0bce809b495e328b460ac46f6fa14cb57572958b65bd7d43f5c0fe33d05f1a855f1637cc882f2e88b43eb7521b21068769e4bc
@@ -1,5 +1,5 @@
1
1
  module Wysihtml
2
2
  module Rails
3
- VERSION = "0.5.0.beta9"
3
+ VERSION = "0.5.0.beta10"
4
4
  end
5
5
  end
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license wysihtml v0.5.0-beta9
2
+ * @license wysihtml v0.5.0-beta10
3
3
  * https://github.com/Voog/wysihtml
4
4
  *
5
5
  * Author: Christopher Blum (https://github.com/tiff)
@@ -10,7 +10,7 @@
10
10
  *
11
11
  */
12
12
  var wysihtml5 = {
13
- version: "0.5.0-beta9",
13
+ version: "0.5.0-beta10",
14
14
 
15
15
  // namespaces
16
16
  commands: {},
@@ -5898,6 +5898,17 @@ wysihtml5.dom.copyAttributes = function(attributesToCopy) {
5898
5898
  emptyTextNode: function(ignoreWhitespace) {
5899
5899
  var regx = ignoreWhitespace ? (/^\s*$/g) : (/^[\r\n]*$/g);
5900
5900
  return node.nodeType === wysihtml5.TEXT_NODE && (regx).test(node.data);
5901
+ },
5902
+
5903
+ visible: function() {
5904
+ var isVisible = !(/^\s*$/g).test(wysihtml5.dom.getTextContent(node));
5905
+
5906
+ if (!isVisible) {
5907
+ if (node.nodeType === 1 && node.querySelector('img, br, hr, object, embed, canvas, input, textarea')) {
5908
+ isVisible = true;
5909
+ }
5910
+ }
5911
+ return isVisible;
5901
5912
  }
5902
5913
  },
5903
5914
 
@@ -10213,7 +10224,7 @@ wysihtml5.quirks.ensureProperClearing = (function() {
10213
10224
 
10214
10225
  // Empty elements are cleaned up from extracted content
10215
10226
  for (var i = childNodes.length; i --;) {
10216
- if (childNodes[i].nodeType === 1 && (/^\s*$/).test(childNodes[i].innerHTML)) {
10227
+ if (!wysihtml5.dom.domNode(childNodes[i]).is.visible()) {
10217
10228
  contentAfterRangeStart.removeChild(childNodes[i]);
10218
10229
  }
10219
10230
  }
@@ -10237,11 +10248,11 @@ wysihtml5.quirks.ensureProperClearing = (function() {
10237
10248
  range.setEndAfter(element);
10238
10249
  }
10239
10250
 
10240
- if ((/^\s*$/).test(element.innerHTML)) {
10241
- if (element.innerHTML === '') {
10251
+ if (!wysihtml5.dom.domNode(element).is.visible()) {
10252
+ if (wysihtml5.dom.getTextContent(element) === '') {
10242
10253
  element.parentNode.removeChild(element);
10243
10254
  } else {
10244
- wysihtml5.dom.unwrap(element);
10255
+ element.parentNode.replaceChild(this.doc.createTextNode(" "), element);
10245
10256
  }
10246
10257
  }
10247
10258
 
@@ -11651,8 +11662,10 @@ wysihtml5.Commands = Base.extend(
11651
11662
  var dom = wysihtml5.dom,
11652
11663
  // When the caret is within a H1 and the H4 is invoked, the H1 should turn into H4
11653
11664
  // instead of creating a H4 within a H1 which would result in semantically invalid html
11654
- UNNESTABLE_BLOCK_ELEMENTS = "h1, h2, h3, h4, h5, h6, p, pre";
11655
- BLOCK_ELEMENTS = "h1, h2, h3, h4, h5, h6, p, pre, div, blockquote";
11665
+ UNNESTABLE_BLOCK_ELEMENTS = "h1, h2, h3, h4, h5, h6, p, pre",
11666
+ BLOCK_ELEMENTS = "h1, h2, h3, h4, h5, h6, p, pre, div, blockquote",
11667
+ INLINE_ELEMENTS = "b, big, i, small, tt, abbr, acronym, cite, code, dfn, em, kbd, strong, samp, var, a, bdo, br, q, span, sub, sup, button, label, textarea, input, select, u";
11668
+
11656
11669
 
11657
11670
  // Removes empty block level elements
11658
11671
  function cleanup(composer) {
@@ -11687,6 +11700,35 @@ wysihtml5.Commands = Base.extend(
11687
11700
  return block;
11688
11701
  }
11689
11702
 
11703
+ function cloneOuterInlines(node, container) {
11704
+ var n = node,
11705
+ innerNode,
11706
+ parentNode,
11707
+ el = null,
11708
+ el2;
11709
+
11710
+ while (n && container && n !== container) {
11711
+ if (n.nodeType === 1 && n.matches(INLINE_ELEMENTS)) {
11712
+ parentNode = n;
11713
+ if (el === null) {
11714
+ el = n.cloneNode(false);
11715
+ innerNode = el;
11716
+ } else {
11717
+ el2 = n.cloneNode(false);
11718
+ el2.appendChild(el);
11719
+ el = el2;
11720
+ }
11721
+ }
11722
+ n = n.parentNode;
11723
+ }
11724
+
11725
+ return {
11726
+ parent: parentNode,
11727
+ outerNode: el,
11728
+ innerNode: innerNode
11729
+ };
11730
+ }
11731
+
11690
11732
  // Formats an element according to options nodeName, className, styleProperty, styleValue
11691
11733
  // If element is not defined, creates new element
11692
11734
  // if opotions is null, remove format instead
@@ -11892,13 +11934,24 @@ wysihtml5.Commands = Base.extend(
11892
11934
 
11893
11935
  blocks = wysihtml5.lang.array(fragment.childNodes).get();
11894
11936
  }
11895
-
11896
11937
  if (firstOuterBlock) {
11897
11938
  // If selection starts inside un-nestable block, split-escape the unnestable point and insert node between
11898
11939
  composer.selection.splitElementAtCaret(firstOuterBlock, fragment);
11899
11940
  } else {
11900
- // Otherwise just insert
11901
- r.insertNode(fragment);
11941
+ // Ensure node does not get inserted into an inline where it is not allowed
11942
+ var outerInlines = cloneOuterInlines(rangeStartContainer, composer.element);
11943
+ if (outerInlines.outerNode && outerInlines.innerNode && outerInlines.parent) {
11944
+ if (fragment.childNodes.length === 1) {
11945
+ while(fragment.firstChild.firstChild) {
11946
+ outerInlines.innerNode.appendChild(fragment.firstChild.firstChild);
11947
+ }
11948
+ fragment.firstChild.appendChild(outerInlines.outerNode);
11949
+ }
11950
+ composer.selection.splitElementAtCaret(outerInlines.parent, fragment);
11951
+ } else {
11952
+ // Otherwise just insert
11953
+ r.insertNode(fragment);
11954
+ }
11902
11955
  }
11903
11956
 
11904
11957
  return blocks;
@@ -12067,7 +12120,7 @@ wysihtml5.Commands = Base.extend(
12067
12120
  (function(wysihtml5) {
12068
12121
 
12069
12122
  var defaultTag = "SPAN",
12070
- INLINE_ELEMENTS = "b, big, i, small, tt, abbr, acronym, cite, code, dfn, em, kbd, strong, samp, var, a, bdo, br, q, span, sub, sup, button, label, textarea, input, select",
12123
+ INLINE_ELEMENTS = "b, big, i, small, tt, abbr, acronym, cite, code, dfn, em, kbd, strong, samp, var, a, bdo, br, q, span, sub, sup, button, label, textarea, input, select, u",
12071
12124
  queryAliasMap = {
12072
12125
  "b": "b, strong",
12073
12126
  "strong": "b, strong",
@@ -15569,7 +15622,7 @@ wysihtml5.views.View = Base.extend(
15569
15622
  this.elementToChange = null;
15570
15623
  dom.removeClass(this.link, CLASS_NAME_OPENED);
15571
15624
  this.container.style.display = "none";
15572
- this.fire("hide");
15625
+ this.fire("cancel");
15573
15626
  }
15574
15627
  });
15575
15628
  })(wysihtml5);
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license wysihtml v0.5.0-beta9
2
+ * @license wysihtml v0.5.0-beta10
3
3
  * https://github.com/Voog/wysihtml
4
4
  *
5
5
  * Author: Christopher Blum (https://github.com/tiff)
@@ -10,7 +10,7 @@
10
10
  *
11
11
  */
12
12
  var wysihtml5 = {
13
- version: "0.5.0-beta9",
13
+ version: "0.5.0-beta10",
14
14
 
15
15
  // namespaces
16
16
  commands: {},
@@ -5898,6 +5898,17 @@ wysihtml5.dom.copyAttributes = function(attributesToCopy) {
5898
5898
  emptyTextNode: function(ignoreWhitespace) {
5899
5899
  var regx = ignoreWhitespace ? (/^\s*$/g) : (/^[\r\n]*$/g);
5900
5900
  return node.nodeType === wysihtml5.TEXT_NODE && (regx).test(node.data);
5901
+ },
5902
+
5903
+ visible: function() {
5904
+ var isVisible = !(/^\s*$/g).test(wysihtml5.dom.getTextContent(node));
5905
+
5906
+ if (!isVisible) {
5907
+ if (node.nodeType === 1 && node.querySelector('img, br, hr, object, embed, canvas, input, textarea')) {
5908
+ isVisible = true;
5909
+ }
5910
+ }
5911
+ return isVisible;
5901
5912
  }
5902
5913
  },
5903
5914
 
@@ -10213,7 +10224,7 @@ wysihtml5.quirks.ensureProperClearing = (function() {
10213
10224
 
10214
10225
  // Empty elements are cleaned up from extracted content
10215
10226
  for (var i = childNodes.length; i --;) {
10216
- if (childNodes[i].nodeType === 1 && (/^\s*$/).test(childNodes[i].innerHTML)) {
10227
+ if (!wysihtml5.dom.domNode(childNodes[i]).is.visible()) {
10217
10228
  contentAfterRangeStart.removeChild(childNodes[i]);
10218
10229
  }
10219
10230
  }
@@ -10237,11 +10248,11 @@ wysihtml5.quirks.ensureProperClearing = (function() {
10237
10248
  range.setEndAfter(element);
10238
10249
  }
10239
10250
 
10240
- if ((/^\s*$/).test(element.innerHTML)) {
10241
- if (element.innerHTML === '') {
10251
+ if (!wysihtml5.dom.domNode(element).is.visible()) {
10252
+ if (wysihtml5.dom.getTextContent(element) === '') {
10242
10253
  element.parentNode.removeChild(element);
10243
10254
  } else {
10244
- wysihtml5.dom.unwrap(element);
10255
+ element.parentNode.replaceChild(this.doc.createTextNode(" "), element);
10245
10256
  }
10246
10257
  }
10247
10258
 
@@ -11651,8 +11662,10 @@ wysihtml5.Commands = Base.extend(
11651
11662
  var dom = wysihtml5.dom,
11652
11663
  // When the caret is within a H1 and the H4 is invoked, the H1 should turn into H4
11653
11664
  // instead of creating a H4 within a H1 which would result in semantically invalid html
11654
- UNNESTABLE_BLOCK_ELEMENTS = "h1, h2, h3, h4, h5, h6, p, pre";
11655
- BLOCK_ELEMENTS = "h1, h2, h3, h4, h5, h6, p, pre, div, blockquote";
11665
+ UNNESTABLE_BLOCK_ELEMENTS = "h1, h2, h3, h4, h5, h6, p, pre",
11666
+ BLOCK_ELEMENTS = "h1, h2, h3, h4, h5, h6, p, pre, div, blockquote",
11667
+ INLINE_ELEMENTS = "b, big, i, small, tt, abbr, acronym, cite, code, dfn, em, kbd, strong, samp, var, a, bdo, br, q, span, sub, sup, button, label, textarea, input, select, u";
11668
+
11656
11669
 
11657
11670
  // Removes empty block level elements
11658
11671
  function cleanup(composer) {
@@ -11687,6 +11700,35 @@ wysihtml5.Commands = Base.extend(
11687
11700
  return block;
11688
11701
  }
11689
11702
 
11703
+ function cloneOuterInlines(node, container) {
11704
+ var n = node,
11705
+ innerNode,
11706
+ parentNode,
11707
+ el = null,
11708
+ el2;
11709
+
11710
+ while (n && container && n !== container) {
11711
+ if (n.nodeType === 1 && n.matches(INLINE_ELEMENTS)) {
11712
+ parentNode = n;
11713
+ if (el === null) {
11714
+ el = n.cloneNode(false);
11715
+ innerNode = el;
11716
+ } else {
11717
+ el2 = n.cloneNode(false);
11718
+ el2.appendChild(el);
11719
+ el = el2;
11720
+ }
11721
+ }
11722
+ n = n.parentNode;
11723
+ }
11724
+
11725
+ return {
11726
+ parent: parentNode,
11727
+ outerNode: el,
11728
+ innerNode: innerNode
11729
+ };
11730
+ }
11731
+
11690
11732
  // Formats an element according to options nodeName, className, styleProperty, styleValue
11691
11733
  // If element is not defined, creates new element
11692
11734
  // if opotions is null, remove format instead
@@ -11892,13 +11934,24 @@ wysihtml5.Commands = Base.extend(
11892
11934
 
11893
11935
  blocks = wysihtml5.lang.array(fragment.childNodes).get();
11894
11936
  }
11895
-
11896
11937
  if (firstOuterBlock) {
11897
11938
  // If selection starts inside un-nestable block, split-escape the unnestable point and insert node between
11898
11939
  composer.selection.splitElementAtCaret(firstOuterBlock, fragment);
11899
11940
  } else {
11900
- // Otherwise just insert
11901
- r.insertNode(fragment);
11941
+ // Ensure node does not get inserted into an inline where it is not allowed
11942
+ var outerInlines = cloneOuterInlines(rangeStartContainer, composer.element);
11943
+ if (outerInlines.outerNode && outerInlines.innerNode && outerInlines.parent) {
11944
+ if (fragment.childNodes.length === 1) {
11945
+ while(fragment.firstChild.firstChild) {
11946
+ outerInlines.innerNode.appendChild(fragment.firstChild.firstChild);
11947
+ }
11948
+ fragment.firstChild.appendChild(outerInlines.outerNode);
11949
+ }
11950
+ composer.selection.splitElementAtCaret(outerInlines.parent, fragment);
11951
+ } else {
11952
+ // Otherwise just insert
11953
+ r.insertNode(fragment);
11954
+ }
11902
11955
  }
11903
11956
 
11904
11957
  return blocks;
@@ -12067,7 +12120,7 @@ wysihtml5.Commands = Base.extend(
12067
12120
  (function(wysihtml5) {
12068
12121
 
12069
12122
  var defaultTag = "SPAN",
12070
- INLINE_ELEMENTS = "b, big, i, small, tt, abbr, acronym, cite, code, dfn, em, kbd, strong, samp, var, a, bdo, br, q, span, sub, sup, button, label, textarea, input, select",
12123
+ INLINE_ELEMENTS = "b, big, i, small, tt, abbr, acronym, cite, code, dfn, em, kbd, strong, samp, var, a, bdo, br, q, span, sub, sup, button, label, textarea, input, select, u",
12071
12124
  queryAliasMap = {
12072
12125
  "b": "b, strong",
12073
12126
  "strong": "b, strong",
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wysihtml-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0.beta9
4
+ version: 0.5.0.beta10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tanel Jakobsoo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-02 00:00:00.000000000 Z
11
+ date: 2015-06-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties