863e388df884c96004ecfc99e8b3669bb8021a04
1 /***************************************************************
3 * javascript functions regarding the TYPO3 wrapper
4 * for the javascript library "prototype".
8 * (c) 2008-2010 Benjamin Mack <www.xnos.org>
11 * This script is part of the TYPO3 backend provided by
12 * Kasper Skaarhoj <kasper@typo3.com> together with TYPO3
14 * Released under GNU/GPL (see license file in /typo3/)
16 * This script is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20 * This copyright notice MUST APPEAR in all copies of this script
22 ***************************************************************/
24 // Please make sure that prototype.js is loaded before loading this
25 // file in your script, the responder is only added if prototype was loaded
28 // adding generic a responder to use when a AJAX request is done
29 Ajax
.Responders
.register({
30 onCreate: function(request
, transport
) {
32 // if the TYPO3 AJAX backend is used,
33 // the onSuccess & onComplete callbacks are hooked
34 if (request
.url
.indexOf("ajax.php") === -1) {
38 var origSuccess
= request
.options
.onSuccess
, origComplete
= request
.options
.onComplete
;
40 // hooking "onSuccess"
42 request
.options
.onSuccess = function(xhr
, json
) {
44 T3AJAX
.showError(xhr
);
46 origSuccess(xhr
, json
);
51 // hooking "onComplete", using T3Error handler if available
53 request
.options
.onComplete = function(xhr
, json
) {
54 if (!json
&& request
.options
.onT3Error
) {
55 request
.options
.onT3Error(xhr
, json
);
57 T3AJAX
.showError(xhr
);
59 origComplete(xhr
, json
);
68 T3AJAX
.showError = function(xhr
, json
) {
69 if (typeof xhr
.responseText
!== undefined && xhr
.responseText
) {
70 if (typeof Ext
.MessageBox
!== undefined) {
71 Ext
.MessageBox
.alert('TYPO3', xhr
.responseText
);
74 alert(xhr
.responseText
);
79 // common storage and global object, could later hold more information about the current user etc.
81 // store instances that only should be running once
83 getInstance: function(className
) {
84 return TYPO3
._instances
[className
] || false;
86 addInstance: function(className
, instance
) {
87 TYPO3
._instances
[className
] = instance
;
92 // creates an array by splitting a string into parts, taking a delimiter
93 split: function(str
, delim
) {
95 while (str
.indexOf(delim
) > 0) {
96 res
.push(str
.substr(0, str
.indexOf(delim
)));
97 str
= str
.substr(str
.indexOf(delim
) + delim
.length
);