@Inject public HelloWorldViewPresenter(final HelloWorldView helloWorldView) { this.helloWorldView = helloWorldView; ScriptInjector.fromUrl(GWT.getModuleBaseURL() + Constants.JAVASCRIPT_FILE_ID) .setWindow(ScriptInjector.TOP_WINDOW) .setCallback( new Callback<Void, Exception>() { @Override public void onSuccess(final Void result) { Log.info(HelloWorldViewPresenter.class, Constants.JAVASCRIPT_FILE_ID + " loaded."); sayHello("Hello from Java Script!"); } @Override public void onFailure(final Exception e) { Log.error( HelloWorldViewPresenter.class, "Unable to load " + Constants.JAVASCRIPT_FILE_ID, e); } }) .inject(); }
public void onModuleLoad() { ScriptInjector.fromUrl(GWT.getModuleBaseURL()+"bower_components/webcomponents-lite.min.js").setWindow(ScriptInjector.TOP_WINDOW).setCallback( new Callback<Void, Exception>() { @Override public void onSuccess(Void result) { LOGGER.info("injection success"); importPolymer(); } @Override public void onFailure(Exception reason) { } }).inject(); LOGGER.info("Initializing Layout client UI module ..."); new ModuleConfigurator().configureModule(new LayoutUIModuleConfiguration()); }
private void injectDocReadyAndC8OCoreScripts(final String convertigoMachineUrl) { final String convertigoStudioJsUrl = convertigoMachineUrl + "/convertigo/studio/js/"; // First, inject docready.js = $(document).ready() (but native JS function) final String docReadyJsUrl = convertigoStudioJsUrl + "libs/docready.js"; ScriptInjector .fromUrl(docReadyJsUrl) .setWindow(ScriptInjector.TOP_WINDOW) .setCallback(new Callback<Void, Exception>() { @Override public void onSuccess(Void result) { // ... then convertigo.js and main.js injectC8OCoreScripts(convertigoStudioJsUrl); } @Override public void onFailure(Exception reason) { Window.alert(formatScriptInjectFailure(docReadyJsUrl, convertigoMachineUrl)); } }) .inject(); }
public static void init() { if(init) return; init = true; String javaScript = "ammo.js"; final String js = GWT.getModuleBaseForStaticFiles() + javaScript; ScriptInjector.fromUrl(js).setCallback(new Callback<Void, Exception>() { @Override public void onFailure(Exception e) { GWT.log("inject " + js + " failure " + e); } @Override public void onSuccess(Void ok) { Bullet.initVariables(); } }).setWindow(ScriptInjector.TOP_WINDOW).inject(); }
private void injectJqueryScript() { // Workaround: https://goo.gl/1OrFqj ScriptInjector.fromUrl(JQUERY_UI_URL).setCallback(new Callback<Void, Exception>() { @Override public void onFailure(Exception reason) { logger.info("Script load failed Info: " + reason); } @Override public void onSuccess(Void result) { logger.info("JQuery for Select loaded successful!"); init(); } }).setRemoveTag(true).setWindow(ScriptInjector.TOP_WINDOW).inject(); }
private void addPremiumSupportHelpAction() { // userVoice init ScriptInjector.fromUrl(resources.userVoice().getSafeUri().asString()) .setWindow(ScriptInjector.TOP_WINDOW) .setCallback( new Callback<Void, Exception>() { @Override public void onSuccess(Void aVoid) { // add action actionManager.registerAction( localizationConstant.createSupportTicketAction(), createSupportTicketAction); helpGroup.addSeparator(); helpGroup.add(createSupportTicketAction); } @Override public void onFailure(Exception e) { Log.error(getClass(), "Unable to inject UserVoice", e); } }) .inject(); }
/** {@inheritDoc} */ @Override public void onModuleLoad() { if (!isjQueryLoaded()) { ScriptInjector.fromString(CytoscapeJsClientBundle.INSTANCE.jQuery().getText()) .setWindow(ScriptInjector.TOP_WINDOW) .inject(); } if (!isCytoscapeUtilsLoaded()) { ScriptInjector.fromString(CytoscapeJsClientBundle.INSTANCE.sageCytoscapeUtils().getText()) .setWindow(ScriptInjector.TOP_WINDOW) .inject(); } }
@Override public void onModuleLoad() { C3Resources resources = loadResources(); boolean pretty = isPretty(resources); GWT.log("[C3Js] Loading " + (pretty ? "pretty" : "obfuscated") + " resources"); TextResource c3Css = resources.c3Css(); GWT.log("[C3Js] Injecting CSS " + c3Css.getName()); StyleInjector.inject(c3Css.getText()); TextResource c3JavaScript = resources.c3JavaScript(); GWT.log("[C3Js] Injecting JavaScript " + c3JavaScript.getName()); ScriptInjector.fromString(c3JavaScript.getText()).setRemoveTag(pretty).setWindow(getWindow()).inject(); GWT.log("[C3Js] C3 v" + getC3Version() + " (using D3 v" + getD3Version() + ") loaded!"); }
@Override public void inject (final OnCompletion oc) { final String js = GWT.getModuleBaseForStaticFiles() + "freetype.js"; ScriptInjector.fromUrl(js).setCallback(new Callback<Void, Exception>() { @Override public void onFailure (Exception reason) { error = true; GWT.log("Exception injecting " + js, reason); oc.run(); } @Override public void onSuccess (Void result) { success = true; GWT.log("Success injecting js."); oc.run(); } }).setWindow(ScriptInjector.TOP_WINDOW).inject(); }
private static void injectScriptOneAfterAnother(final List<String> pathAsList) { ScriptInjector.fromUrl(pathAsList.remove(0)) .setWindow(ScriptInjector.TOP_WINDOW) .setCallback(new Callback<Void, Exception>() { @Override public void onFailure(Exception reason) { } @Override public void onSuccess(Void result) { if (!pathAsList.isEmpty()) { injectScriptOneAfterAnother(pathAsList); } } }) .inject(); }
@Inject public ActivityTrackingExtension(AppContext appContext) { ScriptInjector.fromUrl("/_app/activity.js") .setWindow(TOP_WINDOW) .setCallback( new Callback<Void, Exception>() { @Override public void onSuccess(Void result) { init(appContext.getMasterApiEndpoint(), appContext.getWorkspaceId()); } @Override public void onFailure(Exception reason) {} private native void init(String restContext, String wsId) /*-{ $wnd.ActivityTracker.init(restContext, wsId); }-*/; }) .inject(); }
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(); }
/** * Load the specified script. * * @param script Path to script. * @param callback {@code Callback} called when ready. */ public static void load( String script, Callback<Void, Exception> callback) { if (loadedScripts.contains(script)) { callback.onSuccess(null); return; } ScriptInjector.fromUrl(script) .setWindow(ScriptInjector.TOP_WINDOW) .setCallback(callback) .inject(); loadedScripts.add(script); }
void startPlugins(@Observes UberfireJSAPIReadyEvent event) { runtimePlugins.call(new RemoteCallback<List<RuntimePlugin>>() { @Override public void callback(List<RuntimePlugin> plugins) { try { for (final RuntimePlugin p : plugins) { if (isJSPlugin(p)) { ScriptInjector.fromString(p.getPluginContent()).setWindow(ScriptInjector.TOP_WINDOW).inject(); } else if (isPerspectivePlugin(p)) { perspectiveEditorGenerator.generatePerspective(p.getPluginContent()); } } } finally { workbench.removeStartupBlocker(RuntimePluginStartup.class); } } }).getRuntimePlugins(); }
/** * Loads a javascript file base on the file url */ public void inject() { if (this.cssUrl != null) { loadCss(this.cssUrl); } if (this.jsUrl != null) { scriptElement = ScriptInjector.fromUrl(this.jsUrl) .setCallback(new Callback<Void, Exception>() { @Override public void onSuccess(Void result) { if (ResourceInjector.this.callBack != null) { ResourceInjector.this.callBack.onJsLoaded(); } } @Override public void onFailure(Exception reason) { Window.alert(reason.getMessage() + " for link " + jsUrl); } }).setWindow(ScriptInjector.TOP_WINDOW).inject(); } }
public void setMode(final AceEditorMode mode) { final String modeId = "mode-" + mode.name().toLowerCase(); String js = modeId + ".js"; String path = Util.getModuleBaseUrl() + "ace/" + js; Element el = DOM.getElementById(modeId); if (el == null) { modeScriptElement = ScriptInjector.fromUrl(path).setCallback(new Callback<Void, Exception>() { @Override public void onSuccess(Void result) { JsoHelper.setAttribute(modeScriptElement, "id", modeId); AceEditor.this._setMode(mode); } @Override public void onFailure(Exception reason) { } }).setWindow(ScriptInjector.TOP_WINDOW).inject(); } else { this._setMode(mode); } }
public void setTheme(final AceEditorTheme theme) { final String themeId = "theme-" + theme.name().toLowerCase(); String js = themeId + ".js"; String path = Util.getModuleBaseUrl() + "ace/" + js; Element el = DOM.getElementById(themeId); if (el == null) { themeScriptElement = ScriptInjector.fromUrl(path).setCallback(new Callback<Void, Exception>() { @Override public void onSuccess(Void result) { JsoHelper.setAttribute(themeScriptElement, "id", themeId); AceEditor.this._setTheme(theme); } @Override public void onFailure(Exception reason) { } }).setWindow(ScriptInjector.TOP_WINDOW).inject(); } else { _setTheme(theme); } }
public void ensureWebComponentApi(Do onLoaded) { // Check if document.register exists if (!hasNativeSupport()) { // Nope... Lets inject our polyfill Mutable<JavaScriptObject> script = new Mutable<>(); script.in(ScriptInjector .fromUrl(getPolyfillUrl(VERSION)) .setCallback(voidCallback(() -> { if (VERSION == V1) { JsSupport.win().addEnteredListener("WebComponentsReady", onLoaded.onlyOnce().ignores1()::in, false); } else { onLoaded.done(); } // TODO: remove the script })) .setWindow(ScriptInjector.TOP_WINDOW) .inject()); } else { Scheduler.get().scheduleDeferred(onLoaded::done); } }
public void injectScript(String url, final Runnable onComplete) { ScriptInjector.fromUrl(url) .setCallback(new Callback<Void, Exception>() { @Override public void onFailure(Exception reason) { throw new RuntimeException(reason); } @Override public void onSuccess(Void result) { if (onComplete != null) { onComplete.run(); } } }).inject(); }
@Override public void onModuleLoad() { StyleInjector.injectAtEnd(FullCalendarClientBundle.INSTANCE.fullCalendarCss().getText()); StyleInjector.injectAtEnd("@media print {" + FullCalendarClientBundle.INSTANCE.fullCalendarPrintCss().getText() + "}"); if (!isMomentPresent()) { ScriptInjector.fromString(FullCalendarClientBundle.INSTANCE.getMomentJS().getText()).setWindow(ScriptInjector.TOP_WINDOW).inject(); } if (!isCalendarPresent()) { ScriptInjector.fromString(FullCalendarClientBundle.INSTANCE.getFullCalendarJS().getText()).setWindow(ScriptInjector.TOP_WINDOW).inject(); } if (!isDragAndResizePresent()) { ScriptInjector.fromString(FullCalendarClientBundle.INSTANCE.getCustomDragResizeJS().getText()).setWindow(ScriptInjector.TOP_WINDOW).inject(); } }
public EventSource(final String url, final String color, final String backgroundColor, final String textColor, final String borderColor, final String className, final boolean isEditable, final boolean isStartEditable, final boolean isDurationEditable, final boolean allDayDefault, final boolean ignoreTimeZone, final boolean isGoogle//if true include google script file ) { if (isGoogle && !GCAL_ADDED) { GCAL_ADDED = true; ScriptInjector.fromString(FullCalendarClientBundle.INSTANCE.getGoogleCalJS().getText()).setWindow(ScriptInjector.TOP_WINDOW).inject(); } newEvent(url, color, backgroundColor, textColor, borderColor, className, isEditable, isStartEditable, isDurationEditable, allDayDefault, ignoreTimeZone); }
@Override public final void onModuleLoad() { LOG.info("AbstractModule.onModuleLoad: moduleName=" + GWT.getModuleName()); ScriptInjector.fromUrl(GWT.getModuleBaseURL() + "config.js") .setRemoveTag(true) .setWindow(ScriptInjector.TOP_WINDOW) .setCallback(new Callback<Void, Exception>() { @Override public void onSuccess(Void result) { LOG.info("AbstractModule.onModuleLoad#fromUrl#onSuccess"); onModuleConfigured(); } @Override public void onFailure(Exception reason) { LOG.log(Level.SEVERE, "AbstractModule.onModuleLoad#fromUrl#onFailure:", reason); } }) .inject(); }
public void show() { UniTimePageLabel.getInstance().setPageName(iRoom.getUniqueId() == null ? MESSAGES.pageAddRoom() : MESSAGES.pageEditRoom()); setVisible(true); iLastScrollLeft = Window.getScrollLeft(); iLastScrollTop = Window.getScrollTop(); onShow(); Window.scrollTo(0, 0); if (iGoogleMap != null) { if (isGoogleMapEditable() || iRoom.hasCoordinates()) { iGoogleMap.setVisible(true); if (!iGoogleMapInitialized) { iGoogleMapInitialized = true; ScriptInjector.fromUrl("https://maps.googleapis.com/maps/api/js?" + (iProperties != null && iProperties.hasGoogleMapApiKey() ? "key=" + iProperties.getGoogleMapApiKey() + "&" : "") + "sensor=false&callback=setupGoogleMap").setWindow(ScriptInjector.TOP_WINDOW).setCallback( new Callback<Void, Exception>() { @Override public void onSuccess(Void result) { } @Override public void onFailure(Exception e) { UniTimeNotifications.error(e.getMessage(), e); iGoogleMap = null; iGoogleMapControl = null; } }).inject(); } else if (iGoogleMap != null) { setMarker(); } } else { iGoogleMap.setVisible(false); } } }
/** * Injects lazy firebase loading inside GWT application. */ public void init() { if (rawHtml == null) { Gdx.app.error("GdxFireapp", "You forgot about calling FirebaseConfiguration#init() first."); return; } ScriptInjector.fromUrl(configParser.getFirebaseScriptSrc()) .setRemoveTag(false) .setWindow(ScriptInjector.TOP_WINDOW) .setCallback(new ScriptLoadedCallback(configParser)) .inject(); }
@Inject public MainViewPresenter(MainView mainView, AppContext appContext) { this.mainView = mainView; this.appContext = appContext; exportGetKeyConvertigoMachineUrl(); exportInjectDocReadyAndC8OCoreScripts(); exportGetConvertigoMachineUrl(); defineConvertigoUrl(getConvertigoMachineUrl()); final String jsFile = "init.js"; ScriptInjector.fromUrl(GWT.getModuleBaseURL() + jsFile) .setWindow(ScriptInjector.TOP_WINDOW) .setCallback(new Callback<Void, Exception>() { @Override public void onSuccess(final Void result) { Log.info(MainViewPresenter.class, jsFile + " loaded."); } @Override public void onFailure(final Exception e) { Log.error(MainViewPresenter.class, "Unable to load " + jsFile, e); } }) .inject(); }
private void injectMyFunctionScript() { ScriptInjector.fromUrl(MYFUNCTION_URL).setCallback(new Callback<Void, Exception>() { @Override public void onFailure(Exception reason) { logger.info("Script load failed Info: " + reason); } @Override public void onSuccess(Void result) { logger.info("MyFunction loaded successful!"); } }).setRemoveTag(true).setWindow(ScriptInjector.TOP_WINDOW).inject(); }
public void initComponent(String uploadId) { this.jsIncludeUri = bootstrapJsUrl + "?v=" + resourcesVersion; this.swfUri = flashUrl + "?v=" + resourcesVersion; this.uploadId = uploadId; this.uploadButton.setId("upload_button_" + uploadId); this.progressDiv.setId("upload_progress_" + uploadId); this.themeDiv.setClassName(themeName); if (!scriptInjected) { ScriptInjector.fromUrl(jsIncludeUri).setCallback(new Callback<Void, Exception>() { @Override public void onFailure(Exception reason) { if (bootstrapFailureHandler != null) bootstrapFailureHandler.resourceLoadFailed(); setDisabled(); } @Override public void onSuccess(Void result) { checkAndInitialize(); } }).setWindow(getWindow()).setRemoveTag(false).inject(); scriptInjected = true; } else { checkAndInitialize(); } }
public static boolean loadLibrary() { String scriptUrl = ""; if (libraryVersion == TINYMCE_VERSION_4) { scriptUrl = GWT.getModuleBaseURL() + "tinymce4/tinymce.min.js"; } else if (libraryVersion == TINYMCE_VERSION_3) { // scriptUrl = GWT.getModuleBaseURL() + "tinymce3/tiny_mce.js"; return false; // Security Audit found an issue with using eval. Removing from code base for now. 4.20.2015 } else { // No such version allowed. return false; } JavaScriptObject scriptInstance = ScriptInjector.fromUrl(scriptUrl) .setWindow(ScriptInjector.TOP_WINDOW) .setCallback(new Callback<Void, Exception>() { @Override public void onFailure(Exception reason) { Window.alert("TinyMCE failed to load."); libraryLoaded = false; } @Override public void onSuccess(Void result) { // We need to register the Javascript method that will handle all of the events. registerEventHandler(); libraryLoaded = true; } }).inject(); return (scriptInstance != null); }
protected static void directInjectJs(TextResource resource, boolean removeTag, boolean sourceUrl) { String text = resource.getText() + (sourceUrl ? "//# sourceURL=" + resource.getName() + ".js" : ""); // Inject the script resource ScriptInjector.fromString(text) .setWindow(ScriptInjector.TOP_WINDOW) .setRemoveTag(removeTag) .inject(); }
protected void setupLanguage(DatePickerLanguage language) { if (language.getJs() != null) { ScriptInjector.fromString(language.getJs().getText()).setWindow(ScriptInjector.TOP_WINDOW).inject(); getPicker().stop(); Scheduler.get().scheduleDeferred(() -> load()); } }
protected void inject(TextResource resource, boolean removeTag, boolean sourceUrl) { String text = resource.getText() + (sourceUrl ? "//# sourceURL="+resource.getName()+".js" : ""); // Inject the script resource ScriptInjector.fromString(text) .setWindow(ScriptInjector.TOP_WINDOW) .setRemoveTag(removeTag) .inject(); }
public void require( final RequirejsCallback callback, final RequirejsErrorHandler errorHandler, final RequirejsConfig config, final String[] requiredScripts, final String[] moduleKeys) { if (!requirejsLoaded && !requirejsLoadFailed) { Log.debug(RequireJsLoader.class, "Loading require.js."); /** Using GWT.getModuleBaseForStaticFiles() blocks CodeMirror to run under Super Dev Mode */ ScriptInjector.fromUrl(GWT.getModuleBaseURL() + "require.js") .setWindow(ScriptInjector.TOP_WINDOW) .setCallback( new Callback<Void, Exception>() { @Override public void onSuccess(final Void result) { Log.debug(RequireJsLoader.class, "require.js loaded."); configureGlobalErrorCallback(); requireScripts(callback, errorHandler, config, requiredScripts, moduleKeys); requirejsLoaded = true; } @Override public void onFailure(final Exception e) { Log.error(RequireJsLoader.class, "Unable to load require.js", e); requirejsLoadFailed = true; } }) .inject(); } else if (!requirejsLoadFailed) { requireScripts(callback, null, config, requiredScripts, moduleKeys); } else { Log.error(RequireJsLoader.class, "Require.js load failed, cannot require scripts."); } }
/** * Injects the JS script, that communicates with a Code Server, into a host page. * * @param url host URL where script is located. Usually should be a Code Server URL * @return promise that may be resolved if script has been injected successfully or rejected in * case of any error while script injection */ Promise<Void> inject(String url) { return CallbackPromiseHelper.createFromCallback( promiseCallback -> ScriptInjector.fromUrl(url + DEV_MODE_SCRIPT_NAME) .setWindow(JsBrowser.getWindow()) .setCallback(getScriptInjectionCallback(promiseCallback)) .inject()); }
private void load(List<String> pluginUrls) { for (String url : pluginUrls) { Plugin plugin = Plugin.create(url); plugins().put(url, plugin); ScriptInjector.fromUrl(url) .setWindow(ScriptInjector.TOP_WINDOW) .setCallback(new LoadCallback(plugin)) .inject(); } }
@Override public void load(final Runnable callback) { super.load(new Runnable() { @Override public void run() { ScriptInjector.fromString("jQuery.noConflict();") .setWindow(ScriptInjector.TOP_WINDOW) .inject(); callback.run(); } }); }
@Override public void emit (StringBuilder out, final List<String> lines, final Map<String, String> params) { MapPluginItem item = new MapPluginItem(); item.mapManager = manager; item.instance = this; item.id = HTMLPanel.createUniqueId(); item.lines = lines; item.params = params; items.put(item.id, item); out.append("<div id=\""); out.append(item.id); out.append("\">Loading maps API...</div>"); if (!added) { added = true; ScriptInjector.fromUrl( "https://maps.googleapis.com/maps/api/js?callback=mapsInitialised&key=" + apiKey) .setCallback(EMPTY).inject(); } if (initialised) { mapsInitialised(); } }
@Override protected void onLoad () { super.onLoad(); if (SCRIPT == null) { exposeMethod(this); SCRIPT = ScriptInjector.fromUrl( "https://www.google.com/recaptcha/api.js?onload=call_65fd7992_9064_11e5_aeca_fbe3616fc7e4&render=explicit") .setWindow(ScriptInjector.TOP_WINDOW).inject().cast(); } else { render(); } }
void injectScripts() { ScriptInjector.fromString(HtmlEditorResources.INSTANCE.wysihtml().getText()).setWindow(TOP_WINDOW).inject(); ScriptInjector.fromString(HtmlEditorResources.INSTANCE.wysihtmlAllCommands().getText()).setWindow(TOP_WINDOW).inject(); ScriptInjector.fromString(HtmlEditorResources.INSTANCE.wysihtmlTableEditing().getText()).setWindow(TOP_WINDOW).inject(); ScriptInjector.fromString(HtmlEditorResources.INSTANCE.wysihtmlToolbar().getText()).setWindow(TOP_WINDOW).inject(); ScriptInjector.fromString(HtmlEditorResources.INSTANCE.parserRules().getText()).setWindow(TOP_WINDOW).inject(); PatternFlyBootstrapper.ensurejQueryIsAvailable(); }