PageSourceSearch

https://track24.ru/js/jquery.zclip.js

js track24.ru collected 2026-10-01 13:05:41 UTC 16,811 bytes, 495 lines download raw bytes

1/*
2 * zClip :: jQuery ZeroClipboard v1.1.1
3 * http://steamdev.com/zclip
4 *
5 * Copyright 2011, SteamDev
6 * Released under the MIT license.
7 * http://www.opensource.org/licenses/mit-license.php
8 *
9 * Date: Wed Jun 01, 2011
10 */
11
12
13(function ($) {
14
15    $.fn.zclip = function (params) {
16
17        if (typeof params == "object" && !params.length) {
18
19            var settings = $.extend({
20
21                path: 'ZeroClipboard.swf',
22                copy: null,
23                beforeCopy: null,
24                afterCopy: null,
25                clickAfter: true,
26                setHandCursor: true,
27                setCSSEffects: true
28
29            }, params);
30			
31
32            return this.each(function () {
33
34                var o = $(this);
35
36                if (o.is(':visible') && (typeof settings.copy == 'string' || $.isFunction(settings.copy))) {
37
38                    ZeroClipboard.setMoviePath(settings.path);
39                    var clip = new ZeroClipboard.Client();
40                    
41                    if($.isFunction(settings.copy)){
42                    	o.bind('zClip_copy',settings.copy);
43                    }
44                    if($.isFunction(settings.beforeCopy)){
45                    	o.bind('zClip_beforeCopy',settings.beforeCopy);
46                    }
47                    if($.isFunction(settings.afterCopy)){
48                    	o.bind('zClip_afterCopy',settings.afterCopy);
49                    }                    
50
51                    clip.setHandCursor(settings.setHandCursor);
52                    clip.setCSSEffects(settings.setCSSEffects);
53                    clip.addEventListener('mouseOver', function (client) {
54                        o.trigger('mouseenter');
55                    });
56                    clip.addEventListener('mouseOut', function (client) {
57                        o.trigger('mouseleave');
58                    });
59                    clip.addEventListener('mouseDown', function (client) {
60
61                        o.trigger('mousedown');
62                        
63			if(!$.isFunction(settings.copy)){
64			   clip.setText(settings.copy);
65			} else {
66			   clip.setText(o.triggerHandler('zClip_copy'));
67			}                        
68                        
69                        if ($.isFunction(settings.beforeCopy)) {
70                            o.trigger('zClip_beforeCopy');                            
71                        }
72
73                    });
74
75                    clip.addEventListener('complete', function (client, text) {
76
77                        if ($.isFunction(settings.afterCopy)) {
78                            
79                            o.trigger('zClip_afterCopy');
80
81                        } else {
82                            if (text.length > 500) {
83                                text = text.substr(0, 500) + "...\n\n(" + (text.length - 500) + " characters not shown)";
84                            }
85							
86			                o.removeClass('hover');
87                            //alert("Copied text to clipboard:\n\n " + text);
88							console.log("Copied text to clipboard: " + text);
89                        }
90
91                        if (settings.clickAfter) {
92                            o.trigger('click');
93                        }
94
95                    });
96
97					
98                    clip.glue(o[0], o.parent()[0]);
99					
100		    $(window).bind('load resize',function(){clip.reposition();});
101					
102
103                }
104
105            });
106
107        } else if (typeof params == "string") {
108
109            return this.each(function () {
110
111                var o = $(this);
112
113                params = params.toLowerCase();
114                var zclipId = o.data('zclipId');
115                var clipElm = $('#' + zclipId + '.zclip');
116
117                if (params == "remove") {
118
119                    clipElm.remove();
120                    o.removeClass('active hover');
121
122                } else if (params == "hide") {
123
124                    clipElm.hide();
125                    o.removeClass('active hover');
126
127                } else if (params == "show") {
128
129                    clipElm.show();
130
131                }
132
133            });
134
135        }
136
137    }	
138	
139	
140
141})(jQuery);
142
143
144
145
146
147
148
149// ZeroClipboard
150// Simple Set Clipboard System
151// Author: Joseph Huckaby
152var ZeroClipboard = {
153
154    version: "1.0.7",
155    clients: {},
156    // registered upload clients on page, indexed by id
157    moviePath: 'ZeroClipboard.swf',
158    // URL to movie
159    nextId: 1,
160    // ID of next movie
161    $: function (thingy) {
162        // simple DOM lookup utility function
163        if (typeof(thingy) == 'string') thingy = document.getElementById(thingy);
164        if (!thingy.addClass) {
165            // extend element with a few useful methods
166            thingy.hide = function () {
167                this.style.display = 'none';
168            };
169            thingy.show = function () {
170                this.style.display = '';
171            };
172            thingy.addClass = function (name) {
173                this.removeClass(name);
174                this.className += ' ' + name;
175            };
176            thingy.removeClass = function (name) {
177                var classes = this.className.split(/\s+/);
178                var idx = -1;
179                for (var k = 0; k < classes.length; k++) {
180                    if (classes[k] == name) {
181                        idx = k;
182                        k = classes.length;
183                    }
184                }
185                if (idx > -1) {
186                    classes.splice(idx, 1);
187                    this.className = classes.join(' ');
188                }
189                return this;
190            };
191            thingy.hasClass = function (name) {
192                return !!this.className.match(new RegExp("\\s*" + name + "\\s*"));
193            };
194        }
195        return thingy;
196    },
197
198    setMoviePath: function (path) {
199        // set path to ZeroClipboard.swf
200        this.moviePath = path;
201    },
202
203    dispatch: function (id, eventName, args) {
204        // receive event from flash movie, send to client		
205        var client = this.clients[id];
206        if (client) {
207            client.receiveEvent(eventName, args);
208        }
209    },
210
211    register: function (id, client) {
212        // register new client to receive events
213        this.clients[id] = client;
214    },
215
216    getDOMObjectPosition: function (obj, stopObj) {
217        // get absolute coordinates for dom element
218        var info = {
219            left: 0,
220            top: 0,
221            width: obj.width ? obj.width : obj.offsetWidth,
222            height: obj.height ? obj.height : obj.offsetHeight
223        };
224
225        if (obj && (obj != stopObj)) {
226			info.left += obj.offsetLeft;
227            info.top += obj.offsetTop;
228        }
229
230        return info;
231    },
232
233    Client: function (elem) {
234        // constructor for new simple upload client
235        this.handlers = {};
236
237        // unique ID
238        this.id = ZeroClipboard.nextId++;
239        this.movieId = 'ZeroClipboardMovie_' + this.id;
240
241        // register client with singleton to receive flash events
242        ZeroClipboard.register(this.id, this);
243
244        // create movie
245        if (elem) this.glue(elem);
246    }
247};
248
249ZeroClipboard.Client.prototype = {
250
251    id: 0,
252    // unique ID for us
253    ready: false,
254    // whether movie is ready to receive events or not
255    movie: null,
256    // reference to movie object
257    clipText: '',
258    // text to copy to clipboard
259    handCursorEnabled: true,
260    // whether to show hand cursor, or default pointer cursor
261    cssEffects: true,
262    // enable CSS mouse effects on dom container
263    handlers: null,
264    // user event handlers
265    glue: function (elem, appendElem, stylesToAdd) {
266        // glue to DOM element
267        // elem can be ID or actual DOM element object
268        this.domElement = ZeroClipboard.$(elem);
269
270        // float just above object, or zIndex 99 if dom element isn't set
271        var zIndex = 99;
272        if (this.domElement.style.zIndex) {
273            zIndex = parseInt(this.domElement.style.zIndex, 10) + 1;
274        }
275
276        if (typeof(appendElem) == 'string') {
277            appendElem = ZeroClipboard.$(appendElem);
278        } else if (typeof(appendElem) == 'undefined') {
279            appendElem = document.getElementsByTagName('body')[0];
280        }
281
282        // find X/Y position of domElement
283        var box = ZeroClipboard.getDOMObjectPosition(this.domElement, appendElem);
284
285        // create floating DIV above element
286        this.div = document.createElement('div');
287        this.div.className = "zclip";
288        this.div.id = "zclip-" + this.movieId;
289        $(this.domElement).data('zclipId', 'zclip-' + this.movieId);
290        var style = this.div.style;
291        style.position = 'absolute';
292        style.left = '' + box.left + 'px';
293        style.top = '' + box.top + 'px';
294        style.width = '' + box.width + 'px';
295        style.height = '' + box.height + 'px';
296        style.zIndex = zIndex;
297
298        if (typeof(stylesToAdd) == 'object') {
299            for (addedStyle in stylesToAdd) {
300                style[addedStyle] = stylesToAdd[addedStyle];
301            }
302        }
303
304        // style.backgroundColor = '#f00'; // debug
305        appendElem.appendChild(this.div);
306
307        this.div.innerHTML = this.getHTML(box.width, box.height);
308    },
309
310    getHTML: function (width, height) {
311        // return HTML for movie
312        var html = '';
313        var flashvars = 'id=' + this.id + '&width=' + width + '&height=' + height;
314
315        if (navigator.userAgent.match(/MSIE/)) {
316            // IE gets an OBJECT tag
317            var protocol = location.href.match(/^https/i) ? 'https://' : 'http://';
318            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>';
319        } else {
320            // all other browsers get an EMBED tag
321            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" />';
322        }
323        return html;
324    },
325
326    hide: function () {
327        // temporarily hide floater offscreen
328        if (this.div) {
329            this.div.style.left = '-2000px';
330        }
331    },
332
333    show: function () {
334        // show ourselves after a call to hide()
335        this.reposition();
336    },
337
338    destroy: function () {
339        // destroy control and floater
340        if (this.domElement && this.div) {
341            this.hide();
342            this.div.innerHTML = '';
343
344            var body = document.getElementsByTagName('body')[0];
345            try {
346                body.removeChild(this.div);
347            } catch (e) {;
348            }
349
350            this.domElement = null;
351            this.div = null;
352        }
353    },
354
355    reposition: function (elem) {
356        // reposition our floating div, optionally to new container
357        // warning: container CANNOT change size, only position
358        if (elem) {
359            this.domElement = ZeroClipboard.$(elem);
360            if (!this.domElement) this.hide();
361        }
362
363        if (this.domElement && this.div) {
364            var box = ZeroClipboard.getDOMObjectPosition(this.domElement);
365            var style = this.div.style;
366            style.left = '' + box.left + 'px';
367            style.top = '' + box.top + 'px';
368        }
369    },
370
371    setText: function (newText) {
372        // set text to be copied to clipboard
373        this.clipText = newText;
374        if (this.ready) {
375            this.movie.setText(newText);
376        }
377    },
378
379    addEventListener: function (eventName, func) {
380        // add user event listener for event
381        // event types: load, queueStart, fileStart, fileComplete, queueComplete, progress, error, cancel
382        eventName = eventName.toString().toLowerCase().replace(/^on/, '');
383        if (!this.handlers[eventName]) {
384            this.handlers[eventName] = [];
385        }
386        this.handlers[eventName].push(func);
387    },
388
389    setHandCursor: function (enabled) {
390        // enable hand cursor (true), or default arrow cursor (false)
391        this.handCursorEnabled = enabled;
392        if (this.ready) {
393            this.movie.setHandCursor(enabled);
394        }
395    },
396
397    setCSSEffects: function (enabled) {
398        // enable or disable CSS effects on DOM container
399        this.cssEffects = !! enabled;
400    },
401
402    receiveEvent: function (eventName, args) {
403        // receive event from flash
404        eventName = eventName.toString().toLowerCase().replace(/^on/, '');
405
406        // special behavior for certain events
407        switch (eventName) {
408        case 'load':
409            // movie claims it is ready, but in IE this isn't always the case...
410            // bug fix: Cannot extend EMBED DOM elements in Firefox, must use traditional function
411            this.movie = document.getElementById(this.movieId);
412            if (!this.movie) {
413                var self = this;
414                setTimeout(function () {
415                    self.receiveEvent('load', null);
416                }, 1);
417                return;
418            }
419
420            // firefox on pc needs a "kick" in order to set these in certain cases
421            if (!this.ready && navigator.userAgent.match(/Firefox/) && navigator.userAgent.match(/Windows/)) {
422                var self = this;
423                setTimeout(function () {
424                    self.receiveEvent('load', null);
425                }, 100);
426                this.ready = true;
427                return;
428            }
429
430            this.ready = true;
431            try {
432                this.movie.setText(this.clipText);
433            } catch (e) {}
434            try {
435                this.movie.setHandCursor(this.handCursorEnabled);
436            } catch (e) {}
437            break;
438
439        case 'mouseover':
440            if (this.domElement && this.cssEffects) {
441                this.domElement.addClass('hover');
442                if (this.recoverActive) {
443                    this.domElement.addClass('active');
444                }
445
446
447            }
448
449
450            break;
451
452        case 'mouseout':
453            if (this.domElement && this.cssEffects) {
454                this.recoverActive = false;
455                if (this.domElement.hasClass('active')) {
456                    this.domElement.removeClass('active');
457                    this.recoverActive = true;
458                }
459                this.domElement.removeClass('hover');
460
461            }
462            break;
463
464        case 'mousedown':
465            if (this.domElement && this.cssEffects) {
466                this.domElement.addClass('active');
467            }
468            break;
469
470        case 'mouseup':
471            if (this.domElement && this.cssEffects) {
472                this.domElement.removeClass('active');
473                this.recoverActive = false;
474            }
475            break;
476        } // switch eventName
477        if (this.handlers[eventName]) {
478            for (var idx = 0, len = this.handlers[eventName].length; idx < len; idx++) {
479                var func = this.handlers[eventName][idx];
480
481                if (typeof(func) == 'function') {
482                    // actual function reference
483                    func(this, args);
484                } else if ((typeof(func) == 'object') && (func.length == 2)) {
485                    // PHP style object + method, i.e. [myObject, 'myMethod']
486                    func[0][func[1]](this, args);
487                } else if (typeof(func) == 'string') {
488                    // name of function
489                    window[func](this, args);
490                }
491            } // foreach event handler defined
492        } // user defined handler for event
493    }
494
495};	

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.