From c0c353c41df9b8a728bc5486c5a8b20995058c02 Mon Sep 17 00:00:00 2001 From: ciaoca Date: Tue, 12 Jan 2016 10:25:52 +0800 Subject: [PATCH] =?UTF-8?q?update=20v1.3.9=20=E4=BC=98=E5=8C=96=E5=AF=B9?= =?UTF-8?q?=20Zepto=20=E7=9A=84=E5=85=BC=E5=AE=B9=EF=BC=88v1.3.8=20?= =?UTF-8?q?=E9=9C=80=E8=A6=81=20zepto=20data=20=E6=A8=A1=E5=9D=97=E6=94=AF?= =?UTF-8?q?=E6=8C=81=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 6 +++--- js/jquery.cxselect.js | 12 ++++++------ js/jquery.cxselect.min.js | 6 +++--- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index c45ecff..e9187b3 100644 --- a/README.md +++ b/README.md @@ -12,8 +12,8 @@ cxSelect 是基于 jQuery 的多级联动菜单插件,适用于省市、商品 **版本:** -* jQuery v1.7+ -* jQuery cxSelect v1.3.8 +* jQuery v1.7+ | Zepto v1.0+ +* jQuery cxSelect v1.3.9 文档:http://code.ciaoca.com/jquery/cxselect/ @@ -95,7 +95,7 @@ $.cxSelect.defaults.nodata = 'none'; required false - 是否为必选。设为 flase 时,会在列表头部添加 `<option value="firstValue">firstTitle</option>` 选项。 + 是否为必选。设为 false 时,会在列表头部添加 `<option value="firstValue">firstTitle</option>` 选项。 firstTitle diff --git a/js/jquery.cxselect.js b/js/jquery.cxselect.js index de23db8..4b90b75 100644 --- a/js/jquery.cxselect.js +++ b/js/jquery.cxselect.js @@ -1,8 +1,8 @@ /*! * jQuery cxSelect * @name jquery.cxselect.js - * @version 1.3.8 - * @date 2015-12-7 + * @version 1.3.9 + * @date 2016-01-06 * @author ciaoca * @email ciaoca@gmail.com * @site https://github.com/ciaoca/cxSelect @@ -83,8 +83,8 @@ if (!_tempSelect) {break}; // 保存默认值 - if (typeof _tempSelect.val() === 'string') { - _tempSelect.data('value', _tempSelect.val()); + if (typeof _tempSelect.val() === 'string' && _tempSelect.val().length) { + _tempSelect.attr('data-value', _tempSelect.val()); }; self.selectArray.push(_tempSelect); @@ -102,7 +102,7 @@ self.start(); // 设置 URL,通过 Ajax 获取数据 - } else if (typeof self.settings.url === 'string') { + } else if (typeof self.settings.url === 'string' && self.settings.url.length) { $.getJSON(self.settings.url, function(json) { self.start(json); }); @@ -284,7 +284,7 @@ // 初次加载设置默认值 if (typeof select.data('value') !== 'undefined') { - select.val(String(select.data('value'))).removeData('value').removeAttr('data-value'); + select.val(String(select.data('value'))).removeAttr('data-value'); }; select.trigger('change'); diff --git a/js/jquery.cxselect.min.js b/js/jquery.cxselect.min.js index 56368c5..7e946b7 100644 --- a/js/jquery.cxselect.min.js +++ b/js/jquery.cxselect.min.js @@ -1,11 +1,11 @@ /*! * jQuery cxSelect * @name jquery.cxselect.js - * @version 1.3.8 - * @date 2015-12-7 + * @version 1.3.9 + * @date 2016-01-06 * @author ciaoca * @email ciaoca@gmail.com * @site https://github.com/ciaoca/cxSelect * @license Released under the MIT license */ -!function(a){"function"==typeof define&&define.amd?define(["jquery"],a):a(window.jQuery||window.Zepto||window.$)}(function(a){a.cxSelect=function(){var b={dom:{},api:{}};return b.init=function(){var c,f,g,h,i,b=this,d=function(a){return a&&("function"==typeof HTMLElement||"object"==typeof HTMLElement)&&a instanceof HTMLElement?!0:a&&a.nodeType&&1===a.nodeType?!0:!1},e=function(a){return a&&a.length&&("function"==typeof jQuery||"object"==typeof jQuery)&&a instanceof jQuery?!0:!1};for(f=0,g=arguments.length;g>f;f++)e(arguments[f])?b.dom.box=arguments[f]:d(arguments[f])?b.dom.box=a(arguments[f]):"object"==typeof arguments[f]&&(c=arguments[f]);if(b.dom.box.length&&(b.settings=a.extend({},a.cxSelect.defaults,c,{url:b.dom.box.data("url"),nodata:b.dom.box.data("nodata"),required:b.dom.box.data("required"),firstTitle:b.dom.box.data("firstTitle"),firstValue:b.dom.box.data("firstValue"),jsonSpace:b.dom.box.data("jsonSpace"),jsonName:b.dom.box.data("jsonName"),jsonValue:b.dom.box.data("jsonValue"),jsonSub:b.dom.box.data("jsonSub")}),h=b.dom.box.data("selects"),"string"==typeof h&&h.length&&(b.settings.selects=h.split(",")),a.isArray(b.settings.selects)&&b.settings.selects.length)){for(b.selectArray=[],f=0,g=b.settings.selects.length;g>f&&(i=b.dom.box.find("select."+b.settings.selects[f]),i);f++)"string"==typeof i.val()&&i.data("value",i.val()),b.selectArray.push(i);b.selectArray.length&&(b.dom.box.on("change","select",function(){b.selectChange(this.className)}),b.settings.url?"string"==typeof b.settings.url?a.getJSON(b.settings.url,function(a){b.start(a)}):"object"==typeof b.settings.url&&b.start(b.settings.url):b.start())}},b.getIndex=function(a){return this.settings.required?a:a-1},b.start=function(a){var d,e,f,b=this,c=b.settings.jsonSpace;if(b.dataJson=void 0,a&&"object"==typeof a&&(b.dataJson=a,"string"==typeof c&&c.length))for(d=c.split("."),e=0,f=d.length;f>e;e++)b.dataJson=b.dataJson[d[e]];b.dataJson||"string"==typeof b.selectArray[0].data("url")&&b.selectArray[0].data("url").length?b.getOptionData(0):b.selectArray[0].prop("disabled",!1).css({display:"",visibility:""})},b.selectChange=function(a){var b,c,d;if("string"==typeof a&&a.length){for(a=a.replace(/\s+/g,","),a=","+a+",",c=0,d=this.selectArray.length;d>c;c++)a.indexOf(","+this.settings.selects[c]+",")>-1&&(b=c);"number"==typeof b&&(b+=1,this.getOptionData(b))}},b.getOptionData=function(b){var e,f,g,h,i,j,k,l,m,n,o,p,d=this;if(!("number"!=typeof b||isNaN(b)||0>b||b>=d.selectArray.length)){for(e=b-1,f=d.selectArray[b],j={},k=f.data("url"),l="undefined"==typeof f.data("jsonSpace")?d.settings.jsonSpace:f.data("jsonSpace"),o=0,p=d.selectArray.length;p>o;o++)o>=b&&(d.selectArray[o].empty().prop("disabled",!0),"none"===d.settings.nodata?d.selectArray[o].css("display","none"):"hidden"===d.settings.nodata&&d.selectArray[o].css("visibility","hidden"));if("string"==typeof k&&k.length){if(e>=0){if(!d.selectArray[e].val().length)return;m=f.data("queryName"),n=d.selectArray[e].attr("name"),"string"==typeof m&&m.length?j[m]=d.selectArray[e].val():"string"==typeof n&&n.length&&(j[n]=d.selectArray[e].val())}a.getJSON(k,j,function(a){var b,c,e;if(h=a,"string"==typeof l&&l.length)for(b=l.split("."),c=0,e=b.length;e>c;c++)h=h[b[c]];d.buildOption(f,h)})}else if(d.dataJson&&"object"==typeof d.dataJson){for(h=d.dataJson,o=0,p=d.selectArray.length;p>o;o++)b>o&&(i=d.getIndex(d.selectArray[o][0].selectedIndex),"object"==typeof h[i]&&a.isArray(h[i][d.settings.jsonSub])&&h[i][d.settings.jsonSub].length&&(g=o,h=h[i][d.settings.jsonSub]));(0>e||e===g)&&d.buildOption(f,h)}}},b.buildOption=function(b,c){var i,j,k,d=this,e="undefined"==typeof b.data("firstTitle")?d.settings.firstTitle:String(b.data("firstTitle")),f="undefined"==typeof b.data("firstValue")?d.settings.firstValue:String(b.data("firstValue")),g="undefined"==typeof b.data("jsonName")?d.settings.jsonName:String(b.data("jsonName")),h="undefined"==typeof b.data("jsonValue")?d.settings.jsonValue:String(b.data("jsonValue"));if(a.isArray(c)){if(i=d.settings.required?"":'",g.length)for(h.length||(h=g),j=0,k=c.length;k>j;j++)i+='";else for(j=0,k=c.length;k>j;j++)i+='";b.html(i).prop("disabled",!1).css({display:"",visibility:""}),"undefined"!=typeof b.data("value")&&b.val(String(b.data("value"))).removeData("value").removeAttr("data-value"),b.trigger("change")}},b.init.apply(b,arguments),this},a.cxSelect.defaults={selects:[],url:null,nodata:null,required:!1,firstTitle:"请选择",firstValue:"",jsonSpace:"",jsonName:"n",jsonValue:"",jsonSub:"s"},a.fn.cxSelect=function(b,c){return this.each(function(){a.cxSelect(this,b,c)}),this}}); \ No newline at end of file +!function(a){"function"==typeof define&&define.amd?define(["jquery"],a):a(window.jQuery||window.Zepto||window.$)}(function(a){a.cxSelect=function(){var b={dom:{},api:{}};return b.init=function(){var c,f,g,h,i,b=this,d=function(a){return a&&("function"==typeof HTMLElement||"object"==typeof HTMLElement)&&a instanceof HTMLElement?!0:a&&a.nodeType&&1===a.nodeType?!0:!1},e=function(a){return a&&a.length&&("function"==typeof jQuery||"object"==typeof jQuery)&&a instanceof jQuery?!0:!1};for(f=0,g=arguments.length;g>f;f++)e(arguments[f])?b.dom.box=arguments[f]:d(arguments[f])?b.dom.box=a(arguments[f]):"object"==typeof arguments[f]&&(c=arguments[f]);if(b.dom.box.length&&(b.settings=a.extend({},a.cxSelect.defaults,c,{url:b.dom.box.data("url"),nodata:b.dom.box.data("nodata"),required:b.dom.box.data("required"),firstTitle:b.dom.box.data("firstTitle"),firstValue:b.dom.box.data("firstValue"),jsonSpace:b.dom.box.data("jsonSpace"),jsonName:b.dom.box.data("jsonName"),jsonValue:b.dom.box.data("jsonValue"),jsonSub:b.dom.box.data("jsonSub")}),h=b.dom.box.data("selects"),"string"==typeof h&&h.length&&(b.settings.selects=h.split(",")),a.isArray(b.settings.selects)&&b.settings.selects.length)){for(b.selectArray=[],f=0,g=b.settings.selects.length;g>f&&(i=b.dom.box.find("select."+b.settings.selects[f]),i);f++)"string"==typeof i.val()&&i.val().length&&i.attr("data-value",i.val()),b.selectArray.push(i);b.selectArray.length&&(b.dom.box.on("change","select",function(){b.selectChange(this.className)}),b.settings.url?"string"==typeof b.settings.url&&b.settings.url.length?a.getJSON(b.settings.url,function(a){b.start(a)}):"object"==typeof b.settings.url&&b.start(b.settings.url):b.start())}},b.getIndex=function(a){return this.settings.required?a:a-1},b.start=function(a){var d,e,f,b=this,c=b.settings.jsonSpace;if(b.dataJson=void 0,a&&"object"==typeof a&&(b.dataJson=a,"string"==typeof c&&c.length))for(d=c.split("."),e=0,f=d.length;f>e;e++)b.dataJson=b.dataJson[d[e]];b.dataJson||"string"==typeof b.selectArray[0].data("url")&&b.selectArray[0].data("url").length?b.getOptionData(0):b.selectArray[0].prop("disabled",!1).css({display:"",visibility:""})},b.selectChange=function(a){var b,c,d;if("string"==typeof a&&a.length){for(a=a.replace(/\s+/g,","),a=","+a+",",c=0,d=this.selectArray.length;d>c;c++)a.indexOf(","+this.settings.selects[c]+",")>-1&&(b=c);"number"==typeof b&&(b+=1,this.getOptionData(b))}},b.getOptionData=function(b){var e,f,g,h,i,j,k,l,m,n,o,p,d=this;if(!("number"!=typeof b||isNaN(b)||0>b||b>=d.selectArray.length)){for(e=b-1,f=d.selectArray[b],j={},k=f.data("url"),l="undefined"==typeof f.data("jsonSpace")?d.settings.jsonSpace:f.data("jsonSpace"),o=0,p=d.selectArray.length;p>o;o++)o>=b&&(d.selectArray[o].empty().prop("disabled",!0),"none"===d.settings.nodata?d.selectArray[o].css("display","none"):"hidden"===d.settings.nodata&&d.selectArray[o].css("visibility","hidden"));if("string"==typeof k&&k.length){if(e>=0){if(!d.selectArray[e].val().length)return;m=f.data("queryName"),n=d.selectArray[e].attr("name"),"string"==typeof m&&m.length?j[m]=d.selectArray[e].val():"string"==typeof n&&n.length&&(j[n]=d.selectArray[e].val())}a.getJSON(k,j,function(a){var b,c,e;if(h=a,"string"==typeof l&&l.length)for(b=l.split("."),c=0,e=b.length;e>c;c++)h=h[b[c]];d.buildOption(f,h)})}else if(d.dataJson&&"object"==typeof d.dataJson){for(h=d.dataJson,o=0,p=d.selectArray.length;p>o;o++)b>o&&(i=d.getIndex(d.selectArray[o][0].selectedIndex),"object"==typeof h[i]&&a.isArray(h[i][d.settings.jsonSub])&&h[i][d.settings.jsonSub].length&&(g=o,h=h[i][d.settings.jsonSub]));(0>e||e===g)&&d.buildOption(f,h)}}},b.buildOption=function(b,c){var i,j,k,d=this,e="undefined"==typeof b.data("firstTitle")?d.settings.firstTitle:String(b.data("firstTitle")),f="undefined"==typeof b.data("firstValue")?d.settings.firstValue:String(b.data("firstValue")),g="undefined"==typeof b.data("jsonName")?d.settings.jsonName:String(b.data("jsonName")),h="undefined"==typeof b.data("jsonValue")?d.settings.jsonValue:String(b.data("jsonValue"));if(a.isArray(c)){if(i=d.settings.required?"":'",g.length)for(h.length||(h=g),j=0,k=c.length;k>j;j++)i+='";else for(j=0,k=c.length;k>j;j++)i+='";b.html(i).prop("disabled",!1).css({display:"",visibility:""}),"undefined"!=typeof b.data("value")&&b.val(String(b.data("value"))).removeAttr("data-value"),b.trigger("change")}},b.init.apply(b,arguments),this},a.cxSelect.defaults={selects:[],url:null,nodata:null,required:!1,firstTitle:"请选择",firstValue:"",jsonSpace:"",jsonName:"n",jsonValue:"",jsonSub:"s"},a.fn.cxSelect=function(b,c){return this.each(function(){a.cxSelect(this,b,c)}),this}}); \ No newline at end of file