jquery.zclip.min.js 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  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. (function(a) {
  12. a.fn.zclip = function(c) {
  13. if (typeof c == "object" && !c.length) {
  14. var b = a.extend({
  15. path : "ZeroClipboard.swf",
  16. copy : null,
  17. beforeCopy : null,
  18. afterCopy : null,
  19. clickAfter : true,
  20. setHandCursor : true,
  21. setCSSEffects : true
  22. }, c);
  23. return this
  24. .each(function() {
  25. var e = a(this);
  26. if (e.is(":visible")
  27. && (typeof b.copy == "string" || a
  28. .isFunction(b.copy))) {
  29. ZeroClipboard.setMoviePath(b.path);
  30. var d = new ZeroClipboard.Client();
  31. if (a.isFunction(b.copy)) {
  32. e.bind("zClip_copy", b.copy)
  33. }
  34. if (a.isFunction(b.beforeCopy)) {
  35. e.bind("zClip_beforeCopy", b.beforeCopy)
  36. }
  37. if (a.isFunction(b.afterCopy)) {
  38. e.bind("zClip_afterCopy", b.afterCopy)
  39. }
  40. d.setHandCursor(b.setHandCursor);
  41. d.setCSSEffects(b.setCSSEffects);
  42. d.addEventListener("mouseOver", function(f) {
  43. e.trigger("mouseenter")
  44. });
  45. d.addEventListener("mouseOut", function(f) {
  46. e.trigger("mouseleave")
  47. });
  48. d.addEventListener("mouseDown", function(f) {
  49. e.trigger("mousedown");
  50. if (!a.isFunction(b.copy)) {
  51. d.setText(b.copy)
  52. } else {
  53. d.setText(e.triggerHandler("zClip_copy"))
  54. }
  55. if (a.isFunction(b.beforeCopy)) {
  56. e.trigger("zClip_beforeCopy")
  57. }
  58. });
  59. d.addEventListener("complete", function(f, g) {
  60. if (a.isFunction(b.afterCopy)) {
  61. e.trigger("zClip_afterCopy")
  62. } else {
  63. if (g.length > 500) {
  64. g = g.substr(0, 500) + "...\n\n("
  65. + (g.length - 500)
  66. + " characters not shown)"
  67. }
  68. e.removeClass("hover");
  69. //alert(g.length);
  70. tipsUser('内容已经复制到剪切板:\n\n'+ g,'success');
  71. //alert("Copied text to clipboard:\n\n " + g)
  72. }
  73. if (b.clickAfter) {
  74. e.trigger("click")
  75. }
  76. });
  77. d.glue(e[0], e.parent()[0]);
  78. a(window).bind("load resize", function() {
  79. d.reposition()
  80. })
  81. }
  82. })
  83. } else {
  84. if (typeof c == "string") {
  85. return this.each(function() {
  86. var f = a(this);
  87. c = c.toLowerCase();
  88. var e = f.data("zclipId");
  89. var d = a("#" + e + ".zclip");
  90. if (c == "remove") {
  91. d.remove();
  92. f.removeClass("active hover")
  93. } else {
  94. if (c == "hide") {
  95. d.hide();
  96. f.removeClass("active hover")
  97. } else {
  98. if (c == "show") {
  99. d.show()
  100. }
  101. }
  102. }
  103. })
  104. }
  105. }
  106. }
  107. })(jQuery);
  108. var ZeroClipboard = {
  109. version : "1.0.7",
  110. clients : {},
  111. moviePath : "ZeroClipboard.swf",
  112. nextId : 1,
  113. $ : function(a) {
  114. if (typeof (a) == "string") {
  115. a = document.getElementById(a)
  116. }
  117. if (!a.addClass) {
  118. a.hide = function() {
  119. this.style.display = "none"
  120. };
  121. a.show = function() {
  122. this.style.display = ""
  123. };
  124. a.addClass = function(b) {
  125. this.removeClass(b);
  126. this.className += " " + b
  127. };
  128. a.removeClass = function(d) {
  129. var e = this.className.split(/\s+/);
  130. var b = -1;
  131. for ( var c = 0; c < e.length; c++) {
  132. if (e[c] == d) {
  133. b = c;
  134. c = e.length
  135. }
  136. }
  137. if (b > -1) {
  138. e.splice(b, 1);
  139. this.className = e.join(" ")
  140. }
  141. return this
  142. };
  143. a.hasClass = function(b) {
  144. return !!this.className.match(new RegExp("\\s*" + b + "\\s*"))
  145. }
  146. }
  147. return a
  148. },
  149. setMoviePath : function(a) {
  150. this.moviePath = a
  151. },
  152. dispatch : function(d, b, c) {
  153. var a = this.clients[d];
  154. if (a) {
  155. a.receiveEvent(b, c)
  156. }
  157. },
  158. register : function(b, a) {
  159. this.clients[b] = a
  160. },
  161. getDOMObjectPosition : function(c, a) {
  162. var b = {
  163. left : 0,
  164. top : 0,
  165. width : c.width ? c.width : c.offsetWidth,
  166. height : c.height ? c.height : c.offsetHeight
  167. };
  168. if (c && (c != a)) {
  169. b.left += c.offsetLeft;
  170. b.top += c.offsetTop
  171. }
  172. return b
  173. },
  174. Client : function(a) {
  175. this.handlers = {};
  176. this.id = ZeroClipboard.nextId++;
  177. this.movieId = "ZeroClipboardMovie_" + this.id;
  178. ZeroClipboard.register(this.id, this);
  179. if (a) {
  180. this.glue(a)
  181. }
  182. }
  183. };
  184. ZeroClipboard.Client.prototype = {
  185. id : 0,
  186. ready : false,
  187. movie : null,
  188. clipText : "",
  189. handCursorEnabled : true,
  190. cssEffects : true,
  191. handlers : null,
  192. glue : function(d, b, e) {
  193. this.domElement = ZeroClipboard.$(d);
  194. var f = 99;
  195. if (this.domElement.style.zIndex) {
  196. f = parseInt(this.domElement.style.zIndex, 10) + 1
  197. }
  198. if (typeof (b) == "string") {
  199. b = ZeroClipboard.$(b)
  200. } else {
  201. if (typeof (b) == "undefined") {
  202. b = document.getElementsByTagName("body")[0]
  203. }
  204. }
  205. var c = ZeroClipboard.getDOMObjectPosition(this.domElement, b);
  206. this.div = document.createElement("div");
  207. this.div.className = "zclip";
  208. this.div.id = "zclip-" + this.movieId;
  209. $(this.domElement).data("zclipId", "zclip-" + this.movieId);
  210. var a = this.div.style;
  211. a.position = "absolute";
  212. a.left = "" + c.left + "px";
  213. a.top = "" + c.top + "px";
  214. a.width = "" + c.width + "px";
  215. a.height = "" + c.height + "px";
  216. a.zIndex = f;
  217. if (typeof (e) == "object") {
  218. for (addedStyle in e) {
  219. a[addedStyle] = e[addedStyle]
  220. }
  221. }
  222. b.appendChild(this.div);
  223. this.div.innerHTML = this.getHTML(c.width, c.height)
  224. },
  225. getHTML : function(d, a) {
  226. var c = "";
  227. var b = "id=" + this.id + "&width=" + d + "&height=" + a;
  228. if (navigator.userAgent.match(/MSIE/)) {
  229. var e = location.href.match(/^https/i) ? "https://" : "http://";
  230. c += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="'
  231. + e
  232. + 'download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="'
  233. + d
  234. + '" height="'
  235. + a
  236. + '" id="'
  237. + this.movieId
  238. + '" align="middle"><param name="allowScriptAccess" value="always" /><param name="allowFullScreen" value="false" /><param name="movie" value="'
  239. + ZeroClipboard.moviePath
  240. + '" /><param name="loop" value="false" /><param name="menu" value="false" /><param name="quality" value="best" /><param name="bgcolor" value="#ffffff" /><param name="flashvars" value="'
  241. + b
  242. + '"/><param name="wmode" value="transparent"/></object>'
  243. } else {
  244. c += '<embed id="'
  245. + this.movieId
  246. + '" src="'
  247. + ZeroClipboard.moviePath
  248. + '" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="'
  249. + d
  250. + '" height="'
  251. + a
  252. + '" name="'
  253. + this.movieId
  254. + '" align="middle" allowScriptAccess="always" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="'
  255. + b + '" wmode="transparent" />'
  256. }
  257. return c
  258. },
  259. hide : function() {
  260. if (this.div) {
  261. this.div.style.left = "-2000px"
  262. }
  263. },
  264. show : function() {
  265. this.reposition()
  266. },
  267. destroy : function() {
  268. if (this.domElement && this.div) {
  269. this.hide();
  270. this.div.innerHTML = "";
  271. var a = document.getElementsByTagName("body")[0];
  272. try {
  273. a.removeChild(this.div)
  274. } catch (b) {
  275. }
  276. this.domElement = null;
  277. this.div = null
  278. }
  279. },
  280. reposition : function(c) {
  281. if (c) {
  282. this.domElement = ZeroClipboard.$(c);
  283. if (!this.domElement) {
  284. this.hide()
  285. }
  286. }
  287. if (this.domElement && this.div) {
  288. var b = ZeroClipboard.getDOMObjectPosition(this.domElement);
  289. var a = this.div.style;
  290. a.left = "" + b.left + "px";
  291. a.top = "" + b.top + "px"
  292. }
  293. },
  294. setText : function(a) {
  295. this.clipText = a;
  296. if (this.ready) {
  297. this.movie.setText(a)
  298. }
  299. },
  300. addEventListener : function(a, b) {
  301. a = a.toString().toLowerCase().replace(/^on/, "");
  302. if (!this.handlers[a]) {
  303. this.handlers[a] = []
  304. }
  305. this.handlers[a].push(b)
  306. },
  307. setHandCursor : function(a) {
  308. this.handCursorEnabled = a;
  309. if (this.ready) {
  310. this.movie.setHandCursor(a)
  311. }
  312. },
  313. setCSSEffects : function(a) {
  314. this.cssEffects = !!a
  315. },
  316. receiveEvent : function(d, f) {
  317. d = d.toString().toLowerCase().replace(/^on/, "");
  318. switch (d) {
  319. case "load":
  320. this.movie = document.getElementById(this.movieId);
  321. if (!this.movie) {
  322. var c = this;
  323. setTimeout(function() {
  324. c.receiveEvent("load", null)
  325. }, 1);
  326. return
  327. }
  328. if (!this.ready && navigator.userAgent.match(/Firefox/)
  329. && navigator.userAgent.match(/Windows/)) {
  330. var c = this;
  331. setTimeout(function() {
  332. c.receiveEvent("load", null)
  333. }, 100);
  334. this.ready = true;
  335. return
  336. }
  337. this.ready = true;
  338. try {
  339. this.movie.setText(this.clipText)
  340. } catch (h) {
  341. }
  342. try {
  343. this.movie.setHandCursor(this.handCursorEnabled)
  344. } catch (h) {
  345. }
  346. break;
  347. case "mouseover":
  348. if (this.domElement && this.cssEffects) {
  349. this.domElement.addClass("hover");
  350. if (this.recoverActive) {
  351. this.domElement.addClass("active")
  352. }
  353. }
  354. break;
  355. case "mouseout":
  356. if (this.domElement && this.cssEffects) {
  357. this.recoverActive = false;
  358. if (this.domElement.hasClass("active")) {
  359. this.domElement.removeClass("active");
  360. this.recoverActive = true
  361. }
  362. this.domElement.removeClass("hover")
  363. }
  364. break;
  365. case "mousedown":
  366. if (this.domElement && this.cssEffects) {
  367. this.domElement.addClass("active")
  368. }
  369. break;
  370. case "mouseup":
  371. if (this.domElement && this.cssEffects) {
  372. this.domElement.removeClass("active");
  373. this.recoverActive = false
  374. }
  375. break
  376. }
  377. if (this.handlers[d]) {
  378. for ( var b = 0, a = this.handlers[d].length; b < a; b++) {
  379. var g = this.handlers[d][b];
  380. if (typeof (g) == "function") {
  381. g(this, f)
  382. } else {
  383. if ((typeof (g) == "object") && (g.length == 2)) {
  384. g[0][g[1]](this, f)
  385. } else {
  386. if (typeof (g) == "string") {
  387. window[g](this, f)
  388. }
  389. }
  390. }
  391. }
  392. }
  393. }
  394. };