Java Code Examples for org.apache.wicket.markup.head.OnLoadHeaderItem

The following examples show how to use org.apache.wicket.markup.head.OnLoadHeaderItem. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: onedev   Author: theonedev   File: InfiniteScrollBehavior.java    License: MIT License 6 votes vote down vote up
@Override
public void renderHead(Component component, IHeaderResponse response) {
	super.renderHead(component, response);
	response.render(JavaScriptReferenceHeaderItem.forReference(new InfiniteScrollResourceReference()));
	
	String itemSelector;
	if (getItemSelector() != null)
		itemSelector = "'"+JavaScriptEscape.escapeJavaScript(getItemSelector())+"'";
	else
		itemSelector = "undefined";
	
	// Run onload script as the container size might be adjusted in window resize event (which 
	// happens before onload). An example is the issue board columns
	String script = String.format("onedev.server.infiniteScroll.onLoad('%s', %s, %s, %s);", 
			component.getMarkupId(true), getCallbackFunction(explicit("offset"), explicit("count")), 
			pageSize, itemSelector);
	response.render(OnLoadHeaderItem.forScript(script));
}
 
Example #2
Source Project: onedev   Author: theonedev   File: CodePropertyEditor.java    License: MIT License 6 votes vote down vote up
@Override
public void renderHead(IHeaderResponse response) {
	super.renderHead(response);
	response.render(JavaScriptHeaderItem.forReference(new CodeSupportResourceReference()));

	CallbackParameter matchWith = CallbackParameter.explicit("matchWith");
	CallbackParameter line = CallbackParameter.explicit("line");
	CallbackParameter start = CallbackParameter.explicit("start");
	CallbackParameter end = CallbackParameter.explicit("end");
	String script = String.format(
			"onedev.server.codeSupport.onEditorDomReady('%s', '%s', %s);", 
			input.getMarkupId(), 
			getCode().language(), 
			behavior.getCallbackFunction(matchWith, line, start, end));
	response.render(OnLoadHeaderItem.forScript(script));
}
 
Example #3
Source Project: onedev   Author: theonedev   File: AbstractSelect2Choice.java    License: MIT License 6 votes vote down vote up
@Override
public void renderHead(IHeaderResponse response) {
	super.renderHead(response);

	// initialize select2
	response.render(JavaScriptHeaderItem.forReference(new Select2ResourceReference()));

	// Use OnLoad instead of OnDomReady here as otherwise the placeholder 
	// of multi-choice can not be displayed in a modal dialog
	response.render(OnLoadHeaderItem.forScript(JQuery.execute("$('#%s').select2(%s);", 
			getJquerySafeMarkupId(), settings.toJson())));

	// select current value

	renderInitializationScript(response);
}
 
Example #4
Source Project: onedev   Author: theonedev   File: Select2Choice.java    License: MIT License 6 votes vote down vote up
@Override
protected void renderInitializationScript(IHeaderResponse response) {
	T value;
	if (getWebRequest().getRequestParameters().getParameterNames().contains(getInputName())) {
		convertInput();
		value = getConvertedInput();
	} else {
		value = getModelObject();
	}
	if (value != null) {

		JsonBuilder selection = new JsonBuilder();

		try {
			selection.object();
			getProvider().toJson(value, selection);
			selection.endObject();
		} catch (JSONException e) {
			throw new RuntimeException("Error converting model object to Json", e);
		}
		response.render(OnLoadHeaderItem.forScript(
				JQuery.execute("$('#%s').select2('data', %s);", getJquerySafeMarkupId(), selection.toJson())));
	} else {
		clearInput();
	}
}
 
Example #5
Source Project: sakai   Author: sakaiproject   File: WidgetPage.java    License: Educational Community License v2.0 6 votes vote down vote up
@Override
public void renderHead(final IHeaderResponse response) {
	super.renderHead(response);
	
	// get the Sakai skin header fragment from the request attribute
	final HttpServletRequest request = (HttpServletRequest) getRequest().getContainerRequest();

	response.render(StringHeaderItem.forString((String) request.getAttribute("sakai.html.head")));
	response.render(OnLoadHeaderItem.forScript("setMainFrameHeight( window.name )"));

	// Tool additions (at end so we can override if required)
	response.render(StringHeaderItem.forString("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />"));

	// render jQuery and the Wicket event library
	// Both must be priority so they are emitted into the head
	final String cdnQuery = PortalUtils.getCDNQuery();
	response.render(new PriorityHeaderItem(JavaScriptHeaderItem.forUrl(String.format(PortalUtils.getLatestJQueryPath()+ "?version=%s", cdnQuery))));
	response.render(new PriorityHeaderItem(JavaScriptHeaderItem.forUrl(String.format("/my-calendar/scripts/wicket/wicket-event-jquery.min.js?version=%s", cdnQuery))));

	// NOTE: All libraries apart from jQuery and Wicket Event must be rendered inline with the application. See WidgetPage.html.
}
 
Example #6
Source Project: sakai   Author: sakaiproject   File: BasePage.java    License: Educational Community License v2.0 6 votes vote down vote up
/**
 * This block adds the required wrapper markup to style it like a Sakai tool. 
 * Add to this any additional CSS or JS references that you need.
 * 
 */
public void renderHead(IHeaderResponse response) {
	
	
	//get Sakai skin
	String skinRepo = sakaiProxy.getSkinRepoProperty();
	String toolCSS = sakaiProxy.getToolSkinCSS(skinRepo);
	String toolBaseCSS = skinRepo + "/tool_base.css";
	
	//Sakai additions				
	response.render(JavaScriptReferenceHeaderItem.forUrl("/library/js/headscripts.js"));
	response.render(CssReferenceHeaderItem.forUrl(toolBaseCSS));
	response.render(CssReferenceHeaderItem.forUrl(toolCSS));
	response.render (OnLoadHeaderItem.forScript("setMainFrameHeight( window.name )"));
	response.render(StringHeaderItem.forString("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />"));					
	
}
 
Example #7
Source Project: sakai   Author: sakaiproject   File: WidgetPage.java    License: Educational Community License v2.0 6 votes vote down vote up
@Override
public void renderHead(final IHeaderResponse response) {
    super.renderHead(response);

    // get the Sakai skin header fragment from the request attribute
    final HttpServletRequest request = (HttpServletRequest) getRequest().getContainerRequest();

    response.render(StringHeaderItem.forString((String) request.getAttribute("sakai.html.head")));
    response.render(OnLoadHeaderItem.forScript("setMainFrameHeight( window.name )"));

    // Tool additions (at end so we can override if required)
    response.render(StringHeaderItem.forString("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />"));

    // render jQuery and the Wicket event library
    // Both must be priority so they are emitted into the head
    final String cdnQuery = PortalUtils.getCDNQuery();
    response.render(new PriorityHeaderItem(JavaScriptHeaderItem.forUrl(String.format(PortalUtils.getLatestJQueryPath()+ "?version=%s", cdnQuery))));
    response.render(new PriorityHeaderItem(JavaScriptHeaderItem.forUrl(String.format("/my-calendar/scripts/wicket/wicket-event-jquery.min.js?version=%s", cdnQuery))));

    // NOTE: All libraries apart from jQuery and Wicket Event must be rendered inline with the application. See WidgetPage.html.
}
 
Example #8
Source Project: sakai   Author: sakaiproject   File: BasePage.java    License: Educational Community License v2.0 6 votes vote down vote up
@Override
public void renderHead(final IHeaderResponse response) {

	// get the Sakai skin header fragment from the request attribute
	final HttpServletRequest request = (HttpServletRequest) getRequest().getContainerRequest();

	final String sakaiHtmlHead = (String) request.getAttribute("sakai.html.head");
	if (StringUtils.isNotBlank(sakaiHtmlHead)) {
		response.render(StringHeaderItem.forString((String) request.getAttribute("sakai.html.head")));
	}
	response.render(OnLoadHeaderItem.forScript("setMainFrameHeight( window.name )"));

	String version = PortalUtils.getCDNQuery();

	// Tool additions (at end so we can override if required)
	response.render(StringHeaderItem.forString("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />"));
	response.render(CssHeaderItem.forUrl(String.format("/profile2-tool/css/profile2.css%s", version)));
	response.render(JavaScriptHeaderItem.forUrl(String.format("/profile2-tool/javascript/profile2.js%s", version)));

}
 
Example #9
Source Project: sakai   Author: sakaiproject   File: WidgetPage.java    License: Educational Community License v2.0 6 votes vote down vote up
@Override
public void renderHead(final IHeaderResponse response) {

    super.renderHead(response);

    final String version = this.serverConfigurationService.getString("portal.cdn.version", "");

    // get the Sakai skin header fragment from the request attribute
    final HttpServletRequest request = (HttpServletRequest) getRequest().getContainerRequest();

    response.render(StringHeaderItem.forString((String) request.getAttribute("sakai.html.head")));
    response.render(OnLoadHeaderItem.forScript("setMainFrameHeight( window.name )"));

    // Tool additions (at end so we can override if required)
    response.render(StringHeaderItem.forString("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />"));

    // render jQuery and the Wicket event library
    // Both must be priority so they are emitted into the head
    response.render(new PriorityHeaderItem(JavaScriptHeaderItem.forUrl(String.format("/library/webjars/jquery/1.12.4/jquery.min.js?version=%s", version))));
    response.render(new PriorityHeaderItem(JavaScriptHeaderItem.forUrl(String.format("/site-description/scripts/wicket/wicket-event-jquery.min.js?version=%s", version))));

    // NOTE: All libraries apart from jQuery and Wicket Event must be rendered inline with the application. See WidgetPage.html.
}
 
Example #10
Source Project: sakai   Author: sakaiproject   File: WidgetPage.java    License: Educational Community License v2.0 6 votes vote down vote up
@Override
public void renderHead(final IHeaderResponse response) {
    super.renderHead(response);

    final String version = this.serverConfigurationService.getString("portal.cdn.version", "");

    // get the Sakai skin header fragment from the request attribute
    final HttpServletRequest request = (HttpServletRequest) getRequest().getContainerRequest();

    response.render(StringHeaderItem.forString((String) request.getAttribute("sakai.html.head")));
    response.render(OnLoadHeaderItem.forScript("setMainFrameHeight( window.name )"));

    // Tool additions (at end so we can override if required)
    response.render(StringHeaderItem.forString("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />"));

    // render jQuery and the Wicket event library
    // Both must be priority so they are emitted into the head
    response.render(new PriorityHeaderItem(JavaScriptHeaderItem.forUrl(String.format("/library/webjars/jquery/1.12.4/jquery.min.js?version=%s", version))));
    response.render(new PriorityHeaderItem(JavaScriptHeaderItem.forUrl(String.format("/mycalendar/scripts/wicket/wicket-event-jquery.min.js?version=%s", version))));

    // additional styles (datepicker, this widget etc)
    response.render(CssHeaderItem.forUrl(String.format("/library/webjars/jquery-ui/1.12.1/jquery-ui.min.css?version=%s", version)));

    // NOTE: All libraries apart from jQuery and Wicket Event must be rendered inline with the application. See WidgetPage.html.

}
 
Example #11
Source Project: sakai   Author: sakaiproject   File: BaseChart.java    License: Educational Community License v2.0 6 votes vote down vote up
@Override
public void renderHead(final IHeaderResponse response) {

	final String version = PortalUtils.getCDNQuery();

	// chart requires ChartJS
	response.render(
			JavaScriptHeaderItem.forUrl(String.format("/gradebookng-tool/webjars/chartjs/2.7.0/Chart.min.js%s", version)));

	// our chart functions
	response.render(
			JavaScriptHeaderItem.forUrl(String.format("/gradebookng-tool/scripts/gradebook-chart.js%s", version)));

	// render immediately (for all subclasses)
	final GbChartData data = getData();
	response.render(OnLoadHeaderItem.forScript("renderChart('" + toJson(data) + "');"));
}
 
Example #12
Source Project: syncope   Author: apache   File: ImplementationModalPanel.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void renderHead(final IHeaderResponse response) {
    super.renderHead(response);
    if (viewMode != ViewMode.JAVA_CLASS) {
        response.render(OnLoadHeaderItem.forScript(
                "editor = CodeMirror.fromTextArea("
                + "document.getElementById('groovyClassForm').children['groovyClass'], {"
                + "  readOnly: false, "
                + "  lineNumbers: true, "
                + "  lineWrapping: true, "
                + "  matchBrackets: true,"
                + "  autoCloseBrackets: true,"
                + (viewMode == ViewMode.GROOVY_BODY ? "  mode: 'text/x-groovy'," : "")
                + "  autoRefresh: true"
                + "});"
                + "editor.on('change', updateTextArea);"));
    }
}
 
Example #13
Source Project: syncope   Author: apache   File: BinaryTextPreviewer.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void renderHead(final IHeaderResponse response) {
    super.renderHead(response);
    String options;
    switch (mimeType) {
        case MediaType.APPLICATION_JSON:
            options = "matchBrackets: true, autoCloseBrackets: true,";
            break;
        case MediaType.APPLICATION_XML:
            options = "autoCloseTags: true, mode: 'text/html',";
            break;
        default:
            options = "mode: 'text/html',";
    }

    response.render(OnLoadHeaderItem.forScript(
            "var editor = CodeMirror.fromTextArea(document.getElementById('" + jsonEditorInfoId + "'), {"
            + "  readOnly: true, "
            + "  lineNumbers: true, "
            + "  lineWrapping: false, "
            + options
            + "  autoRefresh: true"
            + "});"
            + "editor.setSize('500', 100)"));
}
 
Example #14
Source Project: sakai   Author: sakaiproject   File: WidgetPage.java    License: Educational Community License v2.0 6 votes vote down vote up
@Override
public void renderHead(final IHeaderResponse response) {
	super.renderHead(response);
	
	// get the Sakai skin header fragment from the request attribute
	final HttpServletRequest request = (HttpServletRequest) getRequest().getContainerRequest();

	response.render(StringHeaderItem.forString((String) request.getAttribute("sakai.html.head")));
	response.render(OnLoadHeaderItem.forScript("setMainFrameHeight( window.name )"));

	// Tool additions (at end so we can override if required)
	response.render(StringHeaderItem.forString("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />"));

	// render jQuery and the Wicket event library
	// Both must be priority so they are emitted into the head
	final String cdnQuery = PortalUtils.getCDNQuery();
	response.render(new PriorityHeaderItem(JavaScriptHeaderItem.forUrl(String.format(PortalUtils.getLatestJQueryPath()+ "?version=%s", cdnQuery))));
	response.render(new PriorityHeaderItem(JavaScriptHeaderItem.forUrl(String.format("/my-calendar/scripts/wicket/wicket-event-jquery.min.js?version=%s", cdnQuery))));

	// NOTE: All libraries apart from jQuery and Wicket Event must be rendered inline with the application. See WidgetPage.html.
}
 
Example #15
Source Project: sakai   Author: sakaiproject   File: BasePage.java    License: Educational Community License v2.0 6 votes vote down vote up
/**
 * This block adds the required wrapper markup to style it like a Sakai tool. 
 * Add to this any additional CSS or JS references that you need.
 * 
 */
public void renderHead(IHeaderResponse response) {
	
	
	//get Sakai skin
	String skinRepo = sakaiProxy.getSkinRepoProperty();
	String toolCSS = sakaiProxy.getToolSkinCSS(skinRepo);
	String toolBaseCSS = skinRepo + "/tool_base.css";
	
	//Sakai additions				
	response.render(JavaScriptReferenceHeaderItem.forUrl("/library/js/headscripts.js"));
	response.render(CssReferenceHeaderItem.forUrl(toolBaseCSS));
	response.render(CssReferenceHeaderItem.forUrl(toolCSS));
	response.render (OnLoadHeaderItem.forScript("setMainFrameHeight( window.name )"));
	response.render(StringHeaderItem.forString("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />"));					
	
}
 
Example #16
Source Project: sakai   Author: sakaiproject   File: WidgetPage.java    License: Educational Community License v2.0 6 votes vote down vote up
@Override
public void renderHead(final IHeaderResponse response) {
    super.renderHead(response);

    // get the Sakai skin header fragment from the request attribute
    final HttpServletRequest request = (HttpServletRequest) getRequest().getContainerRequest();

    response.render(StringHeaderItem.forString((String) request.getAttribute("sakai.html.head")));
    response.render(OnLoadHeaderItem.forScript("setMainFrameHeight( window.name )"));

    // Tool additions (at end so we can override if required)
    response.render(StringHeaderItem.forString("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />"));

    // render jQuery and the Wicket event library
    // Both must be priority so they are emitted into the head
    final String cdnQuery = PortalUtils.getCDNQuery();
    response.render(new PriorityHeaderItem(JavaScriptHeaderItem.forUrl(String.format(PortalUtils.getLatestJQueryPath()+ "?version=%s", cdnQuery))));
    response.render(new PriorityHeaderItem(JavaScriptHeaderItem.forUrl(String.format("/my-calendar/scripts/wicket/wicket-event-jquery.min.js?version=%s", cdnQuery))));

    // NOTE: All libraries apart from jQuery and Wicket Event must be rendered inline with the application. See WidgetPage.html.
}
 
Example #17
Source Project: sakai   Author: sakaiproject   File: BasePage.java    License: Educational Community License v2.0 6 votes vote down vote up
@Override
public void renderHead(final IHeaderResponse response) {

	// get the Sakai skin header fragment from the request attribute
	final HttpServletRequest request = (HttpServletRequest) getRequest().getContainerRequest();

	final String sakaiHtmlHead = (String) request.getAttribute("sakai.html.head");
	if (StringUtils.isNotBlank(sakaiHtmlHead)) {
		response.render(StringHeaderItem.forString((String) request.getAttribute("sakai.html.head")));
	}
	response.render(OnLoadHeaderItem.forScript("setMainFrameHeight( window.name )"));

	String version = PortalUtils.getCDNQuery();

	// Tool additions (at end so we can override if required)
	response.render(StringHeaderItem.forString("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />"));
	response.render(CssHeaderItem.forUrl(String.format("/profile2-tool/css/profile2.css%s", version)));
	response.render(JavaScriptHeaderItem.forUrl(String.format("/profile2-tool/javascript/profile2.js%s", version)));

}
 
Example #18
Source Project: sakai   Author: sakaiproject   File: WidgetPage.java    License: Educational Community License v2.0 6 votes vote down vote up
@Override
public void renderHead(final IHeaderResponse response) {

    super.renderHead(response);

    final String version = this.serverConfigurationService.getString("portal.cdn.version", "");

    // get the Sakai skin header fragment from the request attribute
    final HttpServletRequest request = (HttpServletRequest) getRequest().getContainerRequest();

    response.render(StringHeaderItem.forString((String) request.getAttribute("sakai.html.head")));
    response.render(OnLoadHeaderItem.forScript("setMainFrameHeight( window.name )"));

    // Tool additions (at end so we can override if required)
    response.render(StringHeaderItem.forString("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />"));

    // render jQuery and the Wicket event library
    // Both must be priority so they are emitted into the head
    response.render(new PriorityHeaderItem(JavaScriptHeaderItem.forUrl(String.format("/library/webjars/jquery/1.12.4/jquery.min.js?version=%s", version))));
    response.render(new PriorityHeaderItem(JavaScriptHeaderItem.forUrl(String.format("/site-description/scripts/wicket/wicket-event-jquery.min.js?version=%s", version))));

    // NOTE: All libraries apart from jQuery and Wicket Event must be rendered inline with the application. See WidgetPage.html.
}
 
Example #19
Source Project: sakai   Author: sakaiproject   File: WidgetPage.java    License: Educational Community License v2.0 6 votes vote down vote up
@Override
public void renderHead(final IHeaderResponse response) {
    super.renderHead(response);

    final String version = this.serverConfigurationService.getString("portal.cdn.version", "");

    // get the Sakai skin header fragment from the request attribute
    final HttpServletRequest request = (HttpServletRequest) getRequest().getContainerRequest();

    response.render(StringHeaderItem.forString((String) request.getAttribute("sakai.html.head")));
    response.render(OnLoadHeaderItem.forScript("setMainFrameHeight( window.name )"));

    // Tool additions (at end so we can override if required)
    response.render(StringHeaderItem.forString("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />"));

    // render jQuery and the Wicket event library
    // Both must be priority so they are emitted into the head
    response.render(new PriorityHeaderItem(JavaScriptHeaderItem.forUrl(String.format("/library/webjars/jquery/1.12.4/jquery.min.js?version=%s", version))));
    response.render(new PriorityHeaderItem(JavaScriptHeaderItem.forUrl(String.format("/mycalendar/scripts/wicket/wicket-event-jquery.min.js?version=%s", version))));

    // additional styles (datepicker, this widget etc)
    response.render(CssHeaderItem.forUrl(String.format("/library/webjars/jquery-ui/1.12.1/jquery-ui.min.css?version=%s", version)));

    // NOTE: All libraries apart from jQuery and Wicket Event must be rendered inline with the application. See WidgetPage.html.

}
 
Example #20
Source Project: sakai   Author: sakaiproject   File: BaseChart.java    License: Educational Community License v2.0 6 votes vote down vote up
@Override
public void renderHead(final IHeaderResponse response) {

	final String version = PortalUtils.getCDNQuery();

	// chart requires ChartJS
	response.render(
			JavaScriptHeaderItem.forUrl(String.format("/gradebookng-tool/webjars/chartjs/2.7.0/Chart.min.js%s", version)));

	// our chart functions
	response.render(
			JavaScriptHeaderItem.forUrl(String.format("/gradebookng-tool/scripts/gradebook-chart.js%s", version)));

	// render immediately (for all subclasses)
	final GbChartData data = getData();
	response.render(OnLoadHeaderItem.forScript("renderChart('" + toJson(data) + "');"));
}
 
Example #21
Source Project: inception   Author: inception-project   File: TutorialFooterPanel.java    License: Apache License 2.0 5 votes vote down vote up
@Override
    public void renderHead(IHeaderResponse aResponse) {
        aResponse.render(JavaScriptHeaderItem.forReference(WebAnnoJavascriptReference.get()));
        
        //TODO move it back to web jars after latest release
        aResponse.render(JavaScriptHeaderItem.forReference(EnjoyHintJsReference.get()));
//        aResponse.render(JavaScriptHeaderItem
//                .forReference(new WebjarsJavaScriptResourceReference("enjoyhint/current/enjoyhint.js")));

        // Loading resources for the tour guide feature for the new users
        aResponse.render(JavaScriptHeaderItem.forReference(
                new WebjarsJavaScriptResourceReference("enjoyhint/current/jquery.enjoyhint.js")));
        aResponse.render(CssHeaderItem.forReference(
                new WebjarsCssResourceReference("enjoyhint/current/jquery.enjoyhint.css")));
        aResponse.render(JavaScriptHeaderItem.forReference(new WebjarsJavaScriptResourceReference(
                "jquery.scrollTo/current/jquery.scrollTo.js")));
        aResponse.render(JavaScriptHeaderItem.forReference(
                new WebjarsJavaScriptResourceReference("kinetic/current/kinetic.min.js")));

        aResponse.render(JavaScriptHeaderItem.forReference(TutorialJavascriptReference.get()));
        // add top-margin to next button to fix label and buttons overlapping
        aResponse.render(CssHeaderItem.forCSS(
                ".enjoyhint_next_btn{\n" +
                "  margin-top: 8px;\n" +
                "}",
                "enjoyhint"));
        // check if the tutorial will need to be run
        aResponse.render(OnLoadHeaderItem
                .forScript("setContextPath('" + context.getContextPath() + "');\n" +
                           "runRoutines();"));
    }
 
Example #22
Source Project: onedev   Author: theonedev   File: SortBehavior.java    License: MIT License 5 votes vote down vote up
@Override
public void renderHead(Component component, IHeaderResponse response) {
	super.renderHead(component, response);
	response.render(JavaScriptHeaderItem.forReference(new JQueryUIResourceReference()));
	response.render(CssHeaderItem.forReference(new SortableCssResourceReference()));
	response.render(OnLoadHeaderItem.forScript(getSortScript()));
}
 
Example #23
Source Project: onedev   Author: theonedev   File: CodePropertyViewer.java    License: MIT License 5 votes vote down vote up
@Override
public void renderHead(IHeaderResponse response) {
	super.renderHead(response);
	response.render(JavaScriptHeaderItem.forReference(new CodeSupportResourceReference()));
	
	String script = String.format("onedev.server.codeSupport.onViewerDomReady('%s', '%s');", 
			input.getMarkupId(), language);
	response.render(OnLoadHeaderItem.forScript(script));
}
 
Example #24
Source Project: onedev   Author: theonedev   File: MarkdownEditor.java    License: MIT License 5 votes vote down vote up
@Override
public void renderHead(IHeaderResponse response) {
	super.renderHead(response);
	response.render(JavaScriptHeaderItem.forReference(new MarkdownResourceReference()));
	
	String encodedAttachmentSupport;
	if (getAttachmentSupport() != null) {
		encodedAttachmentSupport = Base64.encodeBase64String(SerializationUtils.serialize(getAttachmentSupport()));
		encodedAttachmentSupport = StringUtils.deleteWhitespace(encodedAttachmentSupport);
		encodedAttachmentSupport = StringEscapeUtils.escapeEcmaScript(encodedAttachmentSupport);
		encodedAttachmentSupport = "'" + encodedAttachmentSupport + "'";
	} else {
		encodedAttachmentSupport = "undefined";
	}
	String callback = ajaxBehavior.getCallbackFunction(explicit("action"), explicit("param1"), explicit("param2"), 
			explicit("param3")).toString();
	
	String autosaveKey = getAutosaveKey();
	if (autosaveKey != null)
		autosaveKey = "'" + JavaScriptEscape.escapeJavaScript(autosaveKey) + "'";
	else
		autosaveKey = "undefined";
	
	String script = String.format("onedev.server.markdown.onDomReady('%s', %s, %d, %s, %d, %b, %b, '%s', %s);", 
			container.getMarkupId(), 
			callback, 
			ATWHO_LIMIT, 
			encodedAttachmentSupport, 
			getAttachmentSupport()!=null?getAttachmentSupport().getAttachmentMaxSize():0,
			getUserMentionSupport() != null,
			getReferenceSupport() != null, 
			JavaScriptEscape.escapeJavaScript(ProjectNameValidator.PATTERN.pattern()),
			autosaveKey);
	response.render(OnDomReadyHeaderItem.forScript(script));
	
	script = String.format("onedev.server.markdown.onWindowLoad('%s');", container.getMarkupId());
	response.render(OnLoadHeaderItem.forScript(script));
}
 
Example #25
Source Project: onedev   Author: theonedev   File: Select2MultiChoice.java    License: MIT License 5 votes vote down vote up
@Override
protected void renderInitializationScript(IHeaderResponse response) {
	response.render(JavaScriptHeaderItem.forReference(new DragSortResourceReference()));
	Collection<? extends T> choices = getModelObject();

	if (choices != null && !choices.isEmpty()) {

		JsonBuilder selection = new JsonBuilder();

		try {
			selection.array();
			for (T choice : choices) {
				selection.object();
				getProvider().toJson(choice, selection);
				selection.endObject();
			}
			selection.endArray();
		} catch (JSONException e) {
			throw new RuntimeException("Error converting model object to Json", e);
		}

		response.render(OnLoadHeaderItem.forScript(
				JQuery.execute("$('#%s').select2('data', %s);", getJquerySafeMarkupId(), selection.toJson())));
	} else {
		clearInput();
	}
	String script = String.format("onedev.server.select2DragSort.onWindowLoad('%s');", getMarkupId());
	response.render(OnLoadHeaderItem.forScript(script));
}
 
Example #26
Source Project: onedev   Author: theonedev   File: SourceEditPanel.java    License: MIT License 5 votes vote down vote up
@Override
public void renderHead(IHeaderResponse response) {
	super.renderHead(response);
	response.render(JavaScriptHeaderItem.forReference(new SourceEditResourceReference()));
	
	String autosaveKey = JavaScriptEscape.escapeJavaScript(context.getAutosaveKey());
	PlanarRange mark = SourceRendererProvider.getRange(context.getPosition());
	
	String script = String.format("onedev.server.sourceEdit.onWindowLoad('%s', %s, '%s');", 
			getEditor().getMarkupId(), mark != null? getJson(mark): "undefined", autosaveKey);
	response.render(OnLoadHeaderItem.forScript(script));		
}
 
Example #27
Source Project: webanno   Author: webanno   File: CurationPage.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * for the first time, open the <b>open document dialog</b>
 */
@Override
public void renderHead(IHeaderResponse response)
{
    super.renderHead(response);

    String jQueryString = "";
    if (firstLoad) {
        jQueryString += "jQuery('#showOpenDocumentModal').trigger('click');";
        firstLoad = false;
    }
    response.render(OnLoadHeaderItem.forScript(jQueryString));
}
 
Example #28
Source Project: webanno   Author: webanno   File: BratVisualizer.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void renderHead(IHeaderResponse aResponse)
{
    super.renderHead(aResponse);

    // CSS
    aResponse.render(CssHeaderItem.forReference(BratCssVisReference.get()));
    aResponse.render(CssHeaderItem.forReference(BratCssUiReference.get()));

    // Libraries
    aResponse.render(forReference(JQueryUILibrarySettings.get().getJavaScriptReference()));
    aResponse.render(JavaScriptHeaderItem.forReference(JQuerySvgResourceReference.get()));
    aResponse.render(JavaScriptHeaderItem.forReference(JQuerySvgDomResourceReference.get()));
    aResponse.render(JavaScriptHeaderItem.forReference(JQueryJsonResourceReference.get()));

    // BRAT helpers
    aResponse.render(
            JavaScriptHeaderItem.forReference(BratConfigurationResourceReference.get()));
    aResponse.render(JavaScriptHeaderItem.forReference(BratUtilResourceReference.get()));

    // BRAT modules
    aResponse.render(JavaScriptHeaderItem.forReference(BratDispatcherResourceReference.get()));
    aResponse.render(JavaScriptHeaderItem.forReference(BratAjaxResourceReference.get()));
    aResponse.render(JavaScriptHeaderItem.forReference(BratVisualizerResourceReference.get()));
    aResponse
            .render(JavaScriptHeaderItem.forReference(BratVisualizerUiResourceReference.get()));
    aResponse.render(JavaScriptHeaderItem.forReference(BratAnnotatorUiResourceReference.get()));

    // BRAT call to load the BRAT JSON from our collProvider and docProvider.
    String[] script = { "Util.embedByURL(", "  '" + vis.getMarkupId() + "',",
            "  '" + collProvider.getCallbackUrl() + "', ",
            "  '" + docProvider.getCallbackUrl() + "', ", "  null);", };

    // This doesn't work with head.js because the onLoad event is fired before all the
    // JavaScript references are loaded.
    aResponse.render(OnLoadHeaderItem.forScript("\n" + StringUtils.join(script, "\n")));
}
 
Example #29
Source Project: webanno   Author: webanno   File: AutoOpenDialogBehavior.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * for the first time, open the <b>open document dialog</b>
 */
@Override
public void renderHead(Component aComponent, IHeaderResponse aResponse)
{
    super.renderHead(aComponent, aResponse);

    aResponse.render(OnLoadHeaderItem.forScript(getCallbackScript()));
}
 
Example #30
Source Project: sakai   Author: sakaiproject   File: InfinitePagingDataTableHeadersToolbar.java    License: Educational Community License v2.0 5 votes vote down vote up
@Override
public void renderHead(IHeaderResponse response)
{
	super.renderHead(response);

	response.render(JavaScriptHeaderItem.forUrl(TOOLBAR_JS));
	long sortableCols = getTable().getColumns().stream().filter(IColumn::isSortable).count();
	String attachScript = String.format("RHTB.init('%s', %d);", getTable().getMarkupId(), sortableCols);
	response.render(OnLoadHeaderItem.forScript(attachScript));
}