application/js/field/file.js in spontaneous-0.2.0.beta7 vs application/js/field/file.js in spontaneous-0.2.0.beta8

- old
+ new

@@ -2,10 +2,14 @@ Spontaneous.Field.File = (function($, S) { var dom = S.Dom; var FileField = new JS.Class(Spontaneous.Field.String, { selected_files: false, + initialize: function(dialogue, conflict) { + this.blobs = []; + this.callSuper(); + }, currentValue: function() { var pending, v = this.get('value'); if ((pending = v.__pending__)) { return pending.value; } @@ -109,15 +113,21 @@ upload_conflict: function(conflict_data) { var dialogue = new S.ConflictedFieldDialogue(this, conflict_data); dialogue.open(); }, unload: function() { - this.callSuper(); this.input = null; this._progress_bar = null; + this.freeBlobs(); Spontaneous.UploadManager.unregister(this); + this.callSuper(); }, + freeBlobs: function() { + this.blobs.forEach(function(url) { + window.URL.revokeObjectURL(url); + }); + }, upload_complete: function(values) { this.set('value', values.processed_value); this.set_version(values.version); this.selected_files = null; this.disable_progress(); @@ -144,10 +154,16 @@ }, is_file: function() { return true; }, + createObjectURL: function(file) { + var url = window.URL.createObjectURL(file); + this.blobs.push(url); + return url; + }, + edit: function() { var self = this; var wrap = dom.div('.file-field', {'style':'position:relative;'}); var value = this.value(); var input = this.input(); @@ -162,13 +178,12 @@ } }; var files_selected = function(files) { if (files.length > 0) { - var file = files[0], url = window.URL.createObjectURL(file); + var file = files[0], url = this.createObjectURL(file); this.selected_files = files; this._edited_value = url; - window.URL.revokeObjectURL(url); set_info(File.filename(file), file.fileSize); } }.bind(this); var onchange = function() {