smalruby-editor 0.0.11 → 0.0.12

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of smalruby-editor might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c69e2a88e97ff7653534ce1a531162647e698b2a
4
- data.tar.gz: b452e1815cc8320ec63e761b6cda8edeb1db1b57
3
+ metadata.gz: b37c640353e2bd15d4b820cdc21bbd89ad3e8cb2
4
+ data.tar.gz: 6101e70c546314f4b878cb621a92b0c1dd2df654
5
5
  SHA512:
6
- metadata.gz: a964c4d0563850e93a14b96a7a345682ce19daeeca42b53eb6a47f017c3df279aabb255936b08ca0dc0b6074869a92e28267f13df345b25a32c094951445ca38
7
- data.tar.gz: 9f1535ed24a5ecd35a2f0a9dda7bb2779e023cd04476dd52227c4823dd69c0afe6b1fc118dc0bcc156c03d1af6a1227bd7a33a1c6e7213146deb36b305a75dfb
6
+ metadata.gz: 43da2382861dc2b6fd3166e605e7ba7fe1f25331c4bc86791a194ef616c0d29f93f4b9fe01b011b6203c3e7f04820a73ddc6752f233f42b27da08e3569d62254
7
+ data.tar.gz: f3646f30ca01d17ffea8584bd36c29a972089b45a7f33e81c3d221b4d6ab07db0ccfc0e9baa522b93c91e7f7afdad8528d13a78e99a1b98fc37b50e215be39fb
@@ -19,7 +19,7 @@ errorMessage = (msg, selector = '#messages') ->
19
19
  .append('<h4><i class="icon-exclamation-sign"></i>エラー</h4>')
20
20
  .append(msg)
21
21
  $(selector).append(html)
22
- html.fadeIn('fast')
22
+ html.fadeIn('slow')
23
23
 
24
24
  $ ->
25
25
  saving = false
@@ -47,7 +47,6 @@ $ ->
47
47
  $('#filename').focus()
48
48
  else
49
49
  afterSave = ->
50
- saving = true
51
50
  changed = false
52
51
  successMessage('セーブしました')
53
52
 
@@ -84,19 +83,21 @@ $ ->
84
83
  type: 'DELETE'
85
84
  dataType: 'json'
86
85
  success: (data, textStatus, jqXHR) ->
87
- if data.source_code.error && confirm("前に#{filename}という名前でセーブしているけど本当にセーブしますか?\nセーブすると前に作成したプログラムは消えてしまうよ!")
88
- $.ajax
89
- url: '/source_codes/write'
90
- type: 'DELETE'
91
- data:
92
- force: true
93
- dataType: 'json'
94
- success: (data, textStatus, jqXHR) ->
95
- afterSave()
86
+ if data.source_code.error
87
+ if confirm("前に#{filename}という名前でセーブしているけど本当にセーブしますか?\nセーブすると前に作成したプログラムは消えてしまうよ!")
88
+ $.ajax
89
+ url: '/source_codes/write?force=1'
90
+ type: 'DELETE'
91
+ dataType: 'json'
92
+ success: (data, textStatus, jqXHR) ->
93
+ afterSave()
94
+ else
95
+ successMessage('セーブをキャンセルしました')
96
96
  else
97
97
  afterSave()
98
98
  <% else %>
99
99
  afterSave()
100
+ saving = true
100
101
  $('#download-link').click()
101
102
  <% end %>
102
103
 
@@ -1,3 +1,3 @@
1
1
  module SmalrubyEditor
2
- VERSION = '0.0.11'
2
+ VERSION = '0.0.12'
3
3
  end
@@ -396,49 +396,78 @@
396
396
 
397
397
  })( jQuery );
398
398
  (function() {
399
- var CSRFToken, anchoredLink, browserCompatibleDocumentParser, browserIsntBuggy, browserSupportsPushState, cacheCurrentPage, cacheSize, changePage, constrainPageCacheTo, createDocument, crossOriginLink, currentState, executeScriptTags, extractLink, extractTitleAndBody, fetchHistory, fetchReplacement, handleClick, ignoreClick, initializeTurbolinks, installClickHandlerLast, loadedAssets, noTurbolink, nonHtmlLink, nonStandardClick, pageCache, pageChangePrevented, pagesCached, processResponse, recallScrollPosition, referer, reflectNewUrl, reflectRedirectedUrl, rememberCurrentState, rememberCurrentUrl, removeHash, removeNoscriptTags, requestMethod, requestMethodIsSafe, resetScrollPosition, targetLink, triggerEvent, visit, xhr, _ref,
400
- __hasProp = {}.hasOwnProperty,
401
- __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
399
+ var CSRFToken, allowLinkExtensions, anchoredLink, browserCompatibleDocumentParser, browserIsntBuggy, browserSupportsCustomEvents, browserSupportsPushState, browserSupportsTurbolinks, cacheCurrentPage, cacheSize, changePage, constrainPageCacheTo, createDocument, crossOriginLink, currentState, enableTransitionCache, executeScriptTags, extractLink, extractTitleAndBody, fetch, fetchHistory, fetchReplacement, handleClick, historyStateIsDefined, htmlExtensions, ignoreClick, initializeTurbolinks, installClickHandlerLast, installDocumentReadyPageEventTriggers, installHistoryChangeHandler, installJqueryAjaxSuccessPageUpdateTrigger, loadedAssets, noTurbolink, nonHtmlLink, nonStandardClick, pageCache, pageChangePrevented, pagesCached, popCookie, processResponse, recallScrollPosition, referer, reflectNewUrl, reflectRedirectedUrl, rememberCurrentState, rememberCurrentUrl, rememberReferer, removeHash, removeHashForIE10compatiblity, removeNoscriptTags, requestMethodIsSafe, resetScrollPosition, targetLink, transitionCacheEnabled, transitionCacheFor, triggerEvent, visit, xhr, _ref,
400
+ __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; },
401
+ __slice = [].slice;
402
+
403
+ pageCache = {};
402
404
 
403
405
  cacheSize = 10;
404
406
 
405
- currentState = null;
407
+ transitionCacheEnabled = false;
406
408
 
407
- referer = null;
409
+ currentState = null;
408
410
 
409
411
  loadedAssets = null;
410
412
 
411
- pageCache = {};
413
+ htmlExtensions = ['html'];
412
414
 
413
- createDocument = null;
415
+ referer = null;
414
416
 
415
- requestMethod = ((_ref = document.cookie.match(/request_method=(\w+)/)) != null ? _ref[1].toUpperCase() : void 0) || '';
417
+ createDocument = null;
416
418
 
417
419
  xhr = null;
418
420
 
419
- fetchReplacement = function(url) {
420
- var safeUrl;
421
- triggerEvent('page:fetch');
422
- safeUrl = removeHash(url);
421
+ fetch = function(url) {
422
+ var cachedPage;
423
+ rememberReferer();
424
+ cacheCurrentPage();
425
+ reflectNewUrl(url);
426
+ if (transitionCacheEnabled && (cachedPage = transitionCacheFor(url))) {
427
+ fetchHistory(cachedPage);
428
+ return fetchReplacement(url);
429
+ } else {
430
+ return fetchReplacement(url, resetScrollPosition);
431
+ }
432
+ };
433
+
434
+ transitionCacheFor = function(url) {
435
+ var cachedPage;
436
+ cachedPage = pageCache[url];
437
+ if (cachedPage && !cachedPage.transitionCacheDisabled) {
438
+ return cachedPage;
439
+ }
440
+ };
441
+
442
+ enableTransitionCache = function(enable) {
443
+ if (enable == null) {
444
+ enable = true;
445
+ }
446
+ return transitionCacheEnabled = enable;
447
+ };
448
+
449
+ fetchReplacement = function(url, onLoadFunction) {
450
+ var _this = this;
451
+ if (onLoadFunction == null) {
452
+ onLoadFunction = function() {};
453
+ }
454
+ triggerEvent('page:fetch', {
455
+ url: url
456
+ });
423
457
  if (xhr != null) {
424
458
  xhr.abort();
425
459
  }
426
460
  xhr = new XMLHttpRequest;
427
- xhr.open('GET', safeUrl, true);
461
+ xhr.open('GET', removeHashForIE10compatiblity(url), true);
428
462
  xhr.setRequestHeader('Accept', 'text/html, application/xhtml+xml, application/xml');
429
463
  xhr.setRequestHeader('X-XHR-Referer', referer);
430
464
  xhr.onload = function() {
431
465
  var doc;
432
466
  triggerEvent('page:receive');
433
467
  if (doc = processResponse()) {
434
- reflectNewUrl(url);
435
468
  changePage.apply(null, extractTitleAndBody(doc));
436
469
  reflectRedirectedUrl();
437
- if (document.location.hash) {
438
- document.location.href = document.location.href;
439
- } else {
440
- resetScrollPosition();
441
- }
470
+ onLoadFunction();
442
471
  return triggerEvent('page:load');
443
472
  } else {
444
473
  return document.location.href = url;
@@ -447,34 +476,30 @@
447
476
  xhr.onloadend = function() {
448
477
  return xhr = null;
449
478
  };
450
- xhr.onabort = function() {
451
- return rememberCurrentUrl();
452
- };
453
479
  xhr.onerror = function() {
454
480
  return document.location.href = url;
455
481
  };
456
482
  return xhr.send();
457
483
  };
458
484
 
459
- fetchHistory = function(position) {
460
- var page;
461
- cacheCurrentPage();
462
- page = pageCache[position];
485
+ fetchHistory = function(cachedPage) {
463
486
  if (xhr != null) {
464
487
  xhr.abort();
465
488
  }
466
- changePage(page.title, page.body);
467
- recallScrollPosition(page);
489
+ changePage(cachedPage.title, cachedPage.body);
490
+ recallScrollPosition(cachedPage);
468
491
  return triggerEvent('page:restore');
469
492
  };
470
493
 
471
494
  cacheCurrentPage = function() {
472
- pageCache[currentState.position] = {
495
+ pageCache[currentState.url] = {
473
496
  url: document.location.href,
474
497
  body: document.body,
475
498
  title: document.title,
476
499
  positionY: window.pageYOffset,
477
- positionX: window.pageXOffset
500
+ positionX: window.pageXOffset,
501
+ cachedAt: new Date().getTime(),
502
+ transitionCacheDisabled: document.querySelector('[data-no-transition-cache]') != null
478
503
  };
479
504
  return constrainPageCacheTo(cacheSize);
480
505
  };
@@ -489,14 +514,23 @@
489
514
  };
490
515
 
491
516
  constrainPageCacheTo = function(limit) {
492
- var key, value;
493
- for (key in pageCache) {
494
- if (!__hasProp.call(pageCache, key)) continue;
495
- value = pageCache[key];
496
- if (key <= currentState.position - limit) {
497
- pageCache[key] = null;
517
+ var cacheTimesRecentFirst, key, pageCacheKeys, _i, _len, _results;
518
+ pageCacheKeys = Object.keys(pageCache);
519
+ cacheTimesRecentFirst = pageCacheKeys.map(function(url) {
520
+ return pageCache[url].cachedAt;
521
+ }).sort(function(a, b) {
522
+ return b - a;
523
+ });
524
+ _results = [];
525
+ for (_i = 0, _len = pageCacheKeys.length; _i < _len; _i++) {
526
+ key = pageCacheKeys[_i];
527
+ if (!(pageCache[key].cachedAt <= cacheTimesRecentFirst[limit])) {
528
+ continue;
498
529
  }
530
+ triggerEvent('page:expire', pageCache[key]);
531
+ _results.push(delete pageCache[key]);
499
532
  }
533
+ return _results;
500
534
  };
501
535
 
502
536
  changePage = function(title, body, csrfToken, runScripts) {
@@ -505,26 +539,26 @@
505
539
  if (csrfToken != null) {
506
540
  CSRFToken.update(csrfToken);
507
541
  }
508
- removeNoscriptTags();
509
542
  if (runScripts) {
510
543
  executeScriptTags();
511
544
  }
512
545
  currentState = window.history.state;
513
- return triggerEvent('page:change');
546
+ triggerEvent('page:change');
547
+ return triggerEvent('page:update');
514
548
  };
515
549
 
516
550
  executeScriptTags = function() {
517
- var attr, copy, nextSibling, parentNode, script, scripts, _i, _j, _len, _len1, _ref1, _ref2;
551
+ var attr, copy, nextSibling, parentNode, script, scripts, _i, _j, _len, _len1, _ref, _ref1;
518
552
  scripts = Array.prototype.slice.call(document.body.querySelectorAll('script:not([data-turbolinks-eval="false"])'));
519
553
  for (_i = 0, _len = scripts.length; _i < _len; _i++) {
520
554
  script = scripts[_i];
521
- if (!((_ref1 = script.type) === '' || _ref1 === 'text/javascript')) {
555
+ if (!((_ref = script.type) === '' || _ref === 'text/javascript')) {
522
556
  continue;
523
557
  }
524
558
  copy = document.createElement('script');
525
- _ref2 = script.attributes;
526
- for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) {
527
- attr = _ref2[_j];
559
+ _ref1 = script.attributes;
560
+ for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
561
+ attr = _ref1[_j];
528
562
  copy.setAttribute(attr.name, attr.value);
529
563
  }
530
564
  copy.appendChild(document.createTextNode(script.innerHTML));
@@ -534,20 +568,16 @@
534
568
  }
535
569
  };
536
570
 
537
- removeNoscriptTags = function() {
538
- var noscript, noscriptTags, _i, _len;
539
- noscriptTags = Array.prototype.slice.call(document.body.getElementsByTagName('noscript'));
540
- for (_i = 0, _len = noscriptTags.length; _i < _len; _i++) {
541
- noscript = noscriptTags[_i];
542
- noscript.parentNode.removeChild(noscript);
543
- }
571
+ removeNoscriptTags = function(node) {
572
+ node.innerHTML = node.innerHTML.replace(/<noscript[\S\s]*?<\/noscript>/ig, '');
573
+ return node;
544
574
  };
545
575
 
546
576
  reflectNewUrl = function(url) {
547
577
  if (url !== referer) {
548
578
  return window.history.pushState({
549
579
  turbolinks: true,
550
- position: currentState.position + 1
580
+ url: url
551
581
  }, '', url);
552
582
  }
553
583
  };
@@ -560,10 +590,14 @@
560
590
  }
561
591
  };
562
592
 
593
+ rememberReferer = function() {
594
+ return referer = document.location.href;
595
+ };
596
+
563
597
  rememberCurrentUrl = function() {
564
598
  return window.history.replaceState({
565
599
  turbolinks: true,
566
- position: Date.now()
600
+ url: document.location.href
567
601
  }, '', document.location.href);
568
602
  };
569
603
 
@@ -576,7 +610,15 @@
576
610
  };
577
611
 
578
612
  resetScrollPosition = function() {
579
- return window.scrollTo(0, 0);
613
+ if (document.location.hash) {
614
+ return document.location.href = document.location.href;
615
+ } else {
616
+ return window.scrollTo(0, 0);
617
+ }
618
+ };
619
+
620
+ removeHashForIE10compatiblity = function(url) {
621
+ return removeHash(url);
580
622
  };
581
623
 
582
624
  removeHash = function(url) {
@@ -589,9 +631,19 @@
589
631
  return link.href.replace(link.hash, '');
590
632
  };
591
633
 
592
- triggerEvent = function(name) {
634
+ popCookie = function(name) {
635
+ var value, _ref;
636
+ value = ((_ref = document.cookie.match(new RegExp(name + "=(\\w+)"))) != null ? _ref[1].toUpperCase() : void 0) || '';
637
+ document.cookie = name + '=; expires=Thu, 01-Jan-70 00:00:01 GMT; path=/';
638
+ return value;
639
+ };
640
+
641
+ triggerEvent = function(name, data) {
593
642
  var event;
594
643
  event = document.createEvent('Events');
644
+ if (data) {
645
+ event.data = data;
646
+ }
595
647
  event.initEvent(name, true, true);
596
648
  return document.dispatchEvent(event);
597
649
  };
@@ -603,18 +655,18 @@
603
655
  processResponse = function() {
604
656
  var assetsChanged, clientOrServerError, doc, extractTrackAssets, intersection, validContent;
605
657
  clientOrServerError = function() {
606
- var _ref1;
607
- return (400 <= (_ref1 = xhr.status) && _ref1 < 600);
658
+ var _ref;
659
+ return (400 <= (_ref = xhr.status) && _ref < 600);
608
660
  };
609
661
  validContent = function() {
610
662
  return xhr.getResponseHeader('Content-Type').match(/^(?:text\/html|application\/xhtml\+xml|application\/xml)(?:;|$)/);
611
663
  };
612
664
  extractTrackAssets = function(doc) {
613
- var node, _i, _len, _ref1, _results;
614
- _ref1 = doc.head.childNodes;
665
+ var node, _i, _len, _ref, _results;
666
+ _ref = doc.head.childNodes;
615
667
  _results = [];
616
- for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
617
- node = _ref1[_i];
668
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
669
+ node = _ref[_i];
618
670
  if ((typeof node.getAttribute === "function" ? node.getAttribute('data-turbolinks-track') : void 0) != null) {
619
671
  _results.push(node.getAttribute('src') || node.getAttribute('href'));
620
672
  }
@@ -628,9 +680,9 @@
628
680
  return fetchedAssets.length !== loadedAssets.length || intersection(fetchedAssets, loadedAssets).length !== loadedAssets.length;
629
681
  };
630
682
  intersection = function(a, b) {
631
- var value, _i, _len, _ref1, _results;
683
+ var value, _i, _len, _ref, _results;
632
684
  if (a.length > b.length) {
633
- _ref1 = [b, a], a = _ref1[0], b = _ref1[1];
685
+ _ref = [b, a], a = _ref[0], b = _ref[1];
634
686
  }
635
687
  _results = [];
636
688
  for (_i = 0, _len = a.length; _i < _len; _i++) {
@@ -652,7 +704,7 @@
652
704
  extractTitleAndBody = function(doc) {
653
705
  var title;
654
706
  title = doc.querySelector('title');
655
- return [title != null ? title.textContent : void 0, doc.body, CSRFToken.get(doc).token, 'runScripts'];
707
+ return [title != null ? title.textContent : void 0, removeNoscriptTags(doc.body), CSRFToken.get(doc).token, 'runScripts'];
656
708
  };
657
709
 
658
710
  CSRFToken = {
@@ -676,7 +728,7 @@
676
728
  };
677
729
 
678
730
  browserCompatibleDocumentParser = function() {
679
- var createDocumentUsingDOM, createDocumentUsingParser, createDocumentUsingWrite, e, testDoc, _ref1;
731
+ var createDocumentUsingDOM, createDocumentUsingParser, createDocumentUsingWrite, e, testDoc, _ref;
680
732
  createDocumentUsingParser = function(html) {
681
733
  return (new DOMParser).parseFromString(html, 'text/html');
682
734
  };
@@ -704,7 +756,7 @@
704
756
  testDoc = createDocumentUsingDOM('<html><body><p>test');
705
757
  return createDocumentUsingDOM;
706
758
  } finally {
707
- if ((testDoc != null ? (_ref1 = testDoc.body) != null ? _ref1.childNodes.length : void 0 : void 0) !== 1) {
759
+ if ((testDoc != null ? (_ref = testDoc.body) != null ? _ref.childNodes.length : void 0 : void 0) !== 1) {
708
760
  return createDocumentUsingWrite;
709
761
  }
710
762
  }
@@ -750,7 +802,7 @@
750
802
  nonHtmlLink = function(link) {
751
803
  var url;
752
804
  url = removeHash(link);
753
- return url.match(/\.[a-z]+(\?.*)?$/g) && !url.match(/\.html?(\?.*)?$/g);
805
+ return url.match(/\.[a-z]+(\?.*)?$/g) && !url.match(new RegExp("\\.(?:" + (htmlExtensions.join('|')) + ")?(\\?.*)?$", 'g'));
754
806
  };
755
807
 
756
808
  noTurbolink = function(link) {
@@ -774,36 +826,73 @@
774
826
  return crossOriginLink(link) || anchoredLink(link) || nonHtmlLink(link) || noTurbolink(link) || targetLink(link) || nonStandardClick(event);
775
827
  };
776
828
 
829
+ allowLinkExtensions = function() {
830
+ var extension, extensions, _i, _len;
831
+ extensions = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
832
+ for (_i = 0, _len = extensions.length; _i < _len; _i++) {
833
+ extension = extensions[_i];
834
+ htmlExtensions.push(extension);
835
+ }
836
+ return htmlExtensions;
837
+ };
838
+
839
+ installDocumentReadyPageEventTriggers = function() {
840
+ return document.addEventListener('DOMContentLoaded', (function() {
841
+ triggerEvent('page:change');
842
+ return triggerEvent('page:update');
843
+ }), true);
844
+ };
845
+
846
+ installJqueryAjaxSuccessPageUpdateTrigger = function() {
847
+ if (typeof jQuery !== 'undefined') {
848
+ return jQuery(document).on('ajaxSuccess', function(event, xhr, settings) {
849
+ if (!jQuery.trim(xhr.responseText)) {
850
+ return;
851
+ }
852
+ return triggerEvent('page:update');
853
+ });
854
+ }
855
+ };
856
+
857
+ installHistoryChangeHandler = function(event) {
858
+ var cachedPage, _ref;
859
+ if ((_ref = event.state) != null ? _ref.turbolinks : void 0) {
860
+ if (cachedPage = pageCache[event.state.url]) {
861
+ cacheCurrentPage();
862
+ return fetchHistory(cachedPage);
863
+ } else {
864
+ return visit(event.target.location.href);
865
+ }
866
+ }
867
+ };
868
+
777
869
  initializeTurbolinks = function() {
778
870
  rememberCurrentUrl();
779
871
  rememberCurrentState();
780
872
  createDocument = browserCompatibleDocumentParser();
781
873
  document.addEventListener('click', installClickHandlerLast, true);
782
- return window.addEventListener('popstate', function(event) {
783
- var state;
784
- state = event.state;
785
- if (state != null ? state.turbolinks : void 0) {
786
- if (pageCache[state.position]) {
787
- return fetchHistory(state.position);
788
- } else {
789
- return visit(event.target.location.href);
790
- }
791
- }
792
- }, false);
874
+ return window.addEventListener('popstate', installHistoryChangeHandler, false);
793
875
  };
794
876
 
795
- browserSupportsPushState = window.history && window.history.pushState && window.history.replaceState && window.history.state !== void 0;
877
+ historyStateIsDefined = window.history.state !== void 0 || navigator.userAgent.match(/Firefox\/26/);
878
+
879
+ browserSupportsPushState = window.history && window.history.pushState && window.history.replaceState && historyStateIsDefined;
796
880
 
797
881
  browserIsntBuggy = !navigator.userAgent.match(/CriOS\//);
798
882
 
799
- requestMethodIsSafe = requestMethod === 'GET' || requestMethod === '';
883
+ requestMethodIsSafe = (_ref = popCookie('request_method')) === 'GET' || _ref === '';
800
884
 
801
- if (browserSupportsPushState && browserIsntBuggy && requestMethodIsSafe) {
802
- visit = function(url) {
803
- referer = document.location.href;
804
- cacheCurrentPage();
805
- return fetchReplacement(url);
806
- };
885
+ browserSupportsTurbolinks = browserSupportsPushState && browserIsntBuggy && requestMethodIsSafe;
886
+
887
+ browserSupportsCustomEvents = document.addEventListener && document.createEvent;
888
+
889
+ if (browserSupportsCustomEvents) {
890
+ installDocumentReadyPageEventTriggers();
891
+ installJqueryAjaxSuccessPageUpdateTrigger();
892
+ }
893
+
894
+ if (browserSupportsTurbolinks) {
895
+ visit = fetch;
807
896
  initializeTurbolinks();
808
897
  } else {
809
898
  visit = function(url) {
@@ -813,7 +902,10 @@
813
902
 
814
903
  this.Turbolinks = {
815
904
  visit: visit,
816
- pagesCached: pagesCached
905
+ pagesCached: pagesCached,
906
+ enableTransitionCache: enableTransitionCache,
907
+ allowLinkExtensions: allowLinkExtensions,
908
+ supported: browserSupportsTurbolinks
817
909
  };
818
910
 
819
911
  }).call(this);
@@ -5095,7 +5187,7 @@ $.each( { show: "fadeIn", hide: "fadeOut" }, function( method, defaultEffect ) {
5095
5187
  }
5096
5188
  html = $('<div class="alert alert-error" style="display: none">').append('<button type="button" class="close" data-dismiss="alert">×</button>').append('<h4><i class="icon-exclamation-sign"></i>エラー</h4>').append(msg);
5097
5189
  $(selector).append(html);
5098
- return html.fadeIn('fast');
5190
+ return html.fadeIn('slow');
5099
5191
  };
5100
5192
 
5101
5193
  $(function() {
@@ -5122,7 +5214,6 @@ $.each( { show: "fadeIn", hide: "fadeOut" }, function( method, defaultEffect ) {
5122
5214
  return $('#filename').focus();
5123
5215
  } else {
5124
5216
  afterSave = function() {
5125
- saving = true;
5126
5217
  changed = false;
5127
5218
  successMessage('セーブしました');
5128
5219
  return $.ajax({
@@ -5172,18 +5263,19 @@ $.each( { show: "fadeIn", hide: "fadeOut" }, function( method, defaultEffect ) {
5172
5263
  type: 'DELETE',
5173
5264
  dataType: 'json',
5174
5265
  success: function(data, textStatus, jqXHR) {
5175
- if (data.source_code.error && confirm("前に" + filename + "という名前でセーブしているけど本当にセーブしますか?\nセーブすると前に作成したプログラムは消えてしまうよ!")) {
5176
- return $.ajax({
5177
- url: '/source_codes/write',
5178
- type: 'DELETE',
5179
- data: {
5180
- force: true
5181
- },
5182
- dataType: 'json',
5183
- success: function(data, textStatus, jqXHR) {
5184
- return afterSave();
5185
- }
5186
- });
5266
+ if (data.source_code.error) {
5267
+ if (confirm("前に" + filename + "という名前でセーブしているけど本当にセーブしますか?\nセーブすると前に作成したプログラムは消えてしまうよ!")) {
5268
+ return $.ajax({
5269
+ url: '/source_codes/write?force=1',
5270
+ type: 'DELETE',
5271
+ dataType: 'json',
5272
+ success: function(data, textStatus, jqXHR) {
5273
+ return afterSave();
5274
+ }
5275
+ });
5276
+ } else {
5277
+ return successMessage('セーブをキャンセルしました');
5278
+ }
5187
5279
  } else {
5188
5280
  return afterSave();
5189
5281
  }
@@ -1 +1 @@
1
- {"files":{"favicon-c7ae857bb9d06de8742ae2d337157e83.ico":{"logical_path":"favicon.ico","mtime":"2013-11-25T21:05:22+09:00","size":16398,"digest":"c7ae857bb9d06de8742ae2d337157e83"},"application-13c48477888bb9c50ee5d1ba2193890f.js":{"logical_path":"application.js","mtime":"2014-01-11T14:04:20+09:00","size":601007,"digest":"13c48477888bb9c50ee5d1ba2193890f"},"application-f51ea0e777d97f12a8ce84308f31eb57.css":{"logical_path":"application.css","mtime":"2013-12-24T10:25:38+09:00","size":104182,"digest":"f51ea0e777d97f12a8ce84308f31eb57"},"loading-e8e6dd7833131c92a6c3b9c8ccc6a6ac.gif":{"logical_path":"loading.gif","mtime":"2014-01-03T14:44:55+09:00","size":3897,"digest":"e8e6dd7833131c92a6c3b9c8ccc6a6ac"},"progressbar-82023a146fba2a0f6d925629ed2b09c5.gif":{"logical_path":"progressbar.gif","mtime":"2014-01-03T14:44:55+09:00","size":3323,"digest":"82023a146fba2a0f6d925629ed2b09c5"},"application-a50281f6a3e2eef79882cacb6d107c26.js":{"logical_path":"application.js","mtime":"2014-01-13T17:53:01+09:00","size":600793,"digest":"a50281f6a3e2eef79882cacb6d107c26"},"application-eff4fb09a71dae23dc9b3962bcd44fa8.js":{"logical_path":"application.js","mtime":"2014-01-15T23:08:51+09:00","size":600764,"digest":"eff4fb09a71dae23dc9b3962bcd44fa8"}},"assets":{"favicon.ico":"favicon-c7ae857bb9d06de8742ae2d337157e83.ico","application.js":"application-eff4fb09a71dae23dc9b3962bcd44fa8.js","application.css":"application-f51ea0e777d97f12a8ce84308f31eb57.css","loading.gif":"loading-e8e6dd7833131c92a6c3b9c8ccc6a6ac.gif","progressbar.gif":"progressbar-82023a146fba2a0f6d925629ed2b09c5.gif"}}
1
+ {"files":{"favicon-c7ae857bb9d06de8742ae2d337157e83.ico":{"logical_path":"favicon.ico","mtime":"2013-11-25T21:05:22+09:00","size":16398,"digest":"c7ae857bb9d06de8742ae2d337157e83"},"application-13c48477888bb9c50ee5d1ba2193890f.js":{"logical_path":"application.js","mtime":"2014-01-11T14:04:20+09:00","size":601007,"digest":"13c48477888bb9c50ee5d1ba2193890f"},"application-f51ea0e777d97f12a8ce84308f31eb57.css":{"logical_path":"application.css","mtime":"2014-01-21T01:58:55+09:00","size":104182,"digest":"f51ea0e777d97f12a8ce84308f31eb57"},"loading-e8e6dd7833131c92a6c3b9c8ccc6a6ac.gif":{"logical_path":"loading.gif","mtime":"2014-01-03T14:44:55+09:00","size":3897,"digest":"e8e6dd7833131c92a6c3b9c8ccc6a6ac"},"progressbar-82023a146fba2a0f6d925629ed2b09c5.gif":{"logical_path":"progressbar.gif","mtime":"2014-01-03T14:44:55+09:00","size":3323,"digest":"82023a146fba2a0f6d925629ed2b09c5"},"application-a50281f6a3e2eef79882cacb6d107c26.js":{"logical_path":"application.js","mtime":"2014-01-13T17:53:01+09:00","size":600793,"digest":"a50281f6a3e2eef79882cacb6d107c26"},"application-eff4fb09a71dae23dc9b3962bcd44fa8.js":{"logical_path":"application.js","mtime":"2014-01-15T23:08:51+09:00","size":600764,"digest":"eff4fb09a71dae23dc9b3962bcd44fa8"},"application-c3ceffcb1cbe2098c7caaa15f8e518c9.js":{"logical_path":"application.js","mtime":"2014-01-20T22:08:05+09:00","size":600858,"digest":"c3ceffcb1cbe2098c7caaa15f8e518c9"},"application-e4088c39fcdcc35e9a5037118afb59e7.js":{"logical_path":"application.js","mtime":"2014-01-20T22:27:19+09:00","size":600833,"digest":"e4088c39fcdcc35e9a5037118afb59e7"},"application-ba0c47b4699119d7c75b88c4eef30e9a.js":{"logical_path":"application.js","mtime":"2014-01-21T01:58:55+09:00","size":603960,"digest":"ba0c47b4699119d7c75b88c4eef30e9a"}},"assets":{"favicon.ico":"favicon-c7ae857bb9d06de8742ae2d337157e83.ico","application.js":"application-ba0c47b4699119d7c75b88c4eef30e9a.js","application.css":"application-f51ea0e777d97f12a8ce84308f31eb57.css","loading.gif":"loading-e8e6dd7833131c92a6c3b9c8ccc6a6ac.gif","progressbar.gif":"progressbar-82023a146fba2a0f6d925629ed2b09c5.gif"}}
@@ -15,7 +15,7 @@
15
15
  かつ ホームディレクトリの "01.rb" の内容が "puts 'Hello, World!'" であること
16
16
  かつ "メッセージ" に "セーブしました" を含むこと
17
17
 
18
- シナリオ: ローカルマシンに同じ名前のプログラムがある状態でセーブボタンを押す
18
+ シナリオ: ローカルマシンに同じ名前のプログラムがある状態でセーブボタンを押して上書き保存する
19
19
  前提 "エディタ" 画面を表示する
20
20
  かつ ホームディレクトリに "puts 'Hello, World!'" という内容の "01.rb" が存在する
21
21
  かつ テキストエディタに "n = 0" を入力済みである
@@ -23,10 +23,23 @@
23
23
 
24
24
  もし "セーブボタン" をクリックする
25
25
  かつ JavaScriptによるリクエストが終わるまで待つ
26
+ かつ JavaScriptによるリクエストが終わるまで待つ
26
27
 
27
28
  ならば 確認メッセージ "前に01.rbという名前でセーブしているけど本当にセーブしますか?\nセーブすると前に作成したプログラムは消えてしまうよ!" を表示すること
28
- かつ ホームディレクトリの "01.rb" の内容が "puts 'Hello, World!'" であること
29
+ かつ "メッセージ" "セーブしました" を含むこと
30
+ かつ ホームディレクトリの "01.rb" の内容が "n = 0" であること
29
31
 
30
- もし JavaScriptによるリクエストが終わるまで待つ
32
+ シナリオ: ローカルマシンに同じ名前のプログラムがある状態でセーブボタンを押すが、キャンセルして上書き保存をしない
33
+ 前提 "エディタ" 画面を表示する
34
+ かつ ホームディレクトリに "puts 'Hello, World!'" という内容の "01.rb" が存在する
35
+ かつ テキストエディタに "n = 0" を入力済みである
36
+ かつ プログラムの名前に "01.rb" を指定する
37
+ かつ 確認ダイアログをキャンセルするようにしておく
31
38
 
32
- ならば "メッセージ" に "セーブしました" を含むこと
39
+ もし "セーブボタン" をクリックする
40
+ かつ JavaScriptによるリクエストが終わるまで待つ
41
+ かつ JavaScriptによるリクエストが終わるまで待つ
42
+
43
+ ならば 確認メッセージ "前に01.rbという名前でセーブしているけど本当にセーブしますか?\nセーブすると前に作成したプログラムは消えてしまうよ!" を表示すること
44
+ かつ "メッセージ" に "セーブをキャンセルしました" を含むこと
45
+ かつ ホームディレクトリの "01.rb" の内容が "puts 'Hello, World!'" であること
@@ -4,12 +4,13 @@ step ':name にアクセスする' do |name|
4
4
  visit NAME_INFO[name][:path]
5
5
 
6
6
  if poltergeist?
7
+ page.execute_script('window.confirmResult = true')
7
8
  page.execute_script(<<-JS)
8
9
  if (window.confirmMsg == undefined) {
9
10
  window.confirmMsg = null;
10
11
  window.confirm = function(msg) {
11
12
  window.confirmMsg = msg;
12
- return true;
13
+ return window.confirmResult;
13
14
  }
14
15
  }
15
16
  JS
@@ -128,6 +129,10 @@ step '警告ダイアログの :name ボタンをクリックする' do |name|
128
129
  end
129
130
  end
130
131
 
132
+ step '確認ダイアログをキャンセルするようにしておく' do
133
+ page.execute_script('window.confirmResult = false') if poltergeist?
134
+ end
135
+
131
136
  step '確認メッセージ :message を表示すること' do |message|
132
137
  message.gsub!('\n', "\n")
133
138
  if poltergeist?
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smalruby-editor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kouji Takao
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-15 00:00:00.000000000 Z
11
+ date: 2014-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -361,8 +361,8 @@ files:
361
361
  - spec/turnip_helper.rb
362
362
  - vendor/assets/javascripts/.keep
363
363
  - vendor/assets/stylesheets/.keep
364
- - public/assets/application-eff4fb09a71dae23dc9b3962bcd44fa8.js
365
- - public/assets/application-eff4fb09a71dae23dc9b3962bcd44fa8.js.gz
364
+ - public/assets/application-ba0c47b4699119d7c75b88c4eef30e9a.js
365
+ - public/assets/application-ba0c47b4699119d7c75b88c4eef30e9a.js.gz
366
366
  - public/assets/application-f51ea0e777d97f12a8ce84308f31eb57.css
367
367
  - public/assets/application-f51ea0e777d97f12a8ce84308f31eb57.css.gz
368
368
  - public/assets/favicon-c7ae857bb9d06de8742ae2d337157e83.ico