copy_tuner_client 0.3.5 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 07fe56c9db1edad412f1af3596b85021fc96d485
4
- data.tar.gz: d8cff9d0621acebe92f9179102106cbb1b7ab371
3
+ metadata.gz: 4361ccce3ca459c59cce845b2dcd51fb3fdb4a80
4
+ data.tar.gz: cda2e1366b4a19985c97bff1e1d9cda1363e8074
5
5
  SHA512:
6
- metadata.gz: c675b1660904b2961660c6f1e18387cc15f663289b3d4cadd3f4a00104c25dd6927a3ecfb11410ebe8bd922a5e08c4dac166a26791363e895c354358014aba6f
7
- data.tar.gz: 9eb3a9e05e2b3919c0c8fc86bd65f0b5e75f30515b95388e8f3f296d8a4503ec10cd4ea2c5d7824464db6441819e6e5f4e583828c5b7733c017ec8f4b5acd097
6
+ metadata.gz: 192a9c5167a77aed0aaf0967b4ea7b27644ffebce0c38baf3606d339e9858c148213fd16bbd898f0b30f1656e98b4f697b2ae68d55cc7c98a6e2f8d9cf3ff22d
7
+ data.tar.gz: 28ecce1a14681689c2b2c9d19e3a66b67ac71ff41d2307b440774320636aea33e0c34f121bf3128db2b74a244f492cc7991bb5e0af4a36ac86b86ab4b54baee0
data/.gitignore CHANGED
@@ -18,3 +18,4 @@ pkg
18
18
  .bundle
19
19
  *.gemfile.lock
20
20
  .idea/
21
+ node_modules
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 0.4.0
2
+ - Remove jQuery dependency.
3
+
1
4
  ## 0.3.5
2
5
  - Support Rails 5.1
3
6
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- copy_tuner_client (0.3.5)
4
+ copy_tuner_client (0.4.0)
5
5
  i18n (>= 0.5.0)
6
6
  json
7
7
 
@@ -78,7 +78,7 @@ GEM
78
78
  activesupport (>= 4.1.0)
79
79
  hashdiff (0.3.2)
80
80
  i18n (0.8.1)
81
- json (2.0.4)
81
+ json (2.0.3)
82
82
  loofah (2.0.3)
83
83
  nokogiri (>= 1.5.9)
84
84
  mail (2.6.4)
@@ -0,0 +1,477 @@
1
+ // Generated by CoffeeScript 1.12.6
2
+ (function() {
3
+ var HIDDEN_CLASS, MAX_ZINDEX, getAllComments, getOffset, init, isMac, isVisible, util,
4
+ hasProp = {}.hasOwnProperty,
5
+ bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
6
+ extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
7
+
8
+ if (window.Copyray == null) {
9
+ window.Copyray = {};
10
+ }
11
+
12
+ MAX_ZINDEX = 2147483647;
13
+
14
+ HIDDEN_CLASS = 'copy-tuner-hidden';
15
+
16
+ isMac = navigator.platform.toUpperCase().indexOf('MAC') !== -1;
17
+
18
+ isVisible = function(element) {
19
+ return !!(element.offsetWidth || element.offsetHeight || element.getClientRects().length);
20
+ };
21
+
22
+ getOffset = function(elment) {
23
+ var box;
24
+ box = elment.getBoundingClientRect();
25
+ return {
26
+ top: box.top + window.pageYOffset - document.documentElement.clientTop,
27
+ left: box.left + window.pageXOffset - document.documentElement.clientLeft
28
+ };
29
+ };
30
+
31
+ Copyray.specimens = function() {
32
+ return Copyray.BlurbSpecimen.all;
33
+ };
34
+
35
+ Copyray.constructorInfo = function(constructor) {
36
+ var func, info, ref;
37
+ if (window.CopyrayPaths) {
38
+ ref = window.CopyrayPaths;
39
+ for (info in ref) {
40
+ if (!hasProp.call(ref, info)) continue;
41
+ func = ref[info];
42
+ if (func === constructor) {
43
+ return JSON.parse(info);
44
+ }
45
+ }
46
+ }
47
+ return null;
48
+ };
49
+
50
+ getAllComments = function(rootElement) {
51
+ var comments, curNode, filterNone, iterator;
52
+ filterNone = function() {
53
+ return NodeFilter.FILTER_ACCEPT;
54
+ };
55
+ comments = [];
56
+ iterator = document.createNodeIterator(rootElement, NodeFilter.SHOW_COMMENT, filterNone, false);
57
+ while ((curNode = iterator.nextNode())) {
58
+ comments.push(curNode);
59
+ }
60
+ return comments;
61
+ };
62
+
63
+ Copyray.findBlurbs = function() {
64
+ return util.bm('findBlurbs', function() {
65
+ var comments;
66
+ comments = getAllComments(document.body).filter(function(comment) {
67
+ return comment.nodeValue.startsWith('COPYRAY START');
68
+ });
69
+ return comments.forEach(function(comment) {
70
+ var _, blurbElement, el, id, path, ref, url;
71
+ ref = comment.nodeValue.match(/^COPYRAY START (\d+) (\S*) (\S*)/), _ = ref[0], id = ref[1], path = ref[2], url = ref[3];
72
+ blurbElement = null;
73
+ el = comment.nextSibling;
74
+ while (!(!el || (el.nodeType === Node.COMMENT_NODE && el.data === ("COPYRAY END " + id)))) {
75
+ if (el.nodeType === Node.ELEMENT_NODE && el.tagName !== 'SCRIPT') {
76
+ blurbElement = el;
77
+ break;
78
+ }
79
+ el = el.nextSibling;
80
+ }
81
+ if ((el != null ? el.nodeType : void 0) === Node.COMMENT_NODE) {
82
+ el.parentNode.removeChild(el);
83
+ }
84
+ comment.parentNode.removeChild(comment);
85
+ if (blurbElement) {
86
+ return Copyray.BlurbSpecimen.add(blurbElement, {
87
+ name: path.split('/').slice(-1)[0],
88
+ path: path,
89
+ url: url
90
+ });
91
+ }
92
+ });
93
+ });
94
+ };
95
+
96
+ Copyray.open = function(url) {
97
+ return window.open(url, null, 'width=700, height=600');
98
+ };
99
+
100
+ Copyray.show = function(type) {
101
+ if (type == null) {
102
+ type = null;
103
+ }
104
+ Copyray.Overlay.instance().show(type);
105
+ return Copyray.showBar();
106
+ };
107
+
108
+ Copyray.hide = function() {
109
+ Copyray.Overlay.instance().hide();
110
+ return Copyray.hideBar();
111
+ };
112
+
113
+ Copyray.addToggleButton = function() {
114
+ var element;
115
+ element = document.createElement('a');
116
+ element.addEventListener('click', function() {
117
+ return Copyray.show();
118
+ });
119
+ element.classList.add('copyray-toggle-button');
120
+ element.textContent = 'Open CopyTuner';
121
+ return document.body.appendChild(element);
122
+ };
123
+
124
+ Copyray.Specimen = (function() {
125
+ Specimen.add = function(el, info) {
126
+ if (info == null) {
127
+ info = {};
128
+ }
129
+ return this.all.push(new this(el, info));
130
+ };
131
+
132
+ Specimen.remove = function(el) {
133
+ var ref;
134
+ return (ref = this.find(el)) != null ? ref.remove() : void 0;
135
+ };
136
+
137
+ Specimen.find = function(el) {
138
+ var i, len, ref, specimen;
139
+ ref = this.all;
140
+ for (i = 0, len = ref.length; i < len; i++) {
141
+ specimen = ref[i];
142
+ if (specimen.el === el) {
143
+ return specimen;
144
+ }
145
+ }
146
+ return null;
147
+ };
148
+
149
+ Specimen.reset = function() {
150
+ return this.all = [];
151
+ };
152
+
153
+ function Specimen(el, info) {
154
+ if (info == null) {
155
+ info = {};
156
+ }
157
+ this.makeLabel = bind(this.makeLabel, this);
158
+ this.el = el;
159
+ this.name = info.name;
160
+ this.path = info.path;
161
+ this.url = info.url;
162
+ }
163
+
164
+ Specimen.prototype.remove = function() {
165
+ var idx;
166
+ idx = this.constructor.all.indexOf(this);
167
+ if (idx !== -1) {
168
+ return this.constructor.all.splice(idx, 1);
169
+ }
170
+ };
171
+
172
+ Specimen.prototype.makeBox = function() {
173
+ var key, ref, value;
174
+ this.bounds = util.computeBoundingBox([this.el]);
175
+ this.box = document.createElement('div');
176
+ this.box.classList.add('copyray-specimen');
177
+ this.box.classList.add(this.constructor.name);
178
+ ref = this.bounds;
179
+ for (key in ref) {
180
+ value = ref[key];
181
+ this.box.style[key] = value + "px";
182
+ }
183
+ if (getComputedStyle(this.el).position === 'fixed') {
184
+ this.box.css({
185
+ position: 'fixed',
186
+ top: getComputedStyle(this.el).top,
187
+ left: getComputedStyle(this.el).left
188
+ });
189
+ }
190
+ this.box.addEventListener('click', (function(_this) {
191
+ return function() {
192
+ return Copyray.open(_this.url + "/blurbs/" + _this.path + "/edit");
193
+ };
194
+ })(this));
195
+ return this.box.appendChild(this.makeLabel());
196
+ };
197
+
198
+ Specimen.prototype.makeLabel = function() {
199
+ var div;
200
+ div = document.createElement('div');
201
+ div.classList.add('copyray-specimen-handle');
202
+ div.classList.add(this.constructor.name);
203
+ div.textContent = this.name;
204
+ return div;
205
+ };
206
+
207
+ return Specimen;
208
+
209
+ })();
210
+
211
+ Copyray.BlurbSpecimen = (function(superClass) {
212
+ extend(BlurbSpecimen, superClass);
213
+
214
+ function BlurbSpecimen() {
215
+ return BlurbSpecimen.__super__.constructor.apply(this, arguments);
216
+ }
217
+
218
+ BlurbSpecimen.all = [];
219
+
220
+ return BlurbSpecimen;
221
+
222
+ })(Copyray.Specimen);
223
+
224
+ Copyray.Overlay = (function() {
225
+ Overlay.instance = function() {
226
+ return this.singletonInstance || (this.singletonInstance = new this);
227
+ };
228
+
229
+ function Overlay() {
230
+ Copyray.Overlay.singletonInstance = this;
231
+ this.overlay = document.createElement('div');
232
+ this.overlay.setAttribute('id', 'copyray-overlay');
233
+ this.shownBoxes = [];
234
+ this.overlay.addEventListener('click', (function(_this) {
235
+ return function() {
236
+ return _this.hide();
237
+ };
238
+ })(this));
239
+ }
240
+
241
+ Overlay.prototype.show = function(type) {
242
+ if (type == null) {
243
+ type = null;
244
+ }
245
+ this.reset();
246
+ Copyray.isShowing = true;
247
+ return util.bm('show', (function(_this) {
248
+ return function() {
249
+ var element, i, len, results, specimens;
250
+ if (!document.body.contains(_this.overlay)) {
251
+ document.body.appendChild(_this.overlay);
252
+ Copyray.findBlurbs();
253
+ specimens = Copyray.specimens();
254
+ }
255
+ results = [];
256
+ for (i = 0, len = specimens.length; i < len; i++) {
257
+ element = specimens[i];
258
+ element.makeBox();
259
+ element.box.style.zIndex = Math.ceil(MAX_ZINDEX * 0.9 + element.bounds.top + element.bounds.left);
260
+ _this.shownBoxes.push(element.box);
261
+ results.push(document.body.appendChild(element.box));
262
+ }
263
+ return results;
264
+ };
265
+ })(this));
266
+ };
267
+
268
+ Overlay.prototype.reset = function() {
269
+ var $box, i, len, ref;
270
+ ref = this.shownBoxes;
271
+ for (i = 0, len = ref.length; i < len; i++) {
272
+ $box = ref[i];
273
+ $box.remove();
274
+ }
275
+ return this.shownBoxes = [];
276
+ };
277
+
278
+ Overlay.prototype.hide = function() {
279
+ Copyray.isShowing = false;
280
+ this.overlay.remove();
281
+ this.reset();
282
+ return Copyray.hideBar();
283
+ };
284
+
285
+ return Overlay;
286
+
287
+ })();
288
+
289
+ util = {
290
+ bm: function(name, fn) {
291
+ var result, time;
292
+ time = new Date;
293
+ result = fn();
294
+ return result;
295
+ },
296
+ computeBoundingBox: function(elements) {
297
+ var boxFrame;
298
+ if (elements.length === 1 && elements[0].clientHeight) {
299
+ return util.computeBoundingBox(elements[0].children);
300
+ }
301
+ boxFrame = {
302
+ top: Number.POSITIVE_INFINITY,
303
+ left: Number.POSITIVE_INFINITY,
304
+ right: Number.NEGATIVE_INFINITY,
305
+ bottom: Number.NEGATIVE_INFINITY
306
+ };
307
+ elements.forEach(function(element) {
308
+ var frame;
309
+ if (!isVisible(element)) {
310
+ return;
311
+ }
312
+ frame = getOffset(element);
313
+ frame.right = frame.left + element.offsetWidth;
314
+ frame.bottom = frame.top + element.offsetHeight;
315
+ if (frame.top < boxFrame.top) {
316
+ boxFrame.top = frame.top;
317
+ }
318
+ if (frame.left < boxFrame.left) {
319
+ boxFrame.left = frame.left;
320
+ }
321
+ if (frame.right > boxFrame.right) {
322
+ boxFrame.right = frame.right;
323
+ }
324
+ if (frame.bottom > boxFrame.bottom) {
325
+ return boxFrame.bottom = frame.bottom;
326
+ }
327
+ });
328
+ return {
329
+ left: boxFrame.left,
330
+ top: boxFrame.top,
331
+ width: boxFrame.right - boxFrame.left,
332
+ height: boxFrame.bottom - boxFrame.top
333
+ };
334
+ }
335
+ };
336
+
337
+ Copyray.showBar = function() {
338
+ document.getElementById('copy-tuner-bar').classList.remove(HIDDEN_CLASS);
339
+ document.querySelector('.copyray-toggle-button').classList.add(HIDDEN_CLASS);
340
+ return Copyray.focusSearchBox();
341
+ };
342
+
343
+ Copyray.hideBar = function() {
344
+ document.getElementById('copy-tuner-bar').classList.add(HIDDEN_CLASS);
345
+ document.querySelector('.copyray-toggle-button').classList.remove(HIDDEN_CLASS);
346
+ return document.querySelector('.js-copy-tuner-bar-log-menu').classList.add(HIDDEN_CLASS);
347
+ };
348
+
349
+ Copyray.createLogMenu = function() {
350
+ var baseUrl, log, tbody;
351
+ tbody = document.querySelector('.js-copy-tuner-bar-log-menu__tbody.is-not-initialized');
352
+ if (!tbody) {
353
+ return;
354
+ }
355
+ tbody.classList.remove('is-not-initialized');
356
+ baseUrl = document.getElementById('copy-tuner-data').dataset.copyTunerUrl;
357
+ log = JSON.parse(document.getElementById('copy-tuner-data').dataset.copyTunerTranslationLog);
358
+ return Object.keys(log).sort().forEach(function(key) {
359
+ var td1, td2, tr, url, value;
360
+ value = log[key];
361
+ if (value === '') {
362
+ return;
363
+ }
364
+ url = baseUrl + "/blurbs/" + key + "/edit";
365
+ td1 = document.createElement('td');
366
+ td1.textContent = key;
367
+ td2 = document.createElement('td');
368
+ td2.textContent = value;
369
+ tr = document.createElement('tr');
370
+ tr.classList.add('copy-tuner-bar-log-menu__row');
371
+ tr.classList.add('js-copy-tuner-blurb-row');
372
+ tr.dataset.url = url;
373
+ tr.addEventListener('click', function(arg) {
374
+ var currentTarget;
375
+ currentTarget = arg.currentTarget;
376
+ return Copyray.open(currentTarget.dataset.url);
377
+ });
378
+ tr.appendChild(td1);
379
+ tr.appendChild(td2);
380
+ return tbody.appendChild(tr);
381
+ });
382
+ };
383
+
384
+ Copyray.focusSearchBox = function() {
385
+ return document.querySelector('.js-copy-tuner-bar-search').focus();
386
+ };
387
+
388
+ Copyray.toggleLogMenu = function() {
389
+ Copyray.createLogMenu();
390
+ return document.getElementById('copy-tuner-bar-log-menu').classList.toggle(HIDDEN_CLASS);
391
+ };
392
+
393
+ Copyray.setupLogMenu = function() {
394
+ var element;
395
+ element = document.querySelector('.js-copy-tuner-bar-open-log');
396
+ return element.addEventListener('click', function(event) {
397
+ event.preventDefault();
398
+ return Copyray.toggleLogMenu();
399
+ });
400
+ };
401
+
402
+ Copyray.setupSearchBar = function() {
403
+ var barElement, lastKeyword, timer;
404
+ timer = null;
405
+ lastKeyword = '';
406
+ barElement = document.querySelector('.js-copy-tuner-bar-search');
407
+ barElement.addEventListener('focus', function(arg) {
408
+ var target;
409
+ target = arg.target;
410
+ return lastKeyword = target.value;
411
+ });
412
+ return barElement.addEventListener('keyup', function(arg) {
413
+ var keyword, target;
414
+ target = arg.target;
415
+ keyword = target.value.trim();
416
+ if (lastKeyword !== keyword) {
417
+ if (!isVisible(document.getElementById('copy-tuner-bar-log-menu'))) {
418
+ Copyray.toggleLogMenu();
419
+ }
420
+ clearTimeout(timer);
421
+ timer = setTimeout(function() {
422
+ var rows;
423
+ rows = Array.from(document.getElementsByClassName('js-copy-tuner-blurb-row'));
424
+ if (keyword === '') {
425
+ return rows.forEach(function(row) {
426
+ return row.classList.remove(HIDDEN_CLASS);
427
+ });
428
+ } else {
429
+ rows.forEach(function(row) {
430
+ return row.classList.add(HIDDEN_CLASS);
431
+ });
432
+ return rows.filter(function(row) {
433
+ return Array.from(row.getElementsByTagName('td')).some(function(td) {
434
+ return td.textContent.includes(keyword);
435
+ });
436
+ }).forEach(function(row) {
437
+ return row.classList.remove(HIDDEN_CLASS);
438
+ });
439
+ }
440
+ }, 500);
441
+ return lastKeyword = keyword;
442
+ }
443
+ });
444
+ };
445
+
446
+ init = function() {
447
+ if (Copyray.initialized) {
448
+ return;
449
+ }
450
+ Copyray.initialized = true;
451
+ document.addEventListener('keydown', function(event) {
452
+ if ((isMac && event.metaKey || !isMac && event.ctrlKey) && event.shiftKey && event.keyCode === 75) {
453
+ if (Copyray.isShowing) {
454
+ Copyray.hide();
455
+ } else {
456
+ Copyray.show();
457
+ }
458
+ }
459
+ if (Copyray.isShowing && event.keyCode === 27) {
460
+ return Copyray.hide();
461
+ }
462
+ });
463
+ new Copyray.Overlay;
464
+ Copyray.findBlurbs();
465
+ Copyray.addToggleButton();
466
+ Copyray.setupSearchBar();
467
+ Copyray.setupLogMenu();
468
+ return typeof console !== "undefined" && console !== null ? console.log("Ready to Copyray. Press " + (isMac ? 'cmd+shift+k' : 'ctrl+shift+k') + " to scan your UI.") : void 0;
469
+ };
470
+
471
+ if (document.readyState === 'complete' || document.readyState !== 'loading') {
472
+ init();
473
+ } else {
474
+ document.addEventListener('DOMContentLoaded', init);
475
+ }
476
+
477
+ }).call(this);