forked from dudeami0/jQuery-ZeroClipboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.html
152 lines (149 loc) · 6.36 KB
/
test.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>ZeroClipboard for jQuery</title>
<link type="text/css" rel="stylesheet" href="http://yandex.st/highlightjs/5.16/styles/default.min.css" />
<style type="text/css">
div.contents {
width: 700px;
}
* {
font-family: Arial;
font-size: 14px;
}
div.example {
border: 2px #333 solid;
padding: 10px;
margin: 10px;
}
code, code * {
font-family: Courier New;
}
h1 {
font-size: 22px;
}
h2 {
font-size: 18px
}
input {
width: 300px;
border: 1px solid #000;
}
body {
padding: 0;
margin: 0;
position: absolute;
}
</style>
</head>
<body>
<script type="text/javascript" src="http://yandex.st/highlightjs/5.16/highlight.min.js"></script>
<script type="text/javascript">hljs.initHighlightingOnLoad();</script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js"></script>
<script type="text/javascript" src="scripts/zeroclipboard.jquery.js"></script>
<script type="text/javascript" src="scripts/example.js"></script>
<div style="padding: 10px;">
<div class="contents">
<h1>ZeroClipboard for jQuery</h1>
<div style="float: right; width: 300px;">
<p>Now, this test is for the window resize event. Just resize the window, and if it stays on the div below, the resize works fine :)</p>
<div id="resizetest" class="example">Copy something :D</div>
</div>
<p>Hello! My name is Kris, I created (Or, modified) this script to allow ZeroClipboard to mingle with jQuery a bit better.
The main goal of this project was to make a very simple clipboard feature, as the original didn't meet my needs. The problem
was that I had a site with multiple clipboards, needing to be managed and updated by the elements, and so this version
stores all the data in the elements, and uses a single flash object as to not bring the browser to a grinding halt.</p>
<p>This script has changed heavily since its first incarnation, and gives just about the same experience. Changes since
the last version:</p>
<ul>
<li>Uses one flash element being repositioned around the page. Decreases load times and stress when multiple elements are copyable.</li>
<li>Added the choice to choose which size method to use (Outer, inner, standard .width()/.height())</li>
<li>Removed a couple of dependencies, and removed the resize event. This was due to the fact that if you resize an inactive
element, it updates next time it is hovered over. Also if needed, the update can be called manually, which is a lot more
resource friendly :p</li>
<li>Added the events 'mouseleave', 'mouseenter', and 'complete' (Which is fired after a successful copy)</li>
<li>Just about rewrote the thing, lots of code changes.</li>
</ul>
<h2>Basic Functionality</h2>
<div id="tester" class="example">Click to Copy Clipboard (Im a DIV)</div>
<p>Paste here -> <input type="text" /></p>
<pre class="javascript"><code>
// Code for a basic clipboard.
$(element).zeroclipboard({
// The text you want to have copied, defaults to 'Copy me!'
text : '',
/*
* Decides if the hand should be shown (true), or the default pointer
* (false). Defaults to false
*/
hand : true,
/*
* Decides which width/height function to use. Can be 'outer', 'inner',
* or null (for .width() and .height()). With 'outer', it includes
* margins
*/
sizeMethod : 'outer'
});
</code></pre>
<p>And as another example, you update the clipboards the same way you make them. So the code above you create or update
the clipboard. Try clicking the div to update the clipboard above.</p>
<div class="example" style="cursor: pointer;" id="testerupdate">Update the Clipboard Above</div>
<p>Note after doing so, the flash object is resized once you mouseover it again.</p>
<h2>Destroying</h2>
<p>Below will be a basic example of the destroying of the clipboard.
<a href="#" onclick="return false;" id="destroyflasha">Click here to remove the flash clipboard below.</a></p>
<div class="example" id="destroyflash">Destroy this thing on me!</div>
<p>To do this, simply add call the zeroclipboard function like:</p>
<pre class="javascript"><code>
$('#destroyflash').zeroclipboard('destroy');
</code></pre>
<p>Now above we destroyed just the flash object, but when the element is removed using the $(ele).remove() method, we
come up with this:</p>
<div class="example" id="destroywhole">Destroy me!</div>
<p>And, <a href="#" id="destroywholea" onclick="return false;">Click me to destroy the element above me.</a></p>
<p>Notice the flash object is also removed with the element. (Really it just gets hidden, but you get the idea)</p>
<h2>Updating</h2>
<p>When you need to update the element manually, just do the following:</p>
<pre class="javascript"><code>
$('#myelement').zeroclipboard('update');
</code></pre>
<h2>Binding Events</h2>
<p>Finally, we come to the binding of events. The events supported are mouseOver, mouseEnter, mouseOut, mouseLeave, mouseDown,
mouseUp, and complete. Using events is also simple:</p>
<div id="testercss" class="example">Watch me change colors!</div>
<p>This is done with events. With this the CSS effects can be much more specific, and you can call other events at certain stages.
The this in the element refers to the element the flash object is paired to.</p>
<p>The following is an example in using the events, its just as you would with any event on the div.</p>
<pre class="javascript"><code>
$('#testercss').zeroclipboard({
'text': 'Copied from #testercss',
'hand': true
})
// Add a mouseover event, note mouseenter also works
.mouseover(function () {
$(this).css({'color': '#f00'}, 1000);
})
// Add a mouseout event, note mouseleave also works
.mouseout(function () {
$(this).css({'color': '#000'}, 1000);
})
// This is fired when the mouse is down
.mousedown(function () {
$(this).css('font-weight', 'bold');
})
// This is fired when the mouse is up
.mouseup(function () {
$(this).css('font-weight', 'normal');
})
// This is fired on a successful copy
.bind('complete', function () {
alert('Copied text!');
});
</code></pre>
</div>
</div>
</body>
</html>