var idUploader = "uploader"; var idUploadButton = "idUploadButton"; var idLayerProgress = "layerUploadProgress"; var idLayerProgressBar = "layerUploadProgressBar"; var idLayerError = "layerUploadError"; var idLayerSelector = "myimageSelector"; var idSizeSelector = "myimageSize"; var idMediumSelector = "myimageMedium"; var idMediumPrice = "myimagePrice"; var idFieldSize = "myimageFieldSize"; var idFieldMedium = "myimageFieldMedium"; function convertDPI( vl ) { return vl; } function convertDPIReverse( vl ) { return vl; } function upload_file_start_callback() { myimageShowButton(false); myimageShowError(false); myimageShowSelector(false); myimageShowProgress(true); myimageShowProgressBar(0); } function upload_progress_callback(bytes, total) { n = Math.round(bytes * 100 / total); if (n < 100) { myimageShowProgressBar(n); } } function upload_file_complete_callback() { myimageShowProgressBar(100); if( typeof( myImagesOnCompleteUrl ) != 'undefined' ) { document.location.href=myImagesOnCompleteUrl; } else { document.location.href='my_images.html?go=y'; } myimageShowButton(true); myimageShowSelector(true); } function upload_file_error_callback() { myimageShowButton(true); myimageShowError(true); } function uploadFile() { var o = document.getElementById(idUploader); var c=''; for( var i in o ) { if( typeof( o[i] )=='function' ) { c+=( i+':'+o[i])+'\n'; } } alert( c ); o.browse(); } function myimageShowProgressBar(n) { var o = document.getElementById(idLayerProgressBar); o.style.width = n + "%"; if (n > 10) { o.innerHTML = n + " %"; } else { o.innerHTML = " "; } } function myimageShowProgress(visible) { var o = document.getElementById(idLayerProgress); o.style.display = (visible ? "" : "none"); } function myimageShowError(visible) { var o = document.getElementById(idLayerError); o.style.display = (visible ? "" : "none"); } function myimageShowSelector(visible) { /* var o = document.getElementById(idLayerSelector); o.style.display = (visible ? "" : "none"); if (visible) { o.src = "myimage-create.php?file=" + myimageFileId; } else { o.src = "myimage-blank.php"; } */ } function myimageShowButton(enabled) { var o = document.getElementById(idUploadButton); o.disabled = !enabled; } function myimageSelectSize() { var o = document.getElementById(idSizeSelector); var size = o.value; myimageFillMediumList(myimageGetMediumList(size)); myimageSetPrice(); } function myimageFillMediumList(list) { var o = document.getElementById(idMediumSelector); o.length = 0; var mlist = list.split(" "); for (var i=0; i < mlist.length; i++) { var row = mlist[i].split(":"); var mediumId = row[0]; var mediumName = myimageGetMediumName(mediumId); o.options[i] = new Option(mediumName, mediumId, false, false); } } function myimageSetPrice() { var size = document.getElementById(idSizeSelector).value; var mediumId = document.getElementById(idMediumSelector).value; var list = myimageGetMediumList(size); var price = "n/a"; var mlist = list.split(" "); for (var i=0; i < mlist.length; i++) { var row = mlist[i].split(":"); if (mediumId == row[0]) { price = "$" + row[1]; break; } } document.getElementById(idMediumPrice).innerHTML = price; document.getElementById(idFieldSize).value = size; document.getElementById(idFieldMedium).value = mediumId; } function myimageGetMediumList(size) { for (i = 0; i < myimageSizeList.length; i++) { if (myimageSizeList[i][0] == size) { return myimageSizeList[i][1]; } } return ""; } function myimageGetMediumName(mediumId) { for (var i = 0; i < myimageMediumList.length; i++) { if (myimageMediumList[i][0] == mediumId) { return myimageMediumList[i][1]; } } } function addEvent( obj,evt,act ) { evtFunc=obj[evt]; if(obj[evt] ) { if( typeof(obj[evt])=='function') { var i=obj[evt].toString().indexOf("{"); obj[evt]=new Function("e",obj[evt].toString().substr(i)+act); } else { obj[evt]=new Function("e",act); } } else { obj[evt]=new Function("e",act); } } function replaceAll (streng, soeg, erstat) { var st = streng; if (soeg.length == 0) return st; var idx = st.indexOf(soeg); while (idx >= 0) { st = st.substring(0,idx) + erstat + st.substr(idx+soeg.length); idx = st.indexOf(soeg); } return st; } function cropperMediumChange() { if( !( cropperSelectedMediumid < 0 ) ) { var medium = cropperMediumElement.getValue(); if( cropperMediumOptions[ medium ]['canframe'] ) { var l = new HTMLLayer( 'myimagesframebutton'); l.style.display=''; var l = new HTMLLayer( 'myimagesaddtocartbutton'); l.style.display='none'; } else { var l = new HTMLLayer( 'myimagesframebutton'); l.style.display='none'; var l = new HTMLLayer( 'myimagesaddtocartbutton'); l.style.display=''; } //myimagesframebutton var paperSize = cropperPaperSizeElement.getValue(); var l = new HTMLLayer( 'cropper_paper_size'); var c = '"; l.write(c); cropperPaperSizeElement = new HTMLLayer('cropper_paper_size_select'); } } function cropperDrawMediumSelectElement() { if( !( cropperSelectedMediumid < 0 ) ) { var l = new HTMLLayer( 'cropper_medium'); var c = '"; l.write(c); cropperMediumElement = new HTMLLayer( 'cropper_medium_select'); } } function cropperPaperSizeChange() { if( cropperSelectedMediumid < 0 ) { resetSelected(); } else { var medium = cropperMediumElement.getValue(); var paperSize = cropperPaperSizeElement.getValue(); currentPaperSize=Array(cropperMediumOptions[medium]['options'][paperSize]['w'],cropperMediumOptions[medium]['options'][paperSize]['h']); resetSelected(); } } function resetSelected() { var pictureRatio=pictureH/pictureW; var paperRatio=currentPaperSize[1]/currentPaperSize[0]; var paperPixelPos; if( pictureW> pictureH ) { paperPixelPos=Array(0,0,pictureW,Math.round(pictureW*paperRatio)); } else { paperPixelPos=Array(0,0,Math.round(pictureH/paperRatio),pictureH); } if( paperPixelPos[2]>pictureW ) { paperPixelPos[3]=Math.round(paperPixelPos[3]*pictureW/paperPixelPos[2]); paperPixelPos[2]=pictureW; } if( paperPixelPos[3]>pictureH ) { paperPixelPos[2]=Math.round(paperPixelPos[2]*pictureH/paperPixelPos[3]); paperPixelPos[3]=pictureH; } diffX=(pictureW-paperPixelPos[2])/2; diffY=(pictureH-paperPixelPos[3])/2; ele_pictureX1.value=(paperPixelPos[0]+diffX)/pictureW; ele_pictureX2.value=(paperPixelPos[2]+diffX)/pictureW; ele_pictureY1.value=(paperPixelPos[1]+diffY)/pictureH; ele_pictureY2.value=(paperPixelPos[3]+diffY)/pictureH; picture_dpi= Math.round(10000*pictureW*( convertDPI( (ele_pictureX2.value-ele_pictureX1.value)/currentPaperSize[0])))/10000; if( !( cropperSelectedMediumid < 0 ) ) { var l=new HTMLLayer("picture_ppi"); l.write(picture_dpi); } updateSelected(); fullWidthCrop = ele_pictureX2.value-ele_pictureX1.value; } function setDPI( dpi ) { cropperCalibrate1 = -1; cropperCalibrate2 = -1; ele_pictureX2.value=1*ele_pictureX1.value+convertDPIReverse((currentPaperSize[0]*dpi)/pictureW); ele_pictureY2.value=1*ele_pictureY1.value+convertDPIReverse((currentPaperSize[1]*dpi)/pictureH); moveSelected(0,0); picture_dpi= Math.round((10000*convertDPI(pictureW*(ele_pictureX2.value-ele_pictureX1.value))/(currentPaperSize[0])))/10000; if( picture_dpi < cropperMinimumDPI ) { setDPI( dpi+0.000001 ) } else { picture_dpi= Math.round(100*picture_dpi)/100; if( !( cropperSelectedMediumid < 0 ) ) { var l=new HTMLLayer("picture_ppi"); l.write(picture_dpi); } } } function updateSelected() { var x1=(Math.round(pictureW*ele_pictureX1.value)); var y1=(Math.round(pictureH*ele_pictureY1.value)); var x2=(Math.round(pictureW*ele_pictureX2.value)); var y2=(Math.round(pictureH*ele_pictureY2.value)); var vx1=(Math.round(viewimageW*ele_pictureX1.value)); var vy1=(Math.round(viewimageH*ele_pictureY1.value)); var vx2=(Math.round(viewimageW*ele_pictureX2.value)); var vy2=(Math.round(viewimageH*ele_pictureY2.value)); cropperCroppedW=(x2-x1); cropperCroppedH=(y2-y1); if( fullimage_selected ) { fullimage_selected.style.backgroundPosition="-"+x1+"px -"+y1+"px "; fullimage_selected.style.width=(x2-x1)+"px"; fullimage_selected.style.height=(y2-y1)+"px"; } if( useTechnique == 0 ) { viewimage_selected.style.marginTop="10px"; var diff=viewimage_selected_outer.getTop(); viewimage_selected.style.marginTop="20px"; diff-=viewimage_selected_outer.getTop(); if( diff ==0 ) { useTechnique = 1; } else { viewimage_selected.style.marginLeft="0"; viewimage_selected.style.marginTop="0"; viewimage_selected.style.marginRight="0"; viewimage_selected.style.marginBottom="0"; viewimage_selected_outer.overflow='hidden'; useTechnique = 2; } } //viewimage_selected.style.backgroundPosition="-"+(vx1+1)+"px -"+vy1+"px "; if( useTechnique==1 ) { viewimage_selected.style.width=((vx2-vx1)-2)+"px"; viewimage_selected.style.height=((vy2-vy1)-2)+"px"; viewimage_selected_outer.width=viewimageW+"px"; viewimage_selected_outer.height=viewimageH+"px"; viewimage_selected.style.marginLeft=vx1+"px"; viewimage_selected.style.marginTop=vy1+"px"; viewimage_selected.style.marginRight=(viewimageW-vx2)+"px"; viewimage_selected.style.marginBottom=(viewimageH-vy2)+1+"px" viewimage_selected_outer.width=viewimageW+"px"; viewimage_selected_outer.height=viewimageH+"px"; } else if( useTechnique==2 ) { viewimage_selected_outer.width=viewimageW+"px"; viewimage_selected_outer.height=viewimageH+"px"; viewimage_selected.style.width=(vx2-vx1-2)+"px"; viewimage_selected.style.height=(vy2-vy1-2)+"px"; viewimage_selected_outer.style.paddingLeft=(vx1)+"px"; viewimage_selected_outer.style.paddingTop=(vy1)+"px"; viewimage_selected_outer.style.width=viewimageW-(vx1)+"px"; viewimage_selected_outer.style.height=viewimageH-(vy1)+"px"; } //viewimage_selected_resizer.style.marginTop=((vy2-vy1)-14)+"px"; } function moveSelected(dx,dy) { dx = Math.round(dx*pictureW/viewimageW); dy = Math.round(dy*pictureH/viewimageH); dx/=pictureW; dy/=pictureH; ele_pictureX1.value=1*dx+1*ele_pictureX1.value; ele_pictureX2.value=1*dx+1*ele_pictureX2.value; ele_pictureY1.value=1*dy+1*ele_pictureY1.value; ele_pictureY2.value=1*dy+1*ele_pictureY2.value; if( ele_pictureX1.value< 0 ) { ele_pictureX2.value=1*ele_pictureX2.value-1*ele_pictureX1.value; ele_pictureX1.value=0; } if( ele_pictureX2.value> 1 ) { ele_pictureX1.value=1+(1*ele_pictureX1.value-1*ele_pictureX2.value); ele_pictureX2.value=1; } if( ele_pictureY1.value< 0 ) { ele_pictureY2.value=1*ele_pictureY2.value-1*ele_pictureY1.value; ele_pictureY1.value=0; } if( ele_pictureY2.value> 1 ) { ele_pictureY1.value=1+(1*ele_pictureY1.value-1*ele_pictureY2.value); ele_pictureY2.value=1; } if( ele_pictureX2.value> 1 ) { var adjust=ele_pictureX2.value-1; ele_pictureX2.value = 1*ele_pictureX2.value - adjust; ele_pictureY2.value = 1*ele_pictureY2.value -adjust*pictureH/pictureW; } if( ele_pictureY2.value> 1 ) { var adjust=ele_pictureY2.value-1; ele_pictureY2.value = 1*ele_pictureY2.value - adjust; ele_pictureX2.value = 1*ele_pictureX2.value - (pictureW/pictureH); } if( ele_pictureX1.value< 0 ) { var adjust=-ele_pictureX1.value; ele_pictureX1.value = 1*ele_pictureX1.value + adjust; ele_pictureY1.value = 1*ele_pictureY1.value + (adjust*pictureW/pictureH); } if( ele_pictureY1.value< 0 ) { var adjust=-ele_pictureY1.value; ele_pictureY1.value = 1*ele_pictureY1.value + adjust; ele_pictureX1.value = 1*ele_pictureX1.value + (adjust*pictureW/pictureH); } updateSelected(); } function cropperMouseDown( e ) { var point=getMouseClickPosition( e,pageLayer); mouseDownPoint = point; var point1=getMouseClickPosition( e,viewimage_selected); var edX = viewimage_selected.getWidth()-point1.x; var edY = viewimage_selected.getHeight()-point1.y; cropperIsResizer = (edX>=0 && edX<=10 && edY>=0 && edY<=10 ); if( cropperIsResizer ) { viewimage_selected.style.backgroundImage='url(\'plugins/myimages/resize_box2.gif\')'; cropperLastDPI = 0; cropperLastDY = 0; cropperDownX1 = point.x; cropperDownY1 = point.y; cropperDownW = cropperCroppedW; cropperDownH = cropperCroppedH; cropperOldBorder = viewimage_selected.style.border; cropperStartDPI=picture_dpi; } else { cropperLastDX = 0; cropperLastDY = 0; cropperDownX1 = point.x; cropperDownY1 = point.y; cropperOldBorder = viewimage_selected.style.border; viewimage_selected.style.border="1px solid yellow"; } return false; } function cropperMouseMove( e ) { if( cropperDownX1 ==-10000) { return; } var point=getMouseClickPosition( e,pageLayer); cropperCalibrate1=point; cropperCalibrate2=-1 // var l=new HTMLLayer("picture_ppi"); // l.write("MOVE1:"+point.x+":"+point.y+":"+e.srcElement.offsetLeft); if( cropperIsResizer ) { cropperChangeSize( point ); } else { dx = point.x-cropperDownX1 ; dy = point.y -cropperDownY1; moveSelected(dx-cropperLastDX,dy-cropperLastDY); cropperLastDX=dx; cropperLastDY=dy; } } function cropperChangeSize( point ) { var dx = (point.x-cropperDownX1)*pictureW/viewimageW; var dy = (point.y-cropperDownY1)*pictureH/viewimageH; var x1 = 1*ele_pictureX1.value; var y1 = 1*ele_pictureY1.value; var maxDpi = Math.min( ((1-x1)*pictureW)/currentPaperSize[0],((1-y1)*pictureH)/currentPaperSize[1] ); var x = cropperDownW+dx; var y = cropperDownH+dy; dpi = convertDPI( Math.min(Math.max( convertDPIReverse( cropperMinimumDPI ), ((x/currentPaperSize[0])+(y/currentPaperSize[1]))/2),maxDpi) ); setDPI( dpi ); } function cropperMouseMove2( e ) { if( cropperDownX1 ==-10000 ) { ignoreNextMouseMove2 = false; return; } e=e?e:window.event; var point=getMouseClickPosition( e,pageLayer); if( cropperCalibrate1!=-1 && cropperCalibrate2==-1) { cropperCalibrate2=cropperCalibrate1; cropperCalibrate2.x-=point.x; cropperCalibrate2.y-=point.y; } if( !cropperIsResizer && cropperCalibrate1!=-1 ) { point.x+=cropperCalibrate2.x; point.y+=cropperCalibrate2.y; } if( cropperIsResizer ) { cropperChangeSize( point ); } else { /* dx = point.x-cropperDownX1 ; dy = point.y -cropperDownY1; moveSelected(dx-cropperLastDX,dy-cropperLastDY); cropperLastDX=dx; cropperLastDY=dy;*/ } } function cropperMouseUp( e ) { var point=getMouseClickPosition( e,viewimage_selected); viewimage_selected.style.border="1px solid red"; viewimage_selected.style.backgroundImage='url(\'plugins/myimages/resize_box1.gif\')'; //viewimage_selected_resizer.style.border="1px solid red"; // dx = point.x-cropperDownX1 ; // dy = point.y -cropperDownY1; // moveSelected(dx,dy) cropperIsResizer = false; cropperDownX1 = -10000; cropperDownY1 = -10000; } function setCropperIsResizer() { cropperIsResizer = true; viewimage_selected.style.border="1px solid red"; viewimage_selected_resizer.style.border="1px solid yellow"; } function disableSelection(t){ if (typeof t.onselectstart!="undefined") //IE route { t.onmousedown=function(){return false} t.onselectstart=function(){return false} } else if (typeof t.style.MozUserSelect!="undefined") //Firefox route { t.style.MozUserSelect="none" ; } else //All other route (ie: Opera) t.onmousedown=function(){return false} t.style.cursor = "default" } var cropperDownX1=-10000; var cropperDownY1=-10000; /* Demo Note: This demo uses a FileProgress class that handles the UI for displaying the file name and percent complete. The FileProgress class is not part of SWFUpload. */ /* ********************** Event Handlers These are my custom event handlers to make my web application behave the way I went when SWFUpload completes different tasks. These aren't part of the SWFUpload package. They are part of my application. Without these none of the actions SWFUpload makes will show up in my application. ********************** */ function fileQueued(file) { try { var progress = new FileProgress(file, this.customSettings.progressTarget); progress.setStatus("Pending..."); progress.toggleCancel(true, this); } catch (ex) { alert(ex); } } function fileQueueError(file, errorCode, message) { try { if (errorCode === SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED) { 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."))); return; } var l = new HTMLLayer( 'upload_button' ); l.style.marginTop='0px'; var progress = new FileProgress(file, this.customSettings.progressTarget); progress.setError(); progress.toggleCancel(false); switch (errorCode) { case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT: progress.setStatus("File is too big."); this.debug("Error Code: File too big, File name: " + file.name + ", File size: " + file.size + ", Message: " + message); break; case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE: progress.setStatus("Cannot upload Zero Byte files."); this.debug("Error Code: Zero byte file, File name: " + file.name + ", File size: " + file.size + ", Message: " + message); break; case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE: progress.setStatus("Invalid File Type."); this.debug("Error Code: Invalid File Type, File name: " + file.name + ", File size: " + file.size + ", Message: " + message); break; default: if (file !== null) { progress.setStatus("Unhandled Error"); } this.debug("Error Code: " + errorCode + ", File name: " + file.name + ", File size: " + file.size + ", Message: " + message); break; } } catch (ex) { alert(ex); } } function fileDialogComplete(numFilesSelected, numFilesQueued) { try { if (numFilesSelected > 0) { var l = new HTMLLayer( 'upload_button' ); l.style.marginTop='2000px'; } /* I want auto start the upload and I can do that here */ this.startUpload(); } catch (ex) { alert(ex); } } function uploadStart(file) { try { /* I don't want to do any file validation or anything, I'll just update the UI and return true to indicate that the upload should start. It's important to update the UI here because in Linux no uploadProgress events are called. The best we can do is say we are uploading. */ var progress = new FileProgress(file, this.customSettings.progressTarget); progress.setStatus("Uploading..."); //progress.toggleCancel(true, this); } catch (ex) {alert( ex );} return true; } function uploadProgress(file, bytesLoaded, bytesTotal) { try { var percent = Math.ceil((bytesLoaded / bytesTotal) * 100); var progress = new FileProgress(file, this.customSettings.progressTarget); progress.setProgress(percent); progress.setStatus("Uploading..."); if( bytesLoaded >= bytesTotal ) { progress.setStatus("Complete."); // document.location.href='my_images.html?go=y'; } } catch (ex) { alert(ex); } } function uploadSuccess(file, serverData) { try { var progress = new FileProgress(file, this.customSettings.progressTarget); progress.setComplete(); progress.setStatus("Complete."); progress.toggleCancel(false); } catch (ex) { alert(ex); } } function uploadError(file, errorCode, message) { try { var l = new HTMLLayer( 'upload_button' ); l.style.marginTop='0px'; var progress = new FileProgress(file, this.customSettings.progressTarget); progress.setError(); progress.toggleCancel(false); switch (errorCode) { case SWFUpload.UPLOAD_ERROR.HTTP_ERROR: progress.setStatus("Upload Error: " + message); this.debug("Error Code: HTTP Error, File name: " + file.name + ", Message: " + message); break; case SWFUpload.UPLOAD_ERROR.UPLOAD_FAILED: progress.setStatus("Upload Failed."); this.debug("Error Code: Upload Failed, File name: " + file.name + ", File size: " + file.size + ", Message: " + message); break; case SWFUpload.UPLOAD_ERROR.IO_ERROR: progress.setStatus("Server (IO) Error"); this.debug("Error Code: IO Error, File name: " + file.name + ", Message: " + message); break; case SWFUpload.UPLOAD_ERROR.SECURITY_ERROR: progress.setStatus("Security Error"); this.debug("Error Code: Security Error, File name: " + file.name + ", Message: " + message); break; case SWFUpload.UPLOAD_ERROR.UPLOAD_LIMIT_EXCEEDED: progress.setStatus("Upload limit exceeded."); this.debug("Error Code: Upload Limit Exceeded, File name: " + file.name + ", File size: " + file.size + ", Message: " + message); break; case SWFUpload.UPLOAD_ERROR.FILE_VALIDATION_FAILED: progress.setStatus("Failed Validation. Upload skipped."); this.debug("Error Code: File Validation Failed, File name: " + file.name + ", File size: " + file.size + ", Message: " + message); break; case SWFUpload.UPLOAD_ERROR.FILE_CANCELLED: // If there aren't any files left (they were all cancelled) disable the cancel button if (this.getStats().files_queued === 0) { document.getElementById(this.customSettings.cancelButtonId).disabled = true; } progress.setStatus("Cancelled"); progress.setCancelled(); break; case SWFUpload.UPLOAD_ERROR.UPLOAD_STOPPED: progress.setStatus("Stopped"); break; default: progress.setStatus("Unhandled Error: " + errorCode); this.debug("Error Code: " + errorCode + ", File name: " + file.name + ", File size: " + file.size + ", Message: " + message); break; } } catch (ex) { alert(ex); } } function uploadComplete(file) { if (this.getStats().files_queued === 0) { if( typeof( myImagesOnCompleteUrl ) != 'undefined' ) { document.location.href=myImagesOnCompleteUrl; } else { document.location.href='my_images.html?go=y'; } // document.getElementById(this.customSettings.cancelButtonId).disabled = true; } } // This event comes from the Queue Plugin function queueComplete(numFilesUploaded) { /* var status = document.getElementById("divStatus"); status.innerHTML = numFilesUploaded + " file" + (numFilesUploaded === 1 ? "" : "s") + " uploaded."; */ } function FileProgress(file, targetID) { this.fileProgressID = file.id; this.opacity = 100; this.height = 0; this.fileProgressWrapper = document.getElementById(this.fileProgressID); if (!this.fileProgressWrapper) { this.fileProgressWrapper = document.createElement("div"); this.fileProgressWrapper.className = "progressWrapper"; this.fileProgressWrapper.id = this.fileProgressID; this.fileProgressElement = document.createElement("div"); this.fileProgressElement.className = "progressContainer"; var progressCancel = document.createElement("a"); progressCancel.className = "progressCancel"; progressCancel.href = "#"; progressCancel.style.visibility = "hidden"; progressCancel.appendChild(document.createTextNode(" ")); var progressText = document.createElement("div"); progressText.className = "progressName"; progressText.appendChild(document.createTextNode(file.name)); var progressBar = document.createElement("div"); progressBar.className = "progressBarInProgress"; var progressStatus = document.createElement("div"); progressStatus.className = "progressBarStatus"; progressStatus.innerHTML = " "; this.fileProgressElement.appendChild(progressCancel); this.fileProgressElement.appendChild(progressText); this.fileProgressElement.appendChild(progressStatus); this.fileProgressElement.appendChild(progressBar); this.fileProgressWrapper.appendChild(this.fileProgressElement); document.getElementById(targetID).appendChild(this.fileProgressWrapper); } else { this.fileProgressElement = this.fileProgressWrapper.firstChild; } this.height = this.fileProgressWrapper.offsetHeight; } FileProgress.prototype.setProgress = function (percentage) { this.fileProgressElement.className = "progressContainer green"; this.fileProgressElement.childNodes[3].className = "progressBarInProgress"; this.fileProgressElement.childNodes[3].style.width = percentage + "%"; }; FileProgress.prototype.setComplete = function () { this.fileProgressElement.className = "progressContainer blue"; this.fileProgressElement.childNodes[3].className = "progressBarComplete"; this.fileProgressElement.childNodes[3].style.width = ""; var oSelf = this; setTimeout(function () { oSelf.disappear(); }, 10000); }; FileProgress.prototype.setError = function () { this.fileProgressElement.className = "progressContainer red"; this.fileProgressElement.childNodes[3].className = "progressBarError"; this.fileProgressElement.childNodes[3].style.width = ""; var oSelf = this; setTimeout(function () { oSelf.disappear(); }, 5000); }; FileProgress.prototype.setCancelled = function () { this.fileProgressElement.className = "progressContainer"; this.fileProgressElement.childNodes[3].className = "progressBarError"; this.fileProgressElement.childNodes[3].style.width = ""; var oSelf = this; setTimeout(function () { oSelf.disappear(); }, 2000); }; FileProgress.prototype.setStatus = function (status) { this.fileProgressElement.childNodes[2].innerHTML = status; }; // Show/Hide the cancel button FileProgress.prototype.toggleCancel = function (show, swfUploadInstance) { this.fileProgressElement.childNodes[0].style.visibility = show ? "visible" : "hidden"; if (swfUploadInstance) { var fileID = this.fileProgressID; this.fileProgressElement.childNodes[0].onclick = function () { swfUploadInstance.cancelUpload(fileID); return false; }; } }; // Fades out and clips away the FileProgress box. FileProgress.prototype.disappear = function () { var reduceOpacityBy = 15; var reduceHeightBy = 4; var rate = 30; // 15 fps if (this.opacity > 0) { this.opacity -= reduceOpacityBy; if (this.opacity < 0) { this.opacity = 0; } if (this.fileProgressWrapper.filters) { try { this.fileProgressWrapper.filters.item("DXImageTransform.Microsoft.Alpha").opacity = this.opacity; } catch (e) { // If it is not set initially, the browser will throw an error. This will set it if it is not set yet. this.fileProgressWrapper.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=" + this.opacity + ")"; } } else { this.fileProgressWrapper.style.opacity = this.opacity / 100; } } if (this.height > 0) { this.height -= reduceHeightBy; if (this.height < 0) { this.height = 0; } this.fileProgressWrapper.style.height = this.height + "px"; } if (this.height > 0 || this.opacity > 0) { var oSelf = this; setTimeout(function () { oSelf.disappear(); }, rate); } else { this.fileProgressWrapper.style.display = "none"; } }; /* Queue Plug-in Features: *Adds a cancelQueue() method for cancelling the entire queue. *All queued files are uploaded when startUpload() is called. *If false is returned from uploadComplete then the queue upload is stopped. If false is not returned (strict comparison) then the queue upload is continued. *Adds a QueueComplete event that is fired when all the queued files have finished uploading. Set the event handler with the queue_complete_handler setting. */ var SWFUpload; if (typeof(SWFUpload) === "function") { SWFUpload.queue = {}; SWFUpload.prototype.initSettings = (function (oldInitSettings) { return function () { if (typeof(oldInitSettings) === "function") { oldInitSettings.call(this); } this.customSettings.queue_cancelled_flag = false; this.customSettings.queue_upload_count = 0; this.settings.user_upload_complete_handler = this.settings.upload_complete_handler; this.settings.upload_complete_handler = SWFUpload.queue.uploadCompleteHandler; this.settings.queue_complete_handler = this.settings.queue_complete_handler || null; }; })(SWFUpload.prototype.initSettings); SWFUpload.prototype.startUpload = function (fileID) { this.customSettings.queue_cancelled_flag = false; this.callFlash("StartUpload", false, [fileID]); }; SWFUpload.prototype.cancelQueue = function () { this.customSettings.queue_cancelled_flag = true; this.stopUpload(); var stats = this.getStats(); while (stats.files_queued > 0) { this.cancelUpload(); stats = this.getStats(); } }; SWFUpload.queue.uploadCompleteHandler = function (file) { var user_upload_complete_handler = this.settings.user_upload_complete_handler; var continueUpload; if (file.filestatus === SWFUpload.FILE_STATUS.COMPLETE) { this.customSettings.queue_upload_count++; } if (typeof(user_upload_complete_handler) === "function") { continueUpload = (user_upload_complete_handler.call(this, file) === false) ? false : true; } else { continueUpload = true; } if (continueUpload) { var stats = this.getStats(); if (stats.files_queued > 0 && this.customSettings.queue_cancelled_flag === false) { this.startUpload(); } else if (this.customSettings.queue_cancelled_flag === false) { this.queueEvent("queue_complete_handler", [this.customSettings.queue_upload_count]); this.customSettings.queue_upload_count = 0; } else { this.customSettings.queue_cancelled_flag = false; this.customSettings.queue_upload_count = 0; } } }; }