Skip to content

Commit

Permalink
handle paste fix on clean contents & fixes on handleWidgetsBackspace
Browse files Browse the repository at this point in the history
  • Loading branch information
michelson committed Aug 10, 2015
1 parent 7e8a949 commit 7fbb2ab
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 43 deletions.
56 changes: 27 additions & 29 deletions app/assets/javascripts/dante/editor.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ class Dante.Editor extends Dante.View

@initializeWidgets(opts)


initializeWidgets: (opts)->
#TODO: this could be a hash to access widgets without var
#Base widgets
Expand Down Expand Up @@ -460,7 +459,7 @@ class Dante.Editor extends Dante.View

when "Up"
prev_node = current_node.prev()
utils.log "PREV NODE IS #{prev_node.attr('class')}"
utils.log "PREV NODE IS #{prev_node.attr('class')} #{prev_node.attr('name')}"
utils.log "CURRENT NODE IS up #{current_node.attr('class')}"

return unless $(current_node).hasClass("graf")
Expand Down Expand Up @@ -540,6 +539,7 @@ class Dante.Editor extends Dante.View
$(@paste_element_id).html("<span>#{pastedText}</span>")

#clean pasted content

@setupElementsClasses $(@paste_element_id), (e)=>
# e is the target object which is cleaned
nodes = $(e.html()).insertAfter($(@aa))
Expand Down Expand Up @@ -670,11 +670,9 @@ class Dante.Editor extends Dante.View
anchor_node = @getNode() #current node on which cursor is positioned
parent = $(anchor_node)


@markAsSelected( anchor_node ) if anchor_node

if e.which is TAB

@handleTab(anchor_node)
return false

Expand Down Expand Up @@ -760,18 +758,19 @@ class Dante.Editor extends Dante.View
utils.log(utils_anchor_node);

#check if any of the widgets can handle a backspace keydown
utils.log("HANDLING WIDGET BACKSPACES");
utils.log("HANDLING WIDGET BACKSPACES")
_.each @widgets, (w)=>
if w.handleBackspaceKey && !handled
handled = w.handleBackspaceKey(e, anchor_node);
if _.isFunction(w.handleBackspaceKey) && !eventHandled
eventHandled = w.handleBackspaceKey(e, anchor_node)
utils.log(eventHandled)

if (eventHandled)
e.preventDefault();
utils.log("SCAPE FROM BACKSPACE HANDLER");
e.preventDefault()
utils.log("SCAPE FROM BACKSPACE HANDLER")
return false;

if(parent.hasClass("graf--li") and @getCharacterPrecedingCaret().length is 0)
return this.handleListBackspace(parent, e);
return this.handleListBackspace(parent, e);

#select an image if backspacing into it from a paragraph
if($(anchor_node).hasClass("graf--p") && @isFirstChar() )
Expand Down Expand Up @@ -806,8 +805,8 @@ class Dante.Editor extends Dante.View
utils.log("SPACEBAR")
if (parent.hasClass("graf--p"))
@handleSmartList(parent, e)

#arrows key
#if _.contains([37,38,39,40], e.which)
#up & down
if _.contains([UPARROW, DOWNARROW], e.which)
utils.log e.which
Expand Down Expand Up @@ -925,7 +924,7 @@ class Dante.Editor extends Dante.View

#mark the current row as selected
markAsSelected: (element)->

utils.log element
return if _.isUndefined element

$(@el).find(".is-selected").removeClass("is-mediaFocused is-selected")
Expand Down Expand Up @@ -1002,20 +1001,20 @@ class Dante.Editor extends Dante.View
else
element = element

setTimeout ()=>
#clean context and wrap text nodes
@cleanContents(element)
@wrapTextNodes(element)
#setup classes
_.each element.children(), (n)=>
name = $(n).prop("tagName").toLowerCase()
n = @addClassesToElement(n)
@setElementName(n)

@setupLinks(element.find("a"))
@setupFirstAndLast()
cb(element) if _.isFunction(cb)
, 20
#setTimeout ()=>
#clean context and wrap text nodes
@cleanContents(element)
@wrapTextNodes(element)
#setup classes
_.each element.children(), (n)=>
name = $(n).prop("tagName").toLowerCase()
n = @addClassesToElement(n)
@setElementName(n)

@setupLinks(element.find("a"))
@setupFirstAndLast()
cb(element) if _.isFunction(cb)
#, 20

cleanContents: (element)->
#TODO: should config tags
Expand All @@ -1041,9 +1040,8 @@ class Dante.Editor extends Dante.View
transformers: [(input)->
if (input.node_name == "span" && $(input.node).hasClass("defaultValue") )
return whitelist_nodes: [input.node]
if input.node_name == 'div'
if(input.node_name == 'div' && ( $(input.node).parents(".dante-paste") or $(input.node).hasClass("dante-paste") ) )
return whitelist_nodes: [input.node]
if( $(input.node).hasClass("dante-paste") )
return whitelist_nodes: [input.node]
else
return null
(input)->
Expand Down
31 changes: 17 additions & 14 deletions app/assets/javascripts/dante/tooltip_widgets/uploader.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -228,24 +228,27 @@ class Dante.View.TooltipWidget.Uploader extends Dante.View.TooltipWidget
# @param {Event} e - The backspace event that is being handled
# @param {Node} node - The node the backspace was used in, assumed to be from te editor's getNode() function
#
# @return {Boolean} true if this function handled the backspace event, otherwise false
# @return {Boolean} true if this function should scape the default behavior
###
handleBackspaceKey: (e, node) =>

#remove graf figure if is selected but not in range (not focus on caption)
if $(".is-selected").hasClass("graf--figure")

#exit if selection is on caption
utils.log "handleBackspaceKey on uploader widget"

# remove graf figure if is selected but not in range (not focus on caption)
if $(node).hasClass("is-selected") && $(node).hasClass("graf--figure")
# exit if selection is on caption
anchor_node = @current_editor.selection().anchorNode

return if ( anchor_node? && $(anchor_node.parentNode).hasClass("imageCaption"))


# return false unless backspace is in the first char
if ( anchor_node? && $(anchor_node.parentNode).hasClass("imageCaption"))
if @current_editor.isFirstChar()
return true
else
return false

else if $(".is-selected").hasClass("is-mediaFocused")
# assume that select node is the current media element
# if it's focused when backspace it means that it should be removed
utils.log("Replacing selected node")

@current_editor.replaceWith("p", $(".is-selected"))

@current_editor.setRangeAt($(".is-selected")[0])

return true

return false
4 changes: 4 additions & 0 deletions app/assets/stylesheets/dante/_scaffold.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@
}

}

.dante-paste{
display:none;
}

0 comments on commit 7fbb2ab

Please sign in to comment.