|
6 | 6 | * |
7 | 7 | * GitHub: http://github.com/qiniu/js-sdk |
8 | 8 | * |
9 | | - * Date: 2015-12-10 |
| 9 | + * Date: 2015-12-28 |
10 | 10 | */ |
11 | 11 |
|
12 | 12 | /*global plupload ,mOxie*/ |
|
16 | 16 |
|
17 | 17 | ;(function( global ){ |
18 | 18 |
|
19 | | -// var store = function store(key, value) { |
20 | | -// var lsSupport = false, |
21 | | -// data = null; |
22 | | - |
23 | | -// // Check for native support |
24 | | -// if (localStorage) { |
25 | | -// lsSupport = true; |
26 | | -// } |
27 | | - |
28 | | -// // If value is detected, set new or modify store |
29 | | -// if (typeof value !== "undefined" && value !== null) { |
30 | | -// // Convert object values to JSON |
31 | | -// if ( typeof value === 'object' ) { |
32 | | -// value = JSON.stringify(value); |
33 | | -// } |
34 | | -// // Set the store |
35 | | -// if (lsSupport) { // Native support |
36 | | -// localStorage.setItem(key, value); |
37 | | -// } else { // Use Cookie |
38 | | -// createCookie(key, value, 30); |
39 | | -// } |
40 | | -// } |
41 | | - |
42 | | -// // No value supplied, return value |
43 | | -// if (typeof value === "undefined") { |
44 | | -// // Get value |
45 | | -// if (lsSupport) { // Native support |
46 | | -// data = localStorage.getItem(key); |
47 | | -// } else { // Use cookie |
48 | | -// data = readCookie(key); |
49 | | -// } |
50 | | - |
51 | | -// // Try to parse JSON... |
52 | | -// try { |
53 | | -// data = JSON.parse(data); |
54 | | -// } |
55 | | -// catch(e) { |
56 | | -// data = data; |
57 | | -// } |
58 | | - |
59 | | -// return data; |
60 | | - |
61 | | -// } |
62 | | - |
63 | | -// // Null specified, remove store |
64 | | -// if (value === null) { |
65 | | -// if (lsSupport) { // Native support |
66 | | -// localStorage.removeItem(key); |
67 | | -// } else { // Use cookie |
68 | | -// createCookie(key, '', -1); |
69 | | -// } |
70 | | -// } |
71 | | - |
72 | | -// /** |
73 | | -// * Creates new cookie or removes cookie with negative expiration |
74 | | -// * @param key The key or identifier for the store |
75 | | -// * @param value Contents of the store |
76 | | -// * @param exp Expiration - creation defaults to 30 days |
77 | | -// */ |
78 | | - |
79 | | -// function createCookie(key, value, exp) { |
80 | | -// var date = new Date(); |
81 | | -// date.setTime(date.getTime() + (exp * 24 * 60 * 60 * 1000)); |
82 | | -// var expires = "; expires=" + date.toGMTString(); |
83 | | -// document.cookie = key + "=" + value + expires + "; path=/"; |
84 | | -// } |
85 | | - |
86 | | -// /** |
87 | | -// * Returns contents of cookie |
88 | | -// * @param key The key or identifier for the store |
89 | | -// */ |
90 | | - |
91 | | -// function readCookie(key) { |
92 | | -// var nameEQ = key + "="; |
93 | | -// var ca = document.cookie.split(';'); |
94 | | -// for (var i = 0, max = ca.length; i < max; i++) { |
95 | | -// var c = ca[i]; |
96 | | -// while (c.charAt(0) === ' ') { |
97 | | -// c = c.substring(1, c.length); |
98 | | -// } |
99 | | -// if (c.indexOf(nameEQ) === 0) { |
100 | | -// return c.substring(nameEQ.length, c.length); |
101 | | -// } |
102 | | -// } |
103 | | -// return null; |
104 | | -// } |
105 | | - |
106 | | -// }; |
| 19 | +/** |
| 20 | + * Creates new cookie or removes cookie with negative expiration |
| 21 | + * @param key The key or identifier for the store |
| 22 | + * @param value Contents of the store |
| 23 | + * @param exp Expiration - creation defaults to 30 days |
| 24 | + */ |
| 25 | +function createCookie(key, value, exp) { |
| 26 | + var date = new Date(); |
| 27 | + date.setTime(date.getTime() + (exp * 24 * 60 * 60 * 1000)); |
| 28 | + var expires = "; expires=" + date.toGMTString(); |
| 29 | + document.cookie = key + "=" + value + expires + "; path=/"; |
| 30 | +} |
| 31 | + |
| 32 | +/** |
| 33 | + * Returns contents of cookie |
| 34 | + * @param key The key or identifier for the store |
| 35 | + */ |
| 36 | +function readCookie(key) { |
| 37 | + var nameEQ = key + "="; |
| 38 | + var ca = document.cookie.split(';'); |
| 39 | + for (var i = 0, max = ca.length; i < max; i++) { |
| 40 | + var c = ca[i]; |
| 41 | + while (c.charAt(0) === ' ') { |
| 42 | + c = c.substring(1, c.length); |
| 43 | + } |
| 44 | + if (c.indexOf(nameEQ) === 0) { |
| 45 | + return c.substring(nameEQ.length, c.length); |
| 46 | + } |
| 47 | + } |
| 48 | + return null; |
| 49 | +} |
| 50 | + |
107 | 51 |
|
108 | 52 | if ( !window.localStorage ) { |
109 | 53 | window.localStorage = { |
110 | | - data: {}, |
111 | 54 | setItem: function (key, value) { |
112 | | - localStorage.data[key] = value; |
| 55 | + createCookie(key, value, 30); |
113 | 56 | }, |
114 | 57 | getItem: function (key) { |
115 | | - return localStorage.data[key] || null ; |
| 58 | + return readCookie(key); |
116 | 59 | }, |
117 | 60 | removeItem: function (key) { |
118 | | - localStorage.data[key] = null; |
| 61 | + createCookie(key, '', -1); |
119 | 62 | } |
120 | 63 | }; |
121 | 64 | } |
@@ -651,6 +594,13 @@ function QiniuJsSDK() { |
651 | 594 | // bind getUpToken to 'Init' event |
652 | 595 | uploader.bind('Init', function(up, params) { |
653 | 596 | logger.debug("Init event activated"); |
| 597 | + // if op.get_new_uptoken is not true |
| 598 | + // invoke getUptoken when uploader init |
| 599 | + // else |
| 600 | + // getUptoken everytime before a new file upload |
| 601 | + if(!op.get_new_uptoken){ |
| 602 | + getUpToken(); |
| 603 | + } |
654 | 604 | getUpToken(); |
655 | 605 | }); |
656 | 606 |
|
|
0 commit comments