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