Skip to content

Commit

Permalink
add jshlint
Browse files Browse the repository at this point in the history
  • Loading branch information
soulteary committed May 11, 2015
1 parent 9c103b4 commit a0e3257
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 72 deletions.
8 changes: 7 additions & 1 deletion Gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {});

Expand Down Expand Up @@ -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"));
});
Expand Down
2 changes: 1 addition & 1 deletion demo/dist/jquery.city.select.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

74 changes: 43 additions & 31 deletions dist/jquery.city.select.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
*
* @author [email protected]
*/
/* global define */
var cityselect;
cityselect = function ($) {
$.fn.extend({
Expand All @@ -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('<option ' + params.metaTag + '="' + data[oo][params.id] + '"' + (params.selected && params.selected == data[oo][params.id] ? hasSelected : '') + '>' + data[oo][params.name] + '</option>');
for (var xx in data[oo][params.children]) {
if (params.idVal) {
html.push('<option ' + params.metaTag + '="' + data[oo][params.children][xx][params.id] + '" value="' + data[oo][params.children][xx][params.name] + '"' + (params.selected && params.selected == data[oo][params.children][xx][params.id] ? hasSelected : '') + '>' + data[oo][params.children][xx][params.name] + '</option>');
} else {
html.push('<option ' + params.metaTag + '="' + data[oo][params.children][xx][params.id] + '" value="' + data[oo][params.children][xx][params.id] + '"' + (params.selected && params.selected == data[oo][params.children][xx][params.id] ? hasSelected : '') + '>' + data[oo][params.children][xx][params.name] + '</option>');
if (data.hasOwnProperty(oo)) {
html.push('<option ' + params.metaTag + '="' + data[oo][params.id] + '"' + (params.selected && params.selected == data[oo][params.id] ? hasSelected : '') + '>' + data[oo][params.name] + '</option>');
for (var xx in data[oo][params.children]) {
if (data[oo][params.children].hasOwnProperty(xx)) {
if (params.idVal) {
html.push('<option ' + params.metaTag + '="' + data[oo][params.children][xx][params.id] + '" value="' + data[oo][params.children][xx][params.name] + '"' + (params.selected && params.selected == data[oo][params.children][xx][params.id] ? hasSelected : '') + '>' + data[oo][params.children][xx][params.name] + '</option>');
} else {
html.push('<option ' + params.metaTag + '="' + data[oo][params.children][xx][params.id] + '" value="' + data[oo][params.children][xx][params.id] + '"' + (params.selected && params.selected == data[oo][params.children][xx][params.id] ? hasSelected : '') + '>' + data[oo][params.children][xx][params.name] + '</option>');
}
}
}
}
}
Expand All @@ -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('<option ' + params.metaTag + '="' + oItem[params.id] + '" value="' + oItem[params.id] + '"' + (params.selected && params.selected[0] == oItem[params.id] ? hasSelected : '') + '>' + oItem[params.name] + '</option>');
} else {
html.push('<option ' + params.metaTag + '="' + oItem[params.id] + '" value="' + oItem[params.name] + '"' + (params.selected && params.selected[0] == oItem[params.id] ? hasSelected : '') + '>' + oItem[params.name] + '</option>');
if (params.data.hasOwnProperty(item)) {
oItem = params.data[item];
if (params.idVal) {
html.push('<option ' + params.metaTag + '="' + oItem[params.id] + '" value="' + oItem[params.id] + '"' + (params.selected && params.selected[0] == oItem[params.id] ? hasSelected : '') + '>' + oItem[params.name] + '</option>');
} else {
html.push('<option ' + params.metaTag + '="' + oItem[params.id] + '" value="' + oItem[params.name] + '"' + (params.selected && params.selected[0] == oItem[params.id] ? hasSelected : '') + '>' + oItem[params.name] + '</option>');
}
}
}
html = html.join('');
Expand All @@ -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('<option ' + params.metaTag + '="' + oItem[sItem][params.id] + '" value="' + oItem[sItem][params.id] + '"' + (params.selected && params.selected[1] == oItem[sItem][params.id] ? hasSelected : '') + '>' + oItem[sItem][params.name] + '</option>');
} else {
html.push('<option ' + params.metaTag + '="' + oItem[sItem][params.id] + '" value="' + oItem[sItem][params.name] + '"' + (params.selected && params.selected[1] == oItem[sItem][params.id] ? hasSelected : '') + '>' + oItem[sItem][params.name] + '</option>');
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('<option ' + params.metaTag + '="' + oItem[sItem][params.id] + '" value="' + oItem[sItem][params.id] + '"' + (params.selected && params.selected[1] == oItem[sItem][params.id] ? hasSelected : '') + '>' + oItem[sItem][params.name] + '</option>');
} else {
html.push('<option ' + params.metaTag + '="' + oItem[sItem][params.id] + '" value="' + oItem[sItem][params.name] + '"' + (params.selected && params.selected[1] == oItem[sItem][params.id] ? hasSelected : '') + '>' + oItem[sItem][params.name] + '</option>');
}
}
}
break;
}
break;
}
}
html = html.join('');
Expand All @@ -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;
}
});
Expand Down
2 changes: 1 addition & 1 deletion dist/jquery.city.select.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading

0 comments on commit a0e3257

Please sign in to comment.