Project

General

Profile

Patch #1286 ยป web_client_utils_1284_patch.txt

Joas de Haan, 12/23/2017 04:39 PM

 
1
Index: src/com/servoy/plugins/BehaviorProvider.java
2
===================================================================
3
--- src/com/servoy/plugins/BehaviorProvider.java	(revision 60)
4
+++ src/com/servoy/plugins/BehaviorProvider.java	(working copy)
5
@@ -253,7 +253,41 @@
6
 			Debug.error(e);
7
 		}	
8
 	}
9
-    
10
+	
11
+	public void addGlobalJsReference(Object url) 
12
+	{
13
+		try 
14
+		{
15
+			Method method = app.getPageContributor().getClass().getMethod("addGlobalJSResourceReference", url.getClass());
16
+			method.invoke(app.getPageContributor(), url);
17
+		}
18
+		catch (NoSuchMethodException ex)
19
+		{
20
+			throw new UnsupportedOperationException("Cannot add global js reference. This operation is not supported for Servoy versions lower than 7.3");
21
+		}
22
+		catch (Exception e) 
23
+		{
24
+			Debug.error(e);
25
+		} 
26
+	}
27
+ 
28
+	public void removeGlobalJsReference(Object url) 
29
+	{
30
+		try 
31
+		{
32
+			Method method = app.getPageContributor().getClass().getMethod("removeGlobalResourceReference", url.getClass());
33
+			method.invoke(app.getPageContributor(), url);
34
+		} 
35
+		catch (NoSuchMethodException ex)
36
+		{
37
+			throw new UnsupportedOperationException("Cannot remove global js reference. This operation is not supported for Servoy versions lower than 7.3");
38
+		}
39
+		catch (Exception e) 
40
+		{
41
+			Debug.error(e);
42
+		}	
43
+	}
44
+	
45
 	/*
46
 	public interface ILatestPageBehaviorListener extends IBehaviorListener
47
 	{
48
Index: src/com/servoy/plugins/WebClientProvider.java
49
===================================================================
50
--- src/com/servoy/plugins/WebClientProvider.java	(revision 60)
51
+++ src/com/servoy/plugins/WebClientProvider.java	(working copy)
52
@@ -298,7 +298,12 @@
53
 		} else if ("removeGlobalCssReference".equals(method)) {
54
 			return "%%elementName%%.removeGlobalCssReference(''http://yourserver.com/css/yourstyle.css');\n" + ((SERVOY_WEB_RESOURCES.YUI_CSS_FONTS == null) ? "" : 
55
 			"\t// you can also remove Servoy internal reference scripts (like Yahoo UI widgets):\n\t%%elementName%%.removeGlobalCssReference(SERVOY_WEB_RESOURCES.YUI_CSS_MENU)");
56
-
57
+		} else if ("addGlobalJsReference".equals(method)) {
58
+			return "%%elementName%%.addGlobalJsReference(''http://yourserver.com/js/yourstyle.js');\n" + ((SERVOY_WEB_RESOURCES.YUI_CSS_FONTS == null) ? "" : 
59
+			"\t// you can also add Servoy internal reference scripts (like Yahoo UI widgets):\n\t%%elementName%%.addGlobalCssReference(SERVOY_WEB_RESOURCES.YUI_CSS_MENU)");
60
+		} else if ("removeGlobalJsReference".equals(method)) {
61
+			return "%%elementName%%.removeGlobalCssReference(''http://yourserver.com/js/yourstyle.js');\n" + ((SERVOY_WEB_RESOURCES.YUI_CSS_FONTS == null) ? "" : 
62
+			"\t// you can also remove Servoy internal reference scripts (like Yahoo UI widgets):\n\t%%elementName%%.removeGlobalCssReference(SERVOY_WEB_RESOURCES.YUI_CSS_MENU)");
63
 		}
64
 
65
 		return null;
66
@@ -316,6 +321,8 @@
67
 			return "Returns a Servoy markup Id to be used in your browser scripts";
68
 		else if ("removeJsReference".equals(method))
69
 			return "Removes a javascript url" + ((SERVOY_WEB_RESOURCES.YUI_CSS_FONTS == null) ? "" : " or build in servoy javascript reference (see SERVOY_WEB_RESOURCES)");
70
+		else if ("removeGlobalJsReference".equals(method))
71
+			return "Removes a global javascript url" + ((SERVOY_WEB_RESOURCES.YUI_CSS_FONTS == null) ? "" : " or build in servoy javascript reference (see SERVOY_WEB_RESOURCES)");
72
 		else if ("removeCssReference".equals(method))
73
 			return "Removes a css url" + ((SERVOY_WEB_RESOURCES.YUI_CSS_FONTS == null) ? "" : " or build in servoy css reference (see SERVOY_WEB_RESOURCES)");
74
 		else if ("removeGlobalCssReference".equals(method))
75
@@ -322,6 +329,8 @@
76
 			return "Removes a global css url" + ((SERVOY_WEB_RESOURCES.YUI_CSS_FONTS == null) ? "" : " or build in servoy css reference (see SERVOY_WEB_RESOURCES)");
77
 		else if ("addJsReference".equals(method))
78
 			return "Adds a javascript url" + ((SERVOY_WEB_RESOURCES.YUI_CSS_FONTS == null) ? "" : " or build in servoy javascript reference (see SERVOY_WEB_RESOURCES) to the page");
79
+		else if ("addGlobalJsReference".equals(method))
80
+			return "Adds a global js url" + ((SERVOY_WEB_RESOURCES.YUI_CSS_FONTS == null) ? "" : "  or build in servoy javascript reference (see SERVOY_WEB_RESOURCES) to the page");
81
 		else if ("addCssReference".equals(method))
82
 			return "Adds a css url" + ((SERVOY_WEB_RESOURCES.YUI_CSS_FONTS == null) ? "" : "  or build in servoy css reference (see SERVOY_WEB_RESOURCES) to the page");
83
 		else if ("addGlobalCssReference".equals(method))
84
@@ -527,7 +536,43 @@
85
 		BehaviorProvider bp = getBehavior(); 
86
 		if (bp != null) bp.addGlobalCssReference(url);
87
 	}
88
+	
89
+	public void js_addGlobalJsReference(String url) {
90
+		addGlobalJsReference(url);
91
+	}
92
+	
93
+	public void js_addGlobalJsReference(ResourceReference url) {
94
+		addGlobalJsReference(url);
95
+	}	
96
+	
97
+	public void js_removeGlobalJsReference(String url) {
98
+		removeGlobalJsReference(url);
99
+	}
100
+	
101
+	public void js_removeGlobalJsReference(ResourceReference url) {
102
+		removeGlobalJsReference(url);
103
+	}
104
 
105
+	private void addGlobalJsReference(String url) {
106
+		BehaviorProvider bp = getBehavior(); 
107
+		if (bp != null) bp.addGlobalJsReference(url);
108
+	}
109
+	
110
+	private void addGlobalJsReference(ResourceReference url) {
111
+		BehaviorProvider bp = getBehavior(); 
112
+		if (bp != null) bp.addGlobalCssReference(url);
113
+	}
114
+	
115
+	public void removeGlobalJsReference(ResourceReference url) {
116
+		BehaviorProvider bp = getBehavior(); 
117
+		if (bp != null) bp.removeGlobalJsReference(url);
118
+	}
119
+	
120
+	public void removeGlobalJsReference(String url) {
121
+		BehaviorProvider bp = getBehavior(); 
122
+		if (bp != null) bp.removeGlobalJsReference(url);
123
+	}	
124
+
125
 	public void js_addJsReference(String url) {
126
 		addJsReference(url);
127
 	}
    (1-1/1)