1
1
angular . module ( 'textAngular.taBind' , [ 'textAngular.factories' , 'textAngular.DOM' ] )
2
- . directive ( 'taBind' , [ 'taSanitize' , '$timeout' , '$window' , '$document' , 'taFixChrome' , 'taBrowserTag' , 'taSelection' , 'taSelectableElements' , 'taApplyCustomRenderers' , 'taOptions' ,
3
- function ( taSanitize , $timeout , $window , $document , taFixChrome , taBrowserTag , taSelection , taSelectableElements , taApplyCustomRenderers , taOptions ) {
2
+ . service ( '_taBlankTest' , [ function ( ) {
3
+ var INLINETAGS_NONBLANK = / < ( a | a b b r | a c r o n y m | b d i | b d o | b i g | c i t e | c o d e | d e l | d f n | i m g | i n s | k b d | l a b e l | m a p | m a r k | q | r u b y | r p | r t | s | s a m p | t i m e | t t | v a r ) [ ^ > ] * ( > | $ ) / i;
4
+ return function ( _defaultTest ) {
5
+ return function ( _blankVal ) {
6
+ if ( ! _blankVal ) return true ;
7
+ _blankVal = _blankVal . toString ( ) ;
8
+ var _firstTagIndex = _blankVal . indexOf ( '>' ) ;
9
+ if ( _firstTagIndex === - 1 ) return _blankVal . trim ( ) . length === 0 ;
10
+ _blankVal = _blankVal . trim ( ) . substring ( _firstTagIndex , _firstTagIndex + 100 ) ;
11
+ // this regex is to match any number of whitespace only between two tags
12
+ if ( _blankVal . length === 0 || _blankVal === _defaultTest || / ^ > ( \s | & n b s p ; ) * < \/ [ ^ > ] + > $ / ig. test ( _blankVal ) ) return true ;
13
+ // this regex tests if there is a tag followed by some optional whitespace and some text after that
14
+ else if ( / > \s * [ ^ \s < ] / i. test ( _blankVal ) || INLINETAGS_NONBLANK . test ( _blankVal ) ) return false ;
15
+ else return true ;
16
+ } ;
17
+ } ;
18
+ } ] )
19
+ . directive ( 'taBind' , [ 'taSanitize' , '$timeout' , '$window' , '$document' , 'taFixChrome' , 'taBrowserTag' , 'taSelection' , 'taSelectableElements' , 'taApplyCustomRenderers' , 'taOptions' , '_taBlankTest' ,
20
+ function ( taSanitize , $timeout , $window , $document , taFixChrome , taBrowserTag , taSelection , taSelectableElements , taApplyCustomRenderers , taOptions , _taBlankTest ) {
4
21
// Uses for this are textarea or input with ng-model and ta-bind='text'
5
22
// OR any non-form element with contenteditable="contenteditable" ta-bind="html|text" ng-model
6
23
return {
@@ -15,7 +32,6 @@ angular.module('textAngular.taBind', ['textAngular.factories', 'textAngular.DOM'
15
32
var _lastKey ;
16
33
var BLOCKED_KEYS = / ^ ( 9 | 1 9 | 2 0 | 2 7 | 3 3 | 3 4 | 3 5 | 3 6 | 3 7 | 3 8 | 3 9 | 4 0 | 4 5 | 1 1 2 | 1 1 3 | 1 1 4 | 1 1 5 | 1 1 6 | 1 1 7 | 1 1 8 | 1 1 9 | 1 2 0 | 1 2 1 | 1 2 2 | 1 2 3 | 1 4 4 | 1 4 5 ) $ / i;
17
34
var UNDO_TRIGGER_KEYS = / ^ ( 8 | 1 3 | 3 2 | 4 6 | 5 9 | 6 1 | 1 0 7 | 1 0 9 | 1 8 6 | 1 8 7 | 1 8 8 | 1 8 9 | 1 9 0 | 1 9 1 | 1 9 2 | 2 1 9 | 2 2 0 | 2 2 1 | 2 2 2 ) $ / i; // spaces, enter, delete, backspace, all punctuation
18
- var INLINETAGS_NONBLANK = / < ( a | a b b r | a c r o n y m | b d i | b d o | b i g | c i t e | c o d e | d e l | d f n | i m g | i n s | k b d | l a b e l | m a p | m a r k | q | r u b y | r p | r t | s | s a m p | t i m e | t t | v a r ) [ ^ > ] * > / i;
19
35
20
36
// defaults to the paragraph element, but we need the line-break or it doesn't allow you to type into the empty element
21
37
// non IE is '<p><br/></p>', ie is '<p></p>' as for once IE gets it correct...
@@ -39,16 +55,7 @@ angular.module('textAngular.taBind', ['textAngular.factories', 'textAngular.DOM'
39
55
'<' + attrs . taDefaultWrap + '> </' + attrs . taDefaultWrap + '>' ;
40
56
}
41
57
42
- var _blankTest = function ( _blankVal ) {
43
- var _firstTagIndex = _blankVal . indexOf ( '>' ) ;
44
- if ( _firstTagIndex === - 1 ) return _blankVal . trim ( ) . length === 0 ;
45
- _blankVal = _blankVal . trim ( ) . substring ( _firstTagIndex , _firstTagIndex + 100 ) ;
46
- // this regex is to match any number of whitespace only between two tags
47
- if ( _blankVal . length === 0 || _blankVal === _defaultTest || / ^ > ( \s | & n b s p ; ) * < \/ [ ^ > ] + > $ / ig. test ( _blankVal ) ) return true ;
48
- // this regex tests if there is a tag followed by some optional whitespace and some text after that
49
- else if ( / > \s * [ ^ \s < ] / i. test ( _blankVal ) || INLINETAGS_NONBLANK . test ( _blankVal ) ) return false ;
50
- else return true ;
51
- } ;
58
+ var _blankTest = _taBlankTest ( _defaultTest ) ;
52
59
53
60
element . addClass ( 'ta-bind' ) ;
54
61
0 commit comments