forked from bergie/hallo
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New widget: an editability indicator
- Loading branch information
Showing
5 changed files
with
100 additions
and
2 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |