summaryrefslogtreecommitdiff
path: root/themes/okadmin/public/js/upload.js
diff options
context:
space:
mode:
Diffstat (limited to 'themes/okadmin/public/js/upload.js')
-rw-r--r--themes/okadmin/public/js/upload.js91
1 files changed, 42 insertions, 49 deletions
diff --git a/themes/okadmin/public/js/upload.js b/themes/okadmin/public/js/upload.js
index 1c9094c..39f7427 100644
--- a/themes/okadmin/public/js/upload.js
+++ b/themes/okadmin/public/js/upload.js
@@ -1,55 +1,48 @@
-var OKUpload = {
- action: "/_services/image",
-
- bind: function(el){
- if (! el) return
- el.addEventListener("change", OKUpload.handleFileSelect)
- },
-
- handleFileSelect: function(e) {
- e.stopPropagation();
- e.preventDefault();
-
- var files = e.dataTransfer ? e.dataTransfer.files : e.target.files;
-
- for (var i = 0, f; f = files[i]; i++) {
- if ( ! f.type.match('image.*')) {
- continue;
- }
- OKUpload.upload(f)
- }
- },
+var OKUpload = function(){
+ this.action = "/_services/image"
+}
+OKUpload.prototype.bind = function(el){
+ if (el.length) el = el[0]
+ el.addEventListener("change", this.handleFileSelect.bind(this))
+}
+OKUpload.prototype.handleFileSelect = function(e) {
+ e.stopPropagation();
+ e.preventDefault();
- upload: function(f){
- var fd = new FormData()
- fd.append('image', f)
+ var files = e.dataTransfer ? e.dataTransfer.files : e.target.files;
- var request = $.ajax({
- url: OKUpload.action,
- type: "post",
- data: fd,
- dataType: "json",
- processData: false,
- contentType: false,
- })
- request.done(OKUpload.success)
- },
-
- success: function(media){
- if (media.error) {
- console.log(media.error)
- return
+ for (var i = 0, f; f = files[i]; i++) {
+ if ( ! f.type.match('image.*')) {
+ continue;
}
- OKUpload.add(media)
- },
-
- add: function(media){
- console.log(media)
- },
-
- error: function(error){
- throw error
- },
+ this.upload(f)
+ }
+}
+OKUpload.prototype.upload = function(f){
+ var fd = new FormData()
+ fd.append('image', f)
+ var request = $.ajax({
+ url: this.action,
+ type: "post",
+ data: fd,
+ dataType: "json",
+ processData: false,
+ contentType: false,
+ })
+ request.done(this.success.bind(this))
+}
+OKUpload.prototype.success = function(media){
+ if (media.error) {
+ console.log(media.error)
+ return
+ }
+ this.add(media)
+}
+OKUpload.prototype.add = function(media){
+ console.log(media)
+}
+OKUpload.prototype.error = function(error){
+ throw error
}