Permalink
Browse files

bug(ie8 docs): docs now work on ie8

  • Loading branch information...
mhevery committed May 7, 2012
1 parent b99f65f commit aa02534865c8e43dcef9e218b12c8c717c837205
Showing with 32 additions and 13 deletions.
  1. +1 −1 angularFiles.js
  2. +1 −1 docs/src/example.js
  3. +26 −9 src/bootstrap/bootstrap-prettify.js
  4. +4 −2 src/bootstrap/google-prettify/prettify.js
View
@@ -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': [
View
@@ -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) + '">');
@@ -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) {
@@ -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' +
@@ -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)));
}
}
}]
@@ -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;
@@ -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)));
}
}
}];
@@ -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));
}
}
}];
@@ -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);
}
}];
@@ -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);
}

0 comments on commit aa02534

Please sign in to comment.