8000 Replace SWF clippy with clipboardjs on repository page by flaix · Pull Request #1438 · gitblit-org/gitblit · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Replace SWF clippy with clipboardjs on repository page #1438

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion releases.moxie
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,20 @@ r34: {
date: ${project.buildDate}
note: ''
From 1.10.0 on Gitblit requires Java 8 as minimum Java version.

Should you have disabled the Flash-based copy-to-clipboard function because it wasn't working anymore
(web.allowFlashCopyToClipboard = false), you may want to rethink this and enable it again. The configuration
property has the same name, but the mechanism was exchanged. Flash is gone, and a modern JavaScript solution
is now used to copy text directly to the clipboard (via clipboard.js).
''
html: ~
text: ~
security: ~
fixes:
- Fix crash in Gitblit Authority when users were deleted from Gitblit but still had entries (certificates) in the Authority.
changes:
- Minimum Java required increased to Java 8
- Minimum Java required increased to Java 8.
- Replaced the Flash-based approach to copy text to the clipboard with a modern JavaScript solution. (issue-1241)
additions: ~
dependencyChanges:
- update to JavaMail 1.5.6 (pr-1217 by @paladox)
Expand All @@ -24,6 +30,7 @@ r34: {
- update to Apache commons-io 2.11.0
- update to Apache commons-compress 1.22
- update to libpam4j 1.11
- added clipboard.js, replacing clippy.swf
contributors:
- paladox
}
Expand Down
6 changes: 5 additions & 1 deletion src/main/distrib/data/defaults.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1076,7 +1076,11 @@ web.allowForking = true
# SINCE 1.2.0
web.shortCommitIdLength = 6

# Use Clippy (Flash solution) to provide a copy-to-clipboard button.
# Use a JavaScript browser API to provide a copy-to-clipboard button.
# The clipboard.js library is used to copy text directly to the browser's
# clipboard.
# (This used to be done with a Flash based solution, but has been replaced
# with a modern JavaScript approach, since Flash support is dying out.)
# If false, a button with a more primitive JavaScript-based prompt box will
# offer a 3-step (click, ctrl+c, enter) copy-to-clipboard alternative.
#
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/gitblit/wicket/pages/RepositoryPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,11 @@ public RepositoryPage(PageParameters params) {
add(searchForm);
searchForm.setTranslatedAttributes();

// load clipboard library to copy repository URL
addBottomScript("../../clipboard/clipboard.min.js");
// instantiate clipboard
addBottomScript("../../clipboard/gitblit-ctcbtn.js");

// set stateless page preference
setStatelessHint(true);
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/gitblit/wicket/pages/SummaryPage.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
<wicket:fragment wicket:id="ownersFragment">

</wicket:fragment>
</wicket:extend>

</wicket:extend>
</body>
</html>
20 changes: 7 additions & 13 deletions src/main/java/com/gitblit/wicket/pages/TicketPage.html
Original file line number Diff line number Diff line change
Expand Up @@ -586,20 +586,14 @@ <h4><i class="fa fa-minus-circle"></i> <span wicket:id="mergeTitle"></span></h4>
<img wicket:id="copyIcon" wicket:message="title:gb.copyToClipboard"></img>
</span>
</wicket:fragment>


<!-- flash-based button-press copy & paste -->
<wicket:fragment wicket:id="clippyPanel">
<object wicket:message="title:gb.copyToClipboard" style="vertical-align:middle;"
wicket:id="clippy"
width="14"
height="14"
bgcolor="#ffffff"
quality="high"
wmode="transparent"
scale="noscale"
allowScriptAccess="sameDomain"></object>
</wicket:fragment>

<!-- JavaScript automatic copy to clipboard -->
<wicket:fragment wicket:id="clippyPanel">
<span class="tooltipped tooltipped-n">
<img class="ctcbtn" wicket:id="copyIcon" wicket:message="title:gb.copyToClipboard" />
</span>
</wicket:fragment>

</wicket:extend>
</body>
Expand Down
11 changes: 5 additions & 6 deletions src/main/java/com/gitblit/wicket/pages/TicketPage.java
6D4E
Original file line numberDiff line number Diff line change
Expand Up @@ -102,7 +102,6 @@
import com.gitblit.wicket.panels.DiffStatPanel;
import com.gitblit.wicket.panels.IconAjaxLink;
import com.gitblit.wicket.panels.LinkPanel;
import com.gitblit.wicket.panels.ShockWaveComponent;
import com.gitblit.wicket.panels.SimpleAjaxLink;

/**
Expand Down Expand Up @@ -1644,12 +1643,12 @@ protected String getPageTitle(String repositoryName) {

protected Fragment createCopyFragment(String wicketId, String text) {
if (app().settings().getBoolean(Keys.web.allowFlashCopyToClipboard, true)) {
// clippy: flash-based copy & paste
// javascript: browser JS API based copy to clipboard
Fragment copyFragment = new Fragment(wicketId, "clippyPanel", this);
String baseUrl = WicketUtils.getGitblitURL(getRequest());
ShockWaveComponent clippy = new ShockWaveComponent("clippy", baseUrl + "/clippy.swf");
clippy.setValue("flashVars", "text=" + StringUtils.encodeURL(text));
copyFragment.add(clippy);
ContextImage img = WicketUtils.newImage("copyIcon", "clippy.png");
// Add the ID of the target element that holds the text to copy to clipboard
img.add(new SimpleAttributeModifier("data-clipboard-text", text));
copyFragment.add(img);
return copyFragment;
} else {
// javascript: manual copy & paste with modal browser prompt dialog
Expand Down
20 changes: 7 additions & 13 deletions src/main/java/com/gitblit/wicket/panels/RepositoryUrlPanel.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@

<wicket:fragment wicket:id="repositoryUrlFragment">
<div class="btn-toolbar" style="margin: 0px;">
<div class="btn-group repositoryUrlContainer">
<div class="btn-group repositoryUrlContainer tooltipped tooltipped-w">
<img style="vertical-align: middle;padding: 0px 0px 1px 3px;" wicket:id="accessRestrictionIcon"></img>
<span wicket:id="menu"></span>
<div class="repositoryUrl">
<span wicket:id="primaryUrl">[repository primary url]</span>
<span class="hidden-phone hidden-tablet" wicket:id="copyFunction"></span>
<span class="tooltipped tooltipped-n">
<span class="hidden-phone hidden-tablet" wicket:id="copyFunction"></span>
</span>
</div>
<span class="hidden-phone hidden-tablet repositoryUrlRightCap" wicket:id="primaryUrlPermission">[repository primary url permission]</span>
</div>
Expand All @@ -33,7 +35,7 @@

<wicket:fragment wicket:id="applicationMenusFragment">
<div class="btn-toolbar" style="margin: 4px 0px 0px 0px;">
<div class="btn-group" wicket:id="appMenus">
<div class="btn-group tooltipped tooltipped-w" wicket:id="appMenus">
<span wicket:id="appMenu"></span>
</div>
</div>
Expand Down Expand Up @@ -85,17 +87,9 @@
</span>
</wicket:fragment>

<!-- flash-based button-press copy & paste -->
<!-- JavaScript automatic copy to clipboard -->
<wicket:fragment wicket:id="clippyPanel">
<object wicket:message="title:gb.copyToClipboard" style="vertical-align:middle;"
wicket:id="clippy"
width="14"
height="14"
bgcolor="#ffffff"
quality="high"
wmode="transparent"
scale="noscale"
allowScriptAccess="sameDomain"></object>
<img class="ctcbtn" wicket:id="copyIcon" wicket:message="title:gb.copyToClipboard" />
</wicket:fragment>

<wicket:fragment wicket:id="workingCopyFragment">
Expand Down
30 changes: 17 additions & 13 deletions src/main/java/com/gitblit/wicket/panels/RepositoryUrlPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import org.apache.wicket.Component;
import org.apache.wicket.RequestCycle;
import org.apache.wicket.behavior.SimpleAttributeModifier;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.image.ContextImage;
import org.apache.wicket.markup.html.panel.Fragment;
Expand Down Expand Up @@ -140,8 +141,7 @@ public void populateItem(final Item<RepositoryUrl> item) {
RepositoryUrl repoUrl = item.getModelObject();
// repository url
Fragment fragment = new Fragment("repoUrl", "actionFragment", this);
Component content = new Label("content", repoUrl.url).setRenderBodyOnly(true);
WicketUtils.setCssClass(content, "commandMenuItem");
Component content = new Label("content", repoUrl.url).setOutputMarkupId(true);
fragment.add(content);
item.add(fragment);

Expand All @@ -150,7 +150,7 @@ public void populateItem(final Item<RepositoryUrl> item) {
String tooltip = getProtocolPermissionDescription(repository, repoUrl);
WicketUtils.setHtmlTooltip(permissionLabel, tooltip);
fragment.add(permissionLabel);
fragment.add(createCopyFragment(repoUrl.url));
fragment.add(createCopyFragment(repoUrl.url, content.getMarkupId()));
}
};

Expand Down Expand Up @@ -199,13 +199,15 @@ public void populateItem(final Item<RepositoryUrl> item) {
}
}

urlPanel.add(new Label("primaryUrl", primaryUrl.url).setRenderBodyOnly(true));
Label primaryUrlLabel = new Label("primaryUrl", primaryUrl.url);
primaryUrlLabel.setOutputMarkupId(true);
urlPanel.add(primaryUrlLabel);

Label permissionLabel = new Label("primaryUrlPermission", primaryUrl.hasPermission() ? primaryUrl.permission.toString() : externalPermission);
String tooltip = getProtocolPermissionDescription(repository, primaryUrl);
WicketUtils.setHtmlTooltip(permissionLabel, tooltip);
urlPanel.add(permissionLabel);
urlPanel.add(createCopyFragment(primaryUrl.url));
urlPanel.add(createCopyFragment(primaryUrl.url, primaryUrlLabel.getMarkupId()));

return urlPanel;
}
Expand Down Expand Up @@ -317,12 +319,13 @@ public void populateItem(final Item<RepositoryUrl> repoLinkItem) {
// command-line
String command = substitute(clientApp.command, repoUrl.url, baseURL, user.username, repository.name);
Label content = new Label("content", command);
content.setOutputMarkupId(true);
WicketUtils.setCssClass(content, "commandMenuItem");
fragment.add(content);
repoLinkItem.add(fragment);

// copy function for command
fragment.add(createCopyFragment(command));
fragment.add(createCopyFragment(command, content.getMarkupId()));
}
}};
appMenu.add(actionItems);
Expand All @@ -346,16 +349,17 @@ protected Label createPermissionBadge(String wicketId, RepositoryUrl repoUrl) {
return permissionLabel;
}

protected Fragment createCopyFragment(String text) {
protected Fragment createCopyFragment(String text, String target) {
if (app().settings().getBoolean(Keys.web.allowFlashCopyToClipboard, true)) {
// clippy: flash-based copy & paste
// javascript: browser JS API based copy to clipboard
Fragment copyFragment = new Fragment("copyFunction", "clippyPanel", this);
String baseUrl = WicketUtils.getGitblitURL(getRequest());
ShockWaveComponent clippy = new ShockWaveComponent("clippy", baseUrl + "/clippy.swf");
clippy.setValue("flashVars", "text=" + StringUtils.encodeURL(text));
copyFragment.add(clippy);
ContextImage img = WicketUtils.newImage("copyIcon", "clippy.png");
// Add the ID of the target element that holds the text to copy to clipboard
img.add(new SimpleAttributeModifier("data-clipboard-target", "#"+target));
copyFragment.add(img);
return copyFragment;
} else {
}
else {
// javascript: manual copy & paste with modal browser prompt dialog
Fragment copyFragment = new Fragment("copyFunction", "jsPanel", this);
ContextImage img = WicketUtils.newImage("copyIcon", "clippy.png");
Expand Down
7 changes: 7 additions & 0 deletions src/main/resources/clipboard/clipboard.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
0