Skip to content

Commit 5f92d41

Browse files
matskomhevery
authored andcommitted
fix(ngdocs): provide test code for syntax links in docs and fix the syntax directive for IE8
1 parent 2f571a9 commit 5f92d41

File tree

2 files changed

+58
-4
lines changed

2 files changed

+58
-4
lines changed

docs/component-spec/syntaxSpec.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
describe('Docs Syntax', function() {
2+
3+
beforeEach(module('bootstrap'));
4+
5+
describe('syntax', function() {
6+
7+
var id, element, document;
8+
9+
beforeEach(inject(function($compile, $rootScope, $document) {
10+
document = $document[0];
11+
//create the HTML elements missing in IE8 for this directive
12+
document.createElement('nav');
13+
14+
element = angular.element(
15+
'<div>' +
16+
'<pre syntax ' +
17+
'syntax-github="gh-url" ' +
18+
'syntax-plunkr="pl-url" ' +
19+
'syntax-fiddle="jf-url">' +
20+
'</pre>' +
21+
'</div>'
22+
);
23+
$compile(element)($rootScope);
24+
$rootScope.$digest();
25+
26+
element = element[0];
27+
document.body.appendChild(element);
28+
}));
29+
30+
it("should properly prepare a github link in the page", function() {
31+
var github = element.querySelector('.syntax-github');
32+
expect(github.innerHTML).toMatch(/View on Github/i);
33+
expect(github.getAttribute('href')).toBe('gh-url');
34+
});
35+
36+
it("should properly prepare a plunkr link in the page", function() {
37+
var plunkr = element.querySelector('.syntax-plunkr');
38+
expect(plunkr.innerHTML).toMatch(/View on Plunkr/i);
39+
expect(plunkr.getAttribute('href')).toBe('pl-url');
40+
});
41+
42+
it("should properly prepare a jsfiddle link in the page", function() {
43+
var jsfiddle = element.querySelector('.syntax-jsfiddle');
44+
expect(jsfiddle.innerHTML).toMatch(/View on JSFiddle/i);
45+
expect(jsfiddle.getAttribute('href')).toBe('jf-url');
46+
});
47+
48+
});
49+
50+
});

docs/components/bootstrap/bootstrap.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ directive.syntax = function() {
5757
'<span class="' + icon + '"></span> ' + text +
5858
'</a>';
5959
};
60-
var html = '<nav class="syntax-links">';
60+
61+
var html = '';
6162
var types = {
6263
'github' : {
6364
text : 'View on Github',
@@ -82,11 +83,14 @@ directive.syntax = function() {
8283
html += makeLink(type, data.text, link, data.icon);
8384
}
8485
};
85-
html += '</nav>';
86-
var nav = angular.element(html);
86+
87+
var nav = document.createElement('nav');
88+
nav.className = 'syntax-links';
89+
nav.innerHTML = html;
90+
8791
var node = element[0];
8892
var par = node.parentNode;
89-
par.insertBefore(nav[0], node);
93+
par.insertBefore(nav, node);
9094
}
9195
}
9296
}

0 commit comments

Comments
 (0)