From a502d96a860456ec5e8c96761db70f7cabb74751 Mon Sep 17 00:00:00 2001 From: Paul Martin <paul@paulsputer.com> Date: Sat, 30 Apr 2016 04:19:14 -0400 Subject: [PATCH] Merge pull request #1073 from gitblit/1062-DocEditorUpdates --- src/main/java/com/gitblit/wicket/pages/BasePage.java | 40 +++++++++++++++++++++++++++++++++++++++- 1 files changed, 39 insertions(+), 1 deletions(-) diff --git a/src/main/java/com/gitblit/wicket/pages/BasePage.java b/src/main/java/com/gitblit/wicket/pages/BasePage.java index b696700..0d99f5e 100644 --- a/src/main/java/com/gitblit/wicket/pages/BasePage.java +++ b/src/main/java/com/gitblit/wicket/pages/BasePage.java @@ -42,6 +42,8 @@ import org.apache.wicket.markup.html.basic.Label; import org.apache.wicket.markup.html.link.ExternalLink; import org.apache.wicket.markup.html.panel.FeedbackPanel; +import org.apache.wicket.markup.html.resources.JavascriptResourceReference; +import org.apache.wicket.markup.repeater.RepeatingView; import org.apache.wicket.protocol.http.RequestUtils; import org.apache.wicket.protocol.http.WebResponse; import org.apache.wicket.protocol.http.servlet.ServletWebRequest; @@ -242,7 +244,7 @@ protected void setupPage(String repositoryName, String pageName) { add(new Label("title", getPageTitle(repositoryName))); - + getBottomScriptContainer(); String rootLinkUrl = app().settings().getString(Keys.web.rootLink, urlFor(GitBlitWebApp.get().getHomePage(), null).toString()); ExternalLink rootLink = new ExternalLink("rootLink", rootLinkUrl); WicketUtils.setHtmlTooltip(rootLink, app().settings().getString(Keys.web.siteName, Constants.NAME)); @@ -506,4 +508,40 @@ return sb.toString(); } + private RepeatingView getBottomScriptContainer() { + RepeatingView bottomScriptContainer = (RepeatingView) get("bottomScripts"); + if (bottomScriptContainer == null) { + bottomScriptContainer = new RepeatingView("bottomScripts"); + bottomScriptContainer.setRenderBodyOnly(true); + add(bottomScriptContainer); + } + return bottomScriptContainer; + } + + /** + * Adds a HTML script element loading the javascript designated by the given path. + * + * @param scriptPath + * page-relative path to the Javascript resource; normally starts with "scripts/" + */ + protected void addBottomScript(String scriptPath) { + RepeatingView bottomScripts = getBottomScriptContainer(); + Label script = new Label(bottomScripts.newChildId(), "<script type='text/javascript' src='" + + urlFor(new JavascriptResourceReference(this.getClass(), scriptPath)) + "'></script>\n"); + bottomScripts.add(script.setEscapeModelStrings(false).setRenderBodyOnly(true)); + } + + /** + * Adds a HTML script element containing the given code. + * + * @param code + * inline script code + */ + protected void addBottomScriptInline(String code) { + RepeatingView bottomScripts = getBottomScriptContainer(); + Label script = new Label(bottomScripts.newChildId(), + "<script type='text/javascript'>/*<![CDATA[*/\n" + code + "\n//]]>\n</script>\n"); + bottomScripts.add(script.setEscapeModelStrings(false).setRenderBodyOnly(true)); + } + } -- Gitblit v1.9.1