@@ -26,7 +26,8 @@ var Tracking = require('../Tracking');
26
26
var TextUtils = require ( '../utils/TextUtils' ) ;
27
27
var Utils = require ( '../utils/Utils' ) ;
28
28
var ExpressionModel = require ( '../net/ExpressionModel' ) ;
29
- var ZeroClipboard = require ( 'zeroclipboard' ) ;
29
+ var Clipboard = require ( 'clipboard' ) ;
30
+ var Tooltip = require ( '../controls/Tooltip' ) ;
30
31
31
32
var ShareMenu = function ( element , docsView ) {
32
33
this . initialize ( element , docsView ) ;
@@ -40,32 +41,21 @@ p.initialize = function (element, docsView) {
40
41
this . docsView = docsView ;
41
42
this . element = element ;
42
43
43
- this . shareLink = $ . el ( "#shareLinkTxt" , this . element ) ;
44
- this . copyLink = $ . el ( "#shareCopyLink" , this . element ) ;
45
44
this . showSaveLink = $ . el ( "#showSaveLink" , this . element ) ;
46
- this . copyExpression = $ . el ( "#copyExpression" , this . element ) ;
47
- this . copyPattern = $ . el ( "#copyPattern" , this . element ) ;
48
-
49
45
this . showSaveLink . onclick = $ . bind ( this , this . handleSaveClick ) ;
50
-
51
46
this . saveView = $ . el ( "#savePrompt" , this . element ) ;
52
- this . shareLinkView = $ . el ( "#shareLinkView " , this . element ) ;
53
- this . copyJavascript = $ . el ( "#copyJavascript " , this . element ) ;
54
-
55
- this . noFlashCopyView = $ . el ( "#noFlashCopyView " , this . element ) ;
56
- this . noFlashCopyInput = $ . el ( "#noFlashCopyInput " , this . element ) ;
47
+ this . shareLinkTxt = $ . el ( "#shareLinkTxt " , this . element ) ;
48
+ this . shareWrap = $ . el ( ".share-wrap " , this . element ) ;
49
+ this . shareExpressionTxt = $ . el ( "#shareExpressionTxt" , this . element ) ;
50
+ this . sharePatternTxt = $ . el ( "#sharePatternTxt " , this . element ) ;
51
+ this . shareJavascriptTxt = $ . el ( "#shareJavascriptTxt " , this . element ) ;
57
52
58
- this . hasFlash = ! $ . isFirefox ( ) && ! $ . isIE ( ) && ! ZeroClipboard . state ( ) . flash . disabled ;
53
+ new Clipboard ( ".share-link-btn" ) . on ( "success" , this . _handleCopySuccess . bind ( this ) ) ;
54
+ new Clipboard ( ".share-expression-btn" ) . on ( "success" , this . _handleCopySuccess . bind ( this ) ) ;
55
+ new Clipboard ( ".share-javascript-btn" ) . on ( "success" , this . _handleCopySuccess . bind ( this ) ) ;
56
+ new Clipboard ( ".share-pattern-btn" ) . on ( "success" , this . _handleCopySuccess . bind ( this ) ) ;
59
57
60
- this . copyMessageView = $ . el ( "#copyMessageView" , this . element ) ;
61
-
62
- if ( this . hasFlash ) {
63
- var _this = this ;
64
- _this . initializeCopyLinks ( ) ;
65
- $ . addClass ( $ . el ( "#noFlashCopyText" , this . element ) , "hidden" ) ;
66
- } else {
67
- this . initializeNoFlashCopyLinks ( ) ;
68
- }
58
+ this . _successToolTip = new Tooltip ( $ . el ( ".share-link-btn" ) , "" , { mode : "custom" } ) ;
69
59
70
60
var copyKeyLabels = $ . els ( ".copyKeyLabel" , this . element ) ;
71
61
var copyKeyLabel = $ . getCtrlKey ( ) ;
@@ -74,47 +64,14 @@ p.initialize = function (element, docsView) {
74
64
}
75
65
} ;
76
66
77
- p . initializeNoFlashCopyLinks = function ( ) {
67
+ p . _handleCopySuccess = function ( event ) {
68
+ var rect = event . trigger . getBoundingClientRect ( ) ;
69
+ this . _successToolTip . show ( "Copied!" , rect ) ;
78
70
var _this = this ;
79
-
80
- $ . addClass ( $ . el ( "#shareCopyLink" , this . element ) , "hidden" ) ;
81
-
82
- this . createNoFlashCopyLink ( this . copyExpression , function ( ) {
83
- Tracking . event ( "share" , "copy" , "expression-noflash" ) ;
84
- return _this . docsView . getExpression ( ) ;
85
- } ) ;
86
-
87
- this . createNoFlashCopyLink ( this . copyPattern , function ( ) {
88
- Tracking . event ( "share" , "copy" , "pattern-noflash" ) ;
89
- return _this . docsView . getPattern ( ) ;
90
- } ) ;
91
-
92
- this . createNoFlashCopyLink ( this . copyJavascript , function ( ) {
93
- Tracking . event ( "share" , "copy" , "javascript-noflash" ) ;
94
- return _this . createJavascriptCopy ( ) ;
95
- } ) ;
96
- } ;
97
-
98
- p . createNoFlashCopyLink = function ( el , copyFunction ) {
99
- var _this = this ;
100
- el . onclick = function ( ) {
101
- var value = copyFunction ( ) ;
102
- var input = _this . noFlashCopyInput ;
103
-
104
- input . value = value ;
105
-
106
- $ . addCopyListener ( input , $ . bind ( _this , _this . handleExpressionCopied ) ) ;
107
-
108
- // Delay so the text actually selects
109
- setTimeout ( function ( ) {
110
- input . select ( ) ;
111
- input . focus ( ) ;
112
- } , 1 ) ;
113
-
114
- _this . hideFlyout ( _this . copyMessageView ) ;
115
- _this . showFlyout ( _this . noFlashCopyView ) ;
116
- }
117
- } ;
71
+ setTimeout ( function ( ) {
72
+ _this . _successToolTip . hide ( ) ;
73
+ } , 750 ) ;
74
+ }
118
75
119
76
p . handleExpressionCopied = function ( event ) {
120
77
var _this = this ;
@@ -128,34 +85,6 @@ p.handleSaveClick = function () {
128
85
this . docsView . showSave ( ) ;
129
86
} ;
130
87
131
- p . initializeCopyLinks = function ( ) {
132
- var _this = this ;
133
-
134
- this . createCopyLink ( this . copyLink , function ( event ) {
135
- var clipboard = event . clipboardData ;
136
- clipboard . setData ( "text/plain" , _this . shareLink . value ) ;
137
- Tracking . event ( "share" , "copy" , "share" ) ;
138
- } ) ;
139
-
140
- this . createCopyLink ( this . copyExpression , function ( event ) {
141
- var clipboard = event . clipboardData ;
142
- clipboard . setData ( "text/plain" , _this . docsView . getExpression ( ) ) ;
143
- Tracking . event ( "share" , "copy" , "expression" ) ;
144
- } ) ;
145
-
146
- this . createCopyLink ( this . copyPattern , function ( event ) {
147
- var clipboard = event . clipboardData ;
148
- clipboard . setData ( "text/plain" , _this . docsView . getPattern ( ) ) ;
149
- Tracking . event ( "share" , "copy" , "pattern" ) ;
150
- } ) ;
151
-
152
- this . createCopyLink ( this . copyJavascript , function ( event ) {
153
- var clipboard = event . clipboardData ;
154
- clipboard . setData ( "text/plain" , _this . createJavascriptCopy ( ) ) ;
155
- Tracking . event ( "share" , "copy" , "javascript" ) ;
156
- } ) ;
157
- } ;
158
-
159
88
p . createJavascriptCopy = function ( ) {
160
89
var pattern = this . docsView . getExpression ( ) ;
161
90
@@ -178,49 +107,28 @@ p.createCopyLink = function (el, dataFunc) {
178
107
} ( ) ;
179
108
} ;
180
109
181
- p . showFlyout = function ( el , time ) {
182
- $ . animate ( el , "information-default" , "information-show" ) ;
183
-
184
- if ( ! isNaN ( time ) ) {
185
- clearTimeout ( this . _toastInt ) ;
186
- var _this = this ;
187
- this . _toastInt = setTimeout ( function ( ) {
188
- _this . hideFlyout ( el ) ;
189
- } , time ) ;
190
- }
191
- } ;
192
-
193
- p . hideFlyout = function ( el ) {
194
- $ . removeClass ( el , "information-show" ) ;
195
- } ;
196
-
197
- p . handleCopyComplete = function ( event ) {
198
- this . showCopyCompleteFlyout ( event . data [ 'text/plain' ] ) ;
199
- } ;
200
-
201
- p . showCopyCompleteFlyout = function ( expression ) {
202
- $ . el ( "#copyTxt" , this . element ) . innerText = TextUtils . shorten ( expression , 31 ) ;
203
- this . showFlyout ( this . copyMessageView , 1500 ) ;
204
- }
205
-
206
110
p . show = function ( ) {
207
111
Tracking . event ( "share" , "show" ) ;
208
112
209
113
Utils . removeClass ( this . saveView , "visible hidden" ) ;
210
- Utils . removeClass ( this . shareLinkView , "visible hidden" ) ;
114
+ Utils . removeClass ( this . shareWrap , "visible hidden" ) ;
211
115
212
116
if ( ! ExpressionModel . id ) {
213
117
Utils . addClass ( this . saveView , "visible" ) ;
214
- Utils . addClass ( this . shareLinkView , "hidden" ) ;
118
+ Utils . addClass ( this . shareWrap , "hidden" ) ;
215
119
} else {
216
- this . shareLink . value = Utils . createURL ( $ . createID ( ExpressionModel . id ) ) ;
120
+ this . shareLinkTxt . value = Utils . createURL ( $ . createID ( ExpressionModel . id ) ) ;
217
121
Utils . addClass ( this . saveView , "hidden" ) ;
218
- Utils . addClass ( this . shareLinkView , "visible" ) ;
122
+ Utils . addClass ( this . shareWrap , "visible" ) ;
123
+
124
+ this . shareExpressionTxt . value = this . docsView . getExpression ( ) ;
125
+ this . sharePatternTxt . value = this . docsView . getPattern ( ) ;
126
+ this . shareJavascriptTxt . value = this . createJavascriptCopy ( ) ;
219
127
220
128
// This was failing in Edge, with this error: "Could not complete the operation due to error 800a025e."
221
129
try {
222
- this . shareLink . focus ( ) ;
223
- this . shareLink . select ( ) ;
130
+ // this.shareLink.focus();
131
+ // this.shareLink.select();
224
132
} catch ( err ) {
225
133
226
134
}
@@ -229,9 +137,6 @@ p.show = function () {
229
137
230
138
p . hide = function ( ) {
231
139
clearTimeout ( this . _toastInt ) ;
232
- this . hideFlyout ( this . noFlashCopyView ) ;
233
- this . hideFlyout ( this . copyMessageView ) ;
234
140
} ;
235
141
236
142
module . exports = ShareMenu ;
237
-
0 commit comments