X Tutup
Skip to content

Commit d9864b4

Browse files
author
jossonsmith
committed
Fixed bug that *.css path is not correct when #registerCSS is called from
*.z.js (e.g Composite's css in Shell.z.js) Now using document.createStyleSheet().cssText instead of former "javascript:..." way to insert CSS styles.
1 parent 01c3402 commit d9864b4

File tree

2 files changed

+22
-20
lines changed

2 files changed

+22
-20
lines changed

sources/net.sf.j2s.java.core/src/java/lang/ClassExt.js

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -762,14 +762,6 @@ Clazz.forName = function (clazzName) {
762762
Clazz.cssAlreadyAggregated = false;
763763
Clazz.cssForcedUsingFile = false;
764764

765-
countxx = 0;
766-
/* private */
767-
Clazz.cssForIE = function (key) {
768-
var value = window[key];
769-
window[key] = true; // loaded and release css text
770-
return value;
771-
};
772-
773765
/**
774766
* Register css for the given class. If the given css text is null, it will
775767
* try to find relative *.css file instead loading css text directly.
@@ -783,15 +775,17 @@ Clazz.registerCSS = function (clazzName, cssText) {
783775
}
784776
clazzName = ClazzLoader.unwrapArray ([clazzName])[0];
785777
var cssPath = ClazzLoader.getClasspathFor (clazzName, false, ".css");
778+
786779
var basePath = ClazzLoader.getClasspathFor (clazzName, true);
780+
var cssID = "c$$." + clazzName;
787781
/*
788782
* Check whether the css resources is loaded or not
789783
*/
790784
if (!ClazzLoader.isResourceExisted (clazzName, cssPath, basePath)) {
791785
if (cssText == null || Clazz.cssForcedUsingFile) {
792786
var cssLink = document.createElement ("LINK");
793787
cssLink.rel = "stylesheet";
794-
cssLink.id = clazzName;
788+
cssLink.id = cssID;
795789
cssLink.href = cssPath;
796790
document.getElementsByTagName ("HEAD")[0].appendChild (cssLink);
797791
} else {
@@ -834,20 +828,15 @@ Clazz.registerCSS = function (clazzName, cssText) {
834828
if (document.createStyleSheet != null) {
835829
/*
836830
* Internet Explorer does not support loading dynamic css styles
837-
* by <STYLE>!
838-
*/
839-
var cssID = "css." + clazzName;
840-
window[cssID] = cssText;
841-
/*
842-
* TODO: Keep eyes open on IE. Maybe IE won't initialize this
843-
* javascript-kind of CSS!
844-
* FIXME: IE7 (or IE6 sp2) does not support this kind of
845-
* CSS loading!
831+
* by creating <STYLE> element!
846832
*/
847-
document.createStyleSheet ("javascript:Clazz.cssForIE (\"" + cssID + "\");");
833+
var sheet = document.createStyleSheet ();
834+
sheet.cssText = cssText;
835+
//sheet.id = cssID; // No ID support the this element for IE
836+
window[cssID] = true;
848837
} else {
849838
var cssStyle = document.createElement ("STYLE");
850-
cssStyle.id = clazzName;
839+
cssStyle.id = cssID;
851840
cssStyle.appendChild (document.createTextNode (cssText));
852841
document.getElementsByTagName ("HEAD")[0].appendChild (cssStyle);
853842
}

sources/net.sf.j2s.java.core/src/java/lang/ClassLoader.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,19 @@ ClazzLoader.getClasspathFor = function (clazz, forRoot, ext) {
395395
var idx = path.lastIndexOf (clazz.replace (/\./g, "/"));
396396
if (idx != -1) {
397397
base = path.substring (0, idx);
398+
} else {
399+
/*
400+
* Check more: Maybe the same class' *.css is located
401+
* in the same folder.
402+
*/
403+
idx = clazz.lastIndexOf (".");
404+
if (idx != -1) {
405+
idx = path.lastIndexOf (clazz.substring (0, idx)
406+
.replace (/\./g, "/"));
407+
if (idx != -1) {
408+
base = path.substring (0, idx);
409+
}
410+
}
398411
}
399412
}
400413
} else {

0 commit comments

Comments
 (0)
X Tutup