Skip to content

Commit

Permalink
Attempt to fix a bug when loading css resources from a component init…
Browse files Browse the repository at this point in the history
…ialy hidden, then shown with an ajax request
  • Loading branch information
Alexis Tual authored and alextu committed Jun 2, 2012
1 parent 48ce60f commit e7b57a9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
10 changes: 8 additions & 2 deletions Frameworks/Ajax/Ajax/WebServerResources/wonder.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,14 @@ var AjaxOnDemand = {
},

loadCSS: function(css) {
new Ajax.Request(css, { method: 'get', asynchronous: false, onComplete: AjaxOnDemand.loadedCSS });
},
var link=document.createElement("link");
link.setAttribute("rel", "stylesheet");
link.setAttribute("type", "text/css");
link.setAttribute("href", css);
if (typeof link!="undefined") {
document.getElementsByTagName("head")[0].appendChild(link);
}
},

loadedCSS: function(request) {
var inlineStyle = new Element("style", {"type": "text/css"});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -491,25 +491,21 @@ public static void addStylesheetResourceInHead(WOResponse response, WOContext co
else {
cssEndTag = "\">";
}
// MS: It looks like all the browsers can load CSS inline, so we don't
// even need all this.
// String fallbackStartTag;
// String fallbackEndTag;
// if (ERXAjaxApplication.isAjaxRequest(context.request())) {
// fallbackStartTag = "<script>AOD.loadCSS('";
// fallbackEndTag = "')</script>";
// }
// else {
// fallbackStartTag = null;
// fallbackEndTag = null;
// }
// ERXResponseRewriter.addResourceInHead(response, context, framework,
// fileName, cssStartTag, cssEndTag, fallbackStartTag, fallbackEndTag,
// TagMissingBehavior.SkipAndWarn);
String fallbackStartTag = null;
String fallbackEndTag = null;

if (ERXAjaxApplication.isAjaxRequest(context.request()) && ERXProperties.booleanForKeyWithDefault("er.extensions.loadOnDemand", true)) {
if (ERXProperties.booleanForKeyWithDefault("er.extensions.loadOnDemandDuringReplace", false)) {
boolean appendTypeAttribute = ERXProperties.booleanForKeyWithDefault("er.extensions.ERXResponseRewriter.javascriptTypeAttribute", false);
fallbackStartTag = (appendTypeAttribute ? "<script type=\"text/javascript\">AOD.loadCSS('" : "<script>AOD.loadCSS('");
fallbackEndTag = "')</script>";
}
}
ERXResponseRewriter.addResourceInHead(response, context, framework, fileName, cssStartTag, cssEndTag, fallbackStartTag, fallbackEndTag, TagMissingBehavior.Inline);

// Q: We use TagMissingBehaviour.Inline in case this is called from inside the
// HEAD tag and there is no close tag yet
ERXResponseRewriter.addResourceInHead(response, context, framework, fileName, cssStartTag, cssEndTag, null, null, TagMissingBehavior.Inline);
// ERXResponseRewriter.addResourceInHead(response, context, framework, fileName, cssStartTag, cssEndTag, null, null, TagMissingBehavior.Inline);
}

/**
Expand Down

0 comments on commit e7b57a9

Please sign in to comment.