Skip to content

Commit

Permalink
Update version to 0.4.9
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliver Pulges committed Jun 17, 2014
1 parent 094f2ba commit df24a8e
Show file tree
Hide file tree
Showing 9 changed files with 172 additions and 98 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.textile
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
*wysihtml5x 0.4.9* (June 17, 2014)
* Prevent possible errors when uneditable element is passed through in parser
* getValue api changed so passing no parameter will parse and remove all possible internals on result. Takes two parameters getValue(true /* parse content */, true /* ensure removal of all internals and selection markers */)

*wysihtml5x 0.4.8* (June 9, 2014)
*Improvements in list indent outdent handling
* Add insertBlockQuote command and remove blockquote creation from formatBlock

*wysihtml5x 0.4.7* (June 2, 2014)
* Fixes mayor bug that prevents deleting some elements.

Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wysihtml5x",
"version": "0.4.8",
"version": "0.4.9",
"main": [
"dist/wysihtml5x.min.js",
"dist/wysihtml5x-toolbar.min.js"
Expand Down
115 changes: 74 additions & 41 deletions dist/wysihtml5x-toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ if(!Array.isArray) {
return Object.prototype.toString.call(arg) === '[object Array]';
};
};/**
* @license wysihtml5x v0.4.8
* @license wysihtml5x v0.4.9
* https://github.com/Edicy/wysihtml5
*
* Author: Christopher Blum (https://github.com/tiff)
Expand All @@ -36,7 +36,7 @@ if(!Array.isArray) {
*
*/
var wysihtml5 = {
version: "0.4.8",
version: "0.4.9",

// namespaces
commands: {},
Expand Down Expand Up @@ -5813,10 +5813,15 @@ wysihtml5.dom.parse = (function() {
var context = config.context || elementOrHtml.ownerDocument || document,
fragment = context.createDocumentFragment(),
isString = typeof(elementOrHtml) === "string",
clearInternals = false,
element,
newNode,
firstChild;

if (config.clearInternals === true) {
clearInternals = true;
}

if (config.uneditableClass) {
uneditableClass = config.uneditableClass;
}
Expand All @@ -5829,11 +5834,13 @@ wysihtml5.dom.parse = (function() {

while (element.firstChild) {
firstChild = element.firstChild;
newNode = _convert(firstChild, config.cleanUp);
element.removeChild(firstChild);
newNode = _convert(firstChild, config.cleanUp, clearInternals);
if (newNode) {
fragment.appendChild(newNode);
}
if (firstChild !== newNode) {
element.removeChild(firstChild);
}
}

// Clear element contents
Expand All @@ -5845,7 +5852,7 @@ wysihtml5.dom.parse = (function() {
return isString ? wysihtml5.quirks.getCorrectInnerHTML(element) : element;
}

function _convert(oldNode, cleanUp) {
function _convert(oldNode, cleanUp, clearInternals) {
var oldNodeType = oldNode.nodeType,
oldChilds = oldNode.childNodes,
oldChildsLength = oldChilds.length,
Expand All @@ -5855,21 +5862,28 @@ wysihtml5.dom.parse = (function() {
newNode,
newChild;

// Passes directly elemets with uneditable class
if (uneditableClass && oldNodeType === 1 && wysihtml5.dom.hasClass(oldNode, uneditableClass)) {
return oldNode;
}

newNode = method && method(oldNode);
newNode = method && method(oldNode, clearInternals);

// Remove or unwrap node in case of return value null or false
if (!newNode) {
if (newNode === false) {
// false defines that tag should be removed but contents should remain (unwrap)
fragment = oldNode.ownerDocument.createDocumentFragment();

for (i = oldChildsLength; i--;) {
newChild = _convert(oldChilds[i], cleanUp);
if (newChild) {
fragment.insertBefore(newChild, fragment.firstChild);
if (oldChilds[i]) {
newChild = _convert(oldChilds[i], cleanUp, clearInternals);
if (newChild) {
if (oldChilds[i] === newChild) {
i--;
}
fragment.insertBefore(newChild, fragment.firstChild);
}
}
}

Expand All @@ -5893,22 +5907,29 @@ wysihtml5.dom.parse = (function() {
}
return fragment;
} else {
return null;
// Remove
return null;
}
}

// Converts all childnodes
for (i=0; i<oldChildsLength; i++) {
newChild = _convert(oldChilds[i], cleanUp);
if (newChild) {
newNode.appendChild(newChild);
if (oldChilds[i]) {
newChild = _convert(oldChilds[i], cleanUp, clearInternals);
if (newChild) {
if (oldChilds[i] === newChild) {
i--;
}
newNode.appendChild(newChild);
}
}
}

// Cleanup senseless <span> elements
if (cleanUp &&
newNode.nodeName.toLowerCase() === DEFAULT_NODE_NAME &&
(!newNode.childNodes.length ||
((/^\s*$/gi).test(newNode.innerHTML) && oldNode.className !== "_wysihtml5-temp-placeholder" && oldNode.className !== "rangySelectionBoundary") ||
((/^\s*$/gi).test(newNode.innerHTML) && (clearInternals || (oldNode.className !== "_wysihtml5-temp-placeholder" && oldNode.className !== "rangySelectionBoundary"))) ||
!newNode.attributes.length)
) {
fragment = newNode.ownerDocument.createDocumentFragment();
Expand All @@ -5927,7 +5948,7 @@ wysihtml5.dom.parse = (function() {
return newNode;
}

function _handleElement(oldNode) {
function _handleElement(oldNode, clearInternals) {
var rule,
newNode,
tagRules = currentRules.tags,
Expand Down Expand Up @@ -5985,10 +6006,10 @@ wysihtml5.dom.parse = (function() {
}

newNode = oldNode.ownerDocument.createElement(rule.rename_tag || nodeName);
_handleAttributes(oldNode, newNode, rule);
_handleAttributes(oldNode, newNode, rule, clearInternals);
_handleStyles(oldNode, newNode, rule);
// tests if type condition is met or node should be removed/unwrapped
if (rule.one_of_type && !_testTypes(oldNode, currentRules, rule.one_of_type)) {
if (rule.one_of_type && !_testTypes(oldNode, currentRules, rule.one_of_type, clearInternals)) {
return (rule.remove_action && rule.remove_action == "unwrap") ? false : null;
}

Expand All @@ -5998,11 +6019,11 @@ wysihtml5.dom.parse = (function() {
return newNode;
}

function _testTypes(oldNode, rules, types) {
function _testTypes(oldNode, rules, types, clearInternals) {
var definition, type;

// do not interfere with placeholder span or pasting caret position is not maintained
if (oldNode.nodeName === "SPAN" && (oldNode.className === "_wysihtml5-temp-placeholder" || oldNode.className === "rangySelectionBoundary")) {
if (oldNode.nodeName === "SPAN" && !clearInternals && (oldNode.className === "_wysihtml5-temp-placeholder" || oldNode.className === "rangySelectionBoundary")) {
return true;
}

Expand Down Expand Up @@ -6112,7 +6133,8 @@ wysihtml5.dom.parse = (function() {
}
}

function _handleAttributes(oldNode, newNode, rule) {
// TODO: refactor. Too long to read
function _handleAttributes(oldNode, newNode, rule, clearInternals) {
var attributes = {}, // fresh new set of attributes to set on newNode
setClass = rule.set_class, // classes to set
addClass = rule.add_class, // add classes based on existing attributes
Expand Down Expand Up @@ -6189,8 +6211,11 @@ wysihtml5.dom.parse = (function() {
attributes["class"] = oldNode.getAttribute("class");
} else {
// make sure that wysihtml5 temp class doesn't get stripped out
allowedClasses["_wysihtml5-temp-placeholder"] = 1;
allowedClasses["_rangySelectionBoundary"] = 1;
if (!clearInternals) {
allowedClasses["_wysihtml5-temp-placeholder"] = 1;
allowedClasses["_rangySelectionBoundary"] = 1;
allowedClasses["wysiwyg-tmp-selected-cell"] = 1;
}

// add old classes last
oldClasses = oldNode.getAttribute("class");
Expand All @@ -6210,6 +6235,14 @@ wysihtml5.dom.parse = (function() {
}
}

// remove table selection class if present
if (attributes["class"] && clearInternals) {
attributes["class"] = attributes["class"].replace("wysiwyg-tmp-selected-cell", "");
if ((/^\s*$/g).test(attributes["class"])) {
delete attributes.class;
}
}

if (styles.length) {
attributes["style"] = wysihtml5.lang.array(styles).unique().join(" ");
}
Expand Down Expand Up @@ -10827,7 +10860,7 @@ wysihtml5.commands.formatCode = {
return wysihtml5.commands.insertList.state(composer, command, "UL");
}
};
;wysihtml5.commands.insertList = (function() {
;wysihtml5.commands.insertList = (function(wysihtml5) {

var isNode = function(node, name) {
if (node && node.nodeName) {
Expand Down Expand Up @@ -10985,7 +11018,7 @@ wysihtml5.commands.formatCode = {
}
};

})();;wysihtml5.commands.italic = {
})(wysihtml5);;wysihtml5.commands.italic = {
exec: function(composer, command) {
wysihtml5.commands.formatInline.execWithToggle(composer, command, "i");
},
Expand Down Expand Up @@ -11451,7 +11484,7 @@ wysihtml5.commands.formatCode = {

transact: function() {
var previousHtml = this.historyStr[this.position - 1],
currentHtml = this.composer.getValue();
currentHtml = this.composer.getValue(false, false);

if (currentHtml === previousHtml) {
return;
Expand Down Expand Up @@ -11654,11 +11687,10 @@ wysihtml5.views.View = Base.extend(
this.element.innerHTML = browser.displaysCaretInEmptyContentEditableCorrectly() ? "" : this.CARET_HACK;
},

getValue: function(parse) {
getValue: function(parse, clearInternals) {
var value = this.isEmpty() ? "" : wysihtml5.quirks.getCorrectInnerHTML(this.element);

if (parse) {
value = this.parent.parse(value);
if (parse !== false) {
value = this.parent.parse(value, (clearInternals === false) ? false : true);
}

return value;
Expand Down Expand Up @@ -11795,7 +11827,7 @@ wysihtml5.views.View = Base.extend(
this.element = (this.config.contentEditableMode) ? this.sandbox.getContentEditable() : this.doc.body;
if (!this.config.noTextarea) {
this.textarea = this.parent.textarea;
this.element.innerHTML = this.textarea.getValue(true);
this.element.innerHTML = this.textarea.getValue(true, false);
} else {
this.cleanUp(); // cleans contenteditable on initiation as it may contain html
}
Expand Down Expand Up @@ -12374,7 +12406,7 @@ wysihtml5.views.View = Base.extend(

wysihtml5.views.Composer.prototype.observe = function() {
var that = this,
state = this.getValue(),
state = this.getValue(false, false),
container = (this.sandbox.getIframe) ? this.sandbox.getIframe() : this.sandbox.getContentEditable(),
element = this.element,
focusBlurElement = (browser.supportsEventsInIframeCorrectly() || this.sandbox.getContentEditable) ? element : this.sandbox.getWindow(),
Expand Down Expand Up @@ -12422,11 +12454,11 @@ wysihtml5.views.View = Base.extend(

// Delay storing of state until all focus handler are fired
// especially the one which resets the placeholder
setTimeout(function() { state = that.getValue(); }, 0);
setTimeout(function() { state = that.getValue(false, false); }, 0);
});

dom.observe(focusBlurElement, "blur", function() {
if (state !== that.getValue()) {
if (state !== that.getValue(false, false)) {
that.parent.fire("change").fire("change:composer");
}
that.parent.fire("blur").fire("blur:composer");
Expand Down Expand Up @@ -12603,7 +12635,7 @@ wysihtml5.views.View = Base.extend(
* @param {Boolean} shouldParseHtml Whether the html should be sanitized before inserting it into the textarea
*/
fromComposerToTextarea: function(shouldParseHtml) {
this.textarea.setValue(wysihtml5.lang.string(this.composer.getValue()).trim(), shouldParseHtml);
this.textarea.setValue(wysihtml5.lang.string(this.composer.getValue(false, false)).trim(), shouldParseHtml);
},

/**
Expand All @@ -12612,7 +12644,7 @@ wysihtml5.views.View = Base.extend(
* @param {Boolean} shouldParseHtml Whether the html should be sanitized before inserting it into the composer
*/
fromTextareaToComposer: function(shouldParseHtml) {
var textareaValue = this.textarea.getValue();
var textareaValue = this.textarea.getValue(false, false);
if (textareaValue) {
this.composer.setValue(textareaValue, shouldParseHtml);
} else {
Expand Down Expand Up @@ -12693,7 +12725,7 @@ wysihtml5.views.View = Base.extend(

getValue: function(parse) {
var value = this.isEmpty() ? "" : this.element.value;
if (parse) {
if (parse !== false) {
value = this.parent.parse(value);
}
return value;
Expand Down Expand Up @@ -12878,8 +12910,8 @@ wysihtml5.views.View = Base.extend(
return this;
},

getValue: function(parse) {
return this.currentView.getValue(parse);
getValue: function(parse, clearInternals) {
return this.currentView.getValue(parse, clearInternals);
},

setValue: function(html, parse) {
Expand Down Expand Up @@ -12926,13 +12958,14 @@ wysihtml5.views.View = Base.extend(
return this.currentView.hasPlaceholderSet();
},

parse: function(htmlOrElement) {
var parseContext = (this.config.contentEditableMode) ? document : this.composer.sandbox.getDocument();
parse: function(htmlOrElement, clearInternals) {
var parseContext = (this.config.contentEditableMode) ? document : ((this.composer) ? this.composer.sandbox.getDocument() : null);
var returnValue = this.config.parser(htmlOrElement, {
"rules": this.config.parserRules,
"cleanUp": this.config.cleanUp,
"context": parseContext,
"uneditableClass": this.config.uneditableContainerClassname
"uneditableClass": this.config.uneditableContainerClassname,
"clearInternals" : clearInternals
});
if (typeof(htmlOrElement) === "object") {
wysihtml5.quirks.redraw(htmlOrElement);
Expand Down
12 changes: 6 additions & 6 deletions dist/wysihtml5x-toolbar.min.js

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

Loading

0 comments on commit df24a8e

Please sign in to comment.