Commit 0d843a60 by dhn

默认第一选项 js修改

parent 1ac9ccfe
......@@ -400,7 +400,7 @@ define([
*
* @private
*/
_RenderControls: function () {
_RenderControls: function (index) {
var $widget = this,
container = this.element,
classes = this.options.classes,
......@@ -408,13 +408,14 @@ define([
showTooltip = this.options.showTooltip;
$widget.optionsMap = {};
$.each(this.options.jsonConfig.attributes, function () {
var item = this,
controlLabelId = 'option-label-' + item.code + '-' + item.id,
options = $widget._RenderSwatchOptions(item, controlLabelId),
select = $widget._RenderSwatchSelect(item, chooseText),
input = $widget._RenderFormInput(item),
areaCheckedId =$widget._RenderSwatchFirstOptionsId(item, controlLabelId),
CheckedId =$widget._RenderSwatchCheckedOptionsId(item),
input = $widget._RenderFormInput(item,CheckedId),
listLabel = '',
label = '';
......@@ -422,7 +423,6 @@ define([
if ($widget.options.onlySwatches && !$widget.options.jsonSwatchConfig.hasOwnProperty(item.id)) {
return;
}
if ($widget.options.enableControlLabel) {
var tem_size = '';
if (item.label.toLowerCase() == "size"){
......@@ -436,7 +436,7 @@ define([
label +=
'<span id="' + controlLabelId + '" class="' + classes.attributeLabelClass + '">' +
$('<i></i>').text(item.label).html() +
'</span>'+ '<span class="' + classes.attributeSelectedOptionLabelClass + '"></span>' ;
'</span>'+ '<span class="' + classes.attributeSelectedOptionLabelClass + '">'+item.options[0].label+'</span>' ;
}
}
......@@ -450,14 +450,17 @@ define([
}
if (item.label.toLowerCase() == "size") {
// Create new control
var sizeContent = '<div class="swatch-attribute-selected-option-size-content" ><div style="font-size:.32rem;color:#999999;">'+$.mage.__("Product Size Describe")+ '</div>'+'<span style="color:#0a0a0a;" class="'+classes.attributeSelectedOptionLabelClass + '"></span></div>';
var sizeContent = '<div class="swatch-attribute-selected-option-size-content" style="display:block;">'+
'<div style="font-size:.32rem;color:#999999;">'+$.mage.__("Product Size Describe")+ '</div>'+
'<span style="color:#0a0a0a;" class="'+classes.attributeSelectedOptionLabelClass + '">'+item.options[0].label+'</span></div>';
container.append(
'<div class="' + classes.attributeClass + ' ' + item.code + '" ' +
'data-attribute-code="' + item.code + '" ' +
'data-attribute-id="' + item.id + '">' +
'data-attribute-id="' + item.id + '" '+
'data-option-selected="' + CheckedId + '">' +
label +
'<div aria-activedescendant="" ' +
'<div aria-activedescendant="'+areaCheckedId+'" ' +
'tabindex="0" ' +
'aria-invalid="false" ' +
'aria-required="true" ' +
......@@ -471,9 +474,10 @@ define([
container.append(
'<div class="' + classes.attributeClass + ' ' + item.code + '" ' +
'data-attribute-code="' + item.code + '" ' +
'data-attribute-id="' + item.id + '">' +
'data-attribute-id="' + item.id + '" '+
'data-option-selected="' + CheckedId + '">' +
label +
'<div aria-activedescendant="" ' +
'<div aria-activedescendant="'+areaCheckedId+'" ' +
'tabindex="0" ' +
'aria-invalid="false" ' +
'aria-required="true" ' +
......@@ -485,7 +489,6 @@ define([
);
}
$widget.optionsMap[item.id] = {};
// Aggregate options array to hash (key => value)
......@@ -577,9 +580,15 @@ define([
label = this.label ? $('<i></i>').text(this.label).html() : '';
attr =
' id="' + controlId + '-item-' + id + '"' +
' index="' + index + '"' +
' aria-checked="false"' +
' aria-describedby="' + controlId + '"' +
' index="' + index + '"';
if(index == 0)
{
attr += ' aria-checked="true"';
}
else {
attr += ' aria-checked="false"';
}
attr += ' aria-describedby="' + controlId + '"' +
' tabindex="0"' +
' data-option-type="' + type + '"' +
' data-option-id="' + id + '"' +
......@@ -598,35 +607,73 @@ define([
if (!this.hasOwnProperty('products') || this.products.length <= 0) {
attr += ' data-option-empty="true"';
}
var selectedStr = '';
if(index == 0)
{
selectedStr = ' selected';
}
if (type === 0) {
// Text
html += '<div class="' + optionClass + ' text" ' + attr + '>' + (value ? value : label) +
html += '<div class="' + optionClass + ' text' + selectedStr + '" ' + attr + '>' + (value ? value : label) +
'</div>';
} else if (type === 1) {
// Color
html += '<div class="' + optionClass + ' color" ' + attr +
html += '<div class="' + optionClass + ' color' + selectedStr + '" ' + attr +
' style="background: ' + value +
' no-repeat center; background-size: cover;">' + '' +
'</div>';
} else if (type === 2) {
// Image
html += '<div class="' + optionClass + ' image" ' + attr +
html += '<div class="' + optionClass + ' image' + selectedStr + '" ' + attr +
' style="background: url(' + value + ') no-repeat center; background-size: cover;width:' +
swatchImageWidth + 'px; height:' + swatchImageHeight + 'px">' + '' +
'</div>';
} else if (type === 3) {
// Clear
html += '<div class="' + optionClass + '" ' + attr + '></div>';
html += '<div class="' + optionClass + selectedStr + '" ' + attr + '></div>';
} else {
// Default
html += '<div class="' + optionClass + '" ' + attr + '>' + label + '</div>';
html += '<div class="' + optionClass + selectedStr + '" ' + attr + '>' + label + '</div>';
}
});
return html;
},
_RenderSwatchFirstOptionsId: function (config, controlId) {
var optionConfig = this.options.jsonSwatchConfig[config.id];
if (!this.options.jsonSwatchConfig.hasOwnProperty(config.id)) {
return '';
}
var returnId = '';
$.each(config.options, function (index) {
if (!optionConfig.hasOwnProperty(this.id)) {
return '';
}
if(index == 0)
{
returnId = controlId + '-item-' + this.id;
}
});
return returnId;
},
_RenderSwatchCheckedOptionsId: function (config) {
var optionConfig = this.options.jsonSwatchConfig[config.id];
if (!this.options.jsonSwatchConfig.hasOwnProperty(config.id)) {
return '';
}
var returnId = '';
$.each(config.options, function (index) {
if (!optionConfig.hasOwnProperty(this.id)) {
return '';
}
if(index == 0)
{
returnId = this.id;
}
});
return returnId;
},
/**
* Render select by part of config
*
......@@ -669,14 +716,15 @@ define([
* @param {Object} config
* @private
*/
_RenderFormInput: function (config) {
_RenderFormInput: function (config,CheckedId) {
return '<input class="' + this.options.classes.attributeInput + ' super-attribute-select" ' +
'name="super_attribute[' + config.id + ']" ' +
'type="text" ' +
'value="" ' +
'value="'+CheckedId+'" ' +
'data-selector="super_attribute[' + config.id + ']" ' +
'data-validate="{required: true}" ' +
'aria-required="true" ' +
'data-attr-name="'+config.code+'" ' +
'aria-invalid="false">';
},
......@@ -1490,20 +1538,9 @@ define([
* @param {HTMLElement} element - DOM element associated with a gallery.
*/
_onGalleryLoaded: function (element) {
var galleryObject = element.data('gallery');
var galleryObject = element.data('gallery');
this.options.mediaGalleryInitial = galleryObject.returnCurrentImages();
/*
if($('.swatch-attribute .swatch-option'))
{
var swatchObj = $('.swatch-attribute');
for(var i=0;i<swatchObj.length;i++)
{
$(swatchObj[i]).find('.swatch-option:first').trigger('click');
}
}
*/
},
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment