dante-editor 0.0.12 → 0.0.13

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: c9de1d8d9a9c05a633a0b47d59b4762f7a568440
4
- data.tar.gz: a4ee6debde48072bafb683d2583d13027a27023e
3
+ metadata.gz: eba2467b8be034552237cb54293358466332638c
4
+ data.tar.gz: 0dae2099d83d79aaf498b58e6b9e28c8b2f4acde
5
5
  SHA512:
6
- metadata.gz: 1ee1b7eddcbe0d0ecc2dfcfba17ec23bbd4c7dd51e516f637599fa21892ad28121bd241d938063087d245589e850e567a98e1b40ca7eef4c516b2420d4822d37
7
- data.tar.gz: a6419b79bda3b8009678e08ce15777aa914ad58773e857e5b58fb0e6f05c0dc3921dbfe13baa587177d5d49beda88336cbfe82cb4ce9a54b08f2cfd2c0abe9fb
6
+ metadata.gz: a54f3a0c8308f70be7bd76404878dff6d61407f1100c859f4aca0564819dcb0b37c788c287f3d53bf7a584ce419050aedd1cd067d61ce8b8a0921f5738cacc4f
7
+ data.tar.gz: bdba4aa9e98ac3e9b4480ed039f56772663ff6e5111dde4cc548bf4472a924bb1d0957f069b22ebd6082f9aca26dabf962766669c36284b81a1b883ff2e4f7c7
data/.gitignore CHANGED
@@ -37,3 +37,4 @@
37
37
  *.a
38
38
  mkmf.log
39
39
  log
40
+ .idea
data/README.md CHANGED
@@ -75,12 +75,26 @@ Until now I´ve been able to implement the following features:
75
75
  + **default_loading_placeholder:** image placeholder to show when uploaded/pasted images are loading , defaults to a grey background
76
76
  + **disable_title** default: false, will hide the initial heading placeholder for initial text
77
77
  + **title_placeholder** default: 'Title'
78
+ + **title** default: none, pass a pre-existing title to the editor here
78
79
  + **body_placeholder** default: 'Tell your story…'
79
80
  + **embed_placeholder** default: 'Paste a YouTube, Vine, Vimeo, or other video link, and press Enter'
80
81
  + **extract_placeholder** default: 'Paste a link to embed content from another site (e.g. Twitter) and press Enter'
81
82
  + **base_widgets:** default: ["uploader", "embed", "embed-extract"],
82
83
  + **extra_tooltip_widgets:** and array of new Dante.TooltipWidget instances.
83
84
 
85
+ ### Initialization
86
+
87
+ #### title
88
+ Use the title option in the initializer to pass a title to Dante.
89
+
90
+ #### body
91
+ Use the following code to get your text into the Dante editor's body:
92
+ ```html
93
+
94
+ <div id="editor editable" > <%= clean_dante_post( @post.excerpt ).try(:html_safe) %> </div>
95
+
96
+ ```
97
+
84
98
  ### Rails / AssetPippeline
85
99
 
86
100
  in Gemfile
@@ -3,6 +3,16 @@ utils = Dante.utils
3
3
 
4
4
  class Dante.Editor extends Dante.View
5
5
 
6
+ #Named constants for javascript key codes
7
+ BACKSPACE = 8
8
+ TAB = 9
9
+ ENTER = 13
10
+ SPACEBAR = 32
11
+ LEFTARROW = 37
12
+ UPARROW = 38
13
+ RIGHTARROW = 39
14
+ DOWNARROW = 40
15
+
6
16
  events:
7
17
  "mouseup" : "handleMouseUp"
8
18
  "keydown" : "handleKeyDown"
@@ -56,6 +66,8 @@ class Dante.Editor extends Dante.View
56
66
 
57
67
  titleplaceholder = opts.title_placeholder || 'Title'
58
68
  @title_placeholder = "<span class='defaultValue defaultValue--root'>#{titleplaceholder}</span><br>"
69
+ title = opts.title || ''
70
+ @title = title
59
71
  bodyplaceholder = opts.body_placeholder || 'Tell your story…'
60
72
  @body_placeholder = "<span class='defaultValue defaultValue--root'>#{bodyplaceholder}</span><br>"
61
73
  embedplaceholder = opts.embed_placeholder || 'Paste a YouTube, Vine, Vimeo, or other video link, and press Enter'
@@ -70,6 +82,7 @@ class Dante.Editor extends Dante.View
70
82
  #TODO: this could be a hash to access widgets without var
71
83
  #Base widgets
72
84
  base_widgets = opts.base_widgets
85
+ self = @
73
86
 
74
87
  if base_widgets.indexOf("uploader") >= 0
75
88
  @uploader_widget = new Dante.View.TooltipWidget.Uploader(current_editor: @)
@@ -86,6 +99,8 @@ class Dante.Editor extends Dante.View
86
99
  #add extra widgets
87
100
  if opts.extra_tooltip_widgets
88
101
  _.each opts.extra_tooltip_widgets, (w)=>
102
+ if !w.current_editor
103
+ w.current_editor = self
89
104
  @widgets.push w
90
105
 
91
106
  store: ()->
@@ -117,7 +132,7 @@ class Dante.Editor extends Dante.View
117
132
  $(@el).find(".section-inner").html()
118
133
 
119
134
  renderTitle: ()->
120
- "<h3 class='graf graf--h3'>#{@title_placeholder} </h3>"
135
+ "<h3 class='graf graf--h3'>#{if @title.length > 0 then @title else @title_placeholder}</h3>"
121
136
 
122
137
  template: ()=>
123
138
  "<section class='section--first section--last'>
@@ -646,12 +661,12 @@ class Dante.Editor extends Dante.View
646
661
 
647
662
  @markAsSelected( anchor_node ) if anchor_node
648
663
 
649
- if e.which is 9
664
+ if e.which is TAB
650
665
 
651
666
  @handleTab(anchor_node)
652
667
  return false
653
668
 
654
- if e.which == 13
669
+ if e.which == ENTER
655
670
 
656
671
  #removes previous selected nodes
657
672
  $(@el).find(".is-selected").removeClass("is-selected")
@@ -718,7 +733,8 @@ class Dante.Editor extends Dante.View
718
733
  , 2
719
734
 
720
735
  #delete key
721
- if (e.which == 8)
736
+ if (e.which == BACKSPACE)
737
+ eventHandled = false;
722
738
  @tooltip_view.hide()
723
739
  utils.log("removing from down")
724
740
  utils.log "REACHED TOP" if @reachedTop
@@ -728,9 +744,29 @@ class Dante.Editor extends Dante.View
728
744
  anchor_node = @getNode()
729
745
  utils_anchor_node = utils.getNode()
730
746
 
747
+ utils.log(anchor_node);
748
+ utils.log(utils_anchor_node);
749
+
750
+ #check if any of the widgets can handle a backspace keydown
751
+ utils.log("HANDLING WIDGET BACKSPACES");
752
+ _.each @widgets, (w)=>
753
+ if w.handleBackspaceKey && !handled
754
+ handled = w.handleBackspaceKey(e, anchor_node);
755
+
756
+ if (eventHandled)
757
+ e.preventDefault();
758
+ return false;
759
+
731
760
  if(parent.hasClass("graf--li") and @getCharacterPrecedingCaret().length is 0)
732
761
  return this.handleListBackspace(parent, e);
733
762
 
763
+ #select an image if backspacing into it from a paragraph
764
+ if($(anchor_node).hasClass("graf--p") && @isFirstChar)
765
+ if($(anchor_node).prev().hasClass("graf--figure"))
766
+ e.preventDefault();
767
+ $(anchor_node).prev().find("img").click();
768
+ utils.log("Focus on the previous image")
769
+
734
770
  if $(utils_anchor_node).hasClass("section-content") || $(utils_anchor_node).hasClass("graf--first")
735
771
  utils.log "SECTION DETECTED FROM KEYDOWN #{_.isEmpty($(utils_anchor_node).text())}"
736
772
  return false if _.isEmpty($(utils_anchor_node).text())
@@ -752,21 +788,15 @@ class Dante.Editor extends Dante.View
752
788
  if $(anchor_node).prev().hasClass("graf--mixtapeEmbed")
753
789
  return false if @isFirstChar() && !_.isEmpty( $(anchor_node).text().trim() )
754
790
 
755
- #remove graf figure is is selected but not in range (not focus on caption)
756
- if $(".is-selected").hasClass("graf--figure") && !anchor_node?
757
- @replaceWith("p", $(".is-selected"))
758
- @setRangeAt($(".is-selected")[0])
759
- return false
760
-
761
791
  #spacebar
762
- if (e.which == 32)
792
+ if (e.which == SPACEBAR)
763
793
  utils.log("SPACEBAR")
764
794
  if (parent.hasClass("graf--p"))
765
795
  @handleSmartList(parent, e)
766
796
  #arrows key
767
797
  #if _.contains([37,38,39,40], e.which)
768
798
  #up & down
769
- if _.contains([38, 40], e.which)
799
+ if _.contains([UPARROW, DOWNARROW], e.which)
770
800
  utils.log e.which
771
801
  @handleArrowForKeyDown(e)
772
802
  #return false
@@ -800,11 +830,11 @@ class Dante.Editor extends Dante.View
800
830
 
801
831
  @handleTextSelection(anchor_node)
802
832
 
803
- if (_.contains([8, 32, 13], e.which))
833
+ if (_.contains([BACKSPACE, SPACEBAR, ENTER], e.which))
804
834
  if $(anchor_node).hasClass("graf--li")
805
835
  @removeSpanTag($(anchor_node));
806
836
 
807
- if (e.which == 8)
837
+ if (e.which == BACKSPACE)
808
838
 
809
839
  #if detect all text deleted , re render
810
840
  if $(utils_anchor_node).hasClass("postField--body")
@@ -846,7 +876,7 @@ class Dante.Editor extends Dante.View
846
876
 
847
877
 
848
878
  #arrows key
849
- if _.contains([37,38,39,40], e.which)
879
+ if _.contains([LEFTARROW, UPARROW, RIGHTARROW, DOWNARROW], e.which)
850
880
  @handleArrow(e)
851
881
  #return false
852
882
 
@@ -222,3 +222,26 @@ class Dante.View.TooltipWidget.Uploader extends Dante.View.TooltipWidget
222
222
  uploadCompleted: (url, node)=>
223
223
  node.find("img").attr("src", url)
224
224
  #return false
225
+
226
+ ###
227
+ # Handles the behavior of deleting images when using the backspace key
228
+ #
229
+ # @param {Event} e - The backspace event that is being handled
230
+ # @param {Node} node - The node the backspace was used in, assumed to be from te editor's getNode() function
231
+ #
232
+ # @return {Boolean} true if this function handled the backspace event, otherwise false
233
+ ###
234
+ handleBackspaceKey: (e, node) =>
235
+
236
+ #remove graf figure is is selected but not in range (not focus on caption)
237
+ if $(".is-selected").hasClass("graf--figure") && !anchor_node?
238
+ utils.log("Replacing selected node")
239
+ @current_editor.replaceWith("p", $(".is-selected"))
240
+
241
+ e.preventDefault() #without this line, the browser may interpret the backspace as a "go pack a page" command
242
+
243
+ @current_editor.setRangeAt($(".is-selected")[0])
244
+ return true
245
+
246
+ return false
247
+
data/bower.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name" : "dante",
3
3
  "description": "Just another Medium editor clone.",
4
4
  "homepage": "michelson.github.io/Dante/",
5
- "version" : "0.0.12",
5
+ "version" : "0.0.13",
6
6
  "keywords": [
7
7
  "css",
8
8
  "sass",
@@ -8,7 +8,7 @@
8
8
  defaults: {
9
9
  image_placeholder: '../images/dante/media-loading-placeholder.png'
10
10
  },
11
- version: "0.0.12"
11
+ version: "0.0.13"
12
12
  };
13
13
 
14
14
  }).call(this);
@@ -432,6 +432,8 @@
432
432
  utils = Dante.utils;
433
433
 
434
434
  Dante.Editor = (function(_super) {
435
+ var BACKSPACE, DOWNARROW, ENTER, LEFTARROW, RIGHTARROW, SPACEBAR, TAB, UPARROW;
436
+
435
437
  __extends(Editor, _super);
436
438
 
437
439
  function Editor() {
@@ -452,6 +454,22 @@
452
454
  return Editor.__super__.constructor.apply(this, arguments);
453
455
  }
454
456
 
457
+ BACKSPACE = 8;
458
+
459
+ TAB = 9;
460
+
461
+ ENTER = 13;
462
+
463
+ SPACEBAR = 32;
464
+
465
+ LEFTARROW = 37;
466
+
467
+ UPARROW = 38;
468
+
469
+ RIGHTARROW = 39;
470
+
471
+ DOWNARROW = 40;
472
+
455
473
  Editor.prototype.events = {
456
474
  "mouseup": "handleMouseUp",
457
475
  "keydown": "handleKeyDown",
@@ -470,7 +488,7 @@
470
488
  };
471
489
 
472
490
  Editor.prototype.initialize = function(opts) {
473
- var bodyplaceholder, embedplaceholder, extractplaceholder, titleplaceholder;
491
+ var bodyplaceholder, embedplaceholder, extractplaceholder, title, titleplaceholder;
474
492
  if (opts == null) {
475
493
  opts = {};
476
494
  }
@@ -503,6 +521,8 @@
503
521
  this.store();
504
522
  titleplaceholder = opts.title_placeholder || 'Title';
505
523
  this.title_placeholder = "<span class='defaultValue defaultValue--root'>" + titleplaceholder + "</span><br>";
524
+ title = opts.title || '';
525
+ this.title = title;
506
526
  bodyplaceholder = opts.body_placeholder || 'Tell your story…';
507
527
  this.body_placeholder = "<span class='defaultValue defaultValue--root'>" + bodyplaceholder + "</span><br>";
508
528
  embedplaceholder = opts.embed_placeholder || 'Paste a YouTube, Vine, Vimeo, or other video link, and press Enter';
@@ -513,8 +533,9 @@
513
533
  };
514
534
 
515
535
  Editor.prototype.initializeWidgets = function(opts) {
516
- var base_widgets;
536
+ var base_widgets, self;
517
537
  base_widgets = opts.base_widgets;
538
+ self = this;
518
539
  if (base_widgets.indexOf("uploader") >= 0) {
519
540
  this.uploader_widget = new Dante.View.TooltipWidget.Uploader({
520
541
  current_editor: this
@@ -536,6 +557,9 @@
536
557
  if (opts.extra_tooltip_widgets) {
537
558
  return _.each(opts.extra_tooltip_widgets, (function(_this) {
538
559
  return function(w) {
560
+ if (!w.current_editor) {
561
+ w.current_editor = self;
562
+ }
539
563
  return _this.widgets.push(w);
540
564
  };
541
565
  })(this));
@@ -584,7 +608,7 @@
584
608
  };
585
609
 
586
610
  Editor.prototype.renderTitle = function() {
587
- return "<h3 class='graf graf--h3'>" + this.title_placeholder + " </h3>";
611
+ return "<h3 class='graf graf--h3'>" + (this.title.length > 0 ? this.title : this.title_placeholder) + "</h3>";
588
612
  };
589
613
 
590
614
  Editor.prototype.template = function() {
@@ -1185,18 +1209,18 @@
1185
1209
  };
1186
1210
 
1187
1211
  Editor.prototype.handleKeyDown = function(e) {
1188
- var anchor_node, li, parent, utils_anchor_node;
1212
+ var anchor_node, eventHandled, li, parent, utils_anchor_node;
1189
1213
  utils.log("KEYDOWN");
1190
1214
  anchor_node = this.getNode();
1191
1215
  parent = $(anchor_node);
1192
1216
  if (anchor_node) {
1193
1217
  this.markAsSelected(anchor_node);
1194
1218
  }
1195
- if (e.which === 9) {
1219
+ if (e.which === TAB) {
1196
1220
  this.handleTab(anchor_node);
1197
1221
  return false;
1198
1222
  }
1199
- if (e.which === 13) {
1223
+ if (e.which === ENTER) {
1200
1224
  $(this.el).find(".is-selected").removeClass("is-selected");
1201
1225
  utils.log(this.isLastChar());
1202
1226
  if (parent.hasClass("graf--p")) {
@@ -1262,7 +1286,8 @@
1262
1286
  };
1263
1287
  })(this), 2);
1264
1288
  }
1265
- if (e.which === 8) {
1289
+ if (e.which === BACKSPACE) {
1290
+ eventHandled = false;
1266
1291
  this.tooltip_view.hide();
1267
1292
  utils.log("removing from down");
1268
1293
  if (this.reachedTop) {
@@ -1274,9 +1299,31 @@
1274
1299
  utils.log("pass initial validations");
1275
1300
  anchor_node = this.getNode();
1276
1301
  utils_anchor_node = utils.getNode();
1302
+ utils.log(anchor_node);
1303
+ utils.log(utils_anchor_node);
1304
+ utils.log("HANDLING WIDGET BACKSPACES");
1305
+ _.each(this.widgets, (function(_this) {
1306
+ return function(w) {
1307
+ var handled;
1308
+ if (w.handleBackspaceKey && !handled) {
1309
+ return handled = w.handleBackspaceKey(e, anchor_node);
1310
+ }
1311
+ };
1312
+ })(this));
1313
+ if (eventHandled) {
1314
+ e.preventDefault();
1315
+ return false;
1316
+ }
1277
1317
  if (parent.hasClass("graf--li") && this.getCharacterPrecedingCaret().length === 0) {
1278
1318
  return this.handleListBackspace(parent, e);
1279
1319
  }
1320
+ if ($(anchor_node).hasClass("graf--p") && this.isFirstChar) {
1321
+ if ($(anchor_node).prev().hasClass("graf--figure")) {
1322
+ e.preventDefault();
1323
+ $(anchor_node).prev().find("img").click();
1324
+ utils.log("Focus on the previous image");
1325
+ }
1326
+ }
1280
1327
  if ($(utils_anchor_node).hasClass("section-content") || $(utils_anchor_node).hasClass("graf--first")) {
1281
1328
  utils.log("SECTION DETECTED FROM KEYDOWN " + (_.isEmpty($(utils_anchor_node).text())));
1282
1329
  if (_.isEmpty($(utils_anchor_node).text())) {
@@ -1301,19 +1348,14 @@
1301
1348
  return false;
1302
1349
  }
1303
1350
  }
1304
- if ($(".is-selected").hasClass("graf--figure") && (anchor_node == null)) {
1305
- this.replaceWith("p", $(".is-selected"));
1306
- this.setRangeAt($(".is-selected")[0]);
1307
- return false;
1308
- }
1309
1351
  }
1310
- if (e.which === 32) {
1352
+ if (e.which === SPACEBAR) {
1311
1353
  utils.log("SPACEBAR");
1312
1354
  if (parent.hasClass("graf--p")) {
1313
1355
  this.handleSmartList(parent, e);
1314
1356
  }
1315
1357
  }
1316
- if (_.contains([38, 40], e.which)) {
1358
+ if (_.contains([UPARROW, DOWNARROW], e.which)) {
1317
1359
  utils.log(e.which);
1318
1360
  this.handleArrowForKeyDown(e);
1319
1361
  }
@@ -1343,12 +1385,12 @@
1343
1385
  anchor_node = this.getNode();
1344
1386
  utils_anchor_node = utils.getNode();
1345
1387
  this.handleTextSelection(anchor_node);
1346
- if (_.contains([8, 32, 13], e.which)) {
1388
+ if (_.contains([BACKSPACE, SPACEBAR, ENTER], e.which)) {
1347
1389
  if ($(anchor_node).hasClass("graf--li")) {
1348
1390
  this.removeSpanTag($(anchor_node));
1349
1391
  }
1350
1392
  }
1351
- if (e.which === 8) {
1393
+ if (e.which === BACKSPACE) {
1352
1394
  if ($(utils_anchor_node).hasClass("postField--body")) {
1353
1395
  utils.log("ALL GONE from UP");
1354
1396
  this.handleCompleteDeletion($(this.el));
@@ -1384,7 +1426,7 @@
1384
1426
  false;
1385
1427
  }
1386
1428
  }
1387
- if (_.contains([37, 38, 39, 40], e.which)) {
1429
+ if (_.contains([LEFTARROW, UPARROW, RIGHTARROW, DOWNARROW], e.which)) {
1388
1430
  return this.handleArrow(e);
1389
1431
  }
1390
1432
  };
@@ -1861,6 +1903,7 @@
1861
1903
  __extends(Uploader, _super);
1862
1904
 
1863
1905
  function Uploader() {
1906
+ this.handleBackspaceKey = __bind(this.handleBackspaceKey, this);
1864
1907
  this.uploadCompleted = __bind(this.uploadCompleted, this);
1865
1908
  this.updateProgressBar = __bind(this.updateProgressBar, this);
1866
1909
  this.uploadFile = __bind(this.uploadFile, this);
@@ -2113,6 +2156,27 @@
2113
2156
  return node.find("img").attr("src", url);
2114
2157
  };
2115
2158
 
2159
+
2160
+ /*
2161
+ * Handles the behavior of deleting images when using the backspace key
2162
+ *
2163
+ * @param {Event} e - The backspace event that is being handled
2164
+ * @param {Node} node - The node the backspace was used in, assumed to be from te editor's getNode() function
2165
+ *
2166
+ * @return {Boolean} true if this function handled the backspace event, otherwise false
2167
+ */
2168
+
2169
+ Uploader.prototype.handleBackspaceKey = function(e, node) {
2170
+ if ($(".is-selected").hasClass("graf--figure") && (typeof anchor_node === "undefined" || anchor_node === null)) {
2171
+ utils.log("Replacing selected node");
2172
+ this.current_editor.replaceWith("p", $(".is-selected"));
2173
+ e.preventDefault();
2174
+ this.current_editor.setRangeAt($(".is-selected")[0]);
2175
+ return true;
2176
+ }
2177
+ return false;
2178
+ };
2179
+
2116
2180
  return Uploader;
2117
2181
 
2118
2182
  })(Dante.View.TooltipWidget);
@@ -1,5 +1,5 @@
1
1
  require "dante-editor/version"
2
2
 
3
3
  module DanteEditor
4
- VERSION = "0.0.12"
4
+ VERSION = "0.0.13"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dante-editor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.12
4
+ version: 0.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miguel Michelson
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-04-22 00:00:00.000000000 Z
12
+ date: 2015-05-29 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: dante-editor yet another Medium editor clone.
15
15
  email: