02575d8e5c6ef34139b887c0dab72ebc9ac541af
[Packages/TYPO3.CMS.git] / typo3 / sysext / rtehtmlarea / Resources / Public / JavaScript / HTMLArea / Util / HTMLArea.util.TYPO3.js
1 /***************************************************
2 * HTMLArea.util.TYPO3: Utility functions for dealing with tabs and inline elements in TYPO3 forms
3 ***************************************************/
4 HTMLArea.util.TYPO3 = function () {
5 return {
6 /*
7 * Simplify the array of nested levels. Create an indexed array with the correct names of the elements.
8 *
9 * @param object nested: The array with the nested levels
10 * @return object The simplified array
11 * @author Oliver Hader <oh@inpublica.de>
12 */
13 simplifyNested: function(nested) {
14 var i, type, level, elementId, max, simplifiedNested=[],
15 elementIdSuffix = {
16 tab: '-DIV',
17 inline: '_fields',
18 flex: '-content'
19 };
20 if (nested && nested.length) {
21 if (nested[0][0]=='inline') {
22 nested = inline.findContinuedNestedLevel(nested, nested[0][1]);
23 }
24 for (i=0, max=nested.length; i<max; i++) {
25 type = nested[i][0];
26 level = nested[i][1];
27 elementId = level + elementIdSuffix[type];
28 if (Ext.get(elementId)) {
29 simplifiedNested.push(elementId);
30 }
31 }
32 }
33 return simplifiedNested;
34 },
35 /*
36 * Access an inline relational element or tab menu and make it "accessible".
37 * If a parent or ancestor object has the style "display: none", offsetWidth & offsetHeight are '0'.
38 *
39 * @params arry parentElements: array of parent elements id's; note that this input array will be modified
40 * @params object callbackFunc: A function to be called, when the embedded objects are "accessible".
41 * @params array args: array of arguments
42 * @return object An object returned by the callbackFunc.
43 * @author Oliver Hader <oh@inpublica.de>
44 */
45 accessParentElements: function (parentElements, callbackFunc, args) {
46 var result = {};
47 if (parentElements.length) {
48 var currentElement = parentElements.pop();
49 currentElement = Ext.get(currentElement);
50 var actionRequired = (currentElement.getStyle('display') == 'none');
51 if (actionRequired) {
52 var visibility = currentElement.dom.style.visibility;
53 var position = currentElement.dom.style.position;
54 var top = currentElement.dom.style.top;
55 var display = currentElement.dom.style.display;
56 var className = currentElement.dom.parentNode.className;
57 currentElement.setStyle({
58 visibility: 'hidden',
59 position: 'absolute',
60 top: '-10000px',
61 display: ''
62 });
63 currentElement.dom.parentElement.className = '';
64 }
65 result = this.accessParentElements(parentElements, callbackFunc, args);
66 if (actionRequired) {
67 currentElement.dom.style.visibility = visibility;
68 currentElement.dom.style.position = position;
69 currentElement.dom.style.top = top;
70 currentElement.dom.style.display = display;
71 currentElement.dom.parentNode.className = className;
72 }
73 } else {
74 result = eval(callbackFunc);
75 }
76 return result;
77 },
78 /*
79 * Check if all elements in input array are currently displayed
80 *
81 * @param array elements: array of element id's
82 * @return boolean true if all elements are displayed
83 */
84 allElementsAreDisplayed: function(elements) {
85 var allDisplayed = true;
86 for (var i = elements.length; --i >= 0;) {
87 allDisplayed = Ext.get(elements[i]).getStyle('display') !== 'none';
88 if (!allDisplayed) {
89 break;
90 }
91 }
92 return allDisplayed;
93 },
94 /*
95 * Get current size of window
96 *
97 * @return object width and height of window
98 */
99 getWindowSize: function () {
100 if (HTMLArea.UserAgent.isIE) {
101 var size = Ext.getBody().getSize();
102 } else {
103 var size = {
104 width: window.innerWidth,
105 height: window.innerHeight
106 };
107 }
108 // Subtract the docheader height from the calculated window height
109 var docHeader = Ext.get('typo3-docheader');
110 if (docHeader) {
111 size.height -= docHeader.getHeight();
112 docHeader.dom = null;
113 }
114 return size;
115 }
116 }
117 }();