1 | /*!
|
2 | * OpenUI5
|
3 | * (c) Copyright 2009-2022 SAP SE or an SAP affiliate company.
|
4 | * Licensed under the Apache License, Version 2.0 - see LICENSE.txt.
|
5 | */
|
6 |
|
7 | // Provides functionality related to DOM analysis and manipulation which is not provided by jQuery itself.
|
8 | sap.ui.define([
|
9 | 'jquery.sap.global', 'sap/ui/dom/containsOrEquals',
|
10 | 'sap/ui/core/syncStyleClass', 'sap/ui/dom/getOwnerWindow', 'sap/ui/dom/getScrollbarSize',
|
11 | 'sap/ui/dom/denormalizeScrollLeftRTL', 'sap/ui/dom/denormalizeScrollBeginRTL',
|
12 | 'sap/ui/dom/units/Rem', 'sap/ui/dom/jquery/Aria',
|
13 | 'sap/ui/dom/jquery/Selection', 'sap/ui/dom/jquery/zIndex', 'sap/ui/dom/jquery/parentByAttribute',
|
14 | 'sap/ui/dom/jquery/cursorPos', 'sap/ui/dom/jquery/selectText', 'sap/ui/dom/jquery/getSelectedText',
|
15 | 'sap/ui/dom/jquery/rect', 'sap/ui/dom/jquery/rectContains', 'sap/ui/dom/jquery/Focusable',
|
16 | 'sap/ui/dom/jquery/hasTabIndex', 'sap/ui/dom/jquery/scrollLeftRTL', 'sap/ui/dom/jquery/scrollRightRTL', 'sap/ui/dom/jquery/Selectors'
|
17 | ], function(jQuery, domContainsOrEquals, fnSyncStyleClass, domGetOwnerWindow,
|
18 | domGetScrollbarSize, domDenormalizeScrollLeftRTL, domDenormalizeScrollBeginRTL, domUnitsRem
|
19 | /*
|
20 | jqueryAria,
|
21 | jquerySelection,
|
22 | jqueryzIndex,
|
23 | jqueryParentByAttribute,
|
24 | jqueryCursorPos,
|
25 | jquerySelectText,
|
26 | jqueryGetSelectedText,
|
27 | jqueryRect,
|
28 | jqueryRectContains,
|
29 | jqueryFocusable,
|
30 | jqueryHasTabIndex,
|
31 | jqueryScrollLeftRTL,
|
32 | jqueryScrollRightRTL,
|
33 | jquerySelectors*/
|
34 | ) {
|
35 | ;
|
36 |
|
37 | /**
|
38 | * Shortcut for document.getElementById().
|
39 | *
|
40 | * @param {string} sId The id of the DOM element to return
|
41 | * @param {Window} [oWindow=window] The window (optional)
|
42 | * @return {Element} The DOMNode identified by the given sId
|
43 | * @public
|
44 | * @since 0.9.0
|
45 | * @deprecated since 1.58 use <code>document.getElementById</code> instead
|
46 | */
|
47 | jQuery.sap.domById = function domById(sId, oWindow) {
|
48 | return sId ? (oWindow || window).document.getElementById(sId) : null;
|
49 | };
|
50 |
|
51 | /**
|
52 | * Shortcut for jQuery("#" + id) with additionally the id being escaped properly.
|
53 | * I.e.: returns the jQuery object for the DOM element with the given id
|
54 | *
|
55 | * Use this method instead of jQuery(...) if you know the argument is exactly one id and
|
56 | * the id is not known in advance because it is in a variable (as opposed to a string
|
57 | * constant with known content).
|
58 | *
|
59 | * @param {string} sId The id to search for and construct the jQuery object
|
60 | * @param {Element} oContext the context DOM Element
|
61 | * @return {Object} The jQuery object for the DOM element identified by the given sId
|
62 | * @public
|
63 | * @since 0.9.1
|
64 | * @function
|
65 | * @deprecated since 1.58 use <code>jQuery(document.getElementById(sId))</code> instead
|
66 | */
|
67 | jQuery.sap.byId = function byId(sId, oContext) {
|
68 | var escapedId = "";
|
69 | if (sId) {
|
70 | // Note: This does not escape all relevant characters according to jQuery's documentation
|
71 | // (see http://api.jquery.com/category/selectors/)
|
72 | // As the behavior hasn't been changed for a long time it is not advisable to change it in
|
73 | // future as users might be already escaping characters on their own or relying on the fact
|
74 | // selector like byId("my-id > div") can be used.
|
75 | escapedId = "#" + sId.replace(/(:|\.)/g,'\\$1');
|
76 | }
|
77 | return jQuery(escapedId, oContext);
|
78 | };
|
79 |
|
80 | /**
|
81 | * Calls focus() on the given DOM element.
|
82 | *
|
83 | * @param {Element} oDomRef The DOM element to focus (or null - in this case the method does nothing)
|
84 | * @return {boolean} Whether the focus() command was executed without an error
|
85 | * @public
|
86 | * @since 1.1.2
|
87 | * @function
|
88 | * @deprecated since 1.58 use <code>oDomRef.focus()</code> instead
|
89 | */
|
90 | jQuery.sap.focus = function focus(oDomRef) {
|
91 | if (!oDomRef) {
|
92 | return;
|
93 | }
|
94 | oDomRef.focus();
|
95 | return true;
|
96 | };
|
97 |
|
98 | /*
|
99 | * Convert <code>px</code> values to <code>rem</code>.
|
100 | *
|
101 | * @param {string|float} vPx The value in <code>px</code> units. E.g.: <code>"16px"</code> or <code>16</code>
|
102 | * @returns {float} The converted value in <code>rem</code> units. E.g.: <code>1</code>
|
103 | * @protected
|
104 | * @since 1.48
|
105 | * @deprecated since 1.58 use {@link module:sap/ui/dom/units/Rem.fromPx} instead
|
106 | */
|
107 | jQuery.sap.pxToRem = domUnitsRem.fromPx;
|
108 |
|
109 | /*
|
110 | * Convert <code>rem</code> values to <code>px</code>.
|
111 | *
|
112 | * @param {string|float} vRem The value in <code>rem</code>. E.g.: <code>"1rem"</code> or <code>1</code>
|
113 | * @returns {float} The converted value in <code>px</code> units. E.g.: <code>16</code>
|
114 | * @protected
|
115 | * @since 1.48
|
116 | * @deprecated since 1.58 use {@link module:sap/ui/dom/units/Rem.toPx} instead
|
117 | */
|
118 | jQuery.sap.remToPx = domUnitsRem.toPx;
|
119 |
|
120 | /**
|
121 | * Returns the outer HTML of the given HTML element.
|
122 | *
|
123 | * @return {string} outer HTML
|
124 | * @public
|
125 | * @name jQuery#outerHTML
|
126 | * @author SAP SE
|
127 | * @since 0.9.0
|
128 | * @function
|
129 | * @deprecated since 1.58 use native <code>Element#outerHTML</code> instead
|
130 | */
|
131 | jQuery.fn.outerHTML = function() {
|
132 | var oDomRef = this.get(0);
|
133 |
|
134 | if (oDomRef && oDomRef.outerHTML) {
|
135 | return oDomRef.outerHTML.trim();
|
136 | } else {
|
137 | var doc = this[0] ? this[0].ownerDocument : document;
|
138 |
|
139 | var oDummy = doc.createElement("div");
|
140 | oDummy.appendChild(oDomRef.cloneNode(true));
|
141 | return oDummy.innerHTML;
|
142 | }
|
143 | };
|
144 |
|
145 | /**
|
146 | * Returns whether <code>oDomRefChild</code> is contained in or equal to <code>oDomRefContainer</code>.
|
147 | *
|
148 | * For compatibility reasons it returns <code>true</code> if <code>oDomRefContainer</code> and
|
149 | * <code>oDomRefChild</code> are equal.
|
150 | *
|
151 | * This method intentionally does not operate on the jQuery object, as the original <code>jQuery.contains()</code>
|
152 | * method also does not do so.
|
153 | *
|
154 | * @param {Element} oDomRefContainer The container element
|
155 | * @param {Element} oDomRefChild The child element (must not be a text node, must be an element)
|
156 | * @return {boolean} Whether <code>oDomRefChild</code> is contained in or equal to <code>oDomRefContainer</code>
|
157 | * @public
|
158 | * @author SAP SE
|
159 | * @since 0.9.0
|
160 | * @function
|
161 | * @deprecated since 1.58 use {@link module:sap/ui/dom/containsOrEquals} instead
|
162 | */
|
163 | jQuery.sap.containsOrEquals = domContainsOrEquals;
|
164 |
|
165 | /**
|
166 | * For the given scrollLeft value this method returns the scrollLeft value as understood by the current browser in RTL mode.
|
167 | * This value is specific to the given DOM element, as the computation may involve its dimensions.
|
168 | *
|
169 | * So when oDomRef should be scrolled 2px from the leftmost position, the number "2" must be given as iNormalizedScrollLeft
|
170 | * and the result of this method (which may be a large or even negative number, depending on the browser) can then be set as
|
171 | * oDomRef.scrollLeft to achieve the desired (cross-browser-consistent) scrolling position.
|
172 | *
|
173 | * This method does no scrolling on its own, it only calculates the value to set (so it can also be used for animations).
|
174 | *
|
175 | * @param {int} iNormalizedScrollLeft The distance from the leftmost position to which the element should be scrolled
|
176 | * @param {Element} oDomRef The DOM Element to which scrollLeft will be applied
|
177 | * @return {int} The scroll position that must be set for the DOM element
|
178 | * @public
|
179 | * @author SAP SE
|
180 | * @since 0.20.0
|
181 | * @function
|
182 | * @deprecated since 1.58 use {@link module:sap/ui/dom/denormalizeScrollLeftRTL} instead
|
183 | */
|
184 | jQuery.sap.denormalizeScrollLeftRTL = domDenormalizeScrollLeftRTL;
|
185 |
|
186 | /**
|
187 | * For the given scroll position measured from the "beginning" of a container (the right edge in RTL mode)
|
188 | * this method returns the scrollLeft value as understood by the current browser in RTL mode.
|
189 | * This value is specific to the given DOM element, as the computation may involve its dimensions.
|
190 | *
|
191 | * So when oDomRef should be scrolled 2px from the beginning, the number "2" must be given as iNormalizedScrollBegin
|
192 | * and the result of this method (which may be a large or even negative number, depending on the browser) can then be set as
|
193 | * oDomRef.scrollLeft to achieve the desired (cross-browser-consistent) scrolling position.
|
194 | * Low values make the right part of the content visible, high values the left part.
|
195 | *
|
196 | * This method does no scrolling on its own, it only calculates the value to set (so it can also be used for animations).
|
197 | *
|
198 | * Only use this method in RTL mode, as the behavior in LTR mode is undefined and may change!
|
199 | *
|
200 | * @param {int} iNormalizedScrollBegin The distance from the rightmost position to which the element should be scrolled
|
201 | * @param {Element} oDomRef The DOM Element to which scrollLeft will be applied
|
202 | * @return {int} The scroll position that must be set for the DOM element
|
203 | * @public
|
204 | * @author SAP SE
|
205 | * @since 1.26.1
|
206 | * @function
|
207 | * @deprecated since 1.58 use {@link module:sap/ui/dom/denormalizeScrollBeginRTL} instead
|
208 | */
|
209 | jQuery.sap.denormalizeScrollBeginRTL = domDenormalizeScrollBeginRTL;
|
210 |
|
211 | /*
|
212 | * The following implementation of jQuery.support.selectstart is taken from jQuery UI core but modified.
|
213 | *
|
214 | * jQuery UI Core
|
215 | * http://jqueryui.com
|
216 | *
|
217 | * Copyright 2014 jQuery Foundation and other contributors
|
218 | * Released under the MIT license.
|
219 | * http://jquery.org/license
|
220 | *
|
221 | * http://api.jqueryui.com/category/ui-core/
|
222 | */
|
223 |
|
224 | /**
|
225 | * States whether the selectstart event is supported by the browser.
|
226 | *
|
227 | * @private
|
228 | * @type {boolean}
|
229 | * @deprecated since 1.58
|
230 | */
|
231 | jQuery.support.selectstart = "onselectstart" in document.createElement("div");
|
232 |
|
233 | /**
|
234 | * Returns the window reference for a DomRef.
|
235 | *
|
236 | * @param {Element} oDomRef The DOM reference
|
237 | * @return {Window} Window reference
|
238 | * @public
|
239 | * @since 0.9.0
|
240 | * @function
|
241 | * @deprecated since 1.58 use {@link module:sap/ui/dom/getOwnerWindow} instead
|
242 | */
|
243 | jQuery.sap.ownerWindow = domGetOwnerWindow;
|
244 |
|
245 | /**
|
246 | * Returns the size (width of the vertical / height of the horizontal) native browser scrollbars.
|
247 | *
|
248 | * This function must only be used when the DOM is ready.
|
249 | *
|
250 | * @param {string} [sClasses=null] the CSS class that should be added to the test element.
|
251 | * @param {boolean} [bForce=false] force recalculation of size (e.g. when CSS was changed). When no classes are passed all calculated sizes are reset.
|
252 | * @return {object} JSON object with properties <code>width</code> and <code>height</code> (the values are of type number and are pixels).
|
253 | * @public
|
254 | * @since 1.4.0
|
255 | * @function
|
256 | * @deprecated since 1.58 use {@link module:sap/ui/dom/getScrollbarSize} instead
|
257 | */
|
258 | jQuery.sap.scrollbarSize = domGetScrollbarSize;
|
259 |
|
260 | /**
|
261 | * Search ancestors of the given source DOM element for the specified CSS class name.
|
262 | * If the class name is found, set it to the root DOM element of the target control.
|
263 | * If the class name is not found, it is also removed from the target DOM element.
|
264 | *
|
265 | * @param {string} sStyleClass CSS class name
|
266 | * @param {jQuery|sap.ui.core.Control|string} vSource jQuery object, control or an id of the source element.
|
267 | * @param {jQuery|sap.ui.core.Control} vDestination target jQuery object or a control.
|
268 | * @return {jQuery|Element} Target element
|
269 | * @public
|
270 | * @since 1.22
|
271 | * @function
|
272 | * @deprecated since 1.58 use {@link module:sap/ui/core/syncStyleClass} instead
|
273 | */
|
274 | jQuery.sap.syncStyleClass = fnSyncStyleClass;
|
275 |
|
276 | return jQuery;
|
277 |
|
278 | });
|