summaryrefslogtreecommitdiff
path: root/misc
diff options
context:
space:
mode:
Diffstat (limited to 'misc')
-rw-r--r--misc/autocomplete.js11
-rw-r--r--misc/machine-name.js24
-rw-r--r--misc/states.js328
-rw-r--r--misc/tabledrag.js38
-rw-r--r--misc/tableheader.js36
-rw-r--r--misc/tableselect.js13
-rw-r--r--misc/vertical-tabs.css5
-rw-r--r--misc/vertical-tabs.js10
8 files changed, 307 insertions, 158 deletions
diff --git a/misc/autocomplete.js b/misc/autocomplete.js
index 02a886c21..267d4b79b 100644
--- a/misc/autocomplete.js
+++ b/misc/autocomplete.js
@@ -32,7 +32,7 @@ Drupal.behaviors.autocomplete = {
Drupal.autocompleteSubmit = function () {
return $('#autocomplete').each(function () {
this.owner.hidePopup();
- }).size() == 0;
+ }).length == 0;
};
/**
@@ -123,7 +123,7 @@ Drupal.jsAC.prototype.selectDown = function () {
}
else if (this.popup) {
var lis = $('li', this.popup);
- if (lis.size() > 0) {
+ if (lis.length > 0) {
this.highlight(lis.get(0));
}
}
@@ -227,7 +227,7 @@ Drupal.jsAC.prototype.found = function (matches) {
// Show popup with matches, if any.
if (this.popup) {
- if (ul.children().size()) {
+ if (ul.children().length) {
$(this.popup).empty().append(ul).show();
$(this.ariaLive).html(Drupal.t('Autocomplete popup'));
}
@@ -287,10 +287,11 @@ Drupal.ACDB.prototype.search = function (searchString) {
this.timer = setTimeout(function () {
db.owner.setStatus('begin');
- // Ajax GET request for autocompletion.
+ // Ajax GET request for autocompletion. We use Drupal.encodePath instead of
+ // encodeURIComponent to allow autocomplete search terms to contain slashes.
$.ajax({
type: 'GET',
- url: db.uri + '/' + encodeURIComponent(searchString),
+ url: db.uri + '/' + Drupal.encodePath(searchString),
dataType: 'json',
success: function (matches) {
if (typeof matches.status == 'undefined' || matches.status != 0) {
diff --git a/misc/machine-name.js b/misc/machine-name.js
index 2691c3b73..ced8c4bee 100644
--- a/misc/machine-name.js
+++ b/misc/machine-name.js
@@ -19,6 +19,10 @@ Drupal.behaviors.machineName = {
* disallowed characters in the machine name; e.g., '[^a-z0-9]+'.
* - replace: A character to replace disallowed characters with; e.g., '_'
* or '-'.
+ * - standalone: Whether the preview should stay in its own element rather
+ * than the suffix of the source element.
+ * - field_prefix: The #field_prefix of the form element.
+ * - field_suffix: The #field_suffix of the form element.
*/
attach: function (context, settings) {
var self = this;
@@ -26,7 +30,7 @@ Drupal.behaviors.machineName = {
var $source = $(source_id, context).addClass('machine-name-source');
var $target = $(options.target, context).addClass('machine-name-target');
var $suffix = $(options.suffix, context);
- var $wrapper = $target.parents('.form-item:first');
+ var $wrapper = $target.closest('.form-item');
// All elements have to exist.
if (!$source.length || !$target.length || !$suffix.length || !$wrapper.length) {
return;
@@ -49,10 +53,12 @@ Drupal.behaviors.machineName = {
var machine = self.transliterate($source.val(), options);
}
// Append the machine name preview to the source field.
- var $preview = $('<span class="machine-name-value">' + machine + '</span>');
- $suffix.empty()
- .append(' ').append('<span class="machine-name-label">' + options.label + ':</span>')
- .append(' ').append($preview);
+ var $preview = $('<span class="machine-name-value">' + options.field_prefix + Drupal.checkPlain(machine) + options.field_suffix + '</span>');
+ $suffix.empty();
+ if (options.label) {
+ $suffix.append(' ').append('<span class="machine-name-label">' + options.label + ':</span>');
+ }
+ $suffix.append(' ').append($preview);
// If the machine name cannot be edited, stop further processing.
if ($target.is(':disabled')) {
@@ -77,9 +83,11 @@ Drupal.behaviors.machineName = {
$source.bind('keyup.machineName change.machineName', function () {
machine = self.transliterate($(this).val(), options);
// Set the machine name to the transliterated value.
- if (machine != options.replace && machine != '') {
- $target.val(machine);
- $preview.text(machine);
+ if (machine != '') {
+ if (machine != options.replace) {
+ $target.val(machine);
+ $preview.html(options.field_prefix + Drupal.checkPlain(machine) + options.field_suffix);
+ }
$suffix.show();
}
else {
diff --git a/misc/states.js b/misc/states.js
index 9b98d5dd2..00eeba17b 100644
--- a/misc/states.js
+++ b/misc/states.js
@@ -21,7 +21,7 @@ Drupal.behaviors.states = {
new states.Dependent({
element: $(selector),
state: states.State.sanitize(state),
- dependees: settings.states[selector][state]
+ constraints: settings.states[selector][state]
});
}
}
@@ -40,12 +40,14 @@ Drupal.behaviors.states = {
* Object with the following keys (all of which are required):
* - element: A jQuery object of the dependent element
* - state: A State object describing the state that is dependent
- * - dependees: An object with dependency specifications. Lists all elements
- * that this element depends on.
+ * - constraints: An object with dependency specifications. Lists all elements
+ * that this element depends on. It can be nested and can contain arbitrary
+ * AND and OR clauses.
*/
states.Dependent = function (args) {
- $.extend(this, { values: {}, oldValue: undefined }, args);
+ $.extend(this, { values: {}, oldValue: null }, args);
+ this.dependees = this.getDependees();
for (var selector in this.dependees) {
this.initializeDependee(selector, this.dependees[selector]);
}
@@ -69,7 +71,7 @@ states.Dependent.comparisons = {
// as a string before applying the strict comparison in compare(). Otherwise
// numeric keys in the form's #states array fail to match string values
// returned from jQuery's val().
- return (value.constructor.name === 'String') ? compare(String(reference), value) : compare(reference, value);
+ return (typeof value === 'string') ? compare(reference.toString(), value) : compare(reference, value);
}
};
@@ -84,26 +86,33 @@ states.Dependent.prototype = {
* dependee's compliance status.
*/
initializeDependee: function (selector, dependeeStates) {
- var self = this;
+ var state;
// Cache for the states of this dependee.
- self.values[selector] = {};
+ this.values[selector] = {};
- $.each(dependeeStates, function (state, value) {
- state = states.State.sanitize(state);
+ for (var i in dependeeStates) {
+ if (dependeeStates.hasOwnProperty(i)) {
+ state = dependeeStates[i];
+ // Make sure we're not initializing this selector/state combination twice.
+ if ($.inArray(state, dependeeStates) === -1) {
+ continue;
+ }
+
+ state = states.State.sanitize(state);
- // Initialize the value of this state.
- self.values[selector][state.pristine] = undefined;
+ // Initialize the value of this state.
+ this.values[selector][state.name] = null;
- // Monitor state changes of the specified state for this dependee.
- $(selector).bind('state:' + state, function (e) {
- var complies = self.compare(value, e.value);
- self.update(selector, state, complies);
- });
+ // Monitor state changes of the specified state for this dependee.
+ $(selector).bind('state:' + state, $.proxy(function (e) {
+ this.update(selector, state, e.value);
+ }, this));
- // Make sure the event we just bound ourselves to is actually fired.
- new states.Trigger({ selector: selector, state: state });
- });
+ // Make sure the event we just bound ourselves to is actually fired.
+ new states.Trigger({ selector: selector, state: state });
+ }
+ }
},
/**
@@ -111,12 +120,16 @@ states.Dependent.prototype = {
*
* @param reference
* The value used for reference.
- * @param value
- * The value to compare with the reference value.
+ * @param selector
+ * CSS selector describing the dependee.
+ * @param state
+ * A State object describing the dependee's updated state.
+ *
* @return
- * true, undefined or false.
+ * true or false.
*/
- compare: function (reference, value) {
+ compare: function (reference, selector, state) {
+ var value = this.values[selector][state.name];
if (reference.constructor.name in states.Dependent.comparisons) {
// Use a custom compare function for certain reference value types.
return states.Dependent.comparisons[reference.constructor.name](reference, value);
@@ -139,8 +152,8 @@ states.Dependent.prototype = {
*/
update: function (selector, state, value) {
// Only act when the 'new' value is actually new.
- if (value !== this.values[selector][state.pristine]) {
- this.values[selector][state.pristine] = value;
+ if (value !== this.values[selector][state.name]) {
+ this.values[selector][state.name] = value;
this.reevaluate();
}
},
@@ -149,16 +162,8 @@ states.Dependent.prototype = {
* Triggers change events in case a state changed.
*/
reevaluate: function () {
- var value = undefined;
-
- // Merge all individual values to find out whether this dependee complies.
- for (var selector in this.values) {
- for (var state in this.values[selector]) {
- state = states.State.sanitize(state);
- var complies = this.values[selector][state.pristine];
- value = ternary(value, invert(complies, state.invert));
- }
- }
+ // Check whether any constraint for this dependent state is satisifed.
+ var value = this.verifyConstraints(this.constraints);
// Only invoke a state change event when the value actually changed.
if (value !== this.oldValue) {
@@ -173,6 +178,124 @@ states.Dependent.prototype = {
// infinite loops.
this.element.trigger({ type: 'state:' + this.state, value: value, trigger: true });
}
+ },
+
+ /**
+ * Evaluates child constraints to determine if a constraint is satisfied.
+ *
+ * @param constraints
+ * A constraint object or an array of constraints.
+ * @param selector
+ * The selector for these constraints. If undefined, there isn't yet a
+ * selector that these constraints apply to. In that case, the keys of the
+ * object are interpreted as the selector if encountered.
+ *
+ * @return
+ * true or false, depending on whether these constraints are satisfied.
+ */
+ verifyConstraints: function(constraints, selector) {
+ var result;
+ if ($.isArray(constraints)) {
+ // This constraint is an array (OR or XOR).
+ var hasXor = $.inArray('xor', constraints) === -1;
+ for (var i = 0, len = constraints.length; i < len; i++) {
+ if (constraints[i] != 'xor') {
+ var constraint = this.checkConstraints(constraints[i], selector, i);
+ // Return if this is OR and we have a satisfied constraint or if this
+ // is XOR and we have a second satisfied constraint.
+ if (constraint && (hasXor || result)) {
+ return hasXor;
+ }
+ result = result || constraint;
+ }
+ }
+ }
+ // Make sure we don't try to iterate over things other than objects. This
+ // shouldn't normally occur, but in case the condition definition is bogus,
+ // we don't want to end up with an infinite loop.
+ else if ($.isPlainObject(constraints)) {
+ // This constraint is an object (AND).
+ for (var n in constraints) {
+ if (constraints.hasOwnProperty(n)) {
+ result = ternary(result, this.checkConstraints(constraints[n], selector, n));
+ // False and anything else will evaluate to false, so return when any
+ // false condition is found.
+ if (result === false) { return false; }
+ }
+ }
+ }
+ return result;
+ },
+
+ /**
+ * Checks whether the value matches the requirements for this constraint.
+ *
+ * @param value
+ * Either the value of a state or an array/object of constraints. In the
+ * latter case, resolving the constraint continues.
+ * @param selector
+ * The selector for this constraint. If undefined, there isn't yet a
+ * selector that this constraint applies to. In that case, the state key is
+ * propagates to a selector and resolving continues.
+ * @param state
+ * The state to check for this constraint. If undefined, resolving
+ * continues.
+ * If both selector and state aren't undefined and valid non-numeric
+ * strings, a lookup for the actual value of that selector's state is
+ * performed. This parameter is not a State object but a pristine state
+ * string.
+ *
+ * @return
+ * true or false, depending on whether this constraint is satisfied.
+ */
+ checkConstraints: function(value, selector, state) {
+ // Normalize the last parameter. If it's non-numeric, we treat it either as
+ // a selector (in case there isn't one yet) or as a trigger/state.
+ if (typeof state !== 'string' || (/[0-9]/).test(state[0])) {
+ state = null;
+ }
+ else if (typeof selector === 'undefined') {
+ // Propagate the state to the selector when there isn't one yet.
+ selector = state;
+ state = null;
+ }
+
+ if (state !== null) {
+ // constraints is the actual constraints of an element to check for.
+ state = states.State.sanitize(state);
+ return invert(this.compare(value, selector, state), state.invert);
+ }
+ else {
+ // Resolve this constraint as an AND/OR operator.
+ return this.verifyConstraints(value, selector);
+ }
+ },
+
+ /**
+ * Gathers information about all required triggers.
+ */
+ getDependees: function() {
+ var cache = {};
+ // Swivel the lookup function so that we can record all available selector-
+ // state combinations for initialization.
+ var _compare = this.compare;
+ this.compare = function(reference, selector, state) {
+ (cache[selector] || (cache[selector] = [])).push(state.name);
+ // Return nothing (=== undefined) so that the constraint loops are not
+ // broken.
+ };
+
+ // This call doesn't actually verify anything but uses the resolving
+ // mechanism to go through the constraints array, trying to look up each
+ // value. Since we swivelled the compare function, this comparison returns
+ // undefined and lookup continues until the very end. Instead of lookup up
+ // the value, we record that combination of selector and state so that we
+ // can initialize all triggers.
+ this.verifyConstraints(this.constraints);
+ // Restore the original function.
+ this.compare = _compare;
+
+ return cache;
}
};
@@ -192,7 +315,6 @@ states.Trigger = function (args) {
states.Trigger.prototype = {
initialize: function () {
- var self = this;
var trigger = states.Trigger.states[this.state];
if (typeof trigger == 'function') {
@@ -200,9 +322,11 @@ states.Trigger.prototype = {
trigger.call(window, this.element);
}
else {
- $.each(trigger, function (event, valueFn) {
- self.defaultTrigger(event, valueFn);
- });
+ for (var event in trigger) {
+ if (trigger.hasOwnProperty(event)) {
+ this.defaultTrigger(event, trigger[event]);
+ }
+ }
}
// Mark this trigger as initialized for this element.
@@ -210,23 +334,22 @@ states.Trigger.prototype = {
},
defaultTrigger: function (event, valueFn) {
- var self = this;
var oldValue = valueFn.call(this.element);
// Attach the event callback.
- this.element.bind(event, function (e) {
- var value = valueFn.call(self.element, e);
+ this.element.bind(event, $.proxy(function (e) {
+ var value = valueFn.call(this.element, e);
// Only trigger the event if the value has actually changed.
if (oldValue !== value) {
- self.element.trigger({ type: 'state:' + self.state, value: value, oldValue: oldValue });
+ this.element.trigger({ type: 'state:' + this.state, value: value, oldValue: oldValue });
oldValue = value;
}
- });
+ }, this));
- states.postponed.push(function () {
+ states.postponed.push($.proxy(function () {
// Trigger the event once for initialization purposes.
- self.element.trigger({ type: 'state:' + self.state, value: oldValue, oldValue: undefined });
- });
+ this.element.trigger({ type: 'state:' + this.state, value: oldValue, oldValue: null });
+ }, this));
}
};
@@ -275,7 +398,7 @@ states.Trigger.states = {
collapsed: {
'collapsed': function(e) {
- return (e !== undefined && 'value' in e) ? e.value : this.is('.collapsed');
+ return (typeof e !== 'undefined' && 'value' in e) ? e.value : this.is('.collapsed');
}
}
};
@@ -307,7 +430,7 @@ states.State = function(state) {
};
/**
- * Create a new State object by sanitizing the passed value.
+ * Creates a new State object by sanitizing the passed value.
*/
states.State.sanitize = function (state) {
if (state instanceof states.State) {
@@ -352,72 +475,69 @@ states.State.prototype = {
* bubble up to these handlers. We use this system so that themes and modules
* can override these state change handlers for particular parts of a page.
*/
-{
- $(document).bind('state:disabled', function(e) {
- // Only act when this change was triggered by a dependency and not by the
- // element monitoring itself.
- if (e.trigger) {
- $(e.target)
- .attr('disabled', e.value)
- .filter('.form-element')
- .closest('.form-item, .form-submit, .form-wrapper')[e.value ? 'addClass' : 'removeClass']('form-disabled');
-
- // Note: WebKit nightlies don't reflect that change correctly.
- // See https://bugs.webkit.org/show_bug.cgi?id=23789
- }
- });
+$(document).bind('state:disabled', function(e) {
+ // Only act when this change was triggered by a dependency and not by the
+ // element monitoring itself.
+ if (e.trigger) {
+ $(e.target)
+ .attr('disabled', e.value)
+ .filter('.form-element')
+ .closest('.form-item, .form-submit, .form-wrapper').toggleClass('form-disabled', e.value);
+
+ // Note: WebKit nightlies don't reflect that change correctly.
+ // See https://bugs.webkit.org/show_bug.cgi?id=23789
+ }
+});
- $(document).bind('state:required', function(e) {
- if (e.trigger) {
- if (e.value) {
- $(e.target).closest('.form-item, .form-wrapper').find('label').append('<span class="form-required">*</span>');
- }
- else {
- $(e.target).closest('.form-item, .form-wrapper').find('label .form-required').remove();
- }
+$(document).bind('state:required', function(e) {
+ if (e.trigger) {
+ if (e.value) {
+ $(e.target).closest('.form-item, .form-wrapper').find('label').append('<span class="form-required">*</span>');
}
- });
-
- $(document).bind('state:visible', function(e) {
- if (e.trigger) {
- $(e.target).closest('.form-item, .form-submit, .form-wrapper')[e.value ? 'show' : 'hide']();
+ else {
+ $(e.target).closest('.form-item, .form-wrapper').find('label .form-required').remove();
}
- });
+ }
+});
- $(document).bind('state:checked', function(e) {
- if (e.trigger) {
- $(e.target).attr('checked', e.value);
- }
- });
+$(document).bind('state:visible', function(e) {
+ if (e.trigger) {
+ $(e.target).closest('.form-item, .form-submit, .form-wrapper').toggle(e.value);
+ }
+});
- $(document).bind('state:collapsed', function(e) {
- if (e.trigger) {
- if ($(e.target).is('.collapsed') !== e.value) {
- $('> legend a', e.target).click();
- }
+$(document).bind('state:checked', function(e) {
+ if (e.trigger) {
+ $(e.target).attr('checked', e.value);
+ }
+});
+
+$(document).bind('state:collapsed', function(e) {
+ if (e.trigger) {
+ if ($(e.target).is('.collapsed') !== e.value) {
+ $('> legend a', e.target).click();
}
- });
-}
+ }
+});
/**
* These are helper functions implementing addition "operators" and don't
* implement any logic that is particular to states.
*/
-{
- // Bitwise AND with a third undefined state.
- function ternary (a, b) {
- return a === undefined ? b : (b === undefined ? a : a && b);
- };
-
- // Inverts a (if it's not undefined) when invert is true.
- function invert (a, invert) {
- return (invert && a !== undefined) ? !a : a;
- };
-
- // Compares two values while ignoring undefined values.
- function compare (a, b) {
- return (a === b) ? (a === undefined ? a : true) : (a === undefined || b === undefined);
- }
+
+// Bitwise AND with a third undefined state.
+function ternary (a, b) {
+ return typeof a === 'undefined' ? b : (typeof b === 'undefined' ? a : a && b);
+}
+
+// Inverts a (if it's not undefined) when invert is true.
+function invert (a, invert) {
+ return (invert && typeof a !== 'undefined') ? !a : a;
+}
+
+// Compares two values while ignoring undefined values.
+function compare (a, b) {
+ return (a === b) ? (typeof a === 'undefined' ? a : true) : (typeof a === 'undefined' || typeof b === 'undefined');
}
})(jQuery);
diff --git a/misc/tabledrag.js b/misc/tabledrag.js
index 41fd47b6e..fed674ca9 100644
--- a/misc/tabledrag.js
+++ b/misc/tabledrag.js
@@ -123,9 +123,9 @@ Drupal.tableDrag.prototype.initColumns = function () {
// Find the first field in this group.
for (var d in this.tableSettings[group]) {
var field = $('.' + this.tableSettings[group][d].target + ':first', this.table);
- if (field.size() && this.tableSettings[group][d].hidden) {
+ if (field.length && this.tableSettings[group][d].hidden) {
var hidden = this.tableSettings[group][d].hidden;
- var cell = field.parents('td:first');
+ var cell = field.closest('td');
break;
}
}
@@ -201,6 +201,8 @@ Drupal.tableDrag.prototype.hideColumns = function () {
// The cookie expires in one year.
expires: 365
});
+ // Trigger an event to allow other scripts to react to this display change.
+ $('table.tabledrag-processed').trigger('columnschange', 'hide');
};
/**
@@ -224,6 +226,8 @@ Drupal.tableDrag.prototype.showColumns = function () {
// The cookie expires in one year.
expires: 365
});
+ // Trigger an event to allow other scripts to react to this display change.
+ $('table.tabledrag-processed').trigger('columnschange', 'show');
};
/**
@@ -256,7 +260,7 @@ Drupal.tableDrag.prototype.makeDraggable = function (item) {
if ($('td:first .indentation:last', item).length) {
$('td:first .indentation:last', item).after(handle);
// Update the total width of indentation in this entire table.
- self.indentCount = Math.max($('.indentation', item).size(), self.indentCount);
+ self.indentCount = Math.max($('.indentation', item).length, self.indentCount);
}
else {
$('td:first', item).prepend(handle);
@@ -362,7 +366,7 @@ Drupal.tableDrag.prototype.makeDraggable = function (item) {
if ($(item).is('.tabledrag-root')) {
// Swap with the previous top-level row.
var groupHeight = 0;
- while (previousRow && $('.indentation', previousRow).size()) {
+ while (previousRow && $('.indentation', previousRow).length) {
previousRow = $(previousRow).prev('tr').get(0);
groupHeight += $(previousRow).is(':hidden') ? 0 : previousRow.offsetHeight;
}
@@ -402,12 +406,12 @@ Drupal.tableDrag.prototype.makeDraggable = function (item) {
if ($(item).is('.tabledrag-root')) {
// Swap with the next group (necessarily a top-level one).
var groupHeight = 0;
- nextGroup = new self.row(nextRow, 'keyboard', self.indentEnabled, self.maxDepth, false);
+ var nextGroup = new self.row(nextRow, 'keyboard', self.indentEnabled, self.maxDepth, false);
if (nextGroup) {
$(nextGroup.group).each(function () {
groupHeight += $(this).is(':hidden') ? 0 : this.offsetHeight;
});
- nextGroupRow = $(nextGroup.group).filter(':last').get(0);
+ var nextGroupRow = $(nextGroup.group).filter(':last').get(0);
self.rowObject.swap('after', nextGroupRow);
// No need to check for indentation, 0 is the only valid one.
window.scrollBy(0, parseInt(groupHeight, 10));
@@ -688,7 +692,7 @@ Drupal.tableDrag.prototype.updateField = function (changedRow, group) {
var sourceRow = changedRow;
if ($(previousRow).is('.draggable') && $('.' + group, previousRow).length) {
if (this.indentEnabled) {
- if ($('.indentations', previousRow).size() == $('.indentations', changedRow)) {
+ if ($('.indentations', previousRow).length == $('.indentations', changedRow)) {
sourceRow = previousRow;
}
}
@@ -698,7 +702,7 @@ Drupal.tableDrag.prototype.updateField = function (changedRow, group) {
}
else if ($(nextRow).is('.draggable') && $('.' + group, nextRow).length) {
if (this.indentEnabled) {
- if ($('.indentations', nextRow).size() == $('.indentations', changedRow)) {
+ if ($('.indentations', nextRow).length == $('.indentations', changedRow)) {
sourceRow = nextRow;
}
}
@@ -754,7 +758,7 @@ Drupal.tableDrag.prototype.updateField = function (changedRow, group) {
switch (rowSettings.action) {
case 'depth':
// Get the depth of the target row.
- targetElement.value = $('.indentation', $(sourceElement).parents('tr:first')).size();
+ targetElement.value = $('.indentation', $(sourceElement).closest('tr')).length;
break;
case 'match':
// Update the value.
@@ -884,20 +888,20 @@ Drupal.tableDrag.prototype.row = function (tableRow, method, indentEnabled, maxD
this.element = tableRow;
this.method = method;
this.group = [tableRow];
- this.groupDepth = $('.indentation', tableRow).size();
+ this.groupDepth = $('.indentation', tableRow).length;
this.changed = false;
- this.table = $(tableRow).parents('table:first').get(0);
+ this.table = $(tableRow).closest('table').get(0);
this.indentEnabled = indentEnabled;
this.maxDepth = maxDepth;
this.direction = ''; // Direction the row is being moved.
if (this.indentEnabled) {
- this.indents = $('.indentation', tableRow).size();
+ this.indents = $('.indentation', tableRow).length;
this.children = this.findChildren(addClasses);
this.group = $.merge(this.group, this.children);
// Find the depth of this entire group.
for (var n = 0; n < this.group.length; n++) {
- this.groupDepth = Math.max($('.indentation', this.group[n]).size(), this.groupDepth);
+ this.groupDepth = Math.max($('.indentation', this.group[n]).length, this.groupDepth);
}
}
};
@@ -1009,7 +1013,7 @@ Drupal.tableDrag.prototype.row.prototype.validIndentInterval = function (prevRow
// Minimum indentation:
// Do not orphan the next row.
- minIndent = nextRow ? $('.indentation', nextRow).size() : 0;
+ minIndent = nextRow ? $('.indentation', nextRow).length : 0;
// Maximum indentation:
if (!prevRow || $(prevRow).is(':not(.draggable)') || $(this.element).is('.tabledrag-root')) {
@@ -1021,7 +1025,7 @@ Drupal.tableDrag.prototype.row.prototype.validIndentInterval = function (prevRow
}
else {
// Do not go deeper than as a child of the previous row.
- maxIndent = $('.indentation', prevRow).size() + ($(prevRow).is('.tabledrag-leaf') ? 0 : 1);
+ maxIndent = $('.indentation', prevRow).length + ($(prevRow).is('.tabledrag-leaf') ? 0 : 1);
// Limit by the maximum allowed depth for the table.
if (this.maxDepth) {
maxIndent = Math.min(maxIndent, this.maxDepth - (this.groupDepth - this.indents));
@@ -1042,8 +1046,8 @@ Drupal.tableDrag.prototype.row.prototype.validIndentInterval = function (prevRow
Drupal.tableDrag.prototype.row.prototype.indent = function (indentDiff) {
// Determine the valid indentations interval if not available yet.
if (!this.interval) {
- prevRow = $(this.element).prev('tr').get(0);
- nextRow = $(this.group).filter(':last').next('tr').get(0);
+ var prevRow = $(this.element).prev('tr').get(0);
+ var nextRow = $(this.group).filter(':last').next('tr').get(0);
this.interval = this.validIndentInterval(prevRow, nextRow);
}
diff --git a/misc/tableheader.js b/misc/tableheader.js
index 949ef5212..a9f98a680 100644
--- a/misc/tableheader.js
+++ b/misc/tableheader.js
@@ -27,6 +27,14 @@ Drupal.tableHeader = function (table) {
this.originalTable = $(table);
this.originalHeader = $(table).children('thead');
this.originalHeaderCells = this.originalHeader.find('> tr > th');
+ this.displayWeight = null;
+
+ // React to columns change to avoid making checks in the scroll callback.
+ this.originalTable.bind('columnschange', function (e, display) {
+ // This will force header size to be calculated on scroll.
+ self.widthCalculated = (self.displayWeight !== null && self.displayWeight === display);
+ self.displayWeight = display;
+ });
// Clone the table header so it inherits original jQuery properties. Hide
// the table to avoid a flash of the header clone upon page load.
@@ -95,15 +103,29 @@ Drupal.tableHeader.prototype.eventhandlerRecalculateStickyHeader = function (eve
// visible or when forced.
if (this.stickyVisible && (calculateWidth || !this.widthCalculated)) {
this.widthCalculated = true;
+ var $that = null;
+ var $stickyCell = null;
+ var display = null;
+ var cellWidth = null;
// Resize header and its cell widths.
- this.stickyHeaderCells.each(function (index) {
- var cellWidth = self.originalHeaderCells.eq(index).css('width');
- // Exception for IE7.
- if (cellWidth == 'auto') {
- cellWidth = self.originalHeaderCells.get(index).clientWidth + 'px';
+ // Only apply width to visible table cells. This prevents the header from
+ // displaying incorrectly when the sticky header is no longer visible.
+ for (var i = 0, il = this.originalHeaderCells.length; i < il; i += 1) {
+ $that = $(this.originalHeaderCells[i]);
+ $stickyCell = this.stickyHeaderCells.eq($that.index());
+ display = $that.css('display');
+ if (display !== 'none') {
+ cellWidth = $that.css('width');
+ // Exception for IE7.
+ if (cellWidth === 'auto') {
+ cellWidth = $that[0].clientWidth + 'px';
+ }
+ $stickyCell.css({'width': cellWidth, 'display': display});
}
- $(this).css('width', cellWidth);
- });
+ else {
+ $stickyCell.css('display', 'none');
+ }
+ }
this.stickyTable.css('width', this.originalTable.css('width'));
}
};
diff --git a/misc/tableselect.js b/misc/tableselect.js
index 1abda24d9..5a88ac20c 100644
--- a/misc/tableselect.js
+++ b/misc/tableselect.js
@@ -2,13 +2,14 @@
Drupal.behaviors.tableSelect = {
attach: function (context, settings) {
- $('table:has(th.select-all)', context).once('table-select', Drupal.tableSelect);
+ // Select the inner-most table in case of nested tables.
+ $('th.select-all', context).closest('table').once('table-select', Drupal.tableSelect);
}
};
Drupal.tableSelect = function () {
// Do not add a "Select all" checkbox if there are no rows with checkboxes in the table
- if ($('td input:checkbox', this).size() == 0) {
+ if ($('td input:checkbox', this).length == 0) {
return;
}
@@ -29,7 +30,7 @@ Drupal.tableSelect = function () {
checkboxes.each(function () {
this.checked = event.target.checked;
// Either add or remove the selected class based on the state of the check all checkbox.
- $(this).parents('tr:first')[ this.checked ? 'addClass' : 'removeClass' ]('selected');
+ $(this).closest('tr').toggleClass('selected', this.checked);
});
// Update the title and the state of the check all box.
updateSelectAll(event.target.checked);
@@ -39,14 +40,14 @@ Drupal.tableSelect = function () {
// For each of the checkboxes within the table that are not disabled.
checkboxes = $('td input:checkbox:enabled', table).click(function (e) {
// Either add or remove the selected class based on the state of the check all checkbox.
- $(this).parents('tr:first')[ this.checked ? 'addClass' : 'removeClass' ]('selected');
+ $(this).closest('tr').toggleClass('selected', this.checked);
// If this is a shift click, we need to highlight everything in the range.
// Also make sure that we are actually checking checkboxes over a range and
// that a checkbox has been checked or unchecked before.
if (e.shiftKey && lastChecked && lastChecked != e.target) {
// We use the checkbox's parent TR to do our range searching.
- Drupal.tableSelectRange($(e.target).parents('tr')[0], $(lastChecked).parents('tr')[0], e.target.checked);
+ Drupal.tableSelectRange($(e.target).closest('tr')[0], $(lastChecked).closest('tr')[0], e.target.checked);
}
// If all checkboxes are checked, make sure the select-all one is checked too, otherwise keep unchecked.
@@ -69,7 +70,7 @@ Drupal.tableSelectRange = function (from, to, state) {
}
// Either add or remove the selected class based on the state of the target checkbox.
- $(i)[ state ? 'addClass' : 'removeClass' ]('selected');
+ $(i).toggleClass('selected', state);
$('input:checkbox', i).each(function () {
this.checked = state;
});
diff --git a/misc/vertical-tabs.css b/misc/vertical-tabs.css
index 10e815391..197fb5f1f 100644
--- a/misc/vertical-tabs.css
+++ b/misc/vertical-tabs.css
@@ -19,9 +19,12 @@ div.vertical-tabs {
padding: 0 1em;
border: 0;
}
-.vertical-tabs legend {
+fieldset.vertical-tabs-pane legend {
display: none;
}
+fieldset.vertical-tabs-pane fieldset legend {
+ display: block;
+}
/* Layout of each tab */
.vertical-tabs ul.vertical-tabs-list li {
diff --git a/misc/vertical-tabs.js b/misc/vertical-tabs.js
index 82dcd2c62..14d06607b 100644
--- a/misc/vertical-tabs.js
+++ b/misc/vertical-tabs.js
@@ -92,16 +92,6 @@ Drupal.verticalTab = function (settings) {
}
});
- // Pressing the Enter key lets you leave the tab again.
- this.fieldset.keydown(function(event) {
- // Enter key should not trigger inside <textarea> to allow for multi-line entries.
- if (event.keyCode == 13 && event.target.nodeName != "TEXTAREA") {
- // Set focus on the selected tab button again.
- $(".vertical-tab-button.selected a").focus();
- return false;
- }
- });
-
this.fieldset
.bind('summaryUpdated', function () {
self.updateSummary();