7
7
'underscore' ,
8
8
'./abstract' ,
9
9
'Magento_Ui/js/lib/key-codes' ,
10
- 'mage/translate'
11
- ] , function ( _ , Abstract , keyCodes , $t ) {
10
+ 'mage/translate' ,
11
+ 'jquery'
12
+ ] , function ( _ , Abstract , keyCodes , $t , $ ) {
12
13
'use strict' ;
13
14
14
15
/**
@@ -46,6 +47,7 @@ define([
46
47
filterInputValue : '' ,
47
48
filterOptionsFocus : false ,
48
49
multiselectFocus : false ,
50
+ mouseSenvity : null ,
49
51
selectedPlaceholders : {
50
52
defaultPlaceholder : $t ( 'Select...' ) ,
51
53
lotPlaceholders : $t ( 'Selected' )
@@ -239,9 +241,7 @@ define([
239
241
} ,
240
242
241
243
/**
242
- * get filtered value
243
- *
244
- * @returns {Array } filtered array
244
+ * Get filtered value*
245
245
*/
246
246
getValue : function ( ) {
247
247
var options = this . options ( ) ,
@@ -255,7 +255,7 @@ define([
255
255
} ,
256
256
257
257
/**
258
- * get selected element labels
258
+ * Get selected element labels
259
259
*
260
260
* @returns {Array } array labels
261
261
*/
@@ -301,16 +301,45 @@ define([
301
301
*
302
302
* @param {Object } data - object with data about this element
303
303
* @param {Number } index - element index
304
+ * @param {Object } event - mousemove event
305
+ */
306
+
307
+ onMousemove : function ( data , index , event ) {
308
+ var target = $ ( event . target ) ,
309
+ id ;
310
+
311
+ if ( this . isCursorPositionChange ( event ) ) {
312
+ return false ;
313
+ }
314
+
315
+ target . is ( 'li' ) ? id = target . index ( ) : id = target . parent ( 'li' ) . index ( ) ;
316
+ id !== this . hoverElIndex ( ) ? this . hoverElIndex ( id ) : false ;
317
+
318
+ this . setCursorPosition ( event ) ;
319
+ } ,
320
+
321
+ /**
322
+ * Set X and Y cursor position
323
+ *
324
+ * @param {Object } event - mousemove event
304
325
*/
305
- onHoveredIn : function ( data , index ) {
306
- this . hoverElIndex ( index ) ;
326
+ setCursorPosition : function ( event ) {
327
+ this . cursorPosition = {
328
+ x : event . pageX ,
329
+ y : event . pageY
330
+ } ;
307
331
} ,
308
332
309
333
/**
310
- * Remove hover to some list element and write element ID from variable
334
+ * Check previous and current cursor position
335
+ *
336
+ * @param {Object } event - mousemove event
337
+ * @returns {Boolean }
311
338
*/
312
- onHoveredOut : function ( ) {
313
- this . hoverElIndex ( null ) ;
339
+ isCursorPositionChange : function ( event ) {
340
+ return this . cursorPosition &&
341
+ this . cursorPosition . x === event . pageX &&
342
+ this . cursorPosition . y === event . pageY ;
314
343
} ,
315
344
316
345
/**
@@ -360,6 +389,7 @@ define([
360
389
if ( this . hoverElIndex ( ) !== this . options ( ) . length - 1 ) {
361
390
this . hoverElIndex ( this . hoverElIndex ( ) + 1 ) ;
362
391
} else {
392
+ this . mouseSenvity = 0 ;
363
393
this . hoverElIndex ( 0 ) ;
364
394
}
365
395
} else {
@@ -394,7 +424,7 @@ define([
394
424
var keyName = keyCodes [ event . keyCode ] ;
395
425
396
426
if ( this . isTabKey ( event ) ) {
397
- if ( ! this . filterOptionsFocus ( ) && this . listVisible ( ) && this . filterOptions ) {
427
+ if ( ! this . filterOptionsFocus ( ) && this . listVisible ( ) && this . filterOptions ) {
398
428
this . cacheUiSelect . blur ( ) ;
399
429
this . filterOptionsFocus ( true ) ;
400
430
this . cleanHoveredElement ( ) ;
0 commit comments