@@ -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,7 @@ 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"], [data- option-type="0"], [data- option-type="3"]' )
466
466
. SwatchRendererTooltip ( ) ;
467
467
}
468
468
@@ -537,21 +537,22 @@ define([
537
537
' aria-checked="false"' +
538
538
' aria-describedby="' + controlId + '"' +
539
539
' tabindex="0"' +
540
- ' option-type="' + type + '"' +
541
- ' option-id="' + id + '"' +
542
- ' option-label="' + label + '"' +
540
+ ' data- option-type="' + type + '"' +
541
+ ' data- option-id="' + id + '"' +
542
+ ' data- option-label="' + label + '"' +
543
543
' aria-label="' + label + '"' +
544
- ' option-tooltip-thumb="' + thumb + '"' +
545
- ' option-tooltip-value="' + value + '"' +
546
544
' role="option"' +
547
- ' thumb-width="' + width + '"' +
548
- ' thumb-height="' + height + '"' ;
545
+ ' data-thumb-width="' + width + '"' +
546
+ ' data-thumb-height="' + height + '"' ;
547
+
548
+ attr += thumb !== '' ? ' data-option-tooltip-thumb="' + thumb + '"' : '' ;
549
+ attr += value !== '' ? ' data-option-tooltip-value="' + value + '"' : '' ;
549
550
550
551
swatchImageWidth = _ . has ( sizeConfig , 'swatchImage' ) ? sizeConfig . swatchImage . width : 30 ;
551
552
swatchImageHeight = _ . has ( sizeConfig , 'swatchImage' ) ? sizeConfig . swatchImage . height : 20 ;
552
553
553
554
if ( ! this . hasOwnProperty ( 'products' ) || this . products . length <= 0 ) {
554
- attr += ' option-empty="true"' ;
555
+ attr += ' data- option-empty="true"' ;
555
556
}
556
557
557
558
if ( type === 0 ) {
@@ -599,14 +600,14 @@ define([
599
600
600
601
html =
601
602
'<select class="' + this . options . classes . selectClass + ' ' + config . code + '">' +
602
- '<option value="0" option-id="0">' + chooseText + '</option>' ;
603
+ '<option value="0" data- option-id="0">' + chooseText + '</option>' ;
603
604
604
605
$ . each ( config . options , function ( ) {
605
606
var label = this . label ,
606
- attr = ' value="' + this . id + '" option-id="' + this . id + '"' ;
607
+ attr = ' value="' + this . id + '" data- option-id="' + this . id + '"' ;
607
608
608
609
if ( ! this . hasOwnProperty ( 'products' ) || this . products . length <= 0 ) {
609
- attr += ' option-empty="true"' ;
610
+ attr += ' data- option-empty="true"' ;
610
611
}
611
612
612
613
html += '<option ' + attr + '>' + label + '</option>' ;
@@ -721,7 +722,7 @@ define([
721
722
var $parent = $this . parents ( '.' + $widget . options . classes . attributeClass ) ,
722
723
$wrapper = $this . parents ( '.' + $widget . options . classes . attributeOptionsWrapper ) ,
723
724
$label = $parent . find ( '.' + $widget . options . classes . attributeSelectedOptionLabelClass ) ,
724
- attributeId = $parent . attr ( 'attribute-id' ) ,
725
+ attributeId = $parent . data ( 'attribute-id' ) ,
725
726
$input = $parent . find ( '.' + $widget . options . classes . attributeInput ) ,
726
727
checkAdditionalData = JSON . parse ( this . options . jsonSwatchConfig [ attributeId ] [ 'additional_data' ] ) ;
727
728
@@ -736,14 +737,14 @@ define([
736
737
}
737
738
738
739
if ( $this . hasClass ( 'selected' ) ) {
739
- $parent . removeAttr ( 'option-selected' ) . find ( '.selected' ) . removeClass ( 'selected' ) ;
740
+ $parent . removeAttr ( 'data- option-selected' ) . find ( '.selected' ) . removeClass ( 'selected' ) ;
740
741
$input . val ( '' ) ;
741
742
$label . text ( '' ) ;
742
743
$this . attr ( 'aria-checked' , false ) ;
743
744
} else {
744
- $parent . attr ( 'option-selected' , $this . attr ( 'option-id' ) ) . find ( '.selected' ) . removeClass ( 'selected' ) ;
745
- $label . text ( $this . attr ( 'option-label' ) ) ;
746
- $input . val ( $this . attr ( 'option-id' ) ) ;
745
+ $parent . attr ( 'data- option-selected' , $this . data ( 'option-id' ) ) . find ( '.selected' ) . removeClass ( 'selected' ) ;
746
+ $label . text ( $this . data ( 'option-label' ) ) ;
747
+ $input . val ( $this . data ( 'option-id' ) ) ;
747
748
$input . attr ( 'data-attr-name' , this . _getAttributeCodeById ( attributeId ) ) ;
748
749
$this . addClass ( 'selected' ) ;
749
750
$widget . _toggleCheckedAttributes ( $this , $wrapper ) ;
@@ -805,7 +806,7 @@ define([
805
806
*/
806
807
_OnChange : function ( $this , $widget ) {
807
808
var $parent = $this . parents ( '.' + $widget . options . classes . attributeClass ) ,
808
- attributeId = $parent . attr ( 'attribute-id' ) ,
809
+ attributeId = $parent . data ( 'attribute-id' ) ,
809
810
$input = $parent . find ( '.' + $widget . options . classes . attributeInput ) ;
810
811
811
812
if ( $widget . productForm . length > 0 ) {
@@ -815,10 +816,10 @@ define([
815
816
}
816
817
817
818
if ( $this . val ( ) > 0 ) {
818
- $parent . attr ( 'option-selected' , $this . val ( ) ) ;
819
+ $parent . attr ( 'data- option-selected' , $this . val ( ) ) ;
819
820
$input . val ( $this . val ( ) ) ;
820
821
} else {
821
- $parent . removeAttr ( 'option-selected' ) ;
822
+ $parent . removeAttr ( 'data- option-selected' ) ;
822
823
$input . val ( '' ) ;
823
824
}
824
825
@@ -845,8 +846,8 @@ define([
845
846
* @private
846
847
*/
847
848
_Rewind : function ( controls ) {
848
- controls . find ( 'div[option-id], option[option-id]' ) . removeClass ( 'disabled' ) . removeAttr ( 'disabled' ) ;
849
- controls . find ( 'div[option-empty], option[option-empty]' )
849
+ controls . find ( 'div[data- option-id], option[data- option-id]' ) . removeClass ( 'disabled' ) . removeAttr ( 'disabled' ) ;
850
+ controls . find ( 'div[data- option-empty], option[data- option-empty]' )
850
851
. attr ( 'disabled' , true )
851
852
. addClass ( 'disabled' )
852
853
. attr ( 'tabindex' , '-1' ) ;
@@ -859,8 +860,8 @@ define([
859
860
*/
860
861
_Rebuild : function ( ) {
861
862
var $widget = this ,
862
- controls = $widget . element . find ( '.' + $widget . options . classes . attributeClass + '[attribute-id]' ) ,
863
- selected = controls . filter ( '[option-selected]' ) ;
863
+ controls = $widget . element . find ( '.' + $widget . options . classes . attributeClass + '[data- attribute-id]' ) ,
864
+ selected = controls . filter ( '[data- option-selected]' ) ;
864
865
865
866
// Enable all options
866
867
$widget . _Rewind ( controls ) ;
@@ -873,16 +874,16 @@ define([
873
874
// Disable not available options
874
875
controls . each ( function ( ) {
875
876
var $this = $ ( this ) ,
876
- id = $this . attr ( 'attribute-id' ) ,
877
+ id = $this . data ( 'attribute-id' ) ,
877
878
products = $widget . _CalcProducts ( id ) ;
878
879
879
- if ( selected . length === 1 && selected . first ( ) . attr ( 'attribute-id' ) === id ) {
880
+ if ( selected . length === 1 && selected . first ( ) . data ( 'attribute-id' ) === id ) {
880
881
return ;
881
882
}
882
883
883
- $this . find ( '[option-id]' ) . each ( function ( ) {
884
+ $this . find ( '[data- option-id]' ) . each ( function ( ) {
884
885
var $element = $ ( this ) ,
885
- option = $element . attr ( 'option-id' ) ;
886
+ option = $element . data ( 'option-id' ) ;
886
887
887
888
if ( ! $widget . optionsMap . hasOwnProperty ( id ) || ! $widget . optionsMap [ id ] . hasOwnProperty ( option ) ||
888
889
$element . hasClass ( 'selected' ) ||
@@ -905,12 +906,13 @@ define([
905
906
*/
906
907
_CalcProducts : function ( $skipAttributeId ) {
907
908
var $widget = this ,
909
+ selectedOptions = '.' + $widget . options . classes . attributeClass + '[data-option-selected]' ,
908
910
products = [ ] ;
909
911
910
912
// Generate intersection of products
911
- $widget . element . find ( '.' + $widget . options . classes . attributeClass + '[option-selected]' ) . each ( function ( ) {
912
- var id = $ ( this ) . attr ( 'attribute-id' ) ,
913
- option = $ ( this ) . attr ( 'option-selected' ) ;
913
+ $widget . element . find ( selectedOptions ) . each ( function ( ) {
914
+ var id = $ ( this ) . data ( 'attribute-id' ) ,
915
+ option = $ ( this ) . attr ( 'data- option-selected' ) ;
914
916
915
917
if ( $skipAttributeId !== undefined && $skipAttributeId === id ) {
916
918
return ;
@@ -1322,7 +1324,7 @@ define([
1322
1324
_EmulateSelected : function ( selectedAttributes ) {
1323
1325
$ . each ( selectedAttributes , $ . proxy ( function ( attributeCode , optionId ) {
1324
1326
var elem = this . element . find ( '.' + this . options . classes . attributeClass +
1325
- '[attribute-code="' + attributeCode + '"] [option-id="' + optionId + '"]' ) ,
1327
+ '[data- attribute-code="' + attributeCode + '"] [data- option-id="' + optionId + '"]' ) ,
1326
1328
parentInput = elem . parent ( ) ;
1327
1329
1328
1330
if ( elem . hasClass ( 'selected' ) ) {
@@ -1346,7 +1348,7 @@ define([
1346
1348
_EmulateSelectedByAttributeId : function ( selectedAttributes ) {
1347
1349
$ . each ( selectedAttributes , $ . proxy ( function ( attributeId , optionId ) {
1348
1350
var elem = this . element . find ( '.' + this . options . classes . attributeClass +
1349
- '[attribute-id="' + attributeId + '"] [option-id="' + optionId + '"]' ) ,
1351
+ '[data- attribute-id="' + attributeId + '"] [data- option-id="' + optionId + '"]' ) ,
1350
1352
parentInput = elem . parent ( ) ;
1351
1353
1352
1354
if ( elem . hasClass ( 'selected' ) ) {
0 commit comments