提交 2dd0398a 编写于 作者: K Kohsuke Kawaguchi

Added <l:copyButton> to copy text into clipboard.

上级 1b1aabf1
......@@ -55,6 +55,8 @@ Upcoming changes</a>
<!-- Record your changes in the trunk here. -->
<div id="trunk" style="display:none"><!--=TRUNK-BEGIN=-->
<ul class=image>
<li class=rfe>
Added a tag to copy text into clipboard for plugins
<li class=rfe>
Removed ASM dependency to avoid class incompatibility trobules.
</ul>
......
......@@ -42,7 +42,7 @@ THE SOFTWARE.
<properties>
<staplerFork>true</staplerFork>
<stapler.version>1.185</stapler.version>
<stapler.version>1.186</stapler.version>
</properties>
<dependencies>
......@@ -149,6 +149,11 @@ THE SOFTWARE.
<artifactId>windows-package-checker</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.kohsuke.stapler</groupId>
<artifactId>stapler-adjunct-zeroclipboard</artifactId>
<version>1.0.7-1</version>
</dependency>
<dependency>
<groupId>org.kohsuke.stapler</groupId>
<artifactId>stapler-adjunct-timeline</artifactId>
......
<!--
The MIT License
Copyright (c) 2004-2010, Sun Microsystems, Inc., Kohsuke Kawaguchi,
Daniel Dyer, Seiji Sogabe, Tom Huybrechts, Manufacture Francaise des Pneumatiques
Michelin, Romain Seguy, CloudBees, Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:i="jelly:fmt" xmlns:x="jelly:xml">
<st:documentation>
Creates a small button that lets the user copies a text into clipboard
<st:attribute name="tooltip">
Tooltip of the button. Currently this doesn't work as reliably as we'd like.
More ZeroClipboard hacking is likely necessary.
</st:attribute>
<st:attribute name="text" use="required">
Text to be copied into the clipboard.
</st:attribute>
<st:attribute name="message" use="required">
Confirmation message to be shown once the text is copied.
This is required as in some browsers, button doesn't properly provide feedback to user actions
due to the nature of the hack needed to make copy work.
</st:attribute>
<st:attribute name="container">
Specify the CSS selector (like ".foo") that points to the ancestor block element that has "positive:relative".
According to ZeroClipboard documentation, having such container would improve the accuracy of invisible flash
overlay.
</st:attribute>
</st:documentation>
<span class="copy-button" tooltip="${attrs.tooltip}" text="${attrs.text}" message="${attrs.message}" container="${attrs.container}">
<input type="button"/>
</span>
<st:adjunct includes="org.kohsuke.stapler.zeroclipboard, lib.layout.copyButton.copyButton"/>
</j:jelly>
\ No newline at end of file
.copy-button BUTTON {
background: url('clipboard.png') center center no-repeat;
width: 20px;
height: 20px;
}
// @include "org.kohsuke.stapler.zeroclipboard"
Behaviour.register({
"span.copy-button" : function(e) {
var btn = e.firstChild;
var id = "copy-button"+(iota++);
btn.id = id;
var clip = new ZeroClipboard.Client();
clip.setText(e.getAttribute("text"));
makeButton(btn);
clip.setHandCursor(true);
var container = e.getAttribute("container");
if (container) {
container = $(e).up(container);
container.style.position = "relative";
clip.glue(id,container);
} else {
clip.glue(id);
}
clip.addEventListener('onComplete',function() {
notificationBar.show(e.getAttribute("message"));
});
clip.addEventListener('onMouseOver',function() {
$(id).addClassName('yui-button-hover')
});
clip.addEventListener('onMouseOut',function() {
$(id).removeClassName('yui-button-hover')
});
clip.addEventListener('onMouseDown',function() {
$(id).addClassName('yui-button-active')
});
clip.addEventListener('onMouseUp',function() {
$(id).removeClassName('yui-button-active')
});
}
});
package jenkins.plugins.ui_samples;
import hudson.Extension;
import java.util.Arrays;
import java.util.List;
/**
* @author Kohsuke Kawaguchi
*/
@Extension
public class CopyButton extends UISample {
@Override
public String getDescription() {
return "A small button to copy text into a clipboard";
}
public List<SourceFile> getSourceFiles() {
// TODO: generate this from index
return Arrays.asList(
new SourceFile("index.groovy"));
}
@Extension
public static final class DescriptorImpl extends UISampleDescriptor {
}
}
package jenkins.plugins.ui_samples.CopyButton;
import lib.JenkinsTagLib
import lib.LayoutTagLib
def st=namespace("jelly:stapler")
t=namespace(JenkinsTagLib.class)
l=namespace(LayoutTagLib.class)
namespace("/lib/samples").sample(title:_("Copy Button")) {
raw(_("blurb"))
div(style:"margin:2em") {
text("Copy this text! ")
l.copyButton(message:"text copied",text:"here comes ABC",container:"DIV")
}
raw(_("aboutContainerElement"))
}
blurb=\
<tt>l.copyButton</tt> tag creates a small button that allows users to paste text into the clipboard. \
Browsers make it unbelievably hard to do this simple task, so that's why we use a tag to encapsulate it. \
The tag requires two mandatory attributes. One is <tt>text</tt>, which represents the text to be copied into the clipboard. \
The other is <tt>message</tt>, which represents a message to be displayed upon the successful copying into the clipboard.
aboutContainerElement=\
According to <a href="http://code.google.com/p/zeroclipboard/wiki/Instructions#Gluing">ZeroClipboard documentation</a>, \
which is what we use for the copying, it is desirable to have an outer block element that houses a button, to improve \
the accuracy of positioning a hidden flash movie. This can be specified as a CSS selector in the <tt>container</tt> attribute. \
Note that you do not need to set the <tt>position:relative</tt> manually, as this tag will automatically set it.
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册