Skip to content

Commit

Permalink
Set the default type only if the property "er.extensions.ERXResponseR…
Browse files Browse the repository at this point in the history
…ewriter.javascriptTypeAttribute" is true
  • Loading branch information
renebock committed Nov 5, 2024
1 parent 11e2f35 commit 0d91a09
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import er.extensions.appserver.ajax.ERXAjaxApplication;
import er.extensions.foundation.ERXMutableURL;
import er.extensions.foundation.ERXProperties;

/**
* <span class="en">
Expand Down Expand Up @@ -364,8 +365,14 @@ else if (_directActionName != null) {

if (ERXAjaxApplication.isAjaxRequest(context.request())) {
boolean hasUpdateContainer = context.request().stringFormValueForKey(ERXAjaxApplication.KEY_UPDATE_CONTAINER_ID) != null;
boolean appendDefaultTypeAttribute = ERXProperties.booleanForKeyWithDefault("er.extensions.ERXResponseRewriter.javascriptTypeAttribute", false);

if (hasUpdateContainer) {
response.appendContentString("<script type=\"text/javascript\">");
if(appendDefaultTypeAttribute) {
response.appendContentString("<script type=\"text/javascript\">");
} else {
response.appendContentString("<script>");
}
}
else {
response.setHeader("text/javascript", "Content-Type");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
* @binding scriptKey if set, the content will get rendered into an external script src
* @binding hideInComment boolean that specifies if the script content should
* be included in HTML comments, true by default of the script tag contains a script
* @binding type defaults to <i>"text/javascript"</i>, if property er.extensions.ERXResponseRewriter.javascriptTypeAttribute is <code>true</code>
*
* @property er.extensions.ERXJavaScript.hideInComment sets globally if the script
* content should be included within HTML comments, defaults to <code>true</code>
Expand Down Expand Up @@ -86,6 +87,7 @@ public WOActionResults performActionNamed(String name) {
WOAssociation _scriptKey;
WOAssociation _hideInComment;
WOAssociation _language;
WOAssociation _type;

public ERXJavaScript(String s, NSDictionary<String, WOAssociation> nsdictionary, WOElement woelement) {
super("script", nsdictionary, woelement);
Expand All @@ -98,6 +100,7 @@ public ERXJavaScript(String s, NSDictionary<String, WOAssociation> nsdictionary,
_hideInComment = _associations.removeObjectForKey("hideInComment");
_scriptFramework = _associations.removeObjectForKey("scriptFramework");
_framework = _associations.removeObjectForKey("framework");
_type = _associations.removeObjectForKey("type");
if((_scriptFile != null && _scriptString != null)
|| (_scriptFile != null && (_scriptSource != null || _filename != null))
|| (_scriptString != null && (_scriptSource != null || _filename != null))) {
Expand All @@ -113,8 +116,16 @@ public ERXJavaScript(String s, NSDictionary<String, WOAssociation> nsdictionary,

@Override
public void appendAttributesToResponse(WOResponse woresponse, WOContext wocontext) {
boolean appendDefaultTypeAttribute = ERXProperties.booleanForKeyWithDefault("er.extensions.ERXResponseRewriter.javascriptTypeAttribute", false);

WOComponent wocomponent = wocontext.component();
woresponse._appendContentAsciiString(" type=\"text/javascript\"");

if(_type != null) {
woresponse._appendContentAsciiString(" type=\""+(String)_type.valueInComponent(wocomponent) +"\"");
}
else if(appendDefaultTypeAttribute) {
woresponse._appendContentAsciiString(" type=\"text/javascript\"");
}

String framework = null;
String scriptName = null;
Expand Down

0 comments on commit 0d91a09

Please sign in to comment.