wysihtml5x-rails 0.4.8 → 0.4.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b4607a6bd62d53bfc0e81a0b0b7113768acf1648
4
- data.tar.gz: 9b291ad470a6fe44b019b325a6b2c696538ed227
3
+ metadata.gz: b3a2130d7224dcba4c3e6d98a379a394d4154769
4
+ data.tar.gz: 652cb61fc14aa44d53cfbcf412015036fe6ec453
5
5
  SHA512:
6
- metadata.gz: b793684dc2eba9cddf6d8b8456763dd229679cefb67f42cae4a227b56d64770d69971d736f09e97e5b5ebd31ca426dbff50128d0174abb047442c8cfd33b2402
7
- data.tar.gz: b7833d96cc98133ea0539e7d482462e2d3dc5398bca8266db50800707c1f5a29162fafe1dfa9f496c90777797df29171362ad0bd3fdbae0a9f61b0ab725ed428
6
+ metadata.gz: 9120a099177dcb0fe653ad639afab5cb188dbb87af2f7c69f4b4c97a049ebbeafd8b255233a87411a335658b789c8c1d95dc17f0207c493fd9aaa9f12cb53c6a
7
+ data.tar.gz: 9fe43031a37d2648e2b619db67c06684824c41f2d5435966bffc17df41bcb4b902467ac17ef44a9cc41f50d3f779d052d1a8cc9a394608315cdcb021c3a329c1
@@ -1,5 +1,5 @@
1
1
  module Wysihtml5x
2
2
  module Rails
3
- VERSION = "0.4.8"
3
+ VERSION = "0.4.9"
4
4
  end
5
5
  end
@@ -25,7 +25,7 @@ if(!Array.isArray) {
25
25
  return Object.prototype.toString.call(arg) === '[object Array]';
26
26
  };
27
27
  };/**
28
- * @license wysihtml5x v0.4.8
28
+ * @license wysihtml5x v0.4.9
29
29
  * https://github.com/Edicy/wysihtml5
30
30
  *
31
31
  * Author: Christopher Blum (https://github.com/tiff)
@@ -36,7 +36,7 @@ if(!Array.isArray) {
36
36
  *
37
37
  */
38
38
  var wysihtml5 = {
39
- version: "0.4.8",
39
+ version: "0.4.9",
40
40
 
41
41
  // namespaces
42
42
  commands: {},
@@ -5813,10 +5813,15 @@ wysihtml5.dom.parse = (function() {
5813
5813
  var context = config.context || elementOrHtml.ownerDocument || document,
5814
5814
  fragment = context.createDocumentFragment(),
5815
5815
  isString = typeof(elementOrHtml) === "string",
5816
+ clearInternals = false,
5816
5817
  element,
5817
5818
  newNode,
5818
5819
  firstChild;
5819
5820
 
5821
+ if (config.clearInternals === true) {
5822
+ clearInternals = true;
5823
+ }
5824
+
5820
5825
  if (config.uneditableClass) {
5821
5826
  uneditableClass = config.uneditableClass;
5822
5827
  }
@@ -5829,11 +5834,13 @@ wysihtml5.dom.parse = (function() {
5829
5834
 
5830
5835
  while (element.firstChild) {
5831
5836
  firstChild = element.firstChild;
5832
- newNode = _convert(firstChild, config.cleanUp);
5833
- element.removeChild(firstChild);
5837
+ newNode = _convert(firstChild, config.cleanUp, clearInternals);
5834
5838
  if (newNode) {
5835
5839
  fragment.appendChild(newNode);
5836
5840
  }
5841
+ if (firstChild !== newNode) {
5842
+ element.removeChild(firstChild);
5843
+ }
5837
5844
  }
5838
5845
 
5839
5846
  // Clear element contents
@@ -5845,7 +5852,7 @@ wysihtml5.dom.parse = (function() {
5845
5852
  return isString ? wysihtml5.quirks.getCorrectInnerHTML(element) : element;
5846
5853
  }
5847
5854
 
5848
- function _convert(oldNode, cleanUp) {
5855
+ function _convert(oldNode, cleanUp, clearInternals) {
5849
5856
  var oldNodeType = oldNode.nodeType,
5850
5857
  oldChilds = oldNode.childNodes,
5851
5858
  oldChildsLength = oldChilds.length,
@@ -5855,21 +5862,28 @@ wysihtml5.dom.parse = (function() {
5855
5862
  newNode,
5856
5863
  newChild;
5857
5864
 
5865
+ // Passes directly elemets with uneditable class
5858
5866
  if (uneditableClass && oldNodeType === 1 && wysihtml5.dom.hasClass(oldNode, uneditableClass)) {
5859
5867
  return oldNode;
5860
5868
  }
5861
5869
 
5862
- newNode = method && method(oldNode);
5870
+ newNode = method && method(oldNode, clearInternals);
5863
5871
 
5872
+ // Remove or unwrap node in case of return value null or false
5864
5873
  if (!newNode) {
5865
5874
  if (newNode === false) {
5866
5875
  // false defines that tag should be removed but contents should remain (unwrap)
5867
5876
  fragment = oldNode.ownerDocument.createDocumentFragment();
5868
5877
 
5869
5878
  for (i = oldChildsLength; i--;) {
5870
- newChild = _convert(oldChilds[i], cleanUp);
5871
- if (newChild) {
5872
- fragment.insertBefore(newChild, fragment.firstChild);
5879
+ if (oldChilds[i]) {
5880
+ newChild = _convert(oldChilds[i], cleanUp, clearInternals);
5881
+ if (newChild) {
5882
+ if (oldChilds[i] === newChild) {
5883
+ i--;
5884
+ }
5885
+ fragment.insertBefore(newChild, fragment.firstChild);
5886
+ }
5873
5887
  }
5874
5888
  }
5875
5889
 
@@ -5893,14 +5907,21 @@ wysihtml5.dom.parse = (function() {
5893
5907
  }
5894
5908
  return fragment;
5895
5909
  } else {
5896
- return null;
5910
+ // Remove
5911
+ return null;
5897
5912
  }
5898
5913
  }
5899
5914
 
5915
+ // Converts all childnodes
5900
5916
  for (i=0; i<oldChildsLength; i++) {
5901
- newChild = _convert(oldChilds[i], cleanUp);
5902
- if (newChild) {
5903
- newNode.appendChild(newChild);
5917
+ if (oldChilds[i]) {
5918
+ newChild = _convert(oldChilds[i], cleanUp, clearInternals);
5919
+ if (newChild) {
5920
+ if (oldChilds[i] === newChild) {
5921
+ i--;
5922
+ }
5923
+ newNode.appendChild(newChild);
5924
+ }
5904
5925
  }
5905
5926
  }
5906
5927
 
@@ -5908,7 +5929,7 @@ wysihtml5.dom.parse = (function() {
5908
5929
  if (cleanUp &&
5909
5930
  newNode.nodeName.toLowerCase() === DEFAULT_NODE_NAME &&
5910
5931
  (!newNode.childNodes.length ||
5911
- ((/^\s*$/gi).test(newNode.innerHTML) && oldNode.className !== "_wysihtml5-temp-placeholder" && oldNode.className !== "rangySelectionBoundary") ||
5932
+ ((/^\s*$/gi).test(newNode.innerHTML) && (clearInternals || (oldNode.className !== "_wysihtml5-temp-placeholder" && oldNode.className !== "rangySelectionBoundary"))) ||
5912
5933
  !newNode.attributes.length)
5913
5934
  ) {
5914
5935
  fragment = newNode.ownerDocument.createDocumentFragment();
@@ -5927,7 +5948,7 @@ wysihtml5.dom.parse = (function() {
5927
5948
  return newNode;
5928
5949
  }
5929
5950
 
5930
- function _handleElement(oldNode) {
5951
+ function _handleElement(oldNode, clearInternals) {
5931
5952
  var rule,
5932
5953
  newNode,
5933
5954
  tagRules = currentRules.tags,
@@ -5985,10 +6006,10 @@ wysihtml5.dom.parse = (function() {
5985
6006
  }
5986
6007
 
5987
6008
  newNode = oldNode.ownerDocument.createElement(rule.rename_tag || nodeName);
5988
- _handleAttributes(oldNode, newNode, rule);
6009
+ _handleAttributes(oldNode, newNode, rule, clearInternals);
5989
6010
  _handleStyles(oldNode, newNode, rule);
5990
6011
  // tests if type condition is met or node should be removed/unwrapped
5991
- if (rule.one_of_type && !_testTypes(oldNode, currentRules, rule.one_of_type)) {
6012
+ if (rule.one_of_type && !_testTypes(oldNode, currentRules, rule.one_of_type, clearInternals)) {
5992
6013
  return (rule.remove_action && rule.remove_action == "unwrap") ? false : null;
5993
6014
  }
5994
6015
 
@@ -5998,11 +6019,11 @@ wysihtml5.dom.parse = (function() {
5998
6019
  return newNode;
5999
6020
  }
6000
6021
 
6001
- function _testTypes(oldNode, rules, types) {
6022
+ function _testTypes(oldNode, rules, types, clearInternals) {
6002
6023
  var definition, type;
6003
6024
 
6004
6025
  // do not interfere with placeholder span or pasting caret position is not maintained
6005
- if (oldNode.nodeName === "SPAN" && (oldNode.className === "_wysihtml5-temp-placeholder" || oldNode.className === "rangySelectionBoundary")) {
6026
+ if (oldNode.nodeName === "SPAN" && !clearInternals && (oldNode.className === "_wysihtml5-temp-placeholder" || oldNode.className === "rangySelectionBoundary")) {
6006
6027
  return true;
6007
6028
  }
6008
6029
 
@@ -6112,7 +6133,8 @@ wysihtml5.dom.parse = (function() {
6112
6133
  }
6113
6134
  }
6114
6135
 
6115
- function _handleAttributes(oldNode, newNode, rule) {
6136
+ // TODO: refactor. Too long to read
6137
+ function _handleAttributes(oldNode, newNode, rule, clearInternals) {
6116
6138
  var attributes = {}, // fresh new set of attributes to set on newNode
6117
6139
  setClass = rule.set_class, // classes to set
6118
6140
  addClass = rule.add_class, // add classes based on existing attributes
@@ -6189,8 +6211,11 @@ wysihtml5.dom.parse = (function() {
6189
6211
  attributes["class"] = oldNode.getAttribute("class");
6190
6212
  } else {
6191
6213
  // make sure that wysihtml5 temp class doesn't get stripped out
6192
- allowedClasses["_wysihtml5-temp-placeholder"] = 1;
6193
- allowedClasses["_rangySelectionBoundary"] = 1;
6214
+ if (!clearInternals) {
6215
+ allowedClasses["_wysihtml5-temp-placeholder"] = 1;
6216
+ allowedClasses["_rangySelectionBoundary"] = 1;
6217
+ allowedClasses["wysiwyg-tmp-selected-cell"] = 1;
6218
+ }
6194
6219
 
6195
6220
  // add old classes last
6196
6221
  oldClasses = oldNode.getAttribute("class");
@@ -6210,6 +6235,14 @@ wysihtml5.dom.parse = (function() {
6210
6235
  }
6211
6236
  }
6212
6237
 
6238
+ // remove table selection class if present
6239
+ if (attributes["class"] && clearInternals) {
6240
+ attributes["class"] = attributes["class"].replace("wysiwyg-tmp-selected-cell", "");
6241
+ if ((/^\s*$/g).test(attributes["class"])) {
6242
+ delete attributes.class;
6243
+ }
6244
+ }
6245
+
6213
6246
  if (styles.length) {
6214
6247
  attributes["style"] = wysihtml5.lang.array(styles).unique().join(" ");
6215
6248
  }
@@ -10827,7 +10860,7 @@ wysihtml5.commands.formatCode = {
10827
10860
  return wysihtml5.commands.insertList.state(composer, command, "UL");
10828
10861
  }
10829
10862
  };
10830
- ;wysihtml5.commands.insertList = (function() {
10863
+ ;wysihtml5.commands.insertList = (function(wysihtml5) {
10831
10864
 
10832
10865
  var isNode = function(node, name) {
10833
10866
  if (node && node.nodeName) {
@@ -10985,7 +11018,7 @@ wysihtml5.commands.formatCode = {
10985
11018
  }
10986
11019
  };
10987
11020
 
10988
- })();;wysihtml5.commands.italic = {
11021
+ })(wysihtml5);;wysihtml5.commands.italic = {
10989
11022
  exec: function(composer, command) {
10990
11023
  wysihtml5.commands.formatInline.execWithToggle(composer, command, "i");
10991
11024
  },
@@ -11451,7 +11484,7 @@ wysihtml5.commands.formatCode = {
11451
11484
 
11452
11485
  transact: function() {
11453
11486
  var previousHtml = this.historyStr[this.position - 1],
11454
- currentHtml = this.composer.getValue();
11487
+ currentHtml = this.composer.getValue(false, false);
11455
11488
 
11456
11489
  if (currentHtml === previousHtml) {
11457
11490
  return;
@@ -11654,11 +11687,10 @@ wysihtml5.views.View = Base.extend(
11654
11687
  this.element.innerHTML = browser.displaysCaretInEmptyContentEditableCorrectly() ? "" : this.CARET_HACK;
11655
11688
  },
11656
11689
 
11657
- getValue: function(parse) {
11690
+ getValue: function(parse, clearInternals) {
11658
11691
  var value = this.isEmpty() ? "" : wysihtml5.quirks.getCorrectInnerHTML(this.element);
11659
-
11660
- if (parse) {
11661
- value = this.parent.parse(value);
11692
+ if (parse !== false) {
11693
+ value = this.parent.parse(value, (clearInternals === false) ? false : true);
11662
11694
  }
11663
11695
 
11664
11696
  return value;
@@ -11795,7 +11827,7 @@ wysihtml5.views.View = Base.extend(
11795
11827
  this.element = (this.config.contentEditableMode) ? this.sandbox.getContentEditable() : this.doc.body;
11796
11828
  if (!this.config.noTextarea) {
11797
11829
  this.textarea = this.parent.textarea;
11798
- this.element.innerHTML = this.textarea.getValue(true);
11830
+ this.element.innerHTML = this.textarea.getValue(true, false);
11799
11831
  } else {
11800
11832
  this.cleanUp(); // cleans contenteditable on initiation as it may contain html
11801
11833
  }
@@ -12374,7 +12406,7 @@ wysihtml5.views.View = Base.extend(
12374
12406
 
12375
12407
  wysihtml5.views.Composer.prototype.observe = function() {
12376
12408
  var that = this,
12377
- state = this.getValue(),
12409
+ state = this.getValue(false, false),
12378
12410
  container = (this.sandbox.getIframe) ? this.sandbox.getIframe() : this.sandbox.getContentEditable(),
12379
12411
  element = this.element,
12380
12412
  focusBlurElement = (browser.supportsEventsInIframeCorrectly() || this.sandbox.getContentEditable) ? element : this.sandbox.getWindow(),
@@ -12422,11 +12454,11 @@ wysihtml5.views.View = Base.extend(
12422
12454
 
12423
12455
  // Delay storing of state until all focus handler are fired
12424
12456
  // especially the one which resets the placeholder
12425
- setTimeout(function() { state = that.getValue(); }, 0);
12457
+ setTimeout(function() { state = that.getValue(false, false); }, 0);
12426
12458
  });
12427
12459
 
12428
12460
  dom.observe(focusBlurElement, "blur", function() {
12429
- if (state !== that.getValue()) {
12461
+ if (state !== that.getValue(false, false)) {
12430
12462
  that.parent.fire("change").fire("change:composer");
12431
12463
  }
12432
12464
  that.parent.fire("blur").fire("blur:composer");
@@ -12603,7 +12635,7 @@ wysihtml5.views.View = Base.extend(
12603
12635
  * @param {Boolean} shouldParseHtml Whether the html should be sanitized before inserting it into the textarea
12604
12636
  */
12605
12637
  fromComposerToTextarea: function(shouldParseHtml) {
12606
- this.textarea.setValue(wysihtml5.lang.string(this.composer.getValue()).trim(), shouldParseHtml);
12638
+ this.textarea.setValue(wysihtml5.lang.string(this.composer.getValue(false, false)).trim(), shouldParseHtml);
12607
12639
  },
12608
12640
 
12609
12641
  /**
@@ -12612,7 +12644,7 @@ wysihtml5.views.View = Base.extend(
12612
12644
  * @param {Boolean} shouldParseHtml Whether the html should be sanitized before inserting it into the composer
12613
12645
  */
12614
12646
  fromTextareaToComposer: function(shouldParseHtml) {
12615
- var textareaValue = this.textarea.getValue();
12647
+ var textareaValue = this.textarea.getValue(false, false);
12616
12648
  if (textareaValue) {
12617
12649
  this.composer.setValue(textareaValue, shouldParseHtml);
12618
12650
  } else {
@@ -12693,7 +12725,7 @@ wysihtml5.views.View = Base.extend(
12693
12725
 
12694
12726
  getValue: function(parse) {
12695
12727
  var value = this.isEmpty() ? "" : this.element.value;
12696
- if (parse) {
12728
+ if (parse !== false) {
12697
12729
  value = this.parent.parse(value);
12698
12730
  }
12699
12731
  return value;
@@ -12878,8 +12910,8 @@ wysihtml5.views.View = Base.extend(
12878
12910
  return this;
12879
12911
  },
12880
12912
 
12881
- getValue: function(parse) {
12882
- return this.currentView.getValue(parse);
12913
+ getValue: function(parse, clearInternals) {
12914
+ return this.currentView.getValue(parse, clearInternals);
12883
12915
  },
12884
12916
 
12885
12917
  setValue: function(html, parse) {
@@ -12926,13 +12958,14 @@ wysihtml5.views.View = Base.extend(
12926
12958
  return this.currentView.hasPlaceholderSet();
12927
12959
  },
12928
12960
 
12929
- parse: function(htmlOrElement) {
12930
- var parseContext = (this.config.contentEditableMode) ? document : this.composer.sandbox.getDocument();
12961
+ parse: function(htmlOrElement, clearInternals) {
12962
+ var parseContext = (this.config.contentEditableMode) ? document : ((this.composer) ? this.composer.sandbox.getDocument() : null);
12931
12963
  var returnValue = this.config.parser(htmlOrElement, {
12932
12964
  "rules": this.config.parserRules,
12933
12965
  "cleanUp": this.config.cleanUp,
12934
12966
  "context": parseContext,
12935
- "uneditableClass": this.config.uneditableContainerClassname
12967
+ "uneditableClass": this.config.uneditableContainerClassname,
12968
+ "clearInternals" : clearInternals
12936
12969
  });
12937
12970
  if (typeof(htmlOrElement) === "object") {
12938
12971
  wysihtml5.quirks.redraw(htmlOrElement);
@@ -25,7 +25,7 @@ if(!Array.isArray) {
25
25
  return Object.prototype.toString.call(arg) === '[object Array]';
26
26
  };
27
27
  };/**
28
- * @license wysihtml5x v0.4.8
28
+ * @license wysihtml5x v0.4.9
29
29
  * https://github.com/Edicy/wysihtml5
30
30
  *
31
31
  * Author: Christopher Blum (https://github.com/tiff)
@@ -36,7 +36,7 @@ if(!Array.isArray) {
36
36
  *
37
37
  */
38
38
  var wysihtml5 = {
39
- version: "0.4.8",
39
+ version: "0.4.9",
40
40
 
41
41
  // namespaces
42
42
  commands: {},
@@ -5813,10 +5813,15 @@ wysihtml5.dom.parse = (function() {
5813
5813
  var context = config.context || elementOrHtml.ownerDocument || document,
5814
5814
  fragment = context.createDocumentFragment(),
5815
5815
  isString = typeof(elementOrHtml) === "string",
5816
+ clearInternals = false,
5816
5817
  element,
5817
5818
  newNode,
5818
5819
  firstChild;
5819
5820
 
5821
+ if (config.clearInternals === true) {
5822
+ clearInternals = true;
5823
+ }
5824
+
5820
5825
  if (config.uneditableClass) {
5821
5826
  uneditableClass = config.uneditableClass;
5822
5827
  }
@@ -5829,11 +5834,13 @@ wysihtml5.dom.parse = (function() {
5829
5834
 
5830
5835
  while (element.firstChild) {
5831
5836
  firstChild = element.firstChild;
5832
- newNode = _convert(firstChild, config.cleanUp);
5833
- element.removeChild(firstChild);
5837
+ newNode = _convert(firstChild, config.cleanUp, clearInternals);
5834
5838
  if (newNode) {
5835
5839
  fragment.appendChild(newNode);
5836
5840
  }
5841
+ if (firstChild !== newNode) {
5842
+ element.removeChild(firstChild);
5843
+ }
5837
5844
  }
5838
5845
 
5839
5846
  // Clear element contents
@@ -5845,7 +5852,7 @@ wysihtml5.dom.parse = (function() {
5845
5852
  return isString ? wysihtml5.quirks.getCorrectInnerHTML(element) : element;
5846
5853
  }
5847
5854
 
5848
- function _convert(oldNode, cleanUp) {
5855
+ function _convert(oldNode, cleanUp, clearInternals) {
5849
5856
  var oldNodeType = oldNode.nodeType,
5850
5857
  oldChilds = oldNode.childNodes,
5851
5858
  oldChildsLength = oldChilds.length,
@@ -5855,21 +5862,28 @@ wysihtml5.dom.parse = (function() {
5855
5862
  newNode,
5856
5863
  newChild;
5857
5864
 
5865
+ // Passes directly elemets with uneditable class
5858
5866
  if (uneditableClass && oldNodeType === 1 && wysihtml5.dom.hasClass(oldNode, uneditableClass)) {
5859
5867
  return oldNode;
5860
5868
  }
5861
5869
 
5862
- newNode = method && method(oldNode);
5870
+ newNode = method && method(oldNode, clearInternals);
5863
5871
 
5872
+ // Remove or unwrap node in case of return value null or false
5864
5873
  if (!newNode) {
5865
5874
  if (newNode === false) {
5866
5875
  // false defines that tag should be removed but contents should remain (unwrap)
5867
5876
  fragment = oldNode.ownerDocument.createDocumentFragment();
5868
5877
 
5869
5878
  for (i = oldChildsLength; i--;) {
5870
- newChild = _convert(oldChilds[i], cleanUp);
5871
- if (newChild) {
5872
- fragment.insertBefore(newChild, fragment.firstChild);
5879
+ if (oldChilds[i]) {
5880
+ newChild = _convert(oldChilds[i], cleanUp, clearInternals);
5881
+ if (newChild) {
5882
+ if (oldChilds[i] === newChild) {
5883
+ i--;
5884
+ }
5885
+ fragment.insertBefore(newChild, fragment.firstChild);
5886
+ }
5873
5887
  }
5874
5888
  }
5875
5889
 
@@ -5893,14 +5907,21 @@ wysihtml5.dom.parse = (function() {
5893
5907
  }
5894
5908
  return fragment;
5895
5909
  } else {
5896
- return null;
5910
+ // Remove
5911
+ return null;
5897
5912
  }
5898
5913
  }
5899
5914
 
5915
+ // Converts all childnodes
5900
5916
  for (i=0; i<oldChildsLength; i++) {
5901
- newChild = _convert(oldChilds[i], cleanUp);
5902
- if (newChild) {
5903
- newNode.appendChild(newChild);
5917
+ if (oldChilds[i]) {
5918
+ newChild = _convert(oldChilds[i], cleanUp, clearInternals);
5919
+ if (newChild) {
5920
+ if (oldChilds[i] === newChild) {
5921
+ i--;
5922
+ }
5923
+ newNode.appendChild(newChild);
5924
+ }
5904
5925
  }
5905
5926
  }
5906
5927
 
@@ -5908,7 +5929,7 @@ wysihtml5.dom.parse = (function() {
5908
5929
  if (cleanUp &&
5909
5930
  newNode.nodeName.toLowerCase() === DEFAULT_NODE_NAME &&
5910
5931
  (!newNode.childNodes.length ||
5911
- ((/^\s*$/gi).test(newNode.innerHTML) && oldNode.className !== "_wysihtml5-temp-placeholder" && oldNode.className !== "rangySelectionBoundary") ||
5932
+ ((/^\s*$/gi).test(newNode.innerHTML) && (clearInternals || (oldNode.className !== "_wysihtml5-temp-placeholder" && oldNode.className !== "rangySelectionBoundary"))) ||
5912
5933
  !newNode.attributes.length)
5913
5934
  ) {
5914
5935
  fragment = newNode.ownerDocument.createDocumentFragment();
@@ -5927,7 +5948,7 @@ wysihtml5.dom.parse = (function() {
5927
5948
  return newNode;
5928
5949
  }
5929
5950
 
5930
- function _handleElement(oldNode) {
5951
+ function _handleElement(oldNode, clearInternals) {
5931
5952
  var rule,
5932
5953
  newNode,
5933
5954
  tagRules = currentRules.tags,
@@ -5985,10 +6006,10 @@ wysihtml5.dom.parse = (function() {
5985
6006
  }
5986
6007
 
5987
6008
  newNode = oldNode.ownerDocument.createElement(rule.rename_tag || nodeName);
5988
- _handleAttributes(oldNode, newNode, rule);
6009
+ _handleAttributes(oldNode, newNode, rule, clearInternals);
5989
6010
  _handleStyles(oldNode, newNode, rule);
5990
6011
  // tests if type condition is met or node should be removed/unwrapped
5991
- if (rule.one_of_type && !_testTypes(oldNode, currentRules, rule.one_of_type)) {
6012
+ if (rule.one_of_type && !_testTypes(oldNode, currentRules, rule.one_of_type, clearInternals)) {
5992
6013
  return (rule.remove_action && rule.remove_action == "unwrap") ? false : null;
5993
6014
  }
5994
6015
 
@@ -5998,11 +6019,11 @@ wysihtml5.dom.parse = (function() {
5998
6019
  return newNode;
5999
6020
  }
6000
6021
 
6001
- function _testTypes(oldNode, rules, types) {
6022
+ function _testTypes(oldNode, rules, types, clearInternals) {
6002
6023
  var definition, type;
6003
6024
 
6004
6025
  // do not interfere with placeholder span or pasting caret position is not maintained
6005
- if (oldNode.nodeName === "SPAN" && (oldNode.className === "_wysihtml5-temp-placeholder" || oldNode.className === "rangySelectionBoundary")) {
6026
+ if (oldNode.nodeName === "SPAN" && !clearInternals && (oldNode.className === "_wysihtml5-temp-placeholder" || oldNode.className === "rangySelectionBoundary")) {
6006
6027
  return true;
6007
6028
  }
6008
6029
 
@@ -6112,7 +6133,8 @@ wysihtml5.dom.parse = (function() {
6112
6133
  }
6113
6134
  }
6114
6135
 
6115
- function _handleAttributes(oldNode, newNode, rule) {
6136
+ // TODO: refactor. Too long to read
6137
+ function _handleAttributes(oldNode, newNode, rule, clearInternals) {
6116
6138
  var attributes = {}, // fresh new set of attributes to set on newNode
6117
6139
  setClass = rule.set_class, // classes to set
6118
6140
  addClass = rule.add_class, // add classes based on existing attributes
@@ -6189,8 +6211,11 @@ wysihtml5.dom.parse = (function() {
6189
6211
  attributes["class"] = oldNode.getAttribute("class");
6190
6212
  } else {
6191
6213
  // make sure that wysihtml5 temp class doesn't get stripped out
6192
- allowedClasses["_wysihtml5-temp-placeholder"] = 1;
6193
- allowedClasses["_rangySelectionBoundary"] = 1;
6214
+ if (!clearInternals) {
6215
+ allowedClasses["_wysihtml5-temp-placeholder"] = 1;
6216
+ allowedClasses["_rangySelectionBoundary"] = 1;
6217
+ allowedClasses["wysiwyg-tmp-selected-cell"] = 1;
6218
+ }
6194
6219
 
6195
6220
  // add old classes last
6196
6221
  oldClasses = oldNode.getAttribute("class");
@@ -6210,6 +6235,14 @@ wysihtml5.dom.parse = (function() {
6210
6235
  }
6211
6236
  }
6212
6237
 
6238
+ // remove table selection class if present
6239
+ if (attributes["class"] && clearInternals) {
6240
+ attributes["class"] = attributes["class"].replace("wysiwyg-tmp-selected-cell", "");
6241
+ if ((/^\s*$/g).test(attributes["class"])) {
6242
+ delete attributes.class;
6243
+ }
6244
+ }
6245
+
6213
6246
  if (styles.length) {
6214
6247
  attributes["style"] = wysihtml5.lang.array(styles).unique().join(" ");
6215
6248
  }
@@ -10827,7 +10860,7 @@ wysihtml5.commands.formatCode = {
10827
10860
  return wysihtml5.commands.insertList.state(composer, command, "UL");
10828
10861
  }
10829
10862
  };
10830
- ;wysihtml5.commands.insertList = (function() {
10863
+ ;wysihtml5.commands.insertList = (function(wysihtml5) {
10831
10864
 
10832
10865
  var isNode = function(node, name) {
10833
10866
  if (node && node.nodeName) {
@@ -10985,7 +11018,7 @@ wysihtml5.commands.formatCode = {
10985
11018
  }
10986
11019
  };
10987
11020
 
10988
- })();;wysihtml5.commands.italic = {
11021
+ })(wysihtml5);;wysihtml5.commands.italic = {
10989
11022
  exec: function(composer, command) {
10990
11023
  wysihtml5.commands.formatInline.execWithToggle(composer, command, "i");
10991
11024
  },
@@ -11451,7 +11484,7 @@ wysihtml5.commands.formatCode = {
11451
11484
 
11452
11485
  transact: function() {
11453
11486
  var previousHtml = this.historyStr[this.position - 1],
11454
- currentHtml = this.composer.getValue();
11487
+ currentHtml = this.composer.getValue(false, false);
11455
11488
 
11456
11489
  if (currentHtml === previousHtml) {
11457
11490
  return;
@@ -11654,11 +11687,10 @@ wysihtml5.views.View = Base.extend(
11654
11687
  this.element.innerHTML = browser.displaysCaretInEmptyContentEditableCorrectly() ? "" : this.CARET_HACK;
11655
11688
  },
11656
11689
 
11657
- getValue: function(parse) {
11690
+ getValue: function(parse, clearInternals) {
11658
11691
  var value = this.isEmpty() ? "" : wysihtml5.quirks.getCorrectInnerHTML(this.element);
11659
-
11660
- if (parse) {
11661
- value = this.parent.parse(value);
11692
+ if (parse !== false) {
11693
+ value = this.parent.parse(value, (clearInternals === false) ? false : true);
11662
11694
  }
11663
11695
 
11664
11696
  return value;
@@ -11795,7 +11827,7 @@ wysihtml5.views.View = Base.extend(
11795
11827
  this.element = (this.config.contentEditableMode) ? this.sandbox.getContentEditable() : this.doc.body;
11796
11828
  if (!this.config.noTextarea) {
11797
11829
  this.textarea = this.parent.textarea;
11798
- this.element.innerHTML = this.textarea.getValue(true);
11830
+ this.element.innerHTML = this.textarea.getValue(true, false);
11799
11831
  } else {
11800
11832
  this.cleanUp(); // cleans contenteditable on initiation as it may contain html
11801
11833
  }
@@ -12374,7 +12406,7 @@ wysihtml5.views.View = Base.extend(
12374
12406
 
12375
12407
  wysihtml5.views.Composer.prototype.observe = function() {
12376
12408
  var that = this,
12377
- state = this.getValue(),
12409
+ state = this.getValue(false, false),
12378
12410
  container = (this.sandbox.getIframe) ? this.sandbox.getIframe() : this.sandbox.getContentEditable(),
12379
12411
  element = this.element,
12380
12412
  focusBlurElement = (browser.supportsEventsInIframeCorrectly() || this.sandbox.getContentEditable) ? element : this.sandbox.getWindow(),
@@ -12422,11 +12454,11 @@ wysihtml5.views.View = Base.extend(
12422
12454
 
12423
12455
  // Delay storing of state until all focus handler are fired
12424
12456
  // especially the one which resets the placeholder
12425
- setTimeout(function() { state = that.getValue(); }, 0);
12457
+ setTimeout(function() { state = that.getValue(false, false); }, 0);
12426
12458
  });
12427
12459
 
12428
12460
  dom.observe(focusBlurElement, "blur", function() {
12429
- if (state !== that.getValue()) {
12461
+ if (state !== that.getValue(false, false)) {
12430
12462
  that.parent.fire("change").fire("change:composer");
12431
12463
  }
12432
12464
  that.parent.fire("blur").fire("blur:composer");
@@ -12603,7 +12635,7 @@ wysihtml5.views.View = Base.extend(
12603
12635
  * @param {Boolean} shouldParseHtml Whether the html should be sanitized before inserting it into the textarea
12604
12636
  */
12605
12637
  fromComposerToTextarea: function(shouldParseHtml) {
12606
- this.textarea.setValue(wysihtml5.lang.string(this.composer.getValue()).trim(), shouldParseHtml);
12638
+ this.textarea.setValue(wysihtml5.lang.string(this.composer.getValue(false, false)).trim(), shouldParseHtml);
12607
12639
  },
12608
12640
 
12609
12641
  /**
@@ -12612,7 +12644,7 @@ wysihtml5.views.View = Base.extend(
12612
12644
  * @param {Boolean} shouldParseHtml Whether the html should be sanitized before inserting it into the composer
12613
12645
  */
12614
12646
  fromTextareaToComposer: function(shouldParseHtml) {
12615
- var textareaValue = this.textarea.getValue();
12647
+ var textareaValue = this.textarea.getValue(false, false);
12616
12648
  if (textareaValue) {
12617
12649
  this.composer.setValue(textareaValue, shouldParseHtml);
12618
12650
  } else {
@@ -12693,7 +12725,7 @@ wysihtml5.views.View = Base.extend(
12693
12725
 
12694
12726
  getValue: function(parse) {
12695
12727
  var value = this.isEmpty() ? "" : this.element.value;
12696
- if (parse) {
12728
+ if (parse !== false) {
12697
12729
  value = this.parent.parse(value);
12698
12730
  }
12699
12731
  return value;
@@ -12878,8 +12910,8 @@ wysihtml5.views.View = Base.extend(
12878
12910
  return this;
12879
12911
  },
12880
12912
 
12881
- getValue: function(parse) {
12882
- return this.currentView.getValue(parse);
12913
+ getValue: function(parse, clearInternals) {
12914
+ return this.currentView.getValue(parse, clearInternals);
12883
12915
  },
12884
12916
 
12885
12917
  setValue: function(html, parse) {
@@ -12926,13 +12958,14 @@ wysihtml5.views.View = Base.extend(
12926
12958
  return this.currentView.hasPlaceholderSet();
12927
12959
  },
12928
12960
 
12929
- parse: function(htmlOrElement) {
12930
- var parseContext = (this.config.contentEditableMode) ? document : this.composer.sandbox.getDocument();
12961
+ parse: function(htmlOrElement, clearInternals) {
12962
+ var parseContext = (this.config.contentEditableMode) ? document : ((this.composer) ? this.composer.sandbox.getDocument() : null);
12931
12963
  var returnValue = this.config.parser(htmlOrElement, {
12932
12964
  "rules": this.config.parserRules,
12933
12965
  "cleanUp": this.config.cleanUp,
12934
12966
  "context": parseContext,
12935
- "uneditableClass": this.config.uneditableContainerClassname
12967
+ "uneditableClass": this.config.uneditableContainerClassname,
12968
+ "clearInternals" : clearInternals
12936
12969
  });
12937
12970
  if (typeof(htmlOrElement) === "object") {
12938
12971
  wysihtml5.quirks.redraw(htmlOrElement);
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wysihtml5x-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.8
4
+ version: 0.4.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tanel Jakobsoo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-09 00:00:00.000000000 Z
11
+ date: 2014-06-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties