Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Commit

Permalink
bug(ie8 docs): docs now work on ie8
Browse files Browse the repository at this point in the history
  • Loading branch information
mhevery committed May 7, 2012
1 parent b99f65f commit aa02534
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 13 deletions.
2 changes: 1 addition & 1 deletion angularFiles.js
Expand Up @@ -59,7 +59,7 @@ angularFiles = {
'src/ng/directive/ngView.js',
'src/ng/directive/script.js',
'src/ng/directive/select.js',
'src/ng/directive/style.js',
'src/ng/directive/style.js'
],

'angularSrcModules': [
Expand Down
2 changes: 1 addition & 1 deletion docs/src/example.js
Expand Up @@ -116,7 +116,7 @@ exports.Example.prototype.toHtmlTabs = function() {

exports.Example.prototype.toHtmlEmbed = function() {
var out = [];
out.push('<div class="well doc-example-live"');
out.push('<div class="well doc-example-live"');
out.push(' ng-embed-app="' + this.module + '"');
out.push(' ng-set-html="' + this.html[0].id + '"');
out.push(' ng-eval-javascript="' + ids(this.js) + '">');
Expand Down
35 changes: 26 additions & 9 deletions src/bootstrap/bootstrap-prettify.js
Expand Up @@ -19,6 +19,17 @@ function escape(text) {
replace(/"/g, '&quot;');
}

/**
* http://stackoverflow.com/questions/451486/pre-tag-loses-line-breaks-when-setting-innerhtml-in-ie
* http://stackoverflow.com/questions/195363/inserting-a-newline-into-a-pre-tag-ie-javascript
*/
function setHtmlIe8SafeWay(element, html) {
var newElement = angular.element('<pre>' + html + '</pre>');

element.html('');
element.append(newElement.contents());
return element;
}


directive.jsFiddle = function(getEmbeddedTemplate, escape, script) {
Expand Down Expand Up @@ -54,7 +65,7 @@ directive.jsFiddle = function(getEmbeddedTemplate, escape, script) {

fields.html += '</div>\n';

element.html(
setHtmlIe8SafeWay(element,
'<form class="jsfiddle" method="post" action="http://jsfiddle.net/api/post/library/pure/" target="_blank">' +
hiddenField('title', 'AngularJS Example: ' + name) +
hiddenField('css', '</style> <!-- Ugly Hack due to jsFiddle issue: http://goo.gl/BUfGZ --> \n' +
Expand Down Expand Up @@ -97,7 +108,7 @@ directive.ngSetText = ['getEmbeddedTemplate', function(getEmbeddedTemplate) {
restrict: 'CA',
priority: 10,
compile: function(element, attr) {
element.text(getEmbeddedTemplate(attr.ngSetText));
setHtmlIe8SafeWay(element, escape(getEmbeddedTemplate(attr.ngSetText)));
}
}
}]
Expand All @@ -109,9 +120,9 @@ directive.ngHtmlWrap = ['reindentCode', 'templateMerge', function(reindentCode,
var properties = {
head: '',
module: '',
body: reindentCode(element.text(), 4)
body: element.text()
},
html = "<!doctype html>\n<html ng-app{{module}}>\n <head>\n{{head}} </head>\n <body>\n{{body}} </body>\n</html>";
html = "<!doctype html>\n<html ng-app{{module}}>\n <head>\n{{head:4}} </head>\n <body>\n{{body:4}} </body>\n</html>";

angular.forEach((attr.ngHtmlWrap || '').split(' '), function(dep) {
if (!dep) return;
Expand All @@ -120,15 +131,15 @@ directive.ngHtmlWrap = ['reindentCode', 'templateMerge', function(reindentCode,
var ext = dep.split(/\./).pop();

if (ext == 'css') {
properties.head += ' <link rel="stylesheet" href="' + dep + '" type="text/css">\n';
properties.head += '<link rel="stylesheet" href="' + dep + '" type="text/css">\n';
} else if(ext == 'js') {
properties.head += ' <script src="' + dep + '"></script>\n';
properties.head += '<script src="' + dep + '"></script>\n';
} else {
properties.module = '="' + dep + '"';
}
});

element.text(templateMerge(html, properties));
setHtmlIe8SafeWay(element, escape(templateMerge(html, properties)));
}
}
}];
Expand All @@ -139,7 +150,7 @@ directive.ngSetHtml = ['getEmbeddedTemplate', function(getEmbeddedTemplate) {
restrict: 'CA',
priority: 10,
compile: function(element, attr) {
element.html(getEmbeddedTemplate(attr.ngSetHtml));
setHtmlIe8SafeWay(element, getEmbeddedTemplate(attr.ngSetHtml));
}
}
}];
Expand Down Expand Up @@ -256,7 +267,13 @@ service.templateMerge = ['reindentCode', function(indentCode) {

service.getEmbeddedTemplate = ['reindentCode', function(reindentCode) {
return function (id) {
return reindentCode(angular.element(document.getElementById(id)).html(), 0);
var element = document.getElementById(id);

if (!element) {
return null;
}

return reindentCode(angular.element(element).html(), 0);
}
}];

Expand Down
6 changes: 4 additions & 2 deletions src/bootstrap/google-prettify/prettify.js
Expand Up @@ -1350,11 +1350,13 @@ var REGEXP_PRECEDER_PATTERN = '(?:^^\\.?|[+-]|[!=]=?=?|\\#|%=?|&&?=?|\\(|\\*=?|[
* or the 1-indexed number of the first line in sourceCodeHtml.
*/
function prettyPrintOne(sourceCodeHtml, opt_langExtension, opt_numberLines) {
var container = document.createElement('pre');
// PATCHED: http://code.google.com/p/google-code-prettify/issues/detail?id=213
var container = document.createElement('div');
// This could cause images to load and onload listeners to fire.
// E.g. <img onerror="alert(1337)" src="nosuchimage.png">.
// We assume that the inner HTML is from a trusted source.
container.innerHTML = sourceCodeHtml;
container.innerHTML = '<pre>' + sourceCodeHtml + '</pre>';
container = container.firstChild;
if (opt_numberLines) {
numberLines(container, opt_numberLines, true);
}
Expand Down

0 comments on commit aa02534

Please sign in to comment.