Skip to content

Commit 456bd27

Browse files
committed
Major fixes with JQuery race loading (for addins particularly).
We will always guarantee that jQuery is loaded in any static loading priority.
1 parent b4fec31 commit 456bd27

File tree

11 files changed

+102
-18
lines changed

11 files changed

+102
-18
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* #%L
3+
* GwtMaterial
4+
* %%
5+
* Copyright (C) 2015 - 2016 GwtMaterialDesign
6+
* %%
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* #L%
19+
*/
20+
package gwt.material.design.client;
21+
22+
import com.google.gwt.core.client.GWT;
23+
import com.google.gwt.resources.client.TextResource;
24+
import gwt.material.design.client.resources.WithJQueryDebugResources;
25+
import gwt.material.design.client.resources.WithJQueryResources;
26+
27+
public class JQueryProvider {
28+
29+
public TextResource jQuery() {
30+
return null;
31+
}
32+
33+
public static class JQueryDebug extends JQueryProvider {
34+
private WithJQueryDebugResources resources;
35+
36+
@Override
37+
public TextResource jQuery() {
38+
if(resources == null) {
39+
resources = GWT.create(WithJQueryDebugResources.class);
40+
}
41+
return resources.jQueryDebug();
42+
}
43+
}
44+
45+
public static class JQueryCompressed extends JQueryProvider {
46+
private WithJQueryResources resources;
47+
48+
@Override
49+
public TextResource jQuery() {
50+
if(resources == null) {
51+
resources = GWT.create(WithJQueryResources.class);
52+
}
53+
return resources.jQuery();
54+
}
55+
}
56+
}

gwt-material/src/main/java/gwt/material/design/client/MaterialDesignBase.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
* #L%
2121
*/
2222

23+
import com.google.gwt.core.client.GWT;
2324
import com.google.gwt.core.client.ScriptInjector;
2425
import com.google.gwt.dom.client.StyleInjector;
2526
import com.google.gwt.resources.client.TextResource;
@@ -41,7 +42,7 @@ public FutureResource(TextResource resource, boolean removeTag, boolean sourceUr
4142
}
4243
}
4344

44-
static TextResource jqueryResource;
45+
static final JQueryProvider jQueryProvider = GWT.create(JQueryProvider.class);
4546
static List<FutureResource> futureResources;
4647

4748
protected void load() {
@@ -93,20 +94,21 @@ public static void injectCss(TextResource resource) {
9394
}
9495

9596
protected static boolean checkJQuery(boolean debug) {
96-
if (!isjQueryLoaded()) {
97-
if (jqueryResource != null) {
98-
if (debug) {
99-
injectDebugJs(jqueryResource);
100-
} else {
101-
injectJs(jqueryResource);
102-
}
97+
if (!isjQueryLoaded() && isProvidingJQuery()) {
98+
if (debug) {
99+
injectDebugJs(jQueryProvider.jQuery());
103100
} else {
104-
return false;
101+
injectJs(jQueryProvider.jQuery());
105102
}
106103
}
107104
return true;
108105
}
109106

107+
public static boolean isProvidingJQuery() {
108+
return jQueryProvider instanceof JQueryProvider.JQueryDebug ||
109+
jQueryProvider instanceof JQueryProvider.JQueryCompressed;
110+
}
111+
110112
/**
111113
* Check to see if jQuery is loaded already
112114
*

gwt-material/src/main/java/gwt/material/design/client/MaterialWithJQuery.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,11 @@
2121
*/
2222

2323
import com.google.gwt.core.client.EntryPoint;
24-
import gwt.material.design.client.resources.WithJQueryResources;
2524

2625
public class MaterialWithJQuery extends MaterialDesignBase implements EntryPoint {
2726

2827
@Override
2928
public void onModuleLoad() {
30-
jqueryResource = WithJQueryResources.INSTANCE.jQuery();
3129
load();
3230
}
3331
}

gwt-material/src/main/java/gwt/material/design/client/MaterialWithJQueryDebug.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
*/
2222

2323
import com.google.gwt.core.client.EntryPoint;
24-
import gwt.material.design.client.resources.WithJQueryDebugResources;
2524

2625
/**
2726
* Entry point classes define <code>onModuleLoad()</code>.
@@ -30,7 +29,6 @@ public class MaterialWithJQueryDebug extends MaterialDesignDebugBase implements
3029

3130
@Override
3231
public void onModuleLoad() {
33-
jqueryResource = WithJQueryDebugResources.INSTANCE.jQueryDebug();
3432
load();
3533
}
3634
}

gwt-material/src/main/java/gwt/material/design/client/resources/WithJQueryDebugResources.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,10 @@
1919
*/
2020
package gwt.material.design.client.resources;
2121

22-
import com.google.gwt.core.client.GWT;
2322
import com.google.gwt.resources.client.ClientBundle;
2423
import com.google.gwt.resources.client.TextResource;
2524

2625
public interface WithJQueryDebugResources extends ClientBundle {
27-
WithJQueryDebugResources INSTANCE = GWT.create(WithJQueryDebugResources.class);
2826

2927
@Source("js/jquery-2.1.1.js")
3028
TextResource jQueryDebug();

gwt-material/src/main/java/gwt/material/design/client/resources/WithJQueryResources.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,10 @@
1919
*/
2020
package gwt.material.design.client.resources;
2121

22-
import com.google.gwt.core.client.GWT;
2322
import com.google.gwt.resources.client.ClientBundle;
2423
import com.google.gwt.resources.client.TextResource;
2524

2625
public interface WithJQueryResources extends ClientBundle {
27-
WithJQueryResources INSTANCE = GWT.create(WithJQueryResources.class);
2826

2927
@Source("js/jquery-2.1.1.min.js")
3028
TextResource jQuery();

gwt-material/src/main/resources/gwt/material/design/GwtMaterialBasicWithJQuery.gwt.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@
2929
<inherits name="gwt.material.design.GwtMaterialDesignBase"/>
3030
<inherits name="gwt.material.design.ResourcesBasic"/>
3131

32+
<replace-with class="gwt.material.design.client.JQueryProvider.JQueryCompressed">
33+
<when-type-is class="gwt.material.design.client.JQueryProvider"/>
34+
</replace-with>
35+
36+
<replace-with class="gwt.material.design.client.resources.WithJQueryResources">
37+
<when-type-is class="gwt.material.design.client.resources.JQueryResource"/>
38+
</replace-with>
39+
3240
<!-- Specify the app entry point class -->
3341
<entry-point class="gwt.material.design.client.MaterialWithJQuery"/>
3442
</module>

gwt-material/src/main/resources/gwt/material/design/GwtMaterialBasicWithJQueryDebug.gwt.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@
2929
<inherits name="gwt.material.design.GwtMaterialDesignBase"/>
3030
<inherits name="gwt.material.design.ResourcesBasic"/>
3131

32+
<replace-with class="gwt.material.design.client.JQueryProvider.JQueryDebug">
33+
<when-type-is class="gwt.material.design.client.JQueryProvider"/>
34+
</replace-with>
35+
36+
<replace-with class="gwt.material.design.client.resources.WithJQueryDebugResources">
37+
<when-type-is class="gwt.material.design.client.resources.JQueryResource"/>
38+
</replace-with>
39+
3240
<!-- Specify the app entry point class -->
3341
<entry-point class="gwt.material.design.client.MaterialWithJQueryDebug"/>
3442
</module>

gwt-material/src/main/resources/gwt/material/design/GwtMaterialWithJQuery.gwt.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@
2929
<inherits name="gwt.material.design.GwtMaterialDesignBase"/>
3030
<inherits name="gwt.material.design.Resources"/>
3131

32+
<replace-with class="gwt.material.design.client.JQueryProvider.JQueryCompressed">
33+
<when-type-is class="gwt.material.design.client.JQueryProvider"/>
34+
</replace-with>
35+
36+
<replace-with class="gwt.material.design.client.resources.WithJQueryResources">
37+
<when-type-is class="gwt.material.design.client.resources.JQueryResource"/>
38+
</replace-with>
39+
3240
<!-- Specify the app entry point class -->
3341
<entry-point class="gwt.material.design.client.MaterialWithJQuery"/>
3442
</module>

gwt-material/src/main/resources/gwt/material/design/GwtMaterialWithJQueryDebug.gwt.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@
2929
<inherits name="gwt.material.design.GwtMaterialDesignBase"/>
3030
<inherits name="gwt.material.design.Resources"/>
3131

32+
<replace-with class="gwt.material.design.client.JQueryProvider.JQueryDebug">
33+
<when-type-is class="gwt.material.design.client.JQueryProvider"/>
34+
</replace-with>
35+
36+
<replace-with class="gwt.material.design.client.resources.WithJQueryDebugResources">
37+
<when-type-is class="gwt.material.design.client.resources.JQueryResource"/>
38+
</replace-with>
39+
3240
<!-- Specify the app entry point class -->
3341
<entry-point class="gwt.material.design.client.MaterialWithJQueryDebug"/>
3442
</module>

0 commit comments

Comments
 (0)