Skip to content

Commit c63baa0

Browse files
author
Oliver Pulges
committed
Update version to 0.5.0
1 parent d730a1f commit c63baa0

File tree

3 files changed

+147
-157
lines changed

3 files changed

+147
-157
lines changed

lib/wysihtml/rails/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module Wysihtml
22
module Rails
3-
VERSION = "0.5.0.beta14"
3+
VERSION = "0.5.0"
44
end
55
end

vendor/assets/javascripts/wysihtml-toolbar.js

Lines changed: 73 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* @license wysihtml v0.5.0-beta14
2+
* @license wysihtml v0.5.0
33
* https://github.com/Voog/wysihtml
44
*
55
* Author: Christopher Blum (https://github.com/tiff)
@@ -10,7 +10,7 @@
1010
*
1111
*/
1212
var wysihtml5 = {
13-
version: "0.5.0-beta14",
13+
version: "0.5.0",
1414

1515
// namespaces
1616
commands: {},
@@ -7040,7 +7040,7 @@ wysihtml5.browser = (function() {
70407040
Should actually check for clipboardData on paste event, but cannot in firefox
70417041
*/
70427042
supportsModernPaste: function () {
7043-
return !("clipboardData" in window);
7043+
return !isIE();
70447044
},
70457045

70467046
// Unifies the property names of element.style by returning the suitable property name for current browser
@@ -9140,27 +9140,31 @@ wysihtml5.dom.parse = function(elementOrHtml_current, config_current) {
91409140
}
91419141

91429142

9143-
if (typeof(allowedClasses) === "string" && allowedClasses === "any" && oldNode.getAttribute("class")) {
9144-
if (currentRules.classes_blacklist) {
9145-
oldClasses = oldNode.getAttribute("class");
9146-
if (oldClasses) {
9147-
classes = classes.concat(oldClasses.split(WHITE_SPACE_REG_EXP));
9148-
}
9143+
if (typeof(allowedClasses) === "string" && allowedClasses === "any") {
9144+
if (oldNode.getAttribute("class")) {
9145+
if (currentRules.classes_blacklist) {
9146+
oldClasses = oldNode.getAttribute("class");
9147+
if (oldClasses) {
9148+
classes = classes.concat(oldClasses.split(WHITE_SPACE_REG_EXP));
9149+
}
91499150

9150-
classesLength = classes.length;
9151-
for (; i<classesLength; i++) {
9152-
currentClass = classes[i];
9153-
if (!currentRules.classes_blacklist[currentClass]) {
9154-
newClasses.push(currentClass);
9151+
classesLength = classes.length;
9152+
for (; i<classesLength; i++) {
9153+
currentClass = classes[i];
9154+
if (!currentRules.classes_blacklist[currentClass]) {
9155+
newClasses.push(currentClass);
9156+
}
91559157
}
9156-
}
91579158

9158-
if (newClasses.length) {
9159-
attributes["class"] = wysihtml5.lang.array(newClasses).unique().join(" ");
9160-
}
9159+
if (newClasses.length) {
9160+
attributes["class"] = wysihtml5.lang.array(newClasses).unique().join(" ");
9161+
}
91619162

9163+
} else {
9164+
attributes["class"] = oldNode.getAttribute("class");
9165+
}
91629166
} else {
9163-
attributes["class"] = oldNode.getAttribute("class");
9167+
attributes["class"] = wysihtml5.lang.array(classes).unique().join(" ");
91649168
}
91659169
} else {
91669170
// make sure that wysihtml5 temp class doesn't get stripped out
@@ -10015,7 +10019,7 @@ wysihtml5.dom.replaceWithChildNodes = function(node) {
1001510019
set = function() {
1001610020
if (view.isEmpty() && !view.placeholderSet) {
1001710021
view.placeholderSet = true;
10018-
view.setValue(placeholderText);
10022+
view.setValue(placeholderText, false);
1001910023
dom.addClass(view.element, CLASS_NAME);
1002010024
}
1002110025
};
@@ -11120,7 +11124,7 @@ wysihtml5.dom.unwrap = function(node) {
1112011124
**/
1112111125
wysihtml5.dom.getPastedHtml = function(event) {
1112211126
var html;
11123-
if (event.clipboardData) {
11127+
if (wysihtml5.browser.supportsModernPaste() && event.clipboardData) {
1112411128
if (wysihtml5.lang.array(event.clipboardData.types).contains('text/html')) {
1112511129
html = event.clipboardData.getData('text/html');
1112611130
} else if (wysihtml5.lang.array(event.clipboardData.types).contains('text/plain')) {
@@ -11990,9 +11994,15 @@ wysihtml5.quirks.ensureProperClearing = (function() {
1199011994
// Deletes selection contents making sure uneditables/unselectables are not partially deleted
1199111995
// Triggers wysihtml5:uneditable:delete custom event on all deleted uneditables if customevents suppoorted
1199211996
deleteContents: function() {
11993-
var range = this.getRange(),
11994-
startParent, endParent, uneditables, ev;
11995-
11997+
var range = this.getRange();
11998+
this.deleteRangeContents(range);
11999+
this.setSelection(range);
12000+
},
12001+
12002+
// Makes sure all uneditable sare notified before deleting contents
12003+
deleteRangeContents: function (range) {
12004+
var startParent, endParent, uneditables, ev;
12005+
1199612006
if (this.unselectableClass) {
1199712007
if ((startParent = wysihtml5.dom.getParentElement(range.startContainer, { query: "." + this.unselectableClass }, false, this.contain))) {
1199812008
range.setStartBefore(startParent);
@@ -12011,10 +12021,8 @@ wysihtml5.quirks.ensureProperClearing = (function() {
1201112021
uneditables[i].dispatchEvent(ev);
1201212022
} catch (err) {}
1201312023
}
12014-
1201512024
}
1201612025
range.deleteContents();
12017-
this.setSelection(range);
1201812026
},
1201912027

1202012028
getPreviousNode: function(node, ignoreEmpty) {
@@ -12301,28 +12309,41 @@ wysihtml5.quirks.ensureProperClearing = (function() {
1230112309
},
1230212310

1230312311
/**
12304-
* Insert html at the caret position and move the cursor after the inserted html
12312+
* Insert html at the caret or selection position and move the cursor after the inserted html
12313+
* Replaces selection content if present
1230512314
*
1230612315
* @param {String} html HTML string to insert
1230712316
* @example
1230812317
* selection.insertHTML("<p>foobar</p>");
1230912318
*/
1231012319
insertHTML: function(html) {
12311-
var range = rangy.createRange(this.doc),
12320+
var range = this.getRange(),
1231212321
node = this.doc.createElement('DIV'),
1231312322
fragment = this.doc.createDocumentFragment(),
12314-
lastChild;
12315-
12316-
node.innerHTML = html;
12317-
lastChild = node.lastChild;
12323+
lastChild, lastEditorElement;
12324+
12325+
if (range) {
12326+
range.deleteContents();
12327+
node.innerHTML = html;
12328+
lastChild = node.lastChild;
1231812329

12319-
while (node.firstChild) {
12320-
fragment.appendChild(node.firstChild);
12321-
}
12322-
this.insertNode(fragment);
12330+
while (node.firstChild) {
12331+
fragment.appendChild(node.firstChild);
12332+
}
12333+
range.insertNode(fragment);
12334+
12335+
lastEditorElement = this.contain.lastChild;
12336+
while (lastEditorElement && lastEditorElement.nodeType === 3 && lastEditorElement.previousSibling && (/^\s*$/).test(lastEditorElement.data)) {
12337+
lastEditorElement = lastEditorElement.previousSibling;
12338+
}
1232312339

12324-
if (lastChild) {
12325-
this.setAfter(lastChild);
12340+
if (lastChild) {
12341+
// fixes some pad cases mostly on webkit where last nr is needed
12342+
if (lastEditorElement && lastChild === lastEditorElement && lastChild.nodeType === 1) {
12343+
this.contain.appendChild(this.doc.createElement('br'));
12344+
}
12345+
this.setAfter(lastChild);
12346+
}
1232612347
}
1232712348
},
1232812349

@@ -15100,11 +15121,7 @@ wysihtml5.Commands = Base.extend(
1510015121
;(function(wysihtml5){
1510115122
wysihtml5.commands.insertHTML = {
1510215123
exec: function(composer, command, html) {
15103-
if (composer.commands.support(command)) {
15104-
composer.doc.execCommand(command, false, html);
15105-
} else {
1510615124
composer.selection.insertHTML(html);
15107-
}
1510815125
},
1510915126

1511015127
state: function() {
@@ -15226,14 +15243,7 @@ wysihtml5.Commands = Base.extend(
1522615243

1522715244
wysihtml5.commands.insertLineBreak = {
1522815245
exec: function(composer, command) {
15229-
if (composer.commands.support(command)) {
15230-
composer.doc.execCommand(command, false, null);
15231-
if (!wysihtml5.browser.autoScrollsToCaret()) {
15232-
composer.selection.scrollIntoView();
15233-
}
15234-
} else {
15235-
composer.commands.exec("insertHTML", LINE_BREAK);
15236-
}
15246+
composer.selection.insertHTML(LINE_BREAK);
1523715247
},
1523815248

1523915249
state: function() {
@@ -16195,9 +16205,6 @@ wysihtml5.views.View = Base.extend(
1619516205
/** @scope wysihtml5.views.Composer.prototype */ {
1619616206
name: "composer",
1619716207

16198-
// Needed for firefox in order to display a proper caret in an empty contentEditable
16199-
CARET_HACK: "<br>",
16200-
1620116208
constructor: function(parent, editableElement, config) {
1620216209
this.base(parent, editableElement, config);
1620316210
if (!this.config.noTextarea) {
@@ -16213,20 +16220,19 @@ wysihtml5.views.View = Base.extend(
1621316220
},
1621416221

1621516222
clear: function() {
16216-
this.element.innerHTML = browser.displaysCaretInEmptyContentEditableCorrectly() ? "" : this.CARET_HACK;
16223+
this.element.innerHTML = browser.displaysCaretInEmptyContentEditableCorrectly() ? "" : "<br>";
1621716224
},
1621816225

1621916226
getValue: function(parse, clearInternals) {
1622016227
var value = this.isEmpty() ? "" : wysihtml5.quirks.getCorrectInnerHTML(this.element);
1622116228
if (parse !== false) {
1622216229
value = this.parent.parse(value, (clearInternals === false) ? false : true);
1622316230
}
16224-
1622516231
return value;
1622616232
},
1622716233

1622816234
setValue: function(html, parse) {
16229-
if (parse) {
16235+
if (parse !== false) {
1623016236
html = this.parent.parse(html);
1623116237
}
1623216238

@@ -16237,12 +16243,12 @@ wysihtml5.views.View = Base.extend(
1623716243
}
1623816244
},
1623916245

16240-
cleanUp: function() {
16246+
cleanUp: function(rules) {
1624116247
var bookmark;
1624216248
if (this.selection) {
1624316249
bookmark = rangy.saveSelection(this.win);
1624416250
}
16245-
this.parent.parse(this.element);
16251+
this.parent.parse(this.element, undefined, rules);
1624616252
if (bookmark) {
1624716253
rangy.restoreSelection(bookmark);
1624816254
}
@@ -16630,17 +16636,6 @@ wysihtml5.views.View = Base.extend(
1663016636
});
1663116637
}
1663216638

16633-
// Under certain circumstances Chrome + Safari create nested <p> or <hX> tags after paste
16634-
// Inserting an invisible white space in front of it fixes the issue
16635-
// This is too hacky and causes selection not to replace content on paste in chrome
16636-
/* if (browser.createsNestedInvalidMarkupAfterPaste()) {
16637-
dom.observe(this.element, "paste", function(event) {
16638-
var invisibleSpace = that.doc.createTextNode(wysihtml5.INVISIBLE_SPACE);
16639-
that.selection.insertNode(invisibleSpace);
16640-
});
16641-
}*/
16642-
16643-
1664416639
dom.observe(this.element, "keydown", function(event) {
1664516640
var keyCode = event.keyCode;
1664616641

@@ -17087,7 +17082,7 @@ wysihtml5.views.View = Base.extend(
1708717082
if (this.config.copyedFromMarking) {
1708817083
// If supported the copied source can be based directly on selection
1708917084
// Very useful for webkit based browsers where copy will otherwise contain a lot of code and styles based on whatever and not actually in selection.
17090-
if (event.clipboardData) {
17085+
if (wysihtml5.browser.supportsModernPaste()) {
1709117086
event.clipboardData.setData("text/html", this.config.copyedFromMarking + this.selection.getHtml());
1709217087
event.clipboardData.setData("text/plain", this.selection.getPlainText());
1709317088
event.preventDefault();
@@ -17466,14 +17461,14 @@ wysihtml5.views.View = Base.extend(
1746617461
},
1746717462

1746817463
setValue: function(html, parse) {
17469-
if (parse) {
17464+
if (parse !== false) {
1747017465
html = this.parent.parse(html);
1747117466
}
1747217467
this.element.value = html;
1747317468
},
1747417469

17475-
cleanUp: function() {
17476-
var html = this.parent.parse(this.element.value);
17470+
cleanUp: function(rules) {
17471+
var html = this.parent.parse(this.element.value, undefined, rules);
1747717472
this.element.value = html;
1747817473
},
1747917474

@@ -17568,7 +17563,7 @@ wysihtml5.views.View = Base.extend(
1756817563
handleTabKey: true,
1756917564
// Object which includes parser rules to apply when html gets cleaned
1757017565
// See parser_rules/*.js for examples
17571-
parserRules: { tags: { br: {}, span: {}, div: {}, p: {} }, classes: {} },
17566+
parserRules: { tags: { br: {}, span: {}, div: {}, p: {}, b: {}, i: {}, u: {} }, classes: {} },
1757217567
// Object which includes parser when the user inserts content via copy & paste. If null parserRules will be used instead
1757317568
pasteParserRulesets: null,
1757417569
// Parser method to use when the user inserts content
@@ -17680,8 +17675,8 @@ wysihtml5.views.View = Base.extend(
1768017675
return this;
1768117676
},
1768217677

17683-
cleanUp: function() {
17684-
this.currentView.cleanUp();
17678+
cleanUp: function(rules) {
17679+
this.currentView.cleanUp(rules);
1768517680
},
1768617681

1768717682
focus: function(setToEnd) {
@@ -17723,10 +17718,10 @@ wysihtml5.views.View = Base.extend(
1772317718
this.off();
1772417719
},
1772517720

17726-
parse: function(htmlOrElement, clearInternals) {
17721+
parse: function(htmlOrElement, clearInternals, customRules) {
1772717722
var parseContext = (this.config.contentEditableMode) ? document : ((this.composer) ? this.composer.sandbox.getDocument() : null);
1772817723
var returnValue = this.config.parser(htmlOrElement, {
17729-
"rules": this.config.parserRules,
17724+
"rules": customRules || this.config.parserRules,
1773017725
"cleanUp": this.config.cleanUp,
1773117726
"context": parseContext,
1773217727
"uneditableClass": this.config.classNames.uneditableContainer,

0 commit comments

Comments
 (0)