@@ -685,8 +685,18 @@ EditableController = (function(superClass) {
685
685
return e . type === 'click' || ( ( ref = e . which ) === KEY_CODE . RIGHT || ref === KEY_CODE . LEFT || ref === KEY_CODE . UP || ref === KEY_CODE . DOWN ) ;
686
686
} ;
687
687
688
+ EditableController . prototype . _unwrap = function ( node ) {
689
+ var next ;
690
+ node = $ ( node ) . unwrap ( ) . get ( 0 ) ;
691
+ if ( ( next = node . nextSibling ) && next . nodeValue ) {
692
+ node . nodeValue += next . nodeValue ;
693
+ $ ( next ) . remove ( ) ;
694
+ }
695
+ return node ;
696
+ } ;
697
+
688
698
EditableController . prototype . catchQuery = function ( e ) {
689
- var $inserted , $query , _range , index , inserted , isString , lastNode , matched , offset , parentNode , query , query_content , range ;
699
+ var $inserted , $query , _range , index , inserted , isString , lastNode , matched , offset , query , query_content , range ;
690
700
if ( ! ( range = this . _getRange ( ) ) ) {
691
701
return ;
692
702
}
@@ -780,9 +790,7 @@ EditableController = (function(superClass) {
780
790
if ( this . _movingEvent ( e ) && $query . hasClass ( 'atwho-inserted' ) ) {
781
791
$query . removeClass ( 'atwho-query' ) ;
782
792
} else if ( false !== this . callbacks ( 'afterMatchFailed' ) . call ( this , this . at , $query ) ) {
783
- parentNode = $query [ 0 ] . parentNode ;
784
- this . _setRange ( "after" , $query . text ( $query . text ( ) ) . contents ( ) . first ( ) . unwrap ( ) ) ;
785
- parentNode . normalize ( ) ;
793
+ this . _setRange ( "after" , this . _unwrap ( $query . text ( $query . text ( ) ) . contents ( ) . first ( ) ) ) ;
786
794
}
787
795
}
788
796
return null ;
@@ -894,14 +902,19 @@ View = (function() {
894
902
function View ( context ) {
895
903
this . context = context ;
896
904
this . $el = $ ( "<div class='atwho-view'><ul class='atwho-view-ul'></ul></div>" ) ;
905
+ this . $elUl = this . $el . children ( ) ;
897
906
this . timeoutID = null ;
898
907
this . context . $el . append ( this . $el ) ;
899
908
this . bindEvent ( ) ;
900
909
}
901
910
902
911
View . prototype . init = function ( ) {
903
- var id ;
912
+ var header_tpl , id ;
904
913
id = this . context . getOpt ( "alias" ) || this . context . at . charCodeAt ( 0 ) ;
914
+ header_tpl = this . context . getOpt ( "headerTpl" ) ;
915
+ if ( header_tpl && this . $el . children ( ) . length === 1 ) {
916
+ this . $el . prepend ( header_tpl ) ;
917
+ }
905
918
return this . $el . attr ( {
906
919
'id' : "at-view-" + id
907
920
} ) ;
@@ -912,12 +925,26 @@ View = (function() {
912
925
} ;
913
926
914
927
View . prototype . bindEvent = function ( ) {
915
- var $menu ;
928
+ var $menu , lastCoordX , lastCoordY ;
916
929
$menu = this . $el . find ( 'ul' ) ;
917
- return $menu . on ( 'mouseenter.atwho-view' , 'li' , function ( e ) {
918
- $menu . find ( '.cur' ) . removeClass ( 'cur' ) ;
919
- return $ ( e . currentTarget ) . addClass ( 'cur' ) ;
920
- } ) . on ( 'click.atwho-view' , 'li' , ( function ( _this ) {
930
+ lastCoordX = 0 ;
931
+ lastCoordY = 0 ;
932
+ return $menu . on ( 'mousemove.atwho-view' , 'li' , ( function ( _this ) {
933
+ return function ( e ) {
934
+ var $cur ;
935
+ if ( lastCoordX === e . clientX && lastCoordY === e . clientY ) {
936
+ return ;
937
+ }
938
+ lastCoordX = e . clientX ;
939
+ lastCoordY = e . clientY ;
940
+ $cur = $ ( e . currentTarget ) ;
941
+ if ( $cur . hasClass ( 'cur' ) ) {
942
+ return ;
943
+ }
944
+ $menu . find ( '.cur' ) . removeClass ( 'cur' ) ;
945
+ return $cur . addClass ( 'cur' ) ;
946
+ } ;
947
+ } ) ( this ) ) . on ( 'click.atwho-view' , 'li' , ( function ( _this ) {
921
948
return function ( e ) {
922
949
$menu . find ( '.cur' ) . removeClass ( 'cur' ) ;
923
950
$ ( e . currentTarget ) . addClass ( 'cur' ) ;
@@ -977,7 +1004,7 @@ View = (function() {
977
1004
next = this . $el . find ( 'li:first' ) ;
978
1005
}
979
1006
next . addClass ( 'cur' ) ;
980
- return this . scrollTop ( Math . max ( 0 , cur . innerHeight ( ) * ( next . index ( ) + 2 ) - this . $el . height ( ) ) ) ;
1007
+ return this . scrollTop ( Math . max ( 0 , cur . outerHeight ( true ) * ( next . index ( ) + 2 ) - this . $el . height ( ) ) ) ;
981
1008
} ;
982
1009
983
1010
View . prototype . prev = function ( ) {
@@ -988,18 +1015,18 @@ View = (function() {
988
1015
prev = this . $el . find ( 'li:last' ) ;
989
1016
}
990
1017
prev . addClass ( 'cur' ) ;
991
- return this . scrollTop ( Math . max ( 0 , cur . innerHeight ( ) * ( prev . index ( ) + 2 ) - this . $el . height ( ) ) ) ;
1018
+ return this . scrollTop ( Math . max ( 0 , cur . outerHeight ( true ) * ( prev . index ( ) + 2 ) - this . $el . height ( ) ) ) ;
992
1019
} ;
993
1020
994
1021
View . prototype . scrollTop = function ( scrollTop ) {
995
1022
var scrollDuration ;
996
1023
scrollDuration = this . context . getOpt ( 'scrollDuration' ) ;
997
1024
if ( scrollDuration ) {
998
- return this . $el . animate ( {
1025
+ return this . $elUl . animate ( {
999
1026
scrollTop : scrollTop
1000
1027
} , scrollDuration ) ;
1001
1028
} else {
1002
- return this . $el . scrollTop ( scrollTop ) ;
1029
+ return this . $elUl . scrollTop ( scrollTop ) ;
1003
1030
}
1004
1031
} ;
1005
1032
0 commit comments