Skip to content

Commit

Permalink
modify classes only on real focus #24
Browse files Browse the repository at this point in the history
  • Loading branch information
layerssss committed Feb 12, 2016
1 parent 8d08124 commit 091813e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
8 changes: 7 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,13 @@
<script type="text/javascript">
$(function(){
$('.demo-noninputable').pastableNonInputable();
$('.demo-textarea').pastableTextarea();
$('.demo-textarea').on('focus', function(){
var isFocused = $(this).hasClass('pastable-focus');
console && console.log('[textarea] focus event fired! ' + (isFocused ? 'fake onfocus' : 'real onfocus'));
}).pastableTextarea().on('blur', function(){
var isFocused = $(this).hasClass('pastable-focus');
console && console.log('[textarea] blur event fired! ' + (isFocused ? 'fake onblur' : 'real onblur'));
});
$('.demo-contenteditable').pastableContenteditable();
$('.demo').on('pasteImage', function(ev, data){
var blobUrl = URL.createObjectURL(data.blob);
Expand Down
13 changes: 9 additions & 4 deletions paste.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,23 @@ class Paste
ctlDown = true if ev.keyCode in [17, 224]
ctlDown = ev.ctrlKey || ev.metaKey if ev.ctrlKey? && ev.metaKey?
if ctlDown && ev.keyCode == 86
paste._textarea_focus_stolen = true
paste._container.focus()
paste._paste_event_fired = false
setTimeout =>
$(textarea).focus() unless paste._paste_event_fired
unless paste._paste_event_fired
$(textarea).focus()
paste._textarea_focus_stolen = false
, 1
null
$(textarea).on 'paste', =>
$(textarea).on 'focus', => $(textarea).addClass 'pastable-focus'
$(textarea).on 'blur', => $(textarea).removeClass 'pastable-focus'
$(textarea).on 'focus', =>
$(textarea).addClass 'pastable-focus' unless paste._textarea_focus_stolen
$(textarea).on 'blur', =>
$(textarea).removeClass 'pastable-focus' unless paste._textarea_focus_stolen
$(paste._target).on '_pasteCheckContainerDone', =>
$(textarea).focus()
paste._textarea_focus_stolen = false
$(paste._target).on 'pasteText', (ev, data)=>
curStart = $(textarea).prop('selectionStart')
curEnd = $(textarea).prop('selectionEnd')
Expand All @@ -99,7 +105,6 @@ class Paste
$(textarea)[0].setSelectionRange curStart + data.text.length, curStart + data.text.length
$(textarea).trigger 'change'


@mountContenteditable: (contenteditable)->
paste = new Paste contenteditable, contenteditable

Expand Down
15 changes: 11 additions & 4 deletions paste.js

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

0 comments on commit 091813e

Please sign in to comment.