-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.zerocliptip.js
79 lines (64 loc) · 2 KB
/
jquery.zerocliptip.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*!
* ZeroClipTip
*
* Copyright 2013 Mayoto Yoshida.
* Released under the MIT License.
*
* Dependencies
* jQuery: http://jquery.com
* ZeroClipboard: http://zeroclipboard.github.io/ZeroClipboard/
* tipsy: http://onehackoranother.com/projects/jquery/tipsy/
*
* Example
* <button class="copy-button" data-clipboard-text="Copy Me!">Copy to Clipboard</button>
* <button class="copy-button" title="copy to clipboard" data-copied-hint="copied!" data-clipboard-text="Copy Me!">Copy to Clipboard</button>
* <script>$('.copy-button').zerocliptip();</script>
*/
;(function($) {
$.fn.zerocliptip = function(options) {
var elements = this;
var settings = $.extend({}, $.fn.zerocliptip.defaults, options);
elements.each(function() {
var $this = $(this);
$this.data('zerocliptip', new ZeroClipTip($this, settings));
});
return this;
};
$.fn.zerocliptip.defaults = {
path: '/flash/ZeroClipboard.swf',
title: 'copy to clipboard',
copied_hint: 'copied!',
gravity: $.fn.tipsy.autoNS
};
function ZeroClipTip(root, settings) {
var self = this;
var initialize = function() {
if (!root.attr('title')) {
root.attr('title', settings.title);
} else if (root.attr('title') !== settings.title) {
root.attr('title', settings.title);
}
var clip = new ZeroClipboard(root, {
moviePath: settings.path
});
clip.on('load', function(client) {
$(clip.htmlBridge).tipsy({ gravity: settings.gravity });
$(clip.htmlBridge).attr('title', settings.title);
});
clip.on('complete', function(client, args) {
var copied_hint = $(this).data('copied-hint');
if (!copied_hint) {
copied_hint = settings.copied_hint;
}
$(clip.htmlBridge)
.prop('title', copied_hint)
.tipsy('show');
});
clip.on('noflash wrongflash', function(client) {
root.hide();
});
return self;
};
return initialize();
};
})(jQuery);