medium-editor-rails 1.1.2 → 1.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fa0ba14c770973e7f22bda092453aaca2b2b5782
4
- data.tar.gz: a453844a62d84214e01f281307ead464074984f3
3
+ metadata.gz: 59ed3d1649f4b21ed2ac23f47a5741106dee459d
4
+ data.tar.gz: e445c754424ca6d986ec525810233b1f010406d3
5
5
  SHA512:
6
- metadata.gz: 48eed5d492ac8bfee58818fea34ba15e3cf64ee3ae3aa789880a249e375add2006f80d56829a42d41a4273e8e28e25365b8bbfc52c853ed6a7b3eb0b1285f887
7
- data.tar.gz: fc05433556125ed58868debbe20c93b1e36bdd52a92096b61537df23f130382a074ee2fb4a52360710b1b7940a7bb3cf7fa5a3f87efe11b60a939a635479bc8a
6
+ metadata.gz: ffb12c796fbfb1720486e39b1f3eeea4b784d159ea2c1fe2421db9a474006a88b82899dd1f4d430ca47da200dbf230a21e0e91a2d08e829e3de492a87ff1837d
7
+ data.tar.gz: 4632fae0f41e107a21d15ce407e7a3397be860998120abacf4a6762cbb0238574c47e81ffab4773ca155bd46a678ab818b11f006cba0c5f1a9e70d97cb8c152b
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
 
2
2
  #### [Current]
3
+ * [9a54e41](../../commit/9a54e41) - __(Ahmet Sezgin Duran)__ Update Medium Editor files
4
+ * [67de6b2](../../commit/67de6b2) - __(Ahmet Sezgin Duran)__ Merge tag '1.1.2' into develop
5
+
6
+ 1.1.2
7
+
8
+ #### 1.1.2
9
+ * [4940597](../../commit/4940597) - __(Ahmet Sezgin Duran)__ Bump versions 1.1.2 and 2.1.2
3
10
  * [4f4d13a](../../commit/4f4d13a) - __(Ahmet Sezgin Duran)__ Update Medium Editor files
4
11
  * [78ae621](../../commit/78ae621) - __(Ahmet Sezgin Duran)__ Merge tag '1.1.0' into develop
5
12
 
data/README.md CHANGED
@@ -8,7 +8,7 @@ This gem integrates [Medium Editor](https://github.com/daviferreira/medium-edito
8
8
 
9
9
  ## Version
10
10
 
11
- The latest version of Medium Editor bundled by this gem is [2.1.2](https://github.com/daviferreira/medium-editor/releases)
11
+ The latest version of Medium Editor bundled by this gem is [2.1.3](https://github.com/daviferreira/medium-editor/releases)
12
12
 
13
13
  ## Installation
14
14
 
@@ -1,6 +1,6 @@
1
1
  module MediumEditorRails
2
2
  module Rails
3
- VERSION = '1.1.2'
4
- MEDIUM_EDITOR_VERSION = '2.1.2'
3
+ VERSION = '1.1.3'
4
+ MEDIUM_EDITOR_VERSION = '2.1.3'
5
5
  end
6
6
  end
@@ -5,9 +5,8 @@ function MediumEditor(elements, options) {
5
5
 
6
6
  if (typeof module === 'object') {
7
7
  module.exports = MediumEditor;
8
- }
9
8
  // AMD support
10
- else if (typeof define === 'function' && define.amd) {
9
+ } else if (typeof define === 'function' && define.amd) {
11
10
  define(function () {
12
11
  'use strict';
13
12
  return MediumEditor;
@@ -31,7 +30,7 @@ else if (typeof define === 'function' && define.amd) {
31
30
  }
32
31
 
33
32
  // https://github.com/jashkenas/underscore
34
- var now = Date.now || function() {
33
+ var now = Date.now || function () {
35
34
  return new Date().getTime();
36
35
  };
37
36
 
@@ -49,7 +48,7 @@ else if (typeof define === 'function' && define.amd) {
49
48
  wait = THROTTLE_INTERVAL;
50
49
  }
51
50
 
52
- later = function() {
51
+ later = function () {
53
52
  previous = now();
54
53
  timeout = null;
55
54
  result = func.apply(context, args);
@@ -58,7 +57,7 @@ else if (typeof define === 'function' && define.amd) {
58
57
  }
59
58
  };
60
59
 
61
- return function() {
60
+ return function () {
62
61
  var currNow = now(),
63
62
  remaining = wait - (currNow - previous);
64
63
  context = this;
@@ -79,14 +78,14 @@ else if (typeof define === 'function' && define.amd) {
79
78
  }
80
79
 
81
80
  function isDescendant(parent, child) {
82
- var node = child.parentNode;
83
- while (node !== null) {
84
- if (node === parent) {
85
- return true;
86
- }
87
- node = node.parentNode;
88
- }
89
- return false;
81
+ var node = child.parentNode;
82
+ while (node !== null) {
83
+ if (node === parent) {
84
+ return true;
85
+ }
86
+ node = node.parentNode;
87
+ }
88
+ return false;
90
89
  }
91
90
 
92
91
  // Find the next node in the DOM tree that represents any text that is being
@@ -108,7 +107,7 @@ else if (typeof define === 'function' && define.amd) {
108
107
  if (nextNode === targetNode) {
109
108
  pastTarget = true;
110
109
  } else if (pastTarget) {
111
- if (nextNode.nodeType === 3 && nextNode.nodeValue.length > 0) {
110
+ if (nextNode.nodeType === 3 && nextNode.nodeValue && nextNode.nodeValue.length > 0) {
112
111
  break;
113
112
  }
114
113
  }
@@ -324,21 +323,21 @@ else if (typeof define === 'function' && define.amd) {
324
323
  //.passInstance();
325
324
  },
326
325
 
327
- on: function(target, event, listener, useCapture) {
326
+ on: function (target, event, listener, useCapture) {
328
327
  target.addEventListener(event, listener, useCapture);
329
328
  this.events.push([target, event, listener, useCapture]);
330
329
  },
331
330
 
332
- off: function(target, event, listener, useCapture) {
331
+ off: function (target, event, listener, useCapture) {
333
332
  var index = this.indexOfListener(target, event, listener, useCapture),
334
333
  e;
335
- if(index !== -1) {
334
+ if (index !== -1) {
336
335
  e = this.events.splice(index, 1)[0];
337
336
  e[0].removeEventListener(e[1], e[2], e[3]);
338
337
  }
339
338
  },
340
339
 
341
- indexOfListener: function(target, event, listener, useCapture) {
340
+ indexOfListener: function (target, event, listener, useCapture) {
342
341
  var i, n, item;
343
342
  for (i = 0, n = this.events.length; i < n; i = i + 1) {
344
343
  item = this.events[i];
@@ -349,30 +348,30 @@ else if (typeof define === 'function' && define.amd) {
349
348
  return -1;
350
349
  },
351
350
 
352
- delay: function(fn) {
351
+ delay: function (fn) {
353
352
  var self = this;
354
- setTimeout(function() {
353
+ setTimeout(function () {
355
354
  if (self.isActive) {
356
355
  fn();
357
356
  }
358
357
  }, this.options.delay);
359
358
  },
360
359
 
361
- removeAllEvents: function() {
360
+ removeAllEvents: function () {
362
361
  var e = this.events.pop();
363
- while(e) {
362
+ while (e) {
364
363
  e[0].removeEventListener(e[1], e[2], e[3]);
365
364
  e = this.events.pop();
366
365
  }
367
366
  },
368
367
 
369
- initThrottledMethods: function() {
368
+ initThrottledMethods: function () {
370
369
  var self = this;
371
370
 
372
371
  // handleResize is throttled because:
373
372
  // - It will be called when the browser is resizing, which can fire many times very quickly
374
373
  // - For some event (like resize) a slight lag in UI responsiveness is OK and provides performance benefits
375
- this.handleResize = throttle(function() {
374
+ this.handleResize = throttle(function () {
376
375
  if (self.isActive) {
377
376
  self.positionToolbarIfShown();
378
377
  }
@@ -382,7 +381,7 @@ else if (typeof define === 'function' && define.amd) {
382
381
  // - This method could be called many times due to the type of event handlers that are calling it
383
382
  // - We want a slight delay so that other events in the stack can run, some of which may
384
383
  // prevent the toolbar from being hidden (via this.keepToolbarAlive).
385
- this.handleBlur = throttle(function() {
384
+ this.handleBlur = throttle(function () {
386
385
  if (self.isActive && !self.keepToolbarAlive) {
387
386
  self.hideToolbarActions();
388
387
  }
@@ -437,15 +436,23 @@ else if (typeof define === 'function' && define.amd) {
437
436
  this.elements = Array.prototype.slice.apply(selector);
438
437
  },
439
438
 
440
- bindBlur: function(i) {
439
+ bindBlur: function () {
441
440
  var self = this,
442
- blurFunction = function(e){
441
+ blurFunction = function (e) {
442
+ var isDescendantOfEditorElements = false,
443
+ i;
444
+ for (i = 0; i < self.elements.length; i += 1) {
445
+ if (isDescendant(self.elements[i], e.target)) {
446
+ isDescendantOfEditorElements = true;
447
+ break;
448
+ }
449
+ }
443
450
  // If it's not part of the editor, or the toolbar
444
- if ( e.target !== self.toolbar
445
- && e.target !== self.elements[0]
446
- && !isDescendant(self.elements[0], e.target)
447
- && !isDescendant(self.toolbar, e.target)
448
- && !isDescendant(self.anchorPreview, e.target)) {
451
+ if (e.target !== self.toolbar
452
+ && self.elements.indexOf(e.target) === -1
453
+ && !isDescendantOfEditorElements
454
+ && !isDescendant(self.toolbar, e.target)
455
+ && !isDescendant(self.anchorPreview, e.target)) {
449
456
 
450
457
  // Activate the placeholder
451
458
  if (!self.options.disablePlaceholders) {
@@ -464,16 +471,16 @@ else if (typeof define === 'function' && define.amd) {
464
471
  return this;
465
472
  },
466
473
 
467
- bindClick: function(i) {
474
+ bindClick: function (i) {
468
475
  var self = this;
469
476
 
470
- this.on(this.elements[i], 'click', function(){
477
+ this.on(this.elements[i], 'click', function () {
471
478
  if (!self.options.disablePlaceholders) {
472
479
  // Remove placeholder
473
480
  this.classList.remove('medium-editor-placeholder');
474
481
  }
475
482
 
476
- if ( self.options.staticToolbar ) {
483
+ if (self.options.staticToolbar) {
477
484
  self.setToolbarPosition();
478
485
  }
479
486
  });
@@ -485,7 +492,7 @@ else if (typeof define === 'function' && define.amd) {
485
492
  * This handles blur and keypress events on elements
486
493
  * Including Placeholders, and tooldbar hiding on blur
487
494
  */
488
- bindElementActions: function() {
495
+ bindElementActions: function () {
489
496
  var i;
490
497
 
491
498
  for (i = 0; i < this.elements.length; i += 1) {
@@ -498,7 +505,7 @@ else if (typeof define === 'function' && define.amd) {
498
505
  // Bind the return and tab keypress events
499
506
  this.bindReturn(i)
500
507
  .bindKeydown(i)
501
- .bindBlur(i)
508
+ .bindBlur()
502
509
  .bindClick(i);
503
510
  }
504
511
 
@@ -613,12 +620,11 @@ else if (typeof define === 'function' && define.amd) {
613
620
  editorElement = self.getSelectionElement();
614
621
 
615
622
  if (!(self.options.disableReturn || editorElement.getAttribute('data-disable-return')) &&
616
- tagName !== 'li' && !self.isListItemChild(node)) {
623
+ tagName !== 'li' && !self.isListItemChild(node)) {
617
624
  if (!e.shiftKey) {
618
625
 
619
626
  // paragraph creation should not be forced within a header tag
620
- if (!/h\d/.test(tagName))
621
- {
627
+ if (!/h\d/.test(tagName)) {
622
628
  self.options.ownerDocument.execCommand('formatBlock', false, 'p');
623
629
  }
624
630
  }
@@ -688,9 +694,7 @@ else if (typeof define === 'function' && define.amd) {
688
694
  self.options.ownerDocument.execCommand('indent', e);
689
695
  }
690
696
  }
691
- }
692
- else if ( e.which === 8 || e.which === 46 || e.which === 13 )
693
- {
697
+ } else if (e.which === 8 || e.which === 46 || e.which === 13) {
694
698
 
695
699
  // Bind keys which can create or destroy a block element: backspace, delete, return
696
700
  self.onBlockModifier(e);
@@ -700,62 +704,63 @@ else if (typeof define === 'function' && define.amd) {
700
704
  return this;
701
705
  },
702
706
 
703
- onBlockModifier: function( e ) {
707
+ onBlockModifier: function (e) {
704
708
 
705
709
  var range, sel, p, node = getSelectionStart.call(this),
706
710
  tagName = node.tagName.toLowerCase(),
707
711
  isEmpty = /^(\s+|<br\/?>)?$/i,
708
712
  isHeader = /h\d/i;
709
713
 
710
- if ( (e.which === 8 || e.which === 13) // backspace or return
711
- && node.previousElementSibling
712
- && isHeader.test(tagName) // in a header
713
- && getCaretOffsets(node).left === 0 ) // at the very end of the block
714
- {
715
- if ( e.which === 8 && isEmpty.test(node.previousElementSibling.innerHTML) )
716
- {
714
+ // backspace or return
715
+ if ((e.which === 8 || e.which === 13)
716
+ && node.previousElementSibling
717
+ // in a header
718
+ && isHeader.test(tagName)
719
+ // at the very end of the block
720
+ && getCaretOffsets(node).left === 0) {
721
+ if (e.which === 8 && isEmpty.test(node.previousElementSibling.innerHTML)) {
717
722
  // backspacing the begining of a header into an empty previous element will
718
723
  // change the tagName of the current node to prevent one
719
724
  // instead delete previous node and cancel the event.
720
- node.previousElementSibling.parentNode.removeChild( node.previousElementSibling );
725
+ node.previousElementSibling.parentNode.removeChild(node.previousElementSibling);
721
726
  e.preventDefault();
722
- }
723
- else if ( e.which === 13 )
724
- {
727
+ } else if (e.which === 13) {
725
728
  // hitting return in the begining of a header will create empty header elements before the current one
726
729
  // instead, make "<p><br></p>" element, which are what happens if you hit return in an empty paragraph
727
730
  p = this.options.ownerDocument.createElement('p');
728
731
  p.innerHTML = '<br>';
729
- node.previousElementSibling.parentNode.insertBefore( p, node );
732
+ node.previousElementSibling.parentNode.insertBefore(p, node);
730
733
  e.preventDefault();
731
734
  }
732
735
 
733
- }
734
- else if ( e.which === 46 // delete
735
- && node.nextElementSibling
736
- && node.previousElementSibling
737
- && !isHeader.test(tagName) // not in a header
738
- && isEmpty.test(node.innerHTML) // in an empty tag
739
- && isHeader.test(node.nextElementSibling.tagName) ) // when the next tag *is* a header
740
- {
741
- // hitting delete in an empty element preceding a header, ex:
742
- // <p>[CURSOR]</p><h1>Header</h1>
743
- // Will cause the h1 to become a paragraph.
744
- // Instead, delete the paragraph node and move the cursor to the begining of the h1
745
-
746
- // remove node and move cursor to start of header
747
- range = document.createRange();
748
- sel = window.getSelection();
749
-
750
- range.setStart(node.nextElementSibling, 0);
751
- range.collapse(true);
736
+ // delete
737
+ } else if (e.which === 46
738
+ && node.nextElementSibling
739
+ && node.previousElementSibling
740
+ // not in a header
741
+ && !isHeader.test(tagName)
742
+ // in an empty tag
743
+ && isEmpty.test(node.innerHTML)
744
+ // when the next tag *is* a header
745
+ && isHeader.test(node.nextElementSibling.tagName)) {
746
+ // hitting delete in an empty element preceding a header, ex:
747
+ // <p>[CURSOR]</p><h1>Header</h1>
748
+ // Will cause the h1 to become a paragraph.
749
+ // Instead, delete the paragraph node and move the cursor to the begining of the h1
750
+
751
+ // remove node and move cursor to start of header
752
+ range = document.createRange();
753
+ sel = window.getSelection();
754
+
755
+ range.setStart(node.nextElementSibling, 0);
756
+ range.collapse(true);
752
757
 
753
- sel.removeAllRanges();
754
- sel.addRange(range);
758
+ sel.removeAllRanges();
759
+ sel.addRange(range);
755
760
 
756
- node.previousElementSibling.parentNode.removeChild(node);
761
+ node.previousElementSibling.parentNode.removeChild(node);
757
762
 
758
- e.preventDefault();
763
+ e.preventDefault();
759
764
  }
760
765
 
761
766
  },
@@ -766,7 +771,7 @@ else if (typeof define === 'function' && define.amd) {
766
771
  'bold': '<button class="medium-editor-action medium-editor-action-bold" data-action="bold" data-element="b" aria-label="bold">' + buttonLabels.bold + '</button>',
767
772
  'italic': '<button class="medium-editor-action medium-editor-action-italic" data-action="italic" data-element="i" aria-label="italic">' + buttonLabels.italic + '</button>',
768
773
  'underline': '<button class="medium-editor-action medium-editor-action-underline" data-action="underline" data-element="u" aria-label="underline">' + buttonLabels.underline + '</button>',
769
- 'strikethrough': '<button class="medium-editor-action medium-editor-action-strikethrough" data-action="strikethrough" data-element="strike" aria-label="strike through">' + buttonLabels.strikethrough +'</button>',
774
+ 'strikethrough': '<button class="medium-editor-action medium-editor-action-strikethrough" data-action="strikethrough" data-element="strike" aria-label="strike through">' + buttonLabels.strikethrough + '</button>',
770
775
  'superscript': '<button class="medium-editor-action medium-editor-action-superscript" data-action="superscript" data-element="sup" aria-label="superscript">' + buttonLabels.superscript + '</button>',
771
776
  'subscript': '<button class="medium-editor-action medium-editor-action-subscript" data-action="subscript" data-element="sub" aria-label="subscript">' + buttonLabels.subscript + '</button>',
772
777
  'anchor': '<button class="medium-editor-action medium-editor-action-anchor" data-action="anchor" data-element="a" aria-label="link">' + buttonLabels.anchor + '</button>',
@@ -871,7 +876,7 @@ else if (typeof define === 'function' && define.amd) {
871
876
  toolbar.id = 'medium-editor-toolbar-' + this.id;
872
877
  toolbar.className = 'medium-editor-toolbar';
873
878
 
874
- if ( this.options.staticToolbar ) {
879
+ if (this.options.staticToolbar) {
875
880
  toolbar.className += " static-toolbar";
876
881
  } else {
877
882
  toolbar.className += " stalker-toolbar";
@@ -932,11 +937,11 @@ else if (typeof define === 'function' && define.amd) {
932
937
  for (name in extensions) {
933
938
  if (extensions.hasOwnProperty(name)) {
934
939
  ext = extensions[name];
935
- if(ext.hasForm){
936
- form = ext.getForm !== undefined ? ext.getForm() : null;
940
+ if (ext.hasForm) {
941
+ form = ext.getForm !== undefined ? ext.getForm() : null;
937
942
  }
938
943
  if (form) {
939
- id = 'medium-editor-toolbar-form-'+name+'-'+this.id;
944
+ id = 'medium-editor-toolbar-form-' + name + '-' + this.id;
940
945
  form.className = 'medium-editor-toolbar-form';
941
946
  form.id = id;
942
947
  ext.getForm().id = id;
@@ -1021,11 +1026,11 @@ else if (typeof define === 'function' && define.amd) {
1021
1026
  return this;
1022
1027
  },
1023
1028
 
1024
- stopSelectionUpdates: function() {
1029
+ stopSelectionUpdates: function () {
1025
1030
  this.preventSelectionUpdates = true;
1026
1031
  },
1027
1032
 
1028
- startSelectionUpdates: function() {
1033
+ startSelectionUpdates: function () {
1029
1034
  this.preventSelectionUpdates = false;
1030
1035
  },
1031
1036
 
@@ -1034,15 +1039,15 @@ else if (typeof define === 'function' && define.amd) {
1034
1039
  selectionElement;
1035
1040
 
1036
1041
  if (!this.preventSelectionUpdates &&
1037
- this.keepToolbarAlive !== true &&
1038
- !this.options.disableToolbar) {
1042
+ this.keepToolbarAlive !== true &&
1043
+ !this.options.disableToolbar) {
1039
1044
 
1040
1045
  newSelection = this.options.contentWindow.getSelection();
1041
1046
  if ((!this.options.updateOnEmptySelection && newSelection.toString().trim() === '') ||
1042
- (this.options.allowMultiParagraphSelection === false && this.hasMultiParagraphs()) ||
1043
- this.selectionInContentEditableFalse()) {
1047
+ (this.options.allowMultiParagraphSelection === false && this.hasMultiParagraphs()) ||
1048
+ this.selectionInContentEditableFalse()) {
1044
1049
 
1045
- if ( !this.options.staticToolbar ) {
1050
+ if (!this.options.staticToolbar) {
1046
1051
  this.hideToolbarActions();
1047
1052
  } else if (this.anchorForm && this.anchorForm.style.display === 'block') {
1048
1053
  this.setToolbarButtonStates();
@@ -1052,7 +1057,7 @@ else if (typeof define === 'function' && define.amd) {
1052
1057
  } else {
1053
1058
  selectionElement = this.getSelectionElement();
1054
1059
  if (!selectionElement || selectionElement.getAttribute('data-disable-toolbar')) {
1055
- if ( !this.options.staticToolbar ) {
1060
+ if (!this.options.staticToolbar) {
1056
1061
  this.hideToolbarActions();
1057
1062
  }
1058
1063
  } else {
@@ -1088,30 +1093,29 @@ else if (typeof define === 'function' && define.amd) {
1088
1093
  this.selection = newSelection;
1089
1094
  this.selectionRange = this.selection.getRangeAt(0);
1090
1095
 
1091
- /*
1096
+ /*
1092
1097
  * In firefox, there are cases (ie doubleclick of a word) where the selectionRange start
1093
1098
  * will be at the very end of an element. In other browsers, the selectionRange start
1094
1099
  * would instead be at the very beginning of an element that actually has content.
1095
1100
  * example:
1096
1101
  * <span>foo</span><span>bar</span>
1097
- *
1102
+ *
1098
1103
  * If the text 'bar' is selected, most browsers will have the selectionRange start at the beginning
1099
1104
  * of the 'bar' span. However, there are cases where firefox will have the selectionRange start
1100
1105
  * at the end of the 'foo' span. The contenteditable behavior will be ok, but if there are any
1101
1106
  * properties on the 'bar' span, they won't be reflected accurately in the toolbar
1102
1107
  * (ie 'Bold' button wouldn't be active)
1103
- *
1108
+ *
1104
1109
  * So, for cases where the selectionRange start is at the end of an element/node, find the next
1105
1110
  * adjacent text node that actually has content in it, and move the selectionRange start there.
1106
1111
  */
1107
- if (
1108
- this.options.standardizeSelectionStart &&
1109
- this.selectionRange.startOffset === this.selectionRange.startContainer.nodeValue.length
1110
- ) {
1112
+ if (this.options.standardizeSelectionStart &&
1113
+ this.selectionRange.startContainer.nodeValue &&
1114
+ (this.selectionRange.startOffset === this.selectionRange.startContainer.nodeValue.length)) {
1111
1115
  adjacentNode = findAdjacentTextNodeWithContent(this.getSelectionElement(), this.selectionRange.startContainer, this.options.ownerDocument);
1112
1116
  if (adjacentNode) {
1113
1117
  offset = 0;
1114
- while(adjacentNode.nodeValue.substr(offset, 1).trim().length === 0) {
1118
+ while (adjacentNode.nodeValue.substr(offset, 1).trim().length === 0) {
1115
1119
  offset = offset + 1;
1116
1120
  }
1117
1121
  newRange = this.options.ownerDocument.createRange();
@@ -1132,12 +1136,12 @@ else if (typeof define === 'function' && define.amd) {
1132
1136
  }
1133
1137
  }
1134
1138
 
1135
- if ( !this.options.staticToolbar ) {
1139
+ if (!this.options.staticToolbar) {
1136
1140
  this.hideToolbarActions();
1137
1141
  }
1138
1142
  },
1139
1143
 
1140
- findMatchingSelectionParent: function(testElementFunction) {
1144
+ findMatchingSelectionParent: function (testElementFunction) {
1141
1145
  var selection = this.options.contentWindow.getSelection(), range, current;
1142
1146
 
1143
1147
  if (selection.rangeCount === 0) {
@@ -1148,31 +1152,30 @@ else if (typeof define === 'function' && define.amd) {
1148
1152
  current = range.commonAncestorContainer;
1149
1153
 
1150
1154
  do {
1151
- if (current.nodeType === 1){
1152
- if ( testElementFunction(current) )
1153
- {
1154
- return current;
1155
- }
1156
- // do not traverse upwards past the nearest containing editor
1157
- if (current.getAttribute('data-medium-element')) {
1158
- return false;
1155
+ if (current.nodeType === 1) {
1156
+ if (testElementFunction(current)) {
1157
+ return current;
1158
+ }
1159
+ // do not traverse upwards past the nearest containing editor
1160
+ if (current.getAttribute('data-medium-element')) {
1161
+ return false;
1162
+ }
1159
1163
  }
1160
- }
1161
1164
 
1162
- current = current.parentNode;
1165
+ current = current.parentNode;
1163
1166
  } while (current);
1164
1167
 
1165
1168
  return false;
1166
1169
  },
1167
1170
 
1168
1171
  getSelectionElement: function () {
1169
- return this.findMatchingSelectionParent(function(el) {
1172
+ return this.findMatchingSelectionParent(function (el) {
1170
1173
  return el.getAttribute('data-medium-element');
1171
1174
  });
1172
1175
  },
1173
1176
 
1174
1177
  selectionInContentEditableFalse: function () {
1175
- return this.findMatchingSelectionParent(function(el) {
1178
+ return this.findMatchingSelectionParent(function (el) {
1176
1179
  return (el && el.nodeName !== '#text' && el.getAttribute('contenteditable') === 'false');
1177
1180
  });
1178
1181
  },
@@ -1180,39 +1183,38 @@ else if (typeof define === 'function' && define.amd) {
1180
1183
  setToolbarPosition: function () {
1181
1184
  // document.documentElement for IE 9
1182
1185
  var scrollTop = (this.options.ownerDocument.documentElement && this.options.ownerDocument.documentElement.scrollTop) || this.options.ownerDocument.body.scrollTop,
1183
- container = this.elements[0],
1184
- containerRect = container.getBoundingClientRect(),
1185
- containerTop = containerRect.top + scrollTop,
1186
- buttonHeight = 50,
1187
- selection = this.options.contentWindow.getSelection(),
1188
- range,
1189
- boundary,
1190
- middleBoundary,
1191
- defaultLeft = (this.options.diffLeft) - (this.toolbar.offsetWidth / 2),
1192
- halfOffsetWidth = this.toolbar.offsetWidth / 2,
1193
- containerCenter = (containerRect.left + (containerRect.width / 2));
1194
-
1195
- if ( selection.focusNode === null ) {
1186
+ container = this.elements[0],
1187
+ containerRect = container.getBoundingClientRect(),
1188
+ containerTop = containerRect.top + scrollTop,
1189
+ buttonHeight = 50,
1190
+ selection = this.options.contentWindow.getSelection(),
1191
+ range,
1192
+ boundary,
1193
+ middleBoundary,
1194
+ defaultLeft = (this.options.diffLeft) - (this.toolbar.offsetWidth / 2),
1195
+ halfOffsetWidth = this.toolbar.offsetWidth / 2,
1196
+ containerCenter = (containerRect.left + (containerRect.width / 2));
1197
+
1198
+ if (selection.focusNode === null) {
1196
1199
  return this;
1197
1200
  }
1198
1201
 
1199
1202
  this.showToolbar();
1200
1203
 
1201
- if ( this.options.staticToolbar ) {
1204
+ if (this.options.staticToolbar) {
1202
1205
 
1203
- if ( this.options.stickyToolbar ) {
1206
+ if (this.options.stickyToolbar) {
1204
1207
 
1205
1208
  // If it's beyond the height of the editor, position it at the bottom of the editor
1206
- if ( scrollTop > (containerTop + this.elements[0].offsetHeight - this.toolbar.offsetHeight)) {
1209
+ if (scrollTop > (containerTop + this.elements[0].offsetHeight - this.toolbar.offsetHeight)) {
1207
1210
  this.toolbar.style.top = (containerTop + this.elements[0].offsetHeight) + 'px';
1208
- }
1211
+
1209
1212
  // Stick the toolbar to the top of the window
1210
- else if ( scrollTop > (containerTop - this.toolbar.offsetHeight) ) {
1213
+ } else if (scrollTop > (containerTop - this.toolbar.offsetHeight)) {
1211
1214
  this.toolbar.classList.add('sticky-toolbar');
1212
1215
  this.toolbar.style.top = "0px";
1213
- }
1214
1216
  // Normal static toolbar position
1215
- else {
1217
+ } else {
1216
1218
  this.toolbar.classList.remove('sticky-toolbar');
1217
1219
  this.toolbar.style.top = containerTop - this.toolbar.offsetHeight + "px";
1218
1220
  }
@@ -1232,7 +1234,7 @@ else if (typeof define === 'function' && define.amd) {
1232
1234
  } else {
1233
1235
  this.toolbar.style.left = (containerCenter - halfOffsetWidth) + "px";
1234
1236
  }
1235
-
1237
+
1236
1238
  } else if (!selection.isCollapsed) {
1237
1239
  range = selection.getRangeAt(0);
1238
1240
  boundary = range.getBoundingClientRect();
@@ -1412,7 +1414,7 @@ else if (typeof define === 'function' && define.amd) {
1412
1414
  // allowing nesting, we need to use outdent
1413
1415
  // https://developer.mozilla.org/en-US/docs/Rich-Text_Editing_in_Mozilla
1414
1416
  if (el === 'blockquote' && selectionData.el &&
1415
- selectionData.el.parentNode.tagName.toLowerCase() === 'blockquote') {
1417
+ selectionData.el.parentNode.tagName.toLowerCase() === 'blockquote') {
1416
1418
  return this.options.ownerDocument.execCommand('outdent', false, null);
1417
1419
  }
1418
1420
  if (selectionData.tagName === el) {
@@ -1459,11 +1461,11 @@ else if (typeof define === 'function' && define.amd) {
1459
1461
  return firstChild;
1460
1462
  },
1461
1463
 
1462
- isToolbarShown: function() {
1464
+ isToolbarShown: function () {
1463
1465
  return this.toolbar && this.toolbar.classList.contains('medium-editor-toolbar-active');
1464
1466
  },
1465
1467
 
1466
- showToolbar: function() {
1468
+ showToolbar: function () {
1467
1469
  if (this.toolbar && !this.isToolbarShown()) {
1468
1470
  this.toolbar.classList.add('medium-editor-toolbar-active');
1469
1471
  if (this.onShowToolbar) {
@@ -1472,7 +1474,7 @@ else if (typeof define === 'function' && define.amd) {
1472
1474
  }
1473
1475
  },
1474
1476
 
1475
- hideToolbar: function() {
1477
+ hideToolbar: function () {
1476
1478
  if (this.isToolbarShown()) {
1477
1479
  this.toolbar.classList.remove('medium-editor-toolbar-active');
1478
1480
  if (this.onHideToolbar) {
@@ -1500,11 +1502,11 @@ else if (typeof define === 'function' && define.amd) {
1500
1502
  });
1501
1503
  },
1502
1504
 
1503
- saveSelection: function() {
1505
+ saveSelection: function () {
1504
1506
  this.savedSelection = saveSelection.call(this);
1505
1507
  },
1506
1508
 
1507
- restoreSelection: function() {
1509
+ restoreSelection: function () {
1508
1510
  restoreSelection.call(this, this.savedSelection);
1509
1511
  },
1510
1512
 
@@ -1544,8 +1546,7 @@ else if (typeof define === 'function' && define.amd) {
1544
1546
  e.preventDefault();
1545
1547
  if (self.options.anchorTarget && self.anchorTarget.checked) {
1546
1548
  target = "_blank";
1547
- }
1548
- else {
1549
+ } else {
1549
1550
  target = "_self";
1550
1551
  }
1551
1552
 
@@ -1554,22 +1555,20 @@ else if (typeof define === 'function' && define.amd) {
1554
1555
  }
1555
1556
 
1556
1557
  self.createLink(this, target, button);
1557
- }
1558
- else if (e.keyCode === 27) {
1558
+ } else if (e.keyCode === 27) {
1559
1559
  e.preventDefault();
1560
1560
  self.showToolbarActions();
1561
1561
  restoreSelection.call(self, self.savedSelection);
1562
1562
  }
1563
1563
  });
1564
1564
 
1565
- this.on(linkSave, 'click', function(e) {
1565
+ this.on(linkSave, 'click', function (e) {
1566
1566
  var button = null,
1567
1567
  target;
1568
1568
  e.preventDefault();
1569
- if ( self.options.anchorTarget && self.anchorTarget.checked) {
1569
+ if (self.options.anchorTarget && self.anchorTarget.checked) {
1570
1570
  target = "_blank";
1571
- }
1572
- else {
1571
+ } else {
1573
1572
  target = "_self";
1574
1573
  }
1575
1574
 
@@ -1615,7 +1614,7 @@ else if (typeof define === 'function' && define.amd) {
1615
1614
  // TODO: break method
1616
1615
  showAnchorPreview: function (anchorEl) {
1617
1616
  if (this.anchorPreview.classList.contains('medium-editor-anchor-preview-active')
1618
- || anchorEl.getAttribute('data-disable-preview')) {
1617
+ || anchorEl.getAttribute('data-disable-preview')) {
1619
1618
  return true;
1620
1619
  }
1621
1620
 
@@ -1804,7 +1803,8 @@ else if (typeof define === 'function' && define.amd) {
1804
1803
  setButtonClass: function (buttonClass) {
1805
1804
  var el = getSelectionStart.call(this),
1806
1805
  classes = buttonClass.split(' '),
1807
- i, j;
1806
+ i,
1807
+ j;
1808
1808
  if (el.tagName.toLowerCase() === 'a') {
1809
1809
  for (j = 0; j < classes.length; j += 1) {
1810
1810
  el.classList.add(classes[j]);
@@ -1856,7 +1856,7 @@ else if (typeof define === 'function' && define.amd) {
1856
1856
  input.value = '';
1857
1857
  },
1858
1858
 
1859
- positionToolbarIfShown: function() {
1859
+ positionToolbarIfShown: function () {
1860
1860
  if (this.isToolbarShown()) {
1861
1861
  this.setToolbarPosition();
1862
1862
  }
@@ -1866,14 +1866,14 @@ else if (typeof define === 'function' && define.amd) {
1866
1866
  var self = this;
1867
1867
 
1868
1868
  // Add a scroll event for sticky toolbar
1869
- if ( this.options.staticToolbar && this.options.stickyToolbar ) {
1869
+ if (this.options.staticToolbar && this.options.stickyToolbar) {
1870
1870
  // On scroll, re-position the toolbar
1871
- this.on(this.options.contentWindow, 'scroll', function() {
1871
+ this.on(this.options.contentWindow, 'scroll', function () {
1872
1872
  self.positionToolbarIfShown();
1873
1873
  }, true);
1874
1874
  }
1875
1875
 
1876
- this.on(this.options.contentWindow, 'resize', function() {
1876
+ this.on(this.options.contentWindow, 'resize', function () {
1877
1877
  self.handleResize();
1878
1878
  });
1879
1879
  return this;
@@ -1973,7 +1973,7 @@ else if (typeof define === 'function' && define.amd) {
1973
1973
 
1974
1974
  setPlaceholders: function () {
1975
1975
  if (!this.options.disablePlaceholders && this.elements && this.elements.length) {
1976
- this.elements.forEach(function(el) {
1976
+ this.elements.forEach(function (el) {
1977
1977
  this.activatePlaceholder(el);
1978
1978
  this.on(el, 'blur', this.placeholderWrapper.bind(this));
1979
1979
  this.on(el, 'keypress', this.placeholderWrapper.bind(this));
@@ -2043,8 +2043,8 @@ else if (typeof define === 'function' && define.amd) {
2043
2043
 
2044
2044
  switch (workEl.tagName.toLowerCase()) {
2045
2045
  case 'a':
2046
- if (this.options.targetBlank){
2047
- this.setTargetBlank(workEl);
2046
+ if (this.options.targetBlank) {
2047
+ this.setTargetBlank(workEl);
2048
2048
  }
2049
2049
  break;
2050
2050
  case 'p':
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: medium-editor-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ahmet Sezgin Duran