/*
* Copyright (C) 2005 - 2011 Jaspersoft Corporation. All rights reserved.
* http://www.jaspersoft.com.
*
* Unless you have purchased a commercial license agreement from Jaspersoft,
* the following license terms apply:
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*/
//////////////////////////////////////////////////////////
// Drag.js
// Generic drag objects and functions
// Note: Not yet utilized by all dragging in Jasperserver
// Author: Angus Croll
//////////////////////////////////////////////////////////
/**
* Drag Listener
* Co-ordinates drag callbacks
*/
function DragListener() {
this.agents = [];
this.currentAgentName = null;
this.dragger;
}
/**
* Standard drag events
*/
DragListener.DRAGGING_STARTED = 'draggingStarted';
DragListener.DRAGGING_FINISHED = 'draggingFinished';
DragListener.DRAGGING = 'dragging';
/**
* register a dragging agent with teh drag listener
* @param {String} agentName A key identifying the distinct functional area from which the drag originates (eg 'Tree', Table' etc.)
* This allows us to segregate event actions according to type of drag
*/
DragListener.prototype.registerAgent = function(agentName) {
this.agents[agentName] = new Array();
}
/**
* Register the event with an action
* @param {String} agentName A key identifying the distinct functional area from which the drag originates (eg Tree, Table etc.)
* @param {String} event Something that happens during drag, e.g. 'mouseOverColumn', 'mouseOutGroup' 'draggingStarted'
* @param {Function} action Function to be performed when the specified event is triggered by the specified agent
*/
DragListener.prototype.publishEvent = function(agentName,event,action) {
this.agents[agentName][event] = action;
}
/**
* Trigger the event
* @param {Object} dragListenerEvent Something that happens during drag, e.g. 'mouseOverColumn', 'mouseOutGroup' 'draggingStarted'
* @param {Object} browserEvent The window event
*/
DragListener.prototype.notify = function(dragListenerEvent,browserEvent) {
var currentAgent = this.agents[this.currentAgentName];
if (currentAgent) {
var thisAction = currentAgent[dragListenerEvent];
if (thisAction) {
var draggingObjs = this.dragger ? this.dragger.draggingObjs : null;
thisAction(browserEvent,draggingObjs);
}
}
}
/**
* any dragging going on right now?
*/
DragListener.prototype.isDragging = function() {
return this.currentAgentName != null;
}
DragListener.prototype.setCurrentAgentName = function(agentName) {
this.currentAgentName = agentName;
}
DragListener.prototype.getCurrentAgentName = function() {
return this.currentAgentName;
}
/**
* Dragger
* Drags anything......
* @param {Object} evt current window event that triggered drag
* @param {Array} draggingObjs are all objects being dragged whether or not the mouse is over them (multi-select)
* @param {Boolean} dragsX can we drag horizontally
* @param {Boolean} dragsY can we drag vertically
* @param {Number} sigMove the number of pixels user must move mouse before we consider drag initiated
* @param {DragListener} dragListener a dragListener instance
* @param {Function} cleanUpUtil an optional utlity function to be invoked after drag is released (i.e. dropped)
*/
function Dragger(evt,draggingObjs,dragsX,dragsY,sigMove,dragListener,cleanUpUtil) {
var evt = evt?evt:event;
this.originalX = new Array();
this.originalY = new Array();
this.draggingObjs = draggingObjs;
this.dragsX = dragsX;
this.dragsY = dragsY;
this.sigMove = sigMove;
this.dragListener = dragListener;
this.cleanUpUtil = cleanUpUtil;
if (this.dragListener) {
this.dragListener.dragger = this;
}
for (var i=0; ithis.sigMove;
}
if (this.dragsY) {
var yDiff = e.clientY-this.mouseY;
movedSignificantly = movedSignificantly || Math.abs(yDiff)>this.sigMove;
}
if (!this.isDragging && movedSignificantly) {
this.isDragging=true;
if (this.dragListener) {
this.dragListener.notify(DragListener.DRAGGING_STARTED,evt);
}
for (i=0; i document.body.clientWidth) {
// xDiff = false;
// break;
// }
}
if (xDiff) {
for (i=0; i document.body.clientHeight) {
// yDiff = false;
// break;
// }
}
if (yDiff) {
for (i=0; i