@@ -26,8 +26,14 @@ angular.module('textAngular.taBind', ['textAngular.factories', 'textAngular.DOM'
26
26
} ;
27
27
} ;
28
28
} ] )
29
- . directive ( 'taBind' , [ 'taSanitize' , '$timeout' , '$window' , '$document' , 'taFixChrome' , 'taBrowserTag' , 'taSelection' , 'taSelectableElements' , 'taApplyCustomRenderers' , 'taOptions' , '_taBlankTest' ,
30
- function ( taSanitize , $timeout , $window , $document , taFixChrome , taBrowserTag , taSelection , taSelectableElements , taApplyCustomRenderers , taOptions , _taBlankTest ) {
29
+ . directive ( 'taBind' , [
30
+ 'taSanitize' , '$timeout' , '$window' , '$document' , 'taFixChrome' , 'taBrowserTag' ,
31
+ 'taSelection' , 'taSelectableElements' , 'taApplyCustomRenderers' , 'taOptions' ,
32
+ '_taBlankTest' , '$parse' , 'taDOM' ,
33
+ function (
34
+ taSanitize , $timeout , $window , $document , taFixChrome , taBrowserTag ,
35
+ taSelection , taSelectableElements , taApplyCustomRenderers , taOptions ,
36
+ _taBlankTest , $parse , taDOM ) {
31
37
// Uses for this are textarea or input with ng-model and ta-bind='text'
32
38
// OR any non-form element with contenteditable="contenteditable" ta-bind="html|text" ng-model
33
39
return {
@@ -247,31 +253,11 @@ angular.module('textAngular.taBind', ['textAngular.factories', 'textAngular.DOM'
247
253
} ) ;
248
254
} else {
249
255
// all the code specific to contenteditable divs
250
- var waitforpastedata = function ( savedcontent , _savedSelection , cb ) {
251
- if ( element [ 0 ] . childNodes && element [ 0 ] . childNodes . length > 0 ) {
252
- cb ( savedcontent , _savedSelection ) ;
253
- } else {
254
- that = {
255
- s : savedcontent ,
256
- _ : _savedSelection ,
257
- cb : cb
258
- } ;
259
- that . callself = function ( ) {
260
- waitforpastedata ( that . s , that . _ , that . cb ) ;
261
- } ;
262
- setTimeout ( that . callself , 5 ) ;
263
- }
264
- } ;
265
256
var _processingPaste = false ;
266
257
/* istanbul ignore next: phantom js cannot test this for some reason */
267
- var processpaste = function ( savedcontent , _savedSelection ) {
268
- text = element [ 0 ] . innerHTML ;
269
- element [ 0 ] . innerHTML = savedcontent ;
270
-
271
- // restore selection
272
- $window . rangy . restoreSelection ( _savedSelection ) ;
258
+ var processpaste = function ( text ) {
273
259
/* istanbul ignore else: don't care if nothing pasted */
274
- if ( text . trim ( ) . length ) {
260
+ if ( text && text . trim ( ) . length ) {
275
261
// test paste from word/microsoft product
276
262
if ( text . match ( / c l a s s = [ " ' ] * M s o ( N o r m a l | L i s t ) / i) ) {
277
263
var textFragment = text . match ( / < ! - - S t a r t F r a g m e n t - - > ( [ \s \S ] * ?) < ! - - E n d F r a g m e n t - - > / i) ;
@@ -373,7 +359,7 @@ angular.module('textAngular.taBind', ['textAngular.factories', 'textAngular.DOM'
373
359
if ( text . match ( / < [ ^ > ] * ?( t e x t - a n g u l a r ) [ ^ > ] * ?> / ) ) {
374
360
var _el = angular . element ( "<div>" + text + "</div>" ) ;
375
361
_el . find ( 'textarea' ) . remove ( ) ;
376
- var binds = getByAttribute ( _el , 'ta-bind' ) ;
362
+ var binds = taDOM . getByAttribute ( _el , 'ta-bind' ) ;
377
363
for ( var _b = 0 ; _b < binds . length ; _b ++ ) {
378
364
var _target = binds [ _b ] [ 0 ] . parentNode . parentNode ;
379
365
for ( var _c = 0 ; _c < binds [ _b ] [ 0 ] . childNodes . length ; _c ++ ) {
@@ -387,7 +373,8 @@ angular.module('textAngular.taBind', ['textAngular.factories', 'textAngular.DOM'
387
373
// in case of pasting only a span - chrome paste, remove them. THis is just some wierd formatting
388
374
text = text . replace ( / < ( | \/ ) s p a n [ ^ > ] * ?> / ig, '' ) ;
389
375
}
390
- text = text . replace ( / < b r c l a s s = " A p p l e - i n t e r c h a n g e - n e w l i n e " [ ^ > ] * ?> / ig, '' ) ;
376
+ // Webkit on Apple tags
377
+ text = text . replace ( / < b r c l a s s = " A p p l e - i n t e r c h a n g e - n e w l i n e " [ ^ > ] * ?> / ig, '' ) . replace ( / < s p a n c l a s s = " A p p l e - c o n v e r t e d - s p a c e " > ( | & n b s p ; ) < \/ s p a n > / ig, ' ' ) ;
391
378
}
392
379
393
380
text = taSanitize ( text , '' , _disableSanitizer ) ;
@@ -414,11 +401,11 @@ angular.module('textAngular.taBind', ['textAngular.factories', 'textAngular.DOM'
414
401
e . preventDefault ( ) ;
415
402
return false ;
416
403
}
404
+
417
405
// Code adapted from http://stackoverflow.com/questions/2176861/javascript-get-clipboard-data-on-paste-event-cross-browser/6804718#6804718
418
- var _savedSelection = $window . rangy . saveSelection ( ) ;
419
406
_processingPaste = true ;
420
407
element . addClass ( 'processing-paste' ) ;
421
- var savedcontent = element [ 0 ] . innerHTML ;
408
+ var pastedContent ;
422
409
var clipboardData = ( e . originalEvent || e ) . clipboardData ;
423
410
if ( clipboardData && clipboardData . getData ) { // Webkit - get data from clipboard, put into editdiv, cleanup, then cancel event
424
411
var _types = "" ;
@@ -427,20 +414,27 @@ angular.module('textAngular.taBind', ['textAngular.factories', 'textAngular.DOM'
427
414
}
428
415
/* istanbul ignore next: browser tests */
429
416
if ( / t e x t \/ h t m l / i. test ( _types ) ) {
430
- element [ 0 ] . innerHTML = clipboardData . getData ( 'text/html' ) ;
417
+ pastedContent = clipboardData . getData ( 'text/html' ) ;
431
418
} else if ( / t e x t \/ p l a i n / i. test ( _types ) ) {
432
- element [ 0 ] . innerHTML = clipboardData . getData ( 'text/plain' ) ;
433
- } else {
434
- element [ 0 ] . innerHTML = "" ;
419
+ pastedContent = clipboardData . getData ( 'text/plain' ) ;
435
420
}
436
- waitforpastedata ( savedcontent , _savedSelection , processpaste ) ;
421
+
422
+ processpaste ( pastedContent ) ;
437
423
e . stopPropagation ( ) ;
438
424
e . preventDefault ( ) ;
439
425
return false ;
440
426
} else { // Everything else - empty editdiv and allow browser to paste content into it, then cleanup
441
- element [ 0 ] . innerHTML = "" ;
442
- waitforpastedata ( savedcontent , _savedSelection , processpaste ) ;
443
- return true ;
427
+ var _savedSelection = $window . rangy . saveSelection ( ) ,
428
+ _tempDiv = angular . element ( '<div class="ta-hidden-input" contenteditable="true"></div>' ) ;
429
+ $document . find ( 'body' ) . append ( _tempDiv ) ;
430
+ _tempDiv [ 0 ] . focus ( ) ;
431
+ $timeout ( function ( ) {
432
+ // restore selection
433
+ $window . rangy . restoreSelection ( _savedSelection ) ;
434
+ processpaste ( _tempDiv [ 0 ] . innerHTML ) ;
435
+ _tempDiv . remove ( ) ;
436
+ element [ 0 ] . focus ( ) ;
437
+ } , 0 ) ;
444
438
}
445
439
} ) ;
446
440
element . on ( 'cut' , scope . events . cut = function ( e ) {
@@ -456,7 +450,7 @@ angular.module('textAngular.taBind', ['textAngular.factories', 'textAngular.DOM'
456
450
if ( eventData ) angular . extend ( event , eventData ) ;
457
451
/* istanbul ignore else: readonly check */
458
452
if ( ! _isReadonly ) {
459
- if ( event . metaKey || event . ctrlKey ) {
453
+ if ( ! event . altKey && event . metaKey || event . ctrlKey ) {
460
454
// covers ctrl/command + z
461
455
if ( ( event . keyCode === 90 && ! event . shiftKey ) ) {
462
456
_undo ( ) ;
0 commit comments