Skip to content

Commit

Permalink
issue #44 fileuploader specific changes made in inheriting class
Browse files Browse the repository at this point in the history
  • Loading branch information
akate committed Aug 7, 2011
1 parent 50fc55f commit 8d74485
Show file tree
Hide file tree
Showing 5 changed files with 238 additions and 65 deletions.
1 change: 1 addition & 0 deletions lib/exe/js.php
Expand Up @@ -44,6 +44,7 @@ function js_out(){
DOKU_INC.'lib/scripts/jquery/jquery.cookie.js',
DOKU_INC."lib/scripts/jquery/jquery-ui$min.js",
DOKU_INC."lib/scripts/fileuploader.js",
DOKU_INC."lib/scripts/fileuploaderextended.js",
DOKU_INC.'lib/scripts/helpers.js',
DOKU_INC.'lib/scripts/events.js',
DOKU_INC.'lib/scripts/delay.js',
Expand Down
64 changes: 3 additions & 61 deletions lib/scripts/fileuploader.js
Expand Up @@ -267,7 +267,6 @@ qq.FileUploaderBasic = function(o){
onProgress: function(id, fileName, loaded, total){},
onComplete: function(id, fileName, responseJSON){},
onCancel: function(id, fileName){},
onUpload: function(){},
// messages
messages: {
typeError: "{file} has invalid extension. Only {extensions} are allowed.",
Expand Down Expand Up @@ -336,9 +335,6 @@ qq.FileUploaderBasic.prototype = {
onCancel: function(id, fileName){
self._onCancel(id, fileName);
self._options.onCancel(id, fileName);
},
onUpload: function(){
self._onUpload();
}
});

Expand Down Expand Up @@ -371,9 +367,6 @@ qq.FileUploaderBasic.prototype = {
_onCancel: function(id, fileName){
this._filesInProgress--;
},
_onUpload: function(){
this._handler.uploadAll(this._options.params);
},
_onInputChange: function(input){
if (this._handler instanceof qq.UploadHandlerXhr){
this._uploadFileList(input.files);
Expand Down Expand Up @@ -401,6 +394,7 @@ qq.FileUploaderBasic.prototype = {

if (this._options.onSubmit(id, fileName) !== false){
this._onSubmit(id, fileName);
this._handler.upload(id, this._options.params);
}
},
_validateFile: function(file){
Expand Down Expand Up @@ -494,13 +488,11 @@ qq.FileUploader = function(o){
'<div class="qq-upload-drop-area"><span>Drop files here to upload</span></div>' +
'<div class="qq-upload-button">Upload a file</div>' +
'<ul class="qq-upload-list"></ul>' +
'<input class="button" type="submit" value="Upload" id="mediamanager__upload_button">' +
'</div>',

// template for one item in file list
fileTemplate: '<li>' +
'<span class="qq-upload-file"></span>' +
'<label><span>Upload as (optional):</span><input class="qq-upload-name-input" type="text"></label>' +
'<span class="qq-upload-spinner"></span>' +
'<span class="qq-upload-size"></span>' +
'<a class="qq-upload-cancel" href="#">Cancel</a>' +
Expand All @@ -513,9 +505,8 @@ qq.FileUploader = function(o){
drop: 'qq-upload-drop-area',
dropActive: 'qq-upload-drop-area-active',
list: 'qq-upload-list',
nameInput: 'qq-upload-name-input',
file: 'qq-upload-file',

file: 'qq-upload-file',
spinner: 'qq-upload-spinner',
size: 'qq-upload-size',
cancel: 'qq-upload-cancel',
Expand All @@ -538,7 +529,6 @@ qq.FileUploader = function(o){
this._button = this._createUploadButton(this._find(this._element, 'button'));

this._bindCancelEvent();
this._bindUploadEvent();
this._setupDragDrop();
};

Expand Down Expand Up @@ -639,10 +629,6 @@ qq.extend(qq.FileUploader.prototype, {
qq.setText(fileElement, this._formatFileName(fileName));
this._find(item, 'size').style.display = 'none';

var nameElement = this._find(item, 'nameInput');
nameElement.value = this._formatFileName(fileName);
nameElement.id = id;

this._listElement.appendChild(item);
},
_getItemByFileId: function(id){
Expand Down Expand Up @@ -674,19 +660,6 @@ qq.extend(qq.FileUploader.prototype, {
qq.remove(item);
}
});
},

_bindUploadEvent: function(){
var self = this,
list = this._listElement;

qq.attach(document.getElementById('mediamanager__upload_button'), 'click', function(e){
e = e || window.event;
var target = e.target || e.srcElement;
qq.preventDefault(e);
self._handler._options.onUpload();

});
}
});

Expand Down Expand Up @@ -904,10 +877,6 @@ qq.UploadHandlerAbstract.prototype = {
* @returns id
**/
add: function(file){},

uploadAll: function(params){
this._uploadAll(params);
},
/**
* Sends the file identified by id and additional query params to the server
*/
Expand Down Expand Up @@ -958,8 +927,6 @@ qq.UploadHandlerAbstract.prototype = {
* Actual upload method
*/
_upload: function(id){},

_uploadAll: function(params){},
/**
* Actual cancel method
*/
Expand Down Expand Up @@ -1059,12 +1026,6 @@ qq.extend(qq.UploadHandlerForm.prototype, {

return id;
},
_uploadAll: function(params){
for (key in this._inputs) {
this.upload(key, params);
}

},
_attachLoadEvent: function(iframe, callback){
qq.attach(iframe, 'load', function(){
// when we remove iframe from dom
Expand Down Expand Up @@ -1192,21 +1153,10 @@ qq.extend(qq.UploadHandlerXhr.prototype, {
getName: function(id){
var file = this._files[id];
// fix missing name in Safari 4
var name = document.getElementById(id);
if (name != null) {
return name.value;
} else {
if (file != null) {
// fix missing name in Safari 4
return file.fileName != null ? file.fileName : file.name;
} else {
return null;
}
}
return file.fileName != null ? file.fileName : file.name;
},
getSize: function(id){
var file = this._files[id];
if (file == null) return null;
return file.fileSize != null ? file.fileSize : file.size;
},
/**
Expand All @@ -1223,7 +1173,6 @@ qq.extend(qq.UploadHandlerXhr.prototype, {
var file = this._files[id],
name = this.getName(id),
size = this.getSize(id);
if (name == null || size == null) return;

this._loaded[id] = 0;

Expand Down Expand Up @@ -1254,13 +1203,6 @@ qq.extend(qq.UploadHandlerXhr.prototype, {
xhr.setRequestHeader("Content-Type", "application/octet-stream");
xhr.send(file);
},

_uploadAll: function(params){
for (key in this._files) {
this.upload(key, params);
}

},
_onComplete: function(id, xhr){
// the request was aborted/cancelled
if (!this._files[id]) return;
Expand Down

0 comments on commit 8d74485

Please sign in to comment.