Skip to content

Commit

Permalink
New widget: an editability indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
bergie committed Jun 9, 2012
1 parent 238f239 commit 75da1a9
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 2 deletions.
4 changes: 2 additions & 2 deletions examples/hallo-min.js

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions examples/hallo.css
Expand Up @@ -9,6 +9,13 @@ div.hallotoolbar {
z-index: 500;
}

div.halloEditIndicator {
background-color: #000000;
color: #ffffff;
padding: 4px;
border-radius: 4px;
}

/* Drag n Drop */
[contenteditable] .tmp {
opacity: 0.3
Expand Down
48 changes: 48 additions & 0 deletions examples/hallo.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions examples/showalways.html
Expand Up @@ -74,6 +74,7 @@ <h1 class="editable">Hello World</h1>
jQuery('#enable').button().click(function() {
jQuery('.editable').hallo({
plugins: {
'halloindicator': {},
'halloformat': {},
'halloheadings': {},
'hallojustify': {},
Expand Down
42 changes: 42 additions & 0 deletions src/plugins/indicator.coffee
@@ -0,0 +1,42 @@
# 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.halloindicator',
options:
editable: null
className: 'halloEditIndicator'

_create: ->
editButton = jQuery('<div><i class="icon-edit"></i> Edit</div>');
editButton.addClass @options.className
do editButton.hide

this.element.before editButton

@bindIndicator editButton
@setIndicatorPosition editButton

bindIndicator: (indicator) ->
indicator.bind 'click', =>
do @options.editable.element.focus

this.element.bind 'halloactivated', ->
do indicator.hide

@options.editable.element.hover ->
return if jQuery(this).hasClass 'inEditMode'
do indicator.show
, (data) ->
return if jQuery(this).hasClass 'inEditMode'
return if data.relatedTarget is indicator.get 0

do indicator.hide

setIndicatorPosition: (indicator) ->
indicator.css 'position', 'absolute'
offset = this.element.offset()
indicator.css 'top', offset.top + 2
indicator.css 'left', offset.left + 2

) jQuery

0 comments on commit 75da1a9

Please sign in to comment.