Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Commit

Permalink
Added "show always" option
Browse files Browse the repository at this point in the history
  • Loading branch information
Reto Ryter committed Oct 4, 2011
1 parent 7cf6ef7 commit 3fe2010
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ This example would enable the simple formatting plugin that provides functionali

Please note that you need to load the plugin JavaScript files you want to use manually.

Hallo has got more options you set when instantiating. See the hallo.coffee file for further documentation.

## Plugins

* halloformat - Adds Bold, Italic, StrikeThrough and Underline support to the toolbar. (Pick with options: "formattings": ["bold", "italic", "strikeThough", "underline"])
Expand Down
39 changes: 37 additions & 2 deletions hallo.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,28 @@
# Hallo, then a floating editing toolbar will be rendered above
# the editable contents when an area is active.
#
# ## Options
#
# Change from floating mode to relative positioning with using
# the offset to position the toolbar where you want it:
#
# jQuery('selector').hallo({
# floating: true,
# offset: {
# 'x' : 0,
# 'y' : 0
# }
# });
#
# Force the toolbar to be shown at all times when a contenteditable
# element is focused:
#
# jQuery('selector').hallo({
# showalways: true
# });
#
# showalways is false by default
#
# ## Events
#
# The Hallo editor provides several jQuery events that web
Expand Down Expand Up @@ -62,6 +84,9 @@
options:
editable: true
plugins: {}
floating: true
offset: {x:0,y:0}
showalways: false
activated: ->
deactivated: ->
selected: ->
Expand Down Expand Up @@ -149,7 +174,16 @@

_getToolbarPosition: (event, selection) ->
if event.originalEvent instanceof MouseEvent
return [event.pageX, event.pageY]
if @options.floating
return [event.pageX, event.pageY]
else
if $(event.target).attr('contenteditable') == "true"
containerElement = $(event.target)
else
containerElement = $(event.target).parent('[contenteditable]').first()

containerPosition = containerElement.position()
return [containerPosition.left - @options.offset.x, containerPosition.top - @options.offset.y]

range = selection.getRangeAt 0
tmpSpan = jQuery "<span/>"
Expand Down Expand Up @@ -178,7 +212,8 @@
widget.toolbar.show()

@element.bind "hallounselected", (event, data) ->
data.editable.toolbar.hide()
if not that.options.showalways
data.editable.toolbar.hide()

_checkModified: (event) ->
widget = event.data
Expand Down

0 comments on commit 3fe2010

Please sign in to comment.