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

bug(html5 navigation): broken in Opera #940

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion angularFiles.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
11 changes: 8 additions & 3 deletions src/ng/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ function Browser(window, document, $log, $sniffer) {
// URL API
//////////////////////////////////////////////////////////////

var lastBrowserUrl = location.href;
var lastBrowserUrl = location.href,
baseElement = document.find('base');

/**
* @ngdoc method
Expand Down Expand Up @@ -152,7 +153,11 @@ function Browser(window, document, $log, $sniffer) {
lastBrowserUrl = url;
if ($sniffer.history) {
if (replace) history.replaceState(null, '', url);
else history.pushState(null, '', url);
else {
history.pushState(null, '', url);
// Crazy Opera Bug: http://my.opera.com/community/forums/topic.dml?id=1185462
baseElement.attr('href', baseElement.attr('href'));
}
} else {
if (replace) location.replace(url);
else location.href = url;
Expand Down Expand Up @@ -231,7 +236,7 @@ function Browser(window, document, $log, $sniffer) {
* @returns {string=}
*/
self.baseHref = function() {
var href = document.find('base').attr('href');
var href = baseElement.attr('href');
return href ? href.replace(/^https?\:\/\/[^\/]*/, '') : href;
};

Expand Down