PageSourceSearch

https://heeg.de/files/SBUIADropFiles/dropScript.js

js heeg.de collected 2026-10-02 18:43:17 UTC 5,383 bytes, 158 lines download raw bytes

1/*****************************************************************************************
2*		SeaBreeze.SBUIADropScript
3******************************************************************************************
4SBUIADropScript contains the Javascript for the drop framework. It will be activated when a SeaBreeze element is rendered with CSS class "sb-uia-droppable". This CSS class is written by the drop manager as soon one is linked to the element in the UIA editor tab.
5*****************************************************************************************/
6
7jQuery(function($){
8	var timeout;
9//  --------------------------------------------------------------------------------------
10function main()
11	{
12	window.uiaForcedModifiers = []; // useful for the tests to temporarily force certain modifiers
13	initializeEventHandlers();
14	var forceModifiers = function(modifiers) {window.uiaForcedModifiers = modifiers; };
15	window.uiaForceModifiers = forceModifiers;
16	window.uiaForceModifierCtrl = function(){ forceModifiers(["ctrl"]); };
17	window.uiaForceModifierShift = function(){ forceModifiers(["shift"]); };
18	window.uiaForceModifierAlt = function(){ forceModifiers(["alt"]); };
19	window.uiaForceModifierMeta = function(){ forceModifiers(["meta"]); };
20	window.uiaForceNoModifiers = function() { window.uiaForcedModifiers = []; };
21	window.uiaSimulateEvent = function(element, selector) { 
22		var event = createSimulatedEventForElement(element);
23		triggerUIAEvent(selector, event);
24	};
25}
26
27
28//  --------------------------------------------------------------------------------------
29function eventOnMouseUp(event)
30	{
31	eventOnDrop(event);
32	}
33
34
35//  --------------------------------------------------------------------------------------
36function flushUIAEventQueue()
37	{
38	timeout = null;
39	if (window.uiaEventQueue == null)
40		return;
41
42	if (window.uiaEventQueue.length == 0)
43		return;
44
45	var body =  jQuery("body");
46	var eventArray = body.data("uiaEventArray");
47	eventArray(window.uiaEventQueue);
48
49	window.uiaEventQueue = [];
50	}
51
52
53//  --------------------------------------------------------------------------------------
54function createSimulatedEventForElement(elementSelector)
55{
56	var element = null;
57	// this event is only meant to be passed to triggerUIAEvent(), it's not meant to be actually used. 
58	if (elementSelector.startsWith("css="))
59	{
60		var query = elementSelector.substr(4);
61		element = document.querySelector(query);
62	}
63	else if(elementSelector.startsWith("xpath="))
64	{
65		var path = elementSelector.substr(6);
66		element = document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
67	}
68	else
69	{
70		throw "invalid element selector";
71	}
72	var event = {};
73	event.currentTarget = element;
74	event.isSimulated = true;
75	event.altKey = false;
76	event.ctrlKey = false;
77	event.shiftKey = false;
78	event.metaKey = false;
79	var $target = jQuery(element);
80	var offset = $target.offset();
81	var centerX = (offset.left + $target.width()) * 0.5;
82	var centerY = (offset.top + $target.height()) * 0.5;
83	event.clientX = centerX;
84	event.clientY = centerY;
85	return event;
86}
87
88
89//  --------------------------------------------------------------------------------------
90function initializeEventHandlers()
91	{
92	jQuery(document).on("mouseup", ".sb-uia-droppable", eventOnMouseUp);
93	}
94
95
96//  --------------------------------------------------------------------------------------
97function eventOnDrop(event)
98	{
99	triggerUIAEvent("eventOnDrop:", event);
100	}
101
102
103//  --------------------------------------------------------------------------------------
104function regionsForEvent(event)
105	{
106	var	target	= jQuery(event.currentTarget);
107	var	offset	= target.offset();
108	var	targetX	= (event.clientX - offset.left) * 100 / target.width();
109	var	targetY	= (event.clientY - offset.top) * 100 / target.height();
110	var	hType	= "hcenter";
111	var	vType	= "vcenter";
112
113	if (!event.isSimulated)
114	{
115		if (targetX < 25)	hType = "left";
116		if (targetX > 75)	hType = "right";
117		if (targetY < 25)	vType = "top";
118		if (targetY > 75)	vType = "bottom";
119	}
120	return { hType: hType, vType: vType };
121	}
122
123
124//  --------------------------------------------------------------------------------------
125function triggerUIAEvent(selector, event)
126	{
127	if (window.uiaEventQueue == null)
128		window.uiaEventQueue = [];
129
130	if (window.uiaEventQueue.length == 0 && !timeout)
131		// create a timeout to only flush once and collect all events up until then
132		// timeout is not postponed upon next event, so that the events are not accumulating too much
133		// without this the dblclick event would not fire because mouseDown and mouseUp take too long as separate callbacks
134		timeout = setTimeout(flushUIAEventQueue, 100);
135	
136	// forced modifiers exist for the selenium-tests. main() defines functions to force modifiers
137	var forcedShift = window.uiaForcedModifiers.includes("shift");
138	var forcedCtrl = window.uiaForcedModifiers.includes("ctrl");
139	var forcedAlt = window.uiaForcedModifiers.includes("alt");
140	var forcedMeta = window.uiaForcedModifiers.includes("meta");
141	
142	window.uiaEventQueue.push({
143		selector:		selector,
144		regions:		regionsForEvent(event),
145		senderID:		event.currentTarget.id,
146		altKey:		(event.altKey || forcedAlt),
147		ctrlKey:		(event.ctrlKey || forcedCtrl),
148		metaKey:		(event.metaKey || forcedMeta),
149		shiftKey:		(event.shiftKey || forcedShift),
150		clientX:		event.clientX,
151		clientY:		event.clientY
152		});
153	}
154
155
156
157	main()
158});

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.