Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
tree: a8acb0ecf2
Fetching contributors…

Cannot retrieve contributors at this time

76 lines (61 sloc) 2.186 kB
# Hallo - a rich text editing jQuery UI widget
# (c) 2011 Henri Bergius, IKS Consortium
# Hallo may be freely distributed under the MIT license
#
# Fixed toolbar plugin
((jQuery) ->
jQuery.widget 'Hallo.halloToolbarFixed',
toolbar: null
options:
parentElement: 'body'
editable: null
toolbar: null
_create: ->
@toolbar = @options.toolbar
@toolbar.show()
jQuery(@options.parentElement).append @toolbar
@_bindEvents()
jQuery(window).resize (event) =>
@setPosition()
# Make sure the toolbar has not got the full width of the editable
# element when floating is set to true
if @options.parentElement is 'body'
el = jQuery(@element)
widthToAdd = parseFloat el.css('padding-left')
widthToAdd += parseFloat el.css('padding-right')
widthToAdd += parseFloat el.css('border-left-width')
widthToAdd += parseFloat el.css('border-right-width')
try
widthToAdd += (parseFloat el.css('outline-width')) * 2
widthToAdd += (parseFloat el.css('outline-offset')) * 2
jQuery(@toolbar).css "width", el.width() + widthToAdd
_getPosition: (event, selection) ->
return position =
top: 0
left: 0
_getCaretPosition: (range) ->
tmpSpan = jQuery "<span/>"
newRange =rangy.createRange()
newRange.setStart range.endContainer, range.endOffset
newRange.insertNode tmpSpan.get 0
position =
top: tmpSpan.offset().top
left: tmpSpan.offset().left
tmpSpan.remove()
return position
setPosition: ->
return unless @options.parentElement is 'body'
@toolbar.css 'position', 'absolute'
@toolbar.css 'top', @element.offset().top - @toolbar.outerHeight()
@toolbar.css 'left', @element.offset().left + 10
_updatePosition: (position) ->
return
_bindEvents: ->
# catch activate -> show
@element.on 'halloactivated', (event, data) =>
@setPosition()
@toolbar.show()
# catch deactivate -> hide
@element.on 'hallodeactivated', (event, data) =>
@toolbar.hide()
) jQuery
Jump to Line
Something went wrong with that request. Please try again.