Skip to content

Commit 7cf451a

Browse files
committed
新增JS代码仓库及新增工具类downloader.js
1 parent e2eb324 commit 7cf451a

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

js-repo/downloader.js

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/**
2+
* Author:Dante Fung
3+
* Date:2017-4-13 21:05:15
4+
* Version:1.0.1
5+
* Memo:依赖jQuery
6+
* Changelog:
7+
* hello world! 2017-4-13 21:06:15
8+
*/
9+
(function(global,factory){
10+
11+
(global.DownLoader = factory());
12+
13+
})(this,function(){
14+
15+
/**
16+
* 这里暴露DownLoader的构造器
17+
* API conventions:
18+
* - public API methods/properties are prefixed with `$`
19+
* 公开的API方法和属性将都以$符号作为前缀开头
20+
* - internal methods/properties are prefixed with `_`
21+
* 内部私有的方法和属性将以_作为前缀开头
22+
* - non-prefixed properties are assumed to be proxied user
23+
* data.
24+
*
25+
*/
26+
function DownLoader(options){
27+
28+
}
29+
30+
/**
31+
* 对象继承
32+
*/
33+
function inherits(Child, Parent) {
34+
var F = function () {};
35+
F.prototype = Parent.prototype;
36+
Child.prototype = new F();
37+
Child.prototype.constructor = Child;
38+
}
39+
40+
/**
41+
* 创建对象方法
42+
*/
43+
function createDownLoader(props) {
44+
return new DownLoader(props || {});
45+
}
46+
47+
/**
48+
* POST方式下载资源
49+
*/
50+
DownLoader.prototype.DownLoadFile = function (_options) {
51+
var config = $.extend(true, { method: 'post' }, _options);
52+
var $iframe = $('<iframe id="down-file-iframe" />');
53+
var $form = $('<form target="down-file-iframe" method="' + config.method + '" />');
54+
$form.attr('action', config.url);
55+
for (var key in config.data) {
56+
$form.append('<input type="hidden" name="' + key + '" value="' + config.data[key] + '" />');
57+
}
58+
$iframe.append($form);
59+
$(document.body).append($iframe);
60+
$form[0].submit();
61+
$iframe.remove();
62+
}
63+
64+
DownLoader = createDownLoader();
65+
DownLoader.version = '1.0.0';
66+
67+
return DownLoader;
68+
});

0 commit comments

Comments
 (0)