Apache2-Translation

 view release on metacpan or  search on metacpan

lib/Apache2/Translation/Admin/resize.js  view on Meta::CPAN

// Copyright (c) 2005 Thomas Fakes (http://craz8.com)
// 
// This code is substantially based on code from script.aculo.us which has the 
// following copyright and permission notice
//
// Copyright (c) 2005 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
// 
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
// 
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

var Resizeable = Class.create();
Resizeable.prototype = {
  initialize: function(element) {
    var options = Object.extend({
      top: 6,
      bottom: 6,
      left: 6,
      right: 6,
      minHeight: 0,
      minWidth: 0,
      zindex: 1000,
      resize: null,
      resizeInsteadWidth: null
    }, arguments[1] || {});

    this.element = $(element);
    this.handle  = this.element;

    Element.makePositioned(this.element); // fix IE    

    this.options      = options;

    if (this.options.resizeInsteadWidth) {
      this.options.resizeInsteadWidth=$(this.options.resizeInsteadWidth);
      Element.makePositioned(this.options.resizeInsteadWidth); // fix IE    
    }

    this.active       = false;
    this.resizing     = false;   
    this.currentDirection = '';

    this.eventMouseDown = this.startResize.bindAsEventListener(this);
    this.eventMouseUp   = this.endResize.bindAsEventListener(this);
    this.eventMouseMove = this.update.bindAsEventListener(this);
    this.eventCursorCheck = this.cursor.bindAsEventListener(this);
    this.eventKeypress  = this.keyPress.bindAsEventListener(this);
    
    this.registerEvents();
  },
  destroy: function() {
    Event.stopObserving(this.handle, "mousedown", this.eventMouseDown);
    this.unregisterEvents();
  },
  registerEvents: function() {
    Event.observe(document, "mouseup", this.eventMouseUp);
    Event.observe(document, "mousemove", this.eventMouseMove);
    Event.observe(document, "keypress", this.eventKeypress);
    Event.observe(this.handle, "mousedown", this.eventMouseDown);
    Event.observe(this.element, "mousemove", this.eventCursorCheck);
  },
  unregisterEvents: function() {
    //if(!this.active) return;
    //Event.stopObserving(document, "mouseup", this.eventMouseUp);
    //Event.stopObserving(document, "mousemove", this.eventMouseMove);
    //Event.stopObserving(document, "mousemove", this.eventCursorCheck);
    //Event.stopObserving(document, "keypress", this.eventKeypress);
  },
  startResize: function(event) {
    if(Event.isLeftClick(event)) {
      
      // abort on form elements, fixes a Firefox issue
      var src = Event.element(event);
      if(src.tagName &&
	 (src.tagName=='INPUT' ||
	  src.tagName=='SELECT' ||
	  src.tagName=='BUTTON' ||
	  src.tagName=='TEXTAREA')) return;
      
      var dir = this.directions(event);
      if (dir.length > 0) {      
	this.active = true;
	Resizeable.current=this;
	var offsets = Position.cumulativeOffset(this.element);
	this.startTop = offsets[1];
	this.startLeft = offsets[0];
	if( this.options.resizeInsteadWidth ) {
	  //this.startWidth = parseInt(Element.getStyle(this.options.resizeInsteadWidth, 'width'));
	  this.startWidth = Element.getWidth(this.options.resizeInsteadWidth);
	} else {
	  //this.startWidth = parseInt(Element.getStyle(this.element, 'width'));
	  this.startWidth = Element.getHeight(this.element);
	}
	//this.startHeight = parseInt(Element.getStyle(this.element, 'height'));
	this.startHeight = Element.getHeight(this.element);
	this.startX = event.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
	this.startY = event.clientY + document.body.scrollTop + document.documentElement.scrollTop;

	this.currentDirection = dir;
	Event.stop(event);
      }
    }
  },
  finishResize: function(event, success) {
    // this.unregisterEvents();

    this.active = false;



( run in 0.650 second using v1.01-cache-2.11-cpan-2398b32b56e )