[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/js/jquery/ui/ -> resizable.js (source)

   1  /*!
   2   * jQuery UI Resizable 1.13.3
   3   * https://jqueryui.com
   4   *
   5   * Copyright OpenJS Foundation and other contributors
   6   * Released under the MIT license.
   7   * https://jquery.org/license
   8   */
   9  
  10  //>>label: Resizable
  11  //>>group: Interactions
  12  //>>description: Enables resize functionality for any element.
  13  //>>docs: https://api.jqueryui.com/resizable/
  14  //>>demos: https://jqueryui.com/resizable/
  15  //>>css.structure: ../../themes/base/core.css
  16  //>>css.structure: ../../themes/base/resizable.css
  17  //>>css.theme: ../../themes/base/theme.css
  18  
  19  ( function( factory ) {
  20      "use strict";
  21  
  22      if ( typeof define === "function" && define.amd ) {
  23  
  24          // AMD. Register as an anonymous module.
  25          define( [
  26              "jquery",
  27              "./mouse",
  28              "../disable-selection",
  29              "../plugin",
  30              "../version",
  31              "../widget"
  32          ], factory );
  33      } else {
  34  
  35          // Browser globals
  36          factory( jQuery );
  37      }
  38  } )( function( $ ) {
  39  "use strict";
  40  
  41  $.widget( "ui.resizable", $.ui.mouse, {
  42      version: "1.13.3",
  43      widgetEventPrefix: "resize",
  44      options: {
  45          alsoResize: false,
  46          animate: false,
  47          animateDuration: "slow",
  48          animateEasing: "swing",
  49          aspectRatio: false,
  50          autoHide: false,
  51          classes: {
  52              "ui-resizable-se": "ui-icon ui-icon-gripsmall-diagonal-se"
  53          },
  54          containment: false,
  55          ghost: false,
  56          grid: false,
  57          handles: "e,s,se",
  58          helper: false,
  59          maxHeight: null,
  60          maxWidth: null,
  61          minHeight: 10,
  62          minWidth: 10,
  63  
  64          // See #7960
  65          zIndex: 90,
  66  
  67          // Callbacks
  68          resize: null,
  69          start: null,
  70          stop: null
  71      },
  72  
  73      _num: function( value ) {
  74          return parseFloat( value ) || 0;
  75      },
  76  
  77      _isNumber: function( value ) {
  78          return !isNaN( parseFloat( value ) );
  79      },
  80  
  81      _hasScroll: function( el, a ) {
  82  
  83          if ( $( el ).css( "overflow" ) === "hidden" ) {
  84              return false;
  85          }
  86  
  87          var scroll = ( a && a === "left" ) ? "scrollLeft" : "scrollTop",
  88              has = false;
  89  
  90          if ( el[ scroll ] > 0 ) {
  91              return true;
  92          }
  93  
  94          // TODO: determine which cases actually cause this to happen
  95          // if the element doesn't have the scroll set, see if it's possible to
  96          // set the scroll
  97          try {
  98              el[ scroll ] = 1;
  99              has = ( el[ scroll ] > 0 );
 100              el[ scroll ] = 0;
 101          } catch ( e ) {
 102  
 103              // `el` might be a string, then setting `scroll` will throw
 104              // an error in strict mode; ignore it.
 105          }
 106          return has;
 107      },
 108  
 109      _create: function() {
 110  
 111          var margins,
 112              o = this.options,
 113              that = this;
 114          this._addClass( "ui-resizable" );
 115  
 116          $.extend( this, {
 117              _aspectRatio: !!( o.aspectRatio ),
 118              aspectRatio: o.aspectRatio,
 119              originalElement: this.element,
 120              _proportionallyResizeElements: [],
 121              _helper: o.helper || o.ghost || o.animate ? o.helper || "ui-resizable-helper" : null
 122          } );
 123  
 124          // Wrap the element if it cannot hold child nodes
 125          if ( this.element[ 0 ].nodeName.match( /^(canvas|textarea|input|select|button|img)$/i ) ) {
 126  
 127              this.element.wrap(
 128                  $( "<div class='ui-wrapper'></div>" ).css( {
 129                      overflow: "hidden",
 130                      position: this.element.css( "position" ),
 131                      width: this.element.outerWidth(),
 132                      height: this.element.outerHeight(),
 133                      top: this.element.css( "top" ),
 134                      left: this.element.css( "left" )
 135                  } )
 136              );
 137  
 138              this.element = this.element.parent().data(
 139                  "ui-resizable", this.element.resizable( "instance" )
 140              );
 141  
 142              this.elementIsWrapper = true;
 143  
 144              margins = {
 145                  marginTop: this.originalElement.css( "marginTop" ),
 146                  marginRight: this.originalElement.css( "marginRight" ),
 147                  marginBottom: this.originalElement.css( "marginBottom" ),
 148                  marginLeft: this.originalElement.css( "marginLeft" )
 149              };
 150  
 151              this.element.css( margins );
 152              this.originalElement.css( "margin", 0 );
 153  
 154              // support: Safari
 155              // Prevent Safari textarea resize
 156              this.originalResizeStyle = this.originalElement.css( "resize" );
 157              this.originalElement.css( "resize", "none" );
 158  
 159              this._proportionallyResizeElements.push( this.originalElement.css( {
 160                  position: "static",
 161                  zoom: 1,
 162                  display: "block"
 163              } ) );
 164  
 165              // Support: IE9
 166              // avoid IE jump (hard set the margin)
 167              this.originalElement.css( margins );
 168  
 169              this._proportionallyResize();
 170          }
 171  
 172          this._setupHandles();
 173  
 174          if ( o.autoHide ) {
 175              $( this.element )
 176                  .on( "mouseenter", function() {
 177                      if ( o.disabled ) {
 178                          return;
 179                      }
 180                      that._removeClass( "ui-resizable-autohide" );
 181                      that._handles.show();
 182                  } )
 183                  .on( "mouseleave", function() {
 184                      if ( o.disabled ) {
 185                          return;
 186                      }
 187                      if ( !that.resizing ) {
 188                          that._addClass( "ui-resizable-autohide" );
 189                          that._handles.hide();
 190                      }
 191                  } );
 192          }
 193  
 194          this._mouseInit();
 195      },
 196  
 197      _destroy: function() {
 198  
 199          this._mouseDestroy();
 200          this._addedHandles.remove();
 201  
 202          var wrapper,
 203              _destroy = function( exp ) {
 204                  $( exp )
 205                      .removeData( "resizable" )
 206                      .removeData( "ui-resizable" )
 207                      .off( ".resizable" );
 208              };
 209  
 210          // TODO: Unwrap at same DOM position
 211          if ( this.elementIsWrapper ) {
 212              _destroy( this.element );
 213              wrapper = this.element;
 214              this.originalElement.css( {
 215                  position: wrapper.css( "position" ),
 216                  width: wrapper.outerWidth(),
 217                  height: wrapper.outerHeight(),
 218                  top: wrapper.css( "top" ),
 219                  left: wrapper.css( "left" )
 220              } ).insertAfter( wrapper );
 221              wrapper.remove();
 222          }
 223  
 224          this.originalElement.css( "resize", this.originalResizeStyle );
 225          _destroy( this.originalElement );
 226  
 227          return this;
 228      },
 229  
 230      _setOption: function( key, value ) {
 231          this._super( key, value );
 232  
 233          switch ( key ) {
 234          case "handles":
 235              this._removeHandles();
 236              this._setupHandles();
 237              break;
 238          case "aspectRatio":
 239              this._aspectRatio = !!value;
 240              break;
 241          default:
 242              break;
 243          }
 244      },
 245  
 246      _setupHandles: function() {
 247          var o = this.options, handle, i, n, hname, axis, that = this;
 248          this.handles = o.handles ||
 249              ( !$( ".ui-resizable-handle", this.element ).length ?
 250                  "e,s,se" : {
 251                      n: ".ui-resizable-n",
 252                      e: ".ui-resizable-e",
 253                      s: ".ui-resizable-s",
 254                      w: ".ui-resizable-w",
 255                      se: ".ui-resizable-se",
 256                      sw: ".ui-resizable-sw",
 257                      ne: ".ui-resizable-ne",
 258                      nw: ".ui-resizable-nw"
 259                  } );
 260  
 261          this._handles = $();
 262          this._addedHandles = $();
 263          if ( this.handles.constructor === String ) {
 264  
 265              if ( this.handles === "all" ) {
 266                  this.handles = "n,e,s,w,se,sw,ne,nw";
 267              }
 268  
 269              n = this.handles.split( "," );
 270              this.handles = {};
 271  
 272              for ( i = 0; i < n.length; i++ ) {
 273  
 274                  handle = String.prototype.trim.call( n[ i ] );
 275                  hname = "ui-resizable-" + handle;
 276                  axis = $( "<div>" );
 277                  this._addClass( axis, "ui-resizable-handle " + hname );
 278  
 279                  axis.css( { zIndex: o.zIndex } );
 280  
 281                  this.handles[ handle ] = ".ui-resizable-" + handle;
 282                  if ( !this.element.children( this.handles[ handle ] ).length ) {
 283                      this.element.append( axis );
 284                      this._addedHandles = this._addedHandles.add( axis );
 285                  }
 286              }
 287  
 288          }
 289  
 290          this._renderAxis = function( target ) {
 291  
 292              var i, axis, padPos, padWrapper;
 293  
 294              target = target || this.element;
 295  
 296              for ( i in this.handles ) {
 297  
 298                  if ( this.handles[ i ].constructor === String ) {
 299                      this.handles[ i ] = this.element.children( this.handles[ i ] ).first().show();
 300                  } else if ( this.handles[ i ].jquery || this.handles[ i ].nodeType ) {
 301                      this.handles[ i ] = $( this.handles[ i ] );
 302                      this._on( this.handles[ i ], { "mousedown": that._mouseDown } );
 303                  }
 304  
 305                  if ( this.elementIsWrapper &&
 306                          this.originalElement[ 0 ]
 307                              .nodeName
 308                              .match( /^(textarea|input|select|button)$/i ) ) {
 309                      axis = $( this.handles[ i ], this.element );
 310  
 311                      padWrapper = /sw|ne|nw|se|n|s/.test( i ) ?
 312                          axis.outerHeight() :
 313                          axis.outerWidth();
 314  
 315                      padPos = [ "padding",
 316                          /ne|nw|n/.test( i ) ? "Top" :
 317                          /se|sw|s/.test( i ) ? "Bottom" :
 318                          /^e$/.test( i ) ? "Right" : "Left" ].join( "" );
 319  
 320                      target.css( padPos, padWrapper );
 321  
 322                      this._proportionallyResize();
 323                  }
 324  
 325                  this._handles = this._handles.add( this.handles[ i ] );
 326              }
 327          };
 328  
 329          // TODO: make renderAxis a prototype function
 330          this._renderAxis( this.element );
 331  
 332          this._handles = this._handles.add( this.element.find( ".ui-resizable-handle" ) );
 333          this._handles.disableSelection();
 334  
 335          this._handles.on( "mouseover", function() {
 336              if ( !that.resizing ) {
 337                  if ( this.className ) {
 338                      axis = this.className.match( /ui-resizable-(se|sw|ne|nw|n|e|s|w)/i );
 339                  }
 340                  that.axis = axis && axis[ 1 ] ? axis[ 1 ] : "se";
 341              }
 342          } );
 343  
 344          if ( o.autoHide ) {
 345              this._handles.hide();
 346              this._addClass( "ui-resizable-autohide" );
 347          }
 348      },
 349  
 350      _removeHandles: function() {
 351          this._addedHandles.remove();
 352      },
 353  
 354      _mouseCapture: function( event ) {
 355          var i, handle,
 356              capture = false;
 357  
 358          for ( i in this.handles ) {
 359              handle = $( this.handles[ i ] )[ 0 ];
 360              if ( handle === event.target || $.contains( handle, event.target ) ) {
 361                  capture = true;
 362              }
 363          }
 364  
 365          return !this.options.disabled && capture;
 366      },
 367  
 368      _mouseStart: function( event ) {
 369  
 370          var curleft, curtop, cursor,
 371              o = this.options,
 372              el = this.element;
 373  
 374          this.resizing = true;
 375  
 376          this._renderProxy();
 377  
 378          curleft = this._num( this.helper.css( "left" ) );
 379          curtop = this._num( this.helper.css( "top" ) );
 380  
 381          if ( o.containment ) {
 382              curleft += $( o.containment ).scrollLeft() || 0;
 383              curtop += $( o.containment ).scrollTop() || 0;
 384          }
 385  
 386          this.offset = this.helper.offset();
 387          this.position = { left: curleft, top: curtop };
 388  
 389          this.size = this._helper ? {
 390                  width: this.helper.width(),
 391                  height: this.helper.height()
 392              } : {
 393                  width: el.width(),
 394                  height: el.height()
 395              };
 396  
 397          this.originalSize = this._helper ? {
 398                  width: el.outerWidth(),
 399                  height: el.outerHeight()
 400              } : {
 401                  width: el.width(),
 402                  height: el.height()
 403              };
 404  
 405          this.sizeDiff = {
 406              width: el.outerWidth() - el.width(),
 407              height: el.outerHeight() - el.height()
 408          };
 409  
 410          this.originalPosition = { left: curleft, top: curtop };
 411          this.originalMousePosition = { left: event.pageX, top: event.pageY };
 412  
 413          this.aspectRatio = ( typeof o.aspectRatio === "number" ) ?
 414              o.aspectRatio :
 415              ( ( this.originalSize.width / this.originalSize.height ) || 1 );
 416  
 417          cursor = $( ".ui-resizable-" + this.axis ).css( "cursor" );
 418          $( "body" ).css( "cursor", cursor === "auto" ? this.axis + "-resize" : cursor );
 419  
 420          this._addClass( "ui-resizable-resizing" );
 421          this._propagate( "start", event );
 422          return true;
 423      },
 424  
 425      _mouseDrag: function( event ) {
 426  
 427          var data, props,
 428              smp = this.originalMousePosition,
 429              a = this.axis,
 430              dx = ( event.pageX - smp.left ) || 0,
 431              dy = ( event.pageY - smp.top ) || 0,
 432              trigger = this._change[ a ];
 433  
 434          this._updatePrevProperties();
 435  
 436          if ( !trigger ) {
 437              return false;
 438          }
 439  
 440          data = trigger.apply( this, [ event, dx, dy ] );
 441  
 442          this._updateVirtualBoundaries( event.shiftKey );
 443          if ( this._aspectRatio || event.shiftKey ) {
 444              data = this._updateRatio( data, event );
 445          }
 446  
 447          data = this._respectSize( data, event );
 448  
 449          this._updateCache( data );
 450  
 451          this._propagate( "resize", event );
 452  
 453          props = this._applyChanges();
 454  
 455          if ( !this._helper && this._proportionallyResizeElements.length ) {
 456              this._proportionallyResize();
 457          }
 458  
 459          if ( !$.isEmptyObject( props ) ) {
 460              this._updatePrevProperties();
 461              this._trigger( "resize", event, this.ui() );
 462              this._applyChanges();
 463          }
 464  
 465          return false;
 466      },
 467  
 468      _mouseStop: function( event ) {
 469  
 470          this.resizing = false;
 471          var pr, ista, soffseth, soffsetw, s, left, top,
 472              o = this.options, that = this;
 473  
 474          if ( this._helper ) {
 475  
 476              pr = this._proportionallyResizeElements;
 477              ista = pr.length && ( /textarea/i ).test( pr[ 0 ].nodeName );
 478              soffseth = ista && this._hasScroll( pr[ 0 ], "left" ) ? 0 : that.sizeDiff.height;
 479              soffsetw = ista ? 0 : that.sizeDiff.width;
 480  
 481              s = {
 482                  width: ( that.helper.width()  - soffsetw ),
 483                  height: ( that.helper.height() - soffseth )
 484              };
 485              left = ( parseFloat( that.element.css( "left" ) ) +
 486                  ( that.position.left - that.originalPosition.left ) ) || null;
 487              top = ( parseFloat( that.element.css( "top" ) ) +
 488                  ( that.position.top - that.originalPosition.top ) ) || null;
 489  
 490              if ( !o.animate ) {
 491                  this.element.css( $.extend( s, { top: top, left: left } ) );
 492              }
 493  
 494              that.helper.height( that.size.height );
 495              that.helper.width( that.size.width );
 496  
 497              if ( this._helper && !o.animate ) {
 498                  this._proportionallyResize();
 499              }
 500          }
 501  
 502          $( "body" ).css( "cursor", "auto" );
 503  
 504          this._removeClass( "ui-resizable-resizing" );
 505  
 506          this._propagate( "stop", event );
 507  
 508          if ( this._helper ) {
 509              this.helper.remove();
 510          }
 511  
 512          return false;
 513  
 514      },
 515  
 516      _updatePrevProperties: function() {
 517          this.prevPosition = {
 518              top: this.position.top,
 519              left: this.position.left
 520          };
 521          this.prevSize = {
 522              width: this.size.width,
 523              height: this.size.height
 524          };
 525      },
 526  
 527      _applyChanges: function() {
 528          var props = {};
 529  
 530          if ( this.position.top !== this.prevPosition.top ) {
 531              props.top = this.position.top + "px";
 532          }
 533          if ( this.position.left !== this.prevPosition.left ) {
 534              props.left = this.position.left + "px";
 535          }
 536  
 537          this.helper.css( props );
 538  
 539          if ( this.size.width !== this.prevSize.width ) {
 540              props.width = this.size.width + "px";
 541              this.helper.width( props.width );
 542          }
 543          if ( this.size.height !== this.prevSize.height ) {
 544              props.height = this.size.height + "px";
 545              this.helper.height( props.height );
 546          }
 547  
 548          return props;
 549      },
 550  
 551      _updateVirtualBoundaries: function( forceAspectRatio ) {
 552          var pMinWidth, pMaxWidth, pMinHeight, pMaxHeight, b,
 553              o = this.options;
 554  
 555          b = {
 556              minWidth: this._isNumber( o.minWidth ) ? o.minWidth : 0,
 557              maxWidth: this._isNumber( o.maxWidth ) ? o.maxWidth : Infinity,
 558              minHeight: this._isNumber( o.minHeight ) ? o.minHeight : 0,
 559              maxHeight: this._isNumber( o.maxHeight ) ? o.maxHeight : Infinity
 560          };
 561  
 562          if ( this._aspectRatio || forceAspectRatio ) {
 563              pMinWidth = b.minHeight * this.aspectRatio;
 564              pMinHeight = b.minWidth / this.aspectRatio;
 565              pMaxWidth = b.maxHeight * this.aspectRatio;
 566              pMaxHeight = b.maxWidth / this.aspectRatio;
 567  
 568              if ( pMinWidth > b.minWidth ) {
 569                  b.minWidth = pMinWidth;
 570              }
 571              if ( pMinHeight > b.minHeight ) {
 572                  b.minHeight = pMinHeight;
 573              }
 574              if ( pMaxWidth < b.maxWidth ) {
 575                  b.maxWidth = pMaxWidth;
 576              }
 577              if ( pMaxHeight < b.maxHeight ) {
 578                  b.maxHeight = pMaxHeight;
 579              }
 580          }
 581          this._vBoundaries = b;
 582      },
 583  
 584      _updateCache: function( data ) {
 585          this.offset = this.helper.offset();
 586          if ( this._isNumber( data.left ) ) {
 587              this.position.left = data.left;
 588          }
 589          if ( this._isNumber( data.top ) ) {
 590              this.position.top = data.top;
 591          }
 592          if ( this._isNumber( data.height ) ) {
 593              this.size.height = data.height;
 594          }
 595          if ( this._isNumber( data.width ) ) {
 596              this.size.width = data.width;
 597          }
 598      },
 599  
 600      _updateRatio: function( data ) {
 601  
 602          var cpos = this.position,
 603              csize = this.size,
 604              a = this.axis;
 605  
 606          if ( this._isNumber( data.height ) ) {
 607              data.width = ( data.height * this.aspectRatio );
 608          } else if ( this._isNumber( data.width ) ) {
 609              data.height = ( data.width / this.aspectRatio );
 610          }
 611  
 612          if ( a === "sw" ) {
 613              data.left = cpos.left + ( csize.width - data.width );
 614              data.top = null;
 615          }
 616          if ( a === "nw" ) {
 617              data.top = cpos.top + ( csize.height - data.height );
 618              data.left = cpos.left + ( csize.width - data.width );
 619          }
 620  
 621          return data;
 622      },
 623  
 624      _respectSize: function( data ) {
 625  
 626          var o = this._vBoundaries,
 627              a = this.axis,
 628              ismaxw = this._isNumber( data.width ) && o.maxWidth && ( o.maxWidth < data.width ),
 629              ismaxh = this._isNumber( data.height ) && o.maxHeight && ( o.maxHeight < data.height ),
 630              isminw = this._isNumber( data.width ) && o.minWidth && ( o.minWidth > data.width ),
 631              isminh = this._isNumber( data.height ) && o.minHeight && ( o.minHeight > data.height ),
 632              dw = this.originalPosition.left + this.originalSize.width,
 633              dh = this.originalPosition.top + this.originalSize.height,
 634              cw = /sw|nw|w/.test( a ), ch = /nw|ne|n/.test( a );
 635          if ( isminw ) {
 636              data.width = o.minWidth;
 637          }
 638          if ( isminh ) {
 639              data.height = o.minHeight;
 640          }
 641          if ( ismaxw ) {
 642              data.width = o.maxWidth;
 643          }
 644          if ( ismaxh ) {
 645              data.height = o.maxHeight;
 646          }
 647  
 648          if ( isminw && cw ) {
 649              data.left = dw - o.minWidth;
 650          }
 651          if ( ismaxw && cw ) {
 652              data.left = dw - o.maxWidth;
 653          }
 654          if ( isminh && ch ) {
 655              data.top = dh - o.minHeight;
 656          }
 657          if ( ismaxh && ch ) {
 658              data.top = dh - o.maxHeight;
 659          }
 660  
 661          // Fixing jump error on top/left - bug #2330
 662          if ( !data.width && !data.height && !data.left && data.top ) {
 663              data.top = null;
 664          } else if ( !data.width && !data.height && !data.top && data.left ) {
 665              data.left = null;
 666          }
 667  
 668          return data;
 669      },
 670  
 671      _getPaddingPlusBorderDimensions: function( element ) {
 672          var i = 0,
 673              widths = [],
 674              borders = [
 675                  element.css( "borderTopWidth" ),
 676                  element.css( "borderRightWidth" ),
 677                  element.css( "borderBottomWidth" ),
 678                  element.css( "borderLeftWidth" )
 679              ],
 680              paddings = [
 681                  element.css( "paddingTop" ),
 682                  element.css( "paddingRight" ),
 683                  element.css( "paddingBottom" ),
 684                  element.css( "paddingLeft" )
 685              ];
 686  
 687          for ( ; i < 4; i++ ) {
 688              widths[ i ] = ( parseFloat( borders[ i ] ) || 0 );
 689              widths[ i ] += ( parseFloat( paddings[ i ] ) || 0 );
 690          }
 691  
 692          return {
 693              height: widths[ 0 ] + widths[ 2 ],
 694              width: widths[ 1 ] + widths[ 3 ]
 695          };
 696      },
 697  
 698      _proportionallyResize: function() {
 699  
 700          if ( !this._proportionallyResizeElements.length ) {
 701              return;
 702          }
 703  
 704          var prel,
 705              i = 0,
 706              element = this.helper || this.element;
 707  
 708          for ( ; i < this._proportionallyResizeElements.length; i++ ) {
 709  
 710              prel = this._proportionallyResizeElements[ i ];
 711  
 712              // TODO: Seems like a bug to cache this.outerDimensions
 713              // considering that we are in a loop.
 714              if ( !this.outerDimensions ) {
 715                  this.outerDimensions = this._getPaddingPlusBorderDimensions( prel );
 716              }
 717  
 718              prel.css( {
 719                  height: ( element.height() - this.outerDimensions.height ) || 0,
 720                  width: ( element.width() - this.outerDimensions.width ) || 0
 721              } );
 722  
 723          }
 724  
 725      },
 726  
 727      _renderProxy: function() {
 728  
 729          var el = this.element, o = this.options;
 730          this.elementOffset = el.offset();
 731  
 732          if ( this._helper ) {
 733  
 734              this.helper = this.helper || $( "<div></div>" ).css( { overflow: "hidden" } );
 735  
 736              this._addClass( this.helper, this._helper );
 737              this.helper.css( {
 738                  width: this.element.outerWidth(),
 739                  height: this.element.outerHeight(),
 740                  position: "absolute",
 741                  left: this.elementOffset.left + "px",
 742                  top: this.elementOffset.top + "px",
 743                  zIndex: ++o.zIndex //TODO: Don't modify option
 744              } );
 745  
 746              this.helper
 747                  .appendTo( "body" )
 748                  .disableSelection();
 749  
 750          } else {
 751              this.helper = this.element;
 752          }
 753  
 754      },
 755  
 756      _change: {
 757          e: function( event, dx ) {
 758              return { width: this.originalSize.width + dx };
 759          },
 760          w: function( event, dx ) {
 761              var cs = this.originalSize, sp = this.originalPosition;
 762              return { left: sp.left + dx, width: cs.width - dx };
 763          },
 764          n: function( event, dx, dy ) {
 765              var cs = this.originalSize, sp = this.originalPosition;
 766              return { top: sp.top + dy, height: cs.height - dy };
 767          },
 768          s: function( event, dx, dy ) {
 769              return { height: this.originalSize.height + dy };
 770          },
 771          se: function( event, dx, dy ) {
 772              return $.extend( this._change.s.apply( this, arguments ),
 773                  this._change.e.apply( this, [ event, dx, dy ] ) );
 774          },
 775          sw: function( event, dx, dy ) {
 776              return $.extend( this._change.s.apply( this, arguments ),
 777                  this._change.w.apply( this, [ event, dx, dy ] ) );
 778          },
 779          ne: function( event, dx, dy ) {
 780              return $.extend( this._change.n.apply( this, arguments ),
 781                  this._change.e.apply( this, [ event, dx, dy ] ) );
 782          },
 783          nw: function( event, dx, dy ) {
 784              return $.extend( this._change.n.apply( this, arguments ),
 785                  this._change.w.apply( this, [ event, dx, dy ] ) );
 786          }
 787      },
 788  
 789      _propagate: function( n, event ) {
 790          $.ui.plugin.call( this, n, [ event, this.ui() ] );
 791          if ( n !== "resize" ) {
 792              this._trigger( n, event, this.ui() );
 793          }
 794      },
 795  
 796      plugins: {},
 797  
 798      ui: function() {
 799          return {
 800              originalElement: this.originalElement,
 801              element: this.element,
 802              helper: this.helper,
 803              position: this.position,
 804              size: this.size,
 805              originalSize: this.originalSize,
 806              originalPosition: this.originalPosition
 807          };
 808      }
 809  
 810  } );
 811  
 812  /*
 813   * Resizable Extensions
 814   */
 815  
 816  $.ui.plugin.add( "resizable", "animate", {
 817  
 818      stop: function( event ) {
 819          var that = $( this ).resizable( "instance" ),
 820              o = that.options,
 821              pr = that._proportionallyResizeElements,
 822              ista = pr.length && ( /textarea/i ).test( pr[ 0 ].nodeName ),
 823              soffseth = ista && that._hasScroll( pr[ 0 ], "left" ) ? 0 : that.sizeDiff.height,
 824              soffsetw = ista ? 0 : that.sizeDiff.width,
 825              style = {
 826                  width: ( that.size.width - soffsetw ),
 827                  height: ( that.size.height - soffseth )
 828              },
 829              left = ( parseFloat( that.element.css( "left" ) ) +
 830                  ( that.position.left - that.originalPosition.left ) ) || null,
 831              top = ( parseFloat( that.element.css( "top" ) ) +
 832                  ( that.position.top - that.originalPosition.top ) ) || null;
 833  
 834          that.element.animate(
 835              $.extend( style, top && left ? { top: top, left: left } : {} ), {
 836                  duration: o.animateDuration,
 837                  easing: o.animateEasing,
 838                  step: function() {
 839  
 840                      var data = {
 841                          width: parseFloat( that.element.css( "width" ) ),
 842                          height: parseFloat( that.element.css( "height" ) ),
 843                          top: parseFloat( that.element.css( "top" ) ),
 844                          left: parseFloat( that.element.css( "left" ) )
 845                      };
 846  
 847                      if ( pr && pr.length ) {
 848                          $( pr[ 0 ] ).css( { width: data.width, height: data.height } );
 849                      }
 850  
 851                      // Propagating resize, and updating values for each animation step
 852                      that._updateCache( data );
 853                      that._propagate( "resize", event );
 854  
 855                  }
 856              }
 857          );
 858      }
 859  
 860  } );
 861  
 862  $.ui.plugin.add( "resizable", "containment", {
 863  
 864      start: function() {
 865          var element, p, co, ch, cw, width, height,
 866              that = $( this ).resizable( "instance" ),
 867              o = that.options,
 868              el = that.element,
 869              oc = o.containment,
 870              ce = ( oc instanceof $ ) ?
 871                  oc.get( 0 ) :
 872                  ( /parent/.test( oc ) ) ? el.parent().get( 0 ) : oc;
 873  
 874          if ( !ce ) {
 875              return;
 876          }
 877  
 878          that.containerElement = $( ce );
 879  
 880          if ( /document/.test( oc ) || oc === document ) {
 881              that.containerOffset = {
 882                  left: 0,
 883                  top: 0
 884              };
 885              that.containerPosition = {
 886                  left: 0,
 887                  top: 0
 888              };
 889  
 890              that.parentData = {
 891                  element: $( document ),
 892                  left: 0,
 893                  top: 0,
 894                  width: $( document ).width(),
 895                  height: $( document ).height() || document.body.parentNode.scrollHeight
 896              };
 897          } else {
 898              element = $( ce );
 899              p = [];
 900              $( [ "Top", "Right", "Left", "Bottom" ] ).each( function( i, name ) {
 901                  p[ i ] = that._num( element.css( "padding" + name ) );
 902              } );
 903  
 904              that.containerOffset = element.offset();
 905              that.containerPosition = element.position();
 906              that.containerSize = {
 907                  height: ( element.innerHeight() - p[ 3 ] ),
 908                  width: ( element.innerWidth() - p[ 1 ] )
 909              };
 910  
 911              co = that.containerOffset;
 912              ch = that.containerSize.height;
 913              cw = that.containerSize.width;
 914              width = ( that._hasScroll( ce, "left" ) ? ce.scrollWidth : cw );
 915              height = ( that._hasScroll( ce ) ? ce.scrollHeight : ch );
 916  
 917              that.parentData = {
 918                  element: ce,
 919                  left: co.left,
 920                  top: co.top,
 921                  width: width,
 922                  height: height
 923              };
 924          }
 925      },
 926  
 927      resize: function( event ) {
 928          var woset, hoset, isParent, isOffsetRelative,
 929              that = $( this ).resizable( "instance" ),
 930              o = that.options,
 931              co = that.containerOffset,
 932              cp = that.position,
 933              pRatio = that._aspectRatio || event.shiftKey,
 934              cop = {
 935                  top: 0,
 936                  left: 0
 937              },
 938              ce = that.containerElement,
 939              continueResize = true;
 940  
 941          if ( ce[ 0 ] !== document && ( /static/ ).test( ce.css( "position" ) ) ) {
 942              cop = co;
 943          }
 944  
 945          if ( cp.left < ( that._helper ? co.left : 0 ) ) {
 946              that.size.width = that.size.width +
 947                  ( that._helper ?
 948                      ( that.position.left - co.left ) :
 949                      ( that.position.left - cop.left ) );
 950  
 951              if ( pRatio ) {
 952                  that.size.height = that.size.width / that.aspectRatio;
 953                  continueResize = false;
 954              }
 955              that.position.left = o.helper ? co.left : 0;
 956          }
 957  
 958          if ( cp.top < ( that._helper ? co.top : 0 ) ) {
 959              that.size.height = that.size.height +
 960                  ( that._helper ?
 961                      ( that.position.top - co.top ) :
 962                      that.position.top );
 963  
 964              if ( pRatio ) {
 965                  that.size.width = that.size.height * that.aspectRatio;
 966                  continueResize = false;
 967              }
 968              that.position.top = that._helper ? co.top : 0;
 969          }
 970  
 971          isParent = that.containerElement.get( 0 ) === that.element.parent().get( 0 );
 972          isOffsetRelative = /relative|absolute/.test( that.containerElement.css( "position" ) );
 973  
 974          if ( isParent && isOffsetRelative ) {
 975              that.offset.left = that.parentData.left + that.position.left;
 976              that.offset.top = that.parentData.top + that.position.top;
 977          } else {
 978              that.offset.left = that.element.offset().left;
 979              that.offset.top = that.element.offset().top;
 980          }
 981  
 982          woset = Math.abs( that.sizeDiff.width +
 983              ( that._helper ?
 984                  that.offset.left - cop.left :
 985                  ( that.offset.left - co.left ) ) );
 986  
 987          hoset = Math.abs( that.sizeDiff.height +
 988              ( that._helper ?
 989                  that.offset.top - cop.top :
 990                  ( that.offset.top - co.top ) ) );
 991  
 992          if ( woset + that.size.width >= that.parentData.width ) {
 993              that.size.width = that.parentData.width - woset;
 994              if ( pRatio ) {
 995                  that.size.height = that.size.width / that.aspectRatio;
 996                  continueResize = false;
 997              }
 998          }
 999  
1000          if ( hoset + that.size.height >= that.parentData.height ) {
1001              that.size.height = that.parentData.height - hoset;
1002              if ( pRatio ) {
1003                  that.size.width = that.size.height * that.aspectRatio;
1004                  continueResize = false;
1005              }
1006          }
1007  
1008          if ( !continueResize ) {
1009              that.position.left = that.prevPosition.left;
1010              that.position.top = that.prevPosition.top;
1011              that.size.width = that.prevSize.width;
1012              that.size.height = that.prevSize.height;
1013          }
1014      },
1015  
1016      stop: function() {
1017          var that = $( this ).resizable( "instance" ),
1018              o = that.options,
1019              co = that.containerOffset,
1020              cop = that.containerPosition,
1021              ce = that.containerElement,
1022              helper = $( that.helper ),
1023              ho = helper.offset(),
1024              w = helper.outerWidth() - that.sizeDiff.width,
1025              h = helper.outerHeight() - that.sizeDiff.height;
1026  
1027          if ( that._helper && !o.animate && ( /relative/ ).test( ce.css( "position" ) ) ) {
1028              $( this ).css( {
1029                  left: ho.left - cop.left - co.left,
1030                  width: w,
1031                  height: h
1032              } );
1033          }
1034  
1035          if ( that._helper && !o.animate && ( /static/ ).test( ce.css( "position" ) ) ) {
1036              $( this ).css( {
1037                  left: ho.left - cop.left - co.left,
1038                  width: w,
1039                  height: h
1040              } );
1041          }
1042      }
1043  } );
1044  
1045  $.ui.plugin.add( "resizable", "alsoResize", {
1046  
1047      start: function() {
1048          var that = $( this ).resizable( "instance" ),
1049              o = that.options;
1050  
1051          $( o.alsoResize ).each( function() {
1052              var el = $( this );
1053              el.data( "ui-resizable-alsoresize", {
1054                  width: parseFloat( el.css( "width" ) ), height: parseFloat( el.css( "height" ) ),
1055                  left: parseFloat( el.css( "left" ) ), top: parseFloat( el.css( "top" ) )
1056              } );
1057          } );
1058      },
1059  
1060      resize: function( event, ui ) {
1061          var that = $( this ).resizable( "instance" ),
1062              o = that.options,
1063              os = that.originalSize,
1064              op = that.originalPosition,
1065              delta = {
1066                  height: ( that.size.height - os.height ) || 0,
1067                  width: ( that.size.width - os.width ) || 0,
1068                  top: ( that.position.top - op.top ) || 0,
1069                  left: ( that.position.left - op.left ) || 0
1070              };
1071  
1072              $( o.alsoResize ).each( function() {
1073                  var el = $( this ), start = $( this ).data( "ui-resizable-alsoresize" ), style = {},
1074                      css = el.parents( ui.originalElement[ 0 ] ).length ?
1075                              [ "width", "height" ] :
1076                              [ "width", "height", "top", "left" ];
1077  
1078                  $.each( css, function( i, prop ) {
1079                      var sum = ( start[ prop ] || 0 ) + ( delta[ prop ] || 0 );
1080                      if ( sum && sum >= 0 ) {
1081                          style[ prop ] = sum || null;
1082                      }
1083                  } );
1084  
1085                  el.css( style );
1086              } );
1087      },
1088  
1089      stop: function() {
1090          $( this ).removeData( "ui-resizable-alsoresize" );
1091      }
1092  } );
1093  
1094  $.ui.plugin.add( "resizable", "ghost", {
1095  
1096      start: function() {
1097  
1098          var that = $( this ).resizable( "instance" ), cs = that.size;
1099  
1100          that.ghost = that.originalElement.clone();
1101          that.ghost.css( {
1102              opacity: 0.25,
1103              display: "block",
1104              position: "relative",
1105              height: cs.height,
1106              width: cs.width,
1107              margin: 0,
1108              left: 0,
1109              top: 0
1110          } );
1111  
1112          that._addClass( that.ghost, "ui-resizable-ghost" );
1113  
1114          // DEPRECATED
1115          // TODO: remove after 1.12
1116          if ( $.uiBackCompat !== false && typeof that.options.ghost === "string" ) {
1117  
1118              // Ghost option
1119              that.ghost.addClass( this.options.ghost );
1120          }
1121  
1122          that.ghost.appendTo( that.helper );
1123  
1124      },
1125  
1126      resize: function() {
1127          var that = $( this ).resizable( "instance" );
1128          if ( that.ghost ) {
1129              that.ghost.css( {
1130                  position: "relative",
1131                  height: that.size.height,
1132                  width: that.size.width
1133              } );
1134          }
1135      },
1136  
1137      stop: function() {
1138          var that = $( this ).resizable( "instance" );
1139          if ( that.ghost && that.helper ) {
1140              that.helper.get( 0 ).removeChild( that.ghost.get( 0 ) );
1141          }
1142      }
1143  
1144  } );
1145  
1146  $.ui.plugin.add( "resizable", "grid", {
1147  
1148      resize: function() {
1149          var outerDimensions,
1150              that = $( this ).resizable( "instance" ),
1151              o = that.options,
1152              cs = that.size,
1153              os = that.originalSize,
1154              op = that.originalPosition,
1155              a = that.axis,
1156              grid = typeof o.grid === "number" ? [ o.grid, o.grid ] : o.grid,
1157              gridX = ( grid[ 0 ] || 1 ),
1158              gridY = ( grid[ 1 ] || 1 ),
1159              ox = Math.round( ( cs.width - os.width ) / gridX ) * gridX,
1160              oy = Math.round( ( cs.height - os.height ) / gridY ) * gridY,
1161              newWidth = os.width + ox,
1162              newHeight = os.height + oy,
1163              isMaxWidth = o.maxWidth && ( o.maxWidth < newWidth ),
1164              isMaxHeight = o.maxHeight && ( o.maxHeight < newHeight ),
1165              isMinWidth = o.minWidth && ( o.minWidth > newWidth ),
1166              isMinHeight = o.minHeight && ( o.minHeight > newHeight );
1167  
1168          o.grid = grid;
1169  
1170          if ( isMinWidth ) {
1171              newWidth += gridX;
1172          }
1173          if ( isMinHeight ) {
1174              newHeight += gridY;
1175          }
1176          if ( isMaxWidth ) {
1177              newWidth -= gridX;
1178          }
1179          if ( isMaxHeight ) {
1180              newHeight -= gridY;
1181          }
1182  
1183          if ( /^(se|s|e)$/.test( a ) ) {
1184              that.size.width = newWidth;
1185              that.size.height = newHeight;
1186          } else if ( /^(ne)$/.test( a ) ) {
1187              that.size.width = newWidth;
1188              that.size.height = newHeight;
1189              that.position.top = op.top - oy;
1190          } else if ( /^(sw)$/.test( a ) ) {
1191              that.size.width = newWidth;
1192              that.size.height = newHeight;
1193              that.position.left = op.left - ox;
1194          } else {
1195              if ( newHeight - gridY <= 0 || newWidth - gridX <= 0 ) {
1196                  outerDimensions = that._getPaddingPlusBorderDimensions( this );
1197              }
1198  
1199              if ( newHeight - gridY > 0 ) {
1200                  that.size.height = newHeight;
1201                  that.position.top = op.top - oy;
1202              } else {
1203                  newHeight = gridY - outerDimensions.height;
1204                  that.size.height = newHeight;
1205                  that.position.top = op.top + os.height - newHeight;
1206              }
1207              if ( newWidth - gridX > 0 ) {
1208                  that.size.width = newWidth;
1209                  that.position.left = op.left - ox;
1210              } else {
1211                  newWidth = gridX - outerDimensions.width;
1212                  that.size.width = newWidth;
1213                  that.position.left = op.left + os.width - newWidth;
1214              }
1215          }
1216      }
1217  
1218  } );
1219  
1220  return $.ui.resizable;
1221  
1222  } );


Generated : Sat Nov 23 08:20:01 2024 Cross-referenced by PHPXref