init repo

This commit is contained in:
nikolay ivanov
2014-07-05 18:22:49 +00:00
commit a8be6b9e72
17348 changed files with 9229832 additions and 0 deletions

View File

@@ -0,0 +1,8 @@
The MIT License (MIT)
Copyright (c) 2012 Joseph Huckaby, Jon Rohan
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.

View File

@@ -0,0 +1,22 @@
NODE_PATH ?= ./node_modules
JS_COMPILER = $(NODE_PATH)/uglify-js/bin/uglifyjs
JS_BEAUTIFIER = $(NODE_PATH)/uglify-js/bin/uglifyjs -b -i 2 -nm -ns
all: \
ZeroClipboard.min.js
ZeroClipboard.min.js: Makefile
@rm -f $@
$(JS_COMPILER) ./src/javascript/ZeroClipboard.js > $@
testpage:
git stash
git checkout gh-pages
git checkout master ZeroClipboard.min.js ZeroClipboard.swf
rm -f javascript/ZeroClipboard*
mv ZeroClipboard.* javascripts/
git add .
git commit -a -m "Update demo files to latest changes."
git push
git checkout master
git stash pop

View File

@@ -0,0 +1,20 @@
Zero Clipboard
==============
The Zero Clipboard library provides an easy way to copy text to the clipboard using an invisible [Adobe Flash](http://en.wikipedia.org/wiki/Adobe_Flash) movie, and a [JavaScript](http://en.wikipedia.org/wiki/JavaScript) interface. The "Zero" signifies that the library is invisible and the user interface is left entirely up to you.
This library is fully compatible with Flash Player 10, which requires that the clipboard copy operation be initiated by a user click event inside the Flash movie. This is achieved by automatically floating the invisible movie on top of a [DOM](http://en.wikipedia.org/wiki/Document_Object_Model) element of your choice. Standard mouse events are even propagated out to your DOM element, so you can still have rollover and mouse down effects.
See the [Instructions](https://github.com/jonrohan/ZeroClipboard/blob/master/docs/instructions.md) for instructions on how to use the library on your site.
Here is a working [Test Page](http://jonrohan.github.com/ZeroClipboard/#demo) where you can try out ZeroClipboard in your browser.
### Zero Clipboard Does Not Work From Local Disk
This is a security restriction by Adobe Flash Player. Unfortunately, since we are utilizing the `JavaScript-to-Flash` interface ("`ExternalInterface`") this only works while truly online (if the page URL starts with "http://" or "https://"). It won't work running from a local file on disk.
However, there is a way for you to edit your local Flash Player security settings and allow this. Go to this website:
http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04a.html
And add the path to your local "ZeroClipboard.swf" file to the trusted files list, or try the "allow all" option.

File diff suppressed because one or more lines are too long

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,387 @@
# Overview
The *Zero Clipboard* [JavaScript](http://en.wikipedia.org/wiki/JavaScript) library provides an easy way to copy text to the clipboard using an invisible [Adobe Flash](http://en.wikipedia.org/wiki/Adobe_Flash) movie. The "Zero" signifies that the library is invisible and the user interface is left entirely up to you.
This library is fully compatible with Flash Player 10, which requires that the copy operation initiated by a user click event inside the Flash movie. This is achieved by automatically floating the invisible movie on top of a [DOM](http://en.wikipedia.org/wiki/Document_Object_Model) element of your choice. Standard mouse events are even propagated out to your DOM element, so you can still have rollover and mouse down effects.
Flash Player 9 is also supported. Please note that if you use the new *Rich HTML* feature, your users must have Flash Player 10. There is no automatic fallback to the Flash 9 movie.
## Usage
The following subsections describe how to use the clipboard library.
### Setup
To use the library, simply include the following JavaScript file in your page:
```
<script type="text/javascript" src="ZeroClipboard.js"></script>
```
You also need to have the "`"ZeroClipboard.swf`" file available to the browser. If this file is located in the same directory as your web page, then it will work out of the box. However, if the SWF file is hosted elsewhere, you need to set the URL like this (place this code _after_ the script tag):
```
ZeroClipboard.setMoviePath( 'http://YOURSERVER/path/ZeroClipboard.swf' );
```
To use the new *Rich HTML* feature available in Zero Clipboard 1.0.7, you must set the movie path to the new "`ZeroClipboard10.swf`" file, which is included in the 1.0.7 archive. Example:
```
ZeroClipboard.setMoviePath( 'ZeroClipboard10.swf' );
```
Or, in a custom location other than the current directory:
```
ZeroClipboard.setMoviePath( 'http://YOURSERVER/path/ZeroClipboard10.swf' );
```
### Clients
Now you are ready to create one or more *Clients*. A client is a single instance of the clipboard library on the page, linked to a particular button or other DOM element. You probably only need a single instance, but if you have multiple copy-to-clipboard buttons on your page, potentially containing different text, you can activate an instance for each. Here is how to create a client instance:
```
var clip = new ZeroClipboard.Client();
```
Next, you can set some options.
### Setting Options
Once you have your client instance, you can set some options. These include setting the initial text to be copied, amongst other things. The following subsections describe all the available options you can set.
#### Text To Copy
This function allows you to set the text to be copied to the clipboard, once the user clicks on the control. You can call this function at any time; when the page first loads, or later in an `onMouseOver` or `onMouseDown` handler. Example:
```
clip.setText( "Copy me!" );
```
#### Hand Cursor
This setting controls whether the "hand" or "arrow" cursor is shown when the mouse hovers over the Flash movie. Here is an example:
```
clip.setHandCursor( true );
```
The only values accepted are *true* (show "hand" cursor), or *false* (show "arrow" cursor). The default is *true*. You can set this option at any time.
### Gluing
Gluing refers to the process of "linking" the Flash movie to a DOM element on the page. Meaning, the library will automatically generate a movie that is the exact size of the DOM element, and float it just above the element. Since the Flash movie is completely transparent, the user sees nothing out of the ordinary.
The Flash movie receives the click event and copies the current text (last set with `setText()`) to the clipboard (a requirement of Flash Player 10 is that a user click event inside the movie must initiate the thread that interacts with the clipboard). Also, mouse actions like hovering and mouse-down generate events that you can capture (see *Event Handlers* below) and set [http://en.wikipedia.org/wiki/Cascading_Style_Sheets CSS] classes on your DOM element too (see *CSS Effects* below).
Here is how to glue your clip library instance to a DOM element:
```
clip.glue( 'd_clip_button' );
```
You can pass in a DOM element ID (as shown above), or a reference to the actual DOM element object itself. The rest all happens automatically -- the movie is created, all your options set, and it is floated above the element, awaiting clicks from the user.
The glue system is an optional implementation. If you would prefer to handle your own implementation of the Flash movie, see *Custom Implementation* below.
#### Recommended Implementation
It is highly recommended you create a "container" DIV element around your button, set its CSS "position" to "relative", and place your button just inside. Then, pass *two* arguments to `glue()`, your button DOM element or ID, and the container DOM element or ID. This way Zero Clipboard can position the floating Flash movie relative to the container DIV (not the page body), resulting in much more exact positioning. Example (HTML):
```
<div id="d_clip_container" style="position:relative">
<div id="d_clip_button">Copy to Clipboard</div>
</div>
```
And the code:
```
clip.glue( 'd_clip_button', 'd_clip_container' );
```
Note that gluing to a container element does not work with the `reposition()` method (see next section).
### Page Resizing
If the page gets resized, or something happens which moves your DOM element, you will need to reposition the movie. This can be achieved by calling the `reposition()` method. Example:
```
clip.reposition();
```
A typical use of this is to put it inside a `window.onresize` handler.
If for some reason your DOM element was destroyed and recreated, you can pass the new ID or DOM element reference to the `reposition()` method. However please note that the new element *must* be the same size as the previous element. The library does not (yet) support elements that change size.
Note that repositioning only works if you glue using a single argument. If you glue to a parent container element, you cannot (and probably won't ever need to) call `reposition()`.
### Hiding and Showing
You can also show and hide the Flash movie on demand, if you have an AJAX web app that dynamically changes content, potentially obscuring the clipboard button. Examples:
```
clip.hide();
clip.show();
```
The `show()` function also calls `reposition()`.
#### CSS Effects
Since the Flash movie is floating on top of your DOM element, it will receive all the mouse events before the browser has a chance to catch them. However, for convenience these events are passed through to your clipboard client which you can capture (see *Event Handlers* below). But in addition to this, the Flash movie can also activate CSS classes on your DOM element to simulate the ":hover" and ":active" pseudo-classes.
If this feature is enabled, the CSS classes "hover" and "active" are added / removed to your DOM element as the mouse hovers over and clicks the Flash movie. This essentially allows your button to behave normally, even though the floating Flash movie is receiving all the mouse events. Please note that the actual CSS pseudo-classes ":hover" and ":active" are not used -- these cannot be programmatically activated with current browser software. Instead, sub-classes named "hover" and "active" are used. Example CSS:
```
#d_clip_button {
width:150px;
text-align:center;
border:1px solid black;
background-color:#ccc;
margin:10px; padding:10px;
}
#d_clip_button.hover { background-color:#eee; }
#d_clip_button.active { background-color:#aaa; }
```
These classes are for a DOM element with an ID: "d_clip_button". The "hover" and "active" sub-classes would automatically be activated as the user hovers over, and clicks down on the Flash movie, respectively. They behave exactly like CSS pseudo-classes of the same names.
The CSS Effect system is enabled by default. To disable it, pass *false* to the `setCSSEffects()` method. Example:
```
clip.setCSSEffects( false );
```
You can set this option at any time.
### Custom Implementation
If you would prefer to instantiate the Flash movie yourself, and completely disable the entire glue and CSS systems, you can simply call the `getHTML()` method, which returns the actual OBJECT/EMBED tag for the Flash movie. Example:
```
var html = clip.getHTML( 150, 20 );
```
The method requires that you pass in the desired pixel width and height of the movie. The returned HTML can then be inserted into a DOM element of your choice, or written to the page with `document.write()`.
*Note:* Microsoft Internet Explorer seems to have a bug where the Flash External Interface (the communication layer between JavaScript and Flash) doesn't activate properly unless you insert the OBJECT tag into an element that is _already appended to the DOM_. So make sure you call `appendChild()` before you insert the HTML into the `innerHTML` property of your element.
### Event Handlers
The clipboard library allows you set a number of different event handlers. These are all set by calling the `addEventListener()` method, as in this example:
```
clip.addEventListener( 'onLoad', my_load_handler );
```
The first argument is the name of the event, and the second is a reference to your function. The function may be passed by name (string), an actual reference to the function object, or a PHP-style object/method array:
```
clip.addEventListener( 'onMouseDown', [myObject, 'myMethod'] );
```
This allows you to get back into object context by calling a specific method on a specific object, as seen in PHP. However, I suppose you could just use the JavaScript `bind()` function to achieve the same effect.
The event names are not case sensitive, and the prefix "on" is optional. For example, the values "onLoad", "onload" and "load" all mean the same thing.
Your custom function will be passed at least one argument -- a reference to the clipboard client object. However, certain events pass additional arguments, which are described in each section below. The following subsections describe all the available events you can hook.
#### onLoad
The `onLoad` event is fired when the Flash movie completes loading and is ready for action. Please note that you don't need to listen for this event to set options -- those are automatically passed to the movie if you call them before it loads. Example use:
```
clip.addEventListener( 'onLoad', my_load_handler );
function my_load_handler( client ) {
alert( "movie has loaded" );
}
```
The handler is passed a reference to the clipboard client object.
#### onMouseOver
The `onMouseOver` event is fired when the user's mouse pointer enters the Flash movie. You can use this to simulate a rollover effect on your DOM element, however see *CSS Effects* for an easier way to do this. Example use:
```
clip.addEventListener( 'onMouseOver', my_mouse_over_handler );
function my_mouse_over_handler( client ) {
alert( "mouse is over movie" );
}
```
The handler is passed a reference to the clipboard client object.
#### onMouseOut
The `onMouseOut` event is fired when the user's mouse pointer leaves the Flash movie. You can use this to simulate a rollover effect on your DOM element, however see *CSS Effects* for an easier way to do this. Example use:
```
clip.addEventListener( 'onMouseOut', my_mouse_out_handler );
function my_mouse_out_handler(client) {
alert( "mouse has left movie" );
}
```
The handler is passed a reference to the clipboard client object.
#### onMouseDown
The `onMouseDown` event is fired when the user clicks on the Flash movie. Please note that this does not guarantee that the user will release the mouse button while still over the movie (i.e. resulting in a click). You can use this to simulate a click effect on your DOM element, however see *CSS Effects* for an easier way to do this. Example use:
```
clip.addEventListener( 'onMouseDown', my_mouse_down_handler );
function my_mouse_down_handler(client) {
alert( "mouse button is down" );
}
```
The handler is passed a reference to the clipboard client object.
#### onMouseUp
The `onMouseUp` event is fired when the user releases the mouse button (having first pressed the mouse button while hovering over the movie). Please note that this does not guarantee that the mouse cursor is still over the movie (i.e. resulting in a click). You can use this to simulate a click effect on your DOM element, however see *CSS Effects* for an easier way to do this. Example use:
```
clip.addEventListener( 'onMouseUp', my_mouse_up_handler );
function my_mouse_up_handler( client ) {
alert( "mouse button is up" );
}
```
The handler is passed a reference to the clipboard client object.
#### onComplete
The `onComplete` event is fired when the text is successfully copied to the clipboard. Example use:
```
clip.addEventListener( 'onComplete', my_complete );
function my_complete( client, text ) {
alert("Copied text to clipboard: " + text );
}
```
The handler is passed two arguments: a reference to the clipboard client object, and the text that was copied.
#### Destroying
You may want to completely destroy the clipboard client movie, for example after a successful copy-to-clipboard. This means that the user cannot click to copy additional text. To do this, simply call the `destroy()` method, as in this example:
```
clip.destroy();
```
This will remove the Flash movie from the DOM, and completely reset the client clipboard object. If you want to reinitialize the object with another container, simply call `glue()` again (see *Gluing* above), or `getHTML()`.
*Note:* For safety reasons, you may not want to call this method directly in your `onComplete` handler function. The reason is that the JavaScript thread originated from within the Flash movie, which you are attempting to destroy with the `destroy()` call. This can cause crashes in certain browsers (namely IE). Better to set a timer with `setTimeout()` and call destroy in its own, safe thread.
## Examples
The following are complete, working examples of using the clipboard client library in HTML pages.
### Minimal Example
Here is a quick example using as few calls as possible:
```
<html>
<body>
<script type="text/javascript" src="ZeroClipboard.js"></script>
<div id="d_clip_button" style="border:1px solid black; padding:20px;">Copy To Clipboard</div>
<script language="JavaScript">
var clip = new ZeroClipboard.Client();
clip.setText( 'Copy me!' );
clip.glue( 'd_clip_button' );
</script>
</body>
</html>
```
When clicked, the text "Copy me!" will be copied to the clipboard.
### Complete Example
Here is a complete example which exercises every option and event handler:
```
<html>
<head>
<style type="text/css">
#d_clip_button {
text-align:center;
border:1px solid black;
background-color:#ccc;
margin:10px; padding:10px;
}
#d_clip_button.hover { background-color:#eee; }
#d_clip_button.active { background-color:#aaa; }
</style>
</head>
<body>
<script type="text/javascript" src="ZeroClipboard.js"></script>
Copy to Clipboard: <input type="text" id="clip_text" size="40" value="Copy me!"/><br/><br/>
<div id="d_clip_button">Copy To Clipboard</div>
<script language="JavaScript">
var clip = new ZeroClipboard.Client();
clip.setText( '' ); // will be set later on mouseDown
clip.setHandCursor( true );
clip.setCSSEffects( true );
clip.addEventListener( 'onLoad', function(client) {
// alert( "movie is loaded" );
} );
clip.addEventListener( 'onComplete', function(client, text) {
alert("Copied text to clipboard: " + text );
} );
clip.addEventListener( 'onMouseOver', function(client) {
// alert("mouse over");
} );
clip.addEventListener( 'onMouseOut', function(client) {
// alert("mouse out");
} );
clip.addEventListener( 'onMouseDown', function(client) {
// set text to copy here
clip.setText( document.getElementById('clip_text').value );
// alert("mouse down");
} );
clip.addEventListener( 'onMouseUp', function(client) {
// alert("mouse up");
} );
clip.glue( 'd_clip_button' );
</script>
</body>
</html>
```
## Browser Support
The Zero Clipboard Library has been tested on the following browsers / platforms:
|| *Browser* || *Windows XP SP3* || *Windows Vista* || *Mac OS X Leopard* ||
|| Internet Exploder || 7.0 || 7.0 || - ||
|| Firefox || 3.0 || 3.0 || 3.0 ||
|| Safari || - || - || 3.0 ||
|| Google Chrome || 1.0 || 1.0 || - ||
Adobe Flash Flash Player versions 9 and 10 are supported.

View File

@@ -0,0 +1,10 @@
### Zero Clipboard 1.0.7 Released
Zero Clipboard 1.0.7 can now copy **Rich HTML** to the clipboard. When this is pasted into an application that supports rich text, it will show up as fully rendered HTML (not the source that was copied). Since this feature only works in Flash Player 10, it is opt-in, and must be specifically enabled in your code. See the updated [Instructions](https://github.com/jonrohan/ZeroClipboard/blob/master/docs/instructions.md) for details. Thanks to jpp at cloudview for the patch!
### Zero Clipboard 1.0.5 Released
Zero Clipboard 1.0.5 can now glue the Flash movie to a relatively positioned parent element (instead of the page body), resulting in perfect positioning of the movie on top of your copy button. This also allows you to use Zero Clipboard inside overflow:auto or position:fixed elements.
The [Instructions](https://github.com/jonrohan/ZeroClipboard/blob/master/docs/instructions.md) have been updated with details on how to use the new feature. The API is 100% backward compatible with previous versions.

View File

@@ -0,0 +1,23 @@
{
"name": "zeroclipboard",
"version": "1.0.8",
"description": "The Zero Clipboard library provides an easy way to copy text to the clipboard using an invisible Adobe Flash movie, and a JavaScript interface.",
"keywords": [
"flash",
"clipboard",
"copy",
"paste"
],
"homepage": "http://jonrohan.github.com/ZeroClipboard/",
"author": {
"name": "Jon Rohan",
"url": "http://jonrohan.me/"
},
"repository": {
"type": "git",
"url": "https://github.com/jonrohan/ZeroClipboard.git"
},
"devDependencies": {
"uglify-js": "1.2.3"
}
}

View File

@@ -0,0 +1,81 @@
package {
// Simple Set Clipboard System
// Author: Joseph Huckaby
import flash.display.Stage;
import flash.display.Sprite;
import flash.display.LoaderInfo;
import flash.display.StageScaleMode;
import flash.events.*;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.external.ExternalInterface;
import flash.system.Security;
import flash.utils.*;
import flash.system.System;
public class ZeroClipboard extends Sprite {
private var id:String = '';
private var button:Sprite;
private var clipText:String = '';
public function ZeroClipboard() {
// constructor, setup event listeners and external interfaces
stage.scaleMode = StageScaleMode.EXACT_FIT;
flash.system.Security.allowDomain("*");
// import flashvars
var flashvars:Object = LoaderInfo( this.root.loaderInfo ).parameters;
id = flashvars.id;
id = id.split("\\").join("\\\\");
// invisible button covers entire stage
button = new Sprite();
button.buttonMode = true;
button.useHandCursor = true;
button.graphics.beginFill(0xCCFF00);
button.graphics.drawRect(0, 0, Math.floor(flashvars.width), Math.floor(flashvars.height));
button.alpha = 0.0;
addChild(button);
button.addEventListener(MouseEvent.CLICK, clickHandler);
button.addEventListener(MouseEvent.MOUSE_OVER, function(event:Event) {
ExternalInterface.call( 'ZeroClipboard.dispatch', id, 'mouseOver', null );
} );
button.addEventListener(MouseEvent.MOUSE_OUT, function(event:Event) {
ExternalInterface.call( 'ZeroClipboard.dispatch', id, 'mouseOut', null );
} );
button.addEventListener(MouseEvent.MOUSE_DOWN, function(event:Event) {
ExternalInterface.call( 'ZeroClipboard.dispatch', id, 'mouseDown', null );
} );
button.addEventListener(MouseEvent.MOUSE_UP, function(event:Event) {
ExternalInterface.call( 'ZeroClipboard.dispatch', id, 'mouseUp', null );
} );
// external functions
ExternalInterface.addCallback("setHandCursor", setHandCursor);
ExternalInterface.addCallback("setText", setText);
// signal to the browser that we are ready
ExternalInterface.call( 'ZeroClipboard.dispatch', id, 'load', null );
}
public function setText(newText) {
// set the maximum number of files allowed
clipText = newText;
}
public function setHandCursor(enabled:Boolean) {
// control whether the hand cursor is shown on rollover (true)
// or the default arrow cursor (false)
button.useHandCursor = enabled;
}
private function clickHandler(event:Event):void {
// user click copies text to clipboard
// as of flash player 10, this MUST happen from an in-movie flash click event
System.setClipboard( clipText );
ExternalInterface.call( 'ZeroClipboard.dispatch', id, 'complete', clipText );
}
}
}

Binary file not shown.

View File

@@ -0,0 +1 @@
package {

Binary file not shown.

View File

@@ -0,0 +1,321 @@
// Simple Set Clipboard System
// Author: Joseph Huckaby
var ZeroClipboard = {
version: "1.0.8",
clients: {}, // registered upload clients on page, indexed by id
moviePath: 'ZeroClipboard.swf', // URL to movie
nextId: 1, // ID of next movie
$: function(thingy) {
// simple DOM lookup utility function
if (typeof(thingy) == 'string') thingy = document.getElementById(thingy);
if (!thingy.addClass) {
// extend element with a few useful methods
thingy.hide = function() { this.style.display = 'none'; };
thingy.show = function() { this.style.display = ''; };
thingy.addClass = function(name) { this.removeClass(name); this.className += ' ' + name; };
thingy.removeClass = function(name) {
var classes = this.className.split(/\s+/);
var idx = -1;
for (var k = 0; k < classes.length; k++) {
if (classes[k] == name) { idx = k; k = classes.length; }
}
if (idx > -1) {
classes.splice( idx, 1 );
this.className = classes.join(' ');
}
return this;
};
thingy.hasClass = function(name) {
return !!this.className.match( new RegExp("\\s*" + name + "\\s*") );
};
}
return thingy;
},
setMoviePath: function(path) {
// set path to ZeroClipboard.swf
this.moviePath = path;
},
// use this method in JSNI calls to obtain a new Client instance
newClient: function() {
return new ZeroClipboard.Client();
},
dispatch: function(id, eventName, args) {
// receive event from flash movie, send to client
var client = this.clients[id];
if (client) {
client.receiveEvent(eventName, args);
}
},
register: function(id, client) {
// register new client to receive events
this.clients[id] = client;
},
getDOMObjectPosition: function(obj, stopObj) {
// get absolute coordinates for dom element
var info = {
left: 0,
top: 0,
width: obj.width ? obj.width : obj.offsetWidth,
height: obj.height ? obj.height : obj.offsetHeight
};
while (obj && (obj != stopObj)) {
info.left += obj.offsetLeft;
info.top += obj.offsetTop;
obj = obj.offsetParent;
}
return info;
},
Client: function(elem) {
// constructor for new simple upload client
this.handlers = {};
// unique ID
this.id = ZeroClipboard.nextId++;
this.movieId = 'ZeroClipboardMovie_' + this.id;
// register client with singleton to receive flash events
ZeroClipboard.register(this.id, this);
// create movie
if (elem) this.glue(elem);
}
};
ZeroClipboard.Client.prototype = {
id: 0, // unique ID for us
ready: false, // whether movie is ready to receive events or not
movie: null, // reference to movie object
clipText: '', // text to copy to clipboard
handCursorEnabled: true, // whether to show hand cursor, or default pointer cursor
cssEffects: true, // enable CSS mouse effects on dom container
handlers: null, // user event handlers
zIndex: 99, // default zIndex of the movie object
glue: function(elem, appendElem, stylesToAdd) {
// glue to DOM element
// elem can be ID or actual DOM element object
this.domElement = ZeroClipboard.$(elem);
// float just above object, or default zIndex if dom element isn't set
if (this.domElement.style.zIndex) {
this.zIndex = parseInt(this.domElement.style.zIndex, 10) + 1;
}
if (typeof(appendElem) == 'string') {
appendElem = ZeroClipboard.$(appendElem);
}
else if (typeof(appendElem) == 'undefined') {
appendElem = document.getElementsByTagName('body')[0];
}
// find X/Y position of domElement
var box = ZeroClipboard.getDOMObjectPosition(this.domElement, appendElem);
// create floating DIV above element
this.div = document.createElement('div');
var style = this.div.style;
style.position = 'absolute';
style.left = '' + box.left + 'px';
style.top = '' + box.top + 'px';
style.width = '' + box.width + 'px';
style.height = '' + box.height + 'px';
style.zIndex = this.zIndex;
if (typeof(stylesToAdd) == 'object') {
for (var addedStyle in stylesToAdd) {
style[addedStyle] = stylesToAdd[addedStyle];
}
}
// style.backgroundColor = '#f00'; // debug
appendElem.appendChild(this.div);
this.div.innerHTML = this.getHTML( box.width, box.height );
},
getHTML: function(width, height) {
// return HTML for movie
var html = '';
var flashvars = 'id=' + this.id +
'&width=' + width +
'&height=' + height;
if (navigator.userAgent.match(/MSIE/)) {
// IE gets an OBJECT tag
var protocol = location.href.match(/^https/i) ? 'https://' : 'http://';
html += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="'+protocol+'download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="'+width+'" height="'+height+'" id="'+this.movieId+'" align="middle"><param name="allowScriptAccess" value="always" /><param name="allowFullScreen" value="false" /><param name="movie" value="'+ZeroClipboard.moviePath+'" /><param name="loop" value="false" /><param name="menu" value="false" /><param name="quality" value="best" /><param name="bgcolor" value="#ffffff" /><param name="flashvars" value="'+flashvars+'"/><param name="wmode" value="transparent"/></object>';
}
else {
// all other browsers get an EMBED tag
html += '<embed id="'+this.movieId+'" src="'+ZeroClipboard.moviePath+'" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="'+width+'" height="'+height+'" name="'+this.movieId+'" align="middle" allowScriptAccess="always" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="'+flashvars+'" wmode="transparent" />';
}
return html;
},
hide: function() {
// temporarily hide floater offscreen
if (this.div) {
this.div.style.left = '-2000px';
}
},
show: function() {
// show ourselves after a call to hide()
this.reposition();
},
destroy: function() {
// destroy control and floater
if (this.domElement && this.div) {
this.hide();
this.div.innerHTML = '';
var body = document.getElementsByTagName('body')[0];
try { body.removeChild( this.div ); } catch(e) {}
this.domElement = null;
this.div = null;
}
},
reposition: function(elem) {
// reposition our floating div, optionally to new container
// warning: container CANNOT change size, only position
if (elem) {
this.domElement = ZeroClipboard.$(elem);
if (!this.domElement) this.hide();
}
if (this.domElement && this.div) {
var box = ZeroClipboard.getDOMObjectPosition(this.domElement);
var style = this.div.style;
style.left = '' + box.left + 'px';
style.top = '' + box.top + 'px';
}
},
setText: function(newText) {
// set text to be copied to clipboard
this.clipText = newText;
if (this.ready) this.movie.setText(newText);
},
addEventListener: function(eventName, func) {
// add user event listener for event
// event types: load, queueStart, fileStart, fileComplete, queueComplete, progress, error, cancel
eventName = eventName.toString().toLowerCase().replace(/^on/, '');
if (!this.handlers[eventName]) this.handlers[eventName] = [];
this.handlers[eventName].push(func);
},
setHandCursor: function(enabled) {
// enable hand cursor (true), or default arrow cursor (false)
this.handCursorEnabled = enabled;
if (this.ready) this.movie.setHandCursor(enabled);
},
setCSSEffects: function(enabled) {
// enable or disable CSS effects on DOM container
this.cssEffects = !!enabled;
},
receiveEvent: function(eventName, args) {
// receive event from flash
eventName = eventName.toString().toLowerCase().replace(/^on/, '');
// special behavior for certain events
switch (eventName) {
case 'load':
// movie claims it is ready, but in IE this isn't always the case...
// bug fix: Cannot extend EMBED DOM elements in Firefox, must use traditional function
this.movie = document.getElementById(this.movieId);
if (!this.movie) {
var self = this;
setTimeout( function() { self.receiveEvent('load', null); }, 1 );
return;
}
// firefox on pc needs a "kick" in order to set these in certain cases
if (!this.ready && navigator.userAgent.match(/Firefox/) && navigator.userAgent.match(/Windows/)) {
var self = this;
setTimeout( function() { self.receiveEvent('load', null); }, 100 );
this.ready = true;
return;
}
this.ready = true;
this.movie.setText( this.clipText );
this.movie.setHandCursor( this.handCursorEnabled );
break;
case 'mouseover':
if (this.domElement && this.cssEffects) {
this.domElement.addClass('hover');
if (this.recoverActive) this.domElement.addClass('active');
}
break;
case 'mouseout':
if (this.domElement && this.cssEffects) {
this.recoverActive = false;
if (this.domElement.hasClass('active')) {
this.domElement.removeClass('active');
this.recoverActive = true;
}
this.domElement.removeClass('hover');
}
break;
case 'mousedown':
if (this.domElement && this.cssEffects) {
this.domElement.addClass('active');
}
break;
case 'mouseup':
if (this.domElement && this.cssEffects) {
this.domElement.removeClass('active');
this.recoverActive = false;
}
break;
} // switch eventName
if (this.handlers[eventName]) {
for (var idx = 0, len = this.handlers[eventName].length; idx < len; idx++) {
var func = this.handlers[eventName][idx];
if (typeof(func) == 'function') {
// actual function reference
func(this, args);
}
else if ((typeof(func) == 'object') && (func.length == 2)) {
// PHP style object + method, i.e. [myObject, 'myMethod']
func[0][ func[1] ](this, args);
}
else if (typeof(func) == 'string') {
// name of function
window[func](this, args);
}
} // foreach event handler defined
} // user defined handler for event
}
};
if (typeof module !== "undefined") {
module.exports = ZeroClipboard;
}