aboutsummaryrefslogtreecommitdiffstats
path: root/dcae_dmaapbc_webapp/src/main/webapp/app/fusion/ase/scripts/resizable.js
blob: 443c63cffd5717a8d050656726b58ddbe50611e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/*
=============================================================================================
The MIT License (MIT)

Copyright 2015 AT&T Intellectual Property. All other rights reserved.

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.
*/

//Contains functions for making and resizing arrows

interact('.resizable')
.resizable({

	snap: {
    	targets: [ interact.createLifelineSnapGrid(	) ],
	    relativePoints: [ { x: 0, y: 0 } ],
		range: Infinity,
		endOnly: true //CREATES SMOOTH SNAP
	},
	edges: { left: true, right: true, bottom: false, top: false },
	invert: 'reposition'
	
})
.on('resizemove', function (event) {
	var target = event.target;
	if (target.id=="") target = event.target.parentNode;
	var x = (parseFloat(target.getAttribute('data_x')) || 0),
	y = (parseFloat(target.getAttribute('data_y')) || 0);
	
	// update the element's style
	if (window.resized == false){
		target.style.width  = event.rect.width + 'px';
	
	
	target.style.height = event.rect.height + 'px';

	// translate when resizing from top or left edges
	x += event.deltaRect.left;
	y += event.deltaRect.top;
	
	target.style.webkitTransform = target.style.transform =
		'translate(' + x + 'px,' + y + 'px)';

	target.setAttribute('data_x', x);
	target.setAttribute('data_y', y);
	}
	uuid = target.id;
	if (uuid==""){
		uuid = target.parentElement.id;
	}
	
	
	var index = storeXY(arrowArr,uuid);
	window.currentArrow = arrowArr[index][1];
	window.leftX = arrowArr[index][3];
	window.rightX = arrowArr[index][6];
	window.currentY = y;
		
	window.resized = false;
	var endingLeftX = event.target.getAttribute("data_x");
	var endingRightX = parseInt(event.target.getAttribute("data_x")) + parseInt($("#"+target.id).width());
	
	if ($("#"+event.target.id).width() == 0){
		target.setAttribute("direction","self");
		makeArrow(target);
	}
	if (target.getAttribute("direction") == "self"){
		if (endingRightX>startingLeftX){ //Not negative case
			target.setAttribute("direction","right");
			makeArrow(target);
		}
		else if (endingLeftX<startingLeftX){ //Negative case: swap 
			startingRightX = startingLeftX;
			target.setAttribute("direction","left");
			makeArrow(target);	
		}
		else if (endingLeftX==endingRightX){
			target.setAttribute("direction","self");
			makeArrow(target);
		}
	}
	else if (target.getAttribute("direction") == "right"){

		if (endingLeftX<startingLeftX && $('#'+target.id).width()<25){ //Negative case: swap 
			startingRightX = startingLeftX;
			target.setAttribute("direction","left");
			makeArrow(target);	
		}	
		else if (endingLeftX==endingRightX){
			target.setAttribute("direction","self");
			makeArrow(target);
		}
		
	}
	else if (target.getAttribute("direction") == "left"){

		if (endingRightX>startingRightX && $('#'+target.id).width()<25){
			startingLeftX = startingRightX;
			target.setAttribute("direction","right");
			makeArrow(target);
		}
		else if (endingLeftX==endingRightX){
			target.setAttribute("direction","self");
			makeArrow(target);
		}
	}
	storeXY(arrowArr,uuid);
	determineLRNode(uuid,"arrow"); //move to resizeend api if lagging
	
	
})
.on('resizestart', function(event){
	startingLeftX = event.target.getAttribute("data_x");
	startingRightX = parseInt(event.target.getAttribute("data_x")) + parseInt($("#"+event.target.id).width());
	startWidth = parseInt($("#"+event.target.id).width());
})
.on('resizeend', function(event){
	if ($("#"+event.target.id).width() == 0){
		event.target.setAttribute("direction","self");
		makeArrow(event.target);
	}
	var target = event.target
	if (target.id=="") target = event.target.parentNode;
	determineLRNode(target.id,"arrow");
});

function makeArrow(target){
	try{
		recallArray(arrowArr, target.id);
		if (target.getAttribute("direction") == "right"){
			target.innerHTML = '<div class="arrow" style="display:inline; width:100%"><div class="makeEllipsis arrowText">'+text+'</div></div><div class="triangle" style="display:inline;"></div>'
		}
		else if (target.getAttribute("direction") == "left"){
			target.innerHTML = '<div class="leftTriangle" style="display:inline;"></div><div class="leftArrow" style="display:inline; width:100%;"><div class="makeEllipsis arrowText">'+text+'</div></div>'
		}
		else if (target.getAttribute("direction") == "self"){
			target.innerHTML = '<div style="display:inline; width:100%"><img src="../images/selfArrow.png" style = "cursor:e-resize;"><div class="makeEllipsisSelf arrowText" style="width:75px;font-size:12px;margin-left:3px;text-align:left;display:inline">'+text+'</div></div>'
		}
	}
	catch(err){
		var uuid = target
		var target = document.getElementById(target);
		recallArray(arrowArr, uuid);
		if (target.getAttribute("direction") == "right"){
			target.innerHTML = '<div class="arrow" style="display:inline; width:100%"><div class="makeEllipsis arrowText">'+text+'</div></div><div class="triangle" style="display:inline;"></div>'
		}
		else if (target.getAttribute("direction") == "left"){
			target.innerHTML = '<div class="leftTriangle" style="display:inline;"></div><div class="leftArrow" style="display:inline; width:100%;"><div class="makeEllipsis arrowText">'+text+'</div></div>'
		}
		else if (target.getAttribute("direction") == "self"){
			target.innerHTML = '<div style="display:inline; width:100%"><img src="../images/selfArrow.png" style = "cursor:e-resize;"><div class="makeEllipsisSelf arrowText" style="width:75px;font-size:12px;margin-left:3px;text-align:left;display:inline">'+text+'</div></div>'
		}
	}
}