2005-08-11 13:00:17 +00:00
|
|
|
// $Id$
|
|
|
|
|
2007-07-01 15:37:10 +00:00
|
|
|
var Drupal = Drupal || { 'settings': {}, 'behaviors': {}, 'themes': {}, 'locale': {} };
|
2005-05-24 06:00:22 +00:00
|
|
|
|
2006-08-23 04:59:17 +00:00
|
|
|
/**
|
2006-08-31 23:31:25 +00:00
|
|
|
* Set the variable that indicates if JavaScript behaviors should be applied
|
2006-08-23 04:59:17 +00:00
|
|
|
*/
|
2006-08-31 23:31:25 +00:00
|
|
|
Drupal.jsEnabled = document.getElementsByTagName && document.createElement && document.createTextNode && document.documentElement && document.getElementById;
|
2006-08-22 09:00:31 +00:00
|
|
|
|
2006-08-23 04:59:17 +00:00
|
|
|
/**
|
2006-08-31 23:31:25 +00:00
|
|
|
* Extends the current object with the parameter. Works recursively.
|
2006-08-23 04:59:17 +00:00
|
|
|
*/
|
2006-08-22 09:00:31 +00:00
|
|
|
Drupal.extend = function(obj) {
|
|
|
|
for (var i in obj) {
|
|
|
|
if (this[i]) {
|
|
|
|
Drupal.extend.apply(this[i], [obj[i]]);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this[i] = obj[i];
|
|
|
|
}
|
|
|
|
}
|
2006-10-14 02:39:48 +00:00
|
|
|
};
|
2005-05-24 06:00:22 +00:00
|
|
|
|
2007-07-01 15:37:10 +00:00
|
|
|
/**
|
|
|
|
* Attach all registered behaviors to a page element.
|
|
|
|
*
|
|
|
|
* Behaviors are event-triggered actions that attach to page elements, enhancing
|
|
|
|
* default non-Javascript UIs. Behaviors are registered in the Drupal.behaviors
|
|
|
|
* object as follows:
|
|
|
|
* @code
|
|
|
|
* Drupal.behaviors.behaviorName = function () {
|
|
|
|
* ...
|
|
|
|
* };
|
|
|
|
* @endcode
|
|
|
|
*
|
|
|
|
* Drupal.attachBehaviors is added below to the jQuery ready event and so
|
|
|
|
* runs on initial page load. Developers implementing AHAH/AJAX in their
|
|
|
|
* solutions should also call this function after new page content has been
|
|
|
|
* loaded, feeding in an element to be processed, in order to attach all
|
|
|
|
* behaviors to the new content.
|
|
|
|
*
|
|
|
|
* Behaviors should use a class in the form behaviorName-processed to ensure
|
|
|
|
* the behavior is attached only once to a given element. (Doing so enables
|
|
|
|
* the reprocessing of given elements, which may be needed on occasion despite
|
|
|
|
* the ability to limit behavior attachment to a particular element.)
|
|
|
|
*
|
|
|
|
* @param context
|
|
|
|
* An element to attach behaviors to. If none is given, the document element
|
|
|
|
* is used.
|
|
|
|
*/
|
|
|
|
Drupal.attachBehaviors = function(context) {
|
|
|
|
context = context || document;
|
|
|
|
if (Drupal.jsEnabled) {
|
|
|
|
// Execute all of them.
|
|
|
|
jQuery.each(Drupal.behaviors, function() {
|
|
|
|
this(context);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2007-06-08 12:51:59 +00:00
|
|
|
/**
|
|
|
|
* Encode special characters in a plain-text string for display as HTML.
|
|
|
|
*/
|
|
|
|
Drupal.checkPlain = function(str) {
|
|
|
|
str = String(str);
|
|
|
|
var replace = { '&': '&', '"': '"', '<': '<', '>': '>' };
|
|
|
|
for (var character in replace) {
|
|
|
|
str = str.replace(character, replace[character]);
|
|
|
|
}
|
|
|
|
return str;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Translate strings to the page language or a given language.
|
|
|
|
*
|
|
|
|
* See the documentation of the server-side t() function for further details.
|
|
|
|
*
|
|
|
|
* @param str
|
|
|
|
* A string containing the English string to translate.
|
|
|
|
* @param args
|
|
|
|
* An object of replacements pairs to make after translation. Incidences
|
|
|
|
* of any key in this array are replaced with the corresponding value.
|
|
|
|
* Based on the first character of the key, the value is escaped and/or themed:
|
|
|
|
* - !variable: inserted as is
|
|
|
|
* - @variable: escape plain text to HTML (Drupal.checkPlain)
|
|
|
|
* - %variable: escape text and theme as a placeholder for user-submitted
|
|
|
|
* content (checkPlain + Drupal.theme('placeholder'))
|
|
|
|
* @return
|
|
|
|
* The translated string.
|
|
|
|
*/
|
|
|
|
Drupal.t = function(str, args) {
|
|
|
|
// Fetch the localized version of the string.
|
|
|
|
if (Drupal.locale.strings && Drupal.locale.strings[str]) {
|
|
|
|
str = Drupal.locale.strings[str];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (args) {
|
|
|
|
// Transform arguments before inserting them
|
|
|
|
for (var key in args) {
|
|
|
|
switch (key.charAt(0)) {
|
|
|
|
// Escaped only
|
|
|
|
case '@':
|
|
|
|
args[key] = Drupal.checkPlain(args[key]);
|
|
|
|
break;
|
|
|
|
// Pass-through
|
|
|
|
case '!':
|
|
|
|
break;
|
|
|
|
// Escaped and placeholder
|
|
|
|
case '%':
|
|
|
|
default:
|
|
|
|
args[key] = Drupal.theme('placeholder', args[key]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
str = str.replace(key, args[key]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return str;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Format a string containing a count of items.
|
|
|
|
*
|
|
|
|
* This function ensures that the string is pluralized correctly. Since Drupal.t() is
|
|
|
|
* called by this function, make sure not to pass already-localized strings to it.
|
|
|
|
*
|
|
|
|
* See the documentation of the server-side format_plural() function for further details.
|
|
|
|
*
|
|
|
|
* @param count
|
|
|
|
* The item count to display.
|
|
|
|
* @param singular
|
|
|
|
* The string for the singular case. Please make sure it is clear this is
|
|
|
|
* singular, to ease translation (e.g. use "1 new comment" instead of "1 new").
|
|
|
|
* Do not use @count in the singular string.
|
|
|
|
* @param plural
|
|
|
|
* The string for the plural case. Please make sure it is clear this is plural,
|
|
|
|
* to ease translation. Use @count in place of the item count, as in "@count
|
|
|
|
* new comments".
|
|
|
|
* @param args
|
|
|
|
* An object of replacements pairs to make after translation. Incidences
|
|
|
|
* of any key in this array are replaced with the corresponding value.
|
|
|
|
* Based on the first character of the key, the value is escaped and/or themed:
|
|
|
|
* - !variable: inserted as is
|
|
|
|
* - @variable: escape plain text to HTML (Drupal.checkPlain)
|
|
|
|
* - %variable: escape text and theme as a placeholder for user-submitted
|
|
|
|
* content (checkPlain + Drupal.theme('placeholder'))
|
|
|
|
* Note that you do not need to include @count in this array.
|
|
|
|
* This replacement is done automatically for the plural case.
|
|
|
|
* @return
|
|
|
|
* A translated string.
|
|
|
|
*/
|
|
|
|
Drupal.formatPlural = function(count, singular, plural, args) {
|
|
|
|
var args = ars || {};
|
|
|
|
args['@count'] = count;
|
|
|
|
// Determine the index of the plural form.
|
|
|
|
var index = Drupal.locale.pluralFormula ? Drupal.locale.pluralFormula(args['@count']) : ((args['@count'] == 1) ? 0 : 1);
|
|
|
|
|
|
|
|
if (index == 0) {
|
|
|
|
return Drupal.t(singular, args);
|
|
|
|
}
|
|
|
|
else if (index == 1) {
|
|
|
|
return Drupal.t(plural, args);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
args['@count['+ index +']'] = args['@count'];
|
|
|
|
delete args['@count'];
|
|
|
|
return Drupal.t(plural.replace('@count', '@count['+ index +']'));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generate the themed representation of a Drupal object.
|
|
|
|
*
|
|
|
|
* All requests for themed output must go through this function. It examines
|
|
|
|
* the request and routes it to the appropriate theme function. If the current
|
|
|
|
* theme does not provide an override function, the generic theme function is
|
|
|
|
* called.
|
|
|
|
*
|
|
|
|
* For example, to retrieve the HTML that is output by theme_placeholder(text),
|
|
|
|
* call Drupal.theme('placeholder', text).
|
|
|
|
*
|
|
|
|
* @param func
|
|
|
|
* The name of the theme function to call.
|
|
|
|
* @param ...
|
|
|
|
* Additional arguments to pass along to the theme function.
|
|
|
|
* @return
|
|
|
|
* Any data the theme function returns. This could be a plain HTML string,
|
|
|
|
* but also a complex object.
|
|
|
|
*/
|
|
|
|
Drupal.theme = function(func) {
|
|
|
|
for (var i = 1, args = []; i < arguments.length; i++) {
|
|
|
|
args.push(arguments[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (Drupal.theme[func] || Drupal.theme.prototype[func]).apply(this, args);
|
|
|
|
};
|
|
|
|
|
- Patch #28483 by Steven: JavaScript enabled uploading.
Comment from Steven: It does this by redirecting the submission of the form to a hidden <iframe> when you click "Attach" (we cannot submit data through Ajax directly because you cannot read file contents from JS for security reasons). Once the file is submitted, the upload-section of the form is updated. Things to note:
* The feature degrades back to the current behaviour without JS.
* If there are errors with the uploaded file (disallowed type, too big, ...), they are displayed at the top of the file attachments fieldset.
* Though the hidden-iframe method sounds dirty, it's quite compact and is 100% implemented in .js files. The drupal.js api makes it a snap to use.
* I included some minor improvements to the Drupal JS API and code.
* I added an API drupal_call_js() to bridge the PHP/JS gap: it takes a function name and arguments, and outputs a <script> tag. The kicker is that it preserves the structure and type of arguments, so e.g. PHP associative arrays end up as objects in JS.
* I also included a progressbar widget that I wrote for drumm's ongoing update.php work. It includes Ajax status updating/monitoring, but it is only used as a pure throbber in this patch. But as the code was already written and is going to be used in the near future, I left that part in. It's pretty small ;). If PHP supports ad-hoc upload info in the future like Ruby on Rails, we can implement that in 5 minutes.
2005-08-31 18:37:30 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2006-08-31 23:31:25 +00:00
|
|
|
Drupal.redirectFormButton = function (uri, button, handler) {
|
- Patch #28483 by Steven: JavaScript enabled uploading.
Comment from Steven: It does this by redirecting the submission of the form to a hidden <iframe> when you click "Attach" (we cannot submit data through Ajax directly because you cannot read file contents from JS for security reasons). Once the file is submitted, the upload-section of the form is updated. Things to note:
* The feature degrades back to the current behaviour without JS.
* If there are errors with the uploaded file (disallowed type, too big, ...), they are displayed at the top of the file attachments fieldset.
* Though the hidden-iframe method sounds dirty, it's quite compact and is 100% implemented in .js files. The drupal.js api makes it a snap to use.
* I included some minor improvements to the Drupal JS API and code.
* I added an API drupal_call_js() to bridge the PHP/JS gap: it takes a function name and arguments, and outputs a <script> tag. The kicker is that it preserves the structure and type of arguments, so e.g. PHP associative arrays end up as objects in JS.
* I also included a progressbar widget that I wrote for drumm's ongoing update.php work. It includes Ajax status updating/monitoring, but it is only used as a pure throbber in this patch. But as the code was already written and is going to be used in the near future, I left that part in. It's pretty small ;). If PHP supports ad-hoc upload info in the future like Ruby on Rails, we can implement that in 5 minutes.
2005-08-31 18:37:30 +00:00
|
|
|
// Trap the button
|
2005-12-21 17:29:08 +00:00
|
|
|
button.onmouseover = button.onfocus = function() {
|
- Patch #28483 by Steven: JavaScript enabled uploading.
Comment from Steven: It does this by redirecting the submission of the form to a hidden <iframe> when you click "Attach" (we cannot submit data through Ajax directly because you cannot read file contents from JS for security reasons). Once the file is submitted, the upload-section of the form is updated. Things to note:
* The feature degrades back to the current behaviour without JS.
* If there are errors with the uploaded file (disallowed type, too big, ...), they are displayed at the top of the file attachments fieldset.
* Though the hidden-iframe method sounds dirty, it's quite compact and is 100% implemented in .js files. The drupal.js api makes it a snap to use.
* I included some minor improvements to the Drupal JS API and code.
* I added an API drupal_call_js() to bridge the PHP/JS gap: it takes a function name and arguments, and outputs a <script> tag. The kicker is that it preserves the structure and type of arguments, so e.g. PHP associative arrays end up as objects in JS.
* I also included a progressbar widget that I wrote for drumm's ongoing update.php work. It includes Ajax status updating/monitoring, but it is only used as a pure throbber in this patch. But as the code was already written and is going to be used in the near future, I left that part in. It's pretty small ;). If PHP supports ad-hoc upload info in the future like Ruby on Rails, we can implement that in 5 minutes.
2005-08-31 18:37:30 +00:00
|
|
|
button.onclick = function() {
|
2006-08-31 23:31:25 +00:00
|
|
|
// Create target iframe
|
|
|
|
Drupal.createIframe();
|
|
|
|
|
2005-10-22 15:14:46 +00:00
|
|
|
// Prepare variables for use in anonymous function.
|
- Patch #28483 by Steven: JavaScript enabled uploading.
Comment from Steven: It does this by redirecting the submission of the form to a hidden <iframe> when you click "Attach" (we cannot submit data through Ajax directly because you cannot read file contents from JS for security reasons). Once the file is submitted, the upload-section of the form is updated. Things to note:
* The feature degrades back to the current behaviour without JS.
* If there are errors with the uploaded file (disallowed type, too big, ...), they are displayed at the top of the file attachments fieldset.
* Though the hidden-iframe method sounds dirty, it's quite compact and is 100% implemented in .js files. The drupal.js api makes it a snap to use.
* I included some minor improvements to the Drupal JS API and code.
* I added an API drupal_call_js() to bridge the PHP/JS gap: it takes a function name and arguments, and outputs a <script> tag. The kicker is that it preserves the structure and type of arguments, so e.g. PHP associative arrays end up as objects in JS.
* I also included a progressbar widget that I wrote for drumm's ongoing update.php work. It includes Ajax status updating/monitoring, but it is only used as a pure throbber in this patch. But as the code was already written and is going to be used in the near future, I left that part in. It's pretty small ;). If PHP supports ad-hoc upload info in the future like Ruby on Rails, we can implement that in 5 minutes.
2005-08-31 18:37:30 +00:00
|
|
|
var button = this;
|
|
|
|
var action = button.form.action;
|
|
|
|
var target = button.form.target;
|
2005-09-07 13:49:39 +00:00
|
|
|
|
2006-08-31 23:31:25 +00:00
|
|
|
// Redirect form submission to iframe
|
- Patch #28483 by Steven: JavaScript enabled uploading.
Comment from Steven: It does this by redirecting the submission of the form to a hidden <iframe> when you click "Attach" (we cannot submit data through Ajax directly because you cannot read file contents from JS for security reasons). Once the file is submitted, the upload-section of the form is updated. Things to note:
* The feature degrades back to the current behaviour without JS.
* If there are errors with the uploaded file (disallowed type, too big, ...), they are displayed at the top of the file attachments fieldset.
* Though the hidden-iframe method sounds dirty, it's quite compact and is 100% implemented in .js files. The drupal.js api makes it a snap to use.
* I included some minor improvements to the Drupal JS API and code.
* I added an API drupal_call_js() to bridge the PHP/JS gap: it takes a function name and arguments, and outputs a <script> tag. The kicker is that it preserves the structure and type of arguments, so e.g. PHP associative arrays end up as objects in JS.
* I also included a progressbar widget that I wrote for drumm's ongoing update.php work. It includes Ajax status updating/monitoring, but it is only used as a pure throbber in this patch. But as the code was already written and is going to be used in the near future, I left that part in. It's pretty small ;). If PHP supports ad-hoc upload info in the future like Ruby on Rails, we can implement that in 5 minutes.
2005-08-31 18:37:30 +00:00
|
|
|
this.form.action = uri;
|
|
|
|
this.form.target = 'redirect-target';
|
2005-09-07 13:49:39 +00:00
|
|
|
|
- Patch #28483 by Steven: JavaScript enabled uploading.
Comment from Steven: It does this by redirecting the submission of the form to a hidden <iframe> when you click "Attach" (we cannot submit data through Ajax directly because you cannot read file contents from JS for security reasons). Once the file is submitted, the upload-section of the form is updated. Things to note:
* The feature degrades back to the current behaviour without JS.
* If there are errors with the uploaded file (disallowed type, too big, ...), they are displayed at the top of the file attachments fieldset.
* Though the hidden-iframe method sounds dirty, it's quite compact and is 100% implemented in .js files. The drupal.js api makes it a snap to use.
* I included some minor improvements to the Drupal JS API and code.
* I added an API drupal_call_js() to bridge the PHP/JS gap: it takes a function name and arguments, and outputs a <script> tag. The kicker is that it preserves the structure and type of arguments, so e.g. PHP associative arrays end up as objects in JS.
* I also included a progressbar widget that I wrote for drumm's ongoing update.php work. It includes Ajax status updating/monitoring, but it is only used as a pure throbber in this patch. But as the code was already written and is going to be used in the near future, I left that part in. It's pretty small ;). If PHP supports ad-hoc upload info in the future like Ruby on Rails, we can implement that in 5 minutes.
2005-08-31 18:37:30 +00:00
|
|
|
handler.onsubmit();
|
2005-09-07 13:49:39 +00:00
|
|
|
|
- Patch #28483 by Steven: JavaScript enabled uploading.
Comment from Steven: It does this by redirecting the submission of the form to a hidden <iframe> when you click "Attach" (we cannot submit data through Ajax directly because you cannot read file contents from JS for security reasons). Once the file is submitted, the upload-section of the form is updated. Things to note:
* The feature degrades back to the current behaviour without JS.
* If there are errors with the uploaded file (disallowed type, too big, ...), they are displayed at the top of the file attachments fieldset.
* Though the hidden-iframe method sounds dirty, it's quite compact and is 100% implemented in .js files. The drupal.js api makes it a snap to use.
* I included some minor improvements to the Drupal JS API and code.
* I added an API drupal_call_js() to bridge the PHP/JS gap: it takes a function name and arguments, and outputs a <script> tag. The kicker is that it preserves the structure and type of arguments, so e.g. PHP associative arrays end up as objects in JS.
* I also included a progressbar widget that I wrote for drumm's ongoing update.php work. It includes Ajax status updating/monitoring, but it is only used as a pure throbber in this patch. But as the code was already written and is going to be used in the near future, I left that part in. It's pretty small ;). If PHP supports ad-hoc upload info in the future like Ruby on Rails, we can implement that in 5 minutes.
2005-08-31 18:37:30 +00:00
|
|
|
// Set iframe handler for later
|
2006-02-05 19:04:58 +00:00
|
|
|
window.iframeHandler = function () {
|
2006-08-31 23:31:25 +00:00
|
|
|
var iframe = $('#redirect-target').get(0);
|
- Patch #28483 by Steven: JavaScript enabled uploading.
Comment from Steven: It does this by redirecting the submission of the form to a hidden <iframe> when you click "Attach" (we cannot submit data through Ajax directly because you cannot read file contents from JS for security reasons). Once the file is submitted, the upload-section of the form is updated. Things to note:
* The feature degrades back to the current behaviour without JS.
* If there are errors with the uploaded file (disallowed type, too big, ...), they are displayed at the top of the file attachments fieldset.
* Though the hidden-iframe method sounds dirty, it's quite compact and is 100% implemented in .js files. The drupal.js api makes it a snap to use.
* I included some minor improvements to the Drupal JS API and code.
* I added an API drupal_call_js() to bridge the PHP/JS gap: it takes a function name and arguments, and outputs a <script> tag. The kicker is that it preserves the structure and type of arguments, so e.g. PHP associative arrays end up as objects in JS.
* I also included a progressbar widget that I wrote for drumm's ongoing update.php work. It includes Ajax status updating/monitoring, but it is only used as a pure throbber in this patch. But as the code was already written and is going to be used in the near future, I left that part in. It's pretty small ;). If PHP supports ad-hoc upload info in the future like Ruby on Rails, we can implement that in 5 minutes.
2005-08-31 18:37:30 +00:00
|
|
|
// Restore form submission
|
|
|
|
button.form.action = action;
|
|
|
|
button.form.target = target;
|
2007-06-04 07:22:23 +00:00
|
|
|
|
2006-02-05 19:04:58 +00:00
|
|
|
// Get response from iframe body
|
|
|
|
try {
|
|
|
|
response = (iframe.contentWindow || iframe.contentDocument || iframe).document.body.innerHTML;
|
2006-04-27 18:12:25 +00:00
|
|
|
// Firefox 1.0.x hack: Remove (corrupted) control characters
|
|
|
|
response = response.replace(/[\f\n\r\t]/g, ' ');
|
2006-02-05 19:04:58 +00:00
|
|
|
if (window.opera) {
|
|
|
|
// Opera-hack: it returns innerHTML sanitized.
|
|
|
|
response = response.replace(/"/g, '"');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
response = null;
|
|
|
|
}
|
2007-06-04 07:22:23 +00:00
|
|
|
|
2006-08-31 23:31:25 +00:00
|
|
|
response = Drupal.parseJson(response);
|
2006-02-05 19:04:58 +00:00
|
|
|
// Check response code
|
|
|
|
if (response.status == 0) {
|
|
|
|
handler.onerror(response.data);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
handler.oncomplete(response.data);
|
2006-08-31 23:31:25 +00:00
|
|
|
|
|
|
|
return true;
|
2007-06-01 09:05:45 +00:00
|
|
|
};
|
2005-09-07 13:49:39 +00:00
|
|
|
|
|
|
|
return true;
|
2007-06-01 09:05:45 +00:00
|
|
|
};
|
|
|
|
};
|
2005-12-21 17:29:08 +00:00
|
|
|
button.onmouseout = button.onblur = function() {
|
- Patch #28483 by Steven: JavaScript enabled uploading.
Comment from Steven: It does this by redirecting the submission of the form to a hidden <iframe> when you click "Attach" (we cannot submit data through Ajax directly because you cannot read file contents from JS for security reasons). Once the file is submitted, the upload-section of the form is updated. Things to note:
* The feature degrades back to the current behaviour without JS.
* If there are errors with the uploaded file (disallowed type, too big, ...), they are displayed at the top of the file attachments fieldset.
* Though the hidden-iframe method sounds dirty, it's quite compact and is 100% implemented in .js files. The drupal.js api makes it a snap to use.
* I included some minor improvements to the Drupal JS API and code.
* I added an API drupal_call_js() to bridge the PHP/JS gap: it takes a function name and arguments, and outputs a <script> tag. The kicker is that it preserves the structure and type of arguments, so e.g. PHP associative arrays end up as objects in JS.
* I also included a progressbar widget that I wrote for drumm's ongoing update.php work. It includes Ajax status updating/monitoring, but it is only used as a pure throbber in this patch. But as the code was already written and is going to be used in the near future, I left that part in. It's pretty small ;). If PHP supports ad-hoc upload info in the future like Ruby on Rails, we can implement that in 5 minutes.
2005-08-31 18:37:30 +00:00
|
|
|
button.onclick = null;
|
2007-06-01 09:05:45 +00:00
|
|
|
};
|
2006-10-14 02:39:48 +00:00
|
|
|
};
|
- Patch #28483 by Steven: JavaScript enabled uploading.
Comment from Steven: It does this by redirecting the submission of the form to a hidden <iframe> when you click "Attach" (we cannot submit data through Ajax directly because you cannot read file contents from JS for security reasons). Once the file is submitted, the upload-section of the form is updated. Things to note:
* The feature degrades back to the current behaviour without JS.
* If there are errors with the uploaded file (disallowed type, too big, ...), they are displayed at the top of the file attachments fieldset.
* Though the hidden-iframe method sounds dirty, it's quite compact and is 100% implemented in .js files. The drupal.js api makes it a snap to use.
* I included some minor improvements to the Drupal JS API and code.
* I added an API drupal_call_js() to bridge the PHP/JS gap: it takes a function name and arguments, and outputs a <script> tag. The kicker is that it preserves the structure and type of arguments, so e.g. PHP associative arrays end up as objects in JS.
* I also included a progressbar widget that I wrote for drumm's ongoing update.php work. It includes Ajax status updating/monitoring, but it is only used as a pure throbber in this patch. But as the code was already written and is going to be used in the near future, I left that part in. It's pretty small ;). If PHP supports ad-hoc upload info in the future like Ruby on Rails, we can implement that in 5 minutes.
2005-08-31 18:37:30 +00:00
|
|
|
|
2005-05-24 06:00:22 +00:00
|
|
|
/**
|
|
|
|
* Retrieves the absolute position of an element on the screen
|
|
|
|
*/
|
2006-08-31 23:31:25 +00:00
|
|
|
Drupal.absolutePosition = function (el) {
|
2005-05-24 06:00:22 +00:00
|
|
|
var sLeft = 0, sTop = 0;
|
|
|
|
var isDiv = /^div$/i.test(el.tagName);
|
|
|
|
if (isDiv && el.scrollLeft) {
|
|
|
|
sLeft = el.scrollLeft;
|
|
|
|
}
|
|
|
|
if (isDiv && el.scrollTop) {
|
|
|
|
sTop = el.scrollTop;
|
|
|
|
}
|
|
|
|
var r = { x: el.offsetLeft - sLeft, y: el.offsetTop - sTop };
|
|
|
|
if (el.offsetParent) {
|
2006-08-31 23:31:25 +00:00
|
|
|
var tmp = Drupal.absolutePosition(el.offsetParent);
|
2005-05-24 06:00:22 +00:00
|
|
|
r.x += tmp.x;
|
|
|
|
r.y += tmp.y;
|
|
|
|
}
|
|
|
|
return r;
|
2006-10-14 02:39:48 +00:00
|
|
|
};
|
2005-12-29 03:59:30 +00:00
|
|
|
|
2005-05-24 06:00:22 +00:00
|
|
|
/**
|
2006-08-31 23:31:25 +00:00
|
|
|
* Return the dimensions of an element on the screen
|
2005-05-24 06:00:22 +00:00
|
|
|
*/
|
2006-08-31 23:31:25 +00:00
|
|
|
Drupal.dimensions = function (el) {
|
|
|
|
return { width: el.offsetWidth, height: el.offsetHeight };
|
2006-10-14 02:39:48 +00:00
|
|
|
};
|
- Patch #28483 by Steven: JavaScript enabled uploading.
Comment from Steven: It does this by redirecting the submission of the form to a hidden <iframe> when you click "Attach" (we cannot submit data through Ajax directly because you cannot read file contents from JS for security reasons). Once the file is submitted, the upload-section of the form is updated. Things to note:
* The feature degrades back to the current behaviour without JS.
* If there are errors with the uploaded file (disallowed type, too big, ...), they are displayed at the top of the file attachments fieldset.
* Though the hidden-iframe method sounds dirty, it's quite compact and is 100% implemented in .js files. The drupal.js api makes it a snap to use.
* I included some minor improvements to the Drupal JS API and code.
* I added an API drupal_call_js() to bridge the PHP/JS gap: it takes a function name and arguments, and outputs a <script> tag. The kicker is that it preserves the structure and type of arguments, so e.g. PHP associative arrays end up as objects in JS.
* I also included a progressbar widget that I wrote for drumm's ongoing update.php work. It includes Ajax status updating/monitoring, but it is only used as a pure throbber in this patch. But as the code was already written and is going to be used in the near future, I left that part in. It's pretty small ;). If PHP supports ad-hoc upload info in the future like Ruby on Rails, we can implement that in 5 minutes.
2005-08-31 18:37:30 +00:00
|
|
|
|
2005-12-29 03:59:30 +00:00
|
|
|
/**
|
2006-08-31 23:31:25 +00:00
|
|
|
* Returns the position of the mouse cursor based on the event object passed
|
2005-12-29 03:59:30 +00:00
|
|
|
*/
|
2006-08-31 23:31:25 +00:00
|
|
|
Drupal.mousePosition = function(e) {
|
|
|
|
return { x: e.clientX + document.documentElement.scrollLeft, y: e.clientY + document.documentElement.scrollTop };
|
2006-10-14 02:39:48 +00:00
|
|
|
};
|
2005-12-29 03:59:30 +00:00
|
|
|
|
2006-02-05 19:04:58 +00:00
|
|
|
/**
|
|
|
|
* Parse a JSON response.
|
|
|
|
*
|
|
|
|
* The result is either the JSON object, or an object with 'status' 0 and 'data' an error message.
|
|
|
|
*/
|
2006-08-31 23:31:25 +00:00
|
|
|
Drupal.parseJson = function (data) {
|
2006-06-07 09:34:11 +00:00
|
|
|
if ((data.substring(0, 1) != '{') && (data.substring(0, 1) != '[')) {
|
2007-06-08 12:51:59 +00:00
|
|
|
return { status: 0, data: data.length ? data : Drupal.t('Unspecified error') };
|
2006-02-05 19:04:58 +00:00
|
|
|
}
|
|
|
|
return eval('(' + data + ');');
|
2006-10-14 02:39:48 +00:00
|
|
|
};
|
2006-02-05 19:04:58 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create an invisible iframe for form submissions.
|
|
|
|
*/
|
2006-08-31 23:31:25 +00:00
|
|
|
Drupal.createIframe = function () {
|
|
|
|
if ($('#redirect-holder').size()) {
|
|
|
|
return;
|
|
|
|
}
|
2006-02-05 19:04:58 +00:00
|
|
|
// 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';
|
2006-08-31 23:31:25 +00:00
|
|
|
$(div).html('<iframe name="redirect-target" id="redirect-target" class="redirect" onload="window.iframeHandler();"></iframe>');
|
2006-02-05 19:04:58 +00:00
|
|
|
var iframe = div.firstChild;
|
2006-08-31 23:31:25 +00:00
|
|
|
$(iframe)
|
|
|
|
.attr({
|
|
|
|
name: 'redirect-target',
|
|
|
|
id: 'redirect-target'
|
|
|
|
})
|
|
|
|
.css({
|
|
|
|
position: 'absolute',
|
|
|
|
height: '1px',
|
|
|
|
width: '1px',
|
|
|
|
visibility: 'hidden'
|
|
|
|
});
|
|
|
|
$('body').append(div);
|
2006-10-14 02:39:48 +00:00
|
|
|
};
|
2006-02-05 19:04:58 +00:00
|
|
|
|
|
|
|
/**
|
2006-08-31 23:31:25 +00:00
|
|
|
* Delete the invisible iframe
|
2006-02-05 19:04:58 +00:00
|
|
|
*/
|
2006-08-31 23:31:25 +00:00
|
|
|
Drupal.deleteIframe = function () {
|
|
|
|
$('#redirect-holder').remove();
|
2006-10-14 02:39:48 +00:00
|
|
|
};
|
2006-08-31 23:31:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Freeze the current body height (as minimum height). Used to prevent
|
|
|
|
* unnecessary upwards scrolling when doing DOM manipulations.
|
|
|
|
*/
|
|
|
|
Drupal.freezeHeight = function () {
|
|
|
|
Drupal.unfreezeHeight();
|
|
|
|
var div = document.createElement('div');
|
|
|
|
$(div).css({
|
|
|
|
position: 'absolute',
|
|
|
|
top: '0px',
|
|
|
|
left: '0px',
|
|
|
|
width: '1px',
|
|
|
|
height: $('body').css('height')
|
|
|
|
}).attr('id', 'freeze-height');
|
|
|
|
$('body').append(div);
|
2006-10-14 02:39:48 +00:00
|
|
|
};
|
2006-08-31 23:31:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Unfreeze the body height
|
|
|
|
*/
|
|
|
|
Drupal.unfreezeHeight = function () {
|
|
|
|
$('#freeze-height').remove();
|
2006-10-14 02:39:48 +00:00
|
|
|
};
|
2006-02-05 19:04:58 +00:00
|
|
|
|
- Patch #28483 by Steven: JavaScript enabled uploading.
Comment from Steven: It does this by redirecting the submission of the form to a hidden <iframe> when you click "Attach" (we cannot submit data through Ajax directly because you cannot read file contents from JS for security reasons). Once the file is submitted, the upload-section of the form is updated. Things to note:
* The feature degrades back to the current behaviour without JS.
* If there are errors with the uploaded file (disallowed type, too big, ...), they are displayed at the top of the file attachments fieldset.
* Though the hidden-iframe method sounds dirty, it's quite compact and is 100% implemented in .js files. The drupal.js api makes it a snap to use.
* I included some minor improvements to the Drupal JS API and code.
* I added an API drupal_call_js() to bridge the PHP/JS gap: it takes a function name and arguments, and outputs a <script> tag. The kicker is that it preserves the structure and type of arguments, so e.g. PHP associative arrays end up as objects in JS.
* I also included a progressbar widget that I wrote for drumm's ongoing update.php work. It includes Ajax status updating/monitoring, but it is only used as a pure throbber in this patch. But as the code was already written and is going to be used in the near future, I left that part in. It's pretty small ;). If PHP supports ad-hoc upload info in the future like Ruby on Rails, we can implement that in 5 minutes.
2005-08-31 18:37:30 +00:00
|
|
|
/**
|
2006-08-31 23:31:25 +00:00
|
|
|
* Wrapper to address the mod_rewrite url encoding bug
|
|
|
|
* (equivalent of drupal_urlencode() in PHP).
|
- Patch #28483 by Steven: JavaScript enabled uploading.
Comment from Steven: It does this by redirecting the submission of the form to a hidden <iframe> when you click "Attach" (we cannot submit data through Ajax directly because you cannot read file contents from JS for security reasons). Once the file is submitted, the upload-section of the form is updated. Things to note:
* The feature degrades back to the current behaviour without JS.
* If there are errors with the uploaded file (disallowed type, too big, ...), they are displayed at the top of the file attachments fieldset.
* Though the hidden-iframe method sounds dirty, it's quite compact and is 100% implemented in .js files. The drupal.js api makes it a snap to use.
* I included some minor improvements to the Drupal JS API and code.
* I added an API drupal_call_js() to bridge the PHP/JS gap: it takes a function name and arguments, and outputs a <script> tag. The kicker is that it preserves the structure and type of arguments, so e.g. PHP associative arrays end up as objects in JS.
* I also included a progressbar widget that I wrote for drumm's ongoing update.php work. It includes Ajax status updating/monitoring, but it is only used as a pure throbber in this patch. But as the code was already written and is going to be used in the near future, I left that part in. It's pretty small ;). If PHP supports ad-hoc upload info in the future like Ruby on Rails, we can implement that in 5 minutes.
2005-08-31 18:37:30 +00:00
|
|
|
*/
|
2006-08-31 23:31:25 +00:00
|
|
|
Drupal.encodeURIComponent = function (item, uri) {
|
|
|
|
uri = uri || location.href;
|
2007-07-13 20:07:15 +00:00
|
|
|
item = encodeURIComponent(item).replace(/%2F/g, '/');
|
|
|
|
return (uri.indexOf('?q=') != -1) ? item : item.replace(/%26/g, '%2526').replace(/%23/g, '%2523').replace(/\/\//g, '/%252F');
|
2006-10-14 02:39:48 +00:00
|
|
|
};
|
2006-08-31 23:31:25 +00:00
|
|
|
|
2007-04-09 13:58:03 +00:00
|
|
|
/**
|
|
|
|
* Get the text selection in a textarea.
|
|
|
|
*/
|
|
|
|
Drupal.getSelection = function (element) {
|
|
|
|
if (typeof(element.selectionStart) != 'number' && document.selection) {
|
|
|
|
// The current selection
|
|
|
|
var range1 = document.selection.createRange();
|
|
|
|
var range2 = range1.duplicate();
|
|
|
|
// Select all text.
|
|
|
|
range2.moveToElementText(element);
|
|
|
|
// Now move 'dummy' end point to end point of original range.
|
|
|
|
range2.setEndPoint('EndToEnd', range1);
|
|
|
|
// Now we can calculate start and end points.
|
|
|
|
var start = range2.text.length - range1.text.length;
|
|
|
|
var end = start + range1.text.length;
|
|
|
|
return { 'start': start, 'end': end };
|
|
|
|
}
|
|
|
|
return { 'start': element.selectionStart, 'end': element.selectionEnd };
|
2007-06-01 09:05:45 +00:00
|
|
|
};
|
2007-04-09 13:58:03 +00:00
|
|
|
|
2006-08-31 23:31:25 +00:00
|
|
|
// Global Killswitch on the <html> element
|
|
|
|
if (Drupal.jsEnabled) {
|
2007-05-04 09:41:37 +00:00
|
|
|
// Global Killswitch on the <html> element
|
2006-08-31 23:31:25 +00:00
|
|
|
document.documentElement.className = 'js';
|
2007-05-04 09:41:37 +00:00
|
|
|
// 'js enabled' cookie
|
|
|
|
document.cookie = 'has_js=1';
|
2007-07-01 15:37:10 +00:00
|
|
|
// Attach all behaviors.
|
|
|
|
$(document).ready(Drupal.attachBehaviors);
|
- Patch #28483 by Steven: JavaScript enabled uploading.
Comment from Steven: It does this by redirecting the submission of the form to a hidden <iframe> when you click "Attach" (we cannot submit data through Ajax directly because you cannot read file contents from JS for security reasons). Once the file is submitted, the upload-section of the form is updated. Things to note:
* The feature degrades back to the current behaviour without JS.
* If there are errors with the uploaded file (disallowed type, too big, ...), they are displayed at the top of the file attachments fieldset.
* Though the hidden-iframe method sounds dirty, it's quite compact and is 100% implemented in .js files. The drupal.js api makes it a snap to use.
* I included some minor improvements to the Drupal JS API and code.
* I added an API drupal_call_js() to bridge the PHP/JS gap: it takes a function name and arguments, and outputs a <script> tag. The kicker is that it preserves the structure and type of arguments, so e.g. PHP associative arrays end up as objects in JS.
* I also included a progressbar widget that I wrote for drumm's ongoing update.php work. It includes Ajax status updating/monitoring, but it is only used as a pure throbber in this patch. But as the code was already written and is going to be used in the near future, I left that part in. It's pretty small ;). If PHP supports ad-hoc upload info in the future like Ruby on Rails, we can implement that in 5 minutes.
2005-08-31 18:37:30 +00:00
|
|
|
}
|
2007-06-08 12:51:59 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The default themes.
|
|
|
|
*/
|
|
|
|
Drupal.theme.prototype = {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Formats text for emphasized display in a placeholder inside a sentence.
|
|
|
|
*
|
|
|
|
* @param str
|
|
|
|
* The text to format (plain-text).
|
|
|
|
* @return
|
|
|
|
* The formatted text (html).
|
|
|
|
*/
|
|
|
|
placeholder: function(str) {
|
|
|
|
return '<em>' + Drupal.checkPlain(str) + '</em>';
|
|
|
|
}
|
|
|
|
};
|