]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-admin/js/image-edit.js
WordPress 4.2.4
[autoinstalls/wordpress.git] / wp-admin / js / image-edit.js
index 9eaf51bf88c91bc073eeccea52e4896a21664879..0abf6efc280d3e20326934913977c35d0695dd01 100644 (file)
@@ -5,6 +5,7 @@ var imageEdit = window.imageEdit = {
        iasapi : {},
        hold : {},
        postid : '',
+       _view : false,
 
        intval : function(f) {
                return f | 0;
@@ -62,7 +63,7 @@ var imageEdit = window.imageEdit = {
        },
 
        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;
        },
 
@@ -241,11 +242,18 @@ var imageEdit = window.imageEdit = {
                $.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;
@@ -266,7 +274,7 @@ var imageEdit = window.imageEdit = {
                        var ret = JSON.parse(r);
 
                        if ( ret.error ) {
-                               $('#imgedit-response-' + postid).html('<div class="error"><p>' + ret.error + '</p><div>');
+                               $('#imgedit-response-' + postid).html('<div class="error"><p>' + ret.error + '</p></div>');
                                imageEdit.close(postid);
                                return;
                        }
@@ -283,16 +291,22 @@ var imageEdit = window.imageEdit = {
                                $('#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) {
-               var data, elem = $('#image-editor-' + postid), head = $('#media-head-' + postid),
+       open : function( postid, nonce, view ) {
+               this._view = view;
+
+               var dfd, data, elem = $('#image-editor-' + postid), head = $('#media-head-' + postid),
                        btn = $('#imgedit-open-btn-' + postid), spin = btn.siblings('.spinner');
 
                btn.prop('disabled', true);
-               spin.show();
+               spin.addClass( 'is-active' );
 
                data = {
                        'action': 'image-editor',
@@ -301,13 +315,20 @@ var imageEdit = window.imageEdit = {
                        'do': 'open'
                };
 
-               elem.load(ajaxurl, data, function() {
-                       elem.fadeIn('fast');
+               dfd = $.ajax({
+                       url:  ajaxurl,
+                       type: 'post',
+                       data: data
+               }).done(function( html ) {
+                       elem.html( html );
                        head.fadeOut('fast', function(){
+                               elem.fadeIn('fast');
                                btn.removeAttr('disabled');
-                               spin.hide();
+                               spin.removeClass( 'is-active' );
                        });
                });
+
+               return dfd;
        },
 
        imgLoaded : function(postid) {
@@ -319,8 +340,10 @@ var imageEdit = window.imageEdit = {
        },
 
        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,
@@ -330,7 +353,13 @@ var imageEdit = window.imageEdit = {
                        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;
 
@@ -363,10 +392,9 @@ var imageEdit = window.imageEdit = {
        },
 
        setCropSelection : function(postid, c) {
-               var sel, min = $('#imgedit-minthumb-' + postid).val() || '128:128',
-                       sizer = this.hold.sizer;
-                       min = min.split(':');
-                       c = c || 0;
+               var sel;
+
+               c = c || 0;
 
                if ( !c || ( c.width < 3 && c.height < 3 ) ) {
                        this.setDisabled($('.imgedit-crop', '#imgedit-panel-' + postid), 0);
@@ -377,12 +405,6 @@ var imageEdit = window.imageEdit = {
                        return false;
                }
 
-               if ( c.width < (min[0] * sizer) && c.height < (min[1] * sizer) ) {
-                       this.setDisabled($('.imgedit-crop', '#imgedit-panel-' + postid), 0);
-                       $('#imgedit-selection-' + postid).val('');
-                       return false;
-               }
-
                sel = { 'x': c.x1, 'y': c.y1, 'w': c.width, 'h': c.height };
                this.setDisabled($('.imgedit-crop', '#imgedit-panel-' + postid), 1);
                $('#imgedit-selection-' + postid).val( JSON.stringify(sel) );
@@ -397,10 +419,22 @@ var imageEdit = window.imageEdit = {
 
                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) {