summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2011-12-17 12:26:31 +0100
committerFlorian Pritz <bluewind@xinu.at>2011-12-17 12:26:31 +0100
commit94aef7b4e9283f5c955cd2c4d5f71937be87b048 (patch)
treedd66b0464cb0adfe3a77ca9362f8e04d217b96bb
parente4ee81d800a08a5839dcfeeb3441f2f0b4247a6f (diff)
move JS of upload_form to separate file
The code hardly changes so it should be cached by the browser. This won't work if it's inlined. Signed-off-by: Florian Pritz <bluewind@xinu.at>
-rw-r--r--application/views/file/upload_form.php66
-rw-r--r--data/.htaccess1
-rw-r--r--data/js/upload_form.js65
3 files changed, 67 insertions, 65 deletions
diff --git a/application/views/file/upload_form.php b/application/views/file/upload_form.php
index 8687490de..7ca0e2a13 100644
--- a/application/views/file/upload_form.php
+++ b/application/views/file/upload_form.php
@@ -6,73 +6,9 @@
Optional password (for deletion and search): <input type="password" name="password" size="10" />
</p>
</form>
+ <script type="text/javascript" src="<?php echo base_url(); ?>data/js/upload_form.js?<?php echo filemtime(FCPATH."/data/js/upload_form.js"); ?>"></script>
<script type="text/javascript">
/* <![CDATA[ */
- // check file size before uploading if browser support html5
- if (window.File && window.FileList) {
- function checkFileUpload(evt) {
- var f = evt.target.files[0]; // FileList object
- if (f.size > <?php echo $max_upload_size; ?>) {
- document.getElementById('upload_button').value = "File too big";
- document.getElementById('upload_button').disabled = true;
- } else {
- document.getElementById('upload_button').value = "Upload";
- document.getElementById('upload_button').disabled = false;
- }
- }
-
- document.getElementById('file').addEventListener('change', checkFileUpload, false);
- }
-
-function encode64(inp){
- var key="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
- var chr1,chr2,chr3,enc3,enc4,i=0,out="";
- while(i<inp.length){
- chr1=inp.charCodeAt(i++);if(chr1>127) chr1=88;
- chr2=inp.charCodeAt(i++);if(chr2>127) chr2=88;
- chr3=inp.charCodeAt(i++);if(chr3>127) chr3=88;
- if(isNaN(chr3)) {enc4=64;chr3=0;} else enc4=chr3&63
- if(isNaN(chr2)) {enc3=64;chr2=0;} else enc3=((chr2<<2)|(chr3>>6))&63
- out+=key.charAt((chr1>>2)&63)+key.charAt(((chr1<<4)|(chr2>>4))&63)+key.charAt(enc3)+key.charAt(enc4);
- }
- return encodeURIComponent(out);
-}
-
-function gen_boundary() {
- var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
- var string_length = 40;
- var randomstring = '';
- for (var i=0; i<string_length; i++) {
- var rnum = Math.floor(Math.random() * chars.length);
- randomstring += chars.substring(rnum,rnum+1);
- }
- return randomstring;
-}
-function do_paste() {
- var http = new XMLHttpRequest();
- var url = "<?php echo site_url("file/do_upload/dumb"); ?>";
- var CRLF = "\r\n";
- var boundary = "--" + gen_boundary();
- var body = "--" + boundary + CRLF
- + 'Content-Disposition: form-data; name="file"; filename="stdin"' + CRLF
- + "Content-Type: text/plain" + CRLF
- + CRLF
- + document.getElementById("textarea").value + CRLF
- + "--" + boundary + "--" + CRLF + CRLF;
- http.open("POST", url, true);
-
- //Send the proper header information along with the request
- http.setRequestHeader("Content-type", "multipart/form-data; boundary=" + boundary);
- http.setRequestHeader("Authorization", "Basic " + encode64(":" + document.getElementById("textarea_password").value));
-
- http.onreadystatechange = function() {//Call a function when the state changes.
- if(http.readyState == 4 && http.status == 200) {
- window.location = http.responseText;
- }
- }
- http.send(body);
-}
-
document.write('\
<p><b>OR</b></p>\
<form action="javascript: do_paste()">\
diff --git a/data/.htaccess b/data/.htaccess
index 13d25207f..c8dfb58fd 100644
--- a/data/.htaccess
+++ b/data/.htaccess
@@ -1,6 +1,7 @@
<IfModule mod_expires.c>
ExpiresActive on
ExpiresByType text/css "access plus 1 year"
+ ExpiresByType application/javascript "access plus 1 year"
</IfModule>
Header append Cache-Control "public"
diff --git a/data/js/upload_form.js b/data/js/upload_form.js
new file mode 100644
index 000000000..0dcb53708
--- /dev/null
+++ b/data/js/upload_form.js
@@ -0,0 +1,65 @@
+// check file size before uploading if browser support html5
+if (window.File && window.FileList) {
+ function checkFileUpload(evt) {
+ var f = evt.target.files[0];
+ if (f.size > <?php echo $max_upload_size; ?>) {
+ document.getElementById('upload_button').value = "File too big";
+ document.getElementById('upload_button').disabled = true;
+ } else {
+ document.getElementById('upload_button').value = "Upload";
+ document.getElementById('upload_button').disabled = false;
+ }
+ }
+
+ document.getElementById('file').addEventListener('change', checkFileUpload, false);
+}
+
+function encode64(inp){
+ var key="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
+ var chr1,chr2,chr3,enc3,enc4,i=0,out="";
+ while(i<inp.length){
+ chr1=inp.charCodeAt(i++);if(chr1>127) chr1=88;
+ chr2=inp.charCodeAt(i++);if(chr2>127) chr2=88;
+ chr3=inp.charCodeAt(i++);if(chr3>127) chr3=88;
+ if(isNaN(chr3)) {enc4=64;chr3=0;} else enc4=chr3&63
+ if(isNaN(chr2)) {enc3=64;chr2=0;} else enc3=((chr2<<2)|(chr3>>6))&63
+ out+=key.charAt((chr1>>2)&63)+key.charAt(((chr1<<4)|(chr2>>4))&63)+key.charAt(enc3)+key.charAt(enc4);
+ }
+ return encodeURIComponent(out);
+}
+
+function gen_boundary() {
+ var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
+ var string_length = 40;
+ var randomstring = '';
+ for (var i=0; i<string_length; i++) {
+ var rnum = Math.floor(Math.random() * chars.length);
+ randomstring += chars.substring(rnum,rnum+1);
+ }
+ return randomstring;
+}
+function do_paste() {
+ var http = new XMLHttpRequest();
+ var url = "<?php echo site_url("file/do_upload/dumb"); ?>";
+ var CRLF = "\r\n";
+ var boundary = "--" + gen_boundary();
+ var body = "--" + boundary + CRLF
+ + 'Content-Disposition: form-data; name="file"; filename="stdin"' + CRLF
+ + "Content-Type: text/plain" + CRLF
+ + CRLF
+ + document.getElementById("textarea").value + CRLF
+ + "--" + boundary + "--" + CRLF + CRLF;
+ http.open("POST", url, true);
+
+ //Send the proper header information along with the request
+ http.setRequestHeader("Content-type", "multipart/form-data; boundary=" + boundary);
+ http.setRequestHeader("Authorization", "Basic " + encode64(":" + document.getElementById("textarea_password").value));
+
+ http.onreadystatechange = function() {
+ if(http.readyState == 4 && http.status == 200) {
+ window.location = http.responseText;
+ }
+ }
+ http.send(body);
+}
+