package com.gwidgets.api.leaflet.utils;

import com.google.gwt.core.client.GWT;

import elemental2.dom.DomGlobal;
import elemental2.dom.Element.OnloadCallbackFn;
import elemental2.dom.HTMLLinkElement;
import elemental2.dom.HTMLScriptElement;


public class LeafletResources {
	
	
	
	public static void whenReady(OnloadCallbackFn function){
		
		HTMLScriptElement leafletScript = (HTMLScriptElement) DomGlobal.document.createElement("script");
		leafletScript.src=GWT.getModuleName()+"/leaflet/leaflet.js";
		leafletScript.type="text/javascript";
		
		HTMLLinkElement leafletStyle = (HTMLLinkElement) DomGlobal.document.createElement("link");
		leafletStyle.href=GWT.getModuleName()+"/leaflet/leaflet.css";
		leafletStyle.rel="stylesheet";
		
		
		DomGlobal.document.head.appendChild(leafletScript);
		DomGlobal.document.head.appendChild(leafletStyle);
		
		leafletScript.onload = function;

	}

}

@@ -268,21 +268,16 @@
 ources %7B
-%0A%09%0A%09%0A
 %09%0A%09publi
@@ -300,16 +300,31 @@
 enReady(
+boolean debug, 
 OnloadCa
@@ -343,19 +343,16 @@
 ction)%7B%0A
-%09%09%0A
 %09%09HTMLSc
@@ -439,24 +439,40 @@
 (%22script%22);%0A
+%09%09if (debug) %7B%0A%09
 %09%09leafletScr
@@ -478,17 +478,19 @@
 ript.src
-=
+ = 
 GWT.getM
@@ -492,33 +492,35 @@
 .getModuleName()
-+
+ + 
 %22/leaflet/leafle
@@ -524,14 +524,101 @@
 flet
+-src
 .js%22;%0A
+%09%09%7D else %7B%0A%09%09%09leafletScript.src = GWT.getModuleName() + %22/leaflet/leaflet.js%22;%0A%09%09%7D%0A
 %09%09le
@@ -1001,11 +1001,8 @@
 on;%0A
-%0A
 %09%7D%0A
-%0A
 %7D
-%0A

add unminified script option in LeafletResources