medium-editor-rails 0.13.1 → 1.0.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: 4e58ad4295ca847f565b03e3c537da4d2fa9b4a0
4
- data.tar.gz: 6bbe1f8535d6757f37740b147eee020dadee37a6
3
+ metadata.gz: bfa61058f24f4aaef259ebf7d18b0669562b4e92
4
+ data.tar.gz: e8c632c87912135a6b0a00a8a2d730e1ef4e3c87
5
5
  SHA512:
6
- metadata.gz: 313670ac55305d945bf64f6a0cc0daa22df1bd4079534594983270dc70a8965014101016321423cee63aedaf54b88e164c476c66d2c01133671ab7ad7c36d277
7
- data.tar.gz: d327eaf5023ee301711ec2c814a199e6943f736206fdde1ca81b93b3f0526200d1ab6af1b503f472bb34ceef1d41f59a0ee2d3b62b3a55eefe4de492c460cb4a
6
+ metadata.gz: 1cc900d59e3b0a79d9c7e0ca7bf95dc2e099c11d19225984932df294d37596c5ca8f01a4a70c0951ca6fb897daab4edb17cbe670d6c864cf97efcfe38a7c4986
7
+ data.tar.gz: e38c565f410987e53920976f1aea84cddf77ce65403f0c4ade06d4106a6af53c9fef55a2c6427c9293a82e3805a2078eadff6f9080a4a0827ae28d73df78d9eb
@@ -1,5 +1,12 @@
1
1
 
2
2
  #### [Current]
3
+ * [fb35ea2](../../commit/fb35ea2) - __(Ahmet Sezgin Duran)__ Bump versions 1.0.0 and 2.0.0
4
+ * [937e1f2](../../commit/937e1f2) - __(Ahmet Sezgin Duran)__ Merge tag '0.13.1' into develop
5
+
6
+ 0.13.1 0.13.1
7
+
8
+ #### 0.13.1
9
+ * [d7b25bb](../../commit/d7b25bb) - __(Ahmet Sezgin Duran)__ Bump versions 0.13.1 and 1.9.13
3
10
  * [c6b96b2](../../commit/c6b96b2) - __(Ahmet Sezgin Duran)__ Update Medium Editor files
4
11
  * [8c242a1](../../commit/8c242a1) - __(Ahmet Sezgin Duran)__ Merge tag '0.13.0' into develop
5
12
 
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014 Ahmet Sezgin Duran
1
+ Copyright (c) 2015 Ahmet Sezgin Duran
2
2
 
3
3
  MIT License
4
4
 
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 [1.9.13](https://github.com/daviferreira/medium-editor/releases)
11
+ The latest version of Medium Editor bundled by this gem is [2.0.0](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 = '0.13.1'
4
- MEDIUM_EDITOR_VERSION = '1.9.13'
3
+ VERSION = '1.0.0'
4
+ MEDIUM_EDITOR_VERSION = '2.0.0'
5
5
  end
6
6
  end
@@ -108,6 +108,39 @@ else if (typeof define === 'function' && define.amd) {
108
108
  return !!(obj && obj.nodeType === 1);
109
109
  }
110
110
 
111
+ // http://stackoverflow.com/questions/6690752/insert-html-at-caret-in-a-contenteditable-div
112
+ function insertHTMLCommand(doc, html) {
113
+ var selection, range, el, fragment, node, lastNode;
114
+
115
+ if (doc.queryCommandSupported('insertHTML')) {
116
+ return doc.execCommand('insertHTML', false, html);
117
+ }
118
+
119
+ selection = window.getSelection();
120
+ if (selection.getRangeAt && selection.rangeCount) {
121
+ range = selection.getRangeAt(0);
122
+ range.deleteContents();
123
+
124
+ el = doc.createElement("div");
125
+ el.innerHTML = html;
126
+ fragment = doc.createDocumentFragment();
127
+ while (el.firstChild) {
128
+ node = el.firstChild;
129
+ lastNode = fragment.appendChild(node);
130
+ }
131
+ range.insertNode(fragment);
132
+
133
+ // Preserve the selection:
134
+ if (lastNode) {
135
+ range = range.cloneRange();
136
+ range.setStartAfter(lastNode);
137
+ range.collapse(true);
138
+ selection.removeAllRanges();
139
+ selection.addRange(range);
140
+ }
141
+ }
142
+ }
143
+
111
144
  MediumEditor.prototype = {
112
145
  defaults: {
113
146
  allowMultiParagraphSelection: true,
@@ -124,6 +157,8 @@ else if (typeof define === 'function' && define.amd) {
124
157
  disableDoubleReturn: false,
125
158
  disableToolbar: false,
126
159
  disableEditing: false,
160
+ disableAnchorForm: false,
161
+ disablePlaceholders: false,
127
162
  elementsContainer: false,
128
163
  contentWindow: window,
129
164
  ownerDocument: document,
@@ -146,6 +181,8 @@ else if (typeof define === 'function' && define.amd) {
146
181
  isIE: ((navigator.appName === 'Microsoft Internet Explorer') || ((navigator.appName === 'Netscape') && (new RegExp('Trident/.*rv:([0-9]{1,}[.0-9]{0,})').exec(navigator.userAgent) !== null))),
147
182
 
148
183
  init: function (elements, options) {
184
+ var uniqueId = 1;
185
+
149
186
  this.options = extend(options, this.defaults);
150
187
  this.setElementSelection(elements);
151
188
  if (this.elements.length === 0) {
@@ -155,7 +192,13 @@ else if (typeof define === 'function' && define.amd) {
155
192
  if (!this.options.elementsContainer) {
156
193
  this.options.elementsContainer = document.body;
157
194
  }
158
- this.id = this.options.elementsContainer.querySelectorAll('.medium-editor-toolbar').length + 1;
195
+
196
+ while (this.options.elementsContainer.querySelector('#medium-editor-toolbar-' + uniqueId)) {
197
+ uniqueId = uniqueId + 1;
198
+ }
199
+
200
+ this.id = uniqueId;
201
+
159
202
  return this.setup();
160
203
  },
161
204
 
@@ -166,6 +209,7 @@ else if (typeof define === 'function' && define.amd) {
166
209
  .bindSelect()
167
210
  .bindPaste()
168
211
  .setPlaceholders()
212
+ .bindElementActions()
169
213
  .bindWindowActions()
170
214
  .passInstance();
171
215
  },
@@ -204,7 +248,7 @@ else if (typeof define === 'function' && define.amd) {
204
248
  this.elements[i].setAttribute('data-placeholder', this.options.placeholder);
205
249
  }
206
250
  this.elements[i].setAttribute('data-medium-element', true);
207
- this.bindParagraphCreation(i).bindReturn(i).bindTab(i);
251
+ this.bindParagraphCreation(i);
208
252
  if (!this.options.disableToolbar && !this.elements[i].getAttribute('data-disable-toolbar')) {
209
253
  addToolbar = true;
210
254
  }
@@ -231,6 +275,114 @@ else if (typeof define === 'function' && define.amd) {
231
275
  }
232
276
  },
233
277
 
278
+ bindBlur: function(i) {
279
+ var self = this,
280
+ timeout,
281
+ blurFunction = function(e){
282
+ // If it's not part of the editor, or the toolbar
283
+ if ( e.target !== self.toolbar
284
+ && e.target !== self.elements[0]
285
+ && !isDescendant(self.elements[0], e.target)
286
+ && !isDescendant(self.toolbar, e.target)
287
+ && !isDescendant(self.anchorPreview, e.target)) {
288
+
289
+ // Activate the placeholder
290
+ if (!self.options.disablePlaceholders) {
291
+ self.placeholderWrapper(self.elements[0], e);
292
+ }
293
+
294
+ clearTimeout(timeout);
295
+ // Hide the toolbar after a small delay so we can prevent this on toolbar click
296
+ timeout = setTimeout(function(){
297
+ if ( !self.keepToolbarAlive ) {
298
+ self.hideToolbarActions();
299
+ }
300
+ }, 200);
301
+ }
302
+ };
303
+
304
+ // Hide the toolbar when focusing outside of the editor.
305
+ this.on(document.body, 'click', blurFunction, true);
306
+ this.on(document.body, 'focus', blurFunction, true);
307
+
308
+ return this;
309
+ },
310
+
311
+ bindKeypress: function(i) {
312
+ if (this.options.disablePlaceholders) {
313
+ return this;
314
+ }
315
+
316
+ var self = this;
317
+
318
+ // Set up the keypress events
319
+ this.on(this.elements[i], 'keypress', function(event){
320
+ self.placeholderWrapper(this,event);
321
+ });
322
+
323
+ return this;
324
+ },
325
+
326
+ bindClick: function(i) {
327
+ var self = this;
328
+
329
+ this.on(this.elements[i], 'click', function(){
330
+ if (!self.options.disablePlaceholders) {
331
+ // Remove placeholder
332
+ this.classList.remove('medium-editor-placeholder');
333
+ }
334
+
335
+ if ( self.options.staticToolbar ) {
336
+ self.setToolbarPosition();
337
+ }
338
+ });
339
+
340
+ return this;
341
+ },
342
+
343
+ /**
344
+ * This handles blur and keypress events on elements
345
+ * Including Placeholders, and tooldbar hiding on blur
346
+ */
347
+ bindElementActions: function() {
348
+ var i;
349
+
350
+ for (i = 0; i < this.elements.length; i += 1) {
351
+
352
+ if (!this.options.disablePlaceholders) {
353
+ // Active all of the placeholders
354
+ this.activatePlaceholder(this.elements[i]);
355
+ }
356
+
357
+ // Bind the return and tab keypress events
358
+ this.bindReturn(i)
359
+ .bindTab(i)
360
+ .bindBlur(i)
361
+ .bindClick(i)
362
+ .bindKeypress(i);
363
+
364
+ }
365
+
366
+ return this;
367
+ },
368
+
369
+ // Two functions to handle placeholders
370
+ activatePlaceholder: function (el) {
371
+
372
+ if (!(el.querySelector('img')) &&
373
+ !(el.querySelector('blockquote')) &&
374
+ el.textContent.replace(/^\s+|\s+$/g, '') === '') {
375
+
376
+ el.classList.add('medium-editor-placeholder');
377
+ }
378
+ },
379
+ placeholderWrapper: function (el, e) {
380
+ el.classList.remove('medium-editor-placeholder');
381
+ if (e.type !== 'keypress') {
382
+ this.activatePlaceholder(el);
383
+ }
384
+ },
385
+
234
386
  serialize: function () {
235
387
  var i,
236
388
  elementid,
@@ -296,9 +448,10 @@ else if (typeof define === 'function' && define.amd) {
296
448
  bindParagraphCreation: function (index) {
297
449
  var self = this;
298
450
  this.on(this.elements[index], 'keypress', function (e) {
299
- var node = getSelectionStart.call(self),
451
+ var node,
300
452
  tagName;
301
453
  if (e.which === 32) {
454
+ node = getSelectionStart.call(self);
302
455
  tagName = node.tagName.toLowerCase();
303
456
  if (tagName === 'a') {
304
457
  document.execCommand('unlink', false, null);
@@ -358,7 +511,7 @@ else if (typeof define === 'function' && define.amd) {
358
511
  e.preventDefault();
359
512
  } else if (self.options.disableDoubleReturn || this.getAttribute('data-disable-double-return')) {
360
513
  var node = getSelectionStart.call(self);
361
- if (node && node.innerText === '\n') {
514
+ if (node && node.textContent === '\n') {
362
515
  e.preventDefault();
363
516
  }
364
517
  }
@@ -487,13 +640,15 @@ else if (typeof define === 'function' && define.amd) {
487
640
  }
488
641
  this.toolbar = this.createToolbar();
489
642
  this.keepToolbarAlive = false;
490
- this.anchorForm = this.toolbar.querySelector('.medium-editor-toolbar-form-anchor');
491
- this.anchorInput = this.anchorForm.querySelector('input.medium-editor-toolbar-anchor-input');
492
- this.anchorTarget = this.anchorForm.querySelector('input.medium-editor-toolbar-anchor-target');
493
- this.anchorButton = this.anchorForm.querySelector('input.medium-editor-toolbar-anchor-button');
494
643
  this.toolbarActions = this.toolbar.querySelector('.medium-editor-toolbar-actions');
495
644
  this.anchorPreview = this.createAnchorPreview();
496
645
 
646
+ if (!this.options.disableAnchorForm) {
647
+ this.anchorForm = this.toolbar.querySelector('.medium-editor-toolbar-form-anchor');
648
+ this.anchorInput = this.anchorForm.querySelector('input.medium-editor-toolbar-anchor-input');
649
+ this.anchorTarget = this.anchorForm.querySelector('input.medium-editor-toolbar-anchor-target');
650
+ this.anchorButton = this.anchorForm.querySelector('input.medium-editor-toolbar-anchor-button');
651
+ }
497
652
  return this;
498
653
  },
499
654
 
@@ -501,8 +656,17 @@ else if (typeof define === 'function' && define.amd) {
501
656
  var toolbar = document.createElement('div');
502
657
  toolbar.id = 'medium-editor-toolbar-' + this.id;
503
658
  toolbar.className = 'medium-editor-toolbar';
659
+
660
+ if ( this.options.staticToolbar ) {
661
+ toolbar.className += " static-toolbar";
662
+ } else {
663
+ toolbar.className += " stalker-toolbar";
664
+ }
665
+
504
666
  toolbar.appendChild(this.toolbarButtons());
505
- toolbar.appendChild(this.toolbarFormAnchor());
667
+ if (!this.options.disableAnchorForm) {
668
+ toolbar.appendChild(this.toolbarFormAnchor());
669
+ }
506
670
  this.options.elementsContainer.appendChild(toolbar);
507
671
  return toolbar;
508
672
  },
@@ -516,7 +680,7 @@ else if (typeof define === 'function' && define.amd) {
516
680
  btn,
517
681
  ext;
518
682
 
519
- ul.id = 'medium-editor-toolbar-actions';
683
+ ul.id = 'medium-editor-toolbar-actions' + this.id;
520
684
  ul.className = 'medium-editor-toolbar-actions clearfix';
521
685
 
522
686
  for (i = 0; i < btns.length; i += 1) {
@@ -576,7 +740,7 @@ else if (typeof define === 'function' && define.amd) {
576
740
 
577
741
 
578
742
  anchor.className = 'medium-editor-toolbar-form-anchor';
579
- anchor.id = 'medium-editor-toolbar-form-anchor';
743
+ anchor.id = 'medium-editor-toolbar-form-anchor-' + this.id;
580
744
  anchor.appendChild(input);
581
745
 
582
746
  anchor.appendChild(save);
@@ -601,7 +765,7 @@ else if (typeof define === 'function' && define.amd) {
601
765
  this.checkSelectionWrapper = function (e) {
602
766
 
603
767
  // Do not close the toolbar when bluring the editable area and clicking into the anchor form
604
- if (e && self.clickingIntoArchorForm(e)) {
768
+ if (!self.options.disableAnchorForm && e && self.clickingIntoArchorForm(e)) {
605
769
  return false;
606
770
  }
607
771
 
@@ -616,6 +780,7 @@ else if (typeof define === 'function' && define.amd) {
616
780
  for (i = 0; i < this.elements.length; i += 1) {
617
781
  this.on(this.elements[i], 'keyup', this.checkSelectionWrapper);
618
782
  this.on(this.elements[i], 'blur', this.checkSelectionWrapper);
783
+ this.on(this.elements[i], 'click', this.checkSelectionWrapper);
619
784
  }
620
785
  return this;
621
786
  },
@@ -627,14 +792,23 @@ else if (typeof define === 'function' && define.amd) {
627
792
  if (this.keepToolbarAlive !== true && !this.options.disableToolbar) {
628
793
 
629
794
  newSelection = this.options.contentWindow.getSelection();
630
- if (newSelection.toString().trim() === '' ||
795
+ if ((!this.options.updateOnEmptySelection && newSelection.toString().trim() === '') ||
631
796
  (this.options.allowMultiParagraphSelection === false && this.hasMultiParagraphs()) ||
632
797
  this.selectionInContentEditableFalse()) {
633
- this.hideToolbarActions();
798
+
799
+ if ( !this.options.staticToolbar ) {
800
+ this.hideToolbarActions();
801
+ } else if (this.anchorForm && this.anchorForm.style.display === 'block') {
802
+ this.setToolbarButtonStates();
803
+ this.showToolbarActions();
804
+ }
805
+
634
806
  } else {
635
807
  selectionElement = this.getSelectionElement();
636
808
  if (!selectionElement || selectionElement.getAttribute('data-disable-toolbar')) {
637
- this.hideToolbarActions();
809
+ if ( !this.options.staticToolbar ) {
810
+ this.hideToolbarActions();
811
+ }
638
812
  } else {
639
813
  this.checkSelectionElement(newSelection, selectionElement);
640
814
  }
@@ -672,7 +846,10 @@ else if (typeof define === 'function' && define.amd) {
672
846
  return;
673
847
  }
674
848
  }
675
- this.hideToolbarActions();
849
+
850
+ if ( !this.options.staticToolbar ) {
851
+ this.hideToolbarActions();
852
+ }
676
853
  },
677
854
 
678
855
  findMatchingSelectionParent: function(testElementFunction) {
@@ -716,28 +893,71 @@ else if (typeof define === 'function' && define.amd) {
716
893
  },
717
894
 
718
895
  setToolbarPosition: function () {
719
- var buttonHeight = 50,
720
- selection = this.options.contentWindow.getSelection(),
721
- range = selection.getRangeAt(0),
722
- boundary = range.getBoundingClientRect(),
723
- defaultLeft = (this.options.diffLeft) - (this.toolbar.offsetWidth / 2),
724
- middleBoundary = (boundary.left + boundary.right) / 2,
725
- halfOffsetWidth = this.toolbar.offsetWidth / 2;
726
- if (boundary.top < buttonHeight) {
727
- this.toolbar.classList.add('medium-toolbar-arrow-over');
728
- this.toolbar.classList.remove('medium-toolbar-arrow-under');
729
- this.toolbar.style.top = buttonHeight + boundary.bottom - this.options.diffTop + this.options.contentWindow.pageYOffset - this.toolbar.offsetHeight + 'px';
730
- } else {
731
- this.toolbar.classList.add('medium-toolbar-arrow-under');
732
- this.toolbar.classList.remove('medium-toolbar-arrow-over');
733
- this.toolbar.style.top = boundary.top + this.options.diffTop + this.options.contentWindow.pageYOffset - this.toolbar.offsetHeight + 'px';
896
+ // document.documentElement for IE 9
897
+ var scrollTop = (document.documentElement && document.documentElement.scrollTop) || document.body.scrollTop,
898
+ container = this.elements[0],
899
+ containerRect = container.getBoundingClientRect(),
900
+ containerTop = containerRect.top + scrollTop,
901
+ buttonHeight = 50,
902
+ selection = window.getSelection(),
903
+ range,
904
+ boundary,
905
+ middleBoundary,
906
+ defaultLeft = (this.options.diffLeft) - (this.toolbar.offsetWidth / 2),
907
+ halfOffsetWidth = this.toolbar.offsetWidth / 2;
908
+
909
+ if ( selection.focusNode === null ) {
910
+ return this;
734
911
  }
735
- if (middleBoundary < halfOffsetWidth) {
736
- this.toolbar.style.left = defaultLeft + halfOffsetWidth + 'px';
737
- } else if ((this.options.contentWindow.innerWidth - middleBoundary) < halfOffsetWidth) {
738
- this.toolbar.style.left = this.options.contentWindow.innerWidth + defaultLeft - halfOffsetWidth + 'px';
739
- } else {
740
- this.toolbar.style.left = defaultLeft + middleBoundary + 'px';
912
+
913
+ this.toolbar.classList.add('medium-editor-toolbar-active');
914
+
915
+ if ( this.options.staticToolbar ) {
916
+
917
+ if ( this.options.stickyToolbar ) {
918
+
919
+ // If it's beyond the height of the editor, position it at the bottom of the editor
920
+ if ( scrollTop > (containerTop + this.elements[0].offsetHeight - this.toolbar.offsetHeight)) {
921
+ this.toolbar.style.top = (containerTop + this.elements[0].offsetHeight) + 'px';
922
+ }
923
+ // Stick the toolbar to the top of the window
924
+ else if ( scrollTop > (containerTop - this.toolbar.offsetHeight) ) {
925
+ this.toolbar.classList.add('sticky-toolbar');
926
+ this.toolbar.style.top = "0px";
927
+ }
928
+ // Normal static toolbar position
929
+ else {
930
+ this.toolbar.classList.remove('sticky-toolbar');
931
+ this.toolbar.style.top = containerTop - this.toolbar.offsetHeight + "px";
932
+ }
933
+
934
+ } else {
935
+ this.toolbar.style.top = containerTop - this.toolbar.offsetHeight + "px";
936
+ }
937
+
938
+ this.toolbar.style.left = containerRect.left + "px";
939
+
940
+ } else if (!selection.isCollapsed) {
941
+ range = selection.getRangeAt(0);
942
+ boundary = range.getBoundingClientRect();
943
+ middleBoundary = (boundary.left + boundary.right) / 2;
944
+
945
+ if (boundary.top < buttonHeight) {
946
+ this.toolbar.classList.add('medium-toolbar-arrow-over');
947
+ this.toolbar.classList.remove('medium-toolbar-arrow-under');
948
+ this.toolbar.style.top = buttonHeight + boundary.bottom - this.options.diffTop + this.options.contentWindow.pageYOffset - this.toolbar.offsetHeight + 'px';
949
+ } else {
950
+ this.toolbar.classList.add('medium-toolbar-arrow-under');
951
+ this.toolbar.classList.remove('medium-toolbar-arrow-over');
952
+ this.toolbar.style.top = boundary.top + this.options.diffTop + this.options.contentWindow.pageYOffset - this.toolbar.offsetHeight + 'px';
953
+ }
954
+ if (middleBoundary < halfOffsetWidth) {
955
+ this.toolbar.style.left = defaultLeft + halfOffsetWidth + 'px';
956
+ } else if ((this.options.contentWindow.innerWidth - middleBoundary) < halfOffsetWidth) {
957
+ this.toolbar.style.left = this.options.contentWindow.innerWidth + defaultLeft - halfOffsetWidth + 'px';
958
+ } else {
959
+ this.toolbar.style.left = defaultLeft + middleBoundary + 'px';
960
+ }
741
961
  }
742
962
 
743
963
  this.hideAnchorPreview();
@@ -817,7 +1037,9 @@ else if (typeof define === 'function' && define.amd) {
817
1037
  this.setToolbarPosition();
818
1038
  this.setToolbarButtonStates();
819
1039
  } else if (action === 'anchor') {
820
- this.triggerAnchorAction(e);
1040
+ if (!this.options.disableAnchorForm) {
1041
+ this.triggerAnchorAction(e);
1042
+ }
821
1043
  } else if (action === 'image') {
822
1044
  this.options.ownerDocument.execCommand('insertImage', false, this.options.contentWindow.getSelection());
823
1045
  } else {
@@ -852,7 +1074,7 @@ else if (typeof define === 'function' && define.amd) {
852
1074
  if (selectedParentElement.tagName &&
853
1075
  selectedParentElement.tagName.toLowerCase() === 'a') {
854
1076
  this.options.ownerDocument.execCommand('unlink', false, null);
855
- } else {
1077
+ } else if (this.anchorForm) {
856
1078
  if (this.anchorForm.style.display === 'block') {
857
1079
  this.showToolbarActions();
858
1080
  } else {
@@ -917,15 +1139,20 @@ else if (typeof define === 'function' && define.amd) {
917
1139
 
918
1140
  hideToolbarActions: function () {
919
1141
  this.keepToolbarAlive = false;
920
- if (this.toolbar !== undefined) {
1142
+ if (this.toolbar !== undefined && this.toolbar.classList.contains('medium-editor-toolbar-active')) {
921
1143
  this.toolbar.classList.remove('medium-editor-toolbar-active');
1144
+ if (this.onHideToolbar) {
1145
+ this.onHideToolbar();
1146
+ }
922
1147
  }
923
1148
  },
924
1149
 
925
1150
  showToolbarActions: function () {
926
1151
  var self = this,
927
1152
  timer;
928
- this.anchorForm.style.display = 'none';
1153
+ if (this.anchorForm) {
1154
+ this.anchorForm.style.display = 'none';
1155
+ }
929
1156
  this.toolbarActions.style.display = 'block';
930
1157
  this.keepToolbarAlive = false;
931
1158
  clearTimeout(timer);
@@ -945,6 +1172,10 @@ else if (typeof define === 'function' && define.amd) {
945
1172
  },
946
1173
 
947
1174
  showAnchorForm: function (link_value) {
1175
+ if (!this.anchorForm) {
1176
+ return;
1177
+ }
1178
+
948
1179
  this.toolbarActions.style.display = 'none';
949
1180
  this.saveSelection();
950
1181
  this.anchorForm.style.display = 'block';
@@ -955,6 +1186,10 @@ else if (typeof define === 'function' && define.amd) {
955
1186
  },
956
1187
 
957
1188
  bindAnchorForm: function () {
1189
+ if (!this.anchorForm) {
1190
+ return this;
1191
+ }
1192
+
958
1193
  var linkCancel = this.anchorForm.querySelector('a.medium-editor-toobar-anchor-close'),
959
1194
  linkSave = this.anchorForm.querySelector('a.medium-editor-toobar-anchor-save'),
960
1195
  self = this;
@@ -1140,7 +1375,7 @@ else if (typeof define === 'function' && define.amd) {
1140
1375
  },
1141
1376
 
1142
1377
  anchorPreviewClickHandler: function (e) {
1143
- if (this.activeAnchor) {
1378
+ if (!this.options.disableAnchorForm && this.activeAnchor) {
1144
1379
 
1145
1380
  var self = this,
1146
1381
  range = this.options.ownerDocument.createRange(),
@@ -1294,6 +1529,18 @@ else if (typeof define === 'function' && define.amd) {
1294
1529
  }
1295
1530
  }, 100);
1296
1531
  };
1532
+
1533
+ // Add a scroll event for sticky toolbar
1534
+ if ( this.options.staticToolbar && this.options.stickyToolbar ) {
1535
+
1536
+ // On scroll, re-position the toolbar
1537
+ this.on(window, 'scroll', function() {
1538
+ if (self.toolbar && self.toolbar.classList.contains('medium-editor-toolbar-active')) {
1539
+ self.setToolbarPosition();
1540
+ }
1541
+ }, true);
1542
+ }
1543
+
1297
1544
  this.on(this.options.contentWindow, 'resize', this.windowResizeHandler);
1298
1545
  return this;
1299
1546
  },
@@ -1340,21 +1587,34 @@ else if (typeof define === 'function' && define.amd) {
1340
1587
  this.pasteWrapper = function (e) {
1341
1588
  var paragraphs,
1342
1589
  html = '',
1343
- p;
1590
+ p,
1591
+ dataFormatHTML = 'text/html',
1592
+ dataFormatPlain = 'text/plain';
1344
1593
 
1345
1594
  this.classList.remove('medium-editor-placeholder');
1346
1595
  if (!self.options.forcePlainText && !self.options.cleanPastedHTML) {
1347
1596
  return this;
1348
1597
  }
1349
1598
 
1599
+ if (window.clipboardData && e.clipboardData === undefined) {
1600
+ e.clipboardData = window.clipboardData;
1601
+ // If window.clipboardData exists, but e.clipboardData doesn't exist,
1602
+ // we're probably in IE. IE only has two possibilities for clipboard
1603
+ // data format: 'Text' and 'URL'.
1604
+ //
1605
+ // Of the two, we want 'Text':
1606
+ dataFormatHTML = 'Text';
1607
+ dataFormatPlain = 'Text';
1608
+ }
1609
+
1350
1610
  if (e.clipboardData && e.clipboardData.getData && !e.defaultPrevented) {
1351
1611
  e.preventDefault();
1352
1612
 
1353
- if (self.options.cleanPastedHTML && e.clipboardData.getData('text/html')) {
1354
- return self.cleanPaste(e.clipboardData.getData('text/html'));
1613
+ if (self.options.cleanPastedHTML && e.clipboardData.getData(dataFormatHTML)) {
1614
+ return self.cleanPaste(e.clipboardData.getData(dataFormatHTML));
1355
1615
  }
1356
1616
  if (!(self.options.disableReturn || this.getAttribute('data-disable-return'))) {
1357
- paragraphs = e.clipboardData.getData('text/plain').split(/[\r\n]/g);
1617
+ paragraphs = e.clipboardData.getData(dataFormatPlain).split(/[\r\n]/g);
1358
1618
  for (p = 0; p < paragraphs.length; p += 1) {
1359
1619
  if (paragraphs[p] !== '') {
1360
1620
  if (navigator.userAgent.match(/firefox/i) && p === 0) {
@@ -1364,10 +1624,10 @@ else if (typeof define === 'function' && define.amd) {
1364
1624
  }
1365
1625
  }
1366
1626
  }
1367
- self.options.ownerDocument.execCommand('insertHTML', false, html);
1627
+ insertHTMLCommand(self.options.ownerDocument, html);
1368
1628
  } else {
1369
- html = self.htmlEntities(e.clipboardData.getData('text/plain'));
1370
- self.options.ownerDocument.execCommand('insertHTML', false, html);
1629
+ html = self.htmlEntities(e.clipboardData.getData(dataFormatPlain));
1630
+ insertHTMLCommand(self.options.ownerDocument, html);
1371
1631
  }
1372
1632
  }
1373
1633
  };
@@ -1378,6 +1638,10 @@ else if (typeof define === 'function' && define.amd) {
1378
1638
  },
1379
1639
 
1380
1640
  setPlaceholders: function () {
1641
+ if (this.options.disablePlaceholders) {
1642
+ return this;
1643
+ }
1644
+
1381
1645
  var i,
1382
1646
  activatePlaceholder = function (el) {
1383
1647
  if (!(el.querySelector('img')) &&
@@ -1515,7 +1779,7 @@ else if (typeof define === 'function' && define.amd) {
1515
1779
  return (el && (el.tagName.toLowerCase() === 'p' || el.tagName.toLowerCase() === 'div'));
1516
1780
  },
1517
1781
  filterCommonBlocks: function (el) {
1518
- if (/^\s*$/.test(el.innerText)) {
1782
+ if (/^\s*$/.test(el.textContent)) {
1519
1783
  el.parentNode.removeChild(el);
1520
1784
  }
1521
1785
  },
@@ -1585,7 +1849,7 @@ else if (typeof define === 'function' && define.amd) {
1585
1849
  if (/^\s*$/.test()) {
1586
1850
  el.parentNode.removeChild(el);
1587
1851
  } else {
1588
- el.parentNode.replaceChild(this.options.ownerDocument.createTextNode(el.innerText), el);
1852
+ el.parentNode.replaceChild(this.options.ownerDocument.createTextNode(el.textContent), el);
1589
1853
  }
1590
1854
 
1591
1855
  }
@@ -116,12 +116,17 @@
116
116
  cursor: pointer; }
117
117
 
118
118
  .medium-editor-toolbar-active, .medium-editor-anchor-preview-active {
119
- visibility: visible;
119
+ visibility: visible; }
120
+
121
+ .sticky-toolbar {
122
+ position: fixed;
123
+ top: 1px; }
124
+
125
+ .stalker-toolbar {
120
126
  -webkit-animation: pop-upwards 160ms forwards linear;
121
127
  -ms-animation: pop-upwards 160ms forwards linear;
122
128
  animation: pop-upwards 160ms forwards linear;
123
- -webkit-transition: top 0.075s ease-out, left 0.075s ease-out;
124
- transition: top 0.075s ease-out, left 0.075s ease-out; }
129
+ transition: top 0.075s ease-out, left 0.075s ease-out; }
125
130
 
126
131
  .medium-editor-action-bold {
127
132
  font-weight: bolder; }
@@ -9,8 +9,7 @@
9
9
  border: 1px solid #357ebd;
10
10
  background-color: #428bca;
11
11
  border-radius: 4px;
12
- -webkit-transition: top 0.075s ease-out, left 0.075s ease-out;
13
- transition: top 0.075s ease-out, left 0.075s ease-out; }
12
+ transition: top 0.075s ease-out, left 0.075s ease-out; }
14
13
  .medium-editor-toolbar li button {
15
14
  min-width: 60px;
16
15
  height: 60px;
@@ -19,8 +18,7 @@
19
18
  background-color: transparent;
20
19
  color: #fff;
21
20
  box-sizing: border-box;
22
- -webkit-transition: background-color 0.2s ease-in, color 0.2s ease-in;
23
- transition: background-color 0.2s ease-in, color 0.2s ease-in; }
21
+ transition: background-color 0.2s ease-in, color 0.2s ease-in; }
24
22
  .medium-editor-toolbar li button:hover {
25
23
  background-color: #3276b1;
26
24
  color: #fff; }
@@ -9,12 +9,10 @@
9
9
  .medium-editor-toolbar {
10
10
  border: 1px solid #000;
11
11
  background-color: #242424;
12
- background: -webkit-linear-gradient(bottom, #242424, rgba(36, 36, 36, 0.75));
13
12
  background: linear-gradient(bottom, #242424, rgba(36, 36, 36, 0.75));
14
13
  border-radius: 5px;
15
14
  box-shadow: 0 0 3px #000;
16
- -webkit-transition: top 0.075s ease-out, left 0.075s ease-out;
17
- transition: top 0.075s ease-out, left 0.075s ease-out; }
15
+ transition: top 0.075s ease-out, left 0.075s ease-out; }
18
16
  .medium-editor-toolbar li button {
19
17
  min-width: 50px;
20
18
  height: 50px;
@@ -24,11 +22,9 @@
24
22
  border-left: 1px solid rgba(255, 255, 255, 0.1);
25
23
  background-color: #242424;
26
24
  color: #fff;
27
- background: -webkit-linear-gradient(bottom, #242424, rgba(36, 36, 36, 0.89));
28
25
  background: linear-gradient(bottom, #242424, rgba(36, 36, 36, 0.89));
29
26
  box-shadow: 0 2px 2px rgba(0, 0, 0, 0.3);
30
- -webkit-transition: background-color 0.2s ease-in;
31
- transition: background-color 0.2s ease-in; }
27
+ transition: background-color 0.2s ease-in; }
32
28
  .medium-editor-toolbar li button:hover {
33
29
  background-color: #000;
34
30
  color: yellow; }
@@ -41,7 +37,6 @@
41
37
  .medium-editor-toolbar li .medium-editor-button-active {
42
38
  background-color: #000;
43
39
  color: #fff;
44
- background: -webkit-linear-gradient(bottom, #242424, rgba(0, 0, 0, 0.89));
45
40
  background: linear-gradient(bottom, #242424, rgba(0, 0, 0, 0.89)); }
46
41
 
47
42
  .medium-editor-toolbar-form-anchor {
@@ -17,8 +17,7 @@
17
17
  border-right: 1px solid #9ccea6;
18
18
  background-color: transparent;
19
19
  color: #fff;
20
- -webkit-transition: background-color 0.2s ease-in, color 0.2s ease-in;
21
- transition: background-color 0.2s ease-in, color 0.2s ease-in; }
20
+ transition: background-color 0.2s ease-in, color 0.2s ease-in; }
22
21
  .medium-editor-toolbar li button:hover {
23
22
  background-color: #346a3f;
24
23
  color: #fff; }
@@ -5,7 +5,6 @@
5
5
  border: 1px solid #cdd6e0;
6
6
  background-color: #dee7f0;
7
7
  background-color: rgba(222, 231, 240, 0.95);
8
- background: -webkit-linear-gradient(bottom, #dee7f0, #ffffff);
9
8
  background: linear-gradient(bottom, #dee7f0, #ffffff);
10
9
  border-radius: 2px;
11
10
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.45); }
@@ -16,8 +15,7 @@
16
15
  border-right: 1px solid #cdd6e0;
17
16
  background-color: transparent;
18
17
  color: #40648a;
19
- -webkit-transition: background-color 0.2s ease-in, color 0.2s ease-in;
20
- transition: background-color 0.2s ease-in, color 0.2s ease-in; }
18
+ transition: background-color 0.2s ease-in, color 0.2s ease-in; }
21
19
  .medium-editor-toolbar li button:hover {
22
20
  background-color: #5c90c7;
23
21
  background-color: rgba(92, 144, 199, 0.45);
@@ -32,7 +30,6 @@
32
30
  background-color: #5c90c7;
33
31
  background-color: rgba(92, 144, 199, 0.45);
34
32
  color: #000;
35
- background: -webkit-linear-gradient(bottom, #dee7f0, rgba(0, 0, 0, 0.1));
36
33
  background: linear-gradient(bottom, #dee7f0, rgba(0, 0, 0, 0.1)); }
37
34
 
38
35
  .medium-editor-toolbar-form-anchor {
@@ -14,11 +14,9 @@
14
14
  background-color: transparent;
15
15
  color: #889aac;
16
16
  box-shadow: inset 0 0 3px #f8f8e6;
17
- background: -webkit-linear-gradient(top, #fff, rgba(0, 0, 0, 0.1));
18
17
  background: linear-gradient(top, #fff, rgba(0, 0, 0, 0.1));
19
18
  text-shadow: 1px 4px 6px #def, 0 0 0 #000, 1px 4px 6px #def;
20
- -webkit-transition: background-color 0.2s ease-in;
21
- transition: background-color 0.2s ease-in; }
19
+ transition: background-color 0.2s ease-in; }
22
20
  .medium-editor-toolbar li button:hover {
23
21
  background-color: #fff;
24
22
  color: #000;
@@ -33,7 +31,6 @@
33
31
  background-color: #ccc;
34
32
  color: #000;
35
33
  color: rgba(0, 0, 0, 0.8);
36
- background: -webkit-linear-gradient(bottom, #fff, rgba(0, 0, 0, 0.2));
37
34
  background: linear-gradient(bottom, #fff, rgba(0, 0, 0, 0.2)); }
38
35
 
39
36
  .medium-editor-toolbar-form-anchor {
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: medium-editor-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ahmet Sezgin Duran
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-24 00:00:00.000000000 Z
11
+ date: 2015-01-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -83,7 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
83
  version: '0'
84
84
  requirements: []
85
85
  rubyforge_project:
86
- rubygems_version: 2.4.2
86
+ rubygems_version: 2.4.4
87
87
  signing_key:
88
88
  specification_version: 4
89
89
  summary: Medium Editor integrated in Rails asset pipeline