#174708 by multiple contributors: update jQuery to 1.2

6.x
Gábor Hojtsy 2007-09-12 18:29:32 +00:00
parent b3fe5b9cbf
commit 21ac9f1917
21 changed files with 59 additions and 223 deletions

View File

@ -1813,7 +1813,7 @@ function drupal_get_js($scope = 'header', $javascript = NULL) {
switch ($type) { switch ($type) {
case 'setting': case 'setting':
$output .= '<script type="text/javascript">Drupal.extend({ settings: '. drupal_to_js(call_user_func_array('array_merge_recursive', $data)) ." });</script>\n"; $output .= '<script type="text/javascript">jQuery.extend(Drupal.settings, '. drupal_to_js(call_user_func_array('array_merge_recursive', $data)) .");</script>\n";
break; break;
case 'inline': case 'inline':
foreach ($data as $info) { foreach ($data as $info) {

View File

@ -69,7 +69,9 @@ Drupal.ahah.prototype.onsubmit = function () {
margin: '0 0 0 20px' margin: '0 0 0 20px'
}); });
button.css('float', 'left').attr('disabled', true).after(progress_element); button.css('float', 'left').attr('disabled', true).after(progress_element);
eval('progress_element.' + this.showEffect + '()'); if (progress_element[this.showEffect]) {
progress_element[this.showEffect]();
}
}; };
/** /**
@ -93,10 +95,12 @@ Drupal.ahah.prototype.oncomplete = function (data) {
if (this.method == 'replace') { if (this.method == 'replace') {
wrapper.empty().append(new_content); wrapper.empty().append(new_content);
} }
else { else if (wrapper[this.method]) {
eval('wrapper.' + this.method + '(new_content)'); wrapper[this.method](new_content);
}
if (new_content[this.showEffect]) {
new_content[this.showEffect]();
} }
eval('new_content.' + this.showEffect + '()');
button.css('float', 'none').attr('disabled', false); button.css('float', 'none').attr('disabled', false);
Drupal.attachBehaviors(new_content); Drupal.attachBehaviors(new_content);

View File

@ -38,7 +38,7 @@ Drupal.jsAC = function (input, db) {
$(this.input) $(this.input)
.keydown(function (event) { return ac.onkeydown(this, event); }) .keydown(function (event) { return ac.onkeydown(this, event); })
.keyup(function (event) { ac.onkeyup(this, event) }) .keyup(function (event) { ac.onkeyup(this, event); })
.blur(function () { ac.hidePopup(); ac.db.cancel(); }); .blur(function () { ac.hidePopup(); ac.db.cancel(); });
}; };
@ -270,9 +270,8 @@ Drupal.ACDB.prototype.search = function (searchString) {
$.ajax({ $.ajax({
type: "GET", type: "GET",
url: db.uri +'/'+ Drupal.encodeURIComponent(searchString), url: db.uri +'/'+ Drupal.encodeURIComponent(searchString),
success: function (data) { dataType: 'json',
// Parse back result success: function (matches) {
var matches = Drupal.parseJson(data);
if (typeof matches['status'] == 'undefined' || matches['status'] != 0) { if (typeof matches['status'] == 'undefined' || matches['status'] != 0) {
db.cache[searchString] = matches; db.cache[searchString] = matches;
// Verify if these are still the matches the user wants to see // Verify if these are still the matches the user wants to see

View File

@ -35,13 +35,13 @@ Drupal.toggleFieldset = function(fieldset) {
Drupal.collapseScrollIntoView = function (node) { Drupal.collapseScrollIntoView = function (node) {
var h = self.innerHeight || document.documentElement.clientHeight || $('body')[0].clientHeight || 0; var h = self.innerHeight || document.documentElement.clientHeight || $('body')[0].clientHeight || 0;
var offset = self.pageYOffset || document.documentElement.scrollTop || $('body')[0].scrollTop || 0; var offset = self.pageYOffset || document.documentElement.scrollTop || $('body')[0].scrollTop || 0;
var pos = Drupal.absolutePosition(node); var posY = $(node).offset().top;
var fudge = 55; var fudge = 55;
if (pos.y + node.offsetHeight + fudge > h + offset) { if (posY + node.offsetHeight + fudge > h + offset) {
if (node.offsetHeight > h) { if (node.offsetHeight > h) {
window.scrollTo(0, pos.y); window.scrollTo(0, posY);
} else { } else {
window.scrollTo(0, pos.y + node.offsetHeight - h + fudge); window.scrollTo(0, posY + node.offsetHeight - h + fudge);
} }
} }
}; };

View File

@ -7,20 +7,6 @@ var Drupal = Drupal || { 'settings': {}, 'behaviors': {}, 'themes': {}, 'locale'
*/ */
Drupal.jsEnabled = document.getElementsByTagName && document.createElement && document.createTextNode && document.documentElement && document.getElementById; Drupal.jsEnabled = document.getElementsByTagName && document.createElement && document.createTextNode && document.documentElement && document.getElementById;
/**
* Extends the current object with the parameter. Works recursively.
*/
Drupal.extend = function(obj) {
for (var i in obj) {
if (this[i]) {
Drupal.extend.apply(this[i], [obj[i]]);
}
else {
this[i] = obj[i];
}
}
};
/** /**
* Attach all registered behaviors to a page element. * Attach all registered behaviors to a page element.
* *
@ -204,6 +190,7 @@ Drupal.redirectFormButton = function (uri, button, handler) {
button.onmouseover = button.onfocus = function() { button.onmouseover = button.onfocus = function() {
button.onclick = function() { button.onclick = function() {
// Create target iframe // Create target iframe
Drupal.deleteIframe();
Drupal.createIframe(); Drupal.createIframe();
// Prepare variables for use in anonymous function. // Prepare variables for use in anonymous function.
@ -214,6 +201,7 @@ Drupal.redirectFormButton = function (uri, button, handler) {
// Redirect form submission to iframe // Redirect form submission to iframe
this.form.action = uri; this.form.action = uri;
this.form.target = 'redirect-target'; this.form.target = 'redirect-target';
this.form.submit();
handler.onsubmit(); handler.onsubmit();
@ -238,10 +226,10 @@ Drupal.redirectFormButton = function (uri, button, handler) {
response = null; response = null;
} }
response = Drupal.parseJson(response); response = eval('('+ response +');');
// Check response code // Check response code
if (response.status == 0) { if (!response || response.status == 0) {
handler.onerror(response.data); handler.onerror(response.data || Drupal.t('Error parsing response'));
return; return;
} }
handler.oncomplete(response.data); handler.oncomplete(response.data);
@ -257,53 +245,6 @@ Drupal.redirectFormButton = function (uri, button, handler) {
}; };
}; };
/**
* Retrieves the absolute position of an element on the screen
*/
Drupal.absolutePosition = function (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 = Drupal.absolutePosition(el.offsetParent);
r.x += tmp.x;
r.y += tmp.y;
}
return r;
};
/**
* Return the dimensions of an element on the screen
*/
Drupal.dimensions = function (el) {
return { width: el.offsetWidth, height: el.offsetHeight };
};
/**
* Returns the position of the mouse cursor based on the event object passed
*/
Drupal.mousePosition = function(e) {
return { x: e.clientX + document.documentElement.scrollLeft, y: e.clientY + document.documentElement.scrollTop };
};
/**
* Parse a JSON response.
*
* The result is either the JSON object, or an object with 'status' 0 and 'data' an error message.
*/
Drupal.parseJson = function (data) {
if ((data.substring(0, 1) != '{') && (data.substring(0, 1) != '[')) {
return { status: 0, data: data.length ? data : Drupal.t('Unspecified error') };
}
return eval('(' + data + ');');
};
/** /**
* Create an invisible iframe for form submissions. * Create an invisible iframe for form submissions.
*/ */

10
misc/form.js Normal file
View File

@ -0,0 +1,10 @@
// $Id$
Drupal.behaviors.multiselectSelector = function() {
// Automatically selects the right radio button in a multiselect control.
$('.multiselect select:not(.multiselectSelector-processed)')
.addClass('multiselectSelector-processed').change(function() {
$('.multiselect input:radio[value="'+ this.id.substr(5) +'"]')
.attr('checked', true);
});
};

8
misc/jquery.js vendored

File diff suppressed because one or more lines are too long

View File

@ -72,9 +72,8 @@ Drupal.progressBar.prototype.sendPing = function () {
type: this.method, type: this.method,
url: this.uri, url: this.uri,
data: '', data: '',
success: function (data) { dataType: 'json',
// Parse response success: function (progress) {
var progress = Drupal.parseJson(data);
// Display errors // Display errors
if (progress.status == 0) { if (progress.status == 0) {
pb.displayError(progress.data); pb.displayError(progress.data);

View File

@ -47,13 +47,13 @@ Drupal.behaviors.tableHeader = function (context) {
ref = table; ref = table;
div.wide = true; div.wide = true;
} }
$(div).css('width', $(ref).width() - parseInt($(div).css('paddingLeft')) +'px'); $(div).width(Math.max(0, $(ref).width() - parseInt($(div).css('paddingLeft'))));
// Get position and store. // Get position and store.
div.cell = this; div.cell = this;
div.table = table; div.table = table;
div.stickyMax = height; div.stickyMax = height;
div.stickyPosition = Drupal.absolutePosition(this).y; div.stickyPosition = $(this).offset().top;
}); });
$(this).addClass('tableHeader-processed'); $(this).addClass('tableHeader-processed');
}); });
@ -91,7 +91,7 @@ Drupal.behaviors.tableHeader = function (context) {
$(cells).each(function () { $(cells).each(function () {
// Get position. // Get position.
this.stickyPosition = Drupal.absolutePosition(this.cell).y; this.stickyPosition = $(this.cell).offset().top;
this.stickyMax = this.table.savedHeight; this.stickyMax = this.table.savedHeight;
// Reflow the cell. // Reflow the cell.
@ -100,7 +100,7 @@ Drupal.behaviors.tableHeader = function (context) {
// Resize the first cell to fit the table. // Resize the first cell to fit the table.
ref = this.table; ref = this.table;
} }
$(this).css('width', $(ref).width() - parseInt($(this).css('paddingLeft')) +'px'); $(this).width(Math.max(0, $(ref).width() - parseInt($(this).css('paddingLeft'))));
}); });
// Reset timer // Reset timer

View File

@ -1,7 +1,7 @@
// $Id$ // $Id$
Drupal.behaviors.tableSelect = function (context) { Drupal.behaviors.tableSelect = function (context) {
$('form table[th.select-all]:not(.tableSelect-processed)', context).each(Drupal.tableSelect); $('form table:has(th.select-all):not(.tableSelect-processed)', context).each(Drupal.tableSelect);
}; };
Drupal.tableSelect = function() { Drupal.tableSelect = function() {

View File

@ -19,14 +19,14 @@ Drupal.behaviors.textarea = function(context) {
grippie.style.marginRight = (grippie.offsetWidth - $(this)[0].offsetWidth) +'px'; grippie.style.marginRight = (grippie.offsetWidth - $(this)[0].offsetWidth) +'px';
function startDrag(e) { function startDrag(e) {
staticOffset = textarea.height() - Drupal.mousePosition(e).y; staticOffset = textarea.height() - e.pageY;
textarea.css('opacity', 0.25); textarea.css('opacity', 0.25);
$(document).mousemove(performDrag).mouseup(endDrag); $(document).mousemove(performDrag).mouseup(endDrag);
return false; return false;
} }
function performDrag(e) { function performDrag(e) {
textarea.height(Math.max(32, staticOffset + Drupal.mousePosition(e).y) + 'px'); textarea.height(Math.max(32, staticOffset + e.pageY) + 'px');
return false; return false;
} }

View File

@ -1,110 +0,0 @@
// $Id$
/**
* Attaches the upload behaviour to the upload form.
*/
Drupal.behaviors.upload = function(context) {
$('input.upload:not(.upload-processed)', context).addClass('upload-processed').each(function () {
var uri = this.value;
// Extract the base name from the id (edit-attach-url -> attach).
var base = this.id.substring(5, this.id.length - 4);
var button = base + '-button';
var wrapper = base + '-wrapper';
var hide = base + '-hide';
var upload = new Drupal.jsUpload(uri, button, wrapper, hide);
$(this).addClass('upload-processed');
});
};
/**
* JS upload object.
*/
Drupal.jsUpload = function(uri, button, wrapper, hide) {
// Note: these elements are replaced after an upload, so we re-select them
// everytime they are needed.
this.button = '#'+ button;
this.wrapper = '#'+ wrapper;
this.hide = '#'+ hide;
Drupal.redirectFormButton(uri, $(this.button).get(0), this);
};
/**
* Handler for the form redirection submission.
*/
Drupal.jsUpload.prototype.onsubmit = function () {
// Insert progressbar and stretch to take the same space.
this.progress = new Drupal.progressBar('uploadprogress');
this.progress.setProgress(-1, Drupal.t('Uploading file'));
var hide = this.hide;
var el = this.progress.element;
var offset = $(hide).get(0).offsetHeight;
$(el).css({
width: '28em',
height: offset +'px',
paddingTop: '10px',
display: 'none'
});
$(hide).css('position', 'absolute');
$(hide).after(el);
$(el).fadeIn('slow');
$(hide).fadeOut('slow');
};
/**
* Handler for the form redirection completion.
*/
Drupal.jsUpload.prototype.oncomplete = function (data) {
// Remove old form
Drupal.freezeHeight(); // Avoid unnecessary scrolling
$(this.wrapper).html('');
// Place HTML into temporary div
var div = document.createElement('div');
$(div).html(data);
// If uploading the first attachment fade in everything
if ($('tr', div).size() == 2) {
// Replace form and re-attach behaviours
$(div).hide();
$(this.wrapper).append(div);
$(div).fadeIn('slow');
}
// Else fade in only the last table row
else {
// Hide form and last table row
$('table tr:last-of-type td', div).hide();
// Note: workaround because jQuery's #id selector does not work outside of 'document'
// Should be: $(this.hide, div).hide();
var hide = this.hide;
$('div', div).each(function() {
if (('#'+ this.id) == hide) {
this.style.display = 'none';
}
});
// Replace form, fade in items and re-attach behaviour
$(this.wrapper).append(div);
$('table tr:last-of-type td', div).fadeIn('slow');
$(this.hide, div).fadeIn('slow');
}
Drupal.attachBehaviors(div);
Drupal.unfreezeHeight();
};
/**
* Handler for the form redirection error.
*/
Drupal.jsUpload.prototype.onerror = function (error) {
alert(Drupal.t('An error occurred:\n\n@error', { '@error': error }));
// Remove progressbar
$(this.progress.element).remove();
this.progress = null;
// Undo hide
$(this.hide).css({
position: 'static',
left: '0px'
});
};

View File

@ -24,9 +24,12 @@ Drupal.bookFillSelect = function() {
pb.setProgress(-1, Drupal.t('Updating parents...')); pb.setProgress(-1, Drupal.t('Updating parents...'));
$('#edit-book-plid-wrapper').html(pb.element); $('#edit-book-plid-wrapper').html(pb.element);
$.get(Drupal.settings.book.formCallback +'/'+ $('#'+ Drupal.settings.book.formId +' input[@name=form_build_id]').val() +'/'+ $('#edit-book-bid').val(), {}, function(data) { $.ajax({
parsedData = Drupal.parseJson(data); url: Drupal.settings.book.formCallback +'/'+ $('#'+ Drupal.settings.book.formId +' input[name=form_build_id]').val() +'/'+ $('#edit-book-bid').val(),
// Insert the new select, and remove the progress bar. dataType: 'json',
$('#edit-book-plid-wrapper').after(parsedData['book']).remove(); success: function(data) {
// Insert the new select, and remove the progress bar.
$('#edit-book-plid-wrapper').after(data['book']).remove();
}
}); });
}; };

View File

@ -188,7 +188,7 @@ Drupal.behaviors.color = function (context) {
// Add new bindings // Add new bindings
focused = this; focused = this;
farb.linkTo(function (color) { callback(input, color, true, false) }); farb.linkTo(function (color) { callback(input, color, true, false); });
farb.setColor(this.value); farb.setColor(this.value);
$(focused).keyup(farb.updateValue).keyup(preview).keyup(resetScheme) $(focused).keyup(farb.updateValue).keyup(preview).keyup(resetScheme)
.parent().addClass('item-selected'); .parent().addClass('item-selected');

View File

@ -6,7 +6,7 @@ Drupal.behaviors.comment = function (context) {
for (i=0;i<3;i++) { for (i=0;i<3;i++) {
cookie = Drupal.comment.getCookie('comment_info_' + parts[i]); cookie = Drupal.comment.getCookie('comment_info_' + parts[i]);
if (cookie != '') { if (cookie != '') {
$("#comment-form input[@name=" + parts[i] + "]:not(.comment-processed)", context) $("#comment-form input[name=" + parts[i] + "]:not(.comment-processed)", context)
.val(cookie) .val(cookie)
.addClass('comment-processed'); .addClass('comment-processed');
} }

View File

@ -268,7 +268,7 @@ function node_filter_form() {
$form['filters']['buttons']['reset'] = array('#type' => 'submit', '#value' => t('Reset')); $form['filters']['buttons']['reset'] = array('#type' => 'submit', '#value' => t('Reset'));
} }
drupal_add_js(drupal_get_path('module', 'node') .'/node.js'); drupal_add_js('misc/form.js', 'core');
return $form; return $form;
} }

View File

@ -1,12 +0,0 @@
// $Id$
if (Drupal.jsEnabled) {
$(function() {
// Automatically selects the right radio button in the filter section of
// the admin content list.
$('#node-admin-filter select').change(function() {
$('#node-admin-filter input:radio[@value="'+ this.id.substr(5) +'"]')
.attr('checked', true);
});
});
}

View File

@ -41,7 +41,7 @@ Drupal.behaviors.cleanURLsSettingsCheck = function(context) {
*/ */
Drupal.cleanURLsInstallCheck = function() { Drupal.cleanURLsInstallCheck = function() {
var pathname = location.pathname +""; var pathname = location.pathname +"";
var url = pathname.replace(/\/[^/]*$/, "/") +"node"; var url = pathname.replace(/\/[^\/]*$/, "/") +"node";
$("#clean-url .description").append('<span><div id="testing">'+ Drupal.settings.cleanURL.testing +"</div></span>"); $("#clean-url .description").append('<span><div id="testing">'+ Drupal.settings.cleanURL.testing +"</div></span>");
$("#clean-url.install").css("display", "block"); $("#clean-url.install").css("display", "block");
$.ajax({url: location.protocol +"//"+ location.host + url, type: "GET", data: " ", complete: function(response) { $.ajax({url: location.protocol +"//"+ location.host + url, type: "GET", data: " ", complete: function(response) {

View File

@ -585,7 +585,7 @@ function upload_js() {
$output = theme('status_messages') . drupal_render($form); $output = theme('status_messages') . drupal_render($form);
// We send the updated file attachments form. // We send the updated file attachments form.
// Don't call drupal_json(). upload.js uses an iframe and // Don't call drupal_json(). ahah.js uses an iframe and
// the header output by drupal_json() causes problems in some browsers. // the header output by drupal_json() causes problems in some browsers.
print drupal_to_js(array('status' => TRUE, 'data' => $output)); print drupal_to_js(array('status' => TRUE, 'data' => $output));
exit; exit;

View File

@ -83,6 +83,8 @@ function user_filter_form() {
); );
} }
drupal_add_js('misc/form.js', 'core');
return $form; return $form;
} }

View File

@ -181,7 +181,7 @@ Drupal.setDefaultTimezone = function() {
* "Picture support" radio buttons. * "Picture support" radio buttons.
*/ */
Drupal.behaviors.userSettings = function (context) { Drupal.behaviors.userSettings = function (context) {
$('div.user-admin-picture-radios input[@type=radio]:not(.userSettings-processed)', context).addClass('userSettings-processed').click(function () { $('div.user-admin-picture-radios input[type=radio]:not(.userSettings-processed)', context).addClass('userSettings-processed').click(function () {
$('div.user-admin-picture-settings', context)[['hide', 'show'][this.value]](); $('div.user-admin-picture-settings', context)[['hide', 'show'][this.value]]();
}); });
}; };