Skip to content

Commit

Permalink
remove spinner when embedly fails
Browse files Browse the repository at this point in the history
  • Loading branch information
michelson committed Mar 16, 2015
1 parent aadeb16 commit 26a4de0
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 16 deletions.
38 changes: 26 additions & 12 deletions app/assets/javascripts/dante/editor.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ utils = Dante.utils
class Dante.Editor extends Dante.View

events:
"mouseup" : "handleMouseUp"
"keydown" : "handleKeyDown"
"keyup" : "handleKeyUp"
"paste" : "handlePaste"
"mouseup" : "handleMouseUp"
"keydown" : "handleKeyDown"
"keyup" : "handleKeyUp"
"paste" : "handlePaste"
"dblclick" : "handleDblclick"
"dragstart": "handleDrag"
"drop" : "handleDrag"
"drop" : "handleDrag"
"click .graf--figure .aspectRatioPlaceholder" : "handleGrafFigureSelectImg"
"click .graf--figure figcaption" : "handleGrafFigureSelectCaption"

Expand Down Expand Up @@ -40,6 +40,10 @@ class Dante.Editor extends Dante.View
@paste_element_id = "#dante-paste-div"
@tooltip_class = opts.tooltip_class || Dante.Editor.Tooltip

opts.base_widgets ||= ["uploader", "embed", "embed_extract"]

@widgets = []

window.debugMode = opts.debug || false

$(@el).addClass("debug") if window.debugMode
Expand All @@ -58,15 +62,25 @@ class Dante.Editor extends Dante.View
extractplaceholder = opts.extract_placeholder|| "Paste a link to embed content from another site (e.g. Twitter) and press Enter"
@extract_placeholder= "<span class='defaultValue defaultValue--root'>#{extractplaceholder}</span><br>"

@initializeWidgets(opts)


initializeWidgets: (opts)->
#TODO: this could be a hash to access widgets without var
#Base widgets
@uploader_widget = new Dante.View.TooltipWidget.Uploader(current_editor: @)
@embed_widget = new Dante.View.TooltipWidget.Embed(current_editor: @)
@embed_extract_widget = new Dante.View.TooltipWidget.EmbedExtract(current_editor: @)
base_widgets = opts.base_widgets

@widgets = []
@widgets.push @uploader_widget
@widgets.push @embed_widget
@widgets.push @embed_extract_widget
if base_widgets.indexOf("uploader") >= 0
@uploader_widget = new Dante.View.TooltipWidget.Uploader(current_editor: @)
@widgets.push @uploader_widget

if base_widgets.indexOf("embed") >= 0
@embed_widget = new Dante.View.TooltipWidget.Embed(current_editor: @)
@widgets.push @embed_widget

if base_widgets.indexOf("embed_extract") >= 0
@embed_extract_widget = new Dante.View.TooltipWidget.EmbedExtract(current_editor: @)
@widgets.push @embed_extract_widget

#add extra widgets
if opts.extra_tooltip_widgets
Expand Down
5 changes: 3 additions & 2 deletions app/assets/javascripts/dante/tooltip_widgets/embed.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ utils = Dante.utils
class Dante.View.TooltipWidget.Embed extends Dante.View.TooltipWidget

initialize: (opts={})->
#super
@icon = opts.icon || "icon-video"
@title = opts.title || "Add a video"
@action = opts.action || "embed"
Expand All @@ -12,7 +11,6 @@ class Dante.View.TooltipWidget.Embed extends Dante.View.TooltipWidget
handleClick: (ev)->
@displayEmbedPlaceHolder(ev)


embedTemplate: ()->
"<figure contenteditable='false' class='graf--figure graf--iframe graf--first' name='504e' tabindex='0'>
<div class='iframeContainer'>
Expand Down Expand Up @@ -53,3 +51,6 @@ class Dante.View.TooltipWidget.Embed extends Dante.View.TooltipWidget
utils.log "URL IS #{url}"
replaced_node.find(".markup--anchor").attr("href", url ).text(url)
@hide()
.error (res)=>
@node.removeClass("spinner")

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ utils = Dante.utils
class Dante.View.TooltipWidget.EmbedExtract extends Dante.View.TooltipWidget

initialize: (opts={})->
#super
@icon = opts.icon || "icon-embed"
@title = opts.title || "Add an embed"
@action = opts.action || "embed-extract"
Expand Down Expand Up @@ -36,7 +35,8 @@ class Dante.View.TooltipWidget.EmbedExtract extends Dante.View.TooltipWidget
@node_name = @node.attr("name")
@node.addClass("spinner")

$.getJSON("#{@current_editor.extract_url}#{$(@node).text()}").success (data)=>
$.getJSON("#{@current_editor.extract_url}#{$(@node).text()}")
.success (data)=>
@node = $("[name=#{@node_name}]")
iframe_src = $(data.html).prop("src")
tmpl = $(@extractTemplate())
Expand All @@ -52,6 +52,8 @@ class Dante.View.TooltipWidget.EmbedExtract extends Dante.View.TooltipWidget
image_node.css("background-image", "url(#{data.images[0].url})")
image_node.removeClass("mixtapeImage--empty u-ignoreBlock")
@hide()
.error (data)=>
@node.removeClass("spinner")

getExtract: (url)=>
$.getJSON("#{@current_editor.extract_url}#{url}").done (data)->
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions source/custom_toolbar.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ title: Dante Editor example
el: "#editor",
upload_url: "/uploads/new.json",
debug: <%= build? ? false : true %>,
base_widgets: ["uploader"],
extra_tooltip_widgets: [btn1, btn2]
}
)
Expand Down

0 comments on commit 26a4de0

Please sign in to comment.