@@ -63,12 +63,12 @@ define([
63
63
/**
64
64
* Render tooltips by attributes (only to up).
65
65
* Required element attributes:
66
- * - option-type (integer, 0-3)
67
- * - option-label (string)
68
- * - option-tooltip-thumb
69
- * - option-tooltip-value
70
- * - thumb-width
71
- * - thumb-height
66
+ * - data- option-type (integer, 0-3)
67
+ * - data- option-label (string)
68
+ * - data- option-tooltip-thumb
69
+ * - data- option-tooltip-value
70
+ * - data- thumb-width
71
+ * - data- thumb-height
72
72
*/
73
73
$ . widget ( 'mage.SwatchRendererTooltip' , {
74
74
options : {
@@ -84,12 +84,12 @@ define([
84
84
$this = this . element ,
85
85
$element = $ ( '.' + $widget . options . tooltipClass ) ,
86
86
timer ,
87
- type = parseInt ( $this . attr ( 'option-type' ) , 10 ) ,
88
- label = $this . attr ( 'option-label' ) ,
89
- thumb = $this . attr ( 'option-tooltip-thumb' ) ,
90
- value = $this . attr ( 'option-tooltip-value' ) ,
91
- width = $this . attr ( 'thumb-width' ) ,
92
- height = $this . attr ( 'thumb-height' ) ,
87
+ type = parseInt ( $this . data ( 'option-type' ) , 10 ) ,
88
+ label = $this . data ( 'option-label' ) ,
89
+ thumb = $this . data ( 'option-tooltip-thumb' ) ,
90
+ value = $this . data ( 'option-tooltip-value' ) ,
91
+ width = $this . data ( 'thumb-width' ) ,
92
+ height = $this . data ( 'thumb-height' ) ,
93
93
$image ,
94
94
$title ,
95
95
$corner ;
@@ -429,8 +429,8 @@ define([
429
429
// Create new control
430
430
container . append (
431
431
'<div class="' + classes . attributeClass + ' ' + item . code + '" ' +
432
- 'attribute-code="' + item . code + '" ' +
433
- 'attribute-id="' + item . id + '">' +
432
+ 'data- attribute-code="' + item . code + '" ' +
433
+ 'data- attribute-id="' + item . id + '">' +
434
434
label +
435
435
'<div aria-activedescendant="" ' +
436
436
'tabindex="0" ' +
@@ -462,7 +462,8 @@ define([
462
462
if ( showTooltip === 1 ) {
463
463
// Connect Tooltip
464
464
container
465
- . find ( '[option-type="1"], [option-type="2"], [option-type="0"], [option-type="3"]' )
465
+ . find ( '[data-option-type="1"], [data-option-type="2"],' +
466
+ ' [data-option-type="0"], [data-option-type="3"]' )
466
467
. SwatchRendererTooltip ( ) ;
467
468
}
468
469
@@ -537,21 +538,22 @@ define([
537
538
' aria-checked="false"' +
538
539
' aria-describedby="' + controlId + '"' +
539
540
' tabindex="0"' +
540
- ' option-type="' + type + '"' +
541
- ' option-id="' + id + '"' +
542
- ' option-label="' + label + '"' +
541
+ ' data- option-type="' + type + '"' +
542
+ ' data- option-id="' + id + '"' +
543
+ ' data- option-label="' + label + '"' +
543
544
' aria-label="' + label + '"' +
544
- ' option-tooltip-thumb="' + thumb + '"' +
545
- ' option-tooltip-value="' + value + '"' +
546
545
' role="option"' +
547
- ' thumb-width="' + width + '"' +
548
- ' thumb-height="' + height + '"' ;
546
+ ' data-thumb-width="' + width + '"' +
547
+ ' data-thumb-height="' + height + '"' ;
548
+
549
+ attr += thumb !== '' ? ' data-option-tooltip-thumb="' + thumb + '"' : '' ;
550
+ attr += value !== '' ? ' data-option-tooltip-value="' + value + '"' : '' ;
549
551
550
552
swatchImageWidth = _ . has ( sizeConfig , 'swatchImage' ) ? sizeConfig . swatchImage . width : 30 ;
551
553
swatchImageHeight = _ . has ( sizeConfig , 'swatchImage' ) ? sizeConfig . swatchImage . height : 20 ;
552
554
553
555
if ( ! this . hasOwnProperty ( 'products' ) || this . products . length <= 0 ) {
554
- attr += ' option-empty="true"' ;
556
+ attr += ' data- option-empty="true"' ;
555
557
}
556
558
557
559
if ( type === 0 ) {
@@ -599,14 +601,14 @@ define([
599
601
600
602
html =
601
603
'<select class="' + this . options . classes . selectClass + ' ' + config . code + '">' +
602
- '<option value="0" option-id="0">' + chooseText + '</option>' ;
604
+ '<option value="0" data- option-id="0">' + chooseText + '</option>' ;
603
605
604
606
$ . each ( config . options , function ( ) {
605
607
var label = this . label ,
606
- attr = ' value="' + this . id + '" option-id="' + this . id + '"' ;
608
+ attr = ' value="' + this . id + '" data- option-id="' + this . id + '"' ;
607
609
608
610
if ( ! this . hasOwnProperty ( 'products' ) || this . products . length <= 0 ) {
609
- attr += ' option-empty="true"' ;
611
+ attr += ' data- option-empty="true"' ;
610
612
}
611
613
612
614
html += '<option ' + attr + '>' + label + '</option>' ;
@@ -721,7 +723,7 @@ define([
721
723
var $parent = $this . parents ( '.' + $widget . options . classes . attributeClass ) ,
722
724
$wrapper = $this . parents ( '.' + $widget . options . classes . attributeOptionsWrapper ) ,
723
725
$label = $parent . find ( '.' + $widget . options . classes . attributeSelectedOptionLabelClass ) ,
724
- attributeId = $parent . attr ( 'attribute-id' ) ,
726
+ attributeId = $parent . data ( 'attribute-id' ) ,
725
727
$input = $parent . find ( '.' + $widget . options . classes . attributeInput ) ,
726
728
checkAdditionalData = JSON . parse ( this . options . jsonSwatchConfig [ attributeId ] [ 'additional_data' ] ) ,
727
729
$priceBox = $widget . element . parents ( $widget . options . selectorProduct )
@@ -738,14 +740,14 @@ define([
738
740
}
739
741
740
742
if ( $this . hasClass ( 'selected' ) ) {
741
- $parent . removeAttr ( 'option-selected' ) . find ( '.selected' ) . removeClass ( 'selected' ) ;
743
+ $parent . removeAttr ( 'data- option-selected' ) . find ( '.selected' ) . removeClass ( 'selected' ) ;
742
744
$input . val ( '' ) ;
743
745
$label . text ( '' ) ;
744
746
$this . attr ( 'aria-checked' , false ) ;
745
747
} else {
746
- $parent . attr ( 'option-selected' , $this . attr ( 'option-id' ) ) . find ( '.selected' ) . removeClass ( 'selected' ) ;
747
- $label . text ( $this . attr ( 'option-label' ) ) ;
748
- $input . val ( $this . attr ( 'option-id' ) ) ;
748
+ $parent . attr ( 'data- option-selected' , $this . data ( 'option-id' ) ) . find ( '.selected' ) . removeClass ( 'selected' ) ;
749
+ $label . text ( $this . data ( 'option-label' ) ) ;
750
+ $input . val ( $this . data ( 'option-id' ) ) ;
749
751
$input . attr ( 'data-attr-name' , this . _getAttributeCodeById ( attributeId ) ) ;
750
752
$this . addClass ( 'selected' ) ;
751
753
$widget . _toggleCheckedAttributes ( $this , $wrapper ) ;
@@ -822,7 +824,7 @@ define([
822
824
*/
823
825
_OnChange : function ( $this , $widget ) {
824
826
var $parent = $this . parents ( '.' + $widget . options . classes . attributeClass ) ,
825
- attributeId = $parent . attr ( 'attribute-id' ) ,
827
+ attributeId = $parent . data ( 'attribute-id' ) ,
826
828
$input = $parent . find ( '.' + $widget . options . classes . attributeInput ) ;
827
829
828
830
if ( $widget . productForm . length > 0 ) {
@@ -832,10 +834,10 @@ define([
832
834
}
833
835
834
836
if ( $this . val ( ) > 0 ) {
835
- $parent . attr ( 'option-selected' , $this . val ( ) ) ;
837
+ $parent . attr ( 'data- option-selected' , $this . val ( ) ) ;
836
838
$input . val ( $this . val ( ) ) ;
837
839
} else {
838
- $parent . removeAttr ( 'option-selected' ) ;
840
+ $parent . removeAttr ( 'data- option-selected' ) ;
839
841
$input . val ( '' ) ;
840
842
}
841
843
@@ -862,8 +864,8 @@ define([
862
864
* @private
863
865
*/
864
866
_Rewind : function ( controls ) {
865
- controls . find ( 'div[option-id], option[option-id]' ) . removeClass ( 'disabled' ) . removeAttr ( 'disabled' ) ;
866
- controls . find ( 'div[option-empty], option[option-empty]' )
867
+ controls . find ( 'div[data- option-id], option[data- option-id]' ) . removeClass ( 'disabled' ) . removeAttr ( 'disabled' ) ;
868
+ controls . find ( 'div[data- option-empty], option[data- option-empty]' )
867
869
. attr ( 'disabled' , true )
868
870
. addClass ( 'disabled' )
869
871
. attr ( 'tabindex' , '-1' ) ;
@@ -876,8 +878,8 @@ define([
876
878
*/
877
879
_Rebuild : function ( ) {
878
880
var $widget = this ,
879
- controls = $widget . element . find ( '.' + $widget . options . classes . attributeClass + '[attribute-id]' ) ,
880
- selected = controls . filter ( '[option-selected]' ) ;
881
+ controls = $widget . element . find ( '.' + $widget . options . classes . attributeClass + '[data- attribute-id]' ) ,
882
+ selected = controls . filter ( '[data- option-selected]' ) ;
881
883
882
884
// Enable all options
883
885
$widget . _Rewind ( controls ) ;
@@ -890,16 +892,16 @@ define([
890
892
// Disable not available options
891
893
controls . each ( function ( ) {
892
894
var $this = $ ( this ) ,
893
- id = $this . attr ( 'attribute-id' ) ,
895
+ id = $this . data ( 'attribute-id' ) ,
894
896
products = $widget . _CalcProducts ( id ) ;
895
897
896
- if ( selected . length === 1 && selected . first ( ) . attr ( 'attribute-id' ) === id ) {
898
+ if ( selected . length === 1 && selected . first ( ) . data ( 'attribute-id' ) === id ) {
897
899
return ;
898
900
}
899
901
900
- $this . find ( '[option-id]' ) . each ( function ( ) {
902
+ $this . find ( '[data- option-id]' ) . each ( function ( ) {
901
903
var $element = $ ( this ) ,
902
- option = $element . attr ( 'option-id' ) ;
904
+ option = $element . data ( 'option-id' ) ;
903
905
904
906
if ( ! $widget . optionsMap . hasOwnProperty ( id ) || ! $widget . optionsMap [ id ] . hasOwnProperty ( option ) ||
905
907
$element . hasClass ( 'selected' ) ||
@@ -922,12 +924,13 @@ define([
922
924
*/
923
925
_CalcProducts : function ( $skipAttributeId ) {
924
926
var $widget = this ,
927
+ selectedOptions = '.' + $widget . options . classes . attributeClass + '[data-option-selected]' ,
925
928
products = [ ] ;
926
929
927
930
// Generate intersection of products
928
- $widget . element . find ( '.' + $widget . options . classes . attributeClass + '[option-selected]' ) . each ( function ( ) {
929
- var id = $ ( this ) . attr ( 'attribute-id' ) ,
930
- option = $ ( this ) . attr ( 'option-selected' ) ;
931
+ $widget . element . find ( selectedOptions ) . each ( function ( ) {
932
+ var id = $ ( this ) . data ( 'attribute-id' ) ,
933
+ option = $ ( this ) . attr ( 'data- option-selected' ) ;
931
934
932
935
if ( $skipAttributeId !== undefined && $skipAttributeId === id ) {
933
936
return ;
@@ -1353,7 +1356,7 @@ define([
1353
1356
_EmulateSelected : function ( selectedAttributes ) {
1354
1357
$ . each ( selectedAttributes , $ . proxy ( function ( attributeCode , optionId ) {
1355
1358
var elem = this . element . find ( '.' + this . options . classes . attributeClass +
1356
- '[attribute-code="' + attributeCode + '"] [option-id="' + optionId + '"]' ) ,
1359
+ '[data- attribute-code="' + attributeCode + '"] [data- option-id="' + optionId + '"]' ) ,
1357
1360
parentInput = elem . parent ( ) ;
1358
1361
1359
1362
if ( elem . hasClass ( 'selected' ) ) {
@@ -1377,7 +1380,7 @@ define([
1377
1380
_EmulateSelectedByAttributeId : function ( selectedAttributes ) {
1378
1381
$ . each ( selectedAttributes , $ . proxy ( function ( attributeId , optionId ) {
1379
1382
var elem = this . element . find ( '.' + this . options . classes . attributeClass +
1380
- '[attribute-id="' + attributeId + '"] [option-id="' + optionId + '"]' ) ,
1383
+ '[data- attribute-id="' + attributeId + '"] [data- option-id="' + optionId + '"]' ) ,
1381
1384
parentInput = elem . parent ( ) ;
1382
1385
1383
1386
if ( elem . hasClass ( 'selected' ) ) {
0 commit comments