diff --git a/lib/rangy-classapplier.js b/lib/rangy-classapplier.js index e3cdc6da..6a87c5ad 100644 --- a/lib/rangy-classapplier.js +++ b/lib/rangy-classapplier.js @@ -9,8 +9,8 @@ * * Copyright 2015, Tim Down * Licensed under the MIT license. - * Version: 1.3.0-alpha.20150122 - * Build date: 10 February 2015 + * Version: 1.3.0-beta.1 + * Build date: 12 February 2015 */ (function(factory, root) { if (typeof define == "function" && define.amd) { @@ -102,6 +102,16 @@ return getSortedClassName(el1) == getSortedClassName(el2); } + function hasAllClasses(el, className) { + var classes = className.split(/\s+/); + for (var i = 0, len = classes.length; i < len; ++i) { + if (!hasClass(el, trim(classes[i]))) { + return false; + } + } + return true; + } + function movePosition(position, oldParent, oldIndex, newParent, newIndex) { var posNode = position.node, posOffset = position.offset; var newNode = posNode, newOffset = posOffset; @@ -412,7 +422,7 @@ var getPreviousMergeableTextNode = createAdjacentMergeableTextNodeGetter(false), getNextMergeableTextNode = createAdjacentMergeableTextNodeGetter(true); - + function Merge(firstNode) { this.isElementMerge = (firstNode.nodeType == 1); this.textNodes = []; @@ -614,7 +624,7 @@ copyAttributesToElement: function(attrs, el) { for (var attrName in attrs) { - if (attrs.hasOwnProperty(attrName)) { + if (attrs.hasOwnProperty(attrName) && !/^class(?:Name)?$/i.test(attrName)) { el.setAttribute(attrName, attrs[attrName]); } } @@ -726,7 +736,11 @@ var applier = this; return each(props, function(p, propValue) { if (p == "className") { - return sortClassName(el.className) == applier.elementSortedClassName; + // For checking whether we should reuse an existing element, we just want to check that the element + // has all the classes specified in the className property. When deciding whether the element is + // removable when unapplying a class, there is separate special handling to check whether the + // element has extra classes so the same simple check will do. + return hasAllClasses(el, propValue); } else if (typeof propValue == "object") { if (!applier.elementHasProperties(el[p], propValue)) { return false; @@ -933,8 +947,6 @@ // Remove class from any appropriate empty elements var emptyElements = applier.getEmptyElements(range); - console.log(emptyElements); - forEach(emptyElements, function(el) { removeClass(el, applier.className); }); @@ -1032,6 +1044,7 @@ addClass: addClass, removeClass: removeClass, hasSameClasses: haveSameClasses, + hasAllClasses: hasAllClasses, replaceWithOwnChildren: replaceWithOwnChildrenPreservingPositions, elementsHaveSameNonClassAttributes: elementsHaveSameNonClassAttributes, elementHasNonClassAttributes: elementHasNonClassAttributes, @@ -1044,6 +1057,6 @@ api.CssClassApplier = api.ClassApplier = ClassApplier; api.createCssClassApplier = api.createClassApplier = createClassApplier; }); - + return rangy; }, this); diff --git a/lib/rangy-core.js b/lib/rangy-core.js index 2a60da14..f8b7eea6 100644 --- a/lib/rangy-core.js +++ b/lib/rangy-core.js @@ -4,8 +4,8 @@ * * Copyright 2015, Tim Down * Licensed under the MIT license. - * Version: 1.3.0-alpha.20150122 - * Build date: 10 February 2015 + * Version: 1.3.0-beta.1 + * Build date: 12 February 2015 */ (function(factory, root) { @@ -109,7 +109,7 @@ }; var api = { - version: "1.3.0-alpha.20150122", + version: "1.3.0-beta.1", initialized: false, isBrowser: isBrowser, supported: true, diff --git a/lib/rangy-highlighter.js b/lib/rangy-highlighter.js index de40cb1b..7445931d 100644 --- a/lib/rangy-highlighter.js +++ b/lib/rangy-highlighter.js @@ -6,8 +6,8 @@ * * Copyright 2015, Tim Down * Licensed under the MIT license. - * Version: 1.3.0-alpha.20150122 - * Build date: 10 February 2015 + * Version: 1.3.0-beta.1 + * Build date: 12 February 2015 */ (function(factory, root) { if (typeof define == "function" && define.amd) { diff --git a/lib/rangy-selectionsaverestore.js b/lib/rangy-selectionsaverestore.js index 5842896b..97ec1492 100644 --- a/lib/rangy-selectionsaverestore.js +++ b/lib/rangy-selectionsaverestore.js @@ -9,8 +9,8 @@ * * Copyright 2015, Tim Down * Licensed under the MIT license. - * Version: 1.3.0-alpha.20150122 - * Build date: 10 February 2015 + * Version: 1.3.0-beta.1 + * Build date: 12 February 2015 */ (function(factory, root) { if (typeof define == "function" && define.amd) { diff --git a/lib/rangy-serializer.js b/lib/rangy-serializer.js index 496cc90b..4a83cc6b 100644 --- a/lib/rangy-serializer.js +++ b/lib/rangy-serializer.js @@ -10,8 +10,8 @@ * * Copyright 2015, Tim Down * Licensed under the MIT license. - * Version: 1.3.0-alpha.20150122 - * Build date: 10 February 2015 + * Version: 1.3.0-beta.1 + * Build date: 12 February 2015 */ (function(factory, root) { if (typeof define == "function" && define.amd) { diff --git a/lib/rangy-textrange.js b/lib/rangy-textrange.js index fc1bfa10..e0265d1c 100644 --- a/lib/rangy-textrange.js +++ b/lib/rangy-textrange.js @@ -26,8 +26,8 @@ * * Copyright 2015, Tim Down * Licensed under the MIT license. - * Version: 1.3.0-alpha.20150122 - * Build date: 10 February 2015 + * Version: 1.3.0-beta.1 + * Build date: 12 February 2015 */ /**