2005-08-11 13:00:17 +00:00
|
|
|
// $Id$
|
|
|
|
|
2005-05-24 06:00:22 +00:00
|
|
|
/**
|
|
|
|
* Only enable Javascript functionality if all required features are supported.
|
|
|
|
*/
|
|
|
|
function isJsEnabled() {
|
2005-06-01 17:43:33 +00:00
|
|
|
if (typeof document.jsEnabled == 'undefined') {
|
2005-05-24 06:00:22 +00:00
|
|
|
// Note: ! casts to boolean implicitly.
|
|
|
|
document.jsEnabled = !(
|
|
|
|
!document.getElementsByTagName ||
|
|
|
|
!document.createElement ||
|
|
|
|
!document.createTextNode ||
|
2005-06-21 09:45:45 +00:00
|
|
|
!document.documentElement ||
|
2005-05-24 06:00:22 +00:00
|
|
|
!document.getElementById);
|
|
|
|
}
|
|
|
|
return document.jsEnabled;
|
|
|
|
}
|
|
|
|
|
2005-12-02 21:28:18 +00:00
|
|
|
// Global Killswitch on the <html> element
|
2005-05-24 06:00:22 +00:00
|
|
|
if (isJsEnabled()) {
|
2005-06-21 09:45:45 +00:00
|
|
|
document.documentElement.className = 'js';
|
2005-05-24 06:00:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Make IE's XMLHTTP object accessible through XMLHttpRequest()
|
|
|
|
*/
|
|
|
|
if (typeof XMLHttpRequest == 'undefined') {
|
2005-07-18 12:56:45 +00:00
|
|
|
XMLHttpRequest = function () {
|
|
|
|
var msxmls = ['MSXML3', 'MSXML2', 'Microsoft']
|
|
|
|
for (var i=0; i < msxmls.length; i++) {
|
|
|
|
try {
|
|
|
|
return new ActiveXObject(msxmls[i]+'.XMLHTTP')
|
|
|
|
}
|
|
|
|
catch (e) { }
|
|
|
|
}
|
2005-08-18 05:14:06 +00:00
|
|
|
throw new Error("No XML component installed!");
|
2005-07-18 12:56:45 +00:00
|
|
|
}
|
2005-05-24 06:00:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2005-12-02 21:28:18 +00:00
|
|
|
* Creates an HTTP GET request and sends the response to the callback function
|
2005-05-24 06:00:22 +00:00
|
|
|
*/
|
|
|
|
function HTTPGet(uri, callbackFunction, callbackParameter) {
|
|
|
|
var xmlHttp = new XMLHttpRequest();
|
|
|
|
var bAsync = true;
|
2005-07-18 12:56:45 +00:00
|
|
|
if (!callbackFunction) {
|
2005-05-24 06:00:22 +00:00
|
|
|
bAsync = false;
|
2005-07-18 12:56:45 +00:00
|
|
|
}
|
2005-05-24 06:00:22 +00:00
|
|
|
xmlHttp.open('GET', uri, bAsync);
|
|
|
|
xmlHttp.send(null);
|
|
|
|
|
|
|
|
if (bAsync) {
|
|
|
|
if (callbackFunction) {
|
|
|
|
xmlHttp.onreadystatechange = function() {
|
2005-07-18 12:56:45 +00:00
|
|
|
if (xmlHttp.readyState == 4) {
|
|
|
|
callbackFunction(xmlHttp.responseText, xmlHttp, callbackParameter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return xmlHttp.responseText;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates an HTTP POST request and sends the response to the callback function
|
2005-12-21 15:03:32 +00:00
|
|
|
*
|
|
|
|
* Note: passing null or undefined for 'object' makes the request fail in Opera 8.
|
|
|
|
* Pass an empty string instead.
|
2005-07-18 12:56:45 +00:00
|
|
|
*/
|
2005-12-06 09:25:22 +00:00
|
|
|
function HTTPPost(uri, callbackFunction, callbackParameter, object) {
|
2005-07-18 12:56:45 +00:00
|
|
|
var xmlHttp = new XMLHttpRequest();
|
|
|
|
var bAsync = true;
|
|
|
|
if (!callbackFunction) {
|
|
|
|
bAsync = false;
|
|
|
|
}
|
|
|
|
xmlHttp.open('POST', uri, bAsync);
|
|
|
|
|
|
|
|
var toSend = '';
|
|
|
|
if (typeof object == 'object') {
|
|
|
|
xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
|
|
|
|
for (var i in object)
|
|
|
|
toSend += (toSend ? '&' : '') + i + '=' + escape(object[i]);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
toSend = object;
|
|
|
|
}
|
|
|
|
xmlHttp.send(toSend);
|
|
|
|
|
|
|
|
if (bAsync) {
|
|
|
|
if (callbackFunction) {
|
|
|
|
xmlHttp.onreadystatechange = function() {
|
|
|
|
if (xmlHttp.readyState == 4) {
|
|
|
|
callbackFunction(xmlHttp.responseText, xmlHttp, callbackParameter);
|
|
|
|
}
|
2005-05-24 06:00:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return xmlHttp.responseText;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
- 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.
|
|
|
|
*/
|
|
|
|
function redirectFormButton(uri, button, handler) {
|
|
|
|
// Insert the iframe
|
2005-12-21 17:29:08 +00:00
|
|
|
// Note: some browsers require the literal name/id attributes on the tag,
|
|
|
|
// some want them set through JS. We do both.
|
|
|
|
var div = document.createElement('div');
|
|
|
|
div.innerHTML = '<iframe name="redirect-target" id="redirect-target" class="redirect"></iframe>';
|
|
|
|
var iframe = div.firstChild;
|
2005-09-07 13:49:39 +00:00
|
|
|
with (iframe) {
|
|
|
|
name = 'redirect-target';
|
|
|
|
setAttribute('name', 'redirect-target');
|
|
|
|
id = 'redirect-target';
|
|
|
|
}
|
|
|
|
with (iframe.style) {
|
|
|
|
position = 'absolute';
|
|
|
|
height = '1px';
|
|
|
|
width = '1px';
|
|
|
|
visibility = 'hidden';
|
|
|
|
}
|
|
|
|
document.body.appendChild(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
|
|
|
|
|
|
|
// 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() {
|
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
|
|
|
|
- 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
|
|
|
// Redirect form submission
|
|
|
|
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
|
|
|
|
window.iframeHandler = function (data) {
|
|
|
|
// Restore form submission
|
|
|
|
button.form.action = action;
|
|
|
|
button.form.target = target;
|
|
|
|
handler.oncomplete(data);
|
|
|
|
}
|
2005-09-07 13:49:39 +00:00
|
|
|
|
|
|
|
return true;
|
- 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-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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-05-24 06:00:22 +00:00
|
|
|
/**
|
|
|
|
* Adds a function to the window onload event
|
|
|
|
*/
|
|
|
|
function addLoadEvent(func) {
|
|
|
|
var oldOnload = window.onload;
|
|
|
|
if (typeof window.onload != 'function') {
|
|
|
|
window.onload = func;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
window.onload = function() {
|
|
|
|
oldOnload();
|
|
|
|
func();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
- 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-02 21:28:18 +00:00
|
|
|
* Adds a function to a given form's submit event
|
- 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
|
|
|
*/
|
|
|
|
function addSubmitEvent(form, func) {
|
|
|
|
var oldSubmit = form.onsubmit;
|
|
|
|
if (typeof oldSubmit != 'function') {
|
|
|
|
form.onsubmit = func;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
form.onsubmit = function() {
|
|
|
|
return oldSubmit() && func();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-05-24 06:00:22 +00:00
|
|
|
/**
|
|
|
|
* Retrieves the absolute position of an element on the screen
|
|
|
|
*/
|
|
|
|
function absolutePosition(el) {
|
|
|
|
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) {
|
|
|
|
var tmp = absolutePosition(el.offsetParent);
|
|
|
|
r.x += tmp.x;
|
|
|
|
r.y += tmp.y;
|
|
|
|
}
|
|
|
|
return r;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if an element has a specified class name
|
|
|
|
*/
|
|
|
|
function hasClass(node, className) {
|
|
|
|
if (node.className == className) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
var reg = new RegExp('(^| )'+ className +'($| )')
|
|
|
|
if (reg.test(node.className)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a class name to an element
|
|
|
|
*/
|
|
|
|
function addClass(node, className) {
|
|
|
|
if (hasClass(node, className)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
node.className += ' '+ className;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes a class name from an element
|
|
|
|
*/
|
|
|
|
function removeClass(node, className) {
|
|
|
|
if (!hasClass(node, className)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
node.className = eregReplace('(^| )'+ className +'($| )', '', node.className);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Toggles a class name on or off for an element
|
|
|
|
*/
|
|
|
|
function toggleClass(node, className) {
|
|
|
|
if (!removeClass(node, className) && !addClass(node, className)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Emulate PHP's ereg_replace function in javascript
|
|
|
|
*/
|
|
|
|
function eregReplace(search, replace, subject) {
|
|
|
|
return subject.replace(new RegExp(search,'g'), replace);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes an element from the page
|
|
|
|
*/
|
|
|
|
function removeNode(node) {
|
|
|
|
if (typeof node == 'string') {
|
- 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
|
|
|
node = $(node);
|
2005-05-24 06:00:22 +00:00
|
|
|
}
|
|
|
|
if (node && node.parentNode) {
|
|
|
|
return node.parentNode.removeChild(node);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return false;
|
|
|
|
}
|
2005-08-11 13:00:17 +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
|
|
|
|
|
|
|
/**
|
|
|
|
* Wrapper around document.getElementById().
|
|
|
|
*/
|
|
|
|
function $(id) {
|
|
|
|
return document.getElementById(id);
|
|
|
|
}
|