summaryrefslogtreecommitdiff
path: root/misc/drupal.js
diff options
context:
space:
mode:
authorGábor Hojtsy <gabor@hojtsy.hu>2007-10-05 09:35:09 +0000
committerGábor Hojtsy <gabor@hojtsy.hu>2007-10-05 09:35:09 +0000
commit31b73898af536da873e12cc0cf6f3a4ee7b7d9cc (patch)
treedd33ce8708f6b929a11b79ae90a2a6957afbe54f /misc/drupal.js
parent5fc06cec4c440ac21b3913c0c9b0c892a6091bb9 (diff)
downloadbrdo-31b73898af536da873e12cc0cf6f3a4ee7b7d9cc.tar.gz
brdo-31b73898af536da873e12cc0cf6f3a4ee7b7d9cc.tar.bz2
#157752 by quicksketch: extend AHAH functionality to most types of form elements, without writing JavaScript. Also AHAH enable the blocks admin page.
Diffstat (limited to 'misc/drupal.js')
-rw-r--r--misc/drupal.js102
1 files changed, 7 insertions, 95 deletions
diff --git a/misc/drupal.js b/misc/drupal.js
index c7e955aae..edf621101 100644
--- a/misc/drupal.js
+++ b/misc/drupal.js
@@ -181,103 +181,15 @@ Drupal.theme = function(func) {
};
/**
- * Redirects a button's form submission to a hidden iframe and displays the result
- * in a given wrapper. The iframe should contain a call to
- * window.parent.iframeHandler() after submission.
- */
-Drupal.redirectFormButton = function (uri, button, handler) {
- // Trap the button
- button.onmouseover = button.onfocus = function() {
- button.onclick = function() {
- // Create target iframe
- Drupal.deleteIframe();
- Drupal.createIframe();
-
- // Prepare variables for use in anonymous function.
- var button = this;
- var action = button.form.action;
- var target = button.form.target;
-
- // Redirect form submission to iframe
- this.form.action = uri;
- this.form.target = 'redirect-target';
- this.form.submit();
-
- handler.onsubmit();
-
- // Set iframe handler for later
- window.iframeHandler = function () {
- var iframe = $('#redirect-target').get(0);
- // Restore form submission
- button.form.action = action;
- button.form.target = target;
-
- // Get response from iframe body
- try {
- response = (iframe.contentWindow || iframe.contentDocument || iframe).document.body.innerHTML;
- // Firefox 1.0.x hack: Remove (corrupted) control characters
- response = response.replace(/[\f\n\r\t]/g, ' ');
- if (window.opera) {
- // Opera-hack: it returns innerHTML sanitized.
- response = response.replace(/&quot;/g, '"');
- }
- }
- catch (e) {
- response = null;
- }
-
- response = eval('('+ response +');');
- // Check response code
- if (!response || response.status == 0) {
- handler.onerror(response.data || Drupal.t('Error parsing response'));
- return;
- }
- handler.oncomplete(response.data);
-
- return true;
- };
-
- return true;
- };
- };
- button.onmouseout = button.onblur = function() {
- button.onclick = null;
- };
-};
-
-/**
- * Create an invisible iframe for form submissions.
+ * Parse a JSON response.
+ *
+ * The result is either the JSON object, or an object with 'status' 0 and 'data' an error message.
*/
-Drupal.createIframe = function () {
- if ($('#redirect-holder').size()) {
- return;
+Drupal.parseJson = function (data) {
+ if ((data.substring(0, 1) != '{') && (data.substring(0, 1) != '[')) {
+ return { status: 0, data: data.length ? data : Drupal.t('Unspecified error') };
}
- // Note: some browsers require the literal name/id attributes on the tag,
- // some want them set through JS. We do both.
- window.iframeHandler = function () {};
- var div = document.createElement('div');
- div.id = 'redirect-holder';
- $(div).html('<iframe name="redirect-target" id="redirect-target" class="redirect" onload="window.iframeHandler();"></iframe>');
- var iframe = div.firstChild;
- $(iframe)
- .attr({
- name: 'redirect-target',
- id: 'redirect-target'
- })
- .css({
- position: 'absolute',
- height: '1px',
- width: '1px',
- visibility: 'hidden'
- });
- $('body').append(div);
-};
-
-/**
- * Delete the invisible iframe
- */
-Drupal.deleteIframe = function () {
- $('#redirect-holder').remove();
+ return eval('(' + data + ');');
};
/**