copy_by_xumc 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md ADDED
@@ -0,0 +1,4 @@
1
+ copy
2
+ ====
3
+
4
+ rails gem, copy gem
@@ -0,0 +1,13 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'copy_by_xumc'
3
+ s.version = '0.0.0'
4
+ s.date = '2012-01-30'
5
+ s.summary = "swf copy "
6
+ s.description = "A simple copy gem"
7
+ s.authors = ["xumc"]
8
+ s.email = 'xumc@grandsoft.com.cn'
9
+ s.files = `git ls-files`.split($\)
10
+ s.executables = s.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
11
+ s.require_paths = ["lib"]
12
+ s.homepage = 'http://rubygems.org/gems/hola'
13
+ end
data/lib/copy.rb ADDED
@@ -0,0 +1,6 @@
1
+ puts "helloworld"
2
+ require "fileutils"
3
+ require File.expand_path('../helpers/copy_helper.rb', __FILE__)
4
+ folder = File.expand_path('../zeroclipboard', __FILE__)
5
+
6
+ FileUtils.cp_r(folder, "public" )
@@ -0,0 +1,11 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module CopyHelper
3
+ def copy_button(button_name, to_copy_text, html_options)
4
+ html_options[:class] = "#{html_options[:class]} zeroclipboard_clip_button"
5
+ html_attrs = html_options.map{|k, v| "#{k.to_s}=\"#{v.to_s}\"" }.join(" ")
6
+ #<script type=\"text/javascript\" src=\"zeroclipboard/ZeroClipboard.js\"></script>
7
+ raw "<a #{html_attrs} data-links=\"#{to_copy_text}\">#{button_name}</a>"
8
+ end
9
+ end
10
+
11
+ ActionView::Base.send :include, CopyHelper
@@ -0,0 +1,81 @@
1
+ package {
2
+ // Simple Set Clipboard System
3
+ // Author: Joseph Huckaby
4
+
5
+ import flash.display.Stage;
6
+ import flash.display.Sprite;
7
+ import flash.display.LoaderInfo;
8
+ import flash.display.StageScaleMode;
9
+ import flash.events.*;
10
+ import flash.display.StageAlign;
11
+ import flash.display.StageScaleMode;
12
+ import flash.external.ExternalInterface;
13
+ import flash.system.Security;
14
+ import flash.utils.*;
15
+ import flash.system.System;
16
+
17
+ public class ZeroClipboard extends Sprite {
18
+
19
+ private var id:String = '';
20
+ private var button:Sprite;
21
+ private var clipText:String = '';
22
+
23
+ public function ZeroClipboard() {
24
+ // constructor, setup event listeners and external interfaces
25
+ stage.scaleMode = StageScaleMode.EXACT_FIT;
26
+ flash.system.Security.allowDomain("*");
27
+
28
+ // import flashvars
29
+ var flashvars:Object = LoaderInfo( this.root.loaderInfo ).parameters;
30
+ id = flashvars.id;
31
+
32
+ // invisible button covers entire stage
33
+ button = new Sprite();
34
+ button.buttonMode = true;
35
+ button.useHandCursor = true;
36
+ button.graphics.beginFill(0xCCFF00);
37
+ button.graphics.drawRect(0, 0, Math.floor(flashvars.width), Math.floor(flashvars.height));
38
+ button.alpha = 0.0;
39
+ addChild(button);
40
+ button.addEventListener(MouseEvent.CLICK, clickHandler);
41
+
42
+ button.addEventListener(MouseEvent.MOUSE_OVER, function(event:Event) {
43
+ ExternalInterface.call( 'ZeroClipboard.dispatch', id, 'mouseOver', null );
44
+ } );
45
+ button.addEventListener(MouseEvent.MOUSE_OUT, function(event:Event) {
46
+ ExternalInterface.call( 'ZeroClipboard.dispatch', id, 'mouseOut', null );
47
+ } );
48
+ button.addEventListener(MouseEvent.MOUSE_DOWN, function(event:Event) {
49
+ ExternalInterface.call( 'ZeroClipboard.dispatch', id, 'mouseDown', null );
50
+ } );
51
+ button.addEventListener(MouseEvent.MOUSE_UP, function(event:Event) {
52
+ ExternalInterface.call( 'ZeroClipboard.dispatch', id, 'mouseUp', null );
53
+ } );
54
+
55
+ // external functions
56
+ ExternalInterface.addCallback("setHandCursor", setHandCursor);
57
+ ExternalInterface.addCallback("setText", setText);
58
+
59
+ // signal to the browser that we are ready
60
+ ExternalInterface.call( 'ZeroClipboard.dispatch', id, 'load', null );
61
+ }
62
+
63
+ public function setText(newText) {
64
+ // set the maximum number of files allowed
65
+ clipText = newText;
66
+ }
67
+
68
+ public function setHandCursor(enabled:Boolean) {
69
+ // control whether the hand cursor is shown on rollover (true)
70
+ // or the default arrow cursor (false)
71
+ button.useHandCursor = enabled;
72
+ }
73
+
74
+ private function clickHandler(event:Event):void {
75
+ // user click copies text to clipboard
76
+ // as of flash player 10, this MUST happen from an in-movie flash click event
77
+ System.setClipboard( clipText );
78
+ ExternalInterface.call( 'ZeroClipboard.dispatch', id, 'complete', clipText );
79
+ }
80
+ }
81
+ }
Binary file
@@ -0,0 +1,334 @@
1
+ // Simple Set Clipboard System
2
+ // Author: Joseph Huckaby
3
+
4
+ var ZeroClipboard = {
5
+
6
+ version: "1.0.7",
7
+ clients: {}, // registered upload clients on page, indexed by id
8
+ moviePath: 'zeroclipboard/ZeroClipboard.swf', // URL to movie
9
+ nextId: 1, // ID of next movie
10
+
11
+ $: function(thingy) {
12
+ // simple DOM lookup utility function
13
+ if (typeof(thingy) == 'string') thingy = document.getElementById(thingy);
14
+ if (!thingy.addClass) {
15
+ // extend element with a few useful methods
16
+ thingy.hide = function() { this.style.display = 'none'; };
17
+ thingy.show = function() { this.style.display = ''; };
18
+ thingy.addClass = function(name) { this.removeClass(name); this.className += ' ' + name; };
19
+ thingy.removeClass = function(name) {
20
+ var classes = this.className.split(/\s+/);
21
+ var idx = -1;
22
+ for (var k = 0; k < classes.length; k++) {
23
+ if (classes[k] == name) { idx = k; k = classes.length; }
24
+ }
25
+ if (idx > -1) {
26
+ classes.splice( idx, 1 );
27
+ this.className = classes.join(' ');
28
+ }
29
+ return this;
30
+ };
31
+ thingy.hasClass = function(name) {
32
+ return !!this.className.match( new RegExp("\\s*" + name + "\\s*") );
33
+ };
34
+ }
35
+ return thingy;
36
+ },
37
+
38
+ setMoviePath: function(path) {
39
+ // set path to ZeroClipboard.swf
40
+ this.moviePath = path;
41
+ },
42
+
43
+ dispatch: function(id, eventName, args) {
44
+ // receive event from flash movie, send to client
45
+ var client = this.clients[id];
46
+ if (client) {
47
+ client.receiveEvent(eventName, args);
48
+ }
49
+ },
50
+
51
+ register: function(id, client) {
52
+ // register new client to receive events
53
+ this.clients[id] = client;
54
+ },
55
+
56
+ getDOMObjectPosition: function(obj, stopObj) {
57
+ // get absolute coordinates for dom element
58
+ var info = {
59
+ left: 0,
60
+ top: 0,
61
+ width: obj.width ? obj.width : obj.offsetWidth,
62
+ height: obj.height ? obj.height : obj.offsetHeight
63
+ };
64
+
65
+ while (obj && (obj != stopObj)) {
66
+ info.left += obj.offsetLeft;
67
+ info.top += obj.offsetTop;
68
+ obj = obj.offsetParent;
69
+ }
70
+
71
+ return info;
72
+ },
73
+
74
+ Client: function(elem) {
75
+ // constructor for new simple upload client
76
+ this.handlers = {};
77
+
78
+ // unique ID
79
+ this.id = ZeroClipboard.nextId++;
80
+ this.movieId = 'ZeroClipboardMovie_' + this.id;
81
+
82
+ // register client with singleton to receive flash events
83
+ ZeroClipboard.register(this.id, this);
84
+
85
+ // create movie
86
+ if (elem) this.glue(elem);
87
+ }
88
+ };
89
+
90
+ ZeroClipboard.Client.prototype = {
91
+
92
+ id: 0, // unique ID for us
93
+ ready: false, // whether movie is ready to receive events or not
94
+ movie: null, // reference to movie object
95
+ clipText: '', // text to copy to clipboard
96
+ handCursorEnabled: true, // whether to show hand cursor, or default pointer cursor
97
+ cssEffects: true, // enable CSS mouse effects on dom container
98
+ handlers: null, // user event handlers
99
+
100
+ glue: function(elem, appendElem, stylesToAdd) {
101
+ // glue to DOM element
102
+ // elem can be ID or actual DOM element object
103
+ this.domElement = ZeroClipboard.$(elem);
104
+
105
+ // float just above object, or zIndex 99 if dom element isn't set
106
+ var zIndex = 99;
107
+ if (this.domElement.style.zIndex) {
108
+ zIndex = parseInt(this.domElement.style.zIndex, 10) + 1;
109
+ }
110
+
111
+ if (typeof(appendElem) == 'string') {
112
+ appendElem = ZeroClipboard.$(appendElem);
113
+ }
114
+ else if (typeof(appendElem) == 'undefined') {
115
+ appendElem = document.getElementsByTagName('body')[0];
116
+ }
117
+
118
+ // find X/Y position of domElement
119
+ var box = ZeroClipboard.getDOMObjectPosition(this.domElement, appendElem);
120
+
121
+ // create floating DIV above element
122
+ this.div = document.createElement('div');
123
+ var style = this.div.style;
124
+ style.position = 'absolute';
125
+ style.left = '' + box.left + 'px';
126
+ style.top = '' + box.top + 'px';
127
+ style.width = '' + box.width + 'px';
128
+ style.height = '' + box.height + 'px';
129
+ style.zIndex = zIndex;
130
+
131
+ if (typeof(stylesToAdd) == 'object') {
132
+ for (addedStyle in stylesToAdd) {
133
+ style[addedStyle] = stylesToAdd[addedStyle];
134
+ }
135
+ }
136
+
137
+ // style.backgroundColor = '#f00'; // debug
138
+
139
+ appendElem.appendChild(this.div);
140
+
141
+ this.div.innerHTML = this.getHTML( box.width, box.height );
142
+ },
143
+
144
+ getHTML: function(width, height) {
145
+ // return HTML for movie
146
+ var html = '';
147
+ var flashvars = 'id=' + this.id +
148
+ '&width=' + width +
149
+ '&height=' + height;
150
+
151
+ if (navigator.userAgent.match(/MSIE/)) {
152
+ // IE gets an OBJECT tag
153
+ var protocol = location.href.match(/^https/i) ? 'https://' : 'http://';
154
+ 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>';
155
+ }
156
+ else {
157
+ // all other browsers get an EMBED tag
158
+ 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" />';
159
+ }
160
+ return html;
161
+ },
162
+
163
+ hide: function() {
164
+ // temporarily hide floater offscreen
165
+ if (this.div) {
166
+ this.div.style.left = '-2000px';
167
+ }
168
+ },
169
+
170
+ show: function() {
171
+ // show ourselves after a call to hide()
172
+ this.reposition();
173
+ },
174
+
175
+ destroy: function() {
176
+ // destroy control and floater
177
+ if (this.domElement && this.div) {
178
+ this.hide();
179
+ this.div.innerHTML = '';
180
+
181
+ var body = document.getElementsByTagName('body')[0];
182
+ try { body.removeChild( this.div ); } catch(e) {;}
183
+
184
+ this.domElement = null;
185
+ this.div = null;
186
+ }
187
+ },
188
+
189
+ reposition: function(elem) {
190
+ // reposition our floating div, optionally to new container
191
+ // warning: container CANNOT change size, only position
192
+ if (elem) {
193
+ this.domElement = ZeroClipboard.$(elem);
194
+ if (!this.domElement) this.hide();
195
+ }
196
+
197
+ if (this.domElement && this.div) {
198
+ var box = ZeroClipboard.getDOMObjectPosition(this.domElement);
199
+ var style = this.div.style;
200
+ style.left = '' + box.left + 'px';
201
+ style.top = '' + box.top + 'px';
202
+ }
203
+ },
204
+
205
+ setText: function(newText) {
206
+ // set text to be copied to clipboard
207
+ this.clipText = newText;
208
+ if (this.ready) this.movie.setText(newText);
209
+ },
210
+
211
+ addEventListener: function(eventName, func) {
212
+ // add user event listener for event
213
+ // event types: load, queueStart, fileStart, fileComplete, queueComplete, progress, error, cancel
214
+ eventName = eventName.toString().toLowerCase().replace(/^on/, '');
215
+ if (!this.handlers[eventName]) this.handlers[eventName] = [];
216
+ this.handlers[eventName].push(func);
217
+ },
218
+
219
+ setHandCursor: function(enabled) {
220
+ // enable hand cursor (true), or default arrow cursor (false)
221
+ this.handCursorEnabled = enabled;
222
+ if (this.ready) this.movie.setHandCursor(enabled);
223
+ },
224
+
225
+ setCSSEffects: function(enabled) {
226
+ // enable or disable CSS effects on DOM container
227
+ this.cssEffects = !!enabled;
228
+ },
229
+
230
+ receiveEvent: function(eventName, args) {
231
+ // receive event from flash
232
+ eventName = eventName.toString().toLowerCase().replace(/^on/, '');
233
+
234
+ // special behavior for certain events
235
+ switch (eventName) {
236
+ case 'load':
237
+ // movie claims it is ready, but in IE this isn't always the case...
238
+ // bug fix: Cannot extend EMBED DOM elements in Firefox, must use traditional function
239
+ this.movie = document.getElementById(this.movieId);
240
+ if (!this.movie) {
241
+ var self = this;
242
+ setTimeout( function() { self.receiveEvent('load', null); }, 1 );
243
+ return;
244
+ }
245
+
246
+ // firefox on pc needs a "kick" in order to set these in certain cases
247
+ if (!this.ready && navigator.userAgent.match(/Firefox/) && navigator.userAgent.match(/Windows/)) {
248
+ var self = this;
249
+ setTimeout( function() { self.receiveEvent('load', null); }, 100 );
250
+ this.ready = true;
251
+ return;
252
+ }
253
+
254
+ this.ready = true;
255
+ this.movie.setText( this.clipText );
256
+ this.movie.setHandCursor( this.handCursorEnabled );
257
+ break;
258
+
259
+ case 'mouseover':
260
+ if (this.domElement && this.cssEffects) {
261
+ this.domElement.addClass('hover');
262
+ if (this.recoverActive) this.domElement.addClass('active');
263
+ }
264
+ break;
265
+
266
+ case 'mouseout':
267
+ if (this.domElement && this.cssEffects) {
268
+ this.recoverActive = false;
269
+ if (this.domElement.hasClass('active')) {
270
+ this.domElement.removeClass('active');
271
+ this.recoverActive = true;
272
+ }
273
+ this.domElement.removeClass('hover');
274
+ }
275
+ break;
276
+
277
+ case 'mousedown':
278
+ if (this.domElement && this.cssEffects) {
279
+ this.domElement.addClass('active');
280
+ }
281
+ break;
282
+
283
+ case 'mouseup':
284
+ if (this.domElement && this.cssEffects) {
285
+ this.domElement.removeClass('active');
286
+ this.recoverActive = false;
287
+ }
288
+ break;
289
+ } // switch eventName
290
+
291
+ if (this.handlers[eventName]) {
292
+ for (var idx = 0, len = this.handlers[eventName].length; idx < len; idx++) {
293
+ var func = this.handlers[eventName][idx];
294
+
295
+ if (typeof(func) == 'function') {
296
+ // actual function reference
297
+ func(this, args);
298
+ }
299
+ else if ((typeof(func) == 'object') && (func.length == 2)) {
300
+ // PHP style object + method, i.e. [myObject, 'myMethod']
301
+ func[0][ func[1] ](this, args);
302
+ }
303
+ else if (typeof(func) == 'string') {
304
+ // name of function
305
+ window[func](this, args);
306
+ }
307
+ } // foreach event handler defined
308
+ } // user defined handler for event
309
+ }
310
+
311
+ };
312
+
313
+
314
+ //xumc add this
315
+ $(document).ready(function(){
316
+ function init(id, to_copy_text) {
317
+ var clip = null;
318
+ clip = new ZeroClipboard.Client();
319
+ clip.setHandCursor( true );
320
+ clip.addEventListener('load', function (client) {
321
+ });
322
+ clip.addEventListener('mouseOver', function (client) {
323
+ // update the text on mouse over
324
+ clip.setText(to_copy_text);
325
+ });
326
+ clip.addEventListener('complete', function (client, text) {
327
+ alert("该链接已成功复制到您的剪切板,请粘贴使用");
328
+ });
329
+ clip.glue(id);
330
+ }
331
+ $(".zeroclipboard_clip_button").each(function(){
332
+ init($(this).attr("id") , $(this).attr("data-links"));
333
+ });
334
+ });
Binary file
@@ -0,0 +1 @@
1
+ package {
2
 
1
3
  Clipboard.generalClipboard.setData(ClipboardFormats.HTML_FORMAT, clipText);
@@ -0,0 +1,76 @@
1
+ <html>
2
+ <head>
3
+ <title>Zero Clipboard Test</title>
4
+ <style type="text/css">
5
+ body { font-family:arial,sans-serif; font-size:9pt; }
6
+
7
+ .my_clip_button { width:150px; text-align:center; border:1px solid black; background-color:#ccc; margin:10px; padding:10px; cursor:default; font-size:9pt; }
8
+ .my_clip_button.hover { background-color:#eee; }
9
+ .my_clip_button.active { background-color:#aaa; }
10
+ </style>
11
+ <script type="text/javascript" src="ZeroClipboard.js"></script>
12
+ <script language="JavaScript">
13
+ var clip = null;
14
+
15
+ function $(id) { return document.getElementById(id); }
16
+
17
+ function init() {
18
+ clip = new ZeroClipboard.Client();
19
+ clip.setHandCursor( true );
20
+
21
+ clip.addEventListener('load', function (client) {
22
+ debugstr("Flash movie loaded and ready.");
23
+ });
24
+
25
+ clip.addEventListener('mouseOver', function (client) {
26
+ // update the text on mouse over
27
+ clip.setText( $('fe_text').value );
28
+ });
29
+
30
+ clip.addEventListener('complete', function (client, text) {
31
+ debugstr("Copied text to clipboard: " + text );
32
+ });
33
+
34
+ clip.glue( 'd_clip_button', 'd_clip_container' );
35
+ }
36
+
37
+ function debugstr(msg) {
38
+ var p = document.createElement('p');
39
+ p.innerHTML = msg;
40
+ $('d_debug').appendChild(p);
41
+ }
42
+ </script>
43
+ </head>
44
+ <body onLoad="init()">
45
+ <h1>Zero Clipboard Test</h1>
46
+ <p><script>document.write("Your browser: " + navigator.userAgent);</script></p>
47
+ <table width="100%">
48
+ <tr>
49
+ <td width="50%" valign="top">
50
+ <!-- Upload Form -->
51
+ <table>
52
+ <tr>
53
+ <td align="right"><b>Text:</b></td>
54
+ <td align="left"><textarea id="fe_text" cols=50 rows=5 onChange="clip.setText(this.value)">Copy me!</textarea></td>
55
+ </tr>
56
+ </table>
57
+ <br/>
58
+ <div id="d_clip_container" style="position:relative">
59
+ <div id="d_clip_button" class="my_clip_button"><b>Copy To Clipboard...</b></div>
60
+ </div>
61
+ </td>
62
+ <td width="50%" valign="top">
63
+ <!-- Debug Console -->
64
+ <div id="d_debug" style="border:1px solid #aaa; padding: 10px; font-size:9pt;">
65
+ <h3>Debug Console:</h3>
66
+ </div>
67
+ </td>
68
+ </tr>
69
+ </table>
70
+
71
+ <br/><br/>
72
+ You can paste text here if you want, to make sure it worked:<br/>
73
+ <textarea id="testarea" cols=50 rows=10></textarea><br/>
74
+ <input type=button value="Clear Test Area" onClick="$('testarea').value = '';"/>
75
+ </body>
76
+ </html>
metadata ADDED
@@ -0,0 +1,56 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: copy_by_xumc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - xumc
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-01-30 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: A simple copy gem
15
+ email: xumc@grandsoft.com.cn
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - README.md
21
+ - copy_by_xumc.gemspec
22
+ - lib/copy.rb
23
+ - lib/helpers/copy_helper.rb
24
+ - lib/zeroclipboard/ZeroClipboard.as
25
+ - lib/zeroclipboard/ZeroClipboard.fla
26
+ - lib/zeroclipboard/ZeroClipboard.js
27
+ - lib/zeroclipboard/ZeroClipboard.swf
28
+ - lib/zeroclipboard/ZeroClipboard10.as
29
+ - lib/zeroclipboard/ZeroClipboard10.fla
30
+ - lib/zeroclipboard/ZeroClipboard10.swf
31
+ - lib/zeroclipboard/test.html
32
+ homepage: http://rubygems.org/gems/hola
33
+ licenses: []
34
+ post_install_message:
35
+ rdoc_options: []
36
+ require_paths:
37
+ - lib
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ! '>='
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ requirements: []
51
+ rubyforge_project:
52
+ rubygems_version: 1.8.23
53
+ signing_key:
54
+ specification_version: 3
55
+ summary: swf copy
56
+ test_files: []