/CS198/WebContent/js/jqueryui/jquery.ui.resizable.js
JavaScript | 807 lines | 568 code | 187 blank | 52 comment | 178 complexity | 0fb23d36efb928757d7d5c57d7098e0e MD5 | raw file
- /*!
- * jQuery UI Resizable 1.8.23
- *
- * Copyright 2012, AUTHORS.txt (http://jqueryui.com/about)
- * Dual licensed under the MIT or GPL Version 2 licenses.
- * http://jquery.org/license
- *
- * http://docs.jquery.com/UI/Resizables
- *
- * Depends:
- * jquery.ui.core.js
- * jquery.ui.mouse.js
- * jquery.ui.widget.js
- */
- (function( $, undefined ) {
- $.widget("ui.resizable", $.ui.mouse, {
- widgetEventPrefix: "resize",
- options: {
- alsoResize: false,
- animate: false,
- animateDuration: "slow",
- animateEasing: "swing",
- aspectRatio: false,
- autoHide: false,
- containment: false,
- ghost: false,
- grid: false,
- handles: "e,s,se",
- helper: false,
- maxHeight: null,
- maxWidth: null,
- minHeight: 10,
- minWidth: 10,
- zIndex: 1000
- },
- _create: function() {
- var self = this, o = this.options;
- this.element.addClass("ui-resizable");
- $.extend(this, {
- _aspectRatio: !!(o.aspectRatio),
- aspectRatio: o.aspectRatio,
- originalElement: this.element,
- _proportionallyResizeElements: [],
- _helper: o.helper || o.ghost || o.animate ? o.helper || 'ui-resizable-helper' : null
- });
- //Wrap the element if it cannot hold child nodes
- if(this.element[0].nodeName.match(/canvas|textarea|input|select|button|img/i)) {
- //Create a wrapper element and set the wrapper to the new current internal element
- this.element.wrap(
- $('<div class="ui-wrapper" style="overflow: hidden;"></div>').css({
- position: this.element.css('position'),
- width: this.element.outerWidth(),
- height: this.element.outerHeight(),
- top: this.element.css('top'),
- left: this.element.css('left')
- })
- );
- //Overwrite the original this.element
- this.element = this.element.parent().data(
- "resizable", this.element.data('resizable')
- );
- this.elementIsWrapper = true;
- //Move margins to the wrapper
- this.element.css({ marginLeft: this.originalElement.css("marginLeft"), marginTop: this.originalElement.css("marginTop"), marginRight: this.originalElement.css("marginRight"), marginBottom: this.originalElement.css("marginBottom") });
- this.originalElement.css({ marginLeft: 0, marginTop: 0, marginRight: 0, marginBottom: 0});
- //Prevent Safari textarea resize
- this.originalResizeStyle = this.originalElement.css('resize');
- this.originalElement.css('resize', 'none');
- //Push the actual element to our proportionallyResize internal array
- this._proportionallyResizeElements.push(this.originalElement.css({ position: 'static', zoom: 1, display: 'block' }));
- // avoid IE jump (hard set the margin)
- this.originalElement.css({ margin: this.originalElement.css('margin') });
- // fix handlers offset
- this._proportionallyResize();
- }
- this.handles = o.handles || (!$('.ui-resizable-handle', this.element).length ? "e,s,se" : { n: '.ui-resizable-n', e: '.ui-resizable-e', s: '.ui-resizable-s', w: '.ui-resizable-w', se: '.ui-resizable-se', sw: '.ui-resizable-sw', ne: '.ui-resizable-ne', nw: '.ui-resizable-nw' });
- if(this.handles.constructor == String) {
- if(this.handles == 'all') this.handles = 'n,e,s,w,se,sw,ne,nw';
- var n = this.handles.split(","); this.handles = {};
- for(var i = 0; i < n.length; i++) {
- var handle = $.trim(n[i]), hname = 'ui-resizable-'+handle;
- var axis = $('<div class="ui-resizable-handle ' + hname + '"></div>');
- // Apply zIndex to all handles - see #7960
- axis.css({ zIndex: o.zIndex });
- //TODO : What's going on here?
- if ('se' == handle) {
- axis.addClass('ui-icon ui-icon-gripsmall-diagonal-se');
- };
- //Insert into internal handles object and append to element
- this.handles[handle] = '.ui-resizable-'+handle;
- this.element.append(axis);
- }
- }
- this._renderAxis = function(target) {
- target = target || this.element;
- for(var i in this.handles) {
- if(this.handles[i].constructor == String)
- this.handles[i] = $(this.handles[i], this.element).show();
- //Apply pad to wrapper element, needed to fix axis position (textarea, inputs, scrolls)
- if (this.elementIsWrapper && this.originalElement[0].nodeName.match(/textarea|input|select|button/i)) {
- var axis = $(this.handles[i], this.element), padWrapper = 0;
- //Checking the correct pad and border
- padWrapper = /sw|ne|nw|se|n|s/.test(i) ? axis.outerHeight() : axis.outerWidth();
- //The padding type i have to apply...
- var padPos = [ 'padding',
- /ne|nw|n/.test(i) ? 'Top' :
- /se|sw|s/.test(i) ? 'Bottom' :
- /^e$/.test(i) ? 'Right' : 'Left' ].join("");
- target.css(padPos, padWrapper);
- this._proportionallyResize();
- }
- //TODO: What's that good for? There's not anything to be executed left
- if(!$(this.handles[i]).length)
- continue;
- }
- };
- //TODO: make renderAxis a prototype function
- this._renderAxis(this.element);
- this._handles = $('.ui-resizable-handle', this.element)
- .disableSelection();
- //Matching axis name
- this._handles.mouseover(function() {
- if (!self.resizing) {
- if (this.className)
- var axis = this.className.match(/ui-resizable-(se|sw|ne|nw|n|e|s|w)/i);
- //Axis, default = se
- self.axis = axis && axis[1] ? axis[1] : 'se';
- }
- });
- //If we want to auto hide the elements
- if (o.autoHide) {
- this._handles.hide();
- $(this.element)
- .addClass("ui-resizable-autohide")
- .hover(function() {
- if (o.disabled) return;
- $(this).removeClass("ui-resizable-autohide");
- self._handles.show();
- },
- function(){
- if (o.disabled) return;
- if (!self.resizing) {
- $(this).addClass("ui-resizable-autohide");
- self._handles.hide();
- }
- });
- }
- //Initialize the mouse interaction
- this._mouseInit();
- },
- destroy: function() {
- this._mouseDestroy();
- var _destroy = function(exp) {
- $(exp).removeClass("ui-resizable ui-resizable-disabled ui-resizable-resizing")
- .removeData("resizable").unbind(".resizable").find('.ui-resizable-handle').remove();
- };
- //TODO: Unwrap at same DOM position
- if (this.elementIsWrapper) {
- _destroy(this.element);
- var wrapper = this.element;
- wrapper.after(
- this.originalElement.css({
- position: wrapper.css('position'),
- width: wrapper.outerWidth(),
- height: wrapper.outerHeight(),
- top: wrapper.css('top'),
- left: wrapper.css('left')
- })
- ).remove();
- }
- this.originalElement.css('resize', this.originalResizeStyle);
- _destroy(this.originalElement);
- return this;
- },
- _mouseCapture: function(event) {
- var handle = false;
- for (var i in this.handles) {
- if ($(this.handles[i])[0] == event.target) {
- handle = true;
- }
- }
- return !this.options.disabled && handle;
- },
- _mouseStart: function(event) {
- var o = this.options, iniPos = this.element.position(), el = this.element;
- this.resizing = true;
- this.documentScroll = { top: $(document).scrollTop(), left: $(document).scrollLeft() };
- // bugfix for http://dev.jquery.com/ticket/1749
- if (el.is('.ui-draggable') || (/absolute/).test(el.css('position'))) {
- el.css({ position: 'absolute', top: iniPos.top, left: iniPos.left });
- }
- this._renderProxy();
- var curleft = num(this.helper.css('left')), curtop = num(this.helper.css('top'));