You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by mg...@apache.org on 2013/02/27 14:46:08 UTC

git commit: WICKET-5047 Wicket Ajax: Inline script header contribution issue

Updated Branches:
  refs/heads/master 57ee84925 -> 9182a8f6e


WICKET-5047 Wicket Ajax: Inline script header contribution issue

Preserve the original type attribute value for <script>.

patch-by: Sebastien Briquet


Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/9182a8f6
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/9182a8f6
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/9182a8f6

Branch: refs/heads/master
Commit: 9182a8f6e77ffa3591a91672ea31dcf580a00a6b
Parents: 57ee849
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
Authored: Wed Feb 27 15:44:38 2013 +0200
Committer: Martin Tzvetanov Grigorov <mg...@apache.org>
Committed: Wed Feb 27 15:44:38 2013 +0200

----------------------------------------------------------------------
 .../wicket/ajax/res/js/wicket-ajax-jquery.js       |   24 +++++++-------
 1 files changed, 12 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/9182a8f6/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery.js
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery.js b/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery.js
index e2861a9..994c27a 100644
--- a/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery.js
+++ b/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery.js
@@ -1983,15 +1983,11 @@
 							text = text.replace(/\n\/\*\]\]>\*\/\n$/, "");
 
 							var id = node.getAttribute("id");
-
 							var type = node.getAttribute("type");
-							if (!type || type.toLowerCase() === "text/javascript") {
-								text = 'try{'+text+'}catch(e){Wicket.Log.error(e);}';
-							}
 
 							if (typeof(id) === "string" && id.length > 0) {
 								// add javascript to document head
-								Wicket.Head.addJavascript(text, id);
+								Wicket.Head.addJavascript(text, id, "", type);
 							} else {
 								try {
 									eval(text);
@@ -2079,13 +2075,21 @@
 			// attribute to filter out duplicates. However, since we set the body of the element, we can't assign
 			// also a src value. Therefore we put the url to the src_ (notice the underscore)  attribute.
 			// Wicket.Head.containsElement is aware of that and takes also the underscored attributes into account.
-			addJavascript: function (content, id, fakeSrc) {
+			addJavascript: function (content, id, fakeSrc, type) {
 				var script = Wicket.Head.createElement("script");
 				if (id) {
 					script.id = id;
 				}
+
+				// WICKET-5047: encloses the content with a try...catch... block if the content is javascript
+				// content is considered javascript if mime-type is empty (html5's default) or is 'text/javascript'
+				if (!type || type.toLowerCase() === "text/javascript") {
+					type = "text/javascript";
+					content = 'try{'+content+'}catch(e){Wicket.Log.error(e);}';
+				}
+
 				script.setAttribute("src_", fakeSrc);
-				script.setAttribute("type", "text/javascript");
+				script.setAttribute("type", type);
 
 				// set the javascript as element content
 				if (null === script.canHaveChildren || script.canHaveChildren) {
@@ -2121,11 +2125,7 @@
 							content = contentFilter(content);
 						}
 
-						if (!type || type.toLowerCase() === "text/javascript") {
-							content = 'try{'+content+'}catch(e){Wicket.Log.error(e);}';
-						}
-
-						Wicket.Head.addJavascript(content, element.id);
+						Wicket.Head.addJavascript(content, element.id, "", type);
 					}
 				}
 				if (typeof(element) !== "undefined" &&