Skip to content

Commit

Permalink
Merge pull request #1756 from BladeRunnerJS/1755/bugfix-ensuresvg-ele…
Browse files Browse the repository at this point in the history
…ments-work-in-IE11

1755/bugfix ensure svg elements work in ie11
  • Loading branch information
thecapdan authored Dec 12, 2016
2 parents 5f82de2 + 7be8c84 commit 69b027a
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ ElementUtility.getElementsByClassName = function(domElement, tagName, className)
* @returns {DOMElement} The ancestor element with the specified class, or null.
*/
ElementUtility.getAncestorElementWithClass = function(element, className) {
while (!element.className || !element.classList.contains(className)) {
while (!element.className || !elementHasClass(element, className)) {
if (!element.parentNode) {
return null;
}
Expand All @@ -163,6 +163,15 @@ ElementUtility.getAncestorElementWithClass = function(element, className) {
return element;
};

/** @private */
function elementHasClass(element, className) {
if(element.classList != null) {
return element.classList.contains(className);
}
//SVGs in IE11:
return element.getAttribute("class") != null && element.getAttribute("class").indexOf(className) > -1;
}

/**
* Returns the node index of the element as it exists in the parent.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,61 @@
(function() {
var ElementUtility = require('br/util/ElementUtility');

ElementUtilityTest = TestCase('ElementUtilityTest');
var testCaseName = 'ElementUtilityTest';
var testCase = {
'test #setNodeText sets the text contents on an empty element': function() {
var element = document.createElement('DIV');

ElementUtilityTest.prototype.test_setNodeText_SetsTheTextContentsOnAEmptyElement = function() {
var element = document.createElement('DIV');
ElementUtility.setNodeText(element, 'foo');

ElementUtility.setNodeText(element, 'foo');
assertEquals(element.innerHTML, 'foo');
},

assertEquals(element.innerHTML, 'foo');
};
'test #setNodeText sets the text contents on a non empty element': function() {
var element = document.createElement('DIV');
element.innerHTML = 'bar';

ElementUtility.setNodeText(element, 'foo');

assertEquals(element.innerHTML, 'foo');
},

'test #getAncestorElementWithClass returns current element when it has matching class': function() {
var element = document.createElement('DIV');
element.className = "myClass";

var returnElement = ElementUtility.getAncestorElementWithClass(element, "myClass");

assertEquals(element, returnElement);
},

'test #getAncestorElementWithClass returns current element when it has multiple classes including the matching class': function() {
var element = document.createElement('DIV');
element.className = "myClass myOtherClass";

ElementUtilityTest.prototype.test_setNodeText_SetsTheTextContentsOnANonEmptyElement = function() {
var element = document.createElement('DIV');
element.innerHTML = 'bar';
var returnElement = ElementUtility.getAncestorElementWithClass(element, "myClass");

ElementUtility.setNodeText(element, 'foo');
assertEquals(element, returnElement);
},

'test #getAncestorElementWithClass returns null when using an svg element with no class': function() {
var element = document.createElementNS("http://www.w3.org/2000/svg", "svg");

var returnElement = ElementUtility.getAncestorElementWithClass(element, "myClass");

assertEquals(null, returnElement);
},

'test #getAncestorElementWithClass returns current element when using an svg element containing the matching class': function() {
var element = document.createElementNS("http://www.w3.org/2000/svg", "svg");
element.setAttribute("class", "myClass myOtherClass");

var returnElement = ElementUtility.getAncestorElementWithClass(element, "myOtherClass");

assertEquals(element, returnElement);
}

assertEquals(element.innerHTML, 'foo');
};

return new TestCase(testCaseName, testCase);
})();
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions releases/v1.5.8.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"milestone": "1.5.8",
"name": "BladeRunnerJS 1.5.8",
"prerelease": false
}
7 changes: 7 additions & 0 deletions releases/v1.5.8.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## BladeRunnerJS @tagVersion@

BladeRunnerJS @tagVersion@ contains one minor bug fix.

### Bug Fixes

- Fixed a bug where ElementUtility would throw an error in IE11 when using SVG elements

0 comments on commit 69b027a

Please sign in to comment.