@@ -63,12 +63,12 @@ define([
6363 /**
6464 * Render tooltips by attributes (only to up).
6565 * 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
7272 */
7373 $ . widget ( 'mage.SwatchRendererTooltip' , {
7474 options : {
@@ -84,12 +84,12 @@ define([
8484 $this = this . element ,
8585 $element = $ ( '.' + $widget . options . tooltipClass ) ,
8686 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' ) ,
9393 $image ,
9494 $title ,
9595 $corner ;
@@ -429,8 +429,8 @@ define([
429429 // Create new control
430430 container . append (
431431 '<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 + '">' +
434434 label +
435435 '<div aria-activedescendant="" ' +
436436 'tabindex="0" ' +
@@ -462,7 +462,8 @@ define([
462462 if ( showTooltip === 1 ) {
463463 // Connect Tooltip
464464 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"]' )
466467 . SwatchRendererTooltip ( ) ;
467468 }
468469
@@ -537,21 +538,22 @@ define([
537538 ' aria-checked="false"' +
538539 ' aria-describedby="' + controlId + '"' +
539540 ' 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 + '"' +
543544 ' aria-label="' + label + '"' +
544- ' option-tooltip-thumb="' + thumb + '"' +
545- ' option-tooltip-value="' + value + '"' +
546545 ' 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 + '"' : '' ;
549551
550552 swatchImageWidth = _ . has ( sizeConfig , 'swatchImage' ) ? sizeConfig . swatchImage . width : 30 ;
551553 swatchImageHeight = _ . has ( sizeConfig , 'swatchImage' ) ? sizeConfig . swatchImage . height : 20 ;
552554
553555 if ( ! this . hasOwnProperty ( 'products' ) || this . products . length <= 0 ) {
554- attr += ' option-empty="true"' ;
556+ attr += ' data- option-empty="true"' ;
555557 }
556558
557559 if ( type === 0 ) {
@@ -599,14 +601,14 @@ define([
599601
600602 html =
601603 '<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>' ;
603605
604606 $ . each ( config . options , function ( ) {
605607 var label = this . label ,
606- attr = ' value="' + this . id + '" option-id="' + this . id + '"' ;
608+ attr = ' value="' + this . id + '" data- option-id="' + this . id + '"' ;
607609
608610 if ( ! this . hasOwnProperty ( 'products' ) || this . products . length <= 0 ) {
609- attr += ' option-empty="true"' ;
611+ attr += ' data- option-empty="true"' ;
610612 }
611613
612614 html += '<option ' + attr + '>' + label + '</option>' ;
@@ -721,7 +723,7 @@ define([
721723 var $parent = $this . parents ( '.' + $widget . options . classes . attributeClass ) ,
722724 $wrapper = $this . parents ( '.' + $widget . options . classes . attributeOptionsWrapper ) ,
723725 $label = $parent . find ( '.' + $widget . options . classes . attributeSelectedOptionLabelClass ) ,
724- attributeId = $parent . attr ( 'attribute-id' ) ,
726+ attributeId = $parent . data ( 'attribute-id' ) ,
725727 $input = $parent . find ( '.' + $widget . options . classes . attributeInput ) ,
726728 checkAdditionalData = JSON . parse ( this . options . jsonSwatchConfig [ attributeId ] [ 'additional_data' ] ) ,
727729 $priceBox = $widget . element . parents ( $widget . options . selectorProduct )
@@ -738,14 +740,14 @@ define([
738740 }
739741
740742 if ( $this . hasClass ( 'selected' ) ) {
741- $parent . removeAttr ( 'option-selected' ) . find ( '.selected' ) . removeClass ( 'selected' ) ;
743+ $parent . removeAttr ( 'data- option-selected' ) . find ( '.selected' ) . removeClass ( 'selected' ) ;
742744 $input . val ( '' ) ;
743745 $label . text ( '' ) ;
744746 $this . attr ( 'aria-checked' , false ) ;
745747 } 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' ) ) ;
749751 $input . attr ( 'data-attr-name' , this . _getAttributeCodeById ( attributeId ) ) ;
750752 $this . addClass ( 'selected' ) ;
751753 $widget . _toggleCheckedAttributes ( $this , $wrapper ) ;
@@ -822,7 +824,7 @@ define([
822824 */
823825 _OnChange : function ( $this , $widget ) {
824826 var $parent = $this . parents ( '.' + $widget . options . classes . attributeClass ) ,
825- attributeId = $parent . attr ( 'attribute-id' ) ,
827+ attributeId = $parent . data ( 'attribute-id' ) ,
826828 $input = $parent . find ( '.' + $widget . options . classes . attributeInput ) ;
827829
828830 if ( $widget . productForm . length > 0 ) {
@@ -832,10 +834,10 @@ define([
832834 }
833835
834836 if ( $this . val ( ) > 0 ) {
835- $parent . attr ( 'option-selected' , $this . val ( ) ) ;
837+ $parent . attr ( 'data- option-selected' , $this . val ( ) ) ;
836838 $input . val ( $this . val ( ) ) ;
837839 } else {
838- $parent . removeAttr ( 'option-selected' ) ;
840+ $parent . removeAttr ( 'data- option-selected' ) ;
839841 $input . val ( '' ) ;
840842 }
841843
@@ -862,8 +864,8 @@ define([
862864 * @private
863865 */
864866 _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]' )
867869 . attr ( 'disabled' , true )
868870 . addClass ( 'disabled' )
869871 . attr ( 'tabindex' , '-1' ) ;
@@ -876,8 +878,8 @@ define([
876878 */
877879 _Rebuild : function ( ) {
878880 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]' ) ;
881883
882884 // Enable all options
883885 $widget . _Rewind ( controls ) ;
@@ -890,16 +892,16 @@ define([
890892 // Disable not available options
891893 controls . each ( function ( ) {
892894 var $this = $ ( this ) ,
893- id = $this . attr ( 'attribute-id' ) ,
895+ id = $this . data ( 'attribute-id' ) ,
894896 products = $widget . _CalcProducts ( id ) ;
895897
896- if ( selected . length === 1 && selected . first ( ) . attr ( 'attribute-id' ) === id ) {
898+ if ( selected . length === 1 && selected . first ( ) . data ( 'attribute-id' ) === id ) {
897899 return ;
898900 }
899901
900- $this . find ( '[option-id]' ) . each ( function ( ) {
902+ $this . find ( '[data- option-id]' ) . each ( function ( ) {
901903 var $element = $ ( this ) ,
902- option = $element . attr ( 'option-id' ) ;
904+ option = $element . data ( 'option-id' ) ;
903905
904906 if ( ! $widget . optionsMap . hasOwnProperty ( id ) || ! $widget . optionsMap [ id ] . hasOwnProperty ( option ) ||
905907 $element . hasClass ( 'selected' ) ||
@@ -922,12 +924,13 @@ define([
922924 */
923925 _CalcProducts : function ( $skipAttributeId ) {
924926 var $widget = this ,
927+ selectedOptions = '.' + $widget . options . classes . attributeClass + '[data-option-selected]' ,
925928 products = [ ] ;
926929
927930 // 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' ) ;
931934
932935 if ( $skipAttributeId !== undefined && $skipAttributeId === id ) {
933936 return ;
@@ -1353,7 +1356,7 @@ define([
13531356 _EmulateSelected : function ( selectedAttributes ) {
13541357 $ . each ( selectedAttributes , $ . proxy ( function ( attributeCode , optionId ) {
13551358 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 + '"]' ) ,
13571360 parentInput = elem . parent ( ) ;
13581361
13591362 if ( elem . hasClass ( 'selected' ) ) {
@@ -1377,7 +1380,7 @@ define([
13771380 _EmulateSelectedByAttributeId : function ( selectedAttributes ) {
13781381 $ . each ( selectedAttributes , $ . proxy ( function ( attributeId , optionId ) {
13791382 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 + '"]' ) ,
13811384 parentInput = elem . parent ( ) ;
13821385
13831386 if ( elem . hasClass ( 'selected' ) ) {
0 commit comments