| Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 1 | /** | 
 | 2 |  * Hint menu | 
 | 3 |  */ | 
| Akron | 1ff3ac2 | 2016-04-28 16:30:45 +0200 | [diff] [blame] | 4 | define(['menu', | 
 | 5 | 	'hint/item', | 
 | 6 | 	'hint/prefix', | 
 | 7 | 	'hint/lengthField'], function (menuClass, itemClass, prefixClass, lengthFieldClass) { | 
| Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 8 |   return { | 
| Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 9 |  | 
 | 10 |     /** | 
 | 11 |      * Create new hint helper menu. | 
 | 12 |      */ | 
| Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 13 |     create : function (hint, context, params) { | 
 | 14 |       var obj = Object.create(menuClass) | 
| Akron | 72f7357 | 2017-12-05 12:31:09 +0100 | [diff] [blame] | 15 | 	        .upgradeTo(this) | 
 | 16 | 	        ._init(params, { | 
 | 17 | 	          itemClass : itemClass, | 
 | 18 | 	          prefixClass : prefixClass, | 
 | 19 | 	          lengthFieldClass : lengthFieldClass | 
 | 20 | 	        }); | 
| Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 21 |       obj._context = context; | 
 | 22 |       obj._element.classList.add('hint'); | 
 | 23 |       obj._hint = hint; | 
 | 24 |  | 
| Nils Diewald | 20f7ace | 2015-05-07 12:51:34 +0000 | [diff] [blame] | 25 |       // Make the top item always active | 
 | 26 |       obj._firstActive = true; | 
 | 27 |  | 
| Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 28 |       // This is only domspecific | 
 | 29 |       obj.element().addEventListener('blur', function (e) { | 
| Akron | e39cc86 | 2018-04-25 15:16:11 +0200 | [diff] [blame] | 30 |         this.menu.hideWithoutDestruction(); | 
| Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 31 |       }); | 
 | 32 |  | 
 | 33 |       // Focus on input field on hide | 
 | 34 |       obj.onHide = function () { | 
| Akron | 72f7357 | 2017-12-05 12:31:09 +0100 | [diff] [blame] | 35 | 	      this._hint.unshow(); | 
| Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 36 |       }; | 
 | 37 |  | 
 | 38 |       return obj; | 
 | 39 |     }, | 
| Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 40 |  | 
 | 41 |     /** | 
 | 42 |      * The hint helper object, | 
 | 43 |      * the menu is attached to. | 
 | 44 |      */  | 
| Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 45 |     hint : function () { | 
 | 46 |       return this._hint; | 
| Akron | e39cc86 | 2018-04-25 15:16:11 +0200 | [diff] [blame] | 47 |     }, | 
 | 48 |  | 
 | 49 |     /** | 
 | 50 |      * Hide the menu just for the moment, | 
| Akron | 95abaf4 | 2018-04-26 15:33:22 +0200 | [diff] [blame] | 51 |      * without cleaning up anything, | 
 | 52 |      /* but resetting the prefix. | 
| Akron | e39cc86 | 2018-04-25 15:16:11 +0200 | [diff] [blame] | 53 |      */ | 
 | 54 |     hideWithoutDestruction : function () { | 
 | 55 |       this.element().classList.remove("visible"); | 
| Akron | 95abaf4 | 2018-04-26 15:33:22 +0200 | [diff] [blame] | 56 |       if (this._hint) { | 
| Akron | e39cc86 | 2018-04-25 15:16:11 +0200 | [diff] [blame] | 57 |         this._hint.inputField().element().focus(); | 
| Akron | 95abaf4 | 2018-04-26 15:33:22 +0200 | [diff] [blame] | 58 |       }; | 
| Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 59 |     } | 
 | 60 |   }; | 
 | 61 | }); |