Skip to content

Commit f4ce225

Browse files
committed
Switched to use clipboardjs.
1 parent b43727a commit f4ce225

File tree

7 files changed

+84
-170
lines changed

7 files changed

+84
-170
lines changed

assets/ZeroClipboard.swf

-6.43 KB
Binary file not shown.

index.html

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -234,36 +234,46 @@ <h1 class="tool-label"></h1>
234234
</div>
235235

236236
<div class="menu share">
237-
<header>
238-
Share
239-
</header>
240-
<hr />
241-
<div id="shareLinkView">
242-
<input type="text" id="shareLinkTxt">
243-
<a id="shareCopyLink">Copy Link<br/><br/></a>
244-
<p id="noFlashCopyText">Press <span class="copyKeyLabel">Ctrl</span>+C to copy your link.</p>
245-
</div>
246237
<div id="savePrompt">
247238
<p><a id="showSaveLink">Save</a> your pattern before sharing.</p>
248239
</div>
249-
<header>Copy</header>
250-
<hr />
251-
<a id="copyExpression">Expression</a>
252-
|
253-
<a id="copyPattern">Pattern</a>
254-
|
255-
<a id="copyJavascript">Javascript</a>
256-
<div id="copyMessageView" class="hidden">
257-
<hr />
258-
<code id="copyTxt"></code>
259-
Copied to clipboard.
260-
</div>
261240

262-
<div id="noFlashCopyView" class="hidden">
263-
<hr />
264-
<input id="noFlashCopyInput" type="text"><br/>
265-
Press <span class="copyKeyLabel">dynamic</span>-C to copy.
266-
</div>
241+
<div class="share-wrap">
242+
<header>
243+
Share
244+
</header>
245+
<hr />
246+
<div id="shareLinkView" class="share-wrap">
247+
<input type="text" id="shareLinkTxt" readonly>
248+
<div data-clipboard-target="#shareLinkTxt" class="icon share-link-btn">&#xE603;</div>
249+
</div>
250+
<header>
251+
Expression
252+
</header>
253+
<hr />
254+
<div id="shareExpressionView" class="share-wrap">
255+
<input type="text" id="shareExpressionTxt" readonly>
256+
<div class="icon share-expression-btn" data-clipboard-target="#shareExpressionTxt">&#xE603;</div>
257+
</div>
258+
259+
<header>
260+
Pattern
261+
</header>
262+
<hr />
263+
<div id="sharePatternView" class="share-wrap">
264+
<input type="text" id="sharePatternTxt" readonly>
265+
<div class="icon share-pattern-btn" data-clipboard-target="#sharePatternTxt">&#xE603;</div>
266+
</div>
267+
268+
<header>
269+
Javascript
270+
</header>
271+
<hr />
272+
<div id="shareJavascriptView" class="share-wrap">
273+
<input type="text" id="shareJavascriptTxt" readonly>
274+
<div class="icon share-javascript-btn" data-clipboard-target="#shareJavascriptTxt">&#xE603;</div>
275+
</div>
276+
</div>
267277
</div>
268278

269279
<div class="menu save">
@@ -365,11 +375,6 @@ <h1 class="regexr-text">RegExr</h1><span class="version regexr-text">v2.1</span>
365375
if (!$.isSupported()) {
366376
el = document.querySelector(".not-supported");
367377
$.removeClass(el, "hidden");
368-
369-
if (!ZeroClipboard.state().flash.disabled) {
370-
var flash = document.getElementsByClassName('flash')[0];
371-
flash.className = "";
372-
}
373378
} else if($.partialSupport()) {
374379
el = document.querySelector(".not-supported-mobile");
375380
$.removeClass(el, "hidden");

js/RegExr.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ require('classlist-polyfill');
77
require('./third-party/history.adapter.native.js');
88
require('./third-party/history.js');
99

10-
window.ZeroClipboard = require('zeroclipboard');
11-
1210
// Import some classes into a shared object, for use in the index.template.js
1311
var Utils = require('./utils/Utils');
1412
window.$ = RegExrShared.Utils = Utils;

js/index.template.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,6 @@
5151
$.removeClass($.el(".beta-banner"), "hidden");
5252
}
5353

54-
// Setup our copy functionality.
55-
ZeroClipboard.config(
56-
{
57-
swfPath: "assets/ZeroClipboard.swf",
58-
cacheBust: false,
59-
forceHandCursor: true,
60-
hoverClass: 'a-hover'
61-
}
62-
);
63-
6454
RegExrShared.List.spinner = $.el(".spinner");
6555

6656
var docView = new RegExrShared.DocView($.el("#docview"));

js/views/ShareMenu.js

Lines changed: 29 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ var Tracking = require('../Tracking');
2626
var TextUtils = require('../utils/TextUtils');
2727
var Utils = require('../utils/Utils');
2828
var ExpressionModel = require('../net/ExpressionModel');
29-
var ZeroClipboard = require('zeroclipboard');
29+
var Clipboard = require('clipboard');
30+
var Tooltip = require('../controls/Tooltip');
3031

3132
var ShareMenu = function (element, docsView) {
3233
this.initialize(element, docsView);
@@ -40,32 +41,21 @@ p.initialize = function (element, docsView) {
4041
this.docsView = docsView;
4142
this.element = element;
4243

43-
this.shareLink = $.el("#shareLinkTxt", this.element);
44-
this.copyLink = $.el("#shareCopyLink", this.element);
4544
this.showSaveLink = $.el("#showSaveLink", this.element);
46-
this.copyExpression = $.el("#copyExpression", this.element);
47-
this.copyPattern = $.el("#copyPattern", this.element);
48-
4945
this.showSaveLink.onclick = $.bind(this, this.handleSaveClick);
50-
5146
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);
5752

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));
5957

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"});
6959

7060
var copyKeyLabels = $.els(".copyKeyLabel", this.element);
7161
var copyKeyLabel = $.getCtrlKey();
@@ -74,47 +64,14 @@ p.initialize = function (element, docsView) {
7464
}
7565
};
7666

77-
p.initializeNoFlashCopyLinks = function () {
67+
p._handleCopySuccess = function(event) {
68+
var rect = event.trigger.getBoundingClientRect();
69+
this._successToolTip.show("Copied!", rect);
7870
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+
}
11875

11976
p.handleExpressionCopied = function (event) {
12077
var _this = this;
@@ -128,34 +85,6 @@ p.handleSaveClick = function () {
12885
this.docsView.showSave();
12986
};
13087

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-
15988
p.createJavascriptCopy = function () {
16089
var pattern = this.docsView.getExpression();
16190

@@ -178,49 +107,28 @@ p.createCopyLink = function (el, dataFunc) {
178107
}();
179108
};
180109

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-
206110
p.show = function () {
207111
Tracking.event("share", "show");
208112

209113
Utils.removeClass(this.saveView, "visible hidden");
210-
Utils.removeClass(this.shareLinkView, "visible hidden");
114+
Utils.removeClass(this.shareWrap, "visible hidden");
211115

212116
if (!ExpressionModel.id) {
213117
Utils.addClass(this.saveView, "visible");
214-
Utils.addClass(this.shareLinkView, "hidden");
118+
Utils.addClass(this.shareWrap, "hidden");
215119
} else {
216-
this.shareLink.value = Utils.createURL($.createID(ExpressionModel.id));
120+
this.shareLinkTxt.value = Utils.createURL($.createID(ExpressionModel.id));
217121
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();
219127

220128
// This was failing in Edge, with this error: "Could not complete the operation due to error 800a025e."
221129
try {
222-
this.shareLink.focus();
223-
this.shareLink.select();
130+
// this.shareLink.focus();
131+
//this.shareLink.select();
224132
} catch (err) {
225133

226134
}
@@ -229,9 +137,6 @@ p.show = function () {
229137

230138
p.hide = function () {
231139
clearTimeout(this._toastInt);
232-
this.hideFlyout(this.noFlashCopyView);
233-
this.hideFlyout(this.copyMessageView);
234140
};
235141

236142
module.exports = ShareMenu;
237-

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@
2929
"engine": "node >= 4.2.2",
3030
"dependencies": {
3131
"classlist-polyfill": "^1.0.2",
32-
"codemirror": "^5.8.0",
32+
"clipboard": "^1.5.5",
33+
"codemirror": "^5.10.0",
3334
"es6-promise": "^3.0.2",
3435
"placeholders.js": "^3.0.2",
35-
"store": "^1.3.17",
36-
"zeroclipboard": "^2.2.0"
36+
"store": "^1.3.20"
3737
}
3838
}

scss/menus.scss

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,22 @@
5050
top: -1px;
5151
}
5252

53+
input[type="text"] {
54+
@include calc("width", "100% - 0.375em*6");
55+
float: left;
56+
}
57+
58+
.share-wrap {
59+
@include calc("width", "0.375em*36");
60+
}
61+
62+
.icon {
63+
@include calc("padding-top", "0.375em*2");
64+
@include calc("padding-left", "100% - 0.375em*3");
65+
@include calc("width", "100% - 0.375em*6");
66+
cursor: pointer;
67+
}
68+
5369
.update-button {
5470
position: absolute;
5571
}

0 commit comments

Comments
 (0)