forked from aralejs/upload
-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.html
119 lines (108 loc) · 3.72 KB
/
demo.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<title>Uploader</title>
<script type="text/javascript" src="http://static.alipayobjects.com/seajs/seajs/2.1.1/sea.js"></script>
<script>
/**
* The Sea.js plugin for loading CommonJS file
* https://github.com/seajs/seajs-wrap
* just for debug enviroment
*/
!function(){function a(a,b){var d=c.ActiveXObject?new c.ActiveXObject("Microsoft.XMLHTTP"):new c.XMLHttpRequest;return d.open("GET",a,!0),d.onreadystatechange=function(){if(4===d.readyState){if(d.status>399&&d.status<600)throw new Error("Could not load: "+a+", status = "+d.status);b(d.responseText)}},d.send(null)}function b(a){a&&/\S/.test(a)&&(c.execScript||function(a){(c.eval||eval).call(c,a)})(a)}var c=window,d={};seajs.on("resolve",function(a){var c=a.id;if(!c)return"";var e=c.match(/[^?]+(\.\w+)?(\?.*)?$/),f=seajs.resolve(c,a.refUri);if(e&&(".js"===e[1]||!e[1])){var g=e[2]||"";d[f]=function(a,c){var d,e=/define\(.*function\s*\(\s*require\s*(.*)?\)\s*\{/;d=e.test(c)||g.indexOf("nowrap")>0?c:"define(function(require, exports, module) {\n"+c+"\n})",b(d)}}a.uri=f}),seajs.on("request",function(b){var c=d[b.uri];c&&(a(b.requestUri,function(a){c(b.uri,a),b.onRequest()}),b.requested=!0)}),define("seajs/seajs-wrap/1.0.0/seajs-wrap",[],{})}();
</script>
<style type="text/css">
.container {
margin: 0 auto;
width: 80%;
max-width: 680px;
padding: 60px 0;
}
</style>
<script type="text/javascript">
seajs.config({
alias: {'jquery': '/spm_modules/jquery/1.7.2/jquery'}
});
</script>
</head>
<body>
<div class="container">
<h1>Uploader DEMO</h1>
<p>This is a project by <a href="http://lepture.com">Hsiaoming Yang</a>.</p>
<h2>Select and Upload</h2>
<div class="cell">
<button id="uploader-1" href="#">Upload</button>
</div>
<h2>Select then upload</h2>
<div class="cell">
<p>
<button id="uploader-2" href="#">Select</button>
<span id="upload-2-text"></span></p>
<p>
<button id="submit-2" href="#">Upload</button>
</p>
</div>
<h2>Only upload image</h2>
<div class="cell">
<button id="uploader-3" href="#">Upload</button>
</div>
<h2>Disable upload</h2>
<div class="cell">
<p><button id="uploader-4" href="#">Select</button>
<span id="upload-4-text"></span></p>
<p><button id="disable" href="#">Disable</button><button id="submit-4" href="#">Upload</button></p>
</div>
</div>
<script type="text/javascript">
seajs.use(['jquery', '/index'], function($, Uploader) {
new Uploader({
trigger: '#uploader-1',
action: '/',
progress: function() {
console.log(arguments);
}
}).success(function(data) {
alert(data);
});
var uploader = new Uploader({
trigger: '#uploader-2',
action: '/'
}).change(function(filename) {
$('#upload-2-text').text(filename);
}).success(function(data) {
alert(data);
});
$('#submit-2').click(function() {
uploader.submit();
return false;
});
new Uploader({
trigger: '#uploader-3',
accept: 'image/*',
action: '/'
}).success(function(data) {
alert(data);
});
var uploaderCanBeDisabled = new Uploader({
trigger: '#uploader-4',
action: '/'
}).change(function(filename) {
$('#upload-4-text').text(filename);
}).success(function(data) {
alert(data);
});
$('#disable').click(function() {
var txt = $(this).html();
uploaderCanBeDisabled[txt === 'Disable'? 'disable': 'enable']();
$(this).html(txt === 'Disable'? 'Enable': 'Disable');
return false;
});
$('#submit-4').click(function() {
uploaderCanBeDisabled.submit();
return false;
});
});
</script>
</body>
</html>