summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEvgeny Fadeev <evgeny.fadeev@gmail.com>2011-06-06 19:23:38 -0400
committerEvgeny Fadeev <evgeny.fadeev@gmail.com>2011-06-06 19:23:38 -0400
commitd128accf343a61896610cdd0ee6dc20d161151b5 (patch)
tree73f904ba015aa6c9c67d59a093bacbbedda0ce97
parent380a26deef0c29bbaa0ce7dc50d1badd59de9fb5 (diff)
downloadaskbot-d128accf343a61896610cdd0ee6dc20d161151b5.tar.gz
askbot-d128accf343a61896610cdd0ee6dc20d161151b5.tar.bz2
askbot-d128accf343a61896610cdd0ee6dc20d161151b5.zip
fixed errors in file upload javascript
-rw-r--r--askbot/skins/default/media/js/editor.js23
-rwxr-xr-xaskbot/skins/default/media/js/wmd/wmd.js15
-rwxr-xr-xaskbot/upfiles/13074025501351966.txt7
3 files changed, 38 insertions, 7 deletions
diff --git a/askbot/skins/default/media/js/editor.js b/askbot/skins/default/media/js/editor.js
index 1c936a80..f5b1e2af 100644
--- a/askbot/skins/default/media/js/editor.js
+++ b/askbot/skins/default/media/js/editor.js
@@ -14,8 +14,15 @@
/*
Ajax upload
*/jQuery.extend({createUploadIframe:function(d,b){var a="jUploadFrame"+d;if(window.ActiveXObject){var c=document.createElement('<iframe id="'+a+'" name="'+a+'" />');if(typeof b=="boolean"){c.src="javascript:false"}else{if(typeof b=="string"){c.src=b}}}else{var c=document.createElement("iframe");c.id=a;c.name=a}c.style.position="absolute";c.style.top="-1000px";c.style.left="-1000px";document.body.appendChild(c);return c},createUploadForm:function(g,b){var e="jUploadForm"+g;var a="jUploadFile"+g;var d=$('<form action="" method="POST" name="'+e+'" id="'+e+'" enctype="multipart/form-data"></form>');var c=$("#"+b);var f=$(c).clone();$(c).attr("id",a);$(c).before(f);$(c).appendTo(d);$(d).css("position","absolute");$(d).css("top","-1200px");$(d).css("left","-1200px");$(d).appendTo("body");return d},ajaxFileUpload:function(k){k=jQuery.extend({},jQuery.ajaxSettings,k);var a=new Date().getTime();var b=jQuery.createUploadForm(a,k.fileElementId);var i=jQuery.createUploadIframe(a,k.secureuri);var h="jUploadFrame"+a;var j="jUploadForm"+a;if(k.global&&!jQuery.active++){jQuery.event.trigger("ajaxStart")}var c=false;var f={};if(k.global){jQuery.event.trigger("ajaxSend",[f,k])}var d=function(l){var p=document.getElementById(h);try{if(p.contentWindow){f.responseText=p.contentWindow.document.body?p.contentWindow.document.body.innerText:null;f.responseXML=p.contentWindow.document.XMLDocument?p.contentWindow.document.XMLDocument:p.contentWindow.document}else{if(p.contentDocument){f.responseText=p.contentDocument.document.body?p.contentDocument.document.body.textContent||document.body.innerText:null;f.responseXML=p.contentDocument.document.XMLDocument?p.contentDocument.document.XMLDocument:p.contentDocument.document}}}catch(o){jQuery.handleError(k,f,null,o)}if(f||l=="timeout"){c=true;var m;try{m=l!="timeout"?"success":"error";if(m!="error"){var n=jQuery.uploadHttpData(f,k.dataType);if(k.success){k.success(n,m)}if(k.global){jQuery.event.trigger("ajaxSuccess",[f,k])}}else{jQuery.handleError(k,f,m)}}catch(o){m="error";jQuery.handleError(k,f,m,o)}if(k.global){jQuery.event.trigger("ajaxComplete",[f,k])}if(k.global&&!--jQuery.active){jQuery.event.trigger("ajaxStop")}if(k.complete){k.complete(f,m)}jQuery(p).unbind();setTimeout(function(){try{$(p).remove();$(b).remove()}catch(q){jQuery.handleError(k,f,null,q)}},100);f=null}};if(k.timeout>0){setTimeout(function(){if(!c){d("timeout")}},k.timeout)}try{var b=$("#"+j);$(b).attr("action",k.url);$(b).attr("method","POST");$(b).attr("target",h);if(b.encoding){b.encoding="multipart/form-data"}else{b.enctype="multipart/form-data"}$(b).submit()}catch(g){jQuery.handleError(k,f,null,g)}if(window.attachEvent){document.getElementById(h).attachEvent("onload",d)}else{document.getElementById(h).addEventListener("load",d,false)}return{abort:function(){}}},uploadHttpData:function(r,type){var data=!type;data=type=="xml"||data?r.responseXML:r.responseText;if(type=="script"){jQuery.globalEval(data)}if(type=="json"){eval("data = "+data)}if(type=="html"){jQuery("<div>").html(data).evalScripts()}return data}});
-/*Upload call*/
-function ajaxFileUpload(imageUrl)
+/**
+ * Upload call. Used only once in the wmd file upload
+ * this is "tightly coupled" with the wmd file uploader
+ * @param {Object} jquery object imageUrl - where the
+ * uploaded url must be inserted on successful upload
+ * @param {Function} handler that is run upon change
+ * of the file upload field
+ */
+function ajaxFileUpload(imageUrl, startUploadHandler)
{
$("#loading").ajaxStart(function(){
$(this).show();
@@ -41,7 +48,12 @@ function ajaxFileUpload(imageUrl)
var fileURL = $(data).find('file_url').text();
var error = $(data).find('error').text();
if(error != ''){
- alert(error);
+ alert(error);
+ if (startUploadHandler){
+ /* re-install this as the upload extension
+ * will remove the handler to prevent double uploading */
+ $('#file-upload').change(startUploadHandler);
+ }
}else{
imageUrl.attr('value', fileURL);
}
@@ -50,6 +62,11 @@ function ajaxFileUpload(imageUrl)
error: function (data, status, e)
{
alert(e);
+ if (startUploadHandler){
+ /* re-install this as the upload extension
+ * will remove the handler to prevent double uploading */
+ $('#file-upload').change(startUploadHandler);
+ }
}
}
)
diff --git a/askbot/skins/default/media/js/wmd/wmd.js b/askbot/skins/default/media/js/wmd/wmd.js
index 74fd4833..bc3b5a0c 100755
--- a/askbot/skins/default/media/js/wmd/wmd.js
+++ b/askbot/skins/default/media/js/wmd/wmd.js
@@ -354,11 +354,12 @@ util.prompt = function(text, defaultInputText, makeLinkMarkdown, dialogType){
upload_input.attr('id', 'file-upload');
upload_input.attr('size', 26);
- upload_input.change(function(){
+ var startUploadHandler = function(){
localUploadFileName = $(this).val();
- return ajaxFileUpload($('#image-url'));
- });
+ return ajaxFileUpload($('#image-url'), startUploadHandler);
+ };
+ upload_input.change(startUploadHandler);
upload_container.append(upload_input);
upload_container.append($('<br/>'));
@@ -376,7 +377,13 @@ util.prompt = function(text, defaultInputText, makeLinkMarkdown, dialogType){
// The ok button
var okButton = doc.createElement("input");
okButton.type = "button";
- okButton.onclick = function(){ return close(false); };
+ okButton.onclick = function(){
+ var isCancel = false;
+ if ($.trim($(input).val()) === ''){
+ isCancel = true;
+ }
+ return close(isCancel);
+ };
okButton.value = "OK";
style = okButton.style;
style.margin = "10px";
diff --git a/askbot/upfiles/13074025501351966.txt b/askbot/upfiles/13074025501351966.txt
new file mode 100755
index 00000000..3cd89541
--- /dev/null
+++ b/askbot/upfiles/13074025501351966.txt
@@ -0,0 +1,7 @@
+
+I would like to introduce myself - my name is Evgeny - I am a director of what is called BioMolecular Spectroscopy Facility.
+The facility includes:
+EPR instrument
+800 MHz NMR spectrometer
+kkk
+