afbc5ca45520a03bd6241611d64736ddae6cb6e7
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Resources / Public / JavaScript / backend.js
1 /*
2 * This file is part of the TYPO3 CMS project.
3 *
4 * It is free software; you can redistribute it and/or modify it under
5 * the terms of the GNU General Public License, either version 2
6 * of the License, or any later version.
7 *
8 * For the full copyright and license information, please read the
9 * LICENSE.txt file that was distributed with this source code.
10 *
11 * The TYPO3 project - inspiring people to share!
12 */
13
14
15 /**
16 * common storage and global object, could later hold more information about the current user etc.
17 */
18 var TYPO3 = TYPO3 || {};
19 TYPO3 = Ext.apply(TYPO3, {
20 // store instances that only should be running once
21 _instances: {},
22 getInstance: function(className) {
23 return TYPO3._instances[className] || false;
24 },
25 addInstance: function(className, instance) {
26 TYPO3._instances[className] = instance;
27 return instance;
28 },
29
30 helpers: {
31 // creates an array by splitting a string into parts, taking a delimiter
32 split: function(str, delim) {
33 var res = [];
34 while (str.indexOf(delim) > 0) {
35 res.push(str.substr(0, str.indexOf(delim)));
36 str = str.substr(str.indexOf(delim) + delim.length);
37 }
38 return res;
39 }
40 }
41 });
42
43 /**
44 * general backend javascript functions
45 */
46
47 Ext.ns('TYPO3.configuration');
48
49 /**
50 * jump the backend to a module
51 */
52 function jump(url, modName, mainModName, pageId) {
53 if (isNaN(pageId)) {
54 pageId = -2;
55 }
56 // clear information about which entry in nav. tree that might have been highlighted.
57 top.fsMod.navFrameHighlightedID = [];
58 top.fsMod.recentIds['web'] = pageId;
59
60 if (top.TYPO3.Backend.NavigationContainer.PageTree) {
61 top.TYPO3.Backend.NavigationContainer.PageTree.refreshTree();
62 }
63
64 top.nextLoadModuleUrl = url;
65 top.TYPO3.ModuleMenu.App.showModule(modName);
66
67 }
68
69 /**
70 * Function similar to PHPs rawurlencode();
71 */
72 function rawurlencode(str) {
73 var output = escape(str);
74 output = str_replace("*","%2A", output);
75 output = str_replace("+","%2B", output);
76 output = str_replace("/","%2F", output);
77 output = str_replace("@","%40", output);
78 return output;
79 }
80
81
82 /**
83 * String-replace function
84 */
85 function str_replace(match,replace,string) { //
86 var input = ""+string;
87 var matchStr = ""+match;
88 if (!matchStr) {return string;}
89 var output = "";
90 var pointer=0;
91 var pos = input.indexOf(matchStr);
92 while (pos !== -1) {
93 output+=""+input.substr(pointer, pos-pointer)+replace;
94 pointer=pos+matchStr.length;
95 pos = input.indexOf(match,pos+1);
96 }
97 output+=""+input.substr(pointer);
98 return output;
99 }
100
101
102
103 /**
104 * Launcing information window for records/files (fileref as "table" argument)
105 */
106 function launchView(table, uid) {
107 var thePreviewWindow = window.open(TYPO3.settings.ShowItem.moduleUrl + '&table=' + encodeURIComponent(table) + "&uid=" + encodeURIComponent(uid),
108 "ShowItem" + TS.uniqueID,
109 "width=650,height=600,status=0,menubar=0,resizable=0,location=0,directories=0,scrollbars=1,toolbar=0");
110 if (thePreviewWindow && thePreviewWindow.focus) {
111 thePreviewWindow.focus();
112 }
113 }
114
115 /**
116 * Opens plain window with url
117 */
118 function openUrlInWindow(url,windowName) { //
119 regularWindow = window.open(
120 url,
121 windowName,
122 "status=1,menubar=1,resizable=1,location=1,directories=0,scrollbars=1,toolbar=1");
123 regularWindow.focus();
124 return false;
125 }
126
127 /**
128 * Loads a page id for editing in the page edit module:
129 */
130 function loadEditId(id,addGetVars) { //
131 top.fsMod.recentIds.web = id;
132 top.fsMod.navFrameHighlightedID.web = "pages" + id + "_0"; // For highlighting
133
134 if (top.content && top.content.nav_frame && top.content.nav_frame.refresh_nav) {
135 top.content.nav_frame.refresh_nav();
136 }
137 if (TYPO3.configuration.pageModule) {
138 top.goToModule(TYPO3.configuration.pageModule, 0, addGetVars?addGetVars:"");
139 }
140 }
141
142 /**
143 * Returns incoming URL (to a module) unless nextLoadModuleUrl is set. If that is the case nextLoadModuleUrl is returned (and cleared)
144 * Used by the shortcut frame to set a "intermediate URL"
145 */
146 var nextLoadModuleUrl="";
147 function getModuleUrl(inUrl) { //
148 var nMU;
149 if (top.nextLoadModuleUrl) {
150 nMU=top.nextLoadModuleUrl;
151 top.nextLoadModuleUrl="";
152 return nMU;
153 } else {
154 return inUrl;
155 }
156 }
157
158
159
160
161 // Used by Frameset Modules
162 var currentSubScript = "";