/** * Injects ChartJS if not injected yet. */ static void ensureInjected() { if (!injected) { // gets resource Resources res = GWT.create(Resources.class); // gets source of ChartJS String source = res.chartJsSource().getText(); // creates a script element ScriptElement scriptElement = Document.get().createScriptElement(); // sets ID scriptElement.setId(CHART_JS_SCRIPT_ELEMENT_ID); // sets the script content with ChartJS source scriptElement.setInnerText(source); // appends to the body Document.get().getBody().appendChild(scriptElement); injected = true; } }
public static void load(Chronoscope.URLResolver resolver, final String libName, final String version, final Command callback) { if (!injectedLoader) { final ScriptElement se = Document.get().createScriptElement(); // se.setSrc(intrinsics.getCachedUrl("http://www.google.com/jsapi?callback=" + JSAPI_CALLBACK)); se.setSrc("http://www.google.com/jsapi?callback=" + JSAPI_CALLBACK); final HeadElement he = HeadElement.as(Document.get().getElementsByTagName("head").getItem(0)); exportHandler(new Command() { public void execute() { injectedLoader=true; he.removeChild(se); nativeLoad(libName, version, callback); } }); he.appendChild(se); } else { nativeLoad(libName, version, callback); } }
public JSLoad(Loaded loaded, String... url) { _callbackList.add(loaded); Document document= Document.get(); for(String u : url) { ScriptElement script= document.createScriptElement(); script.setSrc(u); script.setType("text/javascript"); _map.put(script,false); if (BrowserUtil.isIE() && BrowserUtil.getMajorVersion()<9) { addIEListener(this,script,loaded); } else { addListener(this,script,loaded); } document.getBody().appendChild(script); } }
public static void injectScript(SafeUri js, AsyncCallback<Void> callback) { final ScriptElement[] script = new ScriptElement[1]; script[0] = ScriptInjector.fromUrl(js.asString()) .setWindow(ScriptInjector.TOP_WINDOW) .setCallback( new Callback<Void, Exception>() { @Override public void onSuccess(Void result) { script[0].removeFromParent(); callback.onSuccess(result); } @Override public void onFailure(Exception reason) { callback.onFailure(reason); } }) .inject() .cast(); }
public final static SQLite create(JsArrayInteger data) { // Loads the SQLite.js script if not done already if (bundle == null) { bundle = (SQLiteBundle) GWT.create(SQLiteBundle.class); Document doc = Document.get(); ScriptElement sqljs = doc.createScriptElement(); sqljs.setAttribute("type", "text/javascript"); sqljs.setInnerText(bundle.SqlJs().getText()); doc.getDocumentElement().getFirstChildElement().appendChild(sqljs); } if (data != null) return createWithDataJsni(data); return createJsni(); }
public final static SQLite create( JsArrayInteger data ) { if( bundle == null ) { bundle = (SQLiteBundle) GWT.create( SQLiteBundle.class ); Document doc = Document.get(); ScriptElement sqljs = doc.createScriptElement(); sqljs.setAttribute( "type", "text/javascript" ); sqljs.setInnerText( bundle.SqlJs().getText() ); doc.getDocumentElement().getFirstChildElement().appendChild( sqljs ); } if( data != null ) return createWithDataJsni( data ); return createJsni(); }
public static void ensureScriptsLoaded() { if( bundle != null ) return; bundle = GWT.create( JQueryBundle.class ); Document doc = Document.get(); ScriptElement sqljs = doc.createScriptElement(); sqljs.setAttribute( "type", "text/javascript" ); sqljs.setInnerText( bundle.JQueryJS().getText() ); doc.getDocumentElement().getFirstChildElement().appendChild( sqljs ); sqljs = doc.createScriptElement(); sqljs.setAttribute( "type", "text/javascript" ); sqljs.setInnerText( bundle.JQueryUIJS().getText() ); doc.getDocumentElement().getFirstChildElement().appendChild( sqljs ); }
@Override public void init( final String userAccount ) { final Element firstScript = Document.get().getElementsByTagName( "script" ).getItem( 0 ); final String source = "var _gaq = _gaq || [];_gaq.push(['_setAccount', '" + userAccount + "']);_gaq.push(['_trackPageview']);"; final ScriptElement config = Document.get().createScriptElement( source ); firstScript.getParentNode().insertBefore( config, firstScript ); final ScriptElement script = Document.get().createScriptElement(); // Add the google analytics script. script.setSrc( ( "https:".equals( Window.Location.getProtocol() ) ? "https://ssl" : "http://www" ) + ".google-analytics.com/ga.js" ); script.setType( "text/javascript" ); script.setAttribute( "async", "true" ); firstScript.getParentNode().insertBefore( script, firstScript ); }
/** * Loads Gadget RPC library script. */ private static void loadGadgetRpcScript() { ScriptElement script = Document.get().createScriptElement(); script.setType("text/javascript"); script.setSrc(Flags.get().gadgetRpcPath()); Document.get().getBody().appendChild(script); }
public native void addIEListener(JSLoad jsload, ScriptElement script, Loaded loaded) /*-{ var listener= @edu.caltech.ipac.firefly.ui.JSLoad::doneListenerStatic(Ledu/caltech/ipac/firefly/ui/JSLoad;Lcom/google/gwt/user/client/Event;); script.attachEvent( "onload", $entry( function(event) { listener(jsload, event); }) ); }-*/;
public native void addListener(JSLoad jsload, ScriptElement script, Loaded loaded) /*-{ var listener= @edu.caltech.ipac.firefly.ui.JSLoad::doneListenerStatic(Ledu/caltech/ipac/firefly/ui/JSLoad;Lcom/google/gwt/user/client/Event;); script.addEventListener( "load", $entry( function(event) { listener(jsload, event); }), false); }-*/;
public void doneListener(Event ev) { JavaScriptObject source= ev.getEventTarget(); if (_map.containsKey(source) && ScriptElement.is(source)) { _map.put(source,true); } else { // some error here } if (isAllLoaded()) allCompleteNotify(); }
@PostConstruct public void init() { final ScriptElement se = Document.get().createScriptElement(); se.setId("twitter-wjs"); se.setSrc("http://platform.twitter.com/widgets.js"); this.getElement().appendChild(se); }
/** * Method injecting native chart.js code into the browser<br/> * In case code already been injected do nothing */ public static void ensureInjected(){ //TODO: do real injection (lazy loading) if(injected) return; Resources res = GWT.create(Resources.class); String source = res.chartJsSource().getText(); ScriptElement scriptElement = Document.get().createScriptElement(); scriptElement.setId("_chartjs"); scriptElement.setInnerText(source); Document.get().getBody().appendChild(scriptElement); injected = true; }
private static void _ensureScriptLoaded() { if( bundle != null ) return; bundle = (RaphaelBundle) GWT.create( RaphaelBundle.class ); Document doc = Document.get(); ScriptElement sqljs = doc.createScriptElement(); sqljs.setAttribute( "type", "text/javascript" ); sqljs.setInnerText( bundle.RaphaelJs().getText() ); doc.getDocumentElement().getFirstChildElement().appendChild( sqljs ); }
public void preload( String url, Callback callback ) { if( !isScriptInstalled() ) { ScriptElement script = Document.get().createScriptElement(); script.setText( resources.preloadImageScript().getText() ); Document.get().getBody().appendChild( script ); } preloadImpl( id++, url, callback ); }
private void loadAnalyticsScript() { ScriptElement script = Document.get().createScriptElement(); script.setSrc(GoogleAnalyticsImpl.SCRIPT_URL); script.setType("text/javascript"); script.setAttribute("async", "true"); Element firstScript = Document.get().getElementsByTagName("script").getItem(0); firstScript.getParentNode().insertBefore(script, firstScript); }
private void initGA() { Document doc = Document.get(); ScriptElement script = doc.createScriptElement(); script.setSrc("https://ssl.google-analytics.com/ga.js"); script.setType("text/javascript"); script.setLang("javascript"); doc.getBody().appendChild(script); }
public static void inject(String javascript) { HeadElement head = getHead(); new Timer() { public void run() { // goJsPlumb(); goJS(); } }.schedule(1); ScriptElement element = createScriptElement(); element.setText(javascript); head.appendChild(element); }
public static void render() { ScriptElement scriptElement = Document.get().createScriptElement(); scriptElement.setType("text/javascript"); scriptElement.setAttribute("async", "true"); scriptElement.setSrc("https://apis.google.com/js/plusone.js"); getHead().appendChild(scriptElement); }
/** * Loads Gadget RPC library script. */ private static void loadGadgetRpcScript() { ScriptElement script = Document.get().createScriptElement(); script.setType("text/javascript"); script.setSrc(GADGET_RPC_PATH); Document.get().getBody().appendChild(script); }
public static void insertScript(String scriptSrc) { Document document = Document.get(); ScriptElement element = document.createScriptElement(); element.setType("text/javascript"); element.setLang("javascript"); document.getElementsByTagName("head").getItem(0).appendChild(element); element.setSrc(scriptSrc); }
public static void intject(String javaScript) { HeadElement head = getHead(); ScriptElement element = createScriptElement(); element.setText(javaScript); head.appendChild(element); }
private static ScriptElement createScriptElement() { ScriptElement script = Document.get().createScriptElement(); script.setAttribute("type", "text/javascript"); return script; }
private static ScriptElement createScriptElement() { ScriptElement script = Document.get().createScriptElement(); script.setAttribute("language", "javascript"); return script; }
public static void inject(String javascript) { HeadElement head = getHead(); ScriptElement element = createScriptElement(); element.setText(javascript); head.appendChild(element); }