Skip to content
This repository has been archived by the owner on Sep 27, 2024. It is now read-only.

Commit

Permalink
Q.js 微调
Browse files Browse the repository at this point in the history
Signed-off-by: Devin <[email protected]>
  • Loading branch information
Devin committed Jul 15, 2015
1 parent 75d0fde commit b9ffa4f
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 71 deletions.
4 changes: 2 additions & 2 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var http = require('http'),
app = express();

app.use(express.static('./www'));
app.use(express.bodyParser({ uploadDir: './upload', limit: '500mb' }));
app.use(express.bodyParser({ uploadDir: './upload', limit: '2000mb' }));

app.get('/', function (req, res) {
res.redirect("/demo/default.html");
Expand All @@ -18,7 +18,7 @@ app.post('/upload', function (req, res) {
var path = f.path,
fileName = f.name;

console.log(fileName + " => " + path + " | " + Q.formatSize(f.size).text);
console.log(fileName + " => " + path + " | " + Q.formatSize(f.size));
});

var user = req.body["user"],
Expand Down
28 changes: 15 additions & 13 deletions lib/Q.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*
* Q.js for Node
* author:[email protected]
* update:2014/09/18 15:33
* update:2015/07/15 10:19
*/
(function (global, undefined) {
(function (undefined) {
"use strict";

var toString = Object.prototype.toString,
Expand Down Expand Up @@ -36,6 +36,8 @@
//扩展对象
//forced:是否强制扩展
function extend(destination, source, forced) {
if (!destination || !source) return;

for (var key in source) {
if (key == undefined || !has.call(source, key)) continue;

Expand Down Expand Up @@ -99,7 +101,7 @@
}

if (level && size < stepNow) {
stepNow /= (isNum ? steps : steps[steps.length - 1]);
stepNow /= (isNum ? steps : steps.last());
level--;
}

Expand All @@ -110,22 +112,24 @@

//格式化数字输出,将数字转为合适的单位输出,默认按照1024层级转为文件单位输出
function formatSize(size, ops) {
ops = ops || {};
ops = ops === true ? { all: true } : ops || {};

if (isNaN(size) || size == undefined || size < 0) return { text: ops.error || "--" };
if (isNaN(size) || size == undefined || size < 0) {
var error = ops.error || "--";

var pl = parseLevel(size, ops.steps, ops.limit),
return ops.all ? { text: error } : error;
}

digit = ops.digit,
var pl = parseLevel(size, ops.steps, ops.limit),

value = pl.value,
text = value.toFixed(isUInt(digit) || digit == 0 ? digit : 2);
text = value.toFixed(def(ops.digit, 2));

if (ops.trim !== false && text.lastIndexOf(".") != -1) text = text.replace(/\.?0+$/, "");

pl.text = text + (ops.join || "") + (ops.units || UNITS_FILE_SIZE)[pl.level + (ops.levelFix || 0)];
pl.text = text + (ops.join || "") + (ops.units || UNITS_FILE_SIZE)[pl.level + (ops.start || 0)];

return pl;
return ops.all ? pl : pl.text;
}

//---------------------- export ----------------------
Expand All @@ -145,10 +149,8 @@
formatSize: formatSize
};

global.Q = Q;

if (typeof module === "object" && typeof module.exports === "object") {
module.exports = Q;
}

})(this);
})();
6 changes: 1 addition & 5 deletions www/demo/custom.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,9 @@

<script type="text/javascript">
var Uploader = Q.Uploader,

formatSize = Q.formatSize,
boxView = document.getElementById("upload-info");

function formatSize(size) {
return Q.formatSize(size).text;
}

new Uploader({
url: UPLOAD_URL,
target: document.getElementById("upload-target"),
Expand Down
8 changes: 4 additions & 4 deletions www/dist/Q.Uploader.UI.js

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

20 changes: 10 additions & 10 deletions www/dist/Q.Uploader.js

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

Loading

0 comments on commit b9ffa4f

Please sign in to comment.