@@ -100,6 +100,8 @@ AnnotationBubble.prototype.showStub = function() {
100100 assert ( this . state == 'hidden' || this . state == 'edit' ) ;
101101 assert ( this . text == '' ) ;
102102
103+ var myBubble = this ; // to avoid name clashes with 'this' in inner scopes
104+
103105 // destroy then create a new tip:
104106 this . destroyQTip ( ) ;
105107 $ ( this . hashID ) . qtip ( $ . extend ( { } , qtipShared , {
@@ -115,12 +117,21 @@ AnnotationBubble.prototype.showStub = function() {
115117 }
116118 } ) ) ;
117119
120+
121+ $ ( this . qTipID ( ) )
122+ . unbind ( 'click' ) // unbind all old handlers
123+ . click ( function ( ) {
124+ myBubble . showEditor ( ) ;
125+ } ) ;
126+
118127 this . state = 'stub' ;
119128}
120129
121130AnnotationBubble . prototype . showEditor = function ( ) {
122131 assert ( this . state == 'stub' || this . state == 'view' ) ;
123132
133+ var myBubble = this ; // to avoid name clashes with 'this' in inner scopes
134+
124135 var ta = '<textarea class="bubbleInputText">' + this . text + '</textarea>' ;
125136
126137 // destroy then create a new tip:
@@ -135,6 +146,20 @@ AnnotationBubble.prototype.showEditor = function() {
135146 }
136147 } ) ) ;
137148
149+
150+ $ ( this . qTipContentID ( ) ) . find ( 'textarea.bubbleInputText' )
151+ . blur ( function ( ) { // set handler when the textarea loses focus
152+ myBubble . text = $ ( this ) . val ( ) . trim ( ) ; // strip all leading and trailing spaces
153+
154+ if ( myBubble . text ) {
155+ myBubble . showViewer ( ) ;
156+ }
157+ else {
158+ myBubble . showStub ( ) ;
159+ }
160+ } )
161+ . focus ( ) ; // grab focus so that the user can start typing right away!
162+
138163 this . state = 'edit' ;
139164}
140165
@@ -169,6 +194,19 @@ AnnotationBubble.prototype.restoreViewer = function() {
169194 this . state = 'view' ;
170195}
171196
197+ AnnotationBubble . prototype . enterHiddenMode = function ( ) {
198+ assert ( this . state == 'stub' || this . state == 'edit' ) ;
199+ this . destroyQTip ( ) ;
200+ this . state = 'hidden' ;
201+ }
202+
203+ AnnotationBubble . prototype . qTipContentID = function ( ) {
204+ return '#ui-tooltip-' + this . domID + '-content' ;
205+ }
206+
207+ AnnotationBubble . prototype . qTipID = function ( ) {
208+ return '#ui-tooltip-' + this . domID ;
209+ }
172210
173211AnnotationBubble . prototype . destroyQTip = function ( ) {
174212 $ ( this . hashID ) . qtip ( 'destroy' ) ;
@@ -222,4 +260,5 @@ $(document).ready(function() {
222260 */
223261
224262 x = new AnnotationBubble ( 'frame' , 'v1__stack2' ) ;
263+ x . showStub ( ) ;
225264} ) ;
0 commit comments