Skip to content

Commit 847c3b8

Browse files
committed
- Moved the getStateHash call into DocView
- state hash now uses only the values of the CM instances. - Style fixes for the Share menu
1 parent 050d03f commit 847c3b8

File tree

5 files changed

+52
-61
lines changed

5 files changed

+52
-61
lines changed

index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,8 @@ <h1 class="tool-label"></h1>
247247
<input type="text" id="shareLinkTxt" readonly>
248248
<div data-clipboard-target="#shareLinkTxt" class="icon share-link-btn">&#xE603;</div>
249249
</div>
250+
</div>
251+
250252
<header>
251253
Expression
252254
</header>
@@ -274,7 +276,6 @@ <h1 class="tool-label"></h1>
274276
<div class="icon share-javascript-btn" data-clipboard-target="#shareJavascriptTxt">&#xE603;</div>
275277
</div>
276278
</div>
277-
</div>
278279

279280
<div class="menu save">
280281
<header>

js/net/ExpressionModel.js

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
var EventDispatcher = require('../events/EventDispatcher');
2626
var ServerModel = require('./ServerModel');
2727
var Settings = require('../Settings');
28-
var Utils = require('../utils/Utils');
2928

3029
var s = {};
3130
EventDispatcher.initialize(s);
@@ -45,12 +44,12 @@ s.savePattern = function (tags, name, pattern, content, replace, description, au
4544
};
4645

4746
s.saveState = function () {
48-
s._saveState = s.getStateHash();
47+
s._saveState = s.docView.getStateHash();
4948
s._lastId = null;
5049
};
5150

5251
s.isDirty = function () {
53-
var dirty = s._saveState !== s.getStateHash();
52+
var dirty = s._saveState !== s.docView.getStateHash();
5453
if (dirty && s.id) {
5554
s._lastId = s.id;
5655
s.id = null;
@@ -61,14 +60,6 @@ s.isDirty = function () {
6160
return dirty;
6261
};
6362

64-
s.getStateHash = function () {
65-
var state =
66-
s.docView.getExpression() +
67-
s.docView.getText() +
68-
JSON.stringify(s.docView.getState());
69-
return Utils.getHashCode(state);
70-
};
71-
7263
s.handleSaveSuccess = function (result) {
7364
s.saveState();
7465

js/views/DocView.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ var Tracking = require('../Tracking');
3737
var RegExLexer = require('../RegExLexer');
3838
var BrowserHistory = require('../BrowserHistory');
3939
var SubstLexer = require('../SubstLexer');
40+
var Utils = require('../utils/Utils');
4041

4142
var Docs = require('../utils/Docs');
4243
var Graph = require('../utils/Graph');
@@ -385,6 +386,15 @@ p.getState = function () {
385386
return state;
386387
};
387388

389+
p.getStateHash = function() {
390+
return Utils.getHashCode(
391+
this.getExpression() +
392+
this.getText() +
393+
this.replaceCM.getValue() +
394+
this.listCM.getValue()
395+
);
396+
}
397+
388398
p.showSave = function () {
389399
this.saveTooltip.show();
390400
};

js/views/ShareMenu.js

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -119,47 +119,28 @@ p.createJavascriptCopy = function () {
119119
}
120120
};
121121

122-
p.createCopyLink = function (el, dataFunc) {
123-
var _this = this;
124-
return function () {
125-
var client = new ZeroClipboard(el);
126-
client.on('ready', function (event) {
127-
client.on("copy", dataFunc);
128-
client.on("aftercopy", $.bind(_this, _this.handleCopyComplete));
129-
});
130-
}();
131-
};
132-
133122
p.show = function () {
134123
Tracking.event("share", "show");
135124

136125
Utils.removeClass(this.saveView, "visible hidden");
137126
Utils.removeClass(this.shareWrap, "visible hidden");
138127

128+
this.shareExpressionTxt.value = this.docsView.getExpression();
129+
this.sharePatternTxt.value = this.docsView.getPattern();
130+
this.shareJavascriptTxt.value = this.createJavascriptCopy();
131+
139132
if (!ExpressionModel.id) {
140133
Utils.addClass(this.saveView, "visible");
141134
Utils.addClass(this.shareWrap, "hidden");
142135
} else {
143136
this.shareLinkTxt.value = Utils.createURL($.createID(ExpressionModel.id));
144137
Utils.addClass(this.saveView, "hidden");
145138
Utils.addClass(this.shareWrap, "visible");
146-
147-
this.shareExpressionTxt.value = this.docsView.getExpression();
148-
this.sharePatternTxt.value = this.docsView.getPattern();
149-
this.shareJavascriptTxt.value = this.createJavascriptCopy();
150-
151-
// This was failing in Edge, with this error: "Could not complete the operation due to error 800a025e."
152-
try {
153-
// this.shareLink.focus();
154-
//this.shareLink.select();
155-
} catch (err) {
156-
157-
}
158139
}
159140
};
160141

161142
p.hide = function () {
162-
clearTimeout(this._toastInt);
143+
163144
};
164145

165146
module.exports = ShareMenu;

scss/menus.scss

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,38 @@
1616
min-width: 10rem;
1717
}
1818

19+
&.share {
20+
min-width: 200px;
21+
22+
input[type="text"] {
23+
@include calc("width", "100% - 0.375em*6");
24+
float: left;
25+
}
26+
27+
#savePrompt > p {
28+
@include calc("margin-bottom", "-0.375em");
29+
}
30+
31+
header:not(:first-child) {
32+
@include calc("padding-top", "0.375em*4");
33+
}
34+
35+
.public-wrap {
36+
padding-top: .5rem;
37+
}
38+
39+
.share-wrap {
40+
width: 100%;
41+
}
42+
43+
.icon {
44+
@include calc("padding-top", "0.375em*2");
45+
@include calc("padding-left", "100% - 0.375em*3");
46+
@include calc("width", "100% - 0.375em*6");
47+
cursor: pointer;
48+
}
49+
}
50+
1951
&.save, &.share {
2052
label {
2153
display: inline-block;
@@ -36,14 +68,6 @@
3668
}
3769
}
3870

39-
header:not(:first-child) {
40-
@include calc("padding-top", "0.375em*4");
41-
}
42-
43-
.public-wrap {
44-
padding-top: .5rem;
45-
}
46-
4771
input[type="checkbox"] {
4872
width: 13px;
4973
height: 13px;
@@ -54,22 +78,6 @@
5478
top: -1px;
5579
}
5680

57-
input[type="text"] {
58-
@include calc("width", "100% - 0.375em*6");
59-
float: left;
60-
}
61-
62-
.share-wrap {
63-
@include calc("width", "0.375em*36");
64-
}
65-
66-
.icon {
67-
@include calc("padding-top", "0.375em*2");
68-
@include calc("padding-left", "100% - 0.375em*3");
69-
@include calc("width", "100% - 0.375em*6");
70-
cursor: pointer;
71-
}
72-
7381
.update-button {
7482
position: absolute;
7583
}
@@ -79,7 +87,7 @@
7987
float: left;
8088
padding-top: 0rem;
8189

82-
height: 0.0;
90+
height: 0;
8391
@include vendor-prefix(transition, height $default-transition-duration);
8492
}
8593

0 commit comments

Comments
 (0)