MINOR Fixed tab-spacing in cms/upload js files

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/branches/2.3@71292 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2009-02-03 04:20:00 +00:00 committed by Sam Minnee
parent 7a027eb753
commit aba093c176
3 changed files with 590 additions and 590 deletions

View File

@ -5,173 +5,173 @@
*/ */
CMSMain_upload = Class.create(); CMSMain_upload = Class.create();
CMSMain_upload.prototype = { CMSMain_upload.prototype = {
initialize: function() { initialize: function() {
// This is disabled until we get it working reliably // This is disabled until we get it working reliably
return; return;
// We require flash 9 // We require flash 9
pv = getFlashPlayerVersion(); pv = getFlashPlayerVersion();
if(pv.major < 9) return; 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 // 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(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(pv.major == 9 && pv.minor == 0 && pv.rev < 64) return;
} }
// If those 2 checks pass, we can provide upload capabilities to the user // If those 2 checks pass, we can provide upload capabilities to the user
this.iframe = window.top.document.getElementById('AssetAdmin_upload'); this.iframe = window.top.document.getElementById('AssetAdmin_upload');
this.onLoad(); this.onLoad();
}, },
onLoad: function() { onLoad: function() {
this.upload = new Upload({ this.upload = new Upload({
fileUploadLimit : '6', fileUploadLimit : '6',
securityID : $('SecurityID').value, securityID : $('SecurityID').value,
beginUploadOnQueue : false, beginUploadOnQueue : false,
fileQueued : this.uploadFileQueuedCallback.bind(this), fileQueued : this.uploadFileQueuedCallback.bind(this),
fileProgress : this.uploadProgressCallback.bind(this), fileProgress : this.uploadProgressCallback.bind(this),
fileCancelled : this.uploadFileCancelCallback.bind(this), fileCancelled : this.uploadFileCancelCallback.bind(this),
fileComplete : this.uploadFileCompleteCallback.bind(this), fileComplete : this.uploadFileCompleteCallback.bind(this),
queueComplete : this.uploadQueueCompleteCallback.bind(this), queueComplete : this.uploadQueueCompleteCallback.bind(this),
buildUI : this.extendForm.bind(this) buildUI : this.extendForm.bind(this)
}); });
}, },
/** /**
* Builds UI, called only when Upload object will be able to create flash uploader. * Builds UI, called only when Upload object will be able to create flash uploader.
*/ */
extendForm: function() { extendForm: function() {
if(this.iframe.contentDocument == undefined) this.iframe.contentDocument = document.frames[0].document;//IE HACK if(this.iframe.contentDocument == undefined) this.iframe.contentDocument = document.frames[0].document;//IE HACK
element = this.iframe.contentDocument.getElementById('Form_UploadForm'); element = this.iframe.contentDocument.getElementById('Form_UploadForm');
inputFile = this.iframe.contentDocument.getElementById('Form_UploadForm_Files-0'); inputFile = this.iframe.contentDocument.getElementById('Form_UploadForm_Files-0');
inputFileParent = inputFile.parentNode; inputFileParent = inputFile.parentNode;
inputFileParent.removeChild(inputFile); inputFileParent.removeChild(inputFile);
inputFile = this.iframe.contentDocument.createElement('input'); inputFile = this.iframe.contentDocument.createElement('input');
inputFile.type = 'text'; inputFile.type = 'text';
inputFile.id = 'Form_UploadForm_Files-0'; inputFile.id = 'Form_UploadForm_Files-0';
inputFileParent.appendChild(inputFile); inputFileParent.appendChild(inputFile);
inputButton = this.iframe.contentDocument.getElementById('Form_UploadForm_Files-1'); inputButton = this.iframe.contentDocument.getElementById('Form_UploadForm_Files-1');
if(inputButton != null) inputButton.parentNode.removeChild(inputButton); if(inputButton != null) inputButton.parentNode.removeChild(inputButton);
inputButton = this.iframe.contentDocument.createElement('input'); inputButton = this.iframe.contentDocument.createElement('input');
inputButton.type = 'button'; inputButton.type = 'button';
inputButton.id = 'Form_UploadForm_Files-1'; inputButton.id = 'Form_UploadForm_Files-1';
inputButton.value = ' Browse...'; inputButton.value = ' Browse...';
inputButton.style.width = '66px'; inputButton.style.width = '66px';
inputButton.style.height = '19px'; inputButton.style.height = '19px';
inputButton.style.position = 'relative'; inputButton.style.position = 'relative';
inputButton.style.top = '1px'; inputButton.style.top = '1px';
inputButton.style.fontFamily = 'Arial'; inputButton.style.fontFamily = 'Arial';
inputButton.style.fontSize = '1.06em'; inputButton.style.fontSize = '1.06em';
inputFileParent.appendChild(inputButton); inputFileParent.appendChild(inputButton);
Event.observe(inputButton,'click',this.onBrowseClick.bind(this)); Event.observe(inputButton,'click',this.onBrowseClick.bind(this));
Event.observe(this.iframe.contentDocument.getElementById('Form_UploadForm_action_upload'),'click',this.onUploadClick.bind(this)); Event.observe(this.iframe.contentDocument.getElementById('Form_UploadForm_action_upload'),'click',this.onUploadClick.bind(this));
}, },
onBrowseClick: function(event) { onBrowseClick: function(event) {
this.upload.browse(); this.upload.browse();
}, },
onUploadClick: function(event) { onUploadClick: function(event) {
Event.stop(event); Event.stop(event);
this.upload.startUpload(); this.upload.startUpload();
}, },
uploadFileQueuedCallback: function(file,queueLength) { uploadFileQueuedCallback: function(file,queueLength) {
this.upload.setFolderID(this.iframe.contentDocument.getElementById('Form_UploadForm_ID').value); this.upload.setFolderID(this.iframe.contentDocument.getElementById('Form_UploadForm_ID').value);
this.iframe.contentDocument.getElementById('Form_UploadForm_action_upload').disabled = false; this.iframe.contentDocument.getElementById('Form_UploadForm_action_upload').disabled = false;
var fileContainer = this.iframe.contentDocument.getElementById('Form_UploadForm_FilesList'); var fileContainer = this.iframe.contentDocument.getElementById('Form_UploadForm_FilesList');
if(fileContainer == null) { if(fileContainer == null) {
fileContainer = this.iframe.contentDocument.createElement('div'); fileContainer = this.iframe.contentDocument.createElement('div');
fileContainer.id = 'Form_UploadForm_FilesList'; fileContainer.id = 'Form_UploadForm_FilesList';
this.iframe.contentDocument.getElementById('Form_UploadForm').appendChild(fileContainer); this.iframe.contentDocument.getElementById('Form_UploadForm').appendChild(fileContainer);
} }
var fileToUpload = this.iframe.contentDocument.createElement('div'); var fileToUpload = this.iframe.contentDocument.createElement('div');
fileToUpload.id = 'Form_UploadForm_FilesList_' + file.id; fileToUpload.id = 'Form_UploadForm_FilesList_' + file.id;
fileToUpload.style.marginBottom = '3px'; fileToUpload.style.marginBottom = '3px';
fileContainer.appendChild(fileToUpload); fileContainer.appendChild(fileToUpload);
var fileName = this.iframe.contentDocument.createElement('div'); var fileName = this.iframe.contentDocument.createElement('div');
fileName.id = 'Form_UploadForm_FilesList_Name_' + file.id; fileName.id = 'Form_UploadForm_FilesList_Name_' + file.id;
fileName.style.position = 'relative'; fileName.style.position = 'relative';
fileName.style.top = '-4px'; fileName.style.top = '-4px';
fileName.style.display = 'inline'; fileName.style.display = 'inline';
fileName.style.padding = '2px'; fileName.style.padding = '2px';
fileName.innerHTML = file.name; fileName.innerHTML = file.name;
fileName.style.height = Element.getDimensions(fileName).height + 1 + 'px';//IE hack fileName.style.height = Element.getDimensions(fileName).height + 1 + 'px';//IE hack
fileToUpload.appendChild(fileName); fileToUpload.appendChild(fileName);
var fileProgress = this.iframe.contentDocument.createElement('div'); var fileProgress = this.iframe.contentDocument.createElement('div');
fileProgress.id = 'Form_UploadForm_FilesList_Progress_' + file.id; fileProgress.id = 'Form_UploadForm_FilesList_Progress_' + file.id;
Position.clone(fileName,fileProgress); Position.clone(fileName,fileProgress);
fileProgress.style.backgroundColor = 'black'; fileProgress.style.backgroundColor = 'black';
fileProgress.style.display = 'inline'; fileProgress.style.display = 'inline';
fileProgress.style.position = 'absolute'; fileProgress.style.position = 'absolute';
fileProgress.style.left = '5px'; fileProgress.style.left = '5px';
fileProgress.style.width = '0px'; fileProgress.style.width = '0px';
fileProgress.finished = false; fileProgress.finished = false;
fileProgress.style.top = parseInt(fileProgress.style.top) + 6 + 'px'; fileProgress.style.top = parseInt(fileProgress.style.top) + 6 + 'px';
fileProgress.style.height = Element.getDimensions(fileName).height + 1 + 'px'; fileProgress.style.height = Element.getDimensions(fileName).height + 1 + 'px';
fileToUpload.appendChild(fileProgress); fileToUpload.appendChild(fileProgress);
var fileDelete = this.iframe.contentDocument.createElement('input'); var fileDelete = this.iframe.contentDocument.createElement('input');
fileDelete.id = file.id; fileDelete.id = file.id;
fileDelete.type = 'button'; fileDelete.type = 'button';
fileDelete.value = 'Delete'; fileDelete.value = 'Delete';
Element.addClassName(fileDelete,'delete'); Element.addClassName(fileDelete,'delete');
fileToUpload.appendChild(fileDelete); fileToUpload.appendChild(fileDelete);
Event.observe(fileDelete,'click',this.uploadFileCancelCallback.bind(this)); Event.observe(fileDelete,'click',this.uploadFileCancelCallback.bind(this));
}, },
uploadProgressCallback: function(file,bytesLoaded) { uploadProgressCallback: function(file,bytesLoaded) {
fileName = this.iframe.contentDocument.getElementById('Form_UploadForm_FilesList_Name_' + file.id); fileName = this.iframe.contentDocument.getElementById('Form_UploadForm_FilesList_Name_' + file.id);
fileName.style.border = 'solid 1px black'; fileName.style.border = 'solid 1px black';
fileProgress = this.iframe.contentDocument.getElementById('Form_UploadForm_FilesList_Progress_' + file.id); fileProgress = this.iframe.contentDocument.getElementById('Form_UploadForm_FilesList_Progress_' + file.id);
fileProgress.style.opacity = 0.3;fileProgress.style.filter = 'alpha(opacity=30)'; fileProgress.style.opacity = 0.3;fileProgress.style.filter = 'alpha(opacity=30)';
if(!fileProgress.cloned) { if(!fileProgress.cloned) {
Position.clone(fileName,fileProgress); Position.clone(fileName,fileProgress);
fileProgress.style.width = '0px'; fileProgress.style.width = '0px';
fileProgress.cloned = true; fileProgress.cloned = true;
} }
fileProgress.style.width = (bytesLoaded / file.size) * Element.getDimensions(fileName).width - 1 + 'px'; fileProgress.style.width = (bytesLoaded / file.size) * Element.getDimensions(fileName).width - 1 + 'px';
}, },
uploadFileCompleteCallback: function(file,serverData) { uploadFileCompleteCallback: function(file,serverData) {
this.iframe.contentDocument.getElementById('Form_UploadForm_FilesList_Progress_' + file.id).finished = true; this.iframe.contentDocument.getElementById('Form_UploadForm_FilesList_Progress_' + file.id).finished = true;
}, },
uploadFileCancelCallback: function(event) { uploadFileCancelCallback: function(event) {
element = Event.element(event); element = Event.element(event);
fileId = element.id; fileId = element.id;
fileContainer = this.iframe.contentDocument.getElementById('Form_UploadForm_FilesList'); fileContainer = this.iframe.contentDocument.getElementById('Form_UploadForm_FilesList');
elementToDelete = this.iframe.contentDocument.getElementById('Form_UploadForm_FilesList_' + fileId); elementToDelete = this.iframe.contentDocument.getElementById('Form_UploadForm_FilesList_' + fileId);
elementToDelete.parentNode.removeChild(elementToDelete); elementToDelete.parentNode.removeChild(elementToDelete);
filesToUpload = fileContainer.childNodes.length; filesToUpload = fileContainer.childNodes.length;
if(filesToUpload > 0) { if(filesToUpload > 0) {
this.iframe.contentDocument.getElementById('Form_UploadForm_action_upload').disabled = false; this.iframe.contentDocument.getElementById('Form_UploadForm_action_upload').disabled = false;
} else { } else {
this.iframe.contentDocument.getElementById('Form_UploadForm_action_upload').disabled = true; this.iframe.contentDocument.getElementById('Form_UploadForm_action_upload').disabled = true;
} }
$A(fileContainer.childNodes).each( $A(fileContainer.childNodes).each(
function(item) { function(item) {
$A(item.childNodes).each( $A(item.childNodes).each(
function(item) { function(item) {
if(item.id.indexOf('Name') != -1) { if(item.id.indexOf('Name') != -1) {
fileName = item; fileName = item;
} }
if(item.id.indexOf('Progress') != -1) { if(item.id.indexOf('Progress') != -1) {
fileProgress = item; fileProgress = item;
} }
}); });
Position.clone(fileName,fileProgress); Position.clone(fileName,fileProgress);
if(fileProgress.finished == false) fileProgress.style.width = '0px'; if(fileProgress.finished == false) fileProgress.style.width = '0px';
} }
); );
}, },
uploadQueueCompleteCallback: function() { uploadQueueCompleteCallback: function() {
eval(this.upload.getUploadMessage().replace(/Uploaded 1 files/g,'Uploaded ' + this.upload.getFilesUploaded() + ' files')); eval(this.upload.getUploadMessage().replace(/Uploaded 1 files/g,'Uploaded ' + this.upload.getFilesUploaded() + ' files'));
} }
} }
window.top.document.CMSMain_upload = CMSMain_upload; window.top.document.CMSMain_upload = CMSMain_upload;

View File

@ -4,54 +4,54 @@
*/ */
TinyMCEImageEnhancement = Class.create(); TinyMCEImageEnhancement = Class.create();
TinyMCEImageEnhancement.prototype = { TinyMCEImageEnhancement.prototype = {
initialize: function() { initialize: function() {
this.filesUploaded = 0; this.filesUploaded = 0;
this.processInProgress = false; this.processInProgress = false;
Event.observe(window,'load',this.onWindowLoad.bind(this)); Event.observe(window,'load',this.onWindowLoad.bind(this));
}, },
addListeners: function() { addListeners: function() {
$('Form_EditorToolbarImageForm_FolderID').value = ""; $('Form_EditorToolbarImageForm_FolderID').value = "";
Event.observe($('AddFolder'),'click',this.onAddFolder.bind(this)); Event.observe($('AddFolder'),'click',this.onAddFolder.bind(this));
Event.observe($('FolderOk'),'click',this.onFolderOk.bind(this)); Event.observe($('FolderOk'),'click',this.onFolderOk.bind(this));
Event.observe($('FolderCancel'),'click',this.onFolderCancel.bind(this)); Event.observe($('FolderCancel'),'click',this.onFolderCancel.bind(this));
Event.observe($('UploadFiles'),'click',this.onUpload.bind(this)); Event.observe($('UploadFiles'),'click',this.onUpload.bind(this));
}, },
/** /**
* Method creates HTML element, only reason for this method is DRY. * Method creates HTML element, only reason for this method is DRY.
*/ */
addElement: function(tag, className, parent, properties) { addElement: function(tag, className, parent, properties) {
var e = document.createElement(tag); var e = document.createElement(tag);
Element.addClassName(e,className); Element.addClassName(e,className);
parent.appendChild(e); parent.appendChild(e);
Object.extend(e,properties); Object.extend(e,properties);
return e; return e;
}, },
onUpload: function(event) { onUpload: function(event) {
Event.stop(event); Event.stop(event);
if(!this.processInProgress) { if(!this.processInProgress) {
if(this.getParentID() != 'root') { if(this.getParentID() != 'root') {
this.upload.browse(); this.upload.browse();
} else { } else {
statusMessage("Please choose folder","bad"); statusMessage("Please choose folder","bad");
} }
} }
}, },
/** /**
* Called when user clicks "add folder" anchor. * Called when user clicks "add folder" anchor.
*/ */
onAddFolder: function(event) { onAddFolder: function(event) {
Event.stop(event); Event.stop(event);
Element.hide('AddFolder'); Element.hide('AddFolder');
Element.show('NewFolderName','FolderOk','FolderCancel'); Element.show('NewFolderName','FolderOk','FolderCancel');
this.applyIE6Hack(); this.applyIE6Hack();
}, },
/** /**
* The user clicks the "ok" anchor link, the click event calls up * 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 * 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); new Ajax.Request('admin/assets/addfolder', options);
}, },
/** /**
* If the "addFolderOk" function does a successful AJAX post, call this * If the "addFolderOk" function does a successful AJAX post, call this
* function. Take the folder ID that was created in "addFolderOk" * function. Take the folder ID that was created in "addFolderOk"
* via ajax and send data to modify that folder record. * via ajax and send data to modify that folder record.
*/ */
onFolderGetSuccess: function(transport) { onFolderGetSuccess: function(transport) {
var folderID = transport.responseText; var folderID = transport.responseText;
@ -94,163 +94,163 @@ TinyMCEImageEnhancement.prototype = {
this.folderID = folderID; this.folderID = folderID;
statusMessage('Creating new folder'); statusMessage('Creating new folder');
$('TreeDropdownField_Form_EditorToolbarImageForm_FolderID').itemTree = null; $('TreeDropdownField_Form_EditorToolbarImageForm_FolderID').itemTree = null;
$('TreeDropdownField_Form_EditorToolbarImageForm_FolderID').setValue(this.folderID); $('TreeDropdownField_Form_EditorToolbarImageForm_FolderID').setValue(this.folderID);
$('NewFolderName').value = ''; $('NewFolderName').value = '';
Element.show('AddFolder'); Element.show('AddFolder');
Element.hide('NewFolderName','FolderOk','FolderCancel'); Element.hide('NewFolderName','FolderOk','FolderCancel');
this.removeIE6Hack(); this.removeIE6Hack();
}, },
/** /**
* If user doesn't want to add folder return to default UI. * If user doesn't want to add folder return to default UI.
*/ */
onFolderCancel: function(event) { onFolderCancel: function(event) {
$('NewFolderName').value = ''; $('NewFolderName').value = '';
Element.show('AddFolder'); Element.show('AddFolder');
Element.hide('NewFolderName','FolderOk','FolderCancel'); Element.hide('NewFolderName','FolderOk','FolderCancel');
this.removeIE6Hack(); this.removeIE6Hack();
Event.stop(event); Event.stop(event);
return false; return false;
}, },
/** /**
* Called on window.onload * Called on window.onload
*/ */
onWindowLoad: function() { onWindowLoad: function() {
// Due to a bug in the flash plugin on Linux and Mac, // Due to a bug in the flash plugin on Linux and Mac,
//we need at least version 9.0.64 to use SWFUpload //we need at least version 9.0.64 to use SWFUpload
// see http://open.silverstripe.com/ticket/3023 // see http://open.silverstripe.com/ticket/3023
if(navigator.appVersion.indexOf("Mac") != -1 || navigator.appVersion.indexOf("X11") != -1 || navigator.appVersion.indexOf("Linux") != -1) { if(navigator.appVersion.indexOf("Mac") != -1 || navigator.appVersion.indexOf("X11") != -1 || navigator.appVersion.indexOf("Linux") != -1) {
pv = getFlashPlayerVersion(); pv = getFlashPlayerVersion();
if(pv.major < 9 || pv.major > 9 || (pv.major == 9 && pv.minor == 0 && pv.rev < 64)) { if(pv.major < 9 || pv.major > 9 || (pv.major == 9 && pv.minor == 0 && pv.rev < 64)) {
if($('AddFolderGroup')) $('AddFolderGroup').style.display = 'none'; if($('AddFolderGroup')) $('AddFolderGroup').style.display = 'none';
if($('PipeSeparator')) $('PipeSeparator').style.display = 'none'; if($('PipeSeparator')) $('PipeSeparator').style.display = 'none';
if($('UploadGroup')) $('UploadGroup').style.display = 'none'; if($('UploadGroup')) $('UploadGroup').style.display = 'none';
return; return;
} }
} }
if($('FolderID') != null) { if($('FolderID') != null) {
if($('SecurityID')) var securityid=$('SecurityID').value; if($('SecurityID')) var securityid=$('SecurityID').value;
else var securityid=null; else var securityid=null;
this.upload = new Upload( this.upload = new Upload(
{ {
fileTypes : '*.jpeg;*.jpg;*.jpe;*.png;*.gif;', fileTypes : '*.jpeg;*.jpg;*.jpe;*.png;*.gif;',
fileTypesDescription : 'Image files', fileTypesDescription : 'Image files',
fileUploadLimit : '100', fileUploadLimit : '100',
securityID : securityid, securityID : securityid,
beginUploadOnQueue : true, beginUploadOnQueue : true,
buildUI : this.addListeners.bind(this), buildUI : this.addListeners.bind(this),
fileQueued : this.uploadFileQueuedCallback.bind(this), fileQueued : this.uploadFileQueuedCallback.bind(this),
fileComplete : this.uploadFileCompleteCallback.bind(this), fileComplete : this.uploadFileCompleteCallback.bind(this),
queueComplete : this.uploadQueueCompleteCallback.bind(this) queueComplete : this.uploadQueueCompleteCallback.bind(this)
} }
); );
} }
}, },
uploadFileQueuedCallback: function(file,queueLength) { uploadFileQueuedCallback: function(file,queueLength) {
this.processInProgress = true; this.processInProgress = true;
this.upload.setFolderID(this.getParentID()); this.upload.setFolderID(this.getParentID());
$('UploadFiles').innerHTML = "Uploading ... 1/" + this.upload.getFilesToUpload(); $('UploadFiles').innerHTML = "Uploading ... 1/" + this.upload.getFilesToUpload();
this.upload.startUpload(); this.upload.startUpload();
}, },
uploadFileCompleteCallback: function(file,serverData) { uploadFileCompleteCallback: function(file,serverData) {
Element.addClassName($('UploadFiles'),'link');//Safari hack Element.addClassName($('UploadFiles'),'link');//Safari hack
$('UploadFiles').innerHTML = 'Uploading ... ' + this.upload.getFilesUploaded() + "/" + this.upload.getFilesToUpload(); $('UploadFiles').innerHTML = 'Uploading ... ' + this.upload.getFilesUploaded() + "/" + this.upload.getFilesToUpload();
}, },
uploadQueueCompleteCallback: function() { uploadQueueCompleteCallback: function() {
this.filesUploaded = this.upload.getFilesUploaded(); this.filesUploaded = this.upload.getFilesUploaded();
$('UploadFiles').innerHTML = "upload"; $('UploadFiles').innerHTML = "upload";
statusMessage('Uploaded ' + this.upload.getFilesUploaded() + ' files','good'); statusMessage('Uploaded ' + this.upload.getFilesUploaded() + ' files','good');
if(this.getParentID() != 'root') { if(this.getParentID() != 'root') {
$('Image').ajaxGetFiles(this.getParentID(), null, this.insertImages.bind(this)); $('Image').ajaxGetFiles(this.getParentID(), null, this.insertImages.bind(this));
} }
}, },
/** /**
* Iterates over all uploaded images and add them to TinyMCE editor * Iterates over all uploaded images and add them to TinyMCE editor
* *
* @param transport object * @param transport object
*/ */
insertImages: function(transport) { insertImages: function(transport) {
//HACK FOR STRANGE ERROR OCCURING UNDER SAFARI //HACK FOR STRANGE ERROR OCCURING UNDER SAFARI
if(transport.responseText == '') { if(transport.responseText == '') {
$('Image').ajaxGetFiles(this.getParentID(), null, this.insertImages.bind(this)); $('Image').ajaxGetFiles(this.getParentID(), null, this.insertImages.bind(this));
return; return;
} }
//END OF HACK //END OF HACK
$('Image').reapplyBehaviour(); $('Image').reapplyBehaviour();
this.addToTinyMCE = this.addToTinyMCE.bind(this); this.addToTinyMCE = this.addToTinyMCE.bind(this);
this.processInProgress = false; this.processInProgress = false;
}, },
/** /**
* Adds particular image to TinyMCE. Most of code has been copied from tiny_mce_improvements.js / ImageThumbnail.onclick * 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. * Sorry for not following DRY, I didn't want to break smth in tiny_mce_improvements.
* *
* @param target object * @param target object
*/ */
addToTinyMCE: function(target) { addToTinyMCE: function(target) {
var formObj = $('Form_EditorToolbarImageForm'); var formObj = $('Form_EditorToolbarImageForm');
var altText = formObj.elements.AltText.value; var altText = formObj.elements.AltText.value;
var cssClass = formObj.elements.CSSClass.value; var cssClass = formObj.elements.CSSClass.value;
var baseURL = document.getElementsByTagName('base')[0].href; var baseURL = document.getElementsByTagName('base')[0].href;
var relativeHref = target.href.substr(baseURL.length) var relativeHref = target.href.substr(baseURL.length)
if(!tinyMCE.selectedInstance) tinyMCE.selectedInstance = Toolbar.instance().editor; if(!tinyMCE.selectedInstance) tinyMCE.selectedInstance = Toolbar.instance().editor;
if(tinyMCE.selectedInstance.contentWindow.focus) tinyMCE.selectedInstance.contentWindow.focus(); if(tinyMCE.selectedInstance.contentWindow.focus) tinyMCE.selectedInstance.contentWindow.focus();
// Extract dest width and dest height from the class name // Extract dest width and dest height from the class name
var destWidth = null; var destWidth = null;
var destHeight = null; var destHeight = null;
try { try {
var imgTag = target.getElementsByTagName('img')[0]; var imgTag = target.getElementsByTagName('img')[0];
destWidth = imgTag.className.match(/destwidth=([0-9.\-]+)([, ]|$)/) ? RegExp.$1 : null; destWidth = imgTag.className.match(/destwidth=([0-9.\-]+)([, ]|$)/) ? RegExp.$1 : null;
destHeight = imgTag.className.match(/destheight=([0-9.\-]+)([, ]|$)/) ? RegExp.$1 : null; destHeight = imgTag.className.match(/destheight=([0-9.\-]+)([, ]|$)/) ? RegExp.$1 : null;
} catch(er) { } catch(er) {
} }
TinyMCE_AdvancedTheme._insertImage(relativeHref, altText, 0, '', '', destWidth, destHeight, '', '', cssClass); 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 * Under IE6 when we click on "add folder" anchor, rest of anchors loose their correct position
* *
*/ */
applyIE6Hack: function() { applyIE6Hack: function() {
if(/msie/i.test(navigator.userAgent)) { if(/msie/i.test(navigator.userAgent)) {
elements = [$('FolderOk'),$('FolderCancel'),$('UploadFiles')]; elements = [$('FolderOk'),$('FolderCancel'),$('UploadFiles')];
$A(elements).each(function(element) { $A(elements).each(function(element) {
element.style.position = "relative"; element.style.position = "relative";
element.style.top = "-3px"; element.style.top = "-3px";
}); });
} }
}, },
removeIE6Hack: function() { removeIE6Hack: function() {
if(/msie/i.test(navigator.userAgent)) { if(/msie/i.test(navigator.userAgent)) {
elements = [$('FolderOk'),$('FolderCancel'),$('UploadFiles')]; elements = [$('FolderOk'),$('FolderCancel'),$('UploadFiles')];
$A(elements).each(function(element) { $A(elements).each(function(element) {
element.style.position = ""; element.style.position = "";
}); });
} }
}, },
/** /**
* Returns id of upload folder. * Returns id of upload folder.
* *
*/ */
getParentID: function() { getParentID: function() {
return $('Form_EditorToolbarImageForm_FolderID').value == '' ? 'root' : $('Form_EditorToolbarImageForm_FolderID').value; return $('Form_EditorToolbarImageForm_FolderID').value == '' ? 'root' : $('Form_EditorToolbarImageForm_FolderID').value;
} }
} }
tinyMCEImageEnhancement = new TinyMCEImageEnhancement(); tinyMCEImageEnhancement = new TinyMCEImageEnhancement();

View File

@ -1,129 +1,129 @@
/* /*
This class is wrapper for SWFUpload class. This class is wrapper for SWFUpload class.
If you want use SWFUpload, please use this class becuase it will take care of configuration If you want use SWFUpload, please use this class becuase it will take care of configuration
error handling and other things. error handling and other things.
*/ */
Upload = Class.create(); Upload = Class.create();
Upload.prototype = { Upload.prototype = {
/** /**
* Sets configuration data provided from user if smth is missing sets default value. * Sets configuration data provided from user if smth is missing sets default value.
* *
* @param params object contains all configuration data for upload. * @param params object contains all configuration data for upload.
*/ */
initialize: function(params) { initialize: function(params) {
this.filesUploaded = 0; this.filesUploaded = 0;
this.filesToUpload = 0; this.filesToUpload = 0;
this.folderID = 'root'; this.folderID = 'root';
this.uploadInProgress = false; this.uploadInProgress = false;
this.uploadMessage = ''; this.uploadMessage = '';
if(typeof params.fileSizeLimit != 'undefined') this.setFileSizeLimit = params.fileSizeLimit; else this.fileSizeLimit = '30720'; 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.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.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.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.beginUploadOnQueue != 'undefined') this.beginUploadOnQueue = params.beginUploadOnQueue; else this.beginUploadOnQueue = false;
if(typeof params.fileQueued != 'undefined') this.fileQueued = params.fileQueued; 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.fileProgress != 'undefined') this.fileProgress = params.fileProgress; else this.fileProgress = Prototype.emptyFunction;
if(typeof params.fileCancelled != 'undefined') this.fileCancelled = params.fileCancelled; if(typeof params.fileCancelled != 'undefined') this.fileCancelled = params.fileCancelled;
if(typeof params.fileComplete != 'undefined') this.fileComplete = params.fileComplete ; if(typeof params.fileComplete != 'undefined') this.fileComplete = params.fileComplete ;
if(typeof params.queueComplete != 'undefined') this.queueComplete = params.queueComplete; if(typeof params.queueComplete != 'undefined') this.queueComplete = params.queueComplete;
if(typeof params.buildUI != 'undefined') this.customBuildUI = params.buildUI; if(typeof params.buildUI != 'undefined') this.customBuildUI = params.buildUI;
if(typeof params.securityID != 'undefined') this.securityID = params.securityID; if(typeof params.securityID != 'undefined') this.securityID = params.securityID;
this.onLoad(); this.onLoad();
}, },
/** /**
* Creates SWFUpload object for uploading files. * Creates SWFUpload object for uploading files.
* *
*/ */
onLoad: function() { onLoad: function() {
path = this.getBasePath(); path = this.getBasePath();
sessId = this.getSessionId();//Because flash doesn't send proper cookies, we need to set session id in URL. sessId = this.getSessionId();//Because flash doesn't send proper cookies, we need to set session id in URL.
this.swfu = new SWFUpload({ this.swfu = new SWFUpload({
upload_url: path + 'admin/assets/UploadForm?SecurityID=' + this.securityID + '&PHPSESSID=' + sessId, // Relative to the SWF file upload_url: path + 'admin/assets/UploadForm?SecurityID=' + this.securityID + '&PHPSESSID=' + sessId, // Relative to the SWF file
file_post_name: 'Files', file_post_name: 'Files',
file_size_limit : this.fileSizeLimit, file_size_limit : this.fileSizeLimit,
file_types : this.fileTypes, file_types : this.fileTypes,
file_types_description : this.fileTypesDescription, file_types_description : this.fileTypesDescription,
file_upload_limit : this.fileUploadLimit, file_upload_limit : this.fileUploadLimit,
begin_upload_on_queue : this.beginUploadOnQueue, begin_upload_on_queue : this.beginUploadOnQueue,
use_server_data_event : true, use_server_data_event : true,
validate_files: false, validate_files: false,
file_queued_handler : this.uploadFileQueuedCallback.bind(this), file_queued_handler : this.uploadFileQueuedCallback.bind(this),
upload_success_handler : this.uploadFileCompleteCallback.bind(this), upload_success_handler : this.uploadFileCompleteCallback.bind(this),
upload_progress_handler: this.uploadFileProgressCallback.bind(this), upload_progress_handler: this.uploadFileProgressCallback.bind(this),
error_handler : this.uploadErrorCallback.bind(this), error_handler : this.uploadErrorCallback.bind(this),
file_validation_handler : Prototype.emptyFunction, file_validation_handler : Prototype.emptyFunction,
file_cancelled_handler: Prototype.emptyFunction, file_cancelled_handler: Prototype.emptyFunction,
flash_url : 'jsparty/SWFUpload/swfupload_f9.swf', // Relative to this file flash_url : 'jsparty/SWFUpload/swfupload_f9.swf', // Relative to this file
swfupload_loaded_handler: this.buildUI.bind(this), swfupload_loaded_handler: this.buildUI.bind(this),
debug: false debug: false
}); });
}, },
/** /**
* Retrieves base path from URL. * Retrieves base path from URL.
* TODO: Use base tag. * TODO: Use base tag.
*/ */
getBasePath: function() { getBasePath: function() {
var path = 'http://' + window.location.host + window.location.pathname; var path = 'http://' + window.location.host + window.location.pathname;
if(path.match(/^(.*\/)admin/i)) return RegExp.$1; if(path.match(/^(.*\/)admin/i)) return RegExp.$1;
else return path; else return path;
}, },
/** /**
* Retrieves sessionId from cookie. * Retrieves sessionId from cookie.
* *
*/ */
getSessionId: function() { getSessionId: function() {
var start = document.cookie.indexOf('PHPSESSID')+10; var start = document.cookie.indexOf('PHPSESSID')+10;
var end = document.cookie.indexOf(';',start); var end = document.cookie.indexOf(';',start);
if(end == -1) end = document.cookie.length; if(end == -1) end = document.cookie.length;
return document.cookie.substring(start,end); return document.cookie.substring(start,end);
}, },
/** /**
* Calls method defined by user, method should create user interface. * Calls method defined by user, method should create user interface.
* *
*/ */
buildUI: function() { buildUI: function() {
this.customBuildUI(); this.customBuildUI();
}, },
/** /**
* Called when new file is added to the queue * Called when new file is added to the queue
* *
* @param file object * @param file object
* @param queueLength int * @param queueLength int
*/ */
uploadFileQueuedCallback: function(file,queueLength) { uploadFileQueuedCallback: function(file,queueLength) {
this.filesToUpload++; this.filesToUpload++;
this.fileQueued(file, queueLength); this.fileQueued(file, queueLength);
this.addFileParam(file); this.addFileParam(file);
}, },
/** /**
* Called when uploading of particular file has finished * Called when uploading of particular file has finished
* *
* @param file object * @param file object
* @param servedData string * @param servedData string
*/ */
uploadFileCompleteCallback: function(file,serverData) { uploadFileCompleteCallback: function(file,serverData) {
this.filesUploaded++; this.filesUploaded++;
if(serverData) { if(serverData) {
var toEval = serverData.substr(serverData.indexOf('<script')); var toEval = serverData.substr(serverData.indexOf('<script'));
toEval = toEval.replace('<script type="text/javascript">',''); toEval = toEval.replace('<script type="text/javascript">','');
toEval = toEval.replace('</script>',''); toEval = toEval.replace('</script>','');
this.uploadMessage = toEval; this.uploadMessage = toEval;
} }
this.fileComplete(file, serverData); this.fileComplete(file, serverData);
@ -134,123 +134,123 @@ Upload.prototype = {
else { else {
this.queueComplete(); this.queueComplete();
this.uploadInProgress = false; this.uploadInProgress = false;
this.filesUploaded = 0; this.filesUploaded = 0;
this.filesToUpload = 0; this.filesToUpload = 0;
} }
}, },
/** /**
* Called during uploading file. * Called during uploading file.
* *
* @param file object * @param file object
* @param bytes_complete int * @param bytes_complete int
*/ */
uploadFileProgressCallback: function(file, bytes_complete) { uploadFileProgressCallback: function(file, bytes_complete) {
this.uploadInProgress = true; this.uploadInProgress = true;
this.fileProgress(file, bytes_complete); this.fileProgress(file, bytes_complete);
}, },
/** /**
* Called on error. * Called on error.
* @param error_code int * @param error_code int
* @param file object * @param file object
* @param message string * @param message string
*/ */
uploadErrorCallback: function(error_code, file, message) { uploadErrorCallback: function(error_code, file, message) {
this.swfu.cancelQueue(); this.swfu.cancelQueue();
switch(error_code) { switch(error_code) {
case SWFUpload.ERROR_CODE_HTTP_ERROR: 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); 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; break;
case SWFUpload.ERROR_CODE_IO_ERROR: 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); 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; break;
case SWFUpload.ERROR_CODE_SECURITY_ERROR: 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); 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; break;
case SWFUpload.ERROR_CODE_FILE_EXCEEDS_SIZE_LIMIT: case SWFUpload.ERROR_CODE_FILE_EXCEEDS_SIZE_LIMIT:
alert('Files cannot be bigger than ' + this.fileSizeLimit/1024 + ' MB.'); alert('Files cannot be bigger than ' + this.fileSizeLimit/1024 + ' MB.');
break; break;
case SWFUpload.ERROR_CODE_ZERO_BYTE_FILE: case SWFUpload.ERROR_CODE_ZERO_BYTE_FILE:
alert('Files cannot be empty'); alert('Files cannot be empty');
break; break;
case SWFUpload.ERROR_CODE_QUEUE_LIMIT_EXCEEDED: case SWFUpload.ERROR_CODE_QUEUE_LIMIT_EXCEEDED:
alert('You can only have six files in queue'); alert('You can only have six files in queue');
break; break;
case SWFUpload.ERROR_CODE_UPLOAD_FAILED: 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'); alert('You have encountered an error. File hasn\'t has been uploaded. Please hit the "Refresh" button in your web browser');
break; break;
case SWFUpload.ERROR_CODE_SPECIFIED_FILE_NOT_FOUND: 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'); alert('You have encountered an error. File hasn\'t has been uploaded. Please hit the "Refresh" button in your web browser');
break; break;
default: default:
alert('You have encountered an error. File hasn\'t has been uploaded. Please hit the "Refresh" button in your web browser'); 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 * Because we are on top of standard upload we need to add some POST vars that
* normally are being sent as part of form. * normally are being sent as part of form.
* *
* @param file object * @param file object
*/ */
addFileParam: function(file) { addFileParam: function(file) {
this.swfu.addFileParam(file.id,'ID',this.folderID); this.swfu.addFileParam(file.id,'ID',this.folderID);
this.swfu.addFileParam(file.id,'action_doUpload','1'); this.swfu.addFileParam(file.id,'action_doUpload','1');
this.swfu.addFileParam(file.id,'Files',file.name); this.swfu.addFileParam(file.id,'Files',file.name);
this.swfu.addFileParam(file.id,'MAX_FILE_SIZE','31457280'); this.swfu.addFileParam(file.id,'MAX_FILE_SIZE','31457280');
}, },
/** /**
* Starts file explorer. * Starts file explorer.
* *
*/ */
browse: function() { browse: function() {
this.swfu.selectFiles(); this.swfu.selectFiles();
}, },
/** /**
* Starts upload * Starts upload
* *
*/ */
startUpload: function() { startUpload: function() {
this.swfu.startUpload(); this.swfu.startUpload();
}, },
/** /**
* Cancels uploading of file. * Cancels uploading of file.
*/ */
cancelUpload: function(fileId) { cancelUpload: function(fileId) {
this.filesToUpload--; this.filesToUpload--;
this.swfu.cancelUpload(fileId); this.swfu.cancelUpload(fileId);
}, },
/* /*
* Getters and setters. * Getters and setters.
*/ */
setFolderID: function(id) { setFolderID: function(id) {
this.folderID = id; this.folderID = id;
}, },
getFilesUploaded: function() { getFilesUploaded: function() {
return this.filesUploaded; return this.filesUploaded;
}, },
getFilesToUpload: function() { getFilesToUpload: function() {
return this.filesToUpload; return this.filesToUpload;
}, },
getUploadMessage: function() { getUploadMessage: function() {
return this.uploadMessage; return this.uploadMessage;
}, },
isUploadInProgress: function() { isUploadInProgress: function() {
return this.uploadInProgress; return this.uploadInProgress;
} }
} }