NOTE: The new Flash Player 10 has restricted access to the clipboard. This means that pre 2.0 versions of ClipStation do not work with version 10 of the player. Release 2.0+ operates in compliance with the new security model.
ClipStation is a free lightweight solution for writing to your user’s clipboard from an HTML page. Using a single SWF that is embedded dynamically via JavaScript, you can pass an unlimited number of content clips onto the clipboard.
ClipStation is designed to be lightweight, flexible, and easy to implement. This is all it takes to get started:
<script type="text/javascript" src="clipstation.js"></script>
<script type="text/javascript" src="swfobject.js"></script>
<div id="clip1">This is a plain-text clip.</div>
<div id="clipTrigger_clip1"></div>This approach is very beneficial in situations where you have multiple clips. Essentially you only need to add a unique ID to each clip content container, and a div with a corresponding ID. The JavaScript and Flash take care of the rest.
While the implementation is simple, there are some powerful features to work with. For instance, you can choose whether or not to decode character entities in your content on a clip-by-clip basis. This allows you to keep complex markup like Flash embeds in pretty much any container you want, from a simple text input to a preformatted block, it's all up to you. Telling ClipStation to decode character entities in your clip is done with a rel="decode" in your trigger link, like so:
<div><input type="text" id="clip2" value="This clip has <a href="foo.html">markup</a>"></div>
<div id="clipTrigger_clip2" rel="decode">Copy to Clipboard</div>ClipStation also makes it easy for developers to customize their implementation. The JavaScript that initializes the triggers is easy to adapt to any element, so you're not limited to triggering from div tags. You also have access to the send-to-clipboard function from your own scripts.
There are two versions of the SWF that you can choose from, a 7.0KB version with full character set support, a clipboard icon, and embedded Helvetica glyphs, or a 2.3KB Lite version that supports XML 1.0 entities only (" & ' < >), contains no icon, and uses device fonts. The majority of the file weight is due to the size of the HTML character set encoding table which contains the full set of 252 character mappings. Chances are you don't need all of them - behold; ∂ ∇ ξ ♠ ♣ ♥ ♦. If you have an appliation that only needs a well defined subset of character entities, or if you want to customize the design, grab the source distribution and build your own lean mean SWF that supports a limited character set. Just comment out the character definitions you don't need. You can view the chart of supported entities here.
Code:
<div id="clip1">This is a plain-text clip.</div>
<div id="clipTrigger_clip1" class="clipTrigger">Copy to Clipboard</div>Code:
<input type="text" id="clip2" size="60" value="<object width="425"
height="344"><param name="movie"
value="http://www.youtube.com/v/sZjpWs1h7pU&hl=en&fs=1">
</param><param name="allowFullScreen" value="true">
</param><embed src="http://www.youtube.com/v/sZjpWs1h7pU&hl=en
&fs=1" type="application/x-shockwave-flash" allowfullscreen="true" width="425"
height="344"></embed></object>">
<div id="clipTrigger_clip2" rel="decode">Copy to Clipboard</div>Code:
<input type="text" id="clip2" size="60" value="<object width="425"
height="344"><param name="movie"
value="http://www.youtube.com/v/sZjpWs1h7pU&hl=en&fs=1">
</param><param name="allowFullScreen" value="true">
</param><embed src="http://www.youtube.com/v/sZjpWs1h7pU&hl=en
&fs=1" type="application/x-shockwave-flash" allowfullscreen="true" width="425"
height="344"></embed></object>">
<div id="clipTrigger_clip3" rel="decode">Copy to Clipboard</div>Note: Internet Explorer entity encodes the contents of a textarea, so you need to add rel="decode" to your trigger link.
Code:
<textarea id="clip4" rows="8" cols="60"><object width="425" height="344">
<param name="movie" value="http://www.youtube.com/v/sZjpWs1h7pU&hl=en&fs=1"></param>
<param name="allowFullScreen" value="true"></param>
<embed src="http://www.youtube.com/v/sZjpWs1h7pU&hl=en&fs=1" type="application/x-shockwave-flash" allowfullscreen="true" width="425" height="344"></embed></object>
</textarea>
<div id="clipTrigger_clip4" rel="decode">Copy to Clipboard</div><object width="425" height="344"> <param name="movie" value="http://tinyurl.com/6qlexf"></param> <param name="allowFullScreen" value="true"></param> <embed src="http://tinyurl.com/6qlexf" type="application/x-shockwave-flash" allowfullscreen="true" width="425" height="344"> </embed> </object>
Code:
<pre id="clip5">
<object width="425" height="344">
<param name="movie" value="http://tinyurl.com/6qlexf">
</param>
<param name="allowFullScreen" value="true"></param>
<embed src="http://tinyurl.com/6qlexf"
type="application/x-shockwave-flash"
allowfullscreen="true"
width="425"
height="344">
</embed>
</object>"
</pre>
<div id="clipTrigger_clip5" rel="decode">Copy to Clipboard</div>
class HTTPRequest
{
public function getParameter($param, $return=null)
{
if (isset($_POST[$param]))
{
$return = $_POST[$param];
}
else if (isset($_GET[$param]))
{
$return = $_GET[$param];
}
else if (isset($_FILES[$param]))
{
$return = $_FILES[$param];
}
return $return;
}
}Code:
<pre id="clip6">
class HTTPRequest
{
public function getParameter($param, $return=null)
{
if (isset($_POST[$param]))
{
$return = $_POST[$param];
}
else if (isset($_GET[$param]))
{
$return = $_GET[$param];
}
else if (isset($_FILES[$param]))
{
$return = $_FILES[$param];
}
return $return;
}
}
</pre>
<div id="clipTrigger_clip6">Copy to Clipboard</div>class HTTPRequest
{
public function getParameter($param, $return=null)
{
if (isset($_POST[$param]))
{
$return = $_POST[$param];
}
else if (isset($_GET[$param]))
{
$return = $_GET[$param];
}
else if (isset($_FILES[$param]))
{
$return = $_FILES[$param];
}
return $return;
}
}
Code:
See example above, set display:none on <pre>, add a styled display version.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code:
See first example, text input with entity encoded content. Rinse & repeat.
Changes from 1.0.3 » 2.0.0
Changes from 1.0.2 » 1.0.3
If you find ClipStation useful, please drop us a line and let us know.
This library is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose.