iasapi : {},
hold : {},
postid : '',
+ _view : false,
intval : function(f) {
return f | 0;
},
toggleHelp : function(el) {
- $(el).siblings('.imgedit-help').slideToggle('fast');
+ $( el ).parents( '.imgedit-group-top' ).toggleClass( 'imgedit-help-toggled' ).find( '.imgedit-help' ).slideToggle( 'fast' );
return false;
},
$.post(ajaxurl, data, function(r) {
$('#image-editor-' + postid).empty().append(r);
t.toggleEditor(postid, 0);
+ // refresh the attachment model so that changes propagate
+ if ( t._view ) {
+ t._view.refresh();
+ }
});
},
save : function(postid, nonce) {
- var data, target = this.getTarget(postid), history = this.filterHistory(postid, 0);
+ var data,
+ target = this.getTarget(postid),
+ history = this.filterHistory(postid, 0),
+ self = this;
if ( '' === history ) {
return false;
$('#imgedit-response-' + postid).html('<div class="updated"><p>' + ret.msg + '</p></div>');
}
- imageEdit.close(postid);
+ if ( self._view ) {
+ self._view.save();
+ } else {
+ imageEdit.close(postid);
+ }
});
},
- open : function(postid, nonce) {
+ open : function( postid, nonce, view ) {
+ this._view = view;
+
var data, elem = $('#image-editor-' + postid), head = $('#media-head-' + postid),
btn = $('#imgedit-open-btn-' + postid), spin = btn.siblings('.spinner');
},
initCrop : function(postid, image, parent) {
- var t = this, selW = $('#imgedit-sel-width-' + postid),
- selH = $('#imgedit-sel-height-' + postid);
+ var t = this,
+ selW = $('#imgedit-sel-width-' + postid),
+ selH = $('#imgedit-sel-height-' + postid),
+ $img;
t.iasapi = $(image).imgAreaSelect({
parent: parent,
minWidth: 3,
minHeight: 3,
- onInit: function() {
+ onInit: function( img ) {
+ // Ensure that the imgareaselect wrapper elements are position:absolute
+ // (even if we're in a position:fixed modal)
+ $img = $( img );
+ $img.next().css( 'position', 'absolute' )
+ .nextAll( '.imgareaselect-outer' ).css( 'position', 'absolute' );
+
parent.children().mousedown(function(e){
var ratio = false, sel, defRatio;
this.iasapi = {};
this.hold = {};
- $('#image-editor-' + postid).fadeOut('fast', function() {
- $('#media-head-' + postid).fadeIn('fast');
- $(this).empty();
- });
+
+ // If we've loaded the editor in the context of a Media Modal, then switch to the previous view,
+ // whatever that might have been.
+ if ( this._view ){
+ this._view.back();
+ }
+
+ // In case we are not accessing the image editor in the context of a View, close the editor the old-skool way
+ else {
+ $('#image-editor-' + postid).fadeOut('fast', function() {
+ $('#media-head-' + postid).fadeIn('fast');
+ $(this).empty();
+ });
+ }
+
+
},
notsaved : function(postid) {