Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Plupload: Staighten comments a bit. Build: Add wiki building task.

  • Loading branch information...
commit 5cf650d50b7ca2f9cb62587772c7b966d63cb8b7 1 parent c213c39
Davit Barbakadze jayarjo authored
2  .gitignore
View
@@ -1,10 +1,12 @@
js
examples/uploads/*
tmp
+libs
jslint.xml
.settings
.project
docs
+wiki
jscoverage
*~
*.diff
11 Jakefile.js
View
@@ -9,6 +9,8 @@ var yuidoc = tools.yuidoc;
var jshint = tools.jshint;
var zip = tools.zip;
+var wiki = require('./build/wiki');
+
function exit(message) {
if (message) {
console.info(message);
@@ -91,7 +93,14 @@ task("minifyjs", ["moxie"], function (params) {
desc("Generate documentation using YUIDoc");
task("yuidoc", [], function (params) {
- yuidoc("src", "docs");
+ yuidoc("src", "docs", {
+ norecurse: true
+ });
+});
+
+desc("Generate wiki pages");
+task("wiki", [], function() {
+ wiki("git@github.com:moxiecode/plupload.wiki.git", "wiki", "docs");
});
desc("Runs JSHint on source files");
78 build/utils.js
View
@@ -0,0 +1,78 @@
+
+var extend = function(target) {
+ each(arguments, function(arg, i) {
+ if (i > 0) {
+ each(arg, function(value, key) {
+ if (value !== undefined) {
+ if (typeof(target[key]) === 'object' && typeof(value) === 'object') { // arrays also count
+ extend(target[key], value);
+ } else {
+ target[key] = value;
+ }
+ }
+ });
+ }
+ });
+ return target;
+};
+
+var each = function(obj, callback) {
+ var length, key, i;
+
+ if (obj) {
+ try {
+ length = obj.length;
+ } catch(ex) {
+ length = undefined;
+ }
+
+ if (length === undefined) {
+ // Loop object items
+ for (key in obj) {
+ if (obj.hasOwnProperty(key)) {
+ if (callback(obj[key], key) === false) {
+ return;
+ }
+ }
+ }
+ } else {
+ // Loop array items
+ for (i = 0; i < length; i++) {
+ if (callback(obj[i], i) === false) {
+ return;
+ }
+ }
+ }
+ }
+};
+
+var inSeries = function(queue, cb) {
+ var i = 0, length = queue.length;
+
+ if (typeof(cb) !== 'function') {
+ cb = function() {};
+ }
+
+ function callNext(i) {
+ if (typeof(queue[i]) === 'function') {
+ queue[i](function(error) {
+ ++i < length && !error ? callNext(i) : cb(error);
+ });
+ }
+ }
+ callNext(i);
+};
+
+var color = function(s,c){return (color[c].toLowerCase()||'')+ s + color.reset;};
+color.reset = '\033[39m';
+color.red = '\033[31m';
+color.yellow = '\033[33m';
+color.green = '\033[32m';
+
+
+module.exports = {
+ extend: extend,
+ each: each,
+ inSeries: inSeries,
+ color: color
+};
186 build/wiki.js
View
@@ -0,0 +1,186 @@
+var fs = require("fs");
+var utils = require("./utils");
+
+var wiki = function(githubRepo, dir, YUIDocDir) {
+
+ function parseYUIDoc() {
+ var types = {
+ method: "## Methods\n\n",
+ property: "## Properties\n\n",
+ event: "## Events\n\n"
+ };
+
+ var formatArguments = function(args, level) {
+ var result = !level ? "\n__Arguments__\n\n" : "";
+
+ level = level || 0;
+
+ utils.each(args, function(param) {
+ var name;
+ if (param.type) {
+ if (param.optional) {
+ name = param.optdefault ? "[" + param.name + "=" + param.optdefault + "]" : "[" + param.name + "]";
+ } else {
+ name = param.name;
+ }
+ // indent level times
+ for (var i = 0; i < level; i++) {
+ result += "\t";
+ }
+ // put it together finally
+ result += "* **" + name + "** _(" + param.type.replace(/\|/g, '/') + ")_ " + param.description + "\n";
+
+ // if param has sub-properties
+ if (param.props) {
+ result += formatArguments(param.props, level + 1);
+ }
+ }
+ });
+ return result;
+ };
+
+
+ var formatItem = function(item) {
+ var delimiter = '\n---------------------------------------\n\n'
+ , codeUrl = "/" + githubRepo.replace(/^[\s\S]+?github\.com[:\/]([\s\S]+?)\.wiki[\s\S]+$/, '$1') + "/blob/master/"
+ , title = item.is_constructor ? '# '+item.name : '<a name="'+item.name+'" />\n### '+item.name
+ , line = '_Defined at: ['+item.file+':'+item.line+']('+codeUrl+item.file+'#L'+item.line+')_\n\n\n'
+ , description = item.description + "\n"
+ ;
+
+ // add arguments listing if item is method
+ if (('method' === item.itemtype || item.is_constructor) && item.params) {
+ var titleArgs = [];
+ var args = "\n__Arguments__\n\n";
+ utils.each(item.params, function(param) {
+ var name;
+ if (param.type) {
+ if (param.optional) {
+ name = param.optdefault ? "[" + param.name + "=" + param.optdefault + "]" : "[" + param.name + "]";
+ } else {
+ name = param.name;
+ }
+ titleArgs.push(name);
+ args += "* **" + name + "** _(" + param.type.replace(/\|/g, '/') + ")_ " + param.description + "\n";
+
+ // append sub-properties if any
+ if (param.props) {
+ args += formatArguments(param.props, 1);
+ }
+ }
+ });
+ // add arguments
+ title += "(" + (titleArgs.length ? titleArgs.join(", ") : "") + ")";
+ description += args;
+ }
+
+ // add example
+ if (item.example) {
+ description += "\n__Examples__\n\n"
+ utils.each(item.example, function(example) {
+ var type = /<\w+>/.test(example) ? 'html' : 'javascript';
+ description += "```" + type + example.replace(/^\xA0+/, '') + "\n```\n";
+ });
+ }
+
+ return title + "\n" + line + description + (!item.is_constructor ? delimiter : '\n');
+ };
+
+ if (!fs.existsSync(dir) || !fs.existsSync(YUIDocDir + "/data.json")) {
+ console.info(YUIDocDir + "/data.json cannot be found.");
+ process.exit(1);
+ }
+
+ var data = fs.readFileSync(YUIDocDir + "/data.json").toString();
+ if (data == '') {
+ console.info(YUIDocDir + "/data.json seems to be empty.");
+ process.exit(1);
+ }
+
+ // read YUIDoc exported data in json
+ data = eval("("+data+")");
+
+ // Clear previous versions
+ var apiDir = dir + "/API";
+ if (fs.existsSync(apiDir)) {
+ jake.rmRf(apiDir);
+ }
+ fs.mkdirSync(apiDir, 0755);
+
+
+ // generate TOC page
+ var toc = '## Table of Contents\n\n';
+ utils.each(data.classes, function(item) {
+ if (!item.access || item.access == 'public') {
+ toc += "* [[" + item.name + "|" + item.name + "]]\n";
+ }
+ });
+ fs.writeFileSync(apiDir + "/" + "API.md", toc);
+
+ // generate pages
+ var pages = {};
+ utils.each(data.classitems, function(item) {
+ var className, page;
+
+ // bypass private and protected
+ if (item.access && item.access != 'public') {
+ return true;
+ }
+
+ if (!~['method', 'property', 'event'].indexOf(item.itemtype)) {
+ return true;
+ }
+
+ className = item.class;
+
+ if (!pages[className]) {
+ pages[className] = utils.extend({}, data.classes[className], {
+ toc: {
+ property: "",
+ method: "",
+ event: ""
+ },
+ content: {
+ property: "",
+ method: "",
+ event: ""
+ }
+ });
+ }
+ page = pages[className];
+
+ // put a link in the TOC
+ page.toc[item.itemtype] += "* [%name%](#%name%)".replace(/%name%/g, item.name) + "\n";
+
+ page.content[item.itemtype] += formatItem(item);
+ });
+
+ utils.each(pages, function(page, name) {
+ var toc = "", body = "", header = "";
+
+ header += formatItem(page);
+
+ utils.each(["property", "method", "event"], function(type) {
+ if (page.toc[type] != "") {
+ toc += types[type] + page.toc[type] + "\n";
+ }
+
+ if (page.content[type] != "") {
+ body += types[type] + page.content[type] + "\n";
+ }
+ });
+
+ fs.writeFileSync(apiDir + "/" + name + ".md", header + toc + body);
+ });
+ }
+
+ if (!fs.existsSync(dir)) {
+ exec("git clone " + githubRepo + " ./" + dir, function(error, stdout, stderr) {
+ parseYUIDoc();
+ });
+ } else {
+ parseYUIDoc();
+ }
+};
+
+module.exports = wiki;
293 src/plupload.js
View
@@ -1,10 +1,19 @@
;(function(window, o, undef) {
var delay = window.setTimeout;
-
+
+/**
+ * @module plupload
+ * @static
+ */
var plupload = {
/**
* Plupload version will be replaced on build.
+ *
+ * @property VERSION
+ * @for Plupload
+ * @static
+ * @final
*/
VERSION : '@@version@@',
@@ -12,6 +21,7 @@ var plupload = {
* Inital state of the queue and also the state ones it's finished all it's uploads.
*
* @property STOPPED
+ * @static
* @final
*/
STOPPED : 1,
@@ -20,6 +30,7 @@ var plupload = {
* Upload process is running
*
* @property STARTED
+ * @static
* @final
*/
STARTED : 2,
@@ -28,6 +39,7 @@ var plupload = {
* File is queued for upload
*
* @property QUEUED
+ * @static
* @final
*/
QUEUED : 1,
@@ -36,6 +48,7 @@ var plupload = {
* File is being uploaded
*
* @property UPLOADING
+ * @static
* @final
*/
UPLOADING : 2,
@@ -44,6 +57,7 @@ var plupload = {
* File has failed to be uploaded
*
* @property FAILED
+ * @static
* @final
*/
FAILED : 4,
@@ -52,6 +66,7 @@ var plupload = {
* File has been uploaded successfully
*
* @property DONE
+ * @static
* @final
*/
DONE : 5,
@@ -62,6 +77,7 @@ var plupload = {
* Generic error for example if an exception is thrown inside Silverlight.
*
* @property GENERIC_ERROR
+ * @static
* @final
*/
GENERIC_ERROR : -100,
@@ -70,6 +86,7 @@ var plupload = {
* HTTP transport error. For example if the server produces a HTTP status other than 200.
*
* @property HTTP_ERROR
+ * @static
* @final
*/
HTTP_ERROR : -200,
@@ -78,6 +95,7 @@ var plupload = {
* Generic I/O error. For exampe if it wasn't possible to open the file stream on local machine.
*
* @property IO_ERROR
+ * @static
* @final
*/
IO_ERROR : -300,
@@ -86,6 +104,7 @@ var plupload = {
* Generic I/O error. For exampe if it wasn't possible to open the file stream on local machine.
*
* @property SECURITY_ERROR
+ * @static
* @final
*/
SECURITY_ERROR : -400,
@@ -94,6 +113,7 @@ var plupload = {
* Initialization error. Will be triggered if no runtime was initialized.
*
* @property INIT_ERROR
+ * @static
* @final
*/
INIT_ERROR : -500,
@@ -102,6 +122,7 @@ var plupload = {
* File size error. If the user selects a file that is too large it will be blocked and an error of this type will be triggered.
*
* @property FILE_SIZE_ERROR
+ * @static
* @final
*/
FILE_SIZE_ERROR : -600,
@@ -110,6 +131,7 @@ var plupload = {
* File extension error. If the user selects a file that isn't valid according to the filters setting.
*
* @property FILE_EXTENSION_ERROR
+ * @static
* @final
*/
FILE_EXTENSION_ERROR : -601,
@@ -118,6 +140,7 @@ var plupload = {
* Runtime will try to detect if image is proper one. Otherwise will throw this error.
*
* @property IMAGE_FORMAT_ERROR
+ * @static
* @final
*/
IMAGE_FORMAT_ERROR : -700,
@@ -126,6 +149,7 @@ var plupload = {
* While working on the image runtime will try to detect if the operation may potentially run out of memeory and will throw this error.
*
* @property IMAGE_MEMORY_ERROR
+ * @static
* @final
*/
IMAGE_MEMORY_ERROR : -701,
@@ -134,6 +158,7 @@ var plupload = {
* Each runtime has an upper limit on a dimension of the image it can handle. If bigger, will throw this error.
*
* @property IMAGE_DIMENSIONS_ERROR
+ * @static
* @final
*/
IMAGE_DIMENSIONS_ERROR : -702,
@@ -381,8 +406,6 @@ var plupload = {
return url;
},
-
-
/**
* Formats the specified number as a size string for example 1024 becomes 1 KB.
*
@@ -414,7 +437,6 @@ var plupload = {
},
-
/**
* Parses the specified size string into a byte value. For example 10kb becomes 10240.
*
@@ -426,7 +448,128 @@ var plupload = {
};
+/**
+ *
+ * @class Uploader
+ * @constructor
+ */
plupload.Uploader = function(settings) {
+ /**
+ * Fires when the current RunTime has been initialized.
+ *
+ * @event Init
+ * @param {plupload.Uploader} uploader Uploader instance sending the event.
+ */
+
+ /**
+ * Fires after the init event incase you need to perform actions there.
+ *
+ * @event PostInit
+ * @param {plupload.Uploader} uploader Uploader instance sending the event.
+ */
+
+ /**
+ * Fires when the silverlight/flash or other shim needs to move.
+ *
+ * @event Refresh
+ * @param {plupload.Uploader} uploader Uploader instance sending the event.
+ */
+
+ /**
+ * Fires when the overall state is being changed for the upload queue.
+ *
+ * @event StateChanged
+ * @param {plupload.Uploader} uploader Uploader instance sending the event.
+ */
+
+ /**
+ * Fires when a file is to be uploaded by the runtime.
+ *
+ * @event UploadFile
+ * @param {plupload.Uploader} uploader Uploader instance sending the event.
+ * @param {plupload.File} file File to be uploaded.
+ */
+
+ /**
+ * Fires when just before a file is uploaded. This event enables you to override settings
+ * on the uploader instance before the file is uploaded.
+ *
+ * @event BeforeUpload
+ * @param {plupload.Uploader} uploader Uploader instance sending the event.
+ * @param {plupload.File} file File to be uploaded.
+ */
+
+ /**
+ * Fires when the file queue is changed. In other words when files are added/removed to the files array of the uploader instance.
+ *
+ * @event QueueChanged
+ * @param {plupload.Uploader} uploader Uploader instance sending the event.
+ */
+
+ /**
+ * Fires while a file is being uploaded. Use this event to update the current file upload progress.
+ *
+ * @event UploadProgress
+ * @param {plupload.Uploader} uploader Uploader instance sending the event.
+ * @param {plupload.File} file File that is currently being uploaded.
+ */
+
+ /**
+ * Fires while a file was removed from queue.
+ *
+ * @event FilesRemoved
+ * @param {plupload.Uploader} uploader Uploader instance sending the event.
+ * @param {Array} files Array of files that got removed.
+ */
+
+ /**
+ * Fires while when the user selects files to upload.
+ *
+ * @event FilesAdded
+ * @param {plupload.Uploader} uploader Uploader instance sending the event.
+ * @param {Array} files Array of file objects that was added to queue/selected by the user.
+ */
+
+ /**
+ * Fires when a file is successfully uploaded.
+ *
+ * @event FileUploaded
+ * @param {plupload.Uploader} uploader Uploader instance sending the event.
+ * @param {plupload.File} file File that was uploaded.
+ * @param {Object} response Object with response properties.
+ */
+
+ /**
+ * Fires when file chunk is uploaded.
+ *
+ * @event ChunkUploaded
+ * @param {plupload.Uploader} uploader Uploader instance sending the event.
+ * @param {plupload.File} file File that the chunk was uploaded for.
+ * @param {Object} response Object with response properties.
+ */
+
+ /**
+ * Fires when all files in a queue are uploaded.
+ *
+ * @event UploadComplete
+ * @param {plupload.Uploader} uploader Uploader instance sending the event.
+ * @param {Array} files Array of file objects that was added to queue/selected by the user.
+ */
+
+ /**
+ * Fires when a error occurs.
+ *
+ * @event Error
+ * @param {plupload.Uploader} uploader Uploader instance sending the event.
+ * @param {Object} error Contains code, message and sometimes file and other details.
+ */
+
+ /**
+ * Fires when destroy method is called.
+ *
+ * @event Destroy
+ * @param {plupload.Uploader} uploader Uploader instance sending the event.
+ */
var files = [], events = {}, required_features = [], required_caps = {}, feature2cap = {},
startTime, total, disabled = false,
fileInput, fileDrop, xhr;
@@ -1334,142 +1477,18 @@ plupload.Uploader = function(settings) {
// Clean-up after uploader itself
this.unbindAll();
}
-
- /**
- * Fires when the current RunTime has been initialized.
- *
- * @event Init
- * @param {plupload.Uploader} uploader Uploader instance sending the event.
- */
-
- /**
- * Fires after the init event incase you need to perform actions there.
- *
- * @event PostInit
- * @param {plupload.Uploader} uploader Uploader instance sending the event.
- */
-
- /**
- * Fires when the silverlight/flash or other shim needs to move.
- *
- * @event Refresh
- * @param {plupload.Uploader} uploader Uploader instance sending the event.
- */
-
- /**
- * Fires when the overall state is being changed for the upload queue.
- *
- * @event StateChanged
- * @param {plupload.Uploader} uploader Uploader instance sending the event.
- */
-
- /**
- * Fires when a file is to be uploaded by the runtime.
- *
- * @event UploadFile
- * @param {plupload.Uploader} uploader Uploader instance sending the event.
- * @param {plupload.File} file File to be uploaded.
- */
-
- /**
- * Fires when just before a file is uploaded. This event enables you to override settings
- * on the uploader instance before the file is uploaded.
- *
- * @event BeforeUpload
- * @param {plupload.Uploader} uploader Uploader instance sending the event.
- * @param {plupload.File} file File to be uploaded.
- */
-
- /**
- * Fires when the file queue is changed. In other words when files are added/removed to the files array of the uploader instance.
- *
- * @event QueueChanged
- * @param {plupload.Uploader} uploader Uploader instance sending the event.
- */
-
- /**
- * Fires while a file is being uploaded. Use this event to update the current file upload progress.
- *
- * @event UploadProgress
- * @param {plupload.Uploader} uploader Uploader instance sending the event.
- * @param {plupload.File} file File that is currently being uploaded.
- */
-
- /**
- * Fires while a file was removed from queue.
- *
- * @event FilesRemoved
- * @param {plupload.Uploader} uploader Uploader instance sending the event.
- * @param {Array} files Array of files that got removed.
- */
-
- /**
- * Fires while when the user selects files to upload.
- *
- * @event FilesAdded
- * @param {plupload.Uploader} uploader Uploader instance sending the event.
- * @param {Array} files Array of file objects that was added to queue/selected by the user.
- */
-
- /**
- * Fires when a file is successfully uploaded.
- *
- * @event FileUploaded
- * @param {plupload.Uploader} uploader Uploader instance sending the event.
- * @param {plupload.File} file File that was uploaded.
- * @param {Object} response Object with response properties.
- */
-
- /**
- * Fires when file chunk is uploaded.
- *
- * @event ChunkUploaded
- * @param {plupload.Uploader} uploader Uploader instance sending the event.
- * @param {plupload.File} file File that the chunk was uploaded for.
- * @param {Object} response Object with response properties.
- */
-
- /**
- * Fires when all files in a queue are uploaded.
- *
- * @event UploadComplete
- * @param {plupload.Uploader} uploader Uploader instance sending the event.
- * @param {Array} files Array of file objects that was added to queue/selected by the user.
- */
-
- /**
- * Fires when a error occurs.
- *
- * @event Error
- * @param {plupload.Uploader} uploader Uploader instance sending the event.
- * @param {Object} error Contains code, message and sometimes file and other details.
- */
-
- /**
- * Fires when destroy method is called.
- *
- * @event Destroy
- * @param {plupload.Uploader} uploader Uploader instance sending the event.
- */
});
};
/**
- * File instance.
- *
- * @class plupload.File
- * @param {String} name Name of the file.
- * @param {Number} size File size.
- */
-
-/**
* Constructs a new file instance.
*
+ * @class File
* @constructor
- * @method File
- * @param {String} id Unique file id.
- * @param {String} name File name.
- * @param {Number} size File size in bytes.
+ *
+ * @param {Object} file Object containing file properties
+ * @param {String} file.name Name of the file.
+ * @param {Number} file.size File size.
*/
plupload.File = (function() {
var filepool = {};
@@ -1552,16 +1571,10 @@ plupload.File = (function() {
/**
- * Runtime class gets implemented by each upload runtime.
- *
- * @class plupload.QueueProgress
- */
-
-/**
* Constructs a queue progress.
*
+ * @class QueueProgress
* @constructor
- * @method QueueProgress
*/
plupload.QueueProgress = function() {
var self = this; // Setup alias for self to reduce code size when it's compressed
Please sign in to comment.
Something went wrong with that request. Please try again.