Skip to content

Commit

Permalink
Merge branch 'develop' into gh-pages
Browse files Browse the repository at this point in the history
* develop:
  v3.2.132
  chore(package): update nightmare to version 2.5.0
  Chore(CHANGELOG): added change log file
  Fix(ui,utils): firstElementChild not in Edge (closes #798)
  • Loading branch information
marcoscaceres committed May 27, 2016
2 parents 1bb19d8 + 89fcab9 commit 45b7480
Show file tree
Hide file tree
Showing 7 changed files with 1,775 additions and 12 deletions.
1,727 changes: 1,727 additions & 0 deletions CHANGELOG.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion builds/respec-w3c-common.build.js.map

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions builds/respec-w3c-common.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/core/ui.js
Expand Up @@ -132,7 +132,7 @@ define(
})
.appendTo($div)
;
doc.firstElementChild.addEventListener("click", function(){
doc.documentElement.addEventListener("click", function(){
if(window.getComputedStyle($menu[0]).display === "block"){
$menu.fadeOut(200);
}
Expand Down
28 changes: 25 additions & 3 deletions js/core/utils.js
Expand Up @@ -34,13 +34,35 @@ define(
return function(doc, insertionPoint) {
node.remove();
doc.adoptNode(node);
if (insertionPoint.firstElementChild) {
insertionPoint.insertBefore(node, insertionPoint.firstElementChild);
var firstElementChild = this.findFirstElementChild(insertionPoint);
if (firstElementChild) {
insertionPoint.insertBefore(node, firstElementChild);
return;
}
insertionPoint.appendChild(node);
};
}.bind(this);
}
/**
* Finds the first Element child, given a node. Provides support for
* Microsoft Edge's missing support of .firstElementChild.
*
* @param {Node} node The node to be traversed.
* @return {Element} The first Element in the child list.
*/
, findFirstElementChild: function(node){
if(!node.hasChildNodes()){
return null;
}
// We have native support
if(node.firstElementChild){
return node.firstElementChild;
}
return Array
.from(node.childNodes)
.find(function(node){
return node.nodeType === Node.ELEMENT_NODE;
});
}
, calculateLeftPad: function(text) {
if (typeof text !== "string") {
throw new TypeError("Invalid input");
Expand Down
4 changes: 2 additions & 2 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "respec",
"version": "3.2.131",
"version": "3.2.132",
"license": "W3C",
"description": "Specification Edition Support Tool.",
"engines": {
Expand Down Expand Up @@ -48,7 +48,7 @@
"mocha": "^2.5.3",
"moment": "^2.13.0",
"mozilla-download": "^1.1.1",
"nightmare": "^2.4.1",
"nightmare": "^2.5.0",
"promise-polyfill": "^5.2.0",
"prompt": "^1.0.0",
"requirejs": "^2.2.0",
Expand Down
14 changes: 14 additions & 0 deletions tests/spec/core/utils-spec.js
Expand Up @@ -98,6 +98,20 @@ describe("Core - Utils", function() {
});
});

describe("findFirstElementChild() method", function(){
it("doesn't find elements when there are none to find", function(done){
var textNode = document.createTextNode("text");
expect(utils.findFirstElementChild(textNode)).toBe(null);
done();
});
it("finds the first Element child amongst a list of nodes", function(done){
var div = document.createElement("div");
div.innerHTML = "text <span>pass</span> text <span>fail</span> text";
expect(utils.findFirstElementChild(div)).toBeTruthy();
expect(utils.findFirstElementChild(div).textContent).toEqual("pass");
done();
});
});

describe("toESIterable() method", function() {

Expand Down

0 comments on commit 45b7480

Please sign in to comment.