Skip to content

Commit

Permalink
Fixed an exception from being thrown when positioner is in iframe.
Browse files Browse the repository at this point in the history
Fixed a regexp greediness bug.
  • Loading branch information
toolness committed Jan 12, 2012
1 parent c16c70a commit e2cac9d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
10 changes: 6 additions & 4 deletions static-files/templates/positioner-demo-files/positioner.js
Expand Up @@ -117,8 +117,9 @@ var Positioner = (function(window) {
function onMouseUp(event) {
window.removeEventListener("mouseup", onMouseUp, false);
window.removeEventListener("mousemove", onMouseMove, false);
window.history.pushState({}, "", "?" + makeQueryString() +
window.location.hash);
if (window.parent === window)
window.history.pushState({}, "", "?" + makeQueryString() +
window.location.hash);
event.preventDefault();
inQuasimode = false;
}
Expand Down Expand Up @@ -247,7 +248,7 @@ var Positioner = (function(window) {
return '<style id="positioner-data">\n' + rules + '\n</style>';
},
addOrReplaceStyleHtmlToPage: function(html, rules) {
var styleRe = /\<style id="positioner-data"\>\n(?:.*\n)*\<\/style\>/m;
var styleRe = /\<style id="positioner-data"\>\n(?:.*\n)*?\<\/style\>/m;
var styleMatch = html.match(styleRe);
if (styleMatch)
return html.replace(styleRe, utils.makeStyleHtml(rules));
Expand All @@ -258,7 +259,8 @@ var Positioner = (function(window) {
"\n" + html.slice(titleCloseIndex);
}
return html + utils.makeStyleHtml(rules);
}
},
makeCssRules: makeCssRules
};

return {
Expand Down
4 changes: 2 additions & 2 deletions static-files/templates/positioner-demo-files/test/index.html
Expand Up @@ -74,12 +74,12 @@ <h2 id="qunit-userAgent"></h2>
var start = '<!DOCTYPE html>\n<meta charset="utf-8">\n' +
'<title>My page</title>\n' +
'<style id="positioner-data">\n#blah {}\n\n/**/\n</style>\n' +
'<p>blah</p>';
'<style>\n/* other stuff */\n</style>\n<p>blah</p>';
var rules = '#NEWNEW {}';
equals(Positioner.utils.addOrReplaceStyleHtmlToPage(start, rules),
'<!DOCTYPE html>\n<meta charset="utf-8">\n' +
'<title>My page</title>\n' +
'<style id="positioner-data">\n#NEWNEW {}\n</style>\n' +
'<p>blah</p>');
'<style>\n/* other stuff */\n</style>\n<p>blah</p>');
});
</script>

0 comments on commit e2cac9d

Please sign in to comment.