diff --git a/javascript/CMSMain_upload.js b/javascript/CMSMain_upload.js
index 642f5a4d..d2d59589 100644
--- a/javascript/CMSMain_upload.js
+++ b/javascript/CMSMain_upload.js
@@ -5,173 +5,173 @@
*/
CMSMain_upload = Class.create();
CMSMain_upload.prototype = {
- initialize: function() {
+ initialize: function() {
// This is disabled until we get it working reliably
return;
// We require flash 9
- pv = getFlashPlayerVersion();
+ pv = getFlashPlayerVersion();
if(pv.major < 9) return;
-
- // Due to a bug in the flash plugin on Linux and Mac, we need at least version 9.0.64 to use SWFUpload
- if(navigator.appVersion.indexOf("Mac") != -1 || navigator.appVersion.indexOf("X11") != -1 || navigator.appVersion.indexOf("Linux") != -1) {
- if(pv.major == 9 && pv.minor == 0 && pv.rev < 64) return;
- }
+
+ // Due to a bug in the flash plugin on Linux and Mac, we need at least version 9.0.64 to use SWFUpload
+ if(navigator.appVersion.indexOf("Mac") != -1 || navigator.appVersion.indexOf("X11") != -1 || navigator.appVersion.indexOf("Linux") != -1) {
+ if(pv.major == 9 && pv.minor == 0 && pv.rev < 64) return;
+ }
// If those 2 checks pass, we can provide upload capabilities to the user
- this.iframe = window.top.document.getElementById('AssetAdmin_upload');
- this.onLoad();
- },
+ this.iframe = window.top.document.getElementById('AssetAdmin_upload');
+ this.onLoad();
+ },
- onLoad: function() {
- this.upload = new Upload({
- fileUploadLimit : '6',
- securityID : $('SecurityID').value,
- beginUploadOnQueue : false,
- fileQueued : this.uploadFileQueuedCallback.bind(this),
- fileProgress : this.uploadProgressCallback.bind(this),
- fileCancelled : this.uploadFileCancelCallback.bind(this),
- fileComplete : this.uploadFileCompleteCallback.bind(this),
- queueComplete : this.uploadQueueCompleteCallback.bind(this),
- buildUI : this.extendForm.bind(this)
- });
- },
-
- /**
- * Builds UI, called only when Upload object will be able to create flash uploader.
- */
-
- extendForm: function() {
- if(this.iframe.contentDocument == undefined) this.iframe.contentDocument = document.frames[0].document;//IE HACK
- element = this.iframe.contentDocument.getElementById('Form_UploadForm');
- inputFile = this.iframe.contentDocument.getElementById('Form_UploadForm_Files-0');
- inputFileParent = inputFile.parentNode;
- inputFileParent.removeChild(inputFile);
- inputFile = this.iframe.contentDocument.createElement('input');
- inputFile.type = 'text';
- inputFile.id = 'Form_UploadForm_Files-0';
- inputFileParent.appendChild(inputFile);
- inputButton = this.iframe.contentDocument.getElementById('Form_UploadForm_Files-1');
- if(inputButton != null) inputButton.parentNode.removeChild(inputButton);
- inputButton = this.iframe.contentDocument.createElement('input');
- inputButton.type = 'button';
- inputButton.id = 'Form_UploadForm_Files-1';
- inputButton.value = ' Browse...';
- inputButton.style.width = '66px';
- inputButton.style.height = '19px';
- inputButton.style.position = 'relative';
- inputButton.style.top = '1px';
- inputButton.style.fontFamily = 'Arial';
- inputButton.style.fontSize = '1.06em';
- inputFileParent.appendChild(inputButton);
- Event.observe(inputButton,'click',this.onBrowseClick.bind(this));
- Event.observe(this.iframe.contentDocument.getElementById('Form_UploadForm_action_upload'),'click',this.onUploadClick.bind(this));
- },
-
- onBrowseClick: function(event) {
- this.upload.browse();
- },
-
- onUploadClick: function(event) {
- Event.stop(event);
- this.upload.startUpload();
- },
-
- uploadFileQueuedCallback: function(file,queueLength) {
- this.upload.setFolderID(this.iframe.contentDocument.getElementById('Form_UploadForm_ID').value);
- this.iframe.contentDocument.getElementById('Form_UploadForm_action_upload').disabled = false;
- var fileContainer = this.iframe.contentDocument.getElementById('Form_UploadForm_FilesList');
- if(fileContainer == null) {
- fileContainer = this.iframe.contentDocument.createElement('div');
- fileContainer.id = 'Form_UploadForm_FilesList';
- this.iframe.contentDocument.getElementById('Form_UploadForm').appendChild(fileContainer);
- }
-
- var fileToUpload = this.iframe.contentDocument.createElement('div');
- fileToUpload.id = 'Form_UploadForm_FilesList_' + file.id;
- fileToUpload.style.marginBottom = '3px';
- fileContainer.appendChild(fileToUpload);
-
- var fileName = this.iframe.contentDocument.createElement('div');
- fileName.id = 'Form_UploadForm_FilesList_Name_' + file.id;
- fileName.style.position = 'relative';
- fileName.style.top = '-4px';
- fileName.style.display = 'inline';
- fileName.style.padding = '2px';
- fileName.innerHTML = file.name;
- fileName.style.height = Element.getDimensions(fileName).height + 1 + 'px';//IE hack
- fileToUpload.appendChild(fileName);
-
- var fileProgress = this.iframe.contentDocument.createElement('div');
- fileProgress.id = 'Form_UploadForm_FilesList_Progress_' + file.id;
- Position.clone(fileName,fileProgress);
- fileProgress.style.backgroundColor = 'black';
- fileProgress.style.display = 'inline';
- fileProgress.style.position = 'absolute';
- fileProgress.style.left = '5px';
- fileProgress.style.width = '0px';
- fileProgress.finished = false;
- fileProgress.style.top = parseInt(fileProgress.style.top) + 6 + 'px';
- fileProgress.style.height = Element.getDimensions(fileName).height + 1 + 'px';
- fileToUpload.appendChild(fileProgress);
-
- var fileDelete = this.iframe.contentDocument.createElement('input');
- fileDelete.id = file.id;
- fileDelete.type = 'button';
- fileDelete.value = 'Delete';
- Element.addClassName(fileDelete,'delete');
- fileToUpload.appendChild(fileDelete);
- Event.observe(fileDelete,'click',this.uploadFileCancelCallback.bind(this));
- },
-
- uploadProgressCallback: function(file,bytesLoaded) {
- fileName = this.iframe.contentDocument.getElementById('Form_UploadForm_FilesList_Name_' + file.id);
- fileName.style.border = 'solid 1px black';
- fileProgress = this.iframe.contentDocument.getElementById('Form_UploadForm_FilesList_Progress_' + file.id);
- fileProgress.style.opacity = 0.3;fileProgress.style.filter = 'alpha(opacity=30)';
- if(!fileProgress.cloned) {
- Position.clone(fileName,fileProgress);
- fileProgress.style.width = '0px';
- fileProgress.cloned = true;
- }
- fileProgress.style.width = (bytesLoaded / file.size) * Element.getDimensions(fileName).width - 1 + 'px';
- },
-
- uploadFileCompleteCallback: function(file,serverData) {
- this.iframe.contentDocument.getElementById('Form_UploadForm_FilesList_Progress_' + file.id).finished = true;
- },
-
- uploadFileCancelCallback: function(event) {
- element = Event.element(event);
- fileId = element.id;
- fileContainer = this.iframe.contentDocument.getElementById('Form_UploadForm_FilesList');
- elementToDelete = this.iframe.contentDocument.getElementById('Form_UploadForm_FilesList_' + fileId);
- elementToDelete.parentNode.removeChild(elementToDelete);
- filesToUpload = fileContainer.childNodes.length;
- if(filesToUpload > 0) {
- this.iframe.contentDocument.getElementById('Form_UploadForm_action_upload').disabled = false;
- } else {
- this.iframe.contentDocument.getElementById('Form_UploadForm_action_upload').disabled = true;
- }
- $A(fileContainer.childNodes).each(
- function(item) {
- $A(item.childNodes).each(
- function(item) {
- if(item.id.indexOf('Name') != -1) {
- fileName = item;
- }
- if(item.id.indexOf('Progress') != -1) {
- fileProgress = item;
- }
- });
- Position.clone(fileName,fileProgress);
- if(fileProgress.finished == false) fileProgress.style.width = '0px';
- }
- );
- },
-
- uploadQueueCompleteCallback: function() {
- eval(this.upload.getUploadMessage().replace(/Uploaded 1 files/g,'Uploaded ' + this.upload.getFilesUploaded() + ' files'));
- }
+ onLoad: function() {
+ this.upload = new Upload({
+ fileUploadLimit : '6',
+ securityID : $('SecurityID').value,
+ beginUploadOnQueue : false,
+ fileQueued : this.uploadFileQueuedCallback.bind(this),
+ fileProgress : this.uploadProgressCallback.bind(this),
+ fileCancelled : this.uploadFileCancelCallback.bind(this),
+ fileComplete : this.uploadFileCompleteCallback.bind(this),
+ queueComplete : this.uploadQueueCompleteCallback.bind(this),
+ buildUI : this.extendForm.bind(this)
+ });
+ },
+
+ /**
+ * Builds UI, called only when Upload object will be able to create flash uploader.
+ */
+
+ extendForm: function() {
+ if(this.iframe.contentDocument == undefined) this.iframe.contentDocument = document.frames[0].document;//IE HACK
+ element = this.iframe.contentDocument.getElementById('Form_UploadForm');
+ inputFile = this.iframe.contentDocument.getElementById('Form_UploadForm_Files-0');
+ inputFileParent = inputFile.parentNode;
+ inputFileParent.removeChild(inputFile);
+ inputFile = this.iframe.contentDocument.createElement('input');
+ inputFile.type = 'text';
+ inputFile.id = 'Form_UploadForm_Files-0';
+ inputFileParent.appendChild(inputFile);
+ inputButton = this.iframe.contentDocument.getElementById('Form_UploadForm_Files-1');
+ if(inputButton != null) inputButton.parentNode.removeChild(inputButton);
+ inputButton = this.iframe.contentDocument.createElement('input');
+ inputButton.type = 'button';
+ inputButton.id = 'Form_UploadForm_Files-1';
+ inputButton.value = ' Browse...';
+ inputButton.style.width = '66px';
+ inputButton.style.height = '19px';
+ inputButton.style.position = 'relative';
+ inputButton.style.top = '1px';
+ inputButton.style.fontFamily = 'Arial';
+ inputButton.style.fontSize = '1.06em';
+ inputFileParent.appendChild(inputButton);
+ Event.observe(inputButton,'click',this.onBrowseClick.bind(this));
+ Event.observe(this.iframe.contentDocument.getElementById('Form_UploadForm_action_upload'),'click',this.onUploadClick.bind(this));
+ },
+
+ onBrowseClick: function(event) {
+ this.upload.browse();
+ },
+
+ onUploadClick: function(event) {
+ Event.stop(event);
+ this.upload.startUpload();
+ },
+
+ uploadFileQueuedCallback: function(file,queueLength) {
+ this.upload.setFolderID(this.iframe.contentDocument.getElementById('Form_UploadForm_ID').value);
+ this.iframe.contentDocument.getElementById('Form_UploadForm_action_upload').disabled = false;
+ var fileContainer = this.iframe.contentDocument.getElementById('Form_UploadForm_FilesList');
+ if(fileContainer == null) {
+ fileContainer = this.iframe.contentDocument.createElement('div');
+ fileContainer.id = 'Form_UploadForm_FilesList';
+ this.iframe.contentDocument.getElementById('Form_UploadForm').appendChild(fileContainer);
+ }
+
+ var fileToUpload = this.iframe.contentDocument.createElement('div');
+ fileToUpload.id = 'Form_UploadForm_FilesList_' + file.id;
+ fileToUpload.style.marginBottom = '3px';
+ fileContainer.appendChild(fileToUpload);
+
+ var fileName = this.iframe.contentDocument.createElement('div');
+ fileName.id = 'Form_UploadForm_FilesList_Name_' + file.id;
+ fileName.style.position = 'relative';
+ fileName.style.top = '-4px';
+ fileName.style.display = 'inline';
+ fileName.style.padding = '2px';
+ fileName.innerHTML = file.name;
+ fileName.style.height = Element.getDimensions(fileName).height + 1 + 'px';//IE hack
+ fileToUpload.appendChild(fileName);
+
+ var fileProgress = this.iframe.contentDocument.createElement('div');
+ fileProgress.id = 'Form_UploadForm_FilesList_Progress_' + file.id;
+ Position.clone(fileName,fileProgress);
+ fileProgress.style.backgroundColor = 'black';
+ fileProgress.style.display = 'inline';
+ fileProgress.style.position = 'absolute';
+ fileProgress.style.left = '5px';
+ fileProgress.style.width = '0px';
+ fileProgress.finished = false;
+ fileProgress.style.top = parseInt(fileProgress.style.top) + 6 + 'px';
+ fileProgress.style.height = Element.getDimensions(fileName).height + 1 + 'px';
+ fileToUpload.appendChild(fileProgress);
+
+ var fileDelete = this.iframe.contentDocument.createElement('input');
+ fileDelete.id = file.id;
+ fileDelete.type = 'button';
+ fileDelete.value = 'Delete';
+ Element.addClassName(fileDelete,'delete');
+ fileToUpload.appendChild(fileDelete);
+ Event.observe(fileDelete,'click',this.uploadFileCancelCallback.bind(this));
+ },
+
+ uploadProgressCallback: function(file,bytesLoaded) {
+ fileName = this.iframe.contentDocument.getElementById('Form_UploadForm_FilesList_Name_' + file.id);
+ fileName.style.border = 'solid 1px black';
+ fileProgress = this.iframe.contentDocument.getElementById('Form_UploadForm_FilesList_Progress_' + file.id);
+ fileProgress.style.opacity = 0.3;fileProgress.style.filter = 'alpha(opacity=30)';
+ if(!fileProgress.cloned) {
+ Position.clone(fileName,fileProgress);
+ fileProgress.style.width = '0px';
+ fileProgress.cloned = true;
+ }
+ fileProgress.style.width = (bytesLoaded / file.size) * Element.getDimensions(fileName).width - 1 + 'px';
+ },
+
+ uploadFileCompleteCallback: function(file,serverData) {
+ this.iframe.contentDocument.getElementById('Form_UploadForm_FilesList_Progress_' + file.id).finished = true;
+ },
+
+ uploadFileCancelCallback: function(event) {
+ element = Event.element(event);
+ fileId = element.id;
+ fileContainer = this.iframe.contentDocument.getElementById('Form_UploadForm_FilesList');
+ elementToDelete = this.iframe.contentDocument.getElementById('Form_UploadForm_FilesList_' + fileId);
+ elementToDelete.parentNode.removeChild(elementToDelete);
+ filesToUpload = fileContainer.childNodes.length;
+ if(filesToUpload > 0) {
+ this.iframe.contentDocument.getElementById('Form_UploadForm_action_upload').disabled = false;
+ } else {
+ this.iframe.contentDocument.getElementById('Form_UploadForm_action_upload').disabled = true;
+ }
+ $A(fileContainer.childNodes).each(
+ function(item) {
+ $A(item.childNodes).each(
+ function(item) {
+ if(item.id.indexOf('Name') != -1) {
+ fileName = item;
+ }
+ if(item.id.indexOf('Progress') != -1) {
+ fileProgress = item;
+ }
+ });
+ Position.clone(fileName,fileProgress);
+ if(fileProgress.finished == false) fileProgress.style.width = '0px';
+ }
+ );
+ },
+
+ uploadQueueCompleteCallback: function() {
+ eval(this.upload.getUploadMessage().replace(/Uploaded 1 files/g,'Uploaded ' + this.upload.getFilesUploaded() + ' files'));
+ }
}
window.top.document.CMSMain_upload = CMSMain_upload;
diff --git a/javascript/TinyMCEImageEnhancement.js b/javascript/TinyMCEImageEnhancement.js
index 6f07cf53..a78d88ae 100644
--- a/javascript/TinyMCEImageEnhancement.js
+++ b/javascript/TinyMCEImageEnhancement.js
@@ -4,54 +4,54 @@
*/
TinyMCEImageEnhancement = Class.create();
TinyMCEImageEnhancement.prototype = {
- initialize: function() {
- this.filesUploaded = 0;
- this.processInProgress = false;
- Event.observe(window,'load',this.onWindowLoad.bind(this));
- },
-
- addListeners: function() {
- $('Form_EditorToolbarImageForm_FolderID').value = "";
- Event.observe($('AddFolder'),'click',this.onAddFolder.bind(this));
- Event.observe($('FolderOk'),'click',this.onFolderOk.bind(this));
- Event.observe($('FolderCancel'),'click',this.onFolderCancel.bind(this));
- Event.observe($('UploadFiles'),'click',this.onUpload.bind(this));
- },
-
- /**
- * Method creates HTML element, only reason for this method is DRY.
- */
-
- addElement: function(tag, className, parent, properties) {
- var e = document.createElement(tag);
- Element.addClassName(e,className);
- parent.appendChild(e);
- Object.extend(e,properties);
- return e;
- },
-
- onUpload: function(event) {
- Event.stop(event);
- if(!this.processInProgress) {
- if(this.getParentID() != 'root') {
- this.upload.browse();
- } else {
- statusMessage("Please choose folder","bad");
- }
- }
- },
-
- /**
- * Called when user clicks "add folder" anchor.
- */
-
- onAddFolder: function(event) {
- Event.stop(event);
- Element.hide('AddFolder');
- Element.show('NewFolderName','FolderOk','FolderCancel');
- this.applyIE6Hack();
- },
-
+ initialize: function() {
+ this.filesUploaded = 0;
+ this.processInProgress = false;
+ Event.observe(window,'load',this.onWindowLoad.bind(this));
+ },
+
+ addListeners: function() {
+ $('Form_EditorToolbarImageForm_FolderID').value = "";
+ Event.observe($('AddFolder'),'click',this.onAddFolder.bind(this));
+ Event.observe($('FolderOk'),'click',this.onFolderOk.bind(this));
+ Event.observe($('FolderCancel'),'click',this.onFolderCancel.bind(this));
+ Event.observe($('UploadFiles'),'click',this.onUpload.bind(this));
+ },
+
+ /**
+ * Method creates HTML element, only reason for this method is DRY.
+ */
+
+ addElement: function(tag, className, parent, properties) {
+ var e = document.createElement(tag);
+ Element.addClassName(e,className);
+ parent.appendChild(e);
+ Object.extend(e,properties);
+ return e;
+ },
+
+ onUpload: function(event) {
+ Event.stop(event);
+ if(!this.processInProgress) {
+ if(this.getParentID() != 'root') {
+ this.upload.browse();
+ } else {
+ statusMessage("Please choose folder","bad");
+ }
+ }
+ },
+
+ /**
+ * Called when user clicks "add folder" anchor.
+ */
+
+ onAddFolder: function(event) {
+ Event.stop(event);
+ Element.hide('AddFolder');
+ Element.show('NewFolderName','FolderOk','FolderCancel');
+ this.applyIE6Hack();
+ },
+
/**
* The user clicks the "ok" anchor link, the click event calls up
* this function which creates a new AJAX request to add a new folder
@@ -71,12 +71,12 @@ TinyMCEImageEnhancement.prototype = {
new Ajax.Request('admin/assets/addfolder', options);
},
-
+
/**
* If the "addFolderOk" function does a successful AJAX post, call this
* function. Take the folder ID that was created in "addFolderOk"
* via ajax and send data to modify that folder record.
- */
+ */
onFolderGetSuccess: function(transport) {
var folderID = transport.responseText;
@@ -94,163 +94,163 @@ TinyMCEImageEnhancement.prototype = {
this.folderID = folderID;
statusMessage('Creating new folder');
- $('TreeDropdownField_Form_EditorToolbarImageForm_FolderID').itemTree = null;
- $('TreeDropdownField_Form_EditorToolbarImageForm_FolderID').setValue(this.folderID);
- $('NewFolderName').value = '';
- Element.show('AddFolder');
- Element.hide('NewFolderName','FolderOk','FolderCancel');
- this.removeIE6Hack();
- },
-
- /**
- * If user doesn't want to add folder return to default UI.
- */
-
- onFolderCancel: function(event) {
- $('NewFolderName').value = '';
- Element.show('AddFolder');
- Element.hide('NewFolderName','FolderOk','FolderCancel');
- this.removeIE6Hack();
+ $('TreeDropdownField_Form_EditorToolbarImageForm_FolderID').itemTree = null;
+ $('TreeDropdownField_Form_EditorToolbarImageForm_FolderID').setValue(this.folderID);
+ $('NewFolderName').value = '';
+ Element.show('AddFolder');
+ Element.hide('NewFolderName','FolderOk','FolderCancel');
+ this.removeIE6Hack();
+ },
+
+ /**
+ * If user doesn't want to add folder return to default UI.
+ */
+
+ onFolderCancel: function(event) {
+ $('NewFolderName').value = '';
+ Element.show('AddFolder');
+ Element.hide('NewFolderName','FolderOk','FolderCancel');
+ this.removeIE6Hack();
Event.stop(event);
return false;
- },
-
- /**
- * Called on window.onload
- */
-
- onWindowLoad: function() {
- // Due to a bug in the flash plugin on Linux and Mac,
+ },
+
+ /**
+ * Called on window.onload
+ */
+
+ onWindowLoad: function() {
+ // Due to a bug in the flash plugin on Linux and Mac,
//we need at least version 9.0.64 to use SWFUpload
// see http://open.silverstripe.com/ticket/3023
- if(navigator.appVersion.indexOf("Mac") != -1 || navigator.appVersion.indexOf("X11") != -1 || navigator.appVersion.indexOf("Linux") != -1) {
- pv = getFlashPlayerVersion();
- if(pv.major < 9 || pv.major > 9 || (pv.major == 9 && pv.minor == 0 && pv.rev < 64)) {
- if($('AddFolderGroup')) $('AddFolderGroup').style.display = 'none';
- if($('PipeSeparator')) $('PipeSeparator').style.display = 'none';
- if($('UploadGroup')) $('UploadGroup').style.display = 'none';
- return;
- }
- }
-
- if($('FolderID') != null) {
- if($('SecurityID')) var securityid=$('SecurityID').value;
- else var securityid=null;
- this.upload = new Upload(
- {
- fileTypes : '*.jpeg;*.jpg;*.jpe;*.png;*.gif;',
- fileTypesDescription : 'Image files',
- fileUploadLimit : '100',
- securityID : securityid,
- beginUploadOnQueue : true,
- buildUI : this.addListeners.bind(this),
- fileQueued : this.uploadFileQueuedCallback.bind(this),
- fileComplete : this.uploadFileCompleteCallback.bind(this),
- queueComplete : this.uploadQueueCompleteCallback.bind(this)
- }
- );
- }
- },
-
- uploadFileQueuedCallback: function(file,queueLength) {
- this.processInProgress = true;
- this.upload.setFolderID(this.getParentID());
- $('UploadFiles').innerHTML = "Uploading ... 1/" + this.upload.getFilesToUpload();
- this.upload.startUpload();
- },
-
- uploadFileCompleteCallback: function(file,serverData) {
- Element.addClassName($('UploadFiles'),'link');//Safari hack
- $('UploadFiles').innerHTML = 'Uploading ... ' + this.upload.getFilesUploaded() + "/" + this.upload.getFilesToUpload();
- },
-
- uploadQueueCompleteCallback: function() {
- this.filesUploaded = this.upload.getFilesUploaded();
- $('UploadFiles').innerHTML = "upload";
- statusMessage('Uploaded ' + this.upload.getFilesUploaded() + ' files','good');
- if(this.getParentID() != 'root') {
- $('Image').ajaxGetFiles(this.getParentID(), null, this.insertImages.bind(this));
- }
- },
-
- /**
- * Iterates over all uploaded images and add them to TinyMCE editor
- *
- * @param transport object
- */
- insertImages: function(transport) {
- //HACK FOR STRANGE ERROR OCCURING UNDER SAFARI
- if(transport.responseText == '') {
- $('Image').ajaxGetFiles(this.getParentID(), null, this.insertImages.bind(this));
- return;
- }
- //END OF HACK
+ if(navigator.appVersion.indexOf("Mac") != -1 || navigator.appVersion.indexOf("X11") != -1 || navigator.appVersion.indexOf("Linux") != -1) {
+ pv = getFlashPlayerVersion();
+ if(pv.major < 9 || pv.major > 9 || (pv.major == 9 && pv.minor == 0 && pv.rev < 64)) {
+ if($('AddFolderGroup')) $('AddFolderGroup').style.display = 'none';
+ if($('PipeSeparator')) $('PipeSeparator').style.display = 'none';
+ if($('UploadGroup')) $('UploadGroup').style.display = 'none';
+ return;
+ }
+ }
+
+ if($('FolderID') != null) {
+ if($('SecurityID')) var securityid=$('SecurityID').value;
+ else var securityid=null;
+ this.upload = new Upload(
+ {
+ fileTypes : '*.jpeg;*.jpg;*.jpe;*.png;*.gif;',
+ fileTypesDescription : 'Image files',
+ fileUploadLimit : '100',
+ securityID : securityid,
+ beginUploadOnQueue : true,
+ buildUI : this.addListeners.bind(this),
+ fileQueued : this.uploadFileQueuedCallback.bind(this),
+ fileComplete : this.uploadFileCompleteCallback.bind(this),
+ queueComplete : this.uploadQueueCompleteCallback.bind(this)
+ }
+ );
+ }
+ },
+
+ uploadFileQueuedCallback: function(file,queueLength) {
+ this.processInProgress = true;
+ this.upload.setFolderID(this.getParentID());
+ $('UploadFiles').innerHTML = "Uploading ... 1/" + this.upload.getFilesToUpload();
+ this.upload.startUpload();
+ },
+
+ uploadFileCompleteCallback: function(file,serverData) {
+ Element.addClassName($('UploadFiles'),'link');//Safari hack
+ $('UploadFiles').innerHTML = 'Uploading ... ' + this.upload.getFilesUploaded() + "/" + this.upload.getFilesToUpload();
+ },
+
+ uploadQueueCompleteCallback: function() {
+ this.filesUploaded = this.upload.getFilesUploaded();
+ $('UploadFiles').innerHTML = "upload";
+ statusMessage('Uploaded ' + this.upload.getFilesUploaded() + ' files','good');
+ if(this.getParentID() != 'root') {
+ $('Image').ajaxGetFiles(this.getParentID(), null, this.insertImages.bind(this));
+ }
+ },
+
+ /**
+ * Iterates over all uploaded images and add them to TinyMCE editor
+ *
+ * @param transport object
+ */
+ insertImages: function(transport) {
+ //HACK FOR STRANGE ERROR OCCURING UNDER SAFARI
+ if(transport.responseText == '') {
+ $('Image').ajaxGetFiles(this.getParentID(), null, this.insertImages.bind(this));
+ return;
+ }
+ //END OF HACK
- $('Image').reapplyBehaviour();
+ $('Image').reapplyBehaviour();
- this.addToTinyMCE = this.addToTinyMCE.bind(this);
+ this.addToTinyMCE = this.addToTinyMCE.bind(this);
- this.processInProgress = false;
- },
-
- /**
- * Adds particular image to TinyMCE. Most of code has been copied from tiny_mce_improvements.js / ImageThumbnail.onclick
- * Sorry for not following DRY, I didn't want to break smth in tiny_mce_improvements.
- *
- * @param target object
- */
-
- addToTinyMCE: function(target) {
+ this.processInProgress = false;
+ },
+
+ /**
+ * Adds particular image to TinyMCE. Most of code has been copied from tiny_mce_improvements.js / ImageThumbnail.onclick
+ * Sorry for not following DRY, I didn't want to break smth in tiny_mce_improvements.
+ *
+ * @param target object
+ */
+
+ addToTinyMCE: function(target) {
var formObj = $('Form_EditorToolbarImageForm');
- var altText = formObj.elements.AltText.value;
- var cssClass = formObj.elements.CSSClass.value;
- var baseURL = document.getElementsByTagName('base')[0].href;
- var relativeHref = target.href.substr(baseURL.length)
- if(!tinyMCE.selectedInstance) tinyMCE.selectedInstance = Toolbar.instance().editor;
- if(tinyMCE.selectedInstance.contentWindow.focus) tinyMCE.selectedInstance.contentWindow.focus();
- // Extract dest width and dest height from the class name
- var destWidth = null;
- var destHeight = null;
- try {
- var imgTag = target.getElementsByTagName('img')[0];
- destWidth = imgTag.className.match(/destwidth=([0-9.\-]+)([, ]|$)/) ? RegExp.$1 : null;
- destHeight = imgTag.className.match(/destheight=([0-9.\-]+)([, ]|$)/) ? RegExp.$1 : null;
- } catch(er) {
- }
- TinyMCE_AdvancedTheme._insertImage(relativeHref, altText, 0, '', '', destWidth, destHeight, '', '', cssClass);
- },
-
- /**
- * Under IE6 when we click on "add folder" anchor, rest of anchors loose their correct position
- *
- */
-
- applyIE6Hack: function() {
- if(/msie/i.test(navigator.userAgent)) {
- elements = [$('FolderOk'),$('FolderCancel'),$('UploadFiles')];
- $A(elements).each(function(element) {
- element.style.position = "relative";
- element.style.top = "-3px";
- });
+ var altText = formObj.elements.AltText.value;
+ var cssClass = formObj.elements.CSSClass.value;
+ var baseURL = document.getElementsByTagName('base')[0].href;
+ var relativeHref = target.href.substr(baseURL.length)
+ if(!tinyMCE.selectedInstance) tinyMCE.selectedInstance = Toolbar.instance().editor;
+ if(tinyMCE.selectedInstance.contentWindow.focus) tinyMCE.selectedInstance.contentWindow.focus();
+ // Extract dest width and dest height from the class name
+ var destWidth = null;
+ var destHeight = null;
+ try {
+ var imgTag = target.getElementsByTagName('img')[0];
+ destWidth = imgTag.className.match(/destwidth=([0-9.\-]+)([, ]|$)/) ? RegExp.$1 : null;
+ destHeight = imgTag.className.match(/destheight=([0-9.\-]+)([, ]|$)/) ? RegExp.$1 : null;
+ } catch(er) {
+ }
+ TinyMCE_AdvancedTheme._insertImage(relativeHref, altText, 0, '', '', destWidth, destHeight, '', '', cssClass);
+ },
+
+ /**
+ * Under IE6 when we click on "add folder" anchor, rest of anchors loose their correct position
+ *
+ */
+
+ applyIE6Hack: function() {
+ if(/msie/i.test(navigator.userAgent)) {
+ elements = [$('FolderOk'),$('FolderCancel'),$('UploadFiles')];
+ $A(elements).each(function(element) {
+ element.style.position = "relative";
+ element.style.top = "-3px";
+ });
}
- },
-
- removeIE6Hack: function() {
- if(/msie/i.test(navigator.userAgent)) {
- elements = [$('FolderOk'),$('FolderCancel'),$('UploadFiles')];
- $A(elements).each(function(element) {
- element.style.position = "";
- });
- }
- },
-
- /**
- * Returns id of upload folder.
- *
- */
-
- getParentID: function() {
- return $('Form_EditorToolbarImageForm_FolderID').value == '' ? 'root' : $('Form_EditorToolbarImageForm_FolderID').value;
- }
+ },
+
+ removeIE6Hack: function() {
+ if(/msie/i.test(navigator.userAgent)) {
+ elements = [$('FolderOk'),$('FolderCancel'),$('UploadFiles')];
+ $A(elements).each(function(element) {
+ element.style.position = "";
+ });
+ }
+ },
+
+ /**
+ * Returns id of upload folder.
+ *
+ */
+
+ getParentID: function() {
+ return $('Form_EditorToolbarImageForm_FolderID').value == '' ? 'root' : $('Form_EditorToolbarImageForm_FolderID').value;
+ }
}
tinyMCEImageEnhancement = new TinyMCEImageEnhancement();
diff --git a/javascript/Upload.js b/javascript/Upload.js
index d23eb28e..2b48eaa4 100644
--- a/javascript/Upload.js
+++ b/javascript/Upload.js
@@ -1,129 +1,129 @@
/*
- This class is wrapper for SWFUpload class.
- If you want use SWFUpload, please use this class becuase it will take care of configuration
- error handling and other things.
+ This class is wrapper for SWFUpload class.
+ If you want use SWFUpload, please use this class becuase it will take care of configuration
+ error handling and other things.
*/
Upload = Class.create();
Upload.prototype = {
-
- /**
- * Sets configuration data provided from user if smth is missing sets default value.
- *
- * @param params object contains all configuration data for upload.
- */
- initialize: function(params) {
- this.filesUploaded = 0;
- this.filesToUpload = 0;
- this.folderID = 'root';
- this.uploadInProgress = false;
- this.uploadMessage = '';
- if(typeof params.fileSizeLimit != 'undefined') this.setFileSizeLimit = params.fileSizeLimit; else this.fileSizeLimit = '30720';
- if(typeof params.fileTypes != 'undefined') this.fileTypes = params.fileTypes; else this.fileTypes = '*.*';
- if(typeof params.fileTypesDescription != 'undefined') this.fileTypesDescription = params.fileTypesDescription; else this.fileTypesDescription = 'All Files';
- if(typeof params.fileUploadLimit != 'undefined') this.fileUploadLimit = params.fileUploadLimit; else this.fileUploadLimit = '6';
- if(typeof params.beginUploadOnQueue != 'undefined') this.beginUploadOnQueue = params.beginUploadOnQueue; else this.beginUploadOnQueue = false;
- if(typeof params.fileQueued != 'undefined') this.fileQueued = params.fileQueued;
- if(typeof params.fileProgress != 'undefined') this.fileProgress = params.fileProgress; else this.fileProgress = Prototype.emptyFunction;
- if(typeof params.fileCancelled != 'undefined') this.fileCancelled = params.fileCancelled;
- if(typeof params.fileComplete != 'undefined') this.fileComplete = params.fileComplete ;
- if(typeof params.queueComplete != 'undefined') this.queueComplete = params.queueComplete;
- if(typeof params.buildUI != 'undefined') this.customBuildUI = params.buildUI;
- if(typeof params.securityID != 'undefined') this.securityID = params.securityID;
- this.onLoad();
- },
-
- /**
- * Creates SWFUpload object for uploading files.
- *
- */
- onLoad: function() {
- path = this.getBasePath();
- sessId = this.getSessionId();//Because flash doesn't send proper cookies, we need to set session id in URL.
- this.swfu = new SWFUpload({
- upload_url: path + 'admin/assets/UploadForm?SecurityID=' + this.securityID + '&PHPSESSID=' + sessId, // Relative to the SWF file
- file_post_name: 'Files',
- file_size_limit : this.fileSizeLimit,
- file_types : this.fileTypes,
- file_types_description : this.fileTypesDescription,
- file_upload_limit : this.fileUploadLimit,
- begin_upload_on_queue : this.beginUploadOnQueue,
- use_server_data_event : true,
- validate_files: false,
+
+ /**
+ * Sets configuration data provided from user if smth is missing sets default value.
+ *
+ * @param params object contains all configuration data for upload.
+ */
+ initialize: function(params) {
+ this.filesUploaded = 0;
+ this.filesToUpload = 0;
+ this.folderID = 'root';
+ this.uploadInProgress = false;
+ this.uploadMessage = '';
+ if(typeof params.fileSizeLimit != 'undefined') this.setFileSizeLimit = params.fileSizeLimit; else this.fileSizeLimit = '30720';
+ if(typeof params.fileTypes != 'undefined') this.fileTypes = params.fileTypes; else this.fileTypes = '*.*';
+ if(typeof params.fileTypesDescription != 'undefined') this.fileTypesDescription = params.fileTypesDescription; else this.fileTypesDescription = 'All Files';
+ if(typeof params.fileUploadLimit != 'undefined') this.fileUploadLimit = params.fileUploadLimit; else this.fileUploadLimit = '6';
+ if(typeof params.beginUploadOnQueue != 'undefined') this.beginUploadOnQueue = params.beginUploadOnQueue; else this.beginUploadOnQueue = false;
+ if(typeof params.fileQueued != 'undefined') this.fileQueued = params.fileQueued;
+ if(typeof params.fileProgress != 'undefined') this.fileProgress = params.fileProgress; else this.fileProgress = Prototype.emptyFunction;
+ if(typeof params.fileCancelled != 'undefined') this.fileCancelled = params.fileCancelled;
+ if(typeof params.fileComplete != 'undefined') this.fileComplete = params.fileComplete ;
+ if(typeof params.queueComplete != 'undefined') this.queueComplete = params.queueComplete;
+ if(typeof params.buildUI != 'undefined') this.customBuildUI = params.buildUI;
+ if(typeof params.securityID != 'undefined') this.securityID = params.securityID;
+ this.onLoad();
+ },
+
+ /**
+ * Creates SWFUpload object for uploading files.
+ *
+ */
+ onLoad: function() {
+ path = this.getBasePath();
+ sessId = this.getSessionId();//Because flash doesn't send proper cookies, we need to set session id in URL.
+ this.swfu = new SWFUpload({
+ upload_url: path + 'admin/assets/UploadForm?SecurityID=' + this.securityID + '&PHPSESSID=' + sessId, // Relative to the SWF file
+ file_post_name: 'Files',
+ file_size_limit : this.fileSizeLimit,
+ file_types : this.fileTypes,
+ file_types_description : this.fileTypesDescription,
+ file_upload_limit : this.fileUploadLimit,
+ begin_upload_on_queue : this.beginUploadOnQueue,
+ use_server_data_event : true,
+ validate_files: false,
- file_queued_handler : this.uploadFileQueuedCallback.bind(this),
- upload_success_handler : this.uploadFileCompleteCallback.bind(this),
- upload_progress_handler: this.uploadFileProgressCallback.bind(this),
- error_handler : this.uploadErrorCallback.bind(this),
- file_validation_handler : Prototype.emptyFunction,
- file_cancelled_handler: Prototype.emptyFunction,
-
- flash_url : 'jsparty/SWFUpload/swfupload_f9.swf', // Relative to this file
- swfupload_loaded_handler: this.buildUI.bind(this),
- debug: false
- });
- },
-
- /**
- * Retrieves base path from URL.
- * TODO: Use base tag.
- */
-
- getBasePath: function() {
- var path = 'http://' + window.location.host + window.location.pathname;
+ file_queued_handler : this.uploadFileQueuedCallback.bind(this),
+ upload_success_handler : this.uploadFileCompleteCallback.bind(this),
+ upload_progress_handler: this.uploadFileProgressCallback.bind(this),
+ error_handler : this.uploadErrorCallback.bind(this),
+ file_validation_handler : Prototype.emptyFunction,
+ file_cancelled_handler: Prototype.emptyFunction,
+
+ flash_url : 'jsparty/SWFUpload/swfupload_f9.swf', // Relative to this file
+ swfupload_loaded_handler: this.buildUI.bind(this),
+ debug: false
+ });
+ },
+
+ /**
+ * Retrieves base path from URL.
+ * TODO: Use base tag.
+ */
+
+ getBasePath: function() {
+ var path = 'http://' + window.location.host + window.location.pathname;
if(path.match(/^(.*\/)admin/i)) return RegExp.$1;
else return path;
- },
-
- /**
- * Retrieves sessionId from cookie.
- *
- */
+ },
+
+ /**
+ * Retrieves sessionId from cookie.
+ *
+ */
- getSessionId: function() {
- var start = document.cookie.indexOf('PHPSESSID')+10;
- var end = document.cookie.indexOf(';',start);
- if(end == -1) end = document.cookie.length;
- return document.cookie.substring(start,end);
- },
-
- /**
- * Calls method defined by user, method should create user interface.
- *
- */
-
- buildUI: function() {
- this.customBuildUI();
- },
-
- /**
- * Called when new file is added to the queue
- *
- * @param file object
- * @param queueLength int
- */
-
- uploadFileQueuedCallback: function(file,queueLength) {
- this.filesToUpload++;
- this.fileQueued(file, queueLength);
- this.addFileParam(file);
- },
-
- /**
- * Called when uploading of particular file has finished
- *
- * @param file object
- * @param servedData string
- */
- uploadFileCompleteCallback: function(file,serverData) {
- this.filesUploaded++;
+ getSessionId: function() {
+ var start = document.cookie.indexOf('PHPSESSID')+10;
+ var end = document.cookie.indexOf(';',start);
+ if(end == -1) end = document.cookie.length;
+ return document.cookie.substring(start,end);
+ },
+
+ /**
+ * Calls method defined by user, method should create user interface.
+ *
+ */
+
+ buildUI: function() {
+ this.customBuildUI();
+ },
+
+ /**
+ * Called when new file is added to the queue
+ *
+ * @param file object
+ * @param queueLength int
+ */
+
+ uploadFileQueuedCallback: function(file,queueLength) {
+ this.filesToUpload++;
+ this.fileQueued(file, queueLength);
+ this.addFileParam(file);
+ },
+
+ /**
+ * Called when uploading of particular file has finished
+ *
+ * @param file object
+ * @param servedData string
+ */
+ uploadFileCompleteCallback: function(file,serverData) {
+ this.filesUploaded++;
if(serverData) {
- var toEval = serverData.substr(serverData.indexOf('','');
- this.uploadMessage = toEval;
+ var toEval = serverData.substr(serverData.indexOf('','');
+ this.uploadMessage = toEval;
}
this.fileComplete(file, serverData);
@@ -134,123 +134,123 @@ Upload.prototype = {
else {
this.queueComplete();
this.uploadInProgress = false;
- this.filesUploaded = 0;
- this.filesToUpload = 0;
+ this.filesUploaded = 0;
+ this.filesToUpload = 0;
}
- },
-
- /**
- * Called during uploading file.
- *
- * @param file object
- * @param bytes_complete int
- */
-
- uploadFileProgressCallback: function(file, bytes_complete) {
- this.uploadInProgress = true;
- this.fileProgress(file, bytes_complete);
- },
-
- /**
- * Called on error.
- * @param error_code int
- * @param file object
- * @param message string
- */
+ },
+
+ /**
+ * Called during uploading file.
+ *
+ * @param file object
+ * @param bytes_complete int
+ */
+
+ uploadFileProgressCallback: function(file, bytes_complete) {
+ this.uploadInProgress = true;
+ this.fileProgress(file, bytes_complete);
+ },
+
+ /**
+ * Called on error.
+ * @param error_code int
+ * @param file object
+ * @param message string
+ */
- uploadErrorCallback: function(error_code, file, message) {
- this.swfu.cancelQueue();
- switch(error_code) {
- case SWFUpload.ERROR_CODE_HTTP_ERROR:
- alert('You have encountered an error. File hasn\'t been uploaded. Please hit the "Refresh" button in your web browser. Error Code: HTTP Error, File name: ' + file.name + ', Message: ' + msg);
- break;
- case SWFUpload.ERROR_CODE_IO_ERROR:
- alert('You have encountered an error. File hasn\'t been uploaded. Please hit the "Refresh" button in your web browser. Error Code: IO Error, File name: ' + file.name + ', Message: ' + msg);
- break;
- case SWFUpload.ERROR_CODE_SECURITY_ERROR:
- alert('You have encountered an error. File hasn\'t been uploaded. Please hit the "Refresh" button in your web browser. Error Code: Security Error, File name: ' + file.name + ', Message: ' + msg);
- break;
- case SWFUpload.ERROR_CODE_FILE_EXCEEDS_SIZE_LIMIT:
- alert('Files cannot be bigger than ' + this.fileSizeLimit/1024 + ' MB.');
- break;
- case SWFUpload.ERROR_CODE_ZERO_BYTE_FILE:
- alert('Files cannot be empty');
- break;
- case SWFUpload.ERROR_CODE_QUEUE_LIMIT_EXCEEDED:
- alert('You can only have six files in queue');
- break;
- case SWFUpload.ERROR_CODE_UPLOAD_FAILED:
- alert('You have encountered an error. File hasn\'t has been uploaded. Please hit the "Refresh" button in your web browser');
- break;
- case SWFUpload.ERROR_CODE_SPECIFIED_FILE_NOT_FOUND:
- alert('You have encountered an error. File hasn\'t has been uploaded. Please hit the "Refresh" button in your web browser');
- break;
- default:
- alert('You have encountered an error. File hasn\'t has been uploaded. Please hit the "Refresh" button in your web browser');
- }
- },
-
- /**
- * Because we are on top of standard upload we need to add some POST vars that
- * normally are being sent as part of form.
- *
- * @param file object
- */
-
- addFileParam: function(file) {
- this.swfu.addFileParam(file.id,'ID',this.folderID);
- this.swfu.addFileParam(file.id,'action_doUpload','1');
- this.swfu.addFileParam(file.id,'Files',file.name);
- this.swfu.addFileParam(file.id,'MAX_FILE_SIZE','31457280');
- },
-
- /**
- * Starts file explorer.
- *
- */
-
- browse: function() {
- this.swfu.selectFiles();
- },
-
- /**
- * Starts upload
- *
- */
-
- startUpload: function() {
- this.swfu.startUpload();
- },
-
- /**
- * Cancels uploading of file.
- */
-
- cancelUpload: function(fileId) {
- this.filesToUpload--;
- this.swfu.cancelUpload(fileId);
- },
-
- /*
- * Getters and setters.
- */
- setFolderID: function(id) {
- this.folderID = id;
- },
-
- getFilesUploaded: function() {
- return this.filesUploaded;
- },
-
- getFilesToUpload: function() {
- return this.filesToUpload;
- },
-
- getUploadMessage: function() {
- return this.uploadMessage;
- },
-
- isUploadInProgress: function() {
- return this.uploadInProgress;
- }
+ uploadErrorCallback: function(error_code, file, message) {
+ this.swfu.cancelQueue();
+ switch(error_code) {
+ case SWFUpload.ERROR_CODE_HTTP_ERROR:
+ alert('You have encountered an error. File hasn\'t been uploaded. Please hit the "Refresh" button in your web browser. Error Code: HTTP Error, File name: ' + file.name + ', Message: ' + msg);
+ break;
+ case SWFUpload.ERROR_CODE_IO_ERROR:
+ alert('You have encountered an error. File hasn\'t been uploaded. Please hit the "Refresh" button in your web browser. Error Code: IO Error, File name: ' + file.name + ', Message: ' + msg);
+ break;
+ case SWFUpload.ERROR_CODE_SECURITY_ERROR:
+ alert('You have encountered an error. File hasn\'t been uploaded. Please hit the "Refresh" button in your web browser. Error Code: Security Error, File name: ' + file.name + ', Message: ' + msg);
+ break;
+ case SWFUpload.ERROR_CODE_FILE_EXCEEDS_SIZE_LIMIT:
+ alert('Files cannot be bigger than ' + this.fileSizeLimit/1024 + ' MB.');
+ break;
+ case SWFUpload.ERROR_CODE_ZERO_BYTE_FILE:
+ alert('Files cannot be empty');
+ break;
+ case SWFUpload.ERROR_CODE_QUEUE_LIMIT_EXCEEDED:
+ alert('You can only have six files in queue');
+ break;
+ case SWFUpload.ERROR_CODE_UPLOAD_FAILED:
+ alert('You have encountered an error. File hasn\'t has been uploaded. Please hit the "Refresh" button in your web browser');
+ break;
+ case SWFUpload.ERROR_CODE_SPECIFIED_FILE_NOT_FOUND:
+ alert('You have encountered an error. File hasn\'t has been uploaded. Please hit the "Refresh" button in your web browser');
+ break;
+ default:
+ alert('You have encountered an error. File hasn\'t has been uploaded. Please hit the "Refresh" button in your web browser');
+ }
+ },
+
+ /**
+ * Because we are on top of standard upload we need to add some POST vars that
+ * normally are being sent as part of form.
+ *
+ * @param file object
+ */
+
+ addFileParam: function(file) {
+ this.swfu.addFileParam(file.id,'ID',this.folderID);
+ this.swfu.addFileParam(file.id,'action_doUpload','1');
+ this.swfu.addFileParam(file.id,'Files',file.name);
+ this.swfu.addFileParam(file.id,'MAX_FILE_SIZE','31457280');
+ },
+
+ /**
+ * Starts file explorer.
+ *
+ */
+
+ browse: function() {
+ this.swfu.selectFiles();
+ },
+
+ /**
+ * Starts upload
+ *
+ */
+
+ startUpload: function() {
+ this.swfu.startUpload();
+ },
+
+ /**
+ * Cancels uploading of file.
+ */
+
+ cancelUpload: function(fileId) {
+ this.filesToUpload--;
+ this.swfu.cancelUpload(fileId);
+ },
+
+ /*
+ * Getters and setters.
+ */
+ setFolderID: function(id) {
+ this.folderID = id;
+ },
+
+ getFilesUploaded: function() {
+ return this.filesUploaded;
+ },
+
+ getFilesToUpload: function() {
+ return this.filesToUpload;
+ },
+
+ getUploadMessage: function() {
+ return this.uploadMessage;
+ },
+
+ isUploadInProgress: function() {
+ return this.uploadInProgress;
+ }
}