dante-editor-seo 0.0.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +40 -0
- data/.ruby-version +1 -0
- data/.travis.yml +4 -0
- data/Gemfile +23 -0
- data/Gemfile.lock +140 -0
- data/Procfile +1 -0
- data/README.md +187 -0
- data/ROADMAP.md +10 -0
- data/TODO.md +30 -0
- data/app/assets/fonts/dante/dante.eot +0 -0
- data/app/assets/fonts/dante/dante.svg +14 -0
- data/app/assets/fonts/dante/dante.ttf +0 -0
- data/app/assets/fonts/dante/dante.woff +0 -0
- data/app/assets/fonts/dante/fontello.eot +0 -0
- data/app/assets/fonts/dante/fontello.svg +36 -0
- data/app/assets/fonts/dante/fontello.ttf +0 -0
- data/app/assets/fonts/dante/fontello.woff +0 -0
- data/app/assets/images/dante/media-loading-placeholder.png +0 -0
- data/app/assets/javascripts/dante/dante.js.coffee.erb +10 -0
- data/app/assets/javascripts/dante/editor.js.coffee +1250 -0
- data/app/assets/javascripts/dante/menu.js.coffee +216 -0
- data/app/assets/javascripts/dante/popover.js.coffee +75 -0
- data/app/assets/javascripts/dante/tooltip.js.coffee +82 -0
- data/app/assets/javascripts/dante/tooltip_widget.js.coffee +10 -0
- data/app/assets/javascripts/dante/tooltip_widgets/embed.js.coffee +60 -0
- data/app/assets/javascripts/dante/tooltip_widgets/extract.js.coffee +64 -0
- data/app/assets/javascripts/dante/tooltip_widgets/uploader.js.coffee +248 -0
- data/app/assets/javascripts/dante/utils.js.coffee +235 -0
- data/app/assets/javascripts/dante/view.js.coffee +101 -0
- data/app/assets/javascripts/dante.js +12 -0
- data/app/assets/stylesheets/dante/_animations.scss +54 -0
- data/app/assets/stylesheets/dante/_caption.scss +52 -0
- data/app/assets/stylesheets/dante/_debug.scss +11 -0
- data/app/assets/stylesheets/dante/_fonts.scss +17 -0
- data/app/assets/stylesheets/dante/_graf.scss +238 -0
- data/app/assets/stylesheets/dante/_icons.scss +57 -0
- data/app/assets/stylesheets/dante/_media.scss +39 -0
- data/app/assets/stylesheets/dante/_menu.scss +153 -0
- data/app/assets/stylesheets/dante/_needsorder.scss +209 -0
- data/app/assets/stylesheets/dante/_popover.scss +134 -0
- data/app/assets/stylesheets/dante/_post.scss +69 -0
- data/app/assets/stylesheets/dante/_scaffold.scss +20 -0
- data/app/assets/stylesheets/dante/_tooltip.scss +131 -0
- data/app/assets/stylesheets/dante/_utilities.scss +55 -0
- data/app/assets/stylesheets/dante/_variables.scss +46 -0
- data/app/assets/stylesheets/dante.scss +18 -0
- data/bower.json +44 -0
- data/config.rb +86 -0
- data/config.ru +42 -0
- data/dante-editor.gemspec +19 -0
- data/dist/css/dante-editor.css +1116 -0
- data/dist/fonts/dante/dante.eot +0 -0
- data/dist/fonts/dante/dante.svg +14 -0
- data/dist/fonts/dante/dante.ttf +0 -0
- data/dist/fonts/dante/dante.woff +0 -0
- data/dist/fonts/dante/fontello.eot +0 -0
- data/dist/fonts/dante/fontello.svg +36 -0
- data/dist/fonts/dante/fontello.ttf +0 -0
- data/dist/fonts/dante/fontello.woff +0 -0
- data/dist/images/dante/media-loading-placeholder.png +0 -0
- data/dist/js/dante-editor.js +2878 -0
- data/lib/dante-editor/rails.rb +4 -0
- data/lib/dante-editor/version.rb +5 -0
- data/lib/dante-editor.rb +5 -0
- data/license.md +22 -0
- data/rakefile +2 -0
- data/source/assets/images/dante-editor-logo.png +0 -0
- data/source/assets/images/github-logo.png +0 -0
- data/source/assets/javascripts/all.js +3 -0
- data/source/assets/javascripts/dante-editor.js +1 -0
- data/source/assets/javascripts/deps.js +4 -0
- data/source/assets/javascripts/examples/custom_toolbar.js.coffee +30 -0
- data/source/assets/javascripts/spec.js +2 -0
- data/source/assets/javascripts/specs/cleaner.js.coffee +8 -0
- data/source/assets/javascripts/specs/dante_view.js.coffee +74 -0
- data/source/assets/javascripts/specs/editor.js.coffee +78 -0
- data/source/assets/stylesheets/_layout.scss +51 -0
- data/source/assets/stylesheets/_scaffold.scss +8 -0
- data/source/assets/stylesheets/_tooltips.scss +216 -0
- data/source/assets/stylesheets/all.css.scss +5 -0
- data/source/assets/stylesheets/dante-editor.css.scss +1 -0
- data/source/assets/stylesheets/normalize.css +375 -0
- data/source/custom_toolbar.erb +29 -0
- data/source/embeds.html.erb +27 -0
- data/source/icons/dante.json +143 -0
- data/source/icons/embed.svg +13 -0
- data/source/icons/image.svg +13 -0
- data/source/icons/plus.svg +13 -0
- data/source/icons/video.svg +13 -0
- data/source/index.html.erb +18 -0
- data/source/layouts/layout.erb +26 -0
- data/source/layouts/spec.html.erb +22 -0
- data/source/lists.html.erb +18 -0
- data/source/partials/_content.erb +6 -0
- data/source/partials/_example_1.erb +45 -0
- data/source/partials/_example_2.erb +32 -0
- data/source/partials/_example_3.erb +4 -0
- data/source/partials/_lists.erb +13 -0
- data/source/partials/_readme.markdown +24 -0
- data/source/partials/test/_example_1.erb +39 -0
- data/source/tests/dante_view.html.erb +11 -0
- data/source/tests/index.html.erb +39 -0
- data/tmp/.gitkeep +0 -0
- metadata +151 -0
@@ -0,0 +1,216 @@
|
|
1
|
+
utils = Dante.utils
|
2
|
+
|
3
|
+
class Dante.Editor.Menu extends Dante.View
|
4
|
+
el: "#dante-menu"
|
5
|
+
|
6
|
+
events:
|
7
|
+
"mousedown li" : "handleClick"
|
8
|
+
"click .dante-menu-linkinput .dante-menu-button": "closeInput"
|
9
|
+
"keypress input": "handleInputEnter"
|
10
|
+
|
11
|
+
initialize: (opts={})=>
|
12
|
+
@config = opts.buttons || @default_config()
|
13
|
+
@current_editor = opts.editor
|
14
|
+
|
15
|
+
@commandsReg = {
|
16
|
+
block: /^(?:p|h[1-6]|blockquote|pre)$/
|
17
|
+
inline: /^(?:bold|italic|underline|insertorderedlist|insertunorderedlist|indent|outdent)$/,
|
18
|
+
source: /^(?:insertimage|createlink|unlink)$/
|
19
|
+
insert: /^(?:inserthorizontalrule|insert)$/
|
20
|
+
wrap: /^(?:code)$/
|
21
|
+
}
|
22
|
+
|
23
|
+
@lineBreakReg = /^(?:blockquote|pre|div|p)$/i;
|
24
|
+
|
25
|
+
@effectNodeReg = /(?:[pubia]|h[1-6]|blockquote|[uo]l|li)/i;
|
26
|
+
|
27
|
+
@strReg =
|
28
|
+
whiteSpace: /(^\s+)|(\s+$)/g,
|
29
|
+
mailTo: /^(?!mailto:|.+\/|.+#|.+\?)(.*@.*\..+)$/,
|
30
|
+
http: /^(?!\w+?:\/\/|mailto:|\/|\.\/|\?|#)(.*)$/
|
31
|
+
|
32
|
+
default_config: ()->
|
33
|
+
###
|
34
|
+
buttons: [
|
35
|
+
'blockquote', 'h2', 'h3', 'p', 'code', 'insertorderedlist', 'insertunorderedlist', 'inserthorizontalrule',
|
36
|
+
'indent', 'outdent', 'bold', 'italic', 'underline', 'createlink'
|
37
|
+
]
|
38
|
+
###
|
39
|
+
|
40
|
+
buttons: ['bold', 'italic', 'h2', 'h3', 'h4', 'blockquote', 'createlink']
|
41
|
+
|
42
|
+
template: ()=>
|
43
|
+
html = "<div class='dante-menu-linkinput'><input class='dante-menu-input' placeholder='http://'><div class='dante-menu-button'>x</div></div>"
|
44
|
+
html += "<ul class='dante-menu-buttons'>"
|
45
|
+
_.each @config.buttons, (item)->
|
46
|
+
html += "<li class='dante-menu-button'><i class=\"dante-icon icon-#{item}\" data-action=\"#{item}\"></i></li>"
|
47
|
+
html += "</ul>"
|
48
|
+
html
|
49
|
+
|
50
|
+
render: ()=>
|
51
|
+
$(@el).html(@template())
|
52
|
+
@show()
|
53
|
+
|
54
|
+
handleClick: (ev)->
|
55
|
+
element = $(ev.currentTarget).find('.dante-icon')
|
56
|
+
action = element.data("action")
|
57
|
+
input = $(@el).find("input.dante-menu-input")
|
58
|
+
utils.log("menu #{action} item clicked!")
|
59
|
+
@savedSel = utils.saveSelection()
|
60
|
+
|
61
|
+
if /(?:createlink)/.test(action)
|
62
|
+
if $(ev.currentTarget).hasClass("active")
|
63
|
+
@removeLink()
|
64
|
+
else
|
65
|
+
$(@el).addClass("dante-menu--linkmode")
|
66
|
+
input.focus()
|
67
|
+
else
|
68
|
+
@menuApply action
|
69
|
+
|
70
|
+
return false
|
71
|
+
|
72
|
+
closeInput: (e)->
|
73
|
+
$(@el).removeClass("dante-menu--linkmode")
|
74
|
+
false
|
75
|
+
|
76
|
+
handleInputEnter: (e)=>
|
77
|
+
if (e.which is 13)
|
78
|
+
utils.restoreSelection(@savedSel)
|
79
|
+
return @createlink( $(e.target) )
|
80
|
+
|
81
|
+
removeLink: ()->
|
82
|
+
@menuApply "unlink"
|
83
|
+
elem = @current_editor.getNode()
|
84
|
+
@current_editor.cleanContents($(elem))
|
85
|
+
|
86
|
+
createlink: (input) =>
|
87
|
+
$(@el).removeClass("dante-menu--linkmode")
|
88
|
+
if input.val()
|
89
|
+
inputValue = input.val()
|
90
|
+
.replace(@strReg.whiteSpace, "")
|
91
|
+
.replace(@strReg.mailTo, "mailto:$1")
|
92
|
+
.replace(@strReg.http, "http://$1")
|
93
|
+
return @menuApply("createlink", inputValue)
|
94
|
+
action = "unlink"
|
95
|
+
@menuApply action
|
96
|
+
|
97
|
+
menuApply: (action, value)->
|
98
|
+
|
99
|
+
if @commandsReg.block.test(action)
|
100
|
+
utils.log "block here"
|
101
|
+
@commandBlock action
|
102
|
+
else if @commandsReg.inline.test(action) or @commandsReg.source.test(action)
|
103
|
+
utils.log "overall here"
|
104
|
+
@commandOverall action, value
|
105
|
+
else if @commandsReg.insert.test(action)
|
106
|
+
utils.log "insert here"
|
107
|
+
@commandInsert action
|
108
|
+
else if @commandsReg.wrap.test(action)
|
109
|
+
utils.log "wrap here"
|
110
|
+
@commandWrap action
|
111
|
+
else
|
112
|
+
utils.log "can't find command function for action: " + action
|
113
|
+
|
114
|
+
return false
|
115
|
+
|
116
|
+
setupInsertedElement: (element)->
|
117
|
+
n = @current_editor.addClassesToElement(element)
|
118
|
+
@current_editor.setElementName(n)
|
119
|
+
@current_editor.markAsSelected(n)
|
120
|
+
|
121
|
+
cleanContents: ()->
|
122
|
+
@current_editor.cleanContents()
|
123
|
+
|
124
|
+
commandOverall: (cmd, val) ->
|
125
|
+
message = " to exec 「" + cmd + "」 command" + ((if val then (" with value: " + val) else ""))
|
126
|
+
|
127
|
+
if document.execCommand(cmd, false, val)
|
128
|
+
utils.log "success" + message
|
129
|
+
n = @current_editor.getNode()
|
130
|
+
@current_editor.setupLinks($(n).find("a"))
|
131
|
+
@displayHighlights()
|
132
|
+
if $(n).parent().hasClass("section-inner")
|
133
|
+
n = @current_editor.addClassesToElement(n)
|
134
|
+
@current_editor.setElementName(n)
|
135
|
+
@current_editor.handleTextSelection(n)
|
136
|
+
else
|
137
|
+
utils.log "fail" + message, true
|
138
|
+
return
|
139
|
+
|
140
|
+
commandInsert: (name) ->
|
141
|
+
node = @current_editor.current_node
|
142
|
+
return unless node
|
143
|
+
@current_editor.current_range.selectNode node
|
144
|
+
@current_editor.current_range.collapse false
|
145
|
+
@commandOverall node, name
|
146
|
+
|
147
|
+
commandBlock: (name) ->
|
148
|
+
node = @current_editor.current_node
|
149
|
+
list = @effectNode(@current_editor.getNode(node), true)
|
150
|
+
name = "p" if list.indexOf(name) isnt -1
|
151
|
+
@commandOverall "formatblock", name
|
152
|
+
|
153
|
+
commandWrap: (tag) ->
|
154
|
+
node = @current_editor.current_node
|
155
|
+
val = "<" + tag + ">" + selection + "</" + tag + ">"
|
156
|
+
@commandOverall "insertHTML", val
|
157
|
+
|
158
|
+
# node effects
|
159
|
+
effectNode: (el, returnAsNodeName) ->
|
160
|
+
nodes = []
|
161
|
+
el = el or @current_editor.$el[0]
|
162
|
+
while el isnt @current_editor.$el[0]
|
163
|
+
if el.nodeName.match(@effectNodeReg)
|
164
|
+
nodes.push (if returnAsNodeName then el.nodeName.toLowerCase() else el)
|
165
|
+
el = el.parentNode
|
166
|
+
nodes
|
167
|
+
|
168
|
+
displayHighlights: ()->
|
169
|
+
#remove all active links
|
170
|
+
$(@el).find(".active").removeClass("active")
|
171
|
+
|
172
|
+
nodes = @effectNode(utils.getNode())
|
173
|
+
utils.log(nodes)
|
174
|
+
_.each nodes, (node)=>
|
175
|
+
tag = node.nodeName.toLowerCase()
|
176
|
+
switch tag
|
177
|
+
when "a"
|
178
|
+
$(@el).find('input').val $(node).attr("href")
|
179
|
+
tag = "createlink"
|
180
|
+
when "i"
|
181
|
+
tag = "italic"
|
182
|
+
when "u"
|
183
|
+
tag = "underline"
|
184
|
+
when "b"
|
185
|
+
tag = "bold"
|
186
|
+
when "code"
|
187
|
+
tag = "code"
|
188
|
+
when "ul"
|
189
|
+
tag = "insertunorderedlist"
|
190
|
+
when "ol"
|
191
|
+
tag = "insertorderedlist"
|
192
|
+
when "li"
|
193
|
+
tag = "indent"
|
194
|
+
utils.log "nothing to select"
|
195
|
+
|
196
|
+
if tag.match /(?:h[1-6])/i
|
197
|
+
$(@el).find(".icon-bold, .icon-italic, .icon-blockquote")
|
198
|
+
.parent("li").remove()
|
199
|
+
else if tag is "indent"
|
200
|
+
$(@el).find(".icon-h2, .icon-h3, .icon-h4, .icon-blockquote")
|
201
|
+
.parent("li").remove()
|
202
|
+
#.parent("li").hide()
|
203
|
+
#.addClass("hidden")
|
204
|
+
|
205
|
+
@highlight(tag)
|
206
|
+
|
207
|
+
highlight: (tag)->
|
208
|
+
$(".icon-#{tag}").parent("li").addClass("active")
|
209
|
+
|
210
|
+
show: ()->
|
211
|
+
$(@el).addClass("dante-menu--active")
|
212
|
+
@closeInput()
|
213
|
+
@displayHighlights()
|
214
|
+
|
215
|
+
hide: ()->
|
216
|
+
$(@el).removeClass("dante-menu--active")
|
@@ -0,0 +1,75 @@
|
|
1
|
+
utils = Dante.utils
|
2
|
+
|
3
|
+
class Dante.Editor.PopOver extends Dante.View
|
4
|
+
el: "body"
|
5
|
+
|
6
|
+
events:
|
7
|
+
"mouseover .popover": "cancelHide"
|
8
|
+
"mouseout .popover": "hide"
|
9
|
+
|
10
|
+
initialize: (opts = {})->
|
11
|
+
utils.log("initialized popover")
|
12
|
+
@editor = opts.editor
|
13
|
+
@hideTimeout
|
14
|
+
@settings = {timeout: 300}
|
15
|
+
|
16
|
+
template: ()->
|
17
|
+
"<div class='popover popover--tooltip popover--Linktooltip popover--bottom is-active'>
|
18
|
+
<div class='popover-inner'>
|
19
|
+
<a href='#' target='_blank'> Link </a>
|
20
|
+
</div>
|
21
|
+
<div class='popover-arrow'>
|
22
|
+
</div>
|
23
|
+
</div>"
|
24
|
+
|
25
|
+
#display & copy original link
|
26
|
+
positionAt: (ev)->
|
27
|
+
target = $(ev.currentTarget)
|
28
|
+
target_positions = @resolveTargetPosition(target)
|
29
|
+
target_offset = target.offset()
|
30
|
+
target_width = target.outerWidth()
|
31
|
+
target_height = target.outerHeight()
|
32
|
+
popover_width = $(@el).find(".popover").outerWidth()
|
33
|
+
top_value = target_positions.top + target_height
|
34
|
+
left_value = target_offset.left + (target_width/2) - (popover_width/2)
|
35
|
+
|
36
|
+
$(@el).find(".popover")
|
37
|
+
.css("top", top_value)
|
38
|
+
.css("left", left_value )
|
39
|
+
.show()
|
40
|
+
|
41
|
+
@handleDirection(target)
|
42
|
+
|
43
|
+
displayAt: (ev)->
|
44
|
+
@cancelHide()
|
45
|
+
target = $(ev.currentTarget)
|
46
|
+
$(@el).find(".popover-inner a").text( target.attr('href') ).attr('href', target.attr("href") )
|
47
|
+
@positionAt(ev)
|
48
|
+
$(@el).find(".popover--tooltip").css("pointer-events", "auto")
|
49
|
+
$(@el).show()
|
50
|
+
|
51
|
+
cancelHide: ()->
|
52
|
+
utils.log "Cancel Hide"
|
53
|
+
clearTimeout @hideTimeout
|
54
|
+
|
55
|
+
hide: (ev)->
|
56
|
+
@cancelHide()
|
57
|
+
@hideTimeout = setTimeout ()=>
|
58
|
+
$(@el).find(".popover").hide()
|
59
|
+
, @settings.timeout
|
60
|
+
|
61
|
+
resolveTargetPosition: (target)->
|
62
|
+
if target.parents(".graf--mixtapeEmbed").exists()
|
63
|
+
target.parents(".graf--mixtapeEmbed").position()
|
64
|
+
else
|
65
|
+
target.position()
|
66
|
+
|
67
|
+
|
68
|
+
handleDirection: (target)->
|
69
|
+
if target.parents(".graf--mixtapeEmbed").exists()
|
70
|
+
$(@el).find(".popover").removeClass("popover--bottom").addClass("popover--top")
|
71
|
+
else
|
72
|
+
$(@el).find(".popover").removeClass("popover--top").addClass("popover--bottom")
|
73
|
+
|
74
|
+
render: ()->
|
75
|
+
$(@template()).insertAfter(@editor.$el)
|
@@ -0,0 +1,82 @@
|
|
1
|
+
utils = Dante.utils
|
2
|
+
|
3
|
+
class Dante.Editor.Tooltip extends Dante.View
|
4
|
+
el: ".inlineTooltip"
|
5
|
+
|
6
|
+
events:
|
7
|
+
"click .inlineTooltip-button.control" : "toggleOptions"
|
8
|
+
"click .inlineTooltip-menu button" : "handleClick"
|
9
|
+
|
10
|
+
initialize: (opts = {})=>
|
11
|
+
@current_editor = opts.editor
|
12
|
+
@widgets = opts.widgets
|
13
|
+
|
14
|
+
template: ()->
|
15
|
+
menu = ""
|
16
|
+
|
17
|
+
_.each @widgets, (b)->
|
18
|
+
data_action_value = if b.action_value then "data-action-value='#{b.action_value}'" else ""
|
19
|
+
menu += "<button class='inlineTooltip-button scale' title='#{b.title}' data-action='inline-menu-#{b.action}' #{data_action_value}>
|
20
|
+
<span class='tooltip-icon #{b.icon}'></span>
|
21
|
+
</button>"
|
22
|
+
|
23
|
+
"<button class='inlineTooltip-button control' title='Close Menu' data-action='inline-menu'>
|
24
|
+
<span class='tooltip-icon icon-plus'></span>
|
25
|
+
</button>
|
26
|
+
<div class='inlineTooltip-menu'>
|
27
|
+
#{menu}
|
28
|
+
</div>"
|
29
|
+
|
30
|
+
findWidgetByAction: (name)->
|
31
|
+
|
32
|
+
_.find @widgets, (e)->
|
33
|
+
e.action == name
|
34
|
+
|
35
|
+
|
36
|
+
render: ()=>
|
37
|
+
$(@el).html(@template())
|
38
|
+
$(@el).addClass("is-active")
|
39
|
+
@
|
40
|
+
|
41
|
+
toggleOptions: ()=>
|
42
|
+
utils.log "Toggle Options!!"
|
43
|
+
$(@el).toggleClass("is-scaled")
|
44
|
+
return false
|
45
|
+
|
46
|
+
move: (coords)->
|
47
|
+
tooltip = $(@el)
|
48
|
+
control_width = tooltip.find(".control").css("width")
|
49
|
+
control_spacing = tooltip.find(".inlineTooltip-menu").css("padding-left")
|
50
|
+
pull_size = parseInt(control_width.replace(/px/,"")) + parseInt(control_spacing.replace(/px/,""))
|
51
|
+
coord_left = coords.left - pull_size
|
52
|
+
coord_top = coords.top
|
53
|
+
|
54
|
+
$(@el).offset(top: coord_top, left: coord_left)
|
55
|
+
|
56
|
+
handleClick: (ev)->
|
57
|
+
name = $(ev.currentTarget).data('action')
|
58
|
+
utils.log name
|
59
|
+
###
|
60
|
+
switch name
|
61
|
+
when "inline-menu-image"
|
62
|
+
@placeholder = "<p>PLACEHOLDER</p>"
|
63
|
+
@imageSelect(ev)
|
64
|
+
when "inline-menu-embed"
|
65
|
+
@displayEmbedPlaceHolder()
|
66
|
+
when "inline-menu-embed-extract"
|
67
|
+
@displayExtractPlaceHolder()
|
68
|
+
when "inline-menu-hr"
|
69
|
+
@splitSection()
|
70
|
+
###
|
71
|
+
#debugger
|
72
|
+
sub_name = name.replace("inline-menu-", "")
|
73
|
+
if detected_widget = @findWidgetByAction(sub_name)
|
74
|
+
detected_widget.handleClick(ev)
|
75
|
+
|
76
|
+
return false
|
77
|
+
|
78
|
+
cleanOperationClasses: (node)->
|
79
|
+
node.removeClass("is-embedable is-extractable")
|
80
|
+
|
81
|
+
hide: ()=>
|
82
|
+
$(@el).removeClass("is-active is-scaled")
|
@@ -0,0 +1,60 @@
|
|
1
|
+
utils = Dante.utils
|
2
|
+
|
3
|
+
class Dante.View.TooltipWidget.Embed extends Dante.View.TooltipWidget
|
4
|
+
|
5
|
+
initialize: (opts={})->
|
6
|
+
@icon = opts.icon || "icon-video"
|
7
|
+
@title = opts.title || "Add a video"
|
8
|
+
@action = opts.action || "embed"
|
9
|
+
@current_editor = opts.current_editor
|
10
|
+
|
11
|
+
handleClick: (ev)->
|
12
|
+
@displayEmbedPlaceHolder(ev)
|
13
|
+
|
14
|
+
handleEnterKey: (ev, $node)->
|
15
|
+
if $node.hasClass("is-embedable")
|
16
|
+
@getEmbedFromNode($node);
|
17
|
+
|
18
|
+
embedTemplate: ()->
|
19
|
+
"<figure contenteditable='false' class='graf--figure graf--iframe graf--first' name='504e' tabindex='0'>
|
20
|
+
<div class='iframeContainer'>
|
21
|
+
<iframe frameborder='0' width='700' height='393' data-media-id='' src='' data-height='480' data-width='854'>
|
22
|
+
</iframe>
|
23
|
+
</div>
|
24
|
+
<figcaption contenteditable='true' data-default-value='Type caption for embed (optional)' class='imageCaption'>
|
25
|
+
<a rel='nofollow' class='markup--anchor markup--figure-anchor' data-href='' href='' target='_blank'>
|
26
|
+
|
27
|
+
</a>
|
28
|
+
</figcaption>
|
29
|
+
</figure>"
|
30
|
+
|
31
|
+
displayEmbedPlaceHolder: ()->
|
32
|
+
ph = @current_editor.embed_placeholder
|
33
|
+
@node = @current_editor.getNode()
|
34
|
+
$(@node).html(ph).addClass("is-embedable")
|
35
|
+
|
36
|
+
@current_editor.setRangeAt(@node)
|
37
|
+
@hide()
|
38
|
+
false
|
39
|
+
|
40
|
+
getEmbedFromNode: (node)=>
|
41
|
+
@node = $(node)
|
42
|
+
@node_name = @node.attr("name")
|
43
|
+
@node.addClass("spinner")
|
44
|
+
|
45
|
+
$.getJSON("#{@current_editor.oembed_url}#{$(@node).text()}")
|
46
|
+
.success (data)=>
|
47
|
+
@node = $("[name=#{@node_name}]")
|
48
|
+
iframe_src = $(data.html).prop("src")
|
49
|
+
tmpl = $(@embedTemplate())
|
50
|
+
tmpl.attr("name", @node.attr("name"))
|
51
|
+
$(@node).replaceWith(tmpl)
|
52
|
+
replaced_node = $(".graf--iframe[name=#{@node.attr("name")}]")
|
53
|
+
replaced_node.find("iframe").attr("src", iframe_src)
|
54
|
+
url = data.url || data.author_url
|
55
|
+
utils.log "URL IS #{url}"
|
56
|
+
replaced_node.find(".markup--anchor").attr("href", url ).text(url)
|
57
|
+
@hide()
|
58
|
+
.error (res)=>
|
59
|
+
@node.removeClass("spinner")
|
60
|
+
|
@@ -0,0 +1,64 @@
|
|
1
|
+
utils = Dante.utils
|
2
|
+
|
3
|
+
class Dante.View.TooltipWidget.EmbedExtract extends Dante.View.TooltipWidget
|
4
|
+
|
5
|
+
initialize: (opts={})->
|
6
|
+
@icon = opts.icon || "icon-embed"
|
7
|
+
@title = opts.title || "Add an embed"
|
8
|
+
@action = opts.action || "embed-extract"
|
9
|
+
@current_editor = opts.current_editor
|
10
|
+
|
11
|
+
handleClick: (ev)->
|
12
|
+
@displayExtractPlaceHolder(ev)
|
13
|
+
|
14
|
+
handleEnterKey: (ev, $node)->
|
15
|
+
if $node.hasClass("is-extractable")
|
16
|
+
@getExtractFromNode($node)
|
17
|
+
|
18
|
+
extractTemplate: ()->
|
19
|
+
"<div class='graf graf--mixtapeEmbed is-selected' name=''>
|
20
|
+
<a target='_blank' data-media-id='' class='js-mixtapeImage mixtapeImage mixtapeImage--empty u-ignoreBlock' href=''>
|
21
|
+
</a>
|
22
|
+
<a data-tooltip-type='link' data-tooltip-position='bottom' data-tooltip='' title='' class='markup--anchor markup--mixtapeEmbed-anchor' data-href='' href='' target='_blank'>
|
23
|
+
<strong class='markup--strong markup--mixtapeEmbed-strong'></strong>
|
24
|
+
<em class='markup--em markup--mixtapeEmbed-em'></em>
|
25
|
+
</a>
|
26
|
+
</div>"
|
27
|
+
|
28
|
+
displayExtractPlaceHolder: ()->
|
29
|
+
ph = @current_editor.extract_placeholder
|
30
|
+
@node = @current_editor.getNode()
|
31
|
+
$(@node).html(ph).addClass("is-extractable")
|
32
|
+
|
33
|
+
@current_editor.setRangeAt(@node)
|
34
|
+
@hide()
|
35
|
+
false
|
36
|
+
|
37
|
+
getExtractFromNode: (node)=>
|
38
|
+
@node = $(node)
|
39
|
+
@node_name = @node.attr("name")
|
40
|
+
@node.addClass("spinner")
|
41
|
+
|
42
|
+
$.getJSON("#{@current_editor.extract_url}#{$(@node).text()}")
|
43
|
+
.success (data)=>
|
44
|
+
@node = $("[name=#{@node_name}]")
|
45
|
+
iframe_src = $(data.html).prop("src")
|
46
|
+
tmpl = $(@extractTemplate())
|
47
|
+
tmpl.attr("name", @node.attr("name"))
|
48
|
+
$(@node).replaceWith(tmpl)
|
49
|
+
replaced_node = $(".graf--mixtapeEmbed[name=#{@node.attr("name")}]")
|
50
|
+
replaced_node.find("strong").text(data.title)
|
51
|
+
replaced_node.find("em").text(data.description)
|
52
|
+
replaced_node.append(data.provider_url)
|
53
|
+
replaced_node.find(".markup--anchor").attr("href", data.url )
|
54
|
+
unless _.isEmpty data.images
|
55
|
+
image_node = replaced_node.find(".mixtapeImage")
|
56
|
+
image_node.css("background-image", "url(#{data.images[0].url})")
|
57
|
+
image_node.removeClass("mixtapeImage--empty u-ignoreBlock")
|
58
|
+
@hide()
|
59
|
+
.error (data)=>
|
60
|
+
@node.removeClass("spinner")
|
61
|
+
|
62
|
+
getExtract: (url)=>
|
63
|
+
$.getJSON("#{@current_editor.extract_url}#{url}").done (data)->
|
64
|
+
utils.log(data)
|