Skip to content

Commit 634bf31

Browse files
committed
增加淘宝 API 测试;version 0.1.10
1 parent a0e34d9 commit 634bf31

17 files changed

+577
-420
lines changed

Gruntfile.js

Lines changed: 93 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,97 @@
11
module.exports = function(grunt) {
2-
grunt.initConfig({
3-
//如果需要用到 package.json 中的参数变量,可使用 pkg 引用(如 pkg.name)
4-
pkg : grunt.file.readJSON('package.json'),
5-
//监控自动编译
6-
watch: {
7-
options: {
8-
atBegin: true
9-
},
10-
js: {
11-
files: 'bootstrap-suggest.js',
12-
tasks: ['development']
13-
}
14-
},
15-
//eslint 代码质量检查任务
16-
eslint: {
17-
options: {
18-
},
19-
src: ['src/bootstrap-suggest.js']
20-
},
21-
//concat 多文件合并任务
22-
concat: {
23-
js: {
24-
//banner: "'use strict';\n",
25-
options: {
26-
separator: "\n", //多文件分隔符,
27-
stripBanners: true,
28-
banner: "/**\r\n * <%= pkg.name %> - v<%= pkg.version %>\r\n" +
29-
" * @description <%= pkg.description %>\r\n" +
30-
" * @author <%= pkg.author %>\r\n" +
31-
" * @GitHub <%= pkg.repository.url %>\r\n" +
32-
' * @since <%= grunt.template.today("yyyy-mm-dd HH:MM:ss") %>\r\n' +
33-
" */\r\n"
34-
},
35-
src: ['dist/bootstrap-suggest.min.js'], //合并哪些文件
36-
dest: 'dist/bootstrap-suggest.min.js' //合并后输出
37-
}
38-
},
39-
//uglify 压缩任务,压缩 js
40-
uglify: {
41-
js: {
42-
files: {
43-
'dist/bootstrap-suggest.min.js': ['src/bootstrap-suggest.js'] //替换保存
44-
}
45-
}
46-
}
47-
//cssmin 压缩任务,压缩 css
48-
/*cssmin: {
49-
css: {
50-
src: 'index.min.css',
51-
dest: 'index.min.css'
52-
}
53-
},*/
54-
//复制到发布目录
55-
/*copy: {
56-
main: {
57-
src: 'dist/bootstrap-suggest.min.js',
58-
dest: '../../resources/orion/lib/bootstrap-suggest-plugin/bootstrap-suggest.min.js',
59-
},
60-
}*/
61-
});
62-
//加载包含 eslint、concat 和 uglify 任务的插件
63-
grunt.loadNpmTasks('grunt-contrib-watch');
64-
grunt.loadNpmTasks("gruntify-eslint");
65-
grunt.loadNpmTasks('grunt-contrib-concat');
66-
grunt.loadNpmTasks('grunt-contrib-uglify');
67-
//grunt.loadNpmTasks('grunt-contrib-copy');
2+
grunt.initConfig({
3+
//如果需要用到 package.json 中的参数变量,可使用 pkg 引用(如 pkg.name)
4+
pkg: grunt.file.readJSON('package.json'),
5+
//监控自动编译
6+
watch: {
7+
livereload: {
8+
options: {
9+
livereload: '<%=connect.options.livereload%>' //监听前面声明的端口 28820
10+
},
11+
//监听文件列表
12+
files: [
13+
'demo/**',
14+
'src/**',
15+
'test/**'
16+
]
17+
}
18+
},
19+
connect: {
20+
options: {
21+
port: 8820, //webserver 端口
22+
hostname: '*', //可配置为本机某个 IP,localhost 或域名
23+
livereload: 28820, //声明给 watch 监听的端口
24+
//protocol: 'https',
25+
// key: grunt.file.read('server.key').toString(),
26+
// cert: grunt.file.read('server.crt').toString(),
27+
// ca: grunt.file.read('ca.crt').toString()
28+
},
29+
server: {
30+
options: {
31+
open: true, //自动打开网页 http://localhost:8820
32+
base: [ //主目录
33+
'./'
34+
]
35+
}
36+
}
37+
},
38+
//eslint 代码质量检查任务
39+
eslint: {
40+
options: {},
41+
src: ['src/bootstrap-suggest.js']
42+
},
43+
//concat 多文件合并任务
44+
concat: {
45+
js: {
46+
options: {
47+
separator: "\n", //多文件分隔符,
48+
stripBanners: true,
49+
banner: "/**\r\n * <%= pkg.name %> - v<%= pkg.version %>\r\n" +
50+
" * @description <%= pkg.description %>\r\n" +
51+
" * @author <%= pkg.author %>\r\n" +
52+
" * @GitHub <%= pkg.repository.url %>\r\n" +
53+
' * @since <%= grunt.template.today("yyyy-mm-dd HH:MM:ss") %>\r\n' +
54+
" */\r\n"
55+
},
56+
src: ['dist/bootstrap-suggest.min.js'], //合并哪些文件
57+
dest: 'dist/bootstrap-suggest.min.js' //合并后输出
58+
}
59+
},
60+
//uglify 压缩任务,压缩 js
61+
uglify: {
62+
js: {
63+
files: {
64+
'dist/bootstrap-suggest.min.js': ['src/bootstrap-suggest.js'] //替换保存
65+
}
66+
}
67+
}
68+
//cssmin 压缩任务,压缩 css
69+
/*cssmin: {
70+
css: {
71+
src: 'src/index.css',
72+
dest: 'dist/index.min.css'
73+
}
74+
},*/
75+
//复制到发布目录
76+
/*copy: {
77+
main: {
78+
src: 'dist/bootstrap-suggest.min.js',
79+
dest: '../../resources/orion/lib/bootstrap-suggest-plugin/bootstrap-suggest.min.js',
80+
},
81+
}*/
82+
});
83+
//加载包含 eslint、concat 和 uglify 任务的插件
84+
grunt.loadNpmTasks('grunt-contrib-watch');
85+
grunt.loadNpmTasks('grunt-contrib-connect');
86+
grunt.loadNpmTasks("gruntify-eslint");
87+
grunt.loadNpmTasks('grunt-contrib-concat');
88+
grunt.loadNpmTasks('grunt-contrib-uglify');
89+
//grunt.loadNpmTasks('grunt-contrib-copy');
6890

6991

70-
//默认被执行的任务列表
71-
grunt.registerTask('default', ['eslint', 'uglify', 'concat']);
72-
//自定义任务列表
73-
grunt.registerTask('development', ['eslint', 'uglify', 'concat'/*, 'copy'*/]);
74-
grunt.registerTask('production', ['eslint', 'uglify', 'concat']);
92+
//默认被执行的任务列表
93+
grunt.registerTask('default', ['serve']);
94+
//自定义任务列表
95+
grunt.registerTask('serve', ['connect:server','watch']);
96+
grunt.registerTask('prod', ['eslint', 'uglify', 'concat']);
7597
};

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ var bsSuggest = $("#test").bsSuggest({
5959
});
6060
```
6161

62+
## 使用示例
63+
64+
请参考 demo/index.html 文件源代码,提供了自定义数据、URL 请求数据、百度搜索 API、淘宝搜索 API 的接口演示。
65+
6266
####方法调用
6367
1. 禁用提示: `$("input#test").bsSuggest("disable");`
6468
2. 启用提示: `$("input#test").bsSuggest("enable");`
@@ -82,10 +86,6 @@ $("#test")
8286
});
8387
```
8488

85-
## 使用示例
86-
87-
请参考 demo/index.html 文件源代码,提供了自定义数据、URL 请求数据、百度搜索 API、淘宝搜索 API 的接口演示。
88-
8989
## 配置参数
9090

9191
参数列表中的值均为插件默认值
@@ -157,8 +157,9 @@ var defaultOptions = {
157157

158158
1. 安装grunt `npm install grunt-cli -g`
159159
2. 安装依赖 `npm install`
160-
3. 实时编译 `grunt watch`
161-
4. 执行编译 `npm build`
160+
3. 实时开发 `npm start`
161+
4. 执行测试 `npm test`
162+
4. 执行编译 `npm run build`
162163

163164
提示:对于 phantomjs 的依赖,如下载超时,可使用其他工具下载,然后放到命令行提示的目录,解压,将解压的目录重命名为命令行提示正在解压的名称。然后重新执行 `npm install`
164165

demo/demo.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,6 @@
201201
dataType: 'jsonp',
202202
timeout: 10000,
203203
data: {
204-
t: (new Date()).getTime(),
205204
wd: $('#customKeyword').val() + keyword
206205
}
207206
};

dist/bootstrap-suggest.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "bootstrap-suggest-plugin",
3-
"version": "0.1.9",
3+
"version": "0.1.10",
44
"description": "这是一个基于 bootstrap 按钮式下拉菜单组件的搜索建议插件,必须使用于按钮式下拉菜单组件上。",
55
"repository": {
66
"type": "git",
@@ -32,18 +32,20 @@
3232
"node": ">= 4.1.0"
3333
},
3434
"scripts": {
35-
"test": "mocha-phantomjs test/index.html -v 1366x768",
36-
"build": "npm test && grunt production"
35+
"start": "grunt",
36+
"test": "node_modules/.bin/mocha-phantomjs test/index.html -v 1366x768",
37+
"build": "grunt prod"
3738
},
3839
"dependencies": {
39-
"jquery": ">=1.11.1 <3.0.0",
40-
"bootstrap": "3.3.6"
40+
"bootstrap": "3.3.6",
41+
"jquery": ">=1.11.1 <3.0.0"
4142
},
4243
"devDependencies": {
4344
"babel-eslint": "^6.1.2",
4445
"chai": "^3.5.0",
4546
"grunt": ">0.4.1",
4647
"grunt-contrib-concat": "^1.0.1",
48+
"grunt-contrib-connect": "^1.0.2",
4749
"grunt-contrib-copy": "^1.0.0",
4850
"grunt-contrib-eslint": "^0.0.5",
4951
"grunt-contrib-uglify": "^2.0.0",

src/bootstrap-suggest.js

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
* Bootstrap Search Suggest
33
* @desc 这是一个基于 bootstrap 按钮式下拉菜单组件的搜索建议插件,必须使用于按钮式下拉菜单组件上。
44
* @author renxia <lzwy0820#qq.com>
5-
* @see https://github.com/lzwme/bootstrap-suggest-plugin.git
6-
* @since 2014-10-09 - 2016-07-19
5+
* @github https://github.com/lzwme/bootstrap-suggest-plugin.git
6+
* @since 2014-10-09 - 2016-07-25
77
*===============================================================================
88
* (c) Copyright 2015-2016 lzw.me. All Rights Reserved.
99
********************************************************************************/
@@ -360,17 +360,6 @@
360360

361361
var ajaxParam = {
362362
type: 'GET',
363-
url: function() {
364-
var type = '?';
365-
366-
if (/=$/.test(options.url)) {
367-
type = '';
368-
} else if (/\?/.test(options.url)) {
369-
type = '&';
370-
}
371-
372-
return options.url + type + keyword;
373-
}(),
374363
dataType: options.jsonp ? 'jsonp' : 'json',
375364
timeout: 5000
376365
};
@@ -385,6 +374,22 @@
385374
ajaxParam = $.extend(ajaxParam, options.fnAdjustAjaxParam(keyword, options));
386375
}
387376

377+
//url 调整
378+
ajaxParam.url = function() {
379+
if (! keyword || ajaxParam.data) {
380+
return ajaxParam.url || options.url;
381+
}
382+
383+
var type = '?';
384+
if (/=$/.test(options.url)) {
385+
type = '';
386+
} else if (/\?/.test(options.url)) {
387+
type = '&';
388+
}
389+
390+
return options.url + type + keyword;
391+
}();
392+
388393
return $.ajax(ajaxParam).done(function(result) {
389394
options.data = options.fnProcessData(result);
390395
}).fail(handleError);
@@ -823,7 +828,7 @@
823828
});
824829
},
825830
version: function() {
826-
return '0.1.9';
831+
return '0.1.10';
827832
}
828833
};
829834

0 commit comments

Comments
 (0)