Changeset 24364
- Timestamp:
- 11/25/09 02:09:07 (3 years ago)
- Files:
-
- plugins/sfImaginablePlugin/branches/experimental (modified) (1 prop)
- plugins/sfImaginablePlugin/branches/experimental/lib/helper/jQueryHelper.php (deleted)
- plugins/sfImaginablePlugin/branches/experimental/web/css/default.css (modified) (2 diffs)
- plugins/sfImaginablePlugin/branches/experimental/web/css/default_new.css (deleted)
- plugins/sfImaginablePlugin/branches/experimental/web/js/fileprogress.js (modified) (4 diffs)
- plugins/sfImaginablePlugin/branches/experimental/web/js/handlers.js (modified) (1 diff)
- plugins/sfImaginablePlugin/branches/experimental/web/js/old.compressed.SWFUpload.js.php (deleted)
- plugins/sfImaginablePlugin/branches/experimental/web/js/swfupload.js (modified) (33 diffs)
- plugins/sfImaginablePlugin/branches/experimental/web/swf/ExternalCall.as (modified) (3 diffs)
- plugins/sfImaginablePlugin/branches/experimental/web/swf/SWFUpload.as (modified) (40 diffs)
- plugins/sfImaginablePlugin/branches/experimental/web/swf/obj (deleted)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/sfImaginablePlugin/branches/experimental
- Property tsvn:logtemplate set to [sfImaginablePlugin]
plugins/sfImaginablePlugin/branches/experimental/web/css/default.css
r24360 r24364 1 code { 2 display: block; 3 background:#edffb8 none repeat scroll 0%; 4 border-color:#b2da3a; 5 border-style:solid; 6 border-width:1px 0; 7 font-size: 1em; 8 margin: 1em 0pt; 9 overflow:auto; 10 padding: 0.3em 0.4em; 11 white-space:pre; 12 } 13 1 14 /* -- Layout ------------------------------- */ 15 /* hide link text */ 16 #logo a { 17 display: block; 18 color: #fff; 19 text-indent: -5000px; 20 overflow: hidden; 21 height: 106px; 22 width: 272px; 23 } 24 25 #version { 26 color: #fff; 27 position: absolute; 28 right: 20px; 29 top: 85px; 30 } 31 32 33 #content { width: 680px;} 34 #content { margin: 20px 90px; } 35 36 37 38 39 /* -- Form Styles ------------------------------- */ 40 form { 41 margin: 0; 42 padding: 0; 43 } 2 44 3 45 … … 52 94 display:block; 53 95 margin-right: 5px; 54 } 55 56 57 58 /* 59 Default style definitions for: 60 61 Uploadify v1.6.2 62 Copyright (C) 2009 by Ronnie Garcia 63 Co-developed by Travis Nickels 64 */ 65 .fileUploadQueueItem { 66 font: 11px Verdana, Geneva, sans-serif; 67 background-color: #F5F5F5; 68 border: 3px solid #E5E5E5; 69 margin-top: 5px; 70 padding: 10px; 71 width: 300px; 72 } 73 .fileUploadQueueItem .cancel { 96 } 97 98 #btnSubmit { margin: 0 0 0 155px ; } 99 100 /* -- Table Styles ------------------------------- */ 101 td { 102 font: 10pt Helvetica, Arial, sans-serif; 103 vertical-align: top; 104 } 105 106 .progressWrapper { 107 width: 357px; 108 overflow: hidden; 109 } 110 111 .progressContainer { 112 margin: 5px; 113 padding: 4px; 114 border: solid 1px #E8E8E8; 115 background-color: #F7F7F7; 116 overflow: hidden; 117 } 118 /* Message */ 119 .message { 120 margin: 1em 0; 121 padding: 10px 20px; 122 border: solid 1px #FFDD99; 123 background-color: #FFFFCC; 124 overflow: hidden; 125 } 126 /* Error */ 127 .red { 128 border: solid 1px #B50000; 129 background-color: #FFEBEB; 130 } 131 132 /* Current */ 133 .green { 134 border: solid 1px #DDF0DD; 135 background-color: #EBFFEB; 136 } 137 138 /* Complete */ 139 .blue { 140 border: solid 1px #CEE2F2; 141 background-color: #F0F5FF; 142 } 143 144 .progressName { 145 font-size: 8pt; 146 font-weight: 700; 147 color: #555; 148 width: 323px; 149 height: 14px; 150 text-align: left; 151 white-space: nowrap; 152 overflow: hidden; 153 } 154 155 .progressBarInProgress, 156 .progressBarComplete, 157 .progressBarError { 158 font-size: 0; 159 width: 0%; 160 height: 2px; 161 background-color: blue; 162 margin-top: 2px; 163 } 164 165 .progressBarComplete { 166 width: 100%; 167 background-color: green; 168 visibility: hidden; 169 } 170 171 .progressBarError { 172 width: 100%; 173 background-color: red; 174 visibility: hidden; 175 } 176 177 .progressBarStatus { 178 margin-top: 2px; 179 width: 337px; 180 font-size: 7pt; 181 font-family: Arial; 182 text-align: left; 183 white-space: nowrap; 184 } 185 186 a.progressCancel { 187 font-size: 0; 188 display: block; 189 height: 14px; 190 width: 14px; 191 background-image: url(../images/cancelbutton.gif); 192 background-repeat: no-repeat; 193 background-position: -14px 0px; 74 194 float: right; 75 195 } 76 .fileUploadProgress { 77 background-color: #FFFFFF; 78 border-top: 1px solid #808080; 79 border-left: 1px solid #808080; 80 border-right: 1px solid #C5C5C5; 81 border-bottom: 1px solid #C5C5C5; 82 margin-top: 10px; 83 width: 100%; 84 } 85 .fileUploadProgressBar { 86 background-color: #0099FF; 87 } 88 89 90 91 92 /* 93 sfImaginable extra styles 94 */ 95 96 #indicator{ 97 display:none; 98 margin: auto; 99 vertical-align:middle; 100 } 101 102 .loading-error{ 103 background-color: #FFFF66; 104 border-top: solid 4px #FF9966; 105 border-bottom: solid 4px #FF9966; 106 margin: 10px 25px; 107 padding: 10px 15px; 108 } 109 110 div.loading-error{ 111 display: none; 112 } 113 114 div.sfImaginable_list_record{ 115 width: 100%; 116 height: 97px; 117 } 118 119 div.sfImaginable_list_record-highlight{ 120 width: 100%; 121 height: 97px; 122 background-color: #FFFF66; 123 } 124 125 div.sfImaginable_list_record p{ 126 margin-left: 90px; 127 margin-bottom: 10px 128 } 196 197 a.progressCancel:hover { 198 background-position: 0px 0px; 199 } 200 201 202 /* -- SWFUpload Object Styles ------------------------------- */ 203 .swfupload { 204 vertical-align: top; 205 } plugins/sfImaginablePlugin/branches/experimental/web/js/fileprogress.js
r24360 r24364 1 1 /* 2 A simple class for displaying file information and progress3 Note: This is a demonstration only and not part of SWFUpload.4 Note: Some have had problems adapting this class in IE7. It may not be suitable for your application.2 A simple class for displaying file information and progress 3 Note: This is a demonstration only and not part of SWFUpload. 4 Note: Some have had problems adapting this class in IE7. It may not be suitable for your application. 5 5 */ 6 6 … … 10 10 // Instantiating a new FileProgress object with an existing file will reuse/update the existing DOM elements 11 11 function FileProgress(file, targetID) { 12 this.fileProgressID = file.id;13 14 this.opacity = 100;15 this.height = 0;16 17 18 this.fileProgressWrapper = document.getElementById(this.fileProgressID);19 if (!this.fileProgressWrapper) {20 this.fileProgressWrapper = document.createElement("div");21 this.fileProgressWrapper.className = "progressWrapper";22 this.fileProgressWrapper.id = this.fileProgressID;23 24 this.fileProgressElement = document.createElement("div");25 this.fileProgressElement.className = "progressContainer";26 27 var progressCancel = document.createElement("a");28 progressCancel.className = "progressCancel";29 progressCancel.href = "#";30 progressCancel.style.visibility = "hidden";31 progressCancel.appendChild(document.createTextNode(" "));32 33 var progressText = document.createElement("div");34 progressText.className = "progressName";35 progressText.appendChild(document.createTextNode(file.name));36 37 var progressBar = document.createElement("div");38 progressBar.className = "progressBarInProgress";39 40 var progressStatus = document.createElement("div");41 progressStatus.className = "progressBarStatus";42 progressStatus.innerHTML = " ";43 44 this.fileProgressElement.appendChild(progressCancel);45 this.fileProgressElement.appendChild(progressText);46 this.fileProgressElement.appendChild(progressStatus);47 this.fileProgressElement.appendChild(progressBar);48 49 this.fileProgressWrapper.appendChild(this.fileProgressElement);50 51 document.getElementById(targetID).appendChild(this.fileProgressWrapper);52 } else {53 this.fileProgressElement = this.fileProgressWrapper.firstChild;54 this.reset();55 }56 57 this.height = this.fileProgressWrapper.offsetHeight;58 this.setTimer(null);12 this.fileProgressID = file.id; 13 14 this.opacity = 100; 15 this.height = 0; 16 17 18 this.fileProgressWrapper = document.getElementById(this.fileProgressID); 19 if (!this.fileProgressWrapper) { 20 this.fileProgressWrapper = document.createElement("div"); 21 this.fileProgressWrapper.className = "progressWrapper"; 22 this.fileProgressWrapper.id = this.fileProgressID; 23 24 this.fileProgressElement = document.createElement("div"); 25 this.fileProgressElement.className = "progressContainer"; 26 27 var progressCancel = document.createElement("a"); 28 progressCancel.className = "progressCancel"; 29 progressCancel.href = "#"; 30 progressCancel.style.visibility = "hidden"; 31 progressCancel.appendChild(document.createTextNode(" ")); 32 33 var progressText = document.createElement("div"); 34 progressText.className = "progressName"; 35 progressText.appendChild(document.createTextNode(file.name)); 36 37 var progressBar = document.createElement("div"); 38 progressBar.className = "progressBarInProgress"; 39 40 var progressStatus = document.createElement("div"); 41 progressStatus.className = "progressBarStatus"; 42 progressStatus.innerHTML = " "; 43 44 this.fileProgressElement.appendChild(progressCancel); 45 this.fileProgressElement.appendChild(progressText); 46 this.fileProgressElement.appendChild(progressStatus); 47 this.fileProgressElement.appendChild(progressBar); 48 49 this.fileProgressWrapper.appendChild(this.fileProgressElement); 50 51 document.getElementById(targetID).appendChild(this.fileProgressWrapper); 52 } else { 53 this.fileProgressElement = this.fileProgressWrapper.firstChild; 54 this.reset(); 55 } 56 57 this.height = this.fileProgressWrapper.offsetHeight; 58 this.setTimer(null); 59 59 60 60 … … 62 62 63 63 FileProgress.prototype.setTimer = function (timer) { 64 this.fileProgressElement["FP_TIMER"] = timer;64 this.fileProgressElement["FP_TIMER"] = timer; 65 65 }; 66 66 FileProgress.prototype.getTimer = function (timer) { 67 return this.fileProgressElement["FP_TIMER"] || null;67 return this.fileProgressElement["FP_TIMER"] || null; 68 68 }; 69 69 70 70 FileProgress.prototype.reset = function () { 71 this.fileProgressElement.className = "progressContainer";72 73 this.fileProgressElement.childNodes[2].innerHTML = " ";74 this.fileProgressElement.childNodes[2].className = "progressBarStatus";75 76 this.fileProgressElement.childNodes[3].className = "progressBarInProgress";77 this.fileProgressElement.childNodes[3].style.width = "0%";78 79 this.appear(); 71 this.fileProgressElement.className = "progressContainer"; 72 73 this.fileProgressElement.childNodes[2].innerHTML = " "; 74 this.fileProgressElement.childNodes[2].className = "progressBarStatus"; 75 76 this.fileProgressElement.childNodes[3].className = "progressBarInProgress"; 77 this.fileProgressElement.childNodes[3].style.width = "0%"; 78 79 this.appear(); 80 80 }; 81 81 82 82 FileProgress.prototype.setProgress = function (percentage) { 83 this.fileProgressElement.className = "progressContainer green";84 this.fileProgressElement.childNodes[3].className = "progressBarInProgress";85 this.fileProgressElement.childNodes[3].style.width = percentage + "%";86 87 this.appear(); 83 this.fileProgressElement.className = "progressContainer green"; 84 this.fileProgressElement.childNodes[3].className = "progressBarInProgress"; 85 this.fileProgressElement.childNodes[3].style.width = percentage + "%"; 86 87 this.appear(); 88 88 }; 89 89 FileProgress.prototype.setComplete = function () { 90 this.fileProgressElement.className = "progressContainer blue";91 this.fileProgressElement.childNodes[3].className = "progressBarComplete";92 this.fileProgressElement.childNodes[3].style.width = "";93 94 var oSelf = this;95 this.setTimer(setTimeout(function () {96 oSelf.disappear();97 }, 10000));90 this.fileProgressElement.className = "progressContainer blue"; 91 this.fileProgressElement.childNodes[3].className = "progressBarComplete"; 92 this.fileProgressElement.childNodes[3].style.width = ""; 93 94 var oSelf = this; 95 this.setTimer(setTimeout(function () { 96 oSelf.disappear(); 97 }, 10000)); 98 98 }; 99 99 FileProgress.prototype.setError = function () { 100 this.fileProgressElement.className = "progressContainer red";101 this.fileProgressElement.childNodes[3].className = "progressBarError";102 this.fileProgressElement.childNodes[3].style.width = "";103 104 var oSelf = this;105 this.setTimer(setTimeout(function () {106 oSelf.disappear();107 }, 5000));100 this.fileProgressElement.className = "progressContainer red"; 101 this.fileProgressElement.childNodes[3].className = "progressBarError"; 102 this.fileProgressElement.childNodes[3].style.width = ""; 103 104 var oSelf = this; 105 this.setTimer(setTimeout(function () { 106 oSelf.disappear(); 107 }, 5000)); 108 108 }; 109 109 FileProgress.prototype.setCancelled = function () { 110 this.fileProgressElement.className = "progressContainer";111 this.fileProgressElement.childNodes[3].className = "progressBarError";112 this.fileProgressElement.childNodes[3].style.width = "";113 114 var oSelf = this;115 this.setTimer(setTimeout(function () {116 oSelf.disappear();117 }, 2000));110 this.fileProgressElement.className = "progressContainer"; 111 this.fileProgressElement.childNodes[3].className = "progressBarError"; 112 this.fileProgressElement.childNodes[3].style.width = ""; 113 114 var oSelf = this; 115 this.setTimer(setTimeout(function () { 116 oSelf.disappear(); 117 }, 2000)); 118 118 }; 119 119 FileProgress.prototype.setStatus = function (status) { 120 this.fileProgressElement.childNodes[2].innerHTML = status;120 this.fileProgressElement.childNodes[2].innerHTML = status; 121 121 }; 122 122 123 123 // Show/Hide the cancel button 124 124 FileProgress.prototype.toggleCancel = function (show, swfUploadInstance) { 125 this.fileProgressElement.childNodes[0].style.visibility = show ? "visible" : "hidden";126 if (swfUploadInstance) {127 var fileID = this.fileProgressID;128 this.fileProgressElement.childNodes[0].onclick = function () {129 swfUploadInstance.cancelUpload(fileID);130 return false;131 };132 }125 this.fileProgressElement.childNodes[0].style.visibility = show ? "visible" : "hidden"; 126 if (swfUploadInstance) { 127 var fileID = this.fileProgressID; 128 this.fileProgressElement.childNodes[0].onclick = function () { 129 swfUploadInstance.cancelUpload(fileID); 130 return false; 131 }; 132 } 133 133 }; 134 134 135 135 FileProgress.prototype.appear = function () { 136 if (this.getTimer() !== null) {137 clearTimeout(this.getTimer());138 this.setTimer(null);139 }140 141 if (this.fileProgressWrapper.filters) {142 try {143 this.fileProgressWrapper.filters.item("DXImageTransform.Microsoft.Alpha").opacity = 100;144 } catch (e) {145 // If it is not set initially, the browser will throw an error. This will set it if it is not set yet.146 this.fileProgressWrapper.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=100)";147 }148 } else {149 this.fileProgressWrapper.style.opacity = 1;150 }151 152 this.fileProgressWrapper.style.height = "";153 154 this.height = this.fileProgressWrapper.offsetHeight;155 this.opacity = 100;156 this.fileProgressWrapper.style.display = "";157 136 if (this.getTimer() !== null) { 137 clearTimeout(this.getTimer()); 138 this.setTimer(null); 139 } 140 141 if (this.fileProgressWrapper.filters) { 142 try { 143 this.fileProgressWrapper.filters.item("DXImageTransform.Microsoft.Alpha").opacity = 100; 144 } catch (e) { 145 // If it is not set initially, the browser will throw an error. This will set it if it is not set yet. 146 this.fileProgressWrapper.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=100)"; 147 } 148 } else { 149 this.fileProgressWrapper.style.opacity = 1; 150 } 151 152 this.fileProgressWrapper.style.height = ""; 153 154 this.height = this.fileProgressWrapper.offsetHeight; 155 this.opacity = 100; 156 this.fileProgressWrapper.style.display = ""; 157 158 158 }; 159 159 … … 161 161 FileProgress.prototype.disappear = function () { 162 162 163 var reduceOpacityBy = 15;164 var reduceHeightBy = 4;165 var rate = 30;// 15 fps166 167 if (this.opacity > 0) {168 this.opacity -= reduceOpacityBy;169 if (this.opacity < 0) {170 this.opacity = 0;171 }172 173 if (this.fileProgressWrapper.filters) {174 try {175 this.fileProgressWrapper.filters.item("DXImageTransform.Microsoft.Alpha").opacity = this.opacity;176 } catch (e) {177 // If it is not set initially, the browser will throw an error. This will set it if it is not set yet.178 this.fileProgressWrapper.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=" + this.opacity + ")";179 }180 } else {181 this.fileProgressWrapper.style.opacity = this.opacity / 100;182 }183 }184 185 if (this.height > 0) {186 this.height -= reduceHeightBy;187 if (this.height < 0) {188 this.height = 0;189 }190 191 this.fileProgressWrapper.style.height = this.height + "px";192 }193 194 if (this.height > 0 || this.opacity > 0) {195 var oSelf = this;196 this.setTimer(setTimeout(function () {197 oSelf.disappear();198 }, rate));199 } else {200 this.fileProgressWrapper.style.display = "none";201 this.setTimer(null);202 }203 }; 163 var reduceOpacityBy = 15; 164 var reduceHeightBy = 4; 165 var rate = 30; // 15 fps 166 167 if (this.opacity > 0) { 168 this.opacity -= reduceOpacityBy; 169 if (this.opacity < 0) { 170 this.opacity = 0; 171 } 172 173 if (this.fileProgressWrapper.filters) { 174 try { 175 this.fileProgressWrapper.filters.item("DXImageTransform.Microsoft.Alpha").opacity = this.opacity; 176 } catch (e) { 177 // If it is not set initially, the browser will throw an error. This will set it if it is not set yet. 178 this.fileProgressWrapper.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=" + this.opacity + ")"; 179 } 180 } else { 181 this.fileProgressWrapper.style.opacity = this.opacity / 100; 182 } 183 } 184 185 if (this.height > 0) { 186 this.height -= reduceHeightBy; 187 if (this.height < 0) { 188 this.height = 0; 189 } 190 191 this.fileProgressWrapper.style.height = this.height + "px"; 192 } 193 194 if (this.height > 0 || this.opacity > 0) { 195 var oSelf = this; 196 this.setTimer(setTimeout(function () { 197 oSelf.disappear(); 198 }, rate)); 199 } else { 200 this.fileProgressWrapper.style.display = "none"; 201 this.setTimer(null); 202 } 203 }; plugins/sfImaginablePlugin/branches/experimental/web/js/handlers.js
r24360 r24364 1 queueComplete = function (event, data){ 2 ajaxUpdateImageList(); 1 /* Demo Note: This demo uses a FileProgress class that handles the UI for displaying the file name and percent complete. 2 The FileProgress class is not part of SWFUpload. 3 */ 4 5 6 /* ********************** 7 Event Handlers 8 These are my custom event handlers to make my 9 web application behave the way I went when SWFUpload 10 completes different tasks. These aren't part of the SWFUpload 11 package. They are part of my application. Without these none 12 of the actions SWFUpload makes will show up in my application. 13 ********************** */ 14 15 function swfUploadPreLoad() { 16 var self = this; 17 var loading = function () { 18 //document.getElementById("divSWFUploadUI").style.display = "none"; 19 document.getElementById("divLoadingContent").style.display = ""; 20 21 var longLoad = function () { 22 document.getElementById("divLoadingContent").style.display = "none"; 23 document.getElementById("divLongLoading").style.display = ""; 24 }; 25 this.customSettings.loadingTimeout = setTimeout(function () { 26 longLoad.call(self) 27 }, 28 15 * 1000 29 ); 30 }; 31 32 this.customSettings.loadingTimeout = setTimeout(function () { 33 loading.call(self); 34 }, 35 1*1000 36 ); 37 } 38 function swfUploadLoaded() { 39 var self = this; 40 clearTimeout(this.customSettings.loadingTimeout); 41 //document.getElementById("divSWFUploadUI").style.visibility = "visible"; 42 //document.getElementById("divSWFUploadUI").style.display = "block"; 43 document.getElementById("divLoadingContent").style.display = "none"; 44 document.getElementById("divLongLoading").style.display = "none"; 45 document.getElementById("divAlternateContent").style.display = "none"; 46 47 //document.getElementById("btnBrowse").onclick = function () { self.selectFiles(); }; 48 document.getElementById("btnCancel").onclick = function () { self.cancelQueue(); }; 49 } 50 51 function swfUploadLoadFailed() { 52 clearTimeout(this.customSettings.loadingTimeout); 53 //document.getElementById("divSWFUploadUI").style.display = "none"; 54 document.getElementById("divLoadingContent").style.display = "none"; 55 document.getElementById("divLongLoading").style.display = "none"; 56 document.getElementById("divAlternateContent").style.display = ""; 57 } 58 59 60 function fileQueued(file) { 61 try { 62 var progress = new FileProgress(file, this.customSettings.progressTarget); 63 progress.setStatus("Pending..."); 64 progress.toggleCancel(true, this); 65 66 } catch (ex) { 67 this.debug(ex); 68 } 69 70 } 71 72 function fileQueueError(file, errorCode, message) { 73 try { 74 if (errorCode === SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED) { 75 alert("You have attempted to queue too many files.\n" + (message === 0 ? "You have reached the upload limit." : "You may select " + (message > 1 ? "up to " + message + " files." : "one file."))); 76 return; 77 } 78 79 var progress = new FileProgress(file, this.customSettings.progressTarget); 80 progress.setError(); 81 progress.toggleCancel(false); 82 83 switch (errorCode) { 84 case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT: 85 progress.setStatus("File is too big."); 86 this.debug("Error Code: File too big, File name: " + file.name + ", File size: " + file.size + ", Message: " + message); 87 break; 88 case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE: 89 progress.setStatus("Cannot upload Zero Byte files."); 90 this.debug("Error Code: Zero byte file, File name: " + file.name + ", File size: " + file.size + ", Message: " + message); 91 break; 92 case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE: 93 progress.setStatus("Invalid File Type."); 94 this.debug("Error Code: Invalid File Type, File name: " + file.name + ", File size: " + file.size + ", Message: " + message); 95 break; 96 default: 97 if (file !== null) { 98 progress.setStatus("Unhandled Error"); 99 } 100 this.debug("Error Code: " + errorCode + ", File name: " + file.name + ", File size: " + file.size + ", Message: " + message); 101 break; 102 } 103 } catch (ex) { 104 this.debug(ex); 105 } 106 } 107 108 function fileDialogComplete(numFilesSelected, numFilesQueued) { 109 try { 110 if (numFilesSelected > 0) { 111 document.getElementById(this.customSettings.cancelButtonId).disabled = false; 112 } 113 114 /* I want auto start the upload and I can do that here */ 115 this.startUpload(); 116 } catch (ex) { 117 this.debug(ex); 118 } 119 } 120 121 function uploadStart(file) { 122 try { 123 /* I don't want to do any file validation or anything, I'll just update the UI and 124 return true to indicate that the upload should start. 125 It's important to update the UI here because in Linux no uploadProgress events are called. The best 126 we can do is say we are uploading. 127 */ 128 var progress = new FileProgress(file, this.customSettings.progressTarget); 129 progress.setStatus("Uploading..."); 130 progress.toggleCancel(true, this); 131 } 132 catch (ex) {} 133 134 return true; 135 } 136 137 function uploadProgress(file, bytesLoaded, bytesTotal) { 138 try { 139 var percent = Math.ceil((bytesLoaded / bytesTotal) * 100); 140 141 var progress = new FileProgress(file, this.customSettings.progressTarget); 142 progress.setProgress(percent); 143 progress.setStatus("Uploading..."); 144 } catch (ex) { 145 this.debug(ex); 146 } 147 } 148 149 function uploadSuccess(file, serverData) { 150 try { 151 var progress = new FileProgress(file, this.customSettings.progressTarget); 152 progress.setComplete(); 153 progress.setStatus("Complete."); 154 progress.toggleCancel(false); 155 156 } catch (ex) { 157 this.debug(ex); 158 } 159 } 160 161 function uploadError(file, errorCode, message) { 162 try { 163 var progress = new FileProgress(file, this.customSettings.progressTarget); 164 progress.setError(); 165 progress.toggleCancel(false); 166 167 switch (errorCode) { 168 case SWFUpload.UPLOAD_ERROR.HTTP_ERROR: 169 progress.setStatus("Upload Error: " + message); 170 this.debug("Error Code: HTTP Error, File name: " + file.name + ", Message: " + message); 171 break; 172 case SWFUpload.UPLOAD_ERROR.UPLOAD_FAILED: 173 progress.setStatus("Upload Failed."); 174 this.debug("Error Code: Upload Failed, File name: " + file.name + ", File size: " + file.size + ", Message: " + message); 175 break; 176 case SWFUpload.UPLOAD_ERROR.IO_ERROR: 177 progress.setStatus("Server (IO) Error"); 178 this.debug("Error Code: IO Error, File name: " + file.name + ", Message: " + message); 179 break; 180 case SWFUpload.UPLOAD_ERROR.SECURITY_ERROR: 181 progress.setStatus("Security Error"); 182 this.debug("Error Code: Security Error, File name: " + file.name + ", Message: " + message); 183 break; 184 case SWFUpload.UPLOAD_ERROR.UPLOAD_LIMIT_EXCEEDED: 185 progress.setStatus("Upload limit exceeded."); 186 this.debug("Error Code: Upload Limit Exceeded, File name: " + file.name + ", File size: " + file.size + ", Message: " + message); 187 break; 188 case SWFUpload.UPLOAD_ERROR.FILE_VALIDATION_FAILED: 189 progress.setStatus("Failed Validation. Upload skipped."); 190 this.debug("Error Code: File Validation Failed, File name: " + file.name + ", File size: " + file.size + ", Message: " + message); 191 break; 192 case SWFUpload.UPLOAD_ERROR.FILE_CANCELLED: 193 // If there aren't any files left (they were all cancelled) disable the cancel button 194 if (this.getStats().files_queued === 0) { 195 document.getElementById(this.customSettings.cancelButtonId).disabled = true; 196 } 197 progress.setStatus("Cancelled"); 198 progress.setCancelled(); 199 break; 200 case SWFUpload.UPLOAD_ERROR.UPLOAD_STOPPED: 201 progress.setStatus("Stopped"); 202 break; 203 default: 204 progress.setStatus("Unhandled Error: " + errorCode); 205 this.debug("Error Code: " + errorCode + ", File name: " + file.name + ", File size: " + file.size + ", Message: " + message); 206 break; 207 } 208 } catch (ex) { 209 this.debug(ex); 210 } 211 } 212 213 function uploadComplete(file) { 214 if (this.getStats().files_queued === 0) { 215 document.getElementById(this.customSettings.cancelButtonId).disabled = true; 216 } 217 } 218 219 // This event comes from the Queue Plugin 220 function queueComplete(numFilesUploaded) { 221 var status = document.getElementById("divStatus"); 222 status.innerHTML = numFilesUploaded + " file" + (numFilesUploaded === 1 ? "" : "s") + " uploaded."; 223 ajaxUpdateImageList(); 3 224 }; 4 225 5 function echoInfo(event, queueID, fileObj, response, data) 6 { 7 alert('lol'); 8 alert(response); 9 } 10 /* 226 11 227 function ajaxUpdateImageList() { 12 //new Ajax.Updater('ajax-image-list', '/backend.php/sfImaginable/ajaxList', {asynchronous:true, evalScripts:true, parameters:'object_class=' + object_class + '&object_id=' + object_id }); 13 jQuery('#ajax-image-list').load('/backend.php/sfImaginable/ajaxList', {'object_class' = object_class, 'object_id' = object_id}); 228 new Ajax.Updater('ajax-image-list', ajax_url, {asynchronous:true, evalScripts:true, parameters:'object_class=' + object_class + '&object_id=' + object_id }); 14 229 return false; 15 230 }; 16 */plugins/sfImaginablePlugin/branches/experimental/web/js/swfupload.js
r24360 r24364 4 4 * mmSWFUpload 1.0: Flash upload dialog - http://profandesign.se/swfupload/, http://www.vinterwebb.se/ 5 5 * 6 * SWFUpload is (c) 2006-2007 Lars Huring, Olov Nilz ?nand Mammon Media and is released under the MIT License:6 * SWFUpload is (c) 2006-2007 Lars Huring, Olov Nilz�and Mammon Media and is released under the MIT License: 7 7 * http://www.opensource.org/licenses/mit-license.php 8 8 * … … 19 19 20 20 if (SWFUpload == undefined) { 21 SWFUpload = function (settings) {22 this.initSWFUpload(settings);23 };21 SWFUpload = function (settings) { 22 this.initSWFUpload(settings); 23 }; 24 24 } 25 25 26 26 SWFUpload.prototype.initSWFUpload = function (settings) { 27 try {28 this.customSettings = {};// A container where developers can place their own settings associated with this instance.29 this.settings = settings;30 this.eventQueue = [];31 this.movieName = "SWFUpload_" + SWFUpload.movieCount++;32 this.movieElement = null;33 34 35 // Setup global control tracking36 SWFUpload.instances[this.movieName] = this;37 38 // Load the settings. Load the Flash movie.39 this.initSettings();40 this.loadFlash();41 this.displayDebugInfo();42 } catch (ex) {43 delete SWFUpload.instances[this.movieName];44 throw ex;45 }27 try { 28 this.customSettings = {}; // A container where developers can place their own settings associated with this instance. 29 this.settings = settings; 30 this.eventQueue = []; 31 this.movieName = "SWFUpload_" + SWFUpload.movieCount++; 32 this.movieElement = null; 33 34 35 // Setup global control tracking 36 SWFUpload.instances[this.movieName] = this; 37 38 // Load the settings. Load the Flash movie. 39 this.initSettings(); 40 this.loadFlash(); 41 this.displayDebugInfo(); 42 } catch (ex) { 43 delete SWFUpload.instances[this.movieName]; 44 throw ex; 45 } 46 46 }; 47 47 … … 53 53 SWFUpload.version = "2.2.0 2009-03-25"; 54 54 SWFUpload.QUEUE_ERROR = { 55 QUEUE_LIMIT_EXCEEDED: -100,56 FILE_EXCEEDS_SIZE_LIMIT: -110,57 ZERO_BYTE_FILE: -120,58 INVALID_FILETYPE: -13055 QUEUE_LIMIT_EXCEEDED : -100, 56 FILE_EXCEEDS_SIZE_LIMIT : -110, 57 ZERO_BYTE_FILE : -120, 58 INVALID_FILETYPE : -130 59 59 }; 60 60 SWFUpload.UPLOAD_ERROR = { 61 HTTP_ERROR: -200,62 MISSING_UPLOAD_URL: -210,63 IO_ERROR: -220,64 SECURITY_ERROR: -230,65 UPLOAD_LIMIT_EXCEEDED: -240,66 UPLOAD_FAILED: -250,67 SPECIFIED_FILE_ID_NOT_FOUND: -260,68 FILE_VALIDATION_FAILED: -270,69 FILE_CANCELLED: -280,70 UPLOAD_STOPPED: -29061 HTTP_ERROR : -200, 62 MISSING_UPLOAD_URL : -210, 63 IO_ERROR : -220, 64 SECURITY_ERROR : -230, 65 UPLOAD_LIMIT_EXCEEDED : -240, 66 UPLOAD_FAILED : -250, 67 SPECIFIED_FILE_ID_NOT_FOUND : -260, 68 FILE_VALIDATION_FAILED : -270, 69 FILE_CANCELLED : -280, 70 UPLOAD_STOPPED : -290 71 71 }; 72 72 SWFUpload.FILE_STATUS = { 73 QUEUED: -1,74 IN_PROGRESS: -2,75 ERROR: -3,76 COMPLETE: -4,77 CANCELLED: -573 QUEUED : -1, 74 IN_PROGRESS : -2, 75 ERROR : -3, 76 COMPLETE : -4, 77 CANCELLED : -5 78 78 }; 79 79 SWFUpload.BUTTON_ACTION = { 80 SELECT_FILE : -100,81 SELECT_FILES : -110,82 START_UPLOAD : -12080 SELECT_FILE : -100, 81 SELECT_FILES : -110, 82 START_UPLOAD : -120 83 83 }; 84 84 SWFUpload.CURSOR = { 85 ARROW : -1,86 HAND : -285 ARROW : -1, 86 HAND : -2 87 87 }; 88 88 SWFUpload.WINDOW_MODE = { 89 WINDOW : "window",90 TRANSPARENT : "transparent",91 OPAQUE : "opaque"89 WINDOW : "window", 90 TRANSPARENT : "transparent", 91 OPAQUE : "opaque" 92 92 }; 93 93 … … 95 95 // using the current site. Only processes the URL if it can, otherwise returns the URL untouched 96 96 SWFUpload.completeURL = function(url) { 97 if (typeof(url) !== "string" || url.match(/^https?:\/\//i) || url.match(/^\//)) {98 return url;99 }100 101 var currentURL = window.location.protocol + "//" + window.location.hostname + (window.location.port ? ":" + window.location.port : "");102 103 var indexSlash = window.location.pathname.lastIndexOf("/");104 if (indexSlash <= 0) {105 path = "/";106 } else {107 path = window.location.pathname.substr(0, indexSlash) + "/";108 }109 110 return /*currentURL +*/ path + url;111 97 if (typeof(url) !== "string" || url.match(/^https?:\/\//i) || url.match(/^\//)) { 98 return url; 99 } 100 101 var currentURL = window.location.protocol + "//" + window.location.hostname + (window.location.port ? ":" + window.location.port : ""); 102 103 var indexSlash = window.location.pathname.lastIndexOf("/"); 104 if (indexSlash <= 0) { 105 path = "/"; 106 } else { 107 path = window.location.pathname.substr(0, indexSlash) + "/"; 108 } 109 110 return /*currentURL +*/ path + url; 111 112 112 }; 113 113 … … 120 120 // settings are set, getting a default value if one was not assigned. 121 121 SWFUpload.prototype.initSettings = function () { 122 this.ensureDefault = function (settingName, defaultValue) {123 this.settings[settingName] = (this.settings[settingName] == undefined) ? defaultValue : this.settings[settingName];124 };125 126 // Upload backend settings127 this.ensureDefault("upload_url", "");128 this.ensureDefault("preserve_relative_urls", false);129 this.ensureDefault("file_post_name", "Filedata");130 this.ensureDefault("post_params", {});131 this.ensureDefault("use_query_string", false);132 this.ensureDefault("requeue_on_error", false);133 this.ensureDefault("http_success", []);134 this.ensureDefault("assume_success_timeout", 0);135 136 // File Settings137 this.ensureDefault("file_types", "*.*");138 this.ensureDefault("file_types_description", "All Files");139 this.ensureDefault("file_size_limit", 0);// Default zero means "unlimited"140 this.ensureDefault("file_upload_limit", 0);141 this.ensureDefault("file_queue_limit", 0);142 143 // Flash Settings144 this.ensureDefault("flash_url", "swfupload.swf");145 this.ensureDefault("prevent_swf_caching", true);146 147 // Button Settings148 this.ensureDefault("button_image_url", "");149 this.ensureDefault("button_width", 1);150 this.ensureDefault("button_height", 1);151 this.ensureDefault("button_text", "");152 this.ensureDefault("button_text_style", "color: #000000; font-size: 16pt;");153 this.ensureDefault("button_text_top_padding", 0);154 this.ensureDefault("button_text_left_padding", 0);155 this.ensureDefault("button_action", SWFUpload.BUTTON_ACTION.SELECT_FILES);156 this.ensureDefault("button_disabled", false);157 this.ensureDefault("button_placeholder_id", "");158 this.ensureDefault("button_placeholder", null);159 this.ensureDefault("button_cursor", SWFUpload.CURSOR.ARROW);160 this.ensureDefault("button_window_mode", SWFUpload.WINDOW_MODE.WINDOW);161 162 // Debug Settings163 this.ensureDefault("debug", false);164 this.settings.debug_enabled = this.settings.debug;// Here to maintain v2 API165 166 // Event Handlers167 this.settings.return_upload_start_handler = this.returnUploadStart;168 this.ensureDefault("swfupload_loaded_handler", null);169 this.ensureDefault("file_dialog_start_handler", null);170 this.ensureDefault("file_queued_handler", null);171 this.ensureDefault("file_queue_error_handler", null);172 this.ensureDefault("file_dialog_complete_handler", null);173 174 this.ensureDefault("upload_start_handler", null);175 this.ensureDefault("upload_progress_handler", null);176 this.ensureDefault("upload_error_handler", null);177 this.ensureDefault("upload_success_handler", null);178 this.ensureDefault("upload_complete_handler", null);179 180 this.ensureDefault("debug_handler", this.debugMessage);181 182 this.ensureDefault("custom_settings", {});183 184 // Other settings185 this.customSettings = this.settings.custom_settings;186 187 // Update the flash url if needed188 if (!!this.settings.prevent_swf_caching) {189 this.settings.flash_url = this.settings.flash_url + (this.settings.flash_url.indexOf("?") < 0 ? "?" : "&") + "preventswfcaching=" + new Date().getTime();190 }191 192 if (!this.settings.preserve_relative_urls) {193 //this.settings.flash_url = SWFUpload.completeURL(this.settings.flash_url);// Don't need to do this one since flash doesn't look at it194 this.settings.upload_url = SWFUpload.completeURL(this.settings.upload_url);195 this.settings.button_image_url = SWFUpload.completeURL(this.settings.button_image_url);196 }197 198 delete this.ensureDefault;122 this.ensureDefault = function (settingName, defaultValue) { 123 this.settings[settingName] = (this.settings[settingName] == undefined) ? defaultValue : this.settings[settingName]; 124 }; 125 126 // Upload backend settings 127 this.ensureDefault("upload_url", ""); 128 this.ensureDefault("preserve_relative_urls", false); 129 this.ensureDefault("file_post_name", "Filedata"); 130 this.ensureDefault("post_params", {}); 131 this.ensureDefault("use_query_string", false); 132 this.ensureDefault("requeue_on_error", false); 133 this.ensureDefault("http_success", []); 134 this.ensureDefault("assume_success_timeout", 0); 135 136 // File Settings 137 this.ensureDefault("file_types", "*.*"); 138 this.ensureDefault("file_types_description", "All Files"); 139 this.ensureDefault("file_size_limit", 0); // Default zero means "unlimited" 140 this.ensureDefault("file_upload_limit", 0); 141 this.ensureDefault("file_queue_limit", 0); 142 143 // Flash Settings 144 this.ensureDefault("flash_url", "swfupload.swf"); 145 this.ensureDefault("prevent_swf_caching", true); 146 147 // Button Settings 148 this.ensureDefault("button_image_url", ""); 149 this.ensureDefault("button_width", 1); 150 this.ensureDefault("button_height", 1); 151 this.ensureDefault("button_text", ""); 152 this.ensureDefault("button_text_style", "color: #000000; font-size: 16pt;"); 153 this.ensureDefault("button_text_top_padding", 0); 154 this.ensureDefault("button_text_left_padding", 0); 155 this.ensureDefault("button_action", SWFUpload.BUTTON_ACTION.SELECT_FILES); 156 this.ensureDefault("button_disabled", false); 157 this.ensureDefault("button_placeholder_id", ""); 158 this.ensureDefault("button_placeholder", null); 159 this.ensureDefault("button_cursor", SWFUpload.CURSOR.ARROW); 160 this.ensureDefault("button_window_mode", SWFUpload.WINDOW_MODE.WINDOW); 161 162 // Debug Settings 163 this.ensureDefault("debug", false); 164 this.settings.debug_enabled = this.settings.debug; // Here to maintain v2 API 165 166 // Event Handlers 167 this.settings.return_upload_start_handler = this.returnUploadStart; 168 this.ensureDefault("swfupload_loaded_handler", null); 169 this.ensureDefault("file_dialog_start_handler", null); 170 this.ensureDefault("file_queued_handler", null); 171 this.ensureDefault("file_queue_error_handler", null); 172 this.ensureDefault("file_dialog_complete_handler", null); 173 174 this.ensureDefault("upload_start_handler", null); 175 this.ensureDefault("upload_progress_handler", null); 176 this.ensureDefault("upload_error_handler", null); 177 this.ensureDefault("upload_success_handler", null); 178 this.ensureDefault("upload_complete_handler", null); 179 180 this.ensureDefault("debug_handler", this.debugMessage); 181 182 this.ensureDefault("custom_settings", {}); 183 184 // Other settings 185 this.customSettings = this.settings.custom_settings; 186 187 // Update the flash url if needed 188 if (!!this.settings.prevent_swf_caching) { 189 this.settings.flash_url = this.settings.flash_url + (this.settings.flash_url.indexOf("?") < 0 ? "?" : "&") + "preventswfcaching=" + new Date().getTime(); 190 } 191 192 if (!this.settings.preserve_relative_urls) { 193 //this.settings.flash_url = SWFUpload.completeURL(this.settings.flash_url); // Don't need to do this one since flash doesn't look at it 194 this.settings.upload_url = SWFUpload.completeURL(this.settings.upload_url); 195 this.settings.button_image_url = SWFUpload.completeURL(this.settings.button_image_url); 196 } 197 198 delete this.ensureDefault; 199 199 }; 200 200 201 201 // Private: loadFlash replaces the button_placeholder element with the flash movie. 202 202 SWFUpload.prototype.loadFlash = function () { 203 var targetElement, tempParent;204 205 // Make sure an element with the ID we are going to use doesn't already exist206 if (document.getElementById(this.movieName) !== null) {207 throw "ID " + this.movieName + " is already in use. The Flash Object could not be added";208 }209 210 // Get the element where we will be placing the flash movie211 targetElement = document.getElementById(this.settings.button_placeholder_id) || this.settings.button_placeholder;212 213 if (targetElement == undefined) {214 throw "Could not find the placeholder element: " + this.settings.button_placeholder_id;215 }216 217 // Append the container and load the flash218 tempParent = document.createElement("div");219 tempParent.innerHTML = this.getFlashHTML();// Using innerHTML is non-standard but the only sensible way to dynamically add Flash in IE (and maybe other browsers)220 targetElement.parentNode.replaceChild(tempParent.firstChild, targetElement);221 222 // Fix IE Flash/Form bug223 if (window[this.movieName] == undefined) {224 window[this.movieName] = this.getMovieElement();225 }226 203 var targetElement, tempParent; 204 205 // Make sure an element with the ID we are going to use doesn't already exist 206 if (document.getElementById(this.movieName) !== null) { 207 throw "ID " + this.movieName + " is already in use. The Flash Object could not be added"; 208 } 209 210 // Get the element where we will be placing the flash movie 211 targetElement = document.getElementById(this.settings.button_placeholder_id) || this.settings.button_placeholder; 212 213 if (targetElement == undefined) { 214 throw "Could not find the placeholder element: " + this.settings.button_placeholder_id; 215 } 216 217 // Append the container and load the flash 218 tempParent = document.createElement("div"); 219 tempParent.innerHTML = this.getFlashHTML(); // Using innerHTML is non-standard but the only sensible way to dynamically add Flash in IE (and maybe other browsers) 220 targetElement.parentNode.replaceChild(tempParent.firstChild, targetElement); 221 222 // Fix IE Flash/Form bug 223 if (window[this.movieName] == undefined) { 224 window[this.movieName] = this.getMovieElement(); 225 } 226 227 227 }; 228 228 229 229 // Private: getFlashHTML generates the object tag needed to embed the flash in to the document 230 230 SWFUpload.prototype.getFlashHTML = function () { 231 // Flash Satay object syntax: http://www.alistapart.com/articles/flashsatay232 return ['<object id="', this.movieName, '" type="application/x-shockwave-flash" data="', this.settings.flash_url, '" width="', this.settings.button_width, '" height="', this.settings.button_height, '" class="swfupload">',233 '<param name="wmode" value="', this.settings.button_window_mode, '" />',234 '<param name="movie" value="', this.settings.flash_url, '" />',235 '<param name="quality" value="high" />',236 '<param name="menu" value="false" />',237 '<param name="allowScriptAccess" value="always" />',238 '<param name="flashvars" value="' + this.getFlashVars() + '" />',239 '</object>'].join("");231 // Flash Satay object syntax: http://www.alistapart.com/articles/flashsatay 232 return ['<object id="', this.movieName, '" type="application/x-shockwave-flash" data="', this.settings.flash_url, '" width="', this.settings.button_width, '" height="', this.settings.button_height, '" class="swfupload">', 233 '<param name="wmode" value="', this.settings.button_window_mode, '" />', 234 '<param name="movie" value="', this.settings.flash_url, '" />', 235 '<param name="quality" value="high" />', 236 '<param name="menu" value="false" />', 237 '<param name="allowScriptAccess" value="always" />', 238 '<param name="flashvars" value="' + this.getFlashVars() + '" />', 239 '</object>'].join(""); 240 240 }; 241 241 … … 243 243 // to flash in the flashvars param. 244 244 SWFUpload.prototype.getFlashVars = function () { 245 // Build a string from the post param object246 var paramString = this.buildParamString();247 var httpSuccessString = this.settings.http_success.join(",");248 249 // Build the parameter string250 return ["movieName=", encodeURIComponent(this.movieName),251 "&uploadURL=", encodeURIComponent(this.settings.upload_url),252 "&useQueryString=", encodeURIComponent(this.settings.use_query_string),253 "&requeueOnError=", encodeURIComponent(this.settings.requeue_on_error),254 "&httpSuccess=", encodeURIComponent(httpSuccessString),255 "&assumeSuccessTimeout=", encodeURIComponent(this.settings.assume_success_timeout),256 "&params=", encodeURIComponent(paramString),257 "&filePostName=", encodeURIComponent(this.settings.file_post_name),258 "&fileTypes=", encodeURIComponent(this.settings.file_types),259 "&fileTypesDescription=", encodeURIComponent(this.settings.file_types_description),260 "&fileSizeLimit=", encodeURIComponent(this.settings.file_size_limit),261 "&fileUploadLimit=", encodeURIComponent(this.settings.file_upload_limit),262 "&fileQueueLimit=", encodeURIComponent(this.settings.file_queue_limit),263 "&debugEnabled=", encodeURIComponent(this.settings.debug_enabled),264 "&buttonImageURL=", encodeURIComponent(this.settings.button_image_url),265 "&buttonWidth=", encodeURIComponent(this.settings.button_width),266 "&buttonHeight=", encodeURIComponent(this.settings.button_height),267 "&buttonText=", encodeURIComponent(this.settings.button_text),268 "&buttonTextTopPadding=", encodeURIComponent(this.settings.button_text_top_padding),269 "&buttonTextLeftPadding=", encodeURIComponent(this.settings.button_text_left_padding),270 "&buttonTextStyle=", encodeURIComponent(this.settings.button_text_style),271 "&buttonAction=", encodeURIComponent(this.settings.button_action),272 "&buttonDisabled=", encodeURIComponent(this.settings.button_disabled),273 "&buttonCursor=", encodeURIComponent(this.settings.button_cursor)274 ].join("");245 // Build a string from the post param object 246 var paramString = this.buildParamString(); 247 var httpSuccessString = this.settings.http_success.join(","); 248 249 // Build the parameter string 250 return ["movieName=", encodeURIComponent(this.movieName), 251 "&uploadURL=", encodeURIComponent(this.settings.upload_url), 252 "&useQueryString=", encodeURIComponent(this.settings.use_query_string), 253 "&requeueOnError=", encodeURIComponent(this.settings.requeue_on_error), 254 "&httpSuccess=", encodeURIComponent(httpSuccessString), 255 "&assumeSuccessTimeout=", encodeURIComponent(this.settings.assume_success_timeout), 256 "&params=", encodeURIComponent(paramString), 257 "&filePostName=", encodeURIComponent(this.settings.file_post_name), 258 "&fileTypes=", encodeURIComponent(this.settings.file_types), 259 "&fileTypesDescription=", encodeURIComponent(this.settings.file_types_description), 260 "&fileSizeLimit=", encodeURIComponent(this.settings.file_size_limit), 261 "&fileUploadLimit=", encodeURIComponent(this.settings.file_upload_limit), 262 "&fileQueueLimit=", encodeURIComponent(this.settings.file_queue_limit), 263 "&debugEnabled=", encodeURIComponent(this.settings.debug_enabled), 264 "&buttonImageURL=", encodeURIComponent(this.settings.button_image_url), 265 "&buttonWidth=", encodeURIComponent(this.settings.button_width), 266 "&buttonHeight=", encodeURIComponent(this.settings.button_height), 267 "&buttonText=", encodeURIComponent(this.settings.button_text), 268 "&buttonTextTopPadding=", encodeURIComponent(this.settings.button_text_top_padding), 269 "&buttonTextLeftPadding=", encodeURIComponent(this.settings.button_text_left_padding), 270 "&buttonTextStyle=", encodeURIComponent(this.settings.button_text_style), 271 "&buttonAction=", encodeURIComponent(this.settings.button_action), 272 "&buttonDisabled=", encodeURIComponent(this.settings.button_disabled), 273 "&buttonCursor=", encodeURIComponent(this.settings.button_cursor) 274 ].join(""); 275 275 }; 276 276 … … 278 278 // The element is cached after the first lookup 279 279 SWFUpload.prototype.getMovieElement = function () { 280 if (this.movieElement == undefined) {281 this.movieElement = document.getElementById(this.movieName);282 }283 284 if (this.movieElement === null) {285 throw "Could not find Flash element";286 }287 288 return this.movieElement;280 if (this.movieElement == undefined) { 281 this.movieElement = document.getElementById(this.movieName); 282 } 283 284 if (this.movieElement === null) { 285 throw "Could not find Flash element"; 286 } 287 288 return this.movieElement; 289 289 }; 290 290 … … 292 292 // and joins them up in to a string formatted "name=value&name=value" 293 293 SWFUpload.prototype.buildParamString = function () { 294 var postParams = this.settings.post_params;295 var paramStringPairs = [];296 297 if (typeof(postParams) === "object") {298 for (var name in postParams) {299 if (postParams.hasOwnProperty(name)) {300 paramStringPairs.push(encodeURIComponent(name.toString()) + "=" + encodeURIComponent(postParams[name].toString()));301 }302 }303 }304 305 return paramStringPairs.join("&");294 var postParams = this.settings.post_params; 295 var paramStringPairs = []; 296 297 if (typeof(postParams) === "object") { 298 for (var name in postParams) { 299 if (postParams.hasOwnProperty(name)) { 300 paramStringPairs.push(encodeURIComponent(name.toString()) + "=" + encodeURIComponent(postParams[name].toString())); 301 } 302 } 303 } 304 305 return paramStringPairs.join("&"); 306 306 }; 307 307 … … 311 311 // Credits: Major improvements provided by steffen 312 312 SWFUpload.prototype.destroy = function () { 313 try {314 // Make sure Flash is done before we try to remove it315 this.cancelUpload(null, false);316 317 318 // Remove the SWFUpload DOM nodes319 var movieElement = null;320 movieElement = this.getMovieElement();321 322 if (movieElement && typeof(movieElement.CallFunction) === "unknown") { // We only want to do this in IE323 // Loop through all the movie's properties and remove all function references (DOM/JS IE 6/7 memory leak workaround)324 for (var i in movieElement) {325 try {326 if (typeof(movieElement[i]) === "function") {327 movieElement[i] = null;328 }329 } catch (ex1) {}330 }331 332 // Remove the Movie Element from the page333 try {334 movieElement.parentNode.removeChild(movieElement);335 } catch (ex) {}336 }337 338 // Remove IE form fix reference339 window[this.movieName] = null;340 341 // Destroy other references342 SWFUpload.instances[this.movieName] = null;343 delete SWFUpload.instances[this.movieName];344 345 this.movieElement = null;346 this.settings = null;347 this.customSettings = null;348 this.eventQueue = null;349 this.movieName = null;350 351 352 return true;353 } catch (ex2) {354 return false;355 }313 try { 314 // Make sure Flash is done before we try to remove it 315 this.cancelUpload(null, false); 316 317 318 // Remove the SWFUpload DOM nodes 319 var movieElement = null; 320 movieElement = this.getMovieElement(); 321 322 if (movieElement && typeof(movieElement.CallFunction) === "unknown") { // We only want to do this in IE 323 // Loop through all the movie's properties and remove all function references (DOM/JS IE 6/7 memory leak workaround) 324 for (var i in movieElement) { 325 try { 326 if (typeof(movieElement[i]) === "function") { 327 movieElement[i] = null; 328 } 329 } catch (ex1) {} 330 } 331 332 // Remove the Movie Element from the page 333 try { 334 movieElement.parentNode.removeChild(movieElement); 335 } catch (ex) {} 336 } 337 338 // Remove IE form fix reference 339 window[this.movieName] = null; 340 341 // Destroy other references 342 SWFUpload.instances[this.movieName] = null; 343 delete SWFUpload.instances[this.movieName]; 344 345 this.movieElement = null; 346 this.settings = null; 347 this.customSettings = null; 348 this.eventQueue = null; 349 this.movieName = null; 350 351 352 return true; 353 } catch (ex2) { 354 return false; 355 } 356 356 }; 357 357 … … 362 362 // SWFUpload in production. 363 363 SWFUpload.prototype.displayDebugInfo = function () { 364 this.debug(365 [366 "---SWFUpload Instance Info---\n",367 "Version: ", SWFUpload.version, "\n",368 "Movie Name: ", this.movieName, "\n",369 "Settings:\n",370 "\t", "upload_url: ", this.settings.upload_url, "\n",371 "\t", "flash_url: ", this.settings.flash_url, "\n",372 "\t", "use_query_string: ", this.settings.use_query_string.toString(), "\n",373 "\t", "requeue_on_error: ", this.settings.requeue_on_error.toString(), "\n",374 "\t", "http_success: ", this.settings.http_success.join(", "), "\n",375 "\t", "assume_success_timeout: ", this.settings.assume_success_timeout, "\n",376 "\t", "file_post_name: ", this.settings.file_post_name, "\n",377 "\t", "post_params: ", this.settings.post_params.toString(), "\n",378 "\t", "file_types: ", this.settings.file_types, "\n",379 "\t", "file_types_description: ", this.settings.file_types_description, "\n",380 "\t", "file_size_limit: ", this.settings.file_size_limit, "\n",381 "\t", "file_upload_limit: ", this.settings.file_upload_limit, "\n",382 "\t", "file_queue_limit: ", this.settings.file_queue_limit, "\n",383 "\t", "debug: ", this.settings.debug.toString(), "\n",384 385 "\t", "prevent_swf_caching: ", this.settings.prevent_swf_caching.toString(), "\n",386 387 "\t", "button_placeholder_id: ", this.settings.button_placeholder_id.toString(), "\n",388 "\t", "button_placeholder: ", (this.settings.button_placeholder ? "Set" : "Not Set"), "\n",389 "\t", "button_image_url: ", this.settings.button_image_url.toString(), "\n",390 "\t", "button_width: ", this.settings.button_width.toString(), "\n",391 "\t", "button_height: ", this.settings.button_height.toString(), "\n",392 "\t", "button_text: ", this.settings.button_text.toString(), "\n",393 "\t", "button_text_style: ", this.settings.button_text_style.toString(), "\n",394 "\t", "button_text_top_padding: ", this.settings.button_text_top_padding.toString(), "\n",395 "\t", "button_text_left_padding: ", this.settings.button_text_left_padding.toString(), "\n",396 "\t", "button_action: ", this.settings.button_action.toString(), "\n",397 "\t", "button_disabled: ", this.settings.button_disabled.toString(), "\n",398 399 "\t", "custom_settings: ", this.settings.custom_settings.toString(), "\n",400 "Event Handlers:\n",401 "\t", "swfupload_loaded_handler assigned: ", (typeof this.settings.swfupload_loaded_handler === "function").toString(), "\n",402 "\t", "file_dialog_start_handler assigned: ", (typeof this.settings.file_dialog_start_handler === "function").toString(), "\n",403 "\t", "file_queued_handler assigned: ", (typeof this.settings.file_queued_handler === "function").toString(), "\n",404 "\t", "file_queue_error_handler assigned: ", (typeof this.settings.file_queue_error_handler === "function").toString(), "\n",405 "\t", "upload_start_handler assigned: ", (typeof this.settings.upload_start_handler === "function").toString(), "\n",406 "\t", "upload_progress_handler assigned: ", (typeof this.settings.upload_progress_handler === "function").toString(), "\n",407 "\t", "upload_error_handler assigned: ", (typeof this.settings.upload_error_handler === "function").toString(), "\n",408 "\t", "upload_success_handler assigned: ", (typeof this.settings.upload_success_handler === "function").toString(), "\n",409 "\t", "upload_complete_handler assigned: ", (typeof this.settings.upload_complete_handler === "function").toString(), "\n",410 "\t", "debug_handler assigned: ", (typeof this.settings.debug_handler === "function").toString(), "\n"411 ].join("")412 );364 this.debug( 365 [ 366 "---SWFUpload Instance Info---\n", 367 "Version: ", SWFUpload.version, "\n", 368 "Movie Name: ", this.movieName, "\n", 369 "Settings:\n", 370 "\t", "upload_url: ", this.settings.upload_url, "\n", 371 "\t", "flash_url: ", this.settings.flash_url, "\n", 372 "\t", "use_query_string: ", this.settings.use_query_string.toString(), "\n", 373 "\t", "requeue_on_error: ", this.settings.requeue_on_error.toString(), "\n", 374 "\t", "http_success: ", this.settings.http_success.join(", "), "\n", 375 "\t", "assume_success_timeout: ", this.settings.assume_success_timeout, "\n", 376 "\t", "file_post_name: ", this.settings.file_post_name, "\n", 377 "\t", "post_params: ", this.settings.post_params.toString(), "\n", 378 "\t", "file_types: ", this.settings.file_types, "\n", 379 "\t", "file_types_description: ", this.settings.file_types_description, "\n", 380 "\t", "file_size_limit: ", this.settings.file_size_limit, "\n", 381 "\t", "file_upload_limit: ", this.settings.file_upload_limit, "\n", 382 "\t", "file_queue_limit: ", this.settings.file_queue_limit, "\n", 383 "\t", "debug: ", this.settings.debug.toString(), "\n", 384 385 "\t", "prevent_swf_caching: ", this.settings.prevent_swf_caching.toString(), "\n", 386 387 "\t", "button_placeholder_id: ", this.settings.button_placeholder_id.toString(), "\n", 388 "\t", "button_placeholder: ", (this.settings.button_placeholder ? "Set" : "Not Set"), "\n", 389 "\t", "button_image_url: ", this.settings.button_image_url.toString(), "\n", 390 "\t", "button_width: ", this.settings.button_width.toString(), "\n", 391 "\t", "button_height: ", this.settings.button_height.toString(), "\n", 392 "\t", "button_text: ", this.settings.button_text.toString(), "\n", 393 "\t", "button_text_style: ", this.settings.button_text_style.toString(), "\n", 394 "\t", "button_text_top_padding: ", this.settings.button_text_top_padding.toString(), "\n", 395 "\t", "button_text_left_padding: ", this.settings.button_text_left_padding.toString(), "\n", 396 "\t", "button_action: ", this.settings.button_action.toString(), "\n", 397 "\t", "button_disabled: ", this.settings.button_disabled.toString(), "\n", 398 399 "\t", "custom_settings: ", this.settings.custom_settings.toString(), "\n", 400 "Event Handlers:\n", 401 "\t", "swfupload_loaded_handler assigned: ", (typeof this.settings.swfupload_loaded_handler === "function").toString(), "\n", 402 "\t", "file_dialog_start_handler assigned: ", (typeof this.settings.file_dialog_start_handler === "function").toString(), "\n", 403 "\t", "file_queued_handler assigned: ", (typeof this.settings.file_queued_handler === "function").toString(), "\n", 404 "\t", "file_queue_error_handler assigned: ", (typeof this.settings.file_queue_error_handler === "function").toString(), "\n", 405 "\t", "upload_start_handler assigned: ", (typeof this.settings.upload_start_handler === "function").toString(), "\n", 406 "\t", "upload_progress_handler assigned: ", (typeof this.settings.upload_progress_handler === "function").toString(), "\n", 407 "\t", "upload_error_handler assigned: ", (typeof this.settings.upload_error_handler === "function").toString(), "\n", 408 "\t", "upload_success_handler assigned: ", (typeof this.settings.upload_success_handler === "function").toString(), "\n", 409 "\t", "upload_complete_handler assigned: ", (typeof this.settings.upload_complete_handler === "function").toString(), "\n", 410 "\t", "debug_handler assigned: ", (typeof this.settings.debug_handler === "function").toString(), "\n" 411 ].join("") 412 ); 413 413 }; 414 414 415 415 /* Note: addSetting and getSetting are no longer used by SWFUpload but are included 416 the maintain v2 API compatibility416 the maintain v2 API compatibility 417 417 */ 418 418 // Public: (Deprecated) addSetting adds a setting value. If the value given is undefined or null then the default_value is used. … … 422 422 } else { 423 423 return (this.settings[name] = value); 424 }424 } 425 425 }; 426 426 … … 429 429 if (this.settings[name] != undefined) { 430 430 return this.settings[name]; 431 }431 } 432 432 433 433 return ""; … … 440 440 // bugs in the ExternalInterface library. 441 441 SWFUpload.prototype.callFlash = function (functionName, argumentArray) { 442 argumentArray = argumentArray || [];443 444 var movieElement = this.getMovieElement();445 var returnValue, returnString;446 447 // Flash's method if calling ExternalInterface methods (code adapted from MooTools).448 try {449 returnString = movieElement.CallFunction('<invoke name="' + functionName + '" returntype="javascript">' + __flash__argumentsToXML(argumentArray, 0) + '</invoke>');450 returnValue = eval(returnString);451 } catch (ex) {452 throw "Call to " + functionName + " failed";453 }454 455 // Unescape file post param values456 if (returnValue != undefined && typeof returnValue.post === "object") {457 returnValue = this.unescapeFilePostParams(returnValue);458 }459 460 return returnValue;442 argumentArray = argumentArray || []; 443 444 var movieElement = this.getMovieElement(); 445 var returnValue, returnString; 446 447 // Flash's method if calling ExternalInterface methods (code adapted from MooTools). 448 try { 449 returnString = movieElement.CallFunction('<invoke name="' + functionName + '" returntype="javascript">' + __flash__argumentsToXML(argumentArray, 0) + '</invoke>'); 450 returnValue = eval(returnString); 451 } catch (ex) { 452 throw "Call to " + functionName + " failed"; 453 } 454 455 // Unescape file post param values 456 if (returnValue != undefined && typeof returnValue.post === "object") { 457 returnValue = this.unescapeFilePostParams(returnValue); 458 } 459 460 return returnValue; 461 461 }; 462 462 463 463 /* ***************************** 464 -- Flash control methods --465 Your UI should use these466 to operate SWFUpload464 -- Flash control methods -- 465 Your UI should use these 466 to operate SWFUpload 467 467 ***************************** */ 468 468 … … 471 471 // dialog only allows 1 file to be selected. 472 472 SWFUpload.prototype.selectFile = function () { 473 this.callFlash("SelectFile");473 this.callFlash("SelectFile"); 474 474 }; 475 475 … … 481 481 // for this bug. 482 482 SWFUpload.prototype.selectFiles = function () { 483 this.callFlash("SelectFiles");483 this.callFlash("SelectFiles"); 484 484 }; 485 485 … … 488 488 // the optional parameter 'fileID' specifies the ID 489 489 SWFUpload.prototype.startUpload = function (fileID) { 490 this.callFlash("StartUpload", [fileID]);490 this.callFlash("StartUpload", [fileID]); 491 491 }; 492 492 … … 495 495 // If you do not want the uploadError event to trigger you can specify false for the triggerErrorEvent parameter. 496 496 SWFUpload.prototype.cancelUpload = function (fileID, triggerErrorEvent) { 497 if (triggerErrorEvent !== false) {498 triggerErrorEvent = true;499 }500 this.callFlash("CancelUpload", [fileID, triggerErrorEvent]);497 if (triggerErrorEvent !== false) { 498 triggerErrorEvent = true; 499 } 500 this.callFlash("CancelUpload", [fileID, triggerErrorEvent]); 501 501 }; 502 502 … … 504 504 // If nothing is currently uploading then nothing happens. 505 505 SWFUpload.prototype.stopUpload = function () { 506 this.callFlash("StopUpload");506 this.callFlash("StopUpload"); 507 507 }; 508 508 … … 517 517 // Public: getStats gets the file statistics object. 518 518 SWFUpload.prototype.getStats = function () { 519 return this.callFlash("GetStats");519 return this.callFlash("GetStats"); 520 520 }; 521 521 … … 525 525 // by the upload_limit setting to determine how many files the user may upload. 526 526 SWFUpload.prototype.setStats = function (statsObject) { 527 this.callFlash("SetStats", [statsObject]);527 this.callFlash("SetStats", [statsObject]); 528 528 }; 529 529 … … 531 531 // not found then 'null' is returned. 532 532 SWFUpload.prototype.getFile = function (fileID) { 533 if (typeof(fileID) === "number") {534 return this.callFlash("GetFileByIndex", [fileID]);535 } else {536 return this.callFlash("GetFile", [fileID]);537 }533 if (typeof(fileID) === "number") { 534 return this.callFlash("GetFileByIndex", [fileID]); 535 } else { 536 return this.callFlash("GetFile", [fileID]); 537 } 538 538 }; 539 539 … … 542 542 // exiting value will be overwritten. 543 543 SWFUpload.prototype.addFileParam = function (fileID, name, value) { 544 return this.callFlash("AddFileParam", [fileID, name, value]);544 return this.callFlash("AddFileParam", [fileID, name, value]); 545 545 }; 546 546 … … 548 548 // pair from the specified file. 549 549 SWFUpload.prototype.removeFileParam = function (fileID, name) { 550 this.callFlash("RemoveFileParam", [fileID, name]);550 this.callFlash("RemoveFileParam", [fileID, name]); 551 551 }; 552 552 553 553 // Public: setUploadUrl changes the upload_url setting. 554 554 SWFUpload.prototype.setUploadURL = function (url) { 555 this.settings.upload_url = url.toString();556 this.callFlash("SetUploadURL", [url]);555 this.settings.upload_url = url.toString(); 556 this.callFlash("SetUploadURL", [url]); 557 557 }; 558 558 559 559 // Public: setPostParams changes the post_params setting 560 560 SWFUpload.prototype.setPostParams = function (paramsObject) { 561 this.settings.post_params = paramsObject;562 this.callFlash("SetPostParams", [paramsObject]);561 this.settings.post_params = paramsObject; 562 this.callFlash("SetPostParams", [paramsObject]); 563 563 }; 564 564 565 565 // Public: addPostParam adds post name/value pair. Each name can have only one value. 566 566 SWFUpload.prototype.addPostParam = function (name, value) { 567 this.settings.post_params[name] = value;568 this.callFlash("SetPostParams", [this.settings.post_params]);567 this.settings.post_params[name] = value; 568 this.callFlash("SetPostParams", [this.settings.post_params]); 569 569 }; 570 570 571 571 // Public: removePostParam deletes post name/value pair. 572 572 SWFUpload.prototype.removePostParam = function (name) { 573 delete this.settings.post_params[name];574 this.callFlash("SetPostParams", [this.settings.post_params]);573 delete this.settings.post_params[name]; 574 this.callFlash("SetPostParams", [this.settings.post_params]); 575 575 }; 576 576 577 577 // Public: setFileTypes changes the file_types setting and the file_types_description setting 578 578 SWFUpload.prototype.setFileTypes = function (types, description) { 579 this.settings.file_types = types;580 this.settings.file_types_description = description;581 this.callFlash("SetFileTypes", [types, description]);579 this.settings.file_types = types; 580 this.settings.file_types_description = description; 581 this.callFlash("SetFileTypes", [types, description]); 582 582 }; 583 583 584 584 // Public: setFileSizeLimit changes the file_size_limit setting 585 585 SWFUpload.prototype.setFileSizeLimit = function (fileSizeLimit) { 586 this.settings.file_size_limit = fileSizeLimit;587 this.callFlash("SetFileSizeLimit", [fileSizeLimit]);586 this.settings.file_size_limit = fileSizeLimit; 587 this.callFlash("SetFileSizeLimit", [fileSizeLimit]); 588 588 }; 589 589 590 590 // Public: setFileUploadLimit changes the file_upload_limit setting 591 591 SWFUpload.prototype.setFileUploadLimit = function (fileUploadLimit) { 592 this.settings.file_upload_limit = fileUploadLimit;593 this.callFlash("SetFileUploadLimit", [fileUploadLimit]);592 this.settings.file_upload_limit = fileUploadLimit; 593 this.callFlash("SetFileUploadLimit", [fileUploadLimit]); 594 594 }; 595 595 596 596 // Public: setFileQueueLimit changes the file_queue_limit setting 597 597 SWFUpload.prototype.setFileQueueLimit = function (fileQueueLimit) { 598 this.settings.file_queue_limit = fileQueueLimit;599 this.callFlash("SetFileQueueLimit", [fileQueueLimit]);598 this.settings.file_queue_limit = fileQueueLimit; 599 this.callFlash("SetFileQueueLimit", [fileQueueLimit]); 600 600 }; 601 601 602 602 // Public: setFilePostName changes the file_post_name setting 603 603 SWFUpload.prototype.setFilePostName = function (filePostName) { 604 this.settings.file_post_name = filePostName;605 this.callFlash("SetFilePostName", [filePostName]);604 this.settings.file_post_name = filePostName; 605 this.callFlash("SetFilePostName", [filePostName]); 606 606 }; 607 607 608 608 // Public: setUseQueryString changes the use_query_string setting 609 609 SWFUpload.prototype.setUseQueryString = function (useQueryString) { 610 this.settings.use_query_string = useQueryString;611 this.callFlash("SetUseQueryString", [useQueryString]);610 this.settings.use_query_string = useQueryString; 611 this.callFlash("SetUseQueryString", [useQueryString]); 612 612 }; 613 613 614 614 // Public: setRequeueOnError changes the requeue_on_error setting 615 615 SWFUpload.prototype.setRequeueOnError = function (requeueOnError) { 616 this.settings.requeue_on_error = requeueOnError;617 this.callFlash("SetRequeueOnError", [requeueOnError]);616 this.settings.requeue_on_error = requeueOnError; 617 this.callFlash("SetRequeueOnError", [requeueOnError]); 618 618 }; 619 619 620 620 // Public: setHTTPSuccess changes the http_success setting 621 621 SWFUpload.prototype.setHTTPSuccess = function (http_status_codes) { 622 if (typeof http_status_codes === "string") {623 http_status_codes = http_status_codes.replace(" ", "").split(",");624 }625 626 this.settings.http_success = http_status_codes;627 this.callFlash("SetHTTPSuccess", [http_status_codes]);622 if (typeof http_status_codes === "string") { 623 http_status_codes = http_status_codes.replace(" ", "").split(","); 624 } 625 626 this.settings.http_success = http_status_codes; 627 this.callFlash("SetHTTPSuccess", [http_status_codes]); 628 628 }; 629 629 630 630 // Public: setHTTPSuccess changes the http_success setting 631 631 SWFUpload.prototype.setAssumeSuccessTimeout = function (timeout_seconds) { 632 this.settings.assume_success_timeout = timeout_seconds;633 this.callFlash("SetAssumeSuccessTimeout", [timeout_seconds]);632 this.settings.assume_success_timeout = timeout_seconds; 633 this.callFlash("SetAssumeSuccessTimeout", [timeout_seconds]); 634 634 }; 635 635 636 636 // Public: setDebugEnabled changes the debug_enabled setting 637 637 SWFUpload.prototype.setDebugEnabled = function (debugEnabled) { 638 this.settings.debug_enabled = debugEnabled;639 this.callFlash("SetDebugEnabled", [debugEnabled]);638 this.settings.debug_enabled = debugEnabled; 639 this.callFlash("SetDebugEnabled", [debugEnabled]); 640 640 }; 641 641 642 642 // Public: setButtonImageURL loads a button image sprite 643 643 SWFUpload.prototype.setButtonImageURL = function (buttonImageURL) { 644 if (buttonImageURL == undefined) {645 buttonImageURL = "";646 }647 648 this.settings.button_image_url = buttonImageURL;649 this.callFlash("SetButtonImageURL", [buttonImageURL]);644 if (buttonImageURL == undefined) { 645 buttonImageURL = ""; 646 } 647 648 this.settings.button_image_url = buttonImageURL; 649 this.callFlash("SetButtonImageURL", [buttonImageURL]); 650 650 }; 651 651 652 652 // Public: setButtonDimensions resizes the Flash Movie and button 653 653 SWFUpload.prototype.setButtonDimensions = function (width, height) { 654 this.settings.button_width = width;655 this.settings.button_height = height;656 657 var movie = this.getMovieElement();658 if (movie != undefined) {659 movie.style.width = width + "px";660 movie.style.height = height + "px";661 }662 663 this.callFlash("SetButtonDimensions", [width, height]);654 this.settings.button_width = width; 655 this.settings.button_height = height; 656 657 var movie = this.getMovieElement(); 658 if (movie != undefined) { 659 movie.style.width = width + "px"; 660 movie.style.height = height + "px"; 661 } 662 663 this.callFlash("SetButtonDimensions", [width, height]); 664 664 }; 665 665 // Public: setButtonText Changes the text overlaid on the button 666 666 SWFUpload.prototype.setButtonText = function (html) { 667 this.settings.button_text = html;668 this.callFlash("SetButtonText", [html]);667 this.settings.button_text = html; 668 this.callFlash("SetButtonText", [html]); 669 669 }; 670 670 // Public: setButtonTextPadding changes the top and left padding of the text overlay 671 671 SWFUpload.prototype.setButtonTextPadding = function (left, top) { 672 this.settings.button_text_top_padding = top;673 this.settings.button_text_left_padding = left;674 this.callFlash("SetButtonTextPadding", [left, top]);672 this.settings.button_text_top_padding = top; 673 this.settings.button_text_left_padding = left; 674 this.callFlash("SetButtonTextPadding", [left, top]); 675 675 }; 676 676 677 677 // Public: setButtonTextStyle changes the CSS used to style the HTML/Text overlaid on the button 678 678 SWFUpload.prototype.setButtonTextStyle = function (css) { 679 this.settings.button_text_style = css;680 this.callFlash("SetButtonTextStyle", [css]);679 this.settings.button_text_style = css; 680 this.callFlash("SetButtonTextStyle", [css]); 681 681 }; 682 682 // Public: setButtonDisabled disables/enables the button 683 683 SWFUpload.prototype.setButtonDisabled = function (isDisabled) { 684 this.settings.button_disabled = isDisabled;685 this.callFlash("SetButtonDisabled", [isDisabled]);684 this.settings.button_disabled = isDisabled; 685 this.callFlash("SetButtonDisabled", [isDisabled]); 686 686 }; 687 687 // Public: setButtonAction sets the action that occurs when the button is clicked 688 688 SWFUpload.prototype.setButtonAction = function (buttonAction) { 689 this.settings.button_action = buttonAction;690 this.callFlash("SetButtonAction", [buttonAction]);689 this.settings.button_action = buttonAction; 690 this.callFlash("SetButtonAction", [buttonAction]); 691 691 }; 692 692 693 693 // Public: setButtonCursor changes the mouse cursor displayed when hovering over the button 694 694 SWFUpload.prototype.setButtonCursor = function (cursor) { 695 this.settings.button_cursor = cursor;696 this.callFlash("SetButtonCursor", [cursor]);695 this.settings.button_cursor = cursor; 696 this.callFlash("SetButtonCursor", [cursor]); 697 697 }; 698 698 699 699 /* ******************************* 700 Flash Event Interfaces701 These functions are used by Flash to trigger the various702 events.703 704 All these functions a Private.705 706 Because the ExternalInterface library is buggy the event calls707 are added to a queue and the queue then executed by a setTimeout.708 This ensures that events are executed in a determinate order and that709 the ExternalInterface bugs are avoided.700 Flash Event Interfaces 701 These functions are used by Flash to trigger the various 702 events. 703 704 All these functions a Private. 705 706 Because the ExternalInterface library is buggy the event calls 707 are added to a queue and the queue then executed by a setTimeout. 708 This ensures that events are executed in a determinate order and that 709 the ExternalInterface bugs are avoided. 710 710 ******************************* */ 711 711 712 712 SWFUpload.prototype.queueEvent = function (handlerName, argumentArray) { 713 // Warning: Don't call this.debug inside here or you'll create an infinite loop714 715 if (argumentArray == undefined) {716 argumentArray = [];717 } else if (!(argumentArray instanceof Array)) {718 argumentArray = [argumentArray];719 }720 721 var self = this;722 if (typeof this.settings[handlerName] === "function") {723 // Queue the event724 this.eventQueue.push(function () {725 this.settings[handlerName].apply(this, argumentArray);726 });727 728 // Execute the next queued event729 setTimeout(function () {730 self.executeNextEvent();731 }, 0);732 733 } else if (this.settings[handlerName] !== null) {734 throw "Event handler " + handlerName + " is unknown or is not a function";735 }713 // Warning: Don't call this.debug inside here or you'll create an infinite loop 714 715 if (argumentArray == undefined) { 716 argumentArray = []; 717 } else if (!(argumentArray instanceof Array)) { 718 argumentArray = [argumentArray]; 719 } 720 721 var self = this; 722 if (typeof this.settings[handlerName] === "function") { 723 // Queue the event 724 this.eventQueue.push(function () { 725 this.settings[handlerName].apply(this, argumentArray); 726 }); 727 728 // Execute the next queued event 729 setTimeout(function () { 730 self.executeNextEvent(); 731 }, 0); 732 733 } else if (this.settings[handlerName] !== null) { 734 throw "Event handler " + handlerName + " is unknown or is not a function"; 735 } 736 736 }; 737 737 … … 739 739 // we must queue them in order to garentee that they are executed in order. 740 740 SWFUpload.prototype.executeNextEvent = function () { 741 // Warning: Don't call this.debug inside here or you'll create an infinite loop742 743 var f = this.eventQueue ? this.eventQueue.shift() : null;744 if (typeof(f) === "function") {745 f.apply(this);746 }741 // Warning: Don't call this.debug inside here or you'll create an infinite loop 742 743 var f = this.eventQueue ? this.eventQueue.shift() : null; 744 if (typeof(f) === "function") { 745 f.apply(this); 746 } 747 747 }; 748 748 … … 751 751 // the Flash Component escapes the parameter names and we must unescape again before passing them along. 752 752 SWFUpload.prototype.unescapeFilePostParams = function (file) { 753 var reg = /[$]([0-9a-f]{4})/i;754 var unescapedPost = {};755 var uk;756 757 if (file != undefined) {758 for (var k in file.post) {759 if (file.post.hasOwnProperty(k)) {760 uk = k;761 var match;762 while ((match = reg.exec(uk)) !== null) {763 uk = uk.replace(match[0], String.fromCharCode(parseInt("0x" + match[1], 16)));764 }765 unescapedPost[uk] = file.post[k];766 }767 }768 769 file.post = unescapedPost;770 }771 772 return file;753 var reg = /[$]([0-9a-f]{4})/i; 754 var unescapedPost = {}; 755 var uk; 756 757 if (file != undefined) { 758 for (var k in file.post) { 759 if (file.post.hasOwnProperty(k)) { 760 uk = k; 761 var match; 762 while ((match = reg.exec(uk)) !== null) { 763 uk = uk.replace(match[0], String.fromCharCode(parseInt("0x" + match[1], 16))); 764 } 765 unescapedPost[uk] = file.post[k]; 766 } 767 } 768 769 file.post = unescapedPost; 770 } 771 772 return file; 773 773 }; 774 774 775 775 // Private: Called by Flash to see if JS can call in to Flash (test if External Interface is working) 776 776 SWFUpload.prototype.testExternalInterface = function () { 777 try {778 return this.callFlash("TestExternalInterface");779 } catch (ex) {780 return false;781 }777 try { 778 return this.callFlash("TestExternalInterface"); 779 } catch (ex) { 780 return false; 781 } 782 782 }; 783 783 … … 785 785 // Use the swfupload_loaded_handler event setting to execute custom code when SWFUpload has loaded. 786 786 SWFUpload.prototype.flashReady = function () { 787 // Check that the movie element is loaded correctly with its ExternalInterface methods defined788 var movieElement = this.getMovieElement();789 790 if (!movieElement) {791 this.debug("Flash called back ready but the flash movie can't be found.");792 return;793 }794 795 this.cleanUp(movieElement);796 797 this.queueEvent("swfupload_loaded_handler");787 // Check that the movie element is loaded correctly with its ExternalInterface methods defined 788 var movieElement = this.getMovieElement(); 789 790 if (!movieElement) { 791 this.debug("Flash called back ready but the flash movie can't be found."); 792 return; 793 } 794 795 this.cleanUp(movieElement); 796 797 this.queueEvent("swfupload_loaded_handler"); 798 798 }; 799 799 … … 801 801 // This function is called by Flash each time the ExternalInterface functions are created. 802 802 SWFUpload.prototype.cleanUp = function (movieElement) { 803 // Pro-actively unhook all the Flash functions804 try {805 if (this.movieElement && typeof(movieElement.CallFunction) === "unknown") { // We only want to do this in IE806 this.debug("Removing Flash functions hooks (this should only run in IE and should prevent memory leaks)");807 for (var key in movieElement) {808 try {809 if (typeof(movieElement[key]) === "function") {810 movieElement[key] = null;811 }812 } catch (ex) {813 }814 }815 }816 } catch (ex1) {817 818 }819 820 // Fix Flashes own cleanup code so if the SWFMovie was removed from the page821 // it doesn't display errors.822 window["__flash__removeCallback"] = function (instance, name) {823 try {824 if (instance) {825 instance[name] = null;826 }827 } catch (flashEx) {828 829 }830 };803 // Pro-actively unhook all the Flash functions 804 try { 805 if (this.movieElement && typeof(movieElement.CallFunction) === "unknown") { // We only want to do this in IE 806 this.debug("Removing Flash functions hooks (this should only run in IE and should prevent memory leaks)"); 807 for (var key in movieElement) { 808 try { 809 if (typeof(movieElement[key]) === "function") { 810 movieElement[key] = null; 811 } 812 } catch (ex) { 813 } 814 } 815 } 816 } catch (ex1) { 817 818 } 819 820 // Fix Flashes own cleanup code so if the SWFMovie was removed from the page 821 // it doesn't display errors. 822 window["__flash__removeCallback"] = function (instance, name) { 823 try { 824 if (instance) { 825 instance[name] = null; 826 } 827 } catch (flashEx) { 828 829 } 830 }; 831 831 832 832 }; … … 835 835 /* This is a chance to do something before the browse window opens */ 836 836 SWFUpload.prototype.fileDialogStart = function () { 837 this.queueEvent("file_dialog_start_handler");837 this.queueEvent("file_dialog_start_handler"); 838 838 }; 839 839 … … 841 841 /* Called when a file is successfully added to the queue. */ 842 842 SWFUpload.prototype.fileQueued = function (file) { 843 file = this.unescapeFilePostParams(file);844 this.queueEvent("file_queued_handler", file);843 file = this.unescapeFilePostParams(file); 844 this.queueEvent("file_queued_handler", file); 845 845 }; 846 846 … … 848 848 /* Handle errors that occur when an attempt to queue a file fails. */ 849 849 SWFUpload.prototype.fileQueueError = function (file, errorCode, message) { 850 file = this.unescapeFilePostParams(file);851 this.queueEvent("file_queue_error_handler", [file, errorCode, message]);850 file = this.unescapeFilePostParams(file); 851 this.queueEvent("file_queue_error_handler", [file, errorCode, message]); 852 852 }; 853 853 854 854 /* Called after the file dialog has closed and the selected files have been queued. 855 You could call startUpload here if you want the queued files to begin uploading immediately. */855 You could call startUpload here if you want the queued files to begin uploading immediately. */ 856 856 SWFUpload.prototype.fileDialogComplete = function (numFilesSelected, numFilesQueued, numFilesInQueue) { 857 this.queueEvent("file_dialog_complete_handler", [numFilesSelected, numFilesQueued, numFilesInQueue]);857 this.queueEvent("file_dialog_complete_handler", [numFilesSelected, numFilesQueued, numFilesInQueue]); 858 858 }; 859 859 860 860 SWFUpload.prototype.uploadStart = function (file) { 861 file = this.unescapeFilePostParams(file);862 this.queueEvent("return_upload_start_handler", file);861 file = this.unescapeFilePostParams(file); 862 this.queueEvent("return_upload_start_handler", file); 863 863 }; 864 864 865 865 SWFUpload.prototype.returnUploadStart = function (file) { 866 var returnValue;867 if (typeof this.settings.upload_start_handler === "function") {868 file = this.unescapeFilePostParams(file);869 returnValue = this.settings.upload_start_handler.call(this, file);870 } else if (this.settings.upload_start_handler != undefined) {871 throw "upload_start_handler must be a function";872 }873 874 // Convert undefined to true so if nothing is returned from the upload_start_handler it is875 // interpretted as 'true'.876 if (returnValue === undefined) {877 returnValue = true;878 }879 880 returnValue = !!returnValue;881 882 this.callFlash("ReturnUploadStart", [returnValue]);866 var returnValue; 867 if (typeof this.settings.upload_start_handler === "function") { 868 file = this.unescapeFilePostParams(file); 869 returnValue = this.settings.upload_start_handler.call(this, file); 870 } else if (this.settings.upload_start_handler != undefined) { 871 throw "upload_start_handler must be a function"; 872 } 873 874 // Convert undefined to true so if nothing is returned from the upload_start_handler it is 875 // interpretted as 'true'. 876 if (returnValue === undefined) { 877 returnValue = true; 878 } 879 880 returnValue = !!returnValue; 881 882 this.callFlash("ReturnUploadStart", [returnValue]); 883 883 }; 884 884 … … 886 886 887 887 SWFUpload.prototype.uploadProgress = function (file, bytesComplete, bytesTotal) { 888 file = this.unescapeFilePostParams(file);889 this.queueEvent("upload_progress_handler", [file, bytesComplete, bytesTotal]);888 file = this.unescapeFilePostParams(file); 889 this.queueEvent("upload_progress_handler", [file, bytesComplete, bytesTotal]); 890 890 }; 891 891 892 892 SWFUpload.prototype.uploadError = function (file, errorCode, message) { 893 file = this.unescapeFilePostParams(file);894 this.queueEvent("upload_error_handler", [file, errorCode, message]);893 file = this.unescapeFilePostParams(file); 894 this.queueEvent("upload_error_handler", [file, errorCode, message]); 895 895 }; 896 896 897 897 SWFUpload.prototype.uploadSuccess = function (file, serverData, responseReceived) { 898 file = this.unescapeFilePostParams(file);899 this.queueEvent("upload_success_handler", [file, serverData, responseReceived]);898 file = this.unescapeFilePostParams(file); 899 this.queueEvent("upload_success_handler", [file, serverData, responseReceived]); 900 900 }; 901 901 902 902 SWFUpload.prototype.uploadComplete = function (file) { 903 file = this.unescapeFilePostParams(file);904 this.queueEvent("upload_complete_handler", file);903 file = this.unescapeFilePostParams(file); 904 this.queueEvent("upload_complete_handler", file); 905 905 }; 906 906 … … 908 908 internal debug console. You can override this event and have messages written where you want. */ 909 909 SWFUpload.prototype.debug = function (message) { 910 this.queueEvent("debug_handler", message);910 this.queueEvent("debug_handler", message); 911 911 }; 912 912 913 913 914 914 /* ********************************** 915 Debug Console916 The debug console is a self contained, in page location917 for debug message to be sent. The Debug Console adds918 itself to the body if necessary.919 920 The console is automatically scrolled as messages appear.921 922 If you are using your own debug handler or when you deploy to production and923 have debug disabled you can remove these functions to reduce the file size924 and complexity.915 Debug Console 916 The debug console is a self contained, in page location 917 for debug message to be sent. The Debug Console adds 918 itself to the body if necessary. 919 920 The console is automatically scrolled as messages appear. 921 922 If you are using your own debug handler or when you deploy to production and 923 have debug disabled you can remove these functions to reduce the file size 924 and complexity. 925 925 ********************************** */ 926 926 … … 929 929 // check to see if the debug setting is true before outputting debug information. 930 930 SWFUpload.prototype.debugMessage = function (message) { 931 if (this.settings.debug) {932 var exceptionMessage, exceptionValues = [];933 934 // Check for an exception object and print it nicely935 if (typeof message === "object" && typeof message.name === "string" && typeof message.message === "string") {936 for (var key in message) {937 if (message.hasOwnProperty(key)) {938 exceptionValues.push(key + ": " + message[key]);939 }940 }941 exceptionMessage = exceptionValues.join("\n") || "";942 exceptionValues = exceptionMessage.split("\n");943 exceptionMessage = "EXCEPTION: " + exceptionValues.join("\nEXCEPTION: ");944 SWFUpload.Console.writeLine(exceptionMessage);945 } else {946 SWFUpload.Console.writeLine(message);947 }948 }931 if (this.settings.debug) { 932 var exceptionMessage, exceptionValues = []; 933 934 // Check for an exception object and print it nicely 935 if (typeof message === "object" && typeof message.name === "string" && typeof message.message === "string") { 936 for (var key in message) { 937 if (message.hasOwnProperty(key)) { 938 exceptionValues.push(key + ": " + message[key]); 939 } 940 } 941 exceptionMessage = exceptionValues.join("\n") || ""; 942 exceptionValues = exceptionMessage.split("\n"); 943 exceptionMessage = "EXCEPTION: " + exceptionValues.join("\nEXCEPTION: "); 944 SWFUpload.Console.writeLine(exceptionMessage); 945 } else { 946 SWFUpload.Console.writeLine(message); 947 } 948 } 949 949 }; 950 950 951 951 SWFUpload.Console = {}; 952 952 SWFUpload.Console.writeLine = function (message) { 953 var console, documentForm;954 955 try {956 console = document.getElementById("SWFUpload_Console");957 958 if (!console) {959 documentForm = document.createElement("form");960 document.getElementsByTagName("body")[0].appendChild(documentForm);961 962 console = document.createElement("textarea");963 console.id = "SWFUpload_Console";964 console.style.fontFamily = "monospace";965 console.setAttribute("wrap", "off");966 console.wrap = "off";967 console.style.overflow = "auto";968 console.style.width = "700px";969 console.style.height = "350px";970 console.style.margin = "5px";971 documentForm.appendChild(console);972 }973 974 console.value += message + "\n";975 976 console.scrollTop = console.scrollHeight - console.clientHeight;977 } catch (ex) {978 alert("Exception: " + ex.name + " Message: " + ex.message);979 }980 }; 953 var console, documentForm; 954 955 try { 956 console = document.getElementById("SWFUpload_Console"); 957 958 if (!console) { 959 documentForm = document.createElement("form"); 960 document.getElementsByTagName("body")[0].appendChild(documentForm); 961 962 console = document.createElement("textarea"); 963 console.id = "SWFUpload_Console"; 964 console.style.fontFamily = "monospace"; 965 console.setAttribute("wrap", "off"); 966 console.wrap = "off"; 967 console.style.overflow = "auto"; 968 console.style.width = "700px"; 969 console.style.height = "350px"; 970 console.style.margin = "5px"; 971 documentForm.appendChild(console); 972 } 973 974 console.value += message + "\n"; 975 976 console.scrollTop = console.scrollHeight - console.clientHeight; 977 } catch (ex) { 978 alert("Exception: " + ex.name + " Message: " + ex.message); 979 } 980 }; plugins/sfImaginablePlugin/branches/experimental/web/swf/ExternalCall.as
r24360 r24364 22 22 23 23 } 24 public static function FileDialogComplete(callback:String, num_files_selected:Number, num_files_queued:Number , total_num_files_queued:Number):void {24 public static function FileDialogComplete(callback:String, num_files_selected:Number, num_files_queued:Number):void { 25 25 26 ExternalInterface.call(callback, EscapeMessage(num_files_selected), EscapeMessage(num_files_queued) , EscapeMessage(total_num_files_queued));26 ExternalInterface.call(callback, EscapeMessage(num_files_selected), EscapeMessage(num_files_queued)); 27 27 28 28 } … … 37 37 38 38 } 39 public static function UploadSuccess(callback:String, file_object:Object, server_data:String , responseReceived:Boolean):void {39 public static function UploadSuccess(callback:String, file_object:Object, server_data:String):void { 40 40 41 ExternalInterface.call(callback, EscapeMessage(file_object), EscapeMessage(server_data) , EscapeMessage(responseReceived));41 ExternalInterface.call(callback, EscapeMessage(file_object), EscapeMessage(server_data)); 42 42 43 43 } … … 55 55 56 56 ExternalInterface.call(callback, EscapeMessage(message)); 57 57 58 } 58 59 public static function Bool(callback:String):Boolean {60 return ExternalInterface.call(callback);61 }62 63 59 64 60 /* Escapes all the backslashes which are not translated correctly in the Flash -> JavaScript Interface plugins/sfImaginablePlugin/branches/experimental/web/swf/SWFUpload.as
r24360 r24364 1 1 package { 2 import flash.display.BlendMode;3 2 import flash.display.DisplayObjectContainer; 4 3 import flash.display.Loader; … … 26 25 import flash.text.TextFormat; 27 26 import flash.ui.Mouse; 28 import flash.utils.Timer;29 27 30 28 import FileItem; … … 38 36 } 39 37 40 private const build_number:String = "SWFUPLOAD 2.2.0 ";38 private const build_number:String = "SWFUPLOAD 2.2.0 Alpha 2008-10-17"; 41 39 42 40 // State tracking variables … … 56 54 57 55 private var valid_file_extensions:Array = new Array();// Holds the parsed valid extensions. 58 59 private var serverDataTimer:Timer = null;60 private var assumeSuccessTimer:Timer = null;61 62 private var restoreExtIntTimer:Timer;63 private var hasCalledFlashReady:Boolean = false;64 56 65 57 // Callbacks … … 78 70 79 71 private var debug_Callback:String; 80 private var testExternalInterface_Callback:String;81 private var cleanUp_Callback:String;82 72 83 73 // Values passed in from the HTML … … 93 83 private var useQueryString:Boolean = false; 94 84 private var requeueOnError:Boolean = false; 95 private var httpSuccess:Array = [];96 private var assumeSuccessTimeout:Number = 0;97 85 private var debugEnabled:Boolean; 98 86 99 87 private var buttonLoader:Loader; 100 88 private var buttonTextField:TextField; 101 private var buttonCursorSprite:Sprite;102 89 private var buttonImageURL:String; 103 90 private var buttonWidth:Number; … … 108 95 private var buttonTextLeftPadding:Number; 109 96 private var buttonAction:Number; 110 private var buttonCursor:Number;111 97 private var buttonStateOver:Boolean; 112 98 private var buttonStateMouseDown:Boolean; … … 143 129 private var BUTTON_ACTION_START_UPLOAD:Number = -120; 144 130 145 private var BUTTON_CURSOR_ARROW:Number = -1;146 private var BUTTON_CURSOR_HAND:Number = -2;147 148 131 public function SWFUpload() { 149 132 // Do the feature detection. Make sure this version of Flash supports the features we need. If not … … 153 136 } 154 137 138 155 139 Security.allowDomain("*"); // Allow uploading to any domain 156 140 … … 220 204 this.stage.addChild(this.buttonTextField); 221 205 222 223 this.buttonCursorSprite = new Sprite(); 224 this.buttonCursorSprite.graphics.beginFill(0xFFFFFF, 0); 225 this.buttonCursorSprite.graphics.drawRect(0, 0, 1, 1); 226 this.buttonCursorSprite.graphics.endFill(); 227 this.buttonCursorSprite.buttonMode = true; 228 this.buttonCursorSprite.x = 0; 229 this.buttonCursorSprite.y = 0; 230 this.buttonCursorSprite.addEventListener(MouseEvent.CLICK, doNothing); 231 this.stage.addChild(this.buttonCursorSprite); 206 // FIXME -- figure out about alignment 232 207 233 208 // Get the movie name … … 255 230 this.debug_Callback = "SWFUpload.instances[\"" + this.movieName + "\"].debug"; 256 231 257 this.testExternalInterface_Callback = "SWFUpload.instances[\"" + this.movieName + "\"].testExternalInterface";258 this.cleanUp_Callback = "SWFUpload.instances[\"" + this.movieName + "\"].cleanUp";259 232 260 233 // Get the Flash Vars … … 323 296 324 297 try { 325 this.SetHTTPSuccess(String(root.loaderInfo.parameters.httpSuccess));326 } catch (ex:Object) {327 this.SetHTTPSuccess([]);328 }329 330 try {331 this.SetAssumeSuccessTimeout(Number(root.loaderInfo.parameters.assumeSuccessTimeout));332 } catch (ex:Object) {333 this.SetAssumeSuccessTimeout(0);334 }335 336 337 try {338 298 this.SetButtonDimensions(Number(root.loaderInfo.parameters.buttonWidth), Number(root.loaderInfo.parameters.buttonHeight)); 339 299 } catch (ex:Object) { … … 366 326 367 327 try { 328 this.SetButtonTextStyle(String(root.loaderInfo.parameters.buttonTextStyle)); 329 } catch (ex:Object) { 330 this.SetButtonTextStyle(""); 331 } 332 333 try { 368 334 this.SetButtonAction(Number(root.loaderInfo.parameters.buttonAction)); 369 335 } catch (ex:Object) { … … 378 344 379 345 try { 380 this.SetButtonCursor(Number(root.loaderInfo.parameters.buttonCursor)); 381 } catch (ex:Object) { 382 this.SetButtonCursor(this.BUTTON_CURSOR_ARROW); 383 } 384 385 this.SetupExternalInterface(); 386 387 this.Debug("SWFUpload Init Complete"); 388 this.PrintDebugInfo(); 389 390 if (ExternalCall.Bool(this.testExternalInterface_Callback)) { 391 ExternalCall.Simple(this.flashReady_Callback); 392 this.hasCalledFlashReady = true; 393 } 394 395 // Start periodically checking the external interface 396 var oSelf:SWFUpload = this; 397 this.restoreExtIntTimer = new Timer(1000, 0); 398 this.restoreExtIntTimer.addEventListener(TimerEvent.TIMER, function ():void { oSelf.CheckExternalInterface();} ); 399 this.restoreExtIntTimer.start(); 400 } 401 402 // Used to periodically check that the External Interface functions are still working 403 private function CheckExternalInterface():void { 404 if (!ExternalCall.Bool(this.testExternalInterface_Callback)) { 405 this.SetupExternalInterface(); 406 this.Debug("ExternalInterface reinitialized"); 407 if (!this.hasCalledFlashReady) { 408 ExternalCall.Simple(this.flashReady_Callback); 409 this.hasCalledFlashReady = true; 410 } 411 } 412 } 413 414 // Called by JS to see if it can access the external interface 415 private function TestExternalInterface():Boolean { 416 return true; 417 } 418 419 private function SetupExternalInterface():void { 420 try { 421 ExternalInterface.addCallback("SelectFile", this.SelectFile); 422 ExternalInterface.addCallback("SelectFiles", this.SelectFiles); 346 //ExternalInterface.addCallback("SelectFile", this.SelectFile); 347 //ExternalInterface.addCallback("SelectFiles", this.SelectFiles); 423 348 ExternalInterface.addCallback("StartUpload", this.StartUpload); 424 349 ExternalInterface.addCallback("ReturnUploadStart", this.ReturnUploadStart); 425 350 ExternalInterface.addCallback("StopUpload", this.StopUpload); 426 351 ExternalInterface.addCallback("CancelUpload", this.CancelUpload); 427 ExternalInterface.addCallback("RequeueUpload", this.RequeueUpload);428 352 429 353 ExternalInterface.addCallback("GetStats", this.GetStats); … … 444 368 ExternalInterface.addCallback("SetUseQueryString", this.SetUseQueryString); 445 369 ExternalInterface.addCallback("SetRequeueOnError", this.SetRequeueOnError); 446 ExternalInterface.addCallback("SetHTTPSuccess", this.SetHTTPSuccess);447 ExternalInterface.addCallback("SetAssumeSuccessTimeout", this.SetAssumeSuccessTimeout);448 370 ExternalInterface.addCallback("SetDebugEnabled", this.SetDebugEnabled); 449 371 … … 455 377 ExternalInterface.addCallback("SetButtonAction", this.SetButtonAction); 456 378 ExternalInterface.addCallback("SetButtonDisabled", this.SetButtonDisabled); 457 ExternalInterface.addCallback("SetButtonCursor", this.SetButtonCursor);458 459 ExternalInterface.addCallback("TestExternalInterface", this.TestExternalInterface);460 461 379 } catch (ex:Error) { 462 this.Debug("Callbacks where not set : " + ex.message);380 this.Debug("Callbacks where not set."); 463 381 return; 464 382 } 465 466 ExternalCall.Simple(this.cleanUp_Callback); 467 } 468 383 384 this.Debug("SWFUpload Init Complete"); 385 this.PrintDebugInfo(); 386 387 ExternalCall.Simple(this.flashReady_Callback); 388 } 389 469 390 /* ***************************************** 470 391 * FileReference Event Handlers … … 472 393 private function DialogCancelled_Handler(event:Event):void { 473 394 this.Debug("Event: fileDialogComplete: File Dialog window cancelled."); 474 ExternalCall.FileDialogComplete(this.fileDialogComplete_Callback, 0, 0 , this.queued_uploads);395 ExternalCall.FileDialogComplete(this.fileDialogComplete_Callback, 0, 0); 475 396 } 476 397 … … 486 407 var bytesTotal:Number = event.bytesTotal < 0 ? 0 : event.bytesTotal; 487 408 488 // Because Flash never fires a complete event if the server doesn't respond after 30 seconds or on Macs if there489 // is no content in the response we'll set a timer and assume that the upload is successful after the defined amount of490 // time. If the timeout is zero then we won't use the timer.491 if (bytesLoaded === bytesTotal && bytesTotal > 0 && this.assumeSuccessTimeout > 0) {492 if (this.assumeSuccessTimer !== null) {493 this.assumeSuccessTimer.stop();494 this.assumeSuccessTimer = null;495 }496 497 this.assumeSuccessTimer = new Timer(this.assumeSuccessTimeout * 1000, 1);498 this.assumeSuccessTimer.addEventListener(TimerEvent.TIMER_COMPLETE, AssumeSuccessTimer_Handler);499 this.assumeSuccessTimer.start();500 }501 502 409 this.Debug("Event: uploadProgress: File ID: " + this.current_file_item.id + ". Bytes: " + bytesLoaded + ". Total: " + bytesTotal); 503 410 ExternalCall.UploadProgress(this.uploadProgress_Callback, this.current_file_item.ToJavaScriptObject(), bytesLoaded, bytesTotal); 504 411 } 505 506 private function AssumeSuccessTimer_Handler(event:TimerEvent):void { 507 this.Debug("Event: AssumeSuccess: " + this.assumeSuccessTimeout + " passed without server response"); 508 this.UploadSuccess(this.current_file_item, "", false); 509 } 510 511 private function Complete_Handler(event:Event):void { 512 /* Because we can't do COMPLETE or DATA events (we have to do both) we can't 513 * just call uploadSuccess from the complete handler, we have to wait for 514 * the Data event which may never come. However, testing shows it always comes 515 * within a couple milliseconds if it is going to come so the solution is: 516 * 517 * Set a timer in the COMPLETE event (which always fires) and if DATA is fired 518 * it will stop the timer and call uploadComplete 519 * 520 * If the timer expires then DATA won't be fired and we call uploadComplete 521 * */ 522 523 // Set the timer 524 if (serverDataTimer != null) { 525 this.serverDataTimer.stop(); 526 this.serverDataTimer = null; 527 } 528 529 this.serverDataTimer = new Timer(100, 1); 530 //var self:SWFUpload = this; 531 this.serverDataTimer.addEventListener(TimerEvent.TIMER, this.ServerDataTimer_Handler); 532 this.serverDataTimer.start(); 533 } 534 private function ServerDataTimer_Handler(event:TimerEvent):void { 535 this.UploadSuccess(this.current_file_item, ""); 536 } 537 412 538 413 private function ServerData_Handler(event:DataEvent):void { 539 this.UploadSuccess(this.current_file_item, event.data);540 }541 542 private function UploadSuccess(file:FileItem, serverData:String, responseReceived:Boolean = true):void {543 if (this.serverDataTimer !== null) {544 this.serverDataTimer.stop();545 this.serverDataTimer = null;546 }547 if (this.assumeSuccessTimer !== null) {548 this.assumeSuccessTimer.stop();549 this.assumeSuccessTimer = null;550 }551 552 414 this.successful_uploads++; 553 file.file_status = FileItem.FILE_STATUS_SUCCESS;554 555 this.Debug("Event: uploadSuccess: File ID: " + file.id + " Response Received: " + responseReceived.toString() + " Data: " + serverData);556 ExternalCall.UploadSuccess(this.uploadSuccess_Callback, file.ToJavaScriptObject(), serverData, responseReceived);415 this.current_file_item.file_status = FileItem.FILE_STATUS_SUCCESS; 416 417 this.Debug("Event: uploadSuccess: File ID: " + this.current_file_item.id + " Data: " + event.data); 418 ExternalCall.UploadSuccess(this.uploadSuccess_Callback, this.current_file_item.ToJavaScriptObject(), event.data); 557 419 558 420 this.UploadComplete(false); … … 561 423 562 424 private function HTTPError_Handler(event:HTTPStatusEvent):void { 563 var isSuccessStatus:Boolean = false; 564 for (var i:Number = 0; i < this.httpSuccess.length; i++) { 565 if (this.httpSuccess[i] === event.status) { 566 isSuccessStatus = true; 567 break; 568 } 569 } 570 571 572 if (isSuccessStatus) { 573 this.Debug("Event: httpError: Translating status code " + event.status + " to uploadSuccess"); 574 575 var serverDataEvent:DataEvent = new DataEvent(DataEvent.UPLOAD_COMPLETE_DATA, event.bubbles, event.cancelable, ""); 576 this.ServerData_Handler(serverDataEvent); 577 } else { 578 this.upload_errors++; 579 this.current_file_item.file_status = FileItem.FILE_STATUS_ERROR; 580 581 this.Debug("Event: uploadError: HTTP ERROR : File ID: " + this.current_file_item.id + ". HTTP Status: " + event.status + "."); 582 ExternalCall.UploadError(this.uploadError_Callback, this.ERROR_CODE_HTTP_ERROR, this.current_file_item.ToJavaScriptObject(), event.status.toString()); 583 this.UploadComplete(true); // An IO Error is also called so we don't want to complete the upload yet. 584 } 425 this.upload_errors++; 426 this.current_file_item.file_status = FileItem.FILE_STATUS_ERROR; 427 428 this.Debug("Event: uploadError: HTTP ERROR : File ID: " + this.current_file_item.id + ". HTTP Status: " + event.status + "."); 429 ExternalCall.UploadError(this.uploadError_Callback, this.ERROR_CODE_HTTP_ERROR, this.current_file_item.ToJavaScriptObject(), event.status.toString()); 430 this.UploadComplete(true); // An IO Error is also called so we don't want to complete the upload yet. 585 431 } 586 432 … … 634 480 queue_slots_remaining = remaining_uploads; 635 481 } else if (this.fileQueueLimit < remaining_uploads) { 636 queue_slots_remaining = this.fileQueueLimit - this.queued_uploads; 637 } 638 } 639 640 if (queue_slots_remaining < 0) queue_slots_remaining = 0; 482 queue_slots_remaining = this.fileQueueLimit; 483 } 484 } 641 485 642 486 // Check if the number of files selected is greater than the number allowed to queue up. … … 694 538 695 539 this.Debug("Event: fileDialogComplete : Finished processing selected files. Files selected: " + file_reference_list.length + ". Files Queued: " + num_files_queued); 696 ExternalCall.FileDialogComplete(this.fileDialogComplete_Callback, file_reference_list.length, num_files_queued , this.queued_uploads);540 ExternalCall.FileDialogComplete(this.fileDialogComplete_Callback, file_reference_list.length, num_files_queued); 697 541 } 698 542 … … 750 594 this.current_file_item.file_reference.cancel(); 751 595 596 this.current_file_item.file_status = FileItem.FILE_STATUS_QUEUED; 597 752 598 // Remove the event handlers 753 599 this.removeFileReferenceEventListeners(this.current_file_item); 754 600 755 this.current_file_item.file_status = FileItem.FILE_STATUS_QUEUED;756 601 this.file_queue.unshift(this.current_file_item); 757 602 var js_object:Object = this.current_file_item.ToJavaScriptObject(); … … 774 619 * If the file is not currently uploading then only the uploadCancelled event is fired. 775 620 * */ 776 private function CancelUpload(file_id:String , triggerErrorEvent:Boolean = true):void {621 private function CancelUpload(file_id:String):void { 777 622 var file_item:FileItem = null; 778 623 … … 783 628 this.upload_cancelled++; 784 629 785 if (triggerErrorEvent) { 786 this.Debug("Event: uploadError: File ID: " + this.current_file_item.id + ". Cancelled current upload"); 787 ExternalCall.UploadError(this.uploadError_Callback, this.ERROR_CODE_FILE_CANCELLED, this.current_file_item.ToJavaScriptObject(), "File Upload Cancelled."); 788 } else { 789 this.Debug("Event: cancelUpload: File ID: " + this.current_file_item.id + ". Cancelled current upload. Suppressed uploadError event."); 790 } 630 this.Debug("Event: uploadError: File ID: " + this.current_file_item.id + ". Cancelled current upload"); 631 ExternalCall.UploadError(this.uploadError_Callback, this.ERROR_CODE_FILE_CANCELLED, this.current_file_item.ToJavaScriptObject(), "File Upload Cancelled."); 632 791 633 this.UploadComplete(false); 792 634 } else if (file_id) { … … 806 648 file_item.file_reference = null; 807 649 808 if (triggerErrorEvent) { 809 this.Debug("Event: uploadError : " + file_item.id + ". Cancelled queued upload"); 810 ExternalCall.UploadError(this.uploadError_Callback, this.ERROR_CODE_FILE_CANCELLED, file_item.ToJavaScriptObject(), "File Cancelled"); 811 } else { 812 this.Debug("Event: cancelUpload: File ID: " + file_item.id + ". Cancelled current upload. Suppressed uploadError event."); 813 } 650 this.Debug("Event: uploadError : " + file_item.id + ". Cancelled queued upload"); 651 ExternalCall.UploadError(this.uploadError_Callback, this.ERROR_CODE_FILE_CANCELLED, file_item.ToJavaScriptObject(), "File Cancelled"); 814 652 815 653 // Get rid of the file object … … 838 676 file_item.file_reference = null; 839 677 840 if (triggerErrorEvent) { 841 this.Debug("Event: uploadError : " + file_item.id + ". Cancelled queued upload"); 842 ExternalCall.UploadError(this.uploadError_Callback, this.ERROR_CODE_FILE_CANCELLED, file_item.ToJavaScriptObject(), "File Cancelled"); 843 } else { 844 this.Debug("Event: cancelUpload: File ID: " + file_item.id + ". Cancelled current upload. Suppressed uploadError event."); 845 } 678 this.Debug("Event: uploadError : " + file_item.id + ". Cancelled queued upload"); 679 ExternalCall.UploadError(this.uploadError_Callback, this.ERROR_CODE_FILE_CANCELLED, file_item.ToJavaScriptObject(), "File Cancelled"); 846 680 847 681 // Get rid of the file object … … 853 687 } 854 688 855 /* Requeues the indicated file. Returns true if successful or if the file is856 * already in the queue. Otherwise returns false.857 * */858 private function RequeueUpload(fileIdentifier:*):Boolean {859 var file:FileItem = null;860 if (typeof(fileIdentifier) === "number") {861 var fileIndex:Number = Number(fileIdentifier);862 if (fileIndex >= 0 && fileIndex < this.file_index.length) {863 file = this.file_index[fileIndex];864 }865 } else if (typeof(fileIdentifier) === "string") {866 file = FindFileInFileIndex(String(fileIdentifier));867 } else {868 return false;869 }870 871 if (file !== null) {872 if (file.file_status === FileItem.FILE_STATUS_IN_PROGRESS || file.file_status === FileItem.FILE_STATUS_NEW) {873 return false;874 } else if (file.file_status !== FileItem.FILE_STATUS_QUEUED) {875 file.file_status = FileItem.FILE_STATUS_QUEUED;876 this.file_queue.unshift(file);877 this.queued_uploads++;878 }879 return true;880 } else {881 return false;882 }883 }884 885 886 689 private function GetStats():Object { 887 690 return { … … 1034 837 } 1035 838 1036 private function SetHTTPSuccess(http_status_codes:*):void {1037 this.httpSuccess = [];1038 1039 if (typeof http_status_codes === "string") {1040 var status_code_strings:Array = http_status_codes.replace(" ", "").split(",");1041 for each (var http_status_string:String in status_code_strings)1042 {1043 try {1044 this.httpSuccess.push(Number(http_status_string));1045 } catch (ex:Object) {1046 // Ignore errors1047 this.Debug("Could not add HTTP Success code: " + http_status_string);1048 }1049 }1050 }1051 else if (typeof http_status_codes === "object" && typeof http_status_codes.length === "number") {1052 for each (var http_status:* in http_status_codes)1053 {1054 try {1055 this.Debug("adding: " + http_status);1056 this.httpSuccess.push(Number(http_status));1057 } catch (ex:Object) {1058 this.Debug("Could not add HTTP Success code: " + http_status);1059 }1060 }1061 }1062 }1063 1064 private function SetAssumeSuccessTimeout(timeout_seconds:Number):void {1065 this.assumeSuccessTimeout = timeout_seconds < 0 ? 0 : timeout_seconds;1066 }1067 1068 839 private function SetDebugEnabled(debug_enabled:Boolean):void { 1069 840 this.debugEnabled = debug_enabled; … … 1129 900 this.buttonTextField.width = this.buttonWidth; 1130 901 this.buttonTextField.height = this.buttonHeight; 1131 this.buttonCursorSprite.width = this.buttonWidth;1132 this.buttonCursorSprite.height = this.buttonHeight;1133 902 1134 903 this.UpdateButtonState(); … … 1162 931 private function SetButtonAction(button_action:Number):void { 1163 932 this.buttonAction = button_action; 1164 }1165 1166 private function SetButtonCursor(button_cursor:Number):void {1167 this.buttonCursor = button_cursor;1168 1169 this.buttonCursorSprite.useHandCursor = (button_cursor === this.BUTTON_CURSOR_HAND);1170 933 } 1171 934 … … 1214 977 // Trigger the uploadStart event which will call ReturnUploadStart to begin the actual upload 1215 978 this.Debug("Event: uploadStart : File ID: " + this.current_file_item.id); 1216 1217 this.current_file_item.file_status = FileItem.FILE_STATUS_IN_PROGRESS;1218 979 ExternalCall.UploadStart(this.uploadStart_Callback, this.current_file_item.ToJavaScriptObject()); 1219 980 } … … 1231 992 return; 1232 993 } 1233 1234 var js_object:Object;1235 994 1236 995 if (start_upload) { … … 1242 1001 this.current_file_item.file_reference.addEventListener(SecurityErrorEvent.SECURITY_ERROR, this.SecurityError_Handler); 1243 1002 this.current_file_item.file_reference.addEventListener(HTTPStatusEvent.HTTP_STATUS, this.HTTPError_Handler); 1244 this.current_file_item.file_reference.addEventListener(Event.COMPLETE, this.Complete_Handler);1245 1003 this.current_file_item.file_reference.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA, this.ServerData_Handler); 1246 1004 … … 1250 1008 if (this.uploadURL.length == 0) { 1251 1009 this.Debug("Event: uploadError : IO Error : File ID: " + this.current_file_item.id + ". Upload URL string is empty."); 1252 1253 // Remove the event handlers 1254 this.removeFileReferenceEventListeners(this.current_file_item); 1255 1256 this.current_file_item.file_status = FileItem.FILE_STATUS_QUEUED; 1257 this.file_queue.unshift(this.current_file_item); 1258 js_object = this.current_file_item.ToJavaScriptObject(); 1259 this.current_file_item = null; 1260 1261 ExternalCall.UploadError(this.uploadError_Callback, this.ERROR_CODE_MISSING_UPLOAD_URL, js_object, "Upload URL string is empty."); 1010 ExternalCall.UploadError(this.uploadError_Callback, this.ERROR_CODE_MISSING_UPLOAD_URL, this.current_file_item.ToJavaScriptObject(), "Upload URL string is empty."); 1262 1011 } else { 1263 1012 this.Debug("ReturnUploadStart(): File accepted by startUpload event and readied for upload. Starting upload to " + request.url + " for File ID: " + this.current_file_item.id); … … 1283 1032 // Re-queue the FileItem 1284 1033 this.current_file_item.file_status = FileItem.FILE_STATUS_QUEUED; 1285 js_object = this.current_file_item.ToJavaScriptObject();1034 var js_object:Object = this.current_file_item.ToJavaScriptObject(); 1286 1035 this.file_queue.unshift(this.current_file_item); 1287 1036 this.current_file_item = null; … … 1295 1044 1296 1045 // Completes the file upload by deleting it's reference, advancing the pointer. 1297 // Once this event fi res a new upload can be started.1046 // Once this event files a new upload can be started. 1298 1047 private function UploadComplete(eligible_for_requeue:Boolean):void { 1299 1048 var jsFileObj:Object = this.current_file_item.ToJavaScriptObject(); … … 1305 1054 this.queued_uploads--; 1306 1055 } else if (this.requeueOnError == true) { 1307 this.current_file_item.file_status = FileItem.FILE_STATUS_QUEUED;1308 1056 this.file_queue.unshift(this.current_file_item); 1309 1057 } … … 1319 1067 Utility Functions 1320 1068 *************************************************************** */ 1321 1322 1323 1069 // Check the size of the file against the allowed file size. If it is less the return TRUE. If it is too large return FALSE 1324 1070 private function CheckFileSize(file_item:FileItem):Number { … … 1427 1173 debug_info += "File Types String: " + this.fileTypes + "\n"; 1428 1174 debug_info += "Parsed File Types: " + this.valid_file_extensions.toString() + "\n"; 1429 debug_info += "HTTP Success: " + this.httpSuccess.join(", ") + "\n";1430 1175 debug_info += "File Types Description: " + this.fileTypesDescription + "\n"; 1431 1176 debug_info += "File Size Limit: " + this.fileSizeLimit + " bytes\n"; … … 1444 1189 1445 1190 private function FindIndexInFileQueue(file_id:String):Number { 1446 for (var i:Number = 0; i <this.file_queue.length; i++) {1191 for (var i:Number = 0; i<this.file_queue.length; i++) { 1447 1192 var item:FileItem = this.file_queue[i]; 1448 1193 if (item != null && item.id == file_id) return i;