This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 316
/
block.coffee
82 lines (67 loc) · 2.51 KB
/
block.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# Hallo - a rich text editing jQuery UI widget
# (c) 2011 Henri Bergius, IKS Consortium
# Hallo may be freely distributed under the MIT license
((jQuery) ->
jQuery.widget 'IKS.halloblock',
options:
editable: null
toolbar: null
uuid: ''
elements: [
'h1'
'h2'
'h3'
'p'
'pre'
'blockquote'
]
buttonCssClass: null
populateToolbar: (toolbar) ->
buttonset = jQuery "<span class=\"#{@widgetName}\"></span>"
contentId = "#{@options.uuid}-#{@widgetName}-data"
target = @_prepareDropdown contentId
buttonset.append target
buttonset.append @_prepareButton target
toolbar.append buttonset
_prepareDropdown: (contentId) ->
contentArea = jQuery "<div id=\"#{contentId}\"></div>"
containingElement = @options.editable.element.get(0).tagName.toLowerCase()
addElement = (element) =>
el = jQuery "<button class='blockselector'><#{element} class=\"menu-item\">#{element}</#{element}></button>"
if containingElement is element
el.addClass 'selected'
unless containingElement is 'div'
el.addClass 'disabled'
el.bind 'click', =>
if el.hasClass 'disabled'
return
if jQuery.browser.msie
@options.editable.execute 'FormatBlock', '<'+element.toUpperCase()+'>'
else
@options.editable.execute 'formatBlock', element.toUpperCase()
queryState = (event) =>
block = document.queryCommandValue 'formatBlock'
if block.toLowerCase() is element
el.addClass 'selected'
return
el.removeClass 'selected'
@options.editable.element.bind 'keyup paste change mouseup', queryState
@options.editable.element.bind 'halloenabled', =>
@options.editable.element.bind 'keyup paste change mouseup', queryState
@options.editable.element.bind 'hallodisabled', =>
@options.editable.element.unbind 'keyup paste change mouseup', queryState
el
for element in @options.elements
contentArea.append addElement element
contentArea
_prepareButton: (target) ->
buttonElement = jQuery '<span></span>'
buttonElement.hallodropdownbutton
uuid: @options.uuid
editable: @options.editable
label: 'block'
icon: 'icon-text-height'
target: target
cssClass: @options.buttonCssClass
buttonElement
)(jQuery)