diff --git a/Gulpfile.js b/Gulpfile.js
index d808755..dca0c45 100644
--- a/Gulpfile.js
+++ b/Gulpfile.js
@@ -10,6 +10,8 @@ var rm = require('gulp-rm');
var replace = require('gulp-replace');
var wrap = require("gulp-wrap");
var rjs = require('gulp-requirejs');
+var lintAll = require('gulp-lint-everything')({jshint: ".jshintrc"});
+
gulp.task("default", ["clean:tmp"], function () {});
@@ -38,7 +40,11 @@ gulp.task("scripts:build", ["scripts:make-amd"], function () {
.pipe(gulp.dest("./dist"));
});
-gulp.task("demo:sync", ["scripts:build"], function () {
+gulp.task("scripts:lint", ["scripts:build"], function(){
+ return lintAll("./src/**/*.js");
+});
+
+gulp.task("demo:sync", ["scripts:lint"], function () {
return gulp.src("./dist/jquery.city.select.min.js")
.pipe(gulp.dest("./demo/dist"));
});
diff --git a/demo/dist/jquery.city.select.min.js b/demo/dist/jquery.city.select.min.js
index efe3f09..16fc4d7 100644
--- a/demo/dist/jquery.city.select.min.js
+++ b/demo/dist/jquery.city.select.min.js
@@ -1 +1 @@
-!function(e,i){"function"==typeof define?define(["city.select"],i):"object"==typeof exports?module.exports=i():i()}(this,function(){"use strict";var e;return e=function(e){return e.fn.extend({citylist:function(i){function n(e,i){var n=e,t=i.data,a=[];for(var o in t){a.push("");for(var r in t[o][i.children])a.push(i.idVal?"":"")}a=a.join(""),n.find("option").remove(),n.append(a)}function t(i,n){var t,a=i.eq(0),o=i.eq(1),r=[];for(var c in n.data)t=n.data[c],r.push(n.idVal?"":"");r=r.join(""),a.find("option").remove(),a.append(r);var l=a.find("option");a.on("change",function(){var i=e(this).val();l.each(function(t,a){return e(a).val()==i?function(i){var t,a=e(i).attr(n.metaTag),r=[];for(var c in n.data)if(t=n.data[c],t[n.id]==a&&t[n.children]){t=t[n.children];for(var l in t)r.push(n.idVal?"":"");break}r=r.join(""),o.find("option").remove(),o.append(r)}(a):void 0})}).trigger("change")}i=e.extend({id:"id",name:"name",children:"children",metaTag:"data-extra",idVal:!1,data:!1,selected:!1},i);var a=e(this),d=' selected="selected"';switch(a.length){case 1:n(a,i);break;case 2:t(a,i);break;default:return this}return this}}),e}(jQuery)});
\ No newline at end of file
+!function(e,n){"function"==typeof define?define(["city.select"],n):"object"==typeof exports?module.exports=n():n()}(this,function(){"use strict";var e;return e=function(e){return e.fn.extend({citylist:function(n){function t(e,n){var t=e,i=n.data,a=[];for(var o in i)if(i.hasOwnProperty(o)){a.push("");for(var r in i[o][n.children])i[o][n.children].hasOwnProperty(r)&&a.push(n.idVal?"":"")}a=a.join(""),t.find("option").remove(),t.append(a)}function i(n,t){var i,a=n.eq(0),o=n.eq(1),r=[];for(var c in t.data)t.data.hasOwnProperty(c)&&(i=t.data[c],r.push(t.idVal?"":""));r=r.join(""),a.find("option").remove(),a.append(r);var l=a.find("option");a.on("change",function(){var n=e(this).val();l.each(function(i,a){return e(a).val()==n?function(n){var i,a=e(n).attr(t.metaTag),r=[];for(var c in t.data)if(t.data.hasOwnProperty(c)&&(i=t.data[c],i[t.id]==a&&i[t.children])){i=i[t.children];for(var l in i)i.hasOwnProperty(l)&&r.push(t.idVal?"":"");break}r=r.join(""),o.find("option").remove(),o.append(r)}(a):void 0})}).trigger("change")}n=e.extend({id:"id",name:"name",children:"children",metaTag:"data-extra",idVal:!1,data:!1,selected:!1},n);var a=e(this),d=' selected="selected"';switch(a.length){case 1:t(a,n);break;case 2:i(a,n);break;default:return this}return this}}),e}(jQuery)});
\ No newline at end of file
diff --git a/dist/jquery.city.select.js b/dist/jquery.city.select.js
index fb0224f..499a144 100644
--- a/dist/jquery.city.select.js
+++ b/dist/jquery.city.select.js
@@ -20,6 +20,7 @@
*
* @author soulteary@qq.com
*/
+/* global define */
var cityselect;
cityselect = function ($) {
$.fn.extend({
@@ -41,28 +42,21 @@ cityselect = function ($) {
}, params);
var target = $(this);
var hasSelected = ' selected="selected"';
- switch (target.length) {
- case 1:
- singleBox(target, params);
- break;
- case 2:
- multipleBox(target, params);
- break;
- default:
- // 参数不存在或者不匹配可接受数量时
- return this;
- }
function singleBox(target, params) {
var all = target;
var data = params.data;
var html = [];
for (var oo in data) {
- html.push('');
- for (var xx in data[oo][params.children]) {
- if (params.idVal) {
- html.push('');
- } else {
- html.push('');
+ if (data.hasOwnProperty(oo)) {
+ html.push('');
+ for (var xx in data[oo][params.children]) {
+ if (data[oo][params.children].hasOwnProperty(xx)) {
+ if (params.idVal) {
+ html.push('');
+ } else {
+ html.push('');
+ }
+ }
}
}
}
@@ -75,11 +69,13 @@ cityselect = function ($) {
var city = target.eq(1);
var html = [], oItem;
for (var item in params.data) {
- oItem = params.data[item];
- if (params.idVal) {
- html.push('');
- } else {
- html.push('');
+ if (params.data.hasOwnProperty(item)) {
+ oItem = params.data[item];
+ if (params.idVal) {
+ html.push('');
+ } else {
+ html.push('');
+ }
}
}
html = html.join('');
@@ -90,21 +86,26 @@ cityselect = function ($) {
var curSelect = $(this).val();
provinces.each(function (k, v) {
if ($(v).val() == curSelect) {
+ /*jshint immed: true */
return function (v) {
var extra = $(v).attr(params.metaTag);
var html = [], oItem;
for (var item in params.data) {
- oItem = params.data[item];
- if (oItem[params.id] == extra && oItem[params.children]) {
- oItem = oItem[params.children];
- for (var sItem in oItem) {
- if (params.idVal) {
- html.push('');
- } else {
- html.push('');
+ if (params.data.hasOwnProperty(item)) {
+ oItem = params.data[item];
+ if (oItem[params.id] == extra && oItem[params.children]) {
+ oItem = oItem[params.children];
+ for (var sItem in oItem) {
+ if (oItem.hasOwnProperty(sItem)) {
+ if (params.idVal) {
+ html.push('');
+ } else {
+ html.push('');
+ }
+ }
}
+ break;
}
- break;
}
}
html = html.join('');
@@ -115,6 +116,17 @@ cityselect = function ($) {
});
}).trigger('change');
}
+ switch (target.length) {
+ case 1:
+ singleBox(target, params);
+ break;
+ case 2:
+ multipleBox(target, params);
+ break;
+ default:
+ // 参数不存在或者不匹配可接受数量时
+ return this;
+ }
return this;
}
});
diff --git a/dist/jquery.city.select.min.js b/dist/jquery.city.select.min.js
index efe3f09..16fc4d7 100644
--- a/dist/jquery.city.select.min.js
+++ b/dist/jquery.city.select.min.js
@@ -1 +1 @@
-!function(e,i){"function"==typeof define?define(["city.select"],i):"object"==typeof exports?module.exports=i():i()}(this,function(){"use strict";var e;return e=function(e){return e.fn.extend({citylist:function(i){function n(e,i){var n=e,t=i.data,a=[];for(var o in t){a.push("");for(var r in t[o][i.children])a.push(i.idVal?"":"")}a=a.join(""),n.find("option").remove(),n.append(a)}function t(i,n){var t,a=i.eq(0),o=i.eq(1),r=[];for(var c in n.data)t=n.data[c],r.push(n.idVal?"":"");r=r.join(""),a.find("option").remove(),a.append(r);var l=a.find("option");a.on("change",function(){var i=e(this).val();l.each(function(t,a){return e(a).val()==i?function(i){var t,a=e(i).attr(n.metaTag),r=[];for(var c in n.data)if(t=n.data[c],t[n.id]==a&&t[n.children]){t=t[n.children];for(var l in t)r.push(n.idVal?"":"");break}r=r.join(""),o.find("option").remove(),o.append(r)}(a):void 0})}).trigger("change")}i=e.extend({id:"id",name:"name",children:"children",metaTag:"data-extra",idVal:!1,data:!1,selected:!1},i);var a=e(this),d=' selected="selected"';switch(a.length){case 1:n(a,i);break;case 2:t(a,i);break;default:return this}return this}}),e}(jQuery)});
\ No newline at end of file
+!function(e,n){"function"==typeof define?define(["city.select"],n):"object"==typeof exports?module.exports=n():n()}(this,function(){"use strict";var e;return e=function(e){return e.fn.extend({citylist:function(n){function t(e,n){var t=e,i=n.data,a=[];for(var o in i)if(i.hasOwnProperty(o)){a.push("");for(var r in i[o][n.children])i[o][n.children].hasOwnProperty(r)&&a.push(n.idVal?"":"")}a=a.join(""),t.find("option").remove(),t.append(a)}function i(n,t){var i,a=n.eq(0),o=n.eq(1),r=[];for(var c in t.data)t.data.hasOwnProperty(c)&&(i=t.data[c],r.push(t.idVal?"":""));r=r.join(""),a.find("option").remove(),a.append(r);var l=a.find("option");a.on("change",function(){var n=e(this).val();l.each(function(i,a){return e(a).val()==n?function(n){var i,a=e(n).attr(t.metaTag),r=[];for(var c in t.data)if(t.data.hasOwnProperty(c)&&(i=t.data[c],i[t.id]==a&&i[t.children])){i=i[t.children];for(var l in i)i.hasOwnProperty(l)&&r.push(t.idVal?"":"");break}r=r.join(""),o.find("option").remove(),o.append(r)}(a):void 0})}).trigger("change")}n=e.extend({id:"id",name:"name",children:"children",metaTag:"data-extra",idVal:!1,data:!1,selected:!1},n);var a=e(this),d=' selected="selected"';switch(a.length){case 1:t(a,n);break;case 2:i(a,n);break;default:return this}return this}}),e}(jQuery)});
\ No newline at end of file
diff --git a/package.json b/package.json
index ad74427..0b0f122 100644
--- a/package.json
+++ b/package.json
@@ -26,6 +26,7 @@
"gulp-concat": "^2.5.2",
"gulp-directory-sync": "^1.0.0",
"gulp-less": "^3.0.3",
+ "gulp-lint-everything": "^0.3.2",
"gulp-minify-css": "^1.1.0",
"gulp-requirejs": "^0.1.3",
"gulp-rm": "^1.0.0",
diff --git a/src/jquery.city.select.js b/src/jquery.city.select.js
index 653f3ea..92629ed 100644
--- a/src/jquery.city.select.js
+++ b/src/jquery.city.select.js
@@ -9,11 +9,12 @@
*
* @author soulteary@qq.com
*/
-define('city.select',['jQuery'], function ($) {
+/* global define */
+define('city.select', ['jQuery'], function ($) {
'use strict';
$.fn.extend({
- "citylist": function (params) {
+ 'citylist': function (params) {
params = $.extend({
id : 'id', //数据的ID名称
name : 'name', //数据的VALUE名称
@@ -27,31 +28,22 @@ define('city.select',['jQuery'], function ($) {
var target = $(this);
var hasSelected = ' selected="selected"';
- switch (target.length) {
- case 1:
- singleBox(target, params);
- break;
- case 2:
- multipleBox(target, params);
- break;
- default :
- // 参数不存在或者不匹配可接受数量时
- return this;
- }
-
-
function singleBox (target, params) {
var all = target;
var data = params.data;
var html = [];
for (var oo in data) {
- html.push('');
- for (var xx in data[oo][params.children]) {
- if (params.idVal) {
- html.push('');
- } else {
- html.push('');
+ if (data.hasOwnProperty(oo)) {
+ html.push('');
+ for (var xx in data[oo][params.children]) {
+ if (data[oo][params.children].hasOwnProperty(xx)) {
+ if (params.idVal) {
+ html.push('');
+ } else {
+ html.push('');
+ }
+ }
}
}
}
@@ -66,13 +58,15 @@ define('city.select',['jQuery'], function ($) {
var html = [], oItem;
for (var item in params.data) {
- oItem = params.data[item];
- if (params.idVal) {
- html.push('');
+ if (params.data.hasOwnProperty(item)) {
+ oItem = params.data[item];
+ if (params.idVal) {
+ html.push('');
- } else {
- html.push('');
+ } else {
+ html.push('');
+ }
}
}
html = html.join('');
@@ -84,23 +78,27 @@ define('city.select',['jQuery'], function ($) {
var curSelect = $(this).val();
provinces.each(function (k, v) {
if ($(v).val() == curSelect) {
+ /*jshint immed: true */
return (function (v) {
var extra = $(v).attr(params.metaTag);
var html = [], oItem;
for (var item in params.data) {
- oItem = params.data[item];
- if (oItem[params.id] == extra && oItem[params.children]) {
- oItem = oItem[params.children];
- for (var sItem in oItem) {
- if (params.idVal) {
- html.push('');
-
- } else {
- html.push('');
-
+ if (params.data.hasOwnProperty(item)) {
+ oItem = params.data[item];
+ if (oItem[params.id] == extra && oItem[params.children]) {
+ oItem = oItem[params.children];
+ for (var sItem in oItem) {
+ if (oItem.hasOwnProperty(sItem)) {
+ if (params.idVal) {
+ html.push('');
+
+ } else {
+ html.push('');
+ }
+ }
}
+ break;
}
- break;
}
}
html = html.join('');
@@ -108,11 +106,23 @@ define('city.select',['jQuery'], function ($) {
city.append(html);
}(v));
}
- })
+ });
}).trigger('change');
}
+ switch (target.length) {
+ case 1:
+ singleBox(target, params);
+ break;
+ case 2:
+ multipleBox(target, params);
+ break;
+ default :
+ // 参数不存在或者不匹配可接受数量时
+ return this;
+ }
+
return this;
}
});