dante-editor 0.0.15 → 0.1.0
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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +49 -10
- data/app/assets/fonts/dante/dante.eot +0 -0
- data/app/assets/fonts/dante/dante.svg +9 -5
- data/app/assets/fonts/dante/dante.ttf +0 -0
- data/app/assets/fonts/dante/dante.woff +0 -0
- data/app/assets/javascripts/dante/behavior.js.coffee +2 -0
- data/app/assets/javascripts/dante/behaviors/image.js.coffee +56 -0
- data/app/assets/javascripts/dante/behaviors/list.js.coffee +150 -0
- data/app/assets/javascripts/dante/behaviors/save.js.coffee +40 -0
- data/app/assets/javascripts/dante/behaviors/suggest.js.coffee +118 -0
- data/app/assets/javascripts/dante/editor.js.coffee +110 -228
- data/app/assets/javascripts/dante/popover.js.coffee +350 -11
- data/app/assets/javascripts/dante/tooltip_widgets/uploader.js.coffee +2 -2
- data/app/assets/javascripts/dante.js +5 -0
- data/app/assets/stylesheets/dante/_blame.scss +209 -0
- data/app/assets/stylesheets/dante/_caption.scss +14 -0
- data/app/assets/stylesheets/dante/_icons.scss +10 -5
- data/app/assets/stylesheets/dante/_menu.scss +7 -7
- data/app/assets/stylesheets/dante/_popover.scss +122 -44
- data/app/assets/stylesheets/dante/_utilities.scss +5 -1
- data/app/assets/stylesheets/dante/_variables.scss +7 -3
- data/app/assets/stylesheets/dante.scss +2 -0
- data/config.rb +5 -4
- data/dist/css/dante-editor.css +246 -44
- data/dist/fonts/dante/dante.eot +0 -0
- data/dist/fonts/dante/dante.svg +9 -5
- data/dist/fonts/dante/dante.ttf +0 -0
- data/dist/fonts/dante/dante.woff +0 -0
- data/dist/js/dante-editor.js +1015 -283
- data/lib/dante-editor/version.rb +1 -1
- data/source/api/cristian.json.erb +8 -0
- data/source/api/miguel.json.erb +8 -0
- data/source/api/resource.json.erb +8 -0
- data/source/api/save.json.erb +1 -0
- data/source/api/suggest.json.erb +22 -0
- data/source/assets/images/dante-demo.png +0 -0
- data/source/icons/image-center.svg +12 -0
- data/source/icons/image-fill.svg +11 -0
- data/source/icons/image-left.svg +15 -0
- data/source/icons/image-wide.svg +12 -0
- data/source/index.html.erb +6 -0
- data/source/partials/_readme.markdown +2 -2
- metadata +18 -2
@@ -17,17 +17,13 @@ class Dante.Editor extends Dante.View
|
|
17
17
|
"mouseup" : "handleMouseUp"
|
18
18
|
"keydown" : "handleKeyDown"
|
19
19
|
"keyup" : "handleKeyUp"
|
20
|
+
"keypress" : "handleKeyPress"
|
20
21
|
"paste" : "handlePaste"
|
21
22
|
"dblclick" : "handleDblclick"
|
22
23
|
"dragstart": "handleDrag"
|
23
24
|
"drop" : "handleDrag"
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
"mouseover .graf--figure.graf--iframe" : "handleGrafFigureSelectIframe"
|
28
|
-
"mouseleave .graf--figure.graf--iframe" : "handleGrafFigureUnSelectIframe"
|
29
|
-
"keyup .graf--figure figcaption" : "handleGrafCaptionTyping"
|
30
|
-
|
25
|
+
|
26
|
+
# TODO: this events should be in tooltip class
|
31
27
|
"mouseover .markup--anchor" : "displayPopOver"
|
32
28
|
"mouseout .markup--anchor" : "hidePopOver"
|
33
29
|
|
@@ -37,33 +33,42 @@ class Dante.Editor extends Dante.View
|
|
37
33
|
@initial_html = $(@el).html()
|
38
34
|
@current_range = null
|
39
35
|
@current_node = null
|
36
|
+
|
40
37
|
@el = opts.el || "#editor"
|
38
|
+
|
41
39
|
@upload_url = opts.upload_url || "/uploads.json"
|
42
40
|
@upload_callback = opts.upload_callback
|
43
41
|
@oembed_url = opts.oembed_url || "http://api.embed.ly/1/oembed?url="
|
44
42
|
@extract_url = opts.extract_url || "http://api.embed.ly/1/extract?key=86c28a410a104c8bb58848733c82f840&url="
|
45
43
|
@default_loading_placeholder = opts.default_loading_placeholder || Dante.defaults.image_placeholder
|
44
|
+
|
46
45
|
@store_url = opts.store_url
|
47
46
|
@store_method = opts.store_method || "POST"
|
47
|
+
@store_success_handler = opts.store_success_handler
|
48
|
+
|
48
49
|
@spell_check = opts.spellcheck || false
|
49
50
|
@disable_title = opts.disable_title || false
|
50
|
-
@store_interval = opts.store_interval ||
|
51
|
+
@store_interval = opts.store_interval || 1500
|
51
52
|
@paste_element_id = "#dante-paste-div"
|
52
53
|
@tooltip_class = opts.tooltip_class || Dante.Editor.Tooltip
|
54
|
+
|
55
|
+
# suggest feature options
|
56
|
+
@suggest_url = opts.suggest_url || "/api/suggest.json"
|
57
|
+
@suggest_query_param = opts.suggest_query_param || "q"
|
58
|
+
@suggest_query_timeout = opts.suggest_query_timeout || 300
|
59
|
+
@suggest_handler = opts.suggest_handler || null
|
60
|
+
@suggest_resource_handler = opts.suggest_resource_handler || null
|
61
|
+
|
62
|
+
opts.base_widgets ||= ["uploader", "embed", "embed_extract"]
|
63
|
+
opts.base_behaviors ||= ["save", "image","list", "suggest"]
|
53
64
|
|
54
|
-
|
55
|
-
|
56
|
-
@widgets = []
|
65
|
+
@widgets = []
|
66
|
+
@behaviors = []
|
57
67
|
|
58
68
|
window.debugMode = opts.debug || false
|
59
69
|
|
60
70
|
$(@el).addClass("debug") if window.debugMode
|
61
71
|
|
62
|
-
if (localStorage.getItem('contenteditable'))
|
63
|
-
$(@el).html localStorage.getItem('contenteditable')
|
64
|
-
|
65
|
-
@store()
|
66
|
-
|
67
72
|
titleplaceholder = opts.title_placeholder || 'Title'
|
68
73
|
@title_placeholder = "<span class='defaultValue defaultValue--root'>#{titleplaceholder}</span><br>"
|
69
74
|
title = opts.title || ''
|
@@ -74,9 +79,36 @@ class Dante.Editor extends Dante.View
|
|
74
79
|
@embed_placeholder = "<span class='defaultValue defaultValue--root'>#{embedplaceholder}</span><br>"
|
75
80
|
extractplaceholder = opts.extract_placeholder|| "Paste a link to embed content from another site (e.g. Twitter) and press Enter"
|
76
81
|
@extract_placeholder= "<span class='defaultValue defaultValue--root'>#{extractplaceholder}</span><br>"
|
77
|
-
|
82
|
+
|
78
83
|
@initializeWidgets(opts)
|
79
84
|
|
85
|
+
initializeBehaviors: (opts)->
|
86
|
+
base_behaviors = opts.base_behaviors
|
87
|
+
self = @
|
88
|
+
|
89
|
+
if base_behaviors.indexOf("suggest") >= 0
|
90
|
+
@suggest_behavior = new Dante.View.Behavior.Suggest(current_editor: @, el: @el)
|
91
|
+
@behaviors.push @suggest_behavior
|
92
|
+
|
93
|
+
if base_behaviors.indexOf("save") >= 0
|
94
|
+
@save_behavior = new Dante.View.Behavior.Save(current_editor: @, el: @el)
|
95
|
+
@behaviors.push @save_behavior
|
96
|
+
|
97
|
+
if base_behaviors.indexOf("image") >= 0
|
98
|
+
@save_behavior = new Dante.View.Behavior.Image(current_editor: @, el: @el)
|
99
|
+
@behaviors.push @save_behavior
|
100
|
+
|
101
|
+
if base_behaviors.indexOf("list") >= 0
|
102
|
+
@save_behavior = new Dante.View.Behavior.List(current_editor: @, el: @el)
|
103
|
+
@behaviors.push @save_behavior
|
104
|
+
|
105
|
+
#add extra behaviors
|
106
|
+
if opts.extra_behaviors
|
107
|
+
_.each opts.extra_behaviors, (w)=>
|
108
|
+
if !w.current_editor
|
109
|
+
w.current_editor = self
|
110
|
+
@behaviors.push w
|
111
|
+
|
80
112
|
initializeWidgets: (opts)->
|
81
113
|
#TODO: this could be a hash to access widgets without var
|
82
114
|
#Base widgets
|
@@ -102,31 +134,6 @@ class Dante.Editor extends Dante.View
|
|
102
134
|
w.current_editor = self
|
103
135
|
@widgets.push w
|
104
136
|
|
105
|
-
store: ()->
|
106
|
-
#localStorage.setItem("contenteditable", $(@el).html() )
|
107
|
-
return unless @store_url
|
108
|
-
setTimeout ()=>
|
109
|
-
@checkforStore()
|
110
|
-
, @store_interval
|
111
|
-
|
112
|
-
checkforStore: ()->
|
113
|
-
if @content is @getContent()
|
114
|
-
utils.log "content not changed skip store"
|
115
|
-
@store()
|
116
|
-
else
|
117
|
-
utils.log "content changed! update"
|
118
|
-
@content = @getContent()
|
119
|
-
$.ajax
|
120
|
-
url: @store_url
|
121
|
-
method: @store_method
|
122
|
-
data:
|
123
|
-
body: @getContent()
|
124
|
-
success: (res)->
|
125
|
-
utils.log "store!"
|
126
|
-
utils.log res
|
127
|
-
complete: (jxhr) =>
|
128
|
-
@store()
|
129
|
-
|
130
137
|
getContent: ()->
|
131
138
|
$(@el).find(".section-inner").html()
|
132
139
|
|
@@ -159,6 +166,17 @@ class Dante.Editor extends Dante.View
|
|
159
166
|
@tooltip_view = new @tooltip_class(editor: @ , widgets: @widgets)
|
160
167
|
@pop_over = new Dante.Editor.PopOver(editor: @)
|
161
168
|
@pop_over.render().hide()
|
169
|
+
|
170
|
+
# TODO: this has to be pluggable too!
|
171
|
+
@pop_over_typeahead = new Dante.Editor.PopOverTypeAhead(editor: @)
|
172
|
+
@pop_over_typeahead.render().hide()
|
173
|
+
|
174
|
+
@pop_over_card = new Dante.Editor.PopOverCard(editor: @)
|
175
|
+
@pop_over_card.render().hide()
|
176
|
+
|
177
|
+
@pop_over_align = new Dante.Editor.ImageTooltip(editor: @)
|
178
|
+
@pop_over_align.render().hide()
|
179
|
+
|
162
180
|
@tooltip_view.render().hide()
|
163
181
|
|
164
182
|
appendInitialContent: ()=>
|
@@ -173,6 +191,7 @@ class Dante.Editor extends Dante.View
|
|
173
191
|
@appendMenus()
|
174
192
|
@appendInitialContent() unless _.isEmpty @initial_html.trim()
|
175
193
|
@parseInitialMess()
|
194
|
+
@initializeBehaviors(@editor_options)
|
176
195
|
|
177
196
|
restart: ()=>
|
178
197
|
@render()
|
@@ -196,6 +215,10 @@ class Dante.Editor extends Dante.View
|
|
196
215
|
else if (document.selection && document.selection.type != "Control")
|
197
216
|
selection = document.selection
|
198
217
|
|
218
|
+
getSelectionStart: ->
|
219
|
+
node = document.getSelection().anchorNode
|
220
|
+
if node.nodeType == 3 then node.parentNode else node
|
221
|
+
|
199
222
|
getRange: () ->
|
200
223
|
editor = $(@el)[0]
|
201
224
|
range = selection && selection.rangeCount && selection.getRangeAt(0)
|
@@ -290,12 +313,12 @@ class Dante.Editor extends Dante.View
|
|
290
313
|
return if @selection().rangeCount < 1
|
291
314
|
range = @selection().getRangeAt(0)
|
292
315
|
node = range.commonAncestorContainer
|
293
|
-
return null
|
316
|
+
return null if not node or node is root
|
294
317
|
|
295
318
|
#node = node.parentNode while node and (node.nodeType isnt 1) and (node.parentNode isnt root)
|
296
319
|
#node = node.parentNode while node and (node.parentNode isnt root)
|
297
320
|
|
298
|
-
node = node.parentNode
|
321
|
+
node = node.parentNode while node and (node.nodeType isnt 1 or not $(node).hasClass("graf")) and (node.parentNode isnt root)
|
299
322
|
if not $(node).hasClass("graf--li")
|
300
323
|
node = node.parentNode while node and (node.parentNode isnt root)
|
301
324
|
|
@@ -312,19 +335,13 @@ class Dante.Editor extends Dante.View
|
|
312
335
|
handleDrag: ()->
|
313
336
|
return false
|
314
337
|
|
315
|
-
|
316
|
-
if _.isEmpty(utils.getNode().textContent.trim())
|
317
|
-
$(@getNode()).addClass("is-defaultValue")
|
318
|
-
else
|
319
|
-
$(@getNode()).removeClass("is-defaultValue")
|
320
|
-
|
321
|
-
#get text of selected and displays menu
|
338
|
+
# get text of selected and displays menu
|
322
339
|
handleTextSelection: (anchor_node)->
|
323
340
|
@editor_menu.hide()
|
324
341
|
text = @getSelectedText()
|
325
342
|
if !$(anchor_node).is(".graf--mixtapeEmbed, .graf--figure") && !_.isEmpty text.trim()
|
326
|
-
|
327
|
-
|
343
|
+
@current_node = anchor_node
|
344
|
+
@.displayMenu()
|
328
345
|
|
329
346
|
relocateMenu: (position)->
|
330
347
|
height = @editor_menu.$el.outerHeight()
|
@@ -346,32 +363,6 @@ class Dante.Editor extends Dante.View
|
|
346
363
|
hidePopOver: (ev)->
|
347
364
|
@pop_over.hide(ev)
|
348
365
|
|
349
|
-
handleGrafFigureSelectImg: (ev)->
|
350
|
-
utils.log "FIGURE SELECT"
|
351
|
-
element = ev.currentTarget
|
352
|
-
@markAsSelected( element )
|
353
|
-
$(element).parent(".graf--figure").addClass("is-selected is-mediaFocused")
|
354
|
-
@selection().removeAllRanges()
|
355
|
-
|
356
|
-
handleGrafFigureSelectIframe: (ev)->
|
357
|
-
utils.log "FIGURE IFRAME SELECT"
|
358
|
-
element = ev.currentTarget
|
359
|
-
@iframeSelected = element
|
360
|
-
@markAsSelected( element )
|
361
|
-
$(element).addClass("is-selected is-mediaFocused")
|
362
|
-
@selection().removeAllRanges()
|
363
|
-
|
364
|
-
handleGrafFigureUnSelectIframe: (ev)->
|
365
|
-
utils.log "FIGURE IFRAME UNSELECT"
|
366
|
-
element = ev.currentTarget
|
367
|
-
@iframeSelected = null
|
368
|
-
$(element).removeClass("is-selected is-mediaFocused")
|
369
|
-
|
370
|
-
handleGrafFigureSelectCaption: (ev)->
|
371
|
-
utils.log "FIGCAPTION"
|
372
|
-
element = ev.currentTarget
|
373
|
-
$(element).parent(".graf--figure").removeClass("is-mediaFocused")
|
374
|
-
|
375
366
|
handleMouseUp: (ev)=>
|
376
367
|
utils.log "MOUSE UP"
|
377
368
|
anchor_node = @getNode()
|
@@ -566,7 +557,7 @@ class Dante.Editor extends Dante.View
|
|
566
557
|
return false # Prevent the default handler from running.
|
567
558
|
|
568
559
|
handleUnwrappedImages: (elements)->
|
569
|
-
#http://stackoverflow.com/questions/4998908/convert-data-uri-to-file-then-append-to-formdata
|
560
|
+
# http://stackoverflow.com/questions/4998908/convert-data-uri-to-file-then-append-to-formdata
|
570
561
|
_.each elements.find("img"), (image)=>
|
571
562
|
utils.log ("process image here!")
|
572
563
|
@uploader_widget.uploadExistentImage(image)
|
@@ -578,9 +569,9 @@ class Dante.Editor extends Dante.View
|
|
578
569
|
@setRangeAt($(element).prev()[0])
|
579
570
|
$(element).remove()
|
580
571
|
|
581
|
-
#TODO: not used anymore, remove this
|
582
|
-
#when found that the current node is text node
|
583
|
-
#create a new <p> and focus
|
572
|
+
# TODO: not used anymore, remove this
|
573
|
+
# when found that the current node is text node
|
574
|
+
# create a new <p> and focus
|
584
575
|
handleUnwrappedNode: (element)->
|
585
576
|
tmpl = $(@baseParagraphTmpl())
|
586
577
|
@setElementName(tmpl)
|
@@ -672,6 +663,13 @@ class Dante.Editor extends Dante.View
|
|
672
663
|
|
673
664
|
@markAsSelected( anchor_node ) if anchor_node
|
674
665
|
|
666
|
+
#handle keyups for each widget
|
667
|
+
utils.log("HANDLING Behavior KEYDOWN");
|
668
|
+
|
669
|
+
_.each @behaviors, (b)=>
|
670
|
+
if b.handleKeyDown
|
671
|
+
b.handleKeyDown(e, parent);
|
672
|
+
|
675
673
|
if e.which is TAB
|
676
674
|
@handleTab(anchor_node)
|
677
675
|
return false
|
@@ -683,13 +681,6 @@ class Dante.Editor extends Dante.View
|
|
683
681
|
|
684
682
|
utils.log @isLastChar()
|
685
683
|
|
686
|
-
#smart list support
|
687
|
-
if parent.hasClass("graf--p")
|
688
|
-
li = @handleSmartList(parent, e)
|
689
|
-
anchor_node = li if li
|
690
|
-
else if parent.hasClass("graf--li")
|
691
|
-
@handleListLineBreak(parent, e)
|
692
|
-
|
693
684
|
#handle keydowns for each widget
|
694
685
|
utils.log("HANDLING WIDGET KEYDOWNS");
|
695
686
|
_.each @widgets, (w)=>
|
@@ -724,7 +715,7 @@ class Dante.Editor extends Dante.View
|
|
724
715
|
setTimeout ()=>
|
725
716
|
node = @getNode()
|
726
717
|
return if _.isUndefined(node)
|
727
|
-
#set name on new element
|
718
|
+
# set name on new element
|
728
719
|
@setElementName($(node))
|
729
720
|
|
730
721
|
if node.nodeName.toLowerCase() is "div"
|
@@ -732,17 +723,17 @@ class Dante.Editor extends Dante.View
|
|
732
723
|
@markAsSelected( $(node) ) #if anchor_node
|
733
724
|
@setupFirstAndLast()
|
734
725
|
|
735
|
-
#empty childs if text is empty
|
726
|
+
# empty childs if text is empty
|
736
727
|
if _.isEmpty $(node).text().trim()
|
737
728
|
_.each $(node).children(), (n)->
|
738
729
|
$(n).remove()
|
739
730
|
$(node).append("<br>")
|
740
731
|
|
741
|
-
#shows tooltip
|
732
|
+
# shows tooltip
|
742
733
|
@displayTooltipAt($(@el).find(".is-selected"))
|
743
734
|
, 2
|
744
735
|
|
745
|
-
#delete key
|
736
|
+
# delete key
|
746
737
|
if (e.which is BACKSPACE)
|
747
738
|
eventHandled = false;
|
748
739
|
@tooltip_view.hide()
|
@@ -769,9 +760,6 @@ class Dante.Editor extends Dante.View
|
|
769
760
|
utils.log("SCAPE FROM BACKSPACE HANDLER")
|
770
761
|
return false;
|
771
762
|
|
772
|
-
if(parent.hasClass("graf--li") and @getCharacterPrecedingCaret().length is 0)
|
773
|
-
return this.handleListBackspace(parent, e);
|
774
|
-
|
775
763
|
#select an image if backspacing into it from a paragraph
|
776
764
|
if($(anchor_node).hasClass("graf--p") && @isFirstChar() )
|
777
765
|
if($(anchor_node).prev().hasClass("graf--figure") && @getSelectedText().length == 0)
|
@@ -784,11 +772,11 @@ class Dante.Editor extends Dante.View
|
|
784
772
|
return false if _.isEmpty($(utils_anchor_node).text())
|
785
773
|
|
786
774
|
if anchor_node && anchor_node.nodeType is 3
|
787
|
-
|
775
|
+
# @displayEmptyPlaceholder()
|
788
776
|
utils.log("TextNode detected from Down!")
|
789
777
|
#return false
|
790
778
|
|
791
|
-
#supress del into & delete embed if empty content found on delete key
|
779
|
+
# supress del into & delete embed if empty content found on delete key
|
792
780
|
if $(anchor_node).hasClass("graf--mixtapeEmbed") or $(anchor_node).hasClass("graf--iframe")
|
793
781
|
if _.isEmpty $(anchor_node).text().trim() or @isFirstChar()
|
794
782
|
utils.log("Check for inmediate deletion on empty embed text")
|
@@ -796,16 +784,10 @@ class Dante.Editor extends Dante.View
|
|
796
784
|
@handleInmediateDeletion($(anchor_node)) if @inmediateDeletion
|
797
785
|
return false
|
798
786
|
|
799
|
-
#TODO: supress del when the prev el is embed and current_node is at first char
|
787
|
+
# TODO: supress del when the prev el is embed and current_node is at first char
|
800
788
|
if $(anchor_node).prev().hasClass("graf--mixtapeEmbed")
|
801
789
|
return false if @isFirstChar() && !_.isEmpty( $(anchor_node).text().trim() )
|
802
790
|
|
803
|
-
#spacebar
|
804
|
-
if (e.which is SPACEBAR)
|
805
|
-
utils.log("SPACEBAR")
|
806
|
-
if (parent.hasClass("graf--p"))
|
807
|
-
@handleSmartList(parent, e)
|
808
|
-
|
809
791
|
#arrows key
|
810
792
|
#up & down
|
811
793
|
if _.contains([UPARROW, DOWNARROW], e.which)
|
@@ -833,7 +815,7 @@ class Dante.Editor extends Dante.View
|
|
833
815
|
utils.log "SKIP KEYUP"
|
834
816
|
return false
|
835
817
|
|
836
|
-
utils.log "KEYUP"
|
818
|
+
utils.log "ENTER KEYUP"
|
837
819
|
|
838
820
|
@editor_menu.hide() #hides menu just in case
|
839
821
|
@reachedTop = false
|
@@ -842,9 +824,11 @@ class Dante.Editor extends Dante.View
|
|
842
824
|
|
843
825
|
@handleTextSelection(anchor_node)
|
844
826
|
|
845
|
-
|
846
|
-
|
847
|
-
|
827
|
+
# handle keyups for each widget
|
828
|
+
utils.log("HANDLING Behavior KEYUPS");
|
829
|
+
_.each @behaviors, (b)=>
|
830
|
+
if b.handleKeyUp
|
831
|
+
b.handleKeyUp(e)
|
848
832
|
|
849
833
|
if (e.which == BACKSPACE)
|
850
834
|
|
@@ -886,13 +870,20 @@ class Dante.Editor extends Dante.View
|
|
886
870
|
# @setupFirstAndLast()
|
887
871
|
# @displayTooltipAt($(@el).find(".is-selected"))
|
888
872
|
|
889
|
-
|
890
873
|
#arrows key
|
891
874
|
if _.contains([LEFTARROW, UPARROW, RIGHTARROW, DOWNARROW], e.which)
|
892
875
|
@handleArrow(e)
|
893
876
|
#return false
|
894
877
|
|
895
|
-
|
878
|
+
handleKeyPress: (e, node)->
|
879
|
+
anchor_node = @getNode()
|
880
|
+
parent = $(anchor_node)
|
881
|
+
#handle keyups for each widget
|
882
|
+
utils.log("HANDLING Behavior KEYPRESS");
|
883
|
+
_.each @behaviors, (b)=>
|
884
|
+
if b.handleKeyPress
|
885
|
+
b.handleKeyPress(e, parent);
|
886
|
+
|
896
887
|
handleLineBreakWith: (element_type, from_element)->
|
897
888
|
new_paragraph = $("<#{element_type} class='graf graf--#{element_type} graf--empty is-selected'><br/></#{element_type}>")
|
898
889
|
if from_element.parent().is('[class^="graf--"]')
|
@@ -1017,9 +1008,7 @@ class Dante.Editor extends Dante.View
|
|
1017
1008
|
#, 20
|
1018
1009
|
|
1019
1010
|
cleanContents: (element)->
|
1020
|
-
#TODO: should config tags
|
1021
|
-
utils.log "ti"
|
1022
|
-
utils.log element
|
1011
|
+
# TODO: should config tags
|
1023
1012
|
if _.isUndefined(element)
|
1024
1013
|
element = $(@el).find('.section-inner')
|
1025
1014
|
else
|
@@ -1031,7 +1020,7 @@ class Dante.Editor extends Dante.View
|
|
1031
1020
|
|
1032
1021
|
attributes:
|
1033
1022
|
'__ALL__': ['class']
|
1034
|
-
a: ['href', 'title', 'target']
|
1023
|
+
a: ['href', 'title', 'target', 'data-id', 'data-type', 'data-href', 'data-avatar']
|
1035
1024
|
img: ['src']
|
1036
1025
|
|
1037
1026
|
protocols:
|
@@ -1102,9 +1091,10 @@ class Dante.Editor extends Dante.View
|
|
1102
1091
|
|
1103
1092
|
setupLink: (n)->
|
1104
1093
|
parent_name = $(n).parent().prop("tagName").toLowerCase()
|
1105
|
-
$(n).
|
1106
|
-
|
1107
|
-
|
1094
|
+
unless $(n).data("type") is "user"
|
1095
|
+
$(n).addClass("markup--anchor markup--#{parent_name}-anchor")
|
1096
|
+
href = $(n).attr("href")
|
1097
|
+
$(n).attr("data-href", href)
|
1108
1098
|
|
1109
1099
|
preCleanNode: (element)->
|
1110
1100
|
s = new Sanitize
|
@@ -1141,116 +1131,8 @@ class Dante.Editor extends Dante.View
|
|
1141
1131
|
setElementName: (element)->
|
1142
1132
|
$(element).attr("name", utils.generateUniqueName())
|
1143
1133
|
|
1144
|
-
#
|
1145
|
-
|
1146
|
-
listify: ($paragraph, listType, regex)->
|
1147
|
-
|
1148
|
-
utils.log "LISTIFY PARAGRAPH"
|
1149
|
-
|
1150
|
-
@removeSpanTag($paragraph);
|
1151
|
-
|
1152
|
-
content = $paragraph.html().replace(/ /g, " ").replace(regex, "")
|
1153
|
-
|
1154
|
-
switch(listType)
|
1155
|
-
when "ul" then $list = $("<ul></ul>")
|
1156
|
-
when "ol" then $list = $("<ol></ol>")
|
1157
|
-
else return false
|
1158
|
-
|
1159
|
-
@addClassesToElement($list[0])
|
1160
|
-
@replaceWith("li", $paragraph)
|
1161
|
-
$li = $(".is-selected")
|
1162
|
-
|
1163
|
-
@setElementName($li[0])
|
1164
|
-
|
1165
|
-
$li.html(content).wrap($list)
|
1166
|
-
|
1167
|
-
if($li.find("br").length == 0)
|
1168
|
-
$li.append("<br/>")
|
1169
|
-
|
1170
|
-
@setRangeAt($li[0])
|
1171
|
-
|
1172
|
-
$li[0]
|
1173
|
-
|
1174
|
-
handleSmartList: ($item, e)->
|
1175
|
-
utils.log("HANDLE A SMART LIST")
|
1176
|
-
|
1177
|
-
chars = @getCharacterPrecedingCaret()
|
1178
|
-
match = chars.match(/^\s*(\-|\*)\s*$/)
|
1179
|
-
if(match)
|
1180
|
-
utils.log("CREATING LIST ITEM")
|
1181
|
-
e.preventDefault()
|
1182
|
-
regex = new RegExp(/\s*(\-|\*)\s*/)
|
1183
|
-
$li = @listify($item, "ul", regex)
|
1184
|
-
else
|
1185
|
-
match = chars.match(/^\s*1(\.|\))\s*$/)
|
1186
|
-
if(match)
|
1187
|
-
utils.log("CREATING LIST ITEM")
|
1188
|
-
e.preventDefault()
|
1189
|
-
|
1190
|
-
regex = new RegExp(/\s*1(\.|\))\s*/)
|
1191
|
-
$li = @listify($item, "ol", regex)
|
1192
|
-
$li
|
1193
|
-
|
1194
|
-
handleListLineBreak: ($li, e)->
|
1195
|
-
utils.log("LIST LINE BREAK")
|
1196
|
-
@tooltip_view.hide()
|
1197
|
-
$list = $li.parent("ol, ul")
|
1198
|
-
$paragraph = $("<p></p>")
|
1199
|
-
utils.log($li.prev());
|
1200
|
-
if($list.children().length is 1 and $li.text() is "")
|
1201
|
-
@replaceWith("p", $list)
|
1202
|
-
|
1203
|
-
else if $li.text() is "" and ($li.next().length isnt 0)
|
1204
|
-
e.preventDefault()
|
1205
|
-
|
1206
|
-
else if ($li.next().length is 0)
|
1207
|
-
if($li.text() is "")
|
1208
|
-
e.preventDefault()
|
1209
|
-
utils.log("BREAK FROM LIST")
|
1210
|
-
$list.after($paragraph)
|
1211
|
-
$li.addClass("graf--removed").remove()
|
1212
|
-
|
1213
|
-
else if ($li.prev().length isnt 0 and $li.prev().text() is "" and @getCharacterPrecedingCaret() is "")
|
1214
|
-
e.preventDefault()
|
1215
|
-
utils.log("PREV IS EMPTY")
|
1216
|
-
content = $li.html()
|
1217
|
-
$list.after($paragraph)
|
1218
|
-
$li.prev().remove()
|
1219
|
-
$li.addClass("graf--removed").remove()
|
1220
|
-
$paragraph.html(content)
|
1221
|
-
|
1222
|
-
if $list and $list.children().length is 0 then $list.remove()
|
1223
|
-
|
1224
|
-
utils.log($li);
|
1225
|
-
if ($li.hasClass("graf--removed"))
|
1226
|
-
utils.log("ELEMENT REMOVED")
|
1227
|
-
@addClassesToElement($paragraph[0])
|
1228
|
-
@setRangeAt($paragraph[0])
|
1229
|
-
@markAsSelected($paragraph[0])
|
1230
|
-
@scrollTo($paragraph)
|
1231
|
-
|
1232
|
-
handleListBackspace: ($li, e)->
|
1233
|
-
|
1234
|
-
$list = $li.parent("ol, ul")
|
1235
|
-
utils.log("LIST BACKSPACE")
|
1236
|
-
|
1237
|
-
if($li.prev().length is 0)
|
1238
|
-
e.preventDefault()
|
1239
|
-
|
1240
|
-
$list.before($li)
|
1241
|
-
content = $li.html()
|
1242
|
-
@replaceWith("p", $li)
|
1243
|
-
$paragraph = $(".is-selected")
|
1244
|
-
$paragraph.removeClass("graf--empty").html(content).attr("name", utils.generateUniqueName());
|
1245
|
-
|
1246
|
-
if($list.children().length is 0)
|
1247
|
-
$list.remove()
|
1248
|
-
|
1249
|
-
@setupFirstAndLast()
|
1250
|
-
|
1251
|
-
#Remove Non-default Spans From Elements
|
1134
|
+
# Remove Non-default Spans From Elements
|
1252
1135
|
removeSpanTag: ($item)->
|
1253
|
-
|
1254
1136
|
$spans = $item.find("span")
|
1255
1137
|
$(span).replaceWith($(span).html()) for span in $spans when not $(span).hasClass("defaultValue")
|
1256
1138
|
$item
|