diff --git a/2.0/steps.js b/2.0/steps.js index fe88ca5..05e6063 100644 --- a/2.0/steps.js +++ b/2.0/steps.js @@ -172,9 +172,9 @@ titleIndex = options.dataOrder.indexOf("title"), descIndex = options.dataOrder.indexOf("description"); if(options.direction.toLowerCase() == "vertical" && options.dataWidth.length > 0){ - lineStyle = "flex: " + options.dataWidth[lineIndex] + ";"; - titleStyle = "flex: " + options.dataWidth[titleIndex] + ";"; - descStyle = "flex: " + options.dataWidth[descIndex] + ";"; + lineStyle = "flex: " + (options.dataWidth[lineIndex] ? options.dataWidth[lineIndex] : "none") + ";"; + titleStyle = "flex: " + (options.dataWidth[titleIndex] ? options.dataWidth[titleIndex] : "none") + ";"; + descStyle = "flex: " + (options.dataWidth[descIndex] ? options.dataWidth[descIndex] : "none") + ";"; } var stepLineBox = '
' + stepIconInnerText + '
'; diff --git a/2.0/steps.min.js b/2.0/steps.min.js index d4f6759..8fca56c 100644 --- a/2.0/steps.min.js +++ b/2.0/steps.min.js @@ -1 +1 @@ -!function(undefined){"use strict";var _global,utils={extend:(isObjFunc=function(name){var toString=Object.prototype.toString;return function(){return toString.call(arguments[0])==="[object "+name+"]"}},isObject=isObjFunc("Object"),isArray=isObjFunc("Array"),isBoolean=isObjFunc("Boolean"),function extend(){var index=0,isDeep=!1,obj,copy,destination,source,i;for(isBoolean(arguments[0])&&(index=1,isDeep=arguments[0]),i=arguments.length-1;i>index;i--)if(destination=arguments[i-1],source=arguments[i],isObject(source)||isArray(source))for(var property in source)if(obj=source[property],isDeep&&(isObject(obj)||isArray(obj))){var extended=extend(isDeep,copy=isObject(obj)?{}:[],obj);destination[property]=extended}else destination[property]=source[property];else destination=source;return destination})},isObjFunc,isObject,isArray,isBoolean,steps=function(options){return new _steps(options)};function _steps(options){this._initial(options)}_steps.prototype={constructor:this,_initial:function(options){var _this=this,defined={el:"",data:[],props:{title:"title",description:"description",status:"status",icon:"icon",customHtml:"customHtml"},dataOrder:["line","title","description"],dataWidth:[],space:null,direction:"horizontal",iconType:"number",center:!1,active:0,dataSetStatus:!1,defaultClass:"step-default-class",finishClass:"step-finish-class",finishLine:!0,finishLineClass:"step-finish-line-bg",customClass:""};return this.options=utils.extend(!0,defined,options),this.options.el?this.options.data&&0!=this.options.data.length?(this.options.dataLength=this.options.data.length,void this.render()):(alert("请传入'data'参数"),!1):(alert("请传入'el'参数"),!1)},getBoxClass:function(){var _this=this,options=this.options,direction=options.direction.toLowerCase(),boxClass="";return"horizontal"==direction?(boxClass+="steps-horizontal",options.center&&(boxClass+=" steps-center")):"vertical"==direction?boxClass+="steps-vertical":alert("参数'direction'错误"),boxClass},getParentNode:function(){var _this=this,options=this.options,resultEl;return"object"==typeof options.el?resultEl=options.el:"string"==typeof options.el&&(resultEl=document.querySelector(options.el)),resultEl},render:function(){var _this=this,options=_this.options,boxHtml="",parentNode=_this.getParentNode();options.customClass&&(parentNode.className=parentNode.className+options.customClass),options.boxClass=_this.getBoxClass(),boxHtml=boxHtml+'
';var stepContainer="";if(options.data.forEach(function(currentValue,index,array){(currentValue[options.props.status]||0==currentValue[options.props.status])&&(options.dataSetStatus=!0);var stepClass=currentValue[options.props.status]?options.finishClass:!options.dataSetStatus&&index<=options.active?options.finishClass:"";stepContainer=stepContainer+'
{{stepHtml}}
';var stepIconClass="",stepIconInnerClass="",stepIconInnerText="",iconType=options.iconType.toLowerCase();"number"==iconType?(stepIconInnerClass="step-icon-number",stepIconInnerText=index+1):"bullets"==iconType?stepIconInnerClass="step-icon-bullets":"custom"==iconType&&(stepIconClass="step-icon-custom-box",stepIconInnerClass="step-icon-custom",stepIconInnerText=currentValue[options.props.icon]?currentValue[options.props.icon]:index+1);var stepHtml,lineStyle="",titleStyle="",descStyle="",lineIndex=options.dataOrder.indexOf("line"),titleIndex=options.dataOrder.indexOf("title"),descIndex=options.dataOrder.indexOf("description"),stepLineBox,stepTitle,stepDesc;"vertical"==options.direction.toLowerCase()&&options.dataWidth.length>0&&(lineStyle="flex: "+options.dataWidth[lineIndex]+";",titleStyle="flex: "+options.dataWidth[titleIndex]+";",descStyle="flex: "+options.dataWidth[descIndex]+";"),stepHtml='
'+stepIconInnerText+"
"+('
'+currentValue[options.props.title]+"
")+('
'+currentValue[options.props.description]+"
"),currentValue[options.props.customHtml]&&(stepHtml+=currentValue[options.props.customHtml]),stepContainer=stepContainer.replace("{{stepHtml}}",stepHtml)}),options.dataSetStatus)stepContainer=stepContainer.replace(/{{finishLineClass}}/g,"");else if(options.finishLine)for(var i=0,len=options.dataLength;i"},getStepStyle:function(index){var _this=this,options=this.options,style=[],space="number"==typeof options.space?options.space+"px":options.space?options.space:100/(options.dataLength-(options.center?0:1))+"%";return style.push("flex-basis:"+space+";"),options.center||index!=options.dataLength-1||(style.length=0,style.push("flex-basis: auto!important;"),style.push("flex-shrink: 0;"),style.push("flex-grow: 0;"),style.push("max-width:"+100/options.dataLength+"%;")),style},setActive:function(num){var _this=this;this.options.dataSetStatus?alert("参数'data'中已设置'status',参数'active'已停用"):(this.options.active=num,this.render())},getActive:function(){var _this=this;if(!this.options.dataSetStatus)return this.options.active;alert("参数'data'中已设置'status',参数'active'已停用")}},_global=function(){return this||(0,eval)("this")}(),"undefined"!=typeof module&&module.exports?module.exports=steps:"function"==typeof define&&define.amd?define(function(){return steps}):!("steps"in _global)&&(_global.steps=steps)}(); \ No newline at end of file +!function(undefined){"use strict";var _global,utils={extend:(isObjFunc=function(name){var toString=Object.prototype.toString;return function(){return toString.call(arguments[0])==="[object "+name+"]"}},isObject=isObjFunc("Object"),isArray=isObjFunc("Array"),isBoolean=isObjFunc("Boolean"),function extend(){var index=0,isDeep=!1,obj,copy,destination,source,i;for(isBoolean(arguments[0])&&(index=1,isDeep=arguments[0]),i=arguments.length-1;i>index;i--)if(destination=arguments[i-1],source=arguments[i],isObject(source)||isArray(source))for(var property in source)if(obj=source[property],isDeep&&(isObject(obj)||isArray(obj))){var extended=extend(isDeep,copy=isObject(obj)?{}:[],obj);destination[property]=extended}else destination[property]=source[property];else destination=source;return destination})},isObjFunc,isObject,isArray,isBoolean,steps=function(options){return new _steps(options)};function _steps(options){this._initial(options)}_steps.prototype={constructor:this,_initial:function(options){var _this=this,defined={el:"",data:[],props:{title:"title",description:"description",status:"status",icon:"icon",customHtml:"customHtml"},dataOrder:["line","title","description"],dataWidth:[],space:null,direction:"horizontal",iconType:"number",center:!1,active:0,dataSetStatus:!1,defaultClass:"step-default-class",finishClass:"step-finish-class",finishLine:!0,finishLineClass:"step-finish-line-bg",customClass:""};return this.options=utils.extend(!0,defined,options),this.options.el?this.options.data&&0!=this.options.data.length?(this.options.dataLength=this.options.data.length,void this.render()):(alert("请传入'data'参数"),!1):(alert("请传入'el'参数"),!1)},getBoxClass:function(){var _this=this,options=this.options,direction=options.direction.toLowerCase(),boxClass="";return"horizontal"==direction?(boxClass+="steps-horizontal",options.center&&(boxClass+=" steps-center")):"vertical"==direction?boxClass+="steps-vertical":alert("参数'direction'错误"),boxClass},getParentNode:function(){var _this=this,options=this.options,resultEl;return"object"==typeof options.el?resultEl=options.el:"string"==typeof options.el&&(resultEl=document.querySelector(options.el)),resultEl},render:function(){var _this=this,options=_this.options,boxHtml="",parentNode=_this.getParentNode();options.customClass&&(parentNode.className=parentNode.className+options.customClass),options.boxClass=_this.getBoxClass(),boxHtml=boxHtml+'
';var stepContainer="";if(options.data.forEach(function(currentValue,index,array){(currentValue[options.props.status]||0==currentValue[options.props.status])&&(options.dataSetStatus=!0);var stepClass=currentValue[options.props.status]?options.finishClass:!options.dataSetStatus&&index<=options.active?options.finishClass:"";stepContainer=stepContainer+'
{{stepHtml}}
';var stepIconClass="",stepIconInnerClass="",stepIconInnerText="",iconType=options.iconType.toLowerCase();"number"==iconType?(stepIconInnerClass="step-icon-number",stepIconInnerText=index+1):"bullets"==iconType?stepIconInnerClass="step-icon-bullets":"custom"==iconType&&(stepIconClass="step-icon-custom-box",stepIconInnerClass="step-icon-custom",stepIconInnerText=currentValue[options.props.icon]?currentValue[options.props.icon]:index+1);var stepHtml,lineStyle="",titleStyle="",descStyle="",lineIndex=options.dataOrder.indexOf("line"),titleIndex=options.dataOrder.indexOf("title"),descIndex=options.dataOrder.indexOf("description"),stepLineBox,stepTitle,stepDesc;"vertical"==options.direction.toLowerCase()&&options.dataWidth.length>0&&(lineStyle="flex: "+(options.dataWidth[lineIndex]?options.dataWidth[lineIndex]:"none")+";",titleStyle="flex: "+(options.dataWidth[titleIndex]?options.dataWidth[titleIndex]:"none")+";",descStyle="flex: "+(options.dataWidth[descIndex]?options.dataWidth[descIndex]:"none")+";"),stepHtml='
'+stepIconInnerText+"
"+('
'+currentValue[options.props.title]+"
")+('
'+currentValue[options.props.description]+"
"),currentValue[options.props.customHtml]&&(stepHtml+=currentValue[options.props.customHtml]),stepContainer=stepContainer.replace("{{stepHtml}}",stepHtml)}),options.dataSetStatus)stepContainer=stepContainer.replace(/{{finishLineClass}}/g,"");else if(options.finishLine)for(var i=0,len=options.dataLength;i"},getStepStyle:function(index){var _this=this,options=this.options,style=[],space="number"==typeof options.space?options.space+"px":options.space?options.space:100/(options.dataLength-(options.center?0:1))+"%";return style.push("flex-basis:"+space+";"),options.center||index!=options.dataLength-1||(style.length=0,style.push("flex-basis: auto!important;"),style.push("flex-shrink: 0;"),style.push("flex-grow: 0;"),style.push("max-width:"+100/options.dataLength+"%;")),style},setActive:function(num){var _this=this;this.options.dataSetStatus?alert("参数'data'中已设置'status',参数'active'已停用"):(this.options.active=num,this.render())},getActive:function(){var _this=this;if(!this.options.dataSetStatus)return this.options.active;alert("参数'data'中已设置'status',参数'active'已停用")}},_global=function(){return this||(0,eval)("this")}(),"undefined"!=typeof module&&module.exports?module.exports=steps:"function"==typeof define&&define.amd?define(function(){return steps}):!("steps"in _global)&&(_global.steps=steps)}(); \ No newline at end of file diff --git "a/2.0/\346\233\264\346\226\260\346\227\245\345\277\227.md" "b/2.0/\346\233\264\346\226\260\346\227\245\345\277\227.md" index 8434606..54d4fe8 100644 --- "a/2.0/\346\233\264\346\226\260\346\227\245\345\277\227.md" +++ "b/2.0/\346\233\264\346\226\260\346\227\245\345\277\227.md" @@ -18,6 +18,8 @@ var steps10 = steps({ }); ``` +2. `dataWidth`未设置时,默认都为`none`,也就是`(0 0 auto)`。 + ## 2018-11-07 ## 1. 暂时移除使用`classList`来为`.step`的父元素添加自定义的class。