application/js/field/image.js in spontaneous-0.2.0.beta1 vs application/js/field/image.js in spontaneous-0.2.0.beta2
- old
+ new
@@ -1,7 +1,8 @@
// console.log('Loading ImageField...')
Spontaneous.Field.Image = (function($, S) {
+ "use strict";
var dom = S.Dom;
var ImageFieldConflictView = new JS.Class(S.Field.String.ConflictView, {
panel: function() {
var labels = dom.div('.image-field-conflict.labels.differences'),
@@ -56,17 +57,35 @@
this.waiting.find(':visible').hide();
this.callSuper();
},
currentValue: function() {
- var v = this.get('value');
+ var pending, v = this.get('value');
if ((pending = v['__pending__'])) {
+ pending['path'] = pending['src'];
return pending['value'];
}
return v['__ui__'] || v['original'];
},
+ currentEditValue: function() {
+ var value, pending, ui, v = this.get('value');
+ if ((pending = v['__pending__'])) {
+ return pending['value'];
+ }
+ value = v['original'];
+ if ((ui = v['__ui__'])) {
+ value['path'] = value['src'];
+ value['src'] = ui['src'];
+ }
+ return value;
+ },
+
+ currentFilename: function() {
+ var v = this.currentValue();
+ return v['filename'];
+ },
/*
* HACK: The async nature of image updates means that the version setting
* may be out of date not because of the actions of another, but because
* the field version has been updated in the background.
* The right way to do this would be to use an event to update the field
@@ -78,11 +97,11 @@
*
* Instead hackily use the pending version and hope it's not going to cause
* weird problems with simultaneous updates.
*/
version: function() {
- var value = this.get("value");
+ var pending, value = this.get("value");
if ((pending = value["__pending__"])) {
return pending["version"];
}
return this.data.version;
},
@@ -243,11 +262,11 @@
}
return 0;
},
edit: function() {
var wrap = dom.div({'style':'position:relative;'}),
- value = this.currentValue(),
+ value = this.currentEditValue(),
src = value.src,
img = dom.img({'src':src}),
info, sizes, filename_info, filesize_info, dimensions_info;
if (value.width >= value.height) {
@@ -348,12 +367,12 @@
dropper.bind('dragenter', drag_enter).bind('dragover', drag_over).bind('dragleave', drag_leave);
wrap.append(img, actions, info);
if (value) {
- var s = value.src.split('/'), filename = s[s.length - 1];
- set_info(filename, value.filesize, value.width, value.height);
+ // var s = value.path.split('/'), filename = s[s.length - 1];
+ set_info(this.currentFilename(), value.filesize, value.width, value.height);
}
this.preview_img = img;
return wrap;
},
@@ -367,13 +386,9 @@
},
get_input: function() {
this.input = this.generate_input();
return this.input;
- },
-
- edited_value: function() {
- return this.input.val();
},
cancel_edit: function() {
this.image.attr('src', this.currentValue().src);
},
conflict_view: function(dialogue, conflict) {