1- /**
2- * at.js - 1.5.1
3- * Copyright (c) 2016 chord.luo <[email protected] >; 4- * Homepage: http://ichord.github.com/At.js
5- * License: MIT
6- */
7- ( function ( root , factory ) {
8- if ( typeof define === 'function' && define . amd ) {
9- // AMD. Register as an anonymous module unless amdModuleId is set
10- define ( [ "jquery" ] , function ( a0 ) {
11- return ( factory ( a0 ) ) ;
12- } ) ;
13- } else if ( typeof exports === 'object' ) {
14- // Node. Does not work with strict CommonJS, but
15- // only CommonJS-like environments that support module.exports,
16- // like Node.
17- module . exports = factory ( require ( "jquery" ) ) ;
18- } else {
19- factory ( jQuery ) ;
20- }
21- } ( this , function ( $ ) {
221var DEFAULT_CALLBACKS , KEY_CODE ;
232
243KEY_CODE = {
@@ -705,27 +684,26 @@ EditableController = (function(superClass) {
705684 } ;
706685
707686 EditableController . prototype . catchQuery = function ( e ) {
708- var $inserted , $query , _range , index , inserted , isString , lastNode , matched , offset , query , query_content , range ;
687+ var $inserted , $query , _range , chosen , index , inserted , isString , lastNode , matched , offset , query , query_content , query_parent , range , wasAnInsertedMention ;
709688 if ( ! ( range = this . _getRange ( ) ) ) {
710689 return ;
711690 }
712691 if ( ! range . collapsed ) {
713692 return ;
714693 }
694+ this . $inputor . find ( 'font' ) . each ( function ( ) {
695+ return $ ( this ) . before ( $ ( this ) . text ( ) ) . remove ( ) ;
696+ } ) ;
715697 if ( e . which === KEY_CODE . ENTER ) {
716698 ( $query = $ ( range . startContainer ) . closest ( '.atwho-query' ) ) . contents ( ) . unwrap ( ) ;
717699 if ( $query . is ( ':empty' ) ) {
718700 $query . remove ( ) ;
719701 }
720- ( $query = $ ( ".atwho-query" , this . app . document ) ) . text ( $query . text ( ) ) . contents ( ) . last ( ) . unwrap ( ) ;
702+ ( $query = $ ( ".atwho-query" , this . inputor ) ) . text ( $query . text ( ) ) . contents ( ) . last ( ) . unwrap ( ) ;
721703 this . _clearRange ( ) ;
722704 return ;
723705 }
724706 if ( / f i r e f o x / i. test ( navigator . userAgent ) ) {
725- if ( $ ( range . startContainer ) . is ( this . $inputor ) ) {
726- this . _clearRange ( ) ;
727- return ;
728- }
729707 if ( e . which === KEY_CODE . BACKSPACE && range . startContainer . nodeType === document . ELEMENT_NODE && ( offset = range . startOffset - 1 ) >= 0 ) {
730708 _range = range . cloneRange ( ) ;
731709 _range . setStart ( range . startContainer , offset ) ;
@@ -741,35 +719,41 @@ EditableController = (function(superClass) {
741719 }
742720 }
743721 $ ( range . startContainer ) . closest ( '.atwho-inserted' ) . addClass ( 'atwho-query' ) . siblings ( ) . removeClass ( 'atwho-query' ) ;
744- if ( ( $query = $ ( ".atwho-query" , this . app . document ) ) . length > 0 && $query . is ( ':empty' ) && $query . text ( ) . length === 0 ) {
722+ if ( ( $query = $ ( ".atwho-query" , this . inputor ) ) . length > 0 && $query . is ( ':empty' ) && $query . text ( ) . length === 0 ) {
745723 $query . remove ( ) ;
724+ return ;
725+ }
726+ if ( ! ( query_parent = $ ( range . startContainer ) . closest ( '.atwho-query' ) ) . length ) {
727+ $ ( '.atwho-query' ) . removeClass ( 'atwho-query' ) ;
746728 }
729+ wasAnInsertedMention = $query . is ( '.atwho-inserted' ) ;
747730 if ( ! this . _movingEvent ( e ) ) {
748731 $query . removeClass ( 'atwho-inserted' ) ;
749- }
750- if ( $query . length > 0 ) {
751- switch ( e . which ) {
752- case KEY_CODE . LEFT :
753- this . _setRange ( 'before' , $query . get ( 0 ) , range ) ;
754- $query . removeClass ( 'atwho-query' ) ;
755- return ;
756- case KEY_CODE . RIGHT :
757- this . _setRange ( 'after' , $query . get ( 0 ) . nextSibling , range ) ;
758- $query . removeClass ( 'atwho-query' ) ;
759- return ;
732+ } else {
733+ if ( $query . length > 0 ) {
734+ return ;
760735 }
761736 }
762- if ( $query . length > 0 && ( query_content = $query . attr ( 'data-atwho-at-query' ) ) ) {
763- $query . empty ( ) . html ( query_content ) . attr ( 'data-atwho-at-query' , null ) ;
764- this . _setRange ( 'after' , $query . get ( 0 ) , range ) ;
737+ if ( $query . length > 0 && ( query_content = $query . text ( ) ) && wasAnInsertedMention ) {
738+ chosen = $query . attr ( 'data-atwho-chosen-value' ) ;
739+ if ( e . which === KEY_CODE . BACKSPACE ) {
740+ $query . remove ( ) ;
741+ return ;
742+ } else if ( chosen && query_content !== chosen ) {
743+ $query . before ( query_content ) . remove ( ) ;
744+ return ;
745+ }
765746 }
766747 _range = range . cloneRange ( ) ;
767748 _range . setStart ( range . startContainer , 0 ) ;
768749 matched = this . callbacks ( "matcher" ) . call ( this , this . at , _range . toString ( ) , this . getOpt ( 'startWithSpace' ) , this . getOpt ( "acceptSpaceBar" ) ) ;
769750 isString = typeof matched === 'string' ;
770- if ( $query . length === 0 && isString && ( index = range . startOffset - this . at . length - matched . length ) >= 0 ) {
751+ if ( $query . length === 0 && isString && ( index = range . startOffset - this . at . length - matched . length ) >= 0 && range . startContainer . nodeType === document . TEXT_NODE ) {
752+ console . trace ( 123 ) ;
753+ console . log ( "before" , range ) ;
771754 range . setStart ( range . startContainer , index ) ;
772755 $query = $ ( '<span/>' , this . app . document ) . attr ( this . getOpt ( "editableAtwhoQueryAttrs" ) ) . addClass ( 'atwho-query' ) ;
756+ console . log ( "after" , range ) ;
773757 range . surroundContents ( $query . get ( 0 ) ) ;
774758 lastNode = $query . contents ( ) . last ( ) . get ( 0 ) ;
775759 if ( / f i r e f o x / i. test ( navigator . userAgent ) ) {
@@ -783,7 +767,7 @@ EditableController = (function(superClass) {
783767 if ( isString && matched . length < this . getOpt ( 'minLen' , 0 ) ) {
784768 return ;
785769 }
786- if ( isString && matched . length <= this . getOpt ( 'maxLen' , 20 ) ) {
770+ if ( isString && matched !== null && matched . length <= this . getOpt ( 'maxLen' , 20 ) ) {
787771 query = {
788772 text : matched ,
789773 el : $query
@@ -820,12 +804,14 @@ EditableController = (function(superClass) {
820804
821805 EditableController . prototype . insert = function ( content , $li ) {
822806 var data , range , suffix , suffixNode ;
807+ console . trace ( 123 ) ;
823808 if ( ! this . $inputor . is ( ':focus' ) ) {
824809 this . $inputor . focus ( ) ;
825810 }
826811 suffix = ( suffix = this . getOpt ( 'suffix' ) ) === "" ? suffix : suffix || "\u00A0" ;
827812 data = $li . data ( 'item-data' ) ;
828- this . query . el . removeClass ( 'atwho-query' ) . addClass ( 'atwho-inserted' ) . html ( content ) . attr ( 'data-atwho-at-query' , "" + data [ 'atwho-at' ] + this . query . text ) ;
813+ console . log ( data ) ;
814+ this . query . el . removeClass ( 'atwho-query' ) . addClass ( 'atwho-inserted' ) . html ( content ) . attr ( 'data-atwho-at-query' , "" + data [ 'atwho-at' ] + data [ 'name' ] ) . attr ( 'data-atwho-chosen-value' , "" + data [ 'name' ] ) ;
829815 if ( range = this . _getRange ( ) ) {
830816 range . setEndAfter ( this . query . el [ 0 ] ) ;
831817 range . collapse ( false ) ;
@@ -1198,5 +1184,3 @@ $.fn.atwho["default"] = {
11981184} ;
11991185
12001186$ . fn . atwho . debug = false ;
1201-
1202- } ) ) ;
0 commit comments