25
25
26
26
import org .apache .wicket .Component ;
27
27
import org .apache .wicket .RequestCycle ;
28
+ import org .apache .wicket .behavior .SimpleAttributeModifier ;
28
29
import org .apache .wicket .markup .html .basic .Label ;
29
30
import org .apache .wicket .markup .html .image .ContextImage ;
30
31
import org .apache .wicket .markup .html .panel .Fragment ;
@@ -140,8 +141,7 @@ public void populateItem(final Item<RepositoryUrl> item) {
140
141
RepositoryUrl repoUrl = item .getModelObject ();
141
142
// repository url
142
143
Fragment fragment = new Fragment ("repoUrl" , "actionFragment" , this );
143
- Component content = new Label ("content" , repoUrl .url ).setRenderBodyOnly (true );
144
- WicketUtils .setCssClass (content , "commandMenuItem" );
144
+ Component content = new Label ("content" , repoUrl .url ).setOutputMarkupId (true );
145
145
fragment .add (content );
146
146
item .add (fragment );
147
147
@@ -150,7 +150,7 @@ public void populateItem(final Item<RepositoryUrl> item) {
150
150
String tooltip = getProtocolPermissionDescription (repository , repoUrl );
151
151
WicketUtils .setHtmlTooltip (permissionLabel , tooltip );
152
152
fragment .add (permissionLabel );
153
- fragment .add (createCopyFragment (repoUrl .url ));
153
+ fragment .add (createCopyFragment (repoUrl .url , content . getMarkupId () ));
154
154
}
155
155
};
156
156
@@ -199,13 +199,15 @@ public void populateItem(final Item<RepositoryUrl> item) {
199
199
}
200
200
}
201
201
202
- urlPanel .add (new Label ("primaryUrl" , primaryUrl .url ).setRenderBodyOnly (true ));
202
+ Label primaryUrlLabel = new Label ("primaryUrl" , primaryUrl .url );
203
+ primaryUrlLabel .setOutputMarkupId (true );
204
+ urlPanel .add (primaryUrlLabel );
203
205
204
206
Label permissionLabel = new Label ("primaryUrlPermission" , primaryUrl .hasPermission () ? primaryUrl .permission .toString () : externalPermission );
205
207
String tooltip = getProtocolPermissionDescription (repository , primaryUrl );
206
208
WicketUtils .setHtmlTooltip (permissionLabel , tooltip );
207
209
urlPanel .add (permissionLabel );
208
- urlPanel .add (createCopyFragment (primaryUrl .url ));
210
+ urlPanel .add (createCopyFragment (primaryUrl .url , primaryUrlLabel . getMarkupId () ));
209
211
210
212
return urlPanel ;
211
213
}
@@ -317,12 +319,13 @@ public void populateItem(final Item<RepositoryUrl> repoLinkItem) {
317
319
// command-line
318
320
String command = substitute (clientApp .command , repoUrl .url , baseURL , user .username , repository .name );
319
321
Label content = new Label ("content" , command );
322
+ content .setOutputMarkupId (true );
320
323
WicketUtils .setCssClass (content , "commandMenuItem" );
321
324
fragment .add (content );
322
325
repoLinkItem .add (fragment );
323
326
324
327
// copy function for command
325
- fragment .add (createCopyFragment (command ));
328
+ fragment .add (createCopyFragment (command , content . getMarkupId () ));
326
329
}
327
330
}};
328
331
appMenu .add (actionItems );
@@ -346,16 +349,17 @@ protected Label createPermissionBadge(String wicketId, RepositoryUrl repoUrl) {
346
349
return permissionLabel ;
347
350
}
348
351
349
- protected Fragment createCopyFragment (String text ) {
352
+ protected Fragment createCopyFragment (String text , String target ) {
350
353
if (app ().settings ().getBoolean (Keys .web .allowFlashCopyToClipboard , true )) {
351
- // clippy: flash- based copy & paste
354
+ // javascript: browser JS API based copy to clipboard
352
355
Fragment copyFragment = new Fragment ("copyFunction" , "clippyPanel" , this );
353
- String baseUrl = WicketUtils .getGitblitURL ( getRequest () );
354
- ShockWaveComponent clippy = new ShockWaveComponent ( "clippy" , baseUrl + "/clippy.swf" );
355
- clippy . setValue ( "flashVars " , "text=" + StringUtils . encodeURL ( text ));
356
- copyFragment .add (clippy );
356
+ ContextImage img = WicketUtils .newImage ( "copyIcon" , "clippy.png" );
357
+ // Add the ID of the target element that holds the text to copy to clipboard
358
+ img . add ( new SimpleAttributeModifier ( "data-clipboard-target " , "#" + target ));
359
+ copyFragment .add (img );
357
360
return copyFragment ;
358
- } else {
361
+ }
362
+ else {
359
363
// javascript: manual copy & paste with modal browser prompt dialog
360
364
Fragment copyFragment = new Fragment ("copyFunction" , "jsPanel" , this );
361
365
ContextImage img = WicketUtils .newImage ("copyIcon" , "clippy.png" );
0 commit comments