Commit bda52632 authored by webchick's avatar webchick

#444402 by kkaefer and RobLoach: Enforce coding standards on all core JavaScript.

parent a4dc8467
......@@ -19,7 +19,7 @@
Drupal.behaviors.ahah = {
attach: function(context, settings) {
for (var base in settings.ahah) {
if (!$('#'+ base + '.ahah-processed').size()) {
if (!$('#' + base + '.ahah-processed').size()) {
var element_settings = settings.ahah[base];
$(element_settings.selector).each(function() {
......@@ -27,7 +27,7 @@ Drupal.behaviors.ahah = {
var ahah = new Drupal.ahah(base, element_settings);
});
$('#'+ base).addClass('ahah-processed');
$('#' + base).addClass('ahah-processed');
}
}
}
......@@ -43,7 +43,7 @@ Drupal.ahah = function(base, element_settings) {
this.event = element_settings.event;
this.keypress = element_settings.keypress;
this.url = element_settings.url;
this.wrapper = '#'+ element_settings.wrapper;
this.wrapper = '#' + element_settings.wrapper;
this.effect = element_settings.effect;
this.method = element_settings.method;
this.progress = element_settings.progress;
......@@ -83,7 +83,7 @@ Drupal.ahah = function(base, element_settings) {
success: function(response, status) {
// Sanity check for browser support (object expected).
// When using iFrame uploads, responses must be returned as a string.
if (typeof(response) == 'string') {
if (typeof response == 'string') {
response = Drupal.parseJson(response);
}
return ahah.success(response, status);
......@@ -119,7 +119,7 @@ Drupal.ahah = function(base, element_settings) {
/**
* Handler for the form redirection submission.
*/
Drupal.ahah.prototype.beforeSubmit = function (form_values, element, options) {
Drupal.ahah.prototype.beforeSubmit = function(form_values, element, options) {
// Disable the element that received the change.
$(this.element).addClass('progress-disabled').attr('disabled', true);
......@@ -148,7 +148,7 @@ Drupal.ahah.prototype.beforeSubmit = function (form_values, element, options) {
/**
* Handler for the form redirection completion.
*/
Drupal.ahah.prototype.success = function (response, status) {
Drupal.ahah.prototype.success = function(response, status) {
var wrapper = $(this.wrapper);
var form = $(this.element).parents('form');
// Manually insert HTML into the jQuery object, using $() directly crashes
......@@ -188,7 +188,7 @@ Drupal.ahah.prototype.success = function (response, status) {
if ($('.ahah-new-content', new_content).size() > 0) {
$('.ahah-new-content', new_content).hide();
new_content.show();
$(".ahah-new-content", new_content)[this.showEffect](this.showSpeed);
$('.ahah-new-content', new_content)[this.showEffect](this.showSpeed);
}
else if (this.showEffect != 'show') {
new_content[this.showEffect](this.showSpeed);
......@@ -206,10 +206,10 @@ Drupal.ahah.prototype.success = function (response, status) {
/**
* Handler for the form redirection error.
*/
Drupal.ahah.prototype.error = function (response, uri) {
Drupal.ahah.prototype.error = function(response, uri) {
alert(Drupal.ahahError(response, uri));
// Resore the previous action and target to the form.
$(this.element).parent('form').attr( { action: this.form_action, target: this.form_target} );
$(this.element).parent('form').attr({ action: this.form_action, target: this.form_target });
// Remove the progress element.
if (this.progress.element) {
$(this.progress.element).remove();
......
......@@ -7,7 +7,7 @@
Drupal.behaviors.autocomplete = {
attach: function(context, settings) {
var acdb = [];
$('input.autocomplete:not(.autocomplete-processed)', context).each(function () {
$('input.autocomplete:not(.autocomplete-processed)', context).each(function() {
var uri = this.value;
if (!acdb[uri]) {
acdb[uri] = new Drupal.ACDB(uri);
......@@ -25,8 +25,8 @@ Drupal.behaviors.autocomplete = {
* Prevents the form from submitting if the suggestions popup is open
* and closes the suggestions popup when doing so.
*/
Drupal.autocompleteSubmit = function () {
return $('#autocomplete').each(function () {
Drupal.autocompleteSubmit = function() {
return $('#autocomplete').each(function() {
this.owner.hidePopup();
}).size() == 0;
};
......@@ -34,22 +34,22 @@ Drupal.autocompleteSubmit = function () {
/**
* An AutoComplete object.
*/
Drupal.jsAC = function (input, db) {
Drupal.jsAC = function(input, db) {
var ac = this;
this.input = input;
this.db = db;
$(this.input)
.keydown(function (event) { return ac.onkeydown(this, event); })
.keyup(function (event) { ac.onkeyup(this, event); })
.blur(function () { ac.hidePopup(); ac.db.cancel(); });
.keydown(function(event) { return ac.onkeydown(this, event); })
.keyup(function(event) { ac.onkeyup(this, event); })
.blur(function() { ac.hidePopup(); ac.db.cancel(); });
};
/**
* Handler for the "keydown" event.
*/
Drupal.jsAC.prototype.onkeydown = function (input, e) {
Drupal.jsAC.prototype.onkeydown = function(input, e) {
if (!e) {
e = window.event;
}
......@@ -68,7 +68,7 @@ Drupal.jsAC.prototype.onkeydown = function (input, e) {
/**
* Handler for the "keyup" event.
*/
Drupal.jsAC.prototype.onkeyup = function (input, e) {
Drupal.jsAC.prototype.onkeyup = function(input, e) {
if (!e) {
e = window.event;
}
......@@ -105,14 +105,14 @@ Drupal.jsAC.prototype.onkeyup = function (input, e) {
/**
* Puts the currently highlighted suggestion into the autocomplete field.
*/
Drupal.jsAC.prototype.select = function (node) {
Drupal.jsAC.prototype.select = function(node) {
this.input.value = node.autocompleteValue;
};
/**
* Highlights the next suggestion.
*/
Drupal.jsAC.prototype.selectDown = function () {
Drupal.jsAC.prototype.selectDown = function() {
if (this.selected && this.selected.nextSibling) {
this.highlight(this.selected.nextSibling);
}
......@@ -127,7 +127,7 @@ Drupal.jsAC.prototype.selectDown = function () {
/**
* Highlights the previous suggestion.
*/
Drupal.jsAC.prototype.selectUp = function () {
Drupal.jsAC.prototype.selectUp = function() {
if (this.selected && this.selected.previousSibling) {
this.highlight(this.selected.previousSibling);
}
......@@ -136,7 +136,7 @@ Drupal.jsAC.prototype.selectUp = function () {
/**
* Highlights a suggestion.
*/
Drupal.jsAC.prototype.highlight = function (node) {
Drupal.jsAC.prototype.highlight = function(node) {
if (this.selected) {
$(this.selected).removeClass('selected');
}
......@@ -147,7 +147,7 @@ Drupal.jsAC.prototype.highlight = function (node) {
/**
* Unhighlights a suggestion.
*/
Drupal.jsAC.prototype.unhighlight = function (node) {
Drupal.jsAC.prototype.unhighlight = function(node) {
$(node).removeClass('selected');
this.selected = false;
};
......@@ -155,7 +155,7 @@ Drupal.jsAC.prototype.unhighlight = function (node) {
/**
* Hides the autocomplete suggestions.
*/
Drupal.jsAC.prototype.hidePopup = function (keycode) {
Drupal.jsAC.prototype.hidePopup = function(keycode) {
// Select item if the right key or mousebutton was pressed.
if (this.selected && ((keycode && keycode != 46 && keycode != 8 && keycode != 27) || !keycode)) {
this.input.value = this.selected.autocompleteValue;
......@@ -172,18 +172,17 @@ Drupal.jsAC.prototype.hidePopup = function (keycode) {
/**
* Positions the suggestions popup and starts a search.
*/
Drupal.jsAC.prototype.populatePopup = function () {
Drupal.jsAC.prototype.populatePopup = function() {
// Show popup.
if (this.popup) {
$(this.popup).remove();
}
this.selected = false;
this.popup = document.createElement('div');
this.popup.id = 'autocomplete';
this.popup = $('<div id="autocomplete"></div>')[0];
this.popup.owner = this;
$(this.popup).css({
marginTop: this.input.offsetHeight +'px',
width: (this.input.offsetWidth - 4) +'px',
marginTop: this.input.offsetHeight + 'px',
width: (this.input.offsetWidth - 4) + 'px',
display: 'none'
});
$(this.input).before(this.popup);
......@@ -196,39 +195,38 @@ Drupal.jsAC.prototype.populatePopup = function () {
/**
* Fills the suggestion popup with any matches received.
*/
Drupal.jsAC.prototype.found = function (matches) {
Drupal.jsAC.prototype.found = function(matches) {
// If no value in the textfield, do not show the popup.
if (!this.input.value.length) {
return false;
}
// Prepare matches.
var ul = document.createElement('ul');
var ul = $('<ul></ul>');
var ac = this;
for (key in matches) {
var li = document.createElement('li');
$(li)
.html('<div>'+ matches[key] +'</div>')
.mousedown(function () { ac.select(this); })
.mouseover(function () { ac.highlight(this); })
.mouseout(function () { ac.unhighlight(this); });
li.autocompleteValue = key;
$(ul).append(li);
$('<li></li>')
.html($('<div></div>').html(matches[key]))
.mousedown(function() { ac.select(this); })
.mouseover(function() { ac.highlight(this); })
.mouseout(function() { ac.unhighlight(this); })
.attr('autocompleteValue', key)
.appendTo(ul);
}
// Show popup with matches, if any.
if (this.popup) {
if (ul.childNodes.length > 0) {
if (ul.children().size()) {
$(this.popup).empty().append(ul).show();
}
else {
$(this.popup).css({visibility: 'hidden'});
$(this.popup).css({ visibility: 'hidden' });
this.hidePopup();
}
}
};
Drupal.jsAC.prototype.setStatus = function (status) {
Drupal.jsAC.prototype.setStatus = function(status) {
switch (status) {
case 'begin':
$(this.input).addClass('throbbing');
......@@ -244,7 +242,7 @@ Drupal.jsAC.prototype.setStatus = function (status) {
/**
* An AutoComplete DataBase object.
*/
Drupal.ACDB = function (uri) {
Drupal.ACDB = function(uri) {
this.uri = uri;
this.delay = 300;
this.cache = {};
......@@ -253,7 +251,7 @@ Drupal.ACDB = function (uri) {
/**
* Performs a cached and delayed search.
*/
Drupal.ACDB.prototype.search = function (searchString) {
Drupal.ACDB.prototype.search = function(searchString) {
var db = this;
this.searchString = searchString;
......@@ -271,11 +269,11 @@ Drupal.ACDB.prototype.search = function (searchString) {
// Ajax GET request for autocompletion.
$.ajax({
type: "GET",
url: db.uri +'/'+ Drupal.encodeURIComponent(searchString),
type: 'GET',
url: db.uri + '/' + Drupal.encodeURIComponent(searchString),
dataType: 'json',
success: function (matches) {
if (typeof matches['status'] == 'undefined' || matches['status'] != 0) {
success: function(matches) {
if (typeof matches.status == 'undefined' || matches.status != 0) {
db.cache[searchString] = matches;
// Verify if these are still the matches the user wants to see.
if (db.searchString == searchString) {
......@@ -284,7 +282,7 @@ Drupal.ACDB.prototype.search = function (searchString) {
db.owner.setStatus('found');
}
},
error: function (xmlhttp) {
error: function(xmlhttp) {
alert(Drupal.ahahError(xmlhttp, db.uri));
}
});
......
......@@ -10,32 +10,26 @@ Drupal.behaviors.batch = {
if ($('#progress.batch-processed').size()) {
return;
}
$('#progress', context).addClass('batch-processed').each(function () {
var holder = this;
var uri = settings.batch.uri;
var initMessage = settings.batch.initMessage;
var errorMessage = settings.batch.errorMessage;
$('#progress', context).addClass('batch-processed').each(function() {
var holder = $(this);
// Success: redirect to the summary.
var updateCallback = function (progress, status, pb) {
var updateCallback = function(progress, status, pb) {
if (progress == 100) {
pb.stopMonitoring();
window.location = uri+'&op=finished';
window.location = settings.batch.uri + '&op=finished';
}
};
var errorCallback = function (pb) {
var div = document.createElement('p');
div.className = 'error';
$(div).html(errorMessage);
$(holder).prepend(div);
var errorCallback = function(pb) {
holder.prepend($('<p class="error"></p>').html(settings.batch.errorMessage));
$('#wait').hide();
};
var progress = new Drupal.progressBar('updateprogress', updateCallback, "POST", errorCallback);
progress.setProgress(-1, initMessage);
$(holder).append(progress.element);
progress.startMonitoring(uri+'&op=do', 10);
var progress = new Drupal.progressBar('updateprogress', updateCallback, 'POST', errorCallback);
progress.setProgress(-1, settings.batch.initMessage);
holder.append(progress.element);
progress.startMonitoring(settings.batch.uri + '&op=do', 10);
});
}
};
......
......@@ -11,7 +11,7 @@ Drupal.toggleFieldset = function(fieldset) {
var content = $('> div:not(.action)', fieldset);
$(fieldset).removeClass('collapsed');
content.hide();
content.slideDown( {
content.slideDown({
duration: 'fast',
easing: 'linear',
complete: function() {
......@@ -37,7 +37,7 @@ Drupal.toggleFieldset = function(fieldset) {
/**
* Scroll a given fieldset into view as much as possible.
*/
Drupal.collapseScrollIntoView = function (node) {
Drupal.collapseScrollIntoView = function(node) {
var h = self.innerHeight || document.documentElement.clientHeight || $('body')[0].clientHeight || 0;
var offset = self.pageYOffset || document.documentElement.scrollTop || $('body')[0].scrollTop || 0;
var posY = $(node).offset().top;
......@@ -71,7 +71,7 @@ Drupal.behaviors.collapse = {
// Turn the legend into a clickable link and wrap the contents of the fieldset
// in a div for easier animation
var text = this.innerHTML;
$(this).empty().append($('<a href="#">'+ text +'</a>').click(function() {
$(this).empty().append($('<a href="#">' + text + '</a>').click(function() {
var fieldset = $(this).parents('fieldset:first')[0];
// Don't animate multiple times
if (!fieldset.animating) {
......@@ -82,8 +82,8 @@ Drupal.behaviors.collapse = {
}))
.append(summary)
.after($('<div class="fieldset-wrapper"></div>')
.append(fieldset.children(':not(legend):not(.action)')))
.addClass('collapse-processed');
.append(fieldset.children(':not(legend):not(.action)'))
).addClass('collapse-processed');
});
}
};
......
......@@ -8,7 +8,7 @@ jQuery.noConflict();
// Indicate when other scripts use $ with out wrapping their code.
if ($ === undefined) {
$ = function() {
alert("Please wrap your JavaScript code in (function($) { ... })(jQuery); to be compatible. See http://docs.jquery.com/Using_jQuery_with_Other_Libraries.");
alert('Please wrap your JavaScript code in (function($) { ... })(jQuery); to be compatible. See http://docs.jquery.com/Using_jQuery_with_Other_Libraries.');
};
}
......@@ -195,9 +195,9 @@ Drupal.formatPlural = function(count, singular, plural, args) {
return Drupal.t(plural, args);
}
else {
args['@count['+ index +']'] = args['@count'];
args['@count[' + index + ']'] = args['@count'];
delete args['@count'];
return Drupal.t(plural.replace('@count', '@count['+ index +']'));
return Drupal.t(plural.replace('@count', '@count[' + index + ']'));
}
};
......@@ -233,7 +233,7 @@ Drupal.theme = function(func) {
*
* The result is either the JSON object, or an object with 'status' 0 and 'data' an error message.
*/
Drupal.parseJson = function (data) {
Drupal.parseJson = function(data) {
if ((data.substring(0, 1) != '{') && (data.substring(0, 1) != '[')) {
return { status: 0, data: data.length ? data : Drupal.t('Unspecified error') };
}
......@@ -244,23 +244,21 @@ Drupal.parseJson = function (data) {
* Freeze the current body height (as minimum height). Used to prevent
* unnecessary upwards scrolling when doing DOM manipulations.
*/
Drupal.freezeHeight = function () {
Drupal.freezeHeight = function() {
Drupal.unfreezeHeight();
var div = document.createElement('div');
$(div).css({
$('<div id="freeze-height"></div>').css({
position: 'absolute',
top: '0px',
left: '0px',
width: '1px',
height: $('body').css('height')
}).attr('id', 'freeze-height');
$('body').append(div);
}).appendTo('body');
};
/**
* Unfreeze the body height.
*/
Drupal.unfreezeHeight = function () {
Drupal.unfreezeHeight = function() {
$('#freeze-height').remove();
};
......@@ -268,7 +266,7 @@ Drupal.unfreezeHeight = function () {
* Wrapper to address the mod_rewrite url encoding bug
* (equivalent of drupal_urlencode() in PHP).
*/
Drupal.encodeURIComponent = function (item, uri) {
Drupal.encodeURIComponent = function(item, uri) {
uri = uri || location.href;
item = encodeURIComponent(item).replace(/%2F/g, '/');
return (uri.indexOf('?q=') != -1) ? item : item.replace(/%26/g, '%2526').replace(/%23/g, '%2523').replace(/\/\//g, '/%252F');
......@@ -277,8 +275,8 @@ Drupal.encodeURIComponent = function (item, uri) {
/**
* Get the text selection in a textarea.
*/
Drupal.getSelection = function (element) {
if (typeof(element.selectionStart) != 'number' && document.selection) {
Drupal.getSelection = function(element) {
if (typeof element.selectionStart != 'number' && document.selection) {
// The current selection.
var range1 = document.selection.createRange();
var range2 = range1.duplicate();
......@@ -300,14 +298,14 @@ Drupal.getSelection = function (element) {
Drupal.ahahError = function(xmlhttp, uri) {
if (xmlhttp.status == 200) {
if ($.trim(xmlhttp.responseText)) {
var message = Drupal.t("An error occurred. \n@uri\n@text", {'@uri': uri, '@text': xmlhttp.responseText });
var message = Drupal.t('An error occurred. \n@uri\n@text', { '@uri': uri, '@text': xmlhttp.responseText });
}
else {
var message = Drupal.t("An error occurred. \n@uri\n(no information available).", {'@uri': uri });
var message = Drupal.t('An error occurred. \n@uri\n(no information available).', { '@uri': uri });
}
}
else {
var message = Drupal.t("An HTTP error @status occurred. \n@uri", {'@uri': uri, '@status': xmlhttp.status });
var message = Drupal.t('An HTTP error @status occurred. \n@uri', { '@uri': uri, '@status': xmlhttp.status });
}
return message.replace(/\n/g, '<br />');
};
......
......@@ -20,7 +20,7 @@ $.fn.setSummary = function(callback) {
var that = this;
// To facilitate things, the callback should always be a function. If it's
// not, we wrap it into an anonymous function which just returns the value.
// not, we wrap it into an anonymous function which just returns the value.
if (typeof callback != 'function') {
var val = callback;
callback = function() { return val; };
......@@ -63,7 +63,7 @@ Drupal.behaviors.multiselectSelector = {
// Automatically selects the right radio button in a multiselect control.
$('.multiselect select:not(.multiselectSelector-processed)', context)
.addClass('multiselectSelector-processed').change(function() {
$('.multiselect input:radio[value="'+ this.id.substr(5) +'"]')
$('.multiselect input:radio[value="' + this.id.substr(5) + '"]')
.attr('checked', true);
});
}
......@@ -79,7 +79,7 @@ Drupal.behaviors.filterGuidelines = {
.addClass('filter-guidelines-processed')
.find('label').hide()
.parents('.filter-wrapper').find('select.filter-list')
.bind('change', function () {
.bind('change', function() {
$(this).parents('.filter-wrapper')
.find('.filter-guidelines-item').hide()
.siblings('#filter-guidelines-' + this.value).show();
......
......@@ -11,28 +11,26 @@
* e.g. pb = new progressBar('myProgressBar');
* some_element.appendChild(pb.element);
*/
Drupal.progressBar = function (id, updateCallback, method, errorCallback) {
Drupal.progressBar = function(id, updateCallback, method, errorCallback) {
var pb = this;
this.id = id;
this.method = method || "GET";
this.method = method || 'GET';
this.updateCallback = updateCallback;
this.errorCallback = errorCallback;
this.element = document.createElement('div');
this.element.id = id;
this.element.className = 'progress';
$(this.element).html('<div class="bar"><div class="filled"></div></div>'+
'<div class="percentage"></div>'+
'<div class="message">&nbsp;</div>');
this.element = $('<div class="progress"></div>').attr('id', id);
this.element.html('<div class="bar"><div class="filled"></div></div>' +
'<div class="percentage"></div>' +
'<div class="message">&nbsp;</div>');
};
/**
* Set the percentage and status message for the progressbar.
*/
Drupal.progressBar.prototype.setProgress = function (percentage, message) {
Drupal.progressBar.prototype.setProgress = function(percentage, message) {
if (percentage >= 0 && percentage <= 100) {
$('div.filled', this.element).css('width', percentage +'%');
$('div.percentage', this.element).html(percentage +'%');
$('div.filled', this.element).css('width', percentage + '%');
$('div.percentage', this.element).html(percentage + '%');
}
$('div.message', this.element).html(message);
if (this.updateCallback) {
......@@ -43,7 +41,7 @@ Drupal.progressBar.prototype.setProgress = function (percentage, message) {
/**
* Start monitoring progress via Ajax.
*/
Drupal.progressBar.prototype.startMonitoring = function (uri, delay) {
Drupal.progressBar.prototype.startMonitoring = function(uri, delay) {
this.delay = delay;
this.uri = uri;
this.sendPing();
......@@ -52,7 +50,7 @@ Drupal.progressBar.prototype.startMonitoring = function (uri, delay) {
/**
* Stop monitoring progress via Ajax.
*/
Drupal.progressBar.prototype.stopMonitoring = function () {
Drupal.progressBar.prototype.stopMonitoring = function() {
clearTimeout(this.timer);
// This allows monitoring to be stopped from within the callback.
this.uri = null;
......@@ -61,7 +59,7 @@ Drupal.progressBar.prototype.stopMonitoring = function () {
/**
* Request progress data from server.
*/
Drupal.progressBar.prototype.sendPing = function () {
Drupal.progressBar.prototype.sendPing = function() {
if (this.timer) {
clearTimeout(this.timer);
}
......@@ -74,7 +72,7 @@ Drupal.progressBar.prototype.sendPing = function () {
url: this.uri,
data: '',
dataType: 'json',
success: function (progress) {
success: function(progress) {
// Display errors.
if (progress.status == 0) {
pb.displayError(progress.data);
......@@ -85,7 +83,7 @@ Drupal.progressBar.prototype.sendPing = function () {
// Schedule next timer.
pb.timer = setTimeout(function() { pb.sendPing(); }, pb.delay);
},
error: function (xmlhttp) {
error: function(xmlhttp) {
pb.displayError(Drupal.ahahError(xmlhttp, pb.uri));
}
});
......@@ -95,11 +93,8 @@ Drupal.progressBar.prototype.sendPing = function () {
/**
* Display errors on the page.
*/
Drupal.progressBar.prototype.displayError = function (string) {
var error = document.createElement('div');
error.className = 'error';
error.innerHTML = string;
Drupal.progressBar.prototype.displayError = function(string) {
var error = $('<div class="error"></div>').html(string);
$(this.element).before(error).hide();
if (this.errorCallback) {
......
......@@ -64,11 +64,11 @@ Drupal.tableDrag = function(table, tableSettings) {
this.indentEnabled = false;
for (group in tableSettings) {
for (n in tableSettings[group]) {
if (tableSettings[group][n]['relationship'] == 'parent') {
if (tableSettings[group][n].relationship == 'parent') {
this.indentEnabled = true;
}
if (tableSettings[group][n]['limit'] > 0) {
this.maxDepth = tableSettings[group][n]['limit'];
if (tableSettings[group][n].limit > 0) {
this.maxDepth = tableSettings[group][n].limit;
}
}
}
......@@ -100,13 +100,13 @@ Drupal.tableDrag = function(table, tableSettings) {
* Hide the columns containing form elements according to the settings for
* this tableDrag instance.
*/
Drupal.tableDrag.prototype.hideColumns = function(){
Drupal.tableDrag.prototype.hideColumns = function() {
for (var group in this.tableSettings) {
// 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']) {
var hidden = this.tableSettings[group][d]['hidden'];
var field = $('.' + this.tableSettings[group][d].target + ':first', this.table);
if (field.size() && this.tableSettings[group][d].hidden) {
var hidden = this.tableSettings[group][d].hidden;
var cell = field.parents('td:first');
break;
}
......@@ -117,7 +117,7 @@ Drupal.tableDrag.prototype.hideColumns = function(){
// Add 1 to our indexes. The nth-child selector is 1 based, not 0 based.
var columnIndex = $('td', cell.parent()).index(cell.get(0)) + 1;
var headerIndex = $('td:not(:hidden)', cell.parent()).index(cell.get(0)) + 1;
$('tr', this.table).each(function(){
$('tr', this.table).each(function() {
var row = $(this);
var parentTag = row.parent().get(0).tagName.toLowerCase();
var index = (parentTag == 'thead') ? headerIndex : columnIndex;
......@@ -151,10 +151,10 @@ Drupal.tableDrag.prototype.hideColumns = function(){
Drupal.tableDrag.prototype.rowSettings = function(group, row) {
var field = $('.' + group, row);
for (delta in this.tableSettings[group]) {
var targetClass = this.tableSettings[group][delta]['target'];
var targetClass = this.tableSettings[group][delta].target;
if (field.is('.' + targetClass)) {
// Return a copy of the row settings.
var rowSettings = new Object();
var rowSettings = {};
for (var n in this.tableSettings[group][delta]) {
rowSettings[n] = this.tableSettings[group][delta][n];
}
......@@ -190,7 +190,7 @@ Drupal.tableDrag.prototype.makeDraggable = function(item) {
// Add the mousedown action for the handle.
handle.mousedown(function(event) {
// Create a new dragObject recording the event information.
self.dragObject = new Object();
self.dragObject = {};
self.dragObject.initMouseOffset = self.getMouseOffset(item, event);
self.dragObject.initMouseCoords = self.mouseCoords(event);
if (self.indentEnabled) {
......@@ -322,7 +322,7 @@ Drupal.tableDrag.prototype.makeDraggable = function(item) {
var groupHeight = 0;
nextGroup = new self.row(nextRow, 'keyboard', self.indentEnabled, self.maxDepth, false);
if (nextGroup) {
$(nextGroup.group).each(function () {
$(nextGroup.group).each(function() {
groupHeight += $(this).is(':hidden') ? 0 : this.offsetHeight;
});
nextGroupRow = $(nextGroup.group).filter(':last').get(0);
......@@ -488,13 +488,13 @@ Drupal.tableDrag.prototype.dropRow = function(event, self) {
/**
* Get the mouse coordinates from the event (allowing for browser differences).
*/
Drupal.tableDrag.prototype.mouseCoords = function(event){
Drupal.tableDrag.prototype.mouseCoords = function(event) {
if (event.pageX || event.pageY) {
return {x:event.pageX, y:event.pageY};
return { x: event.pageX, y: event.pageY };
}
return {
x:event.clientX + document.body.scrollLeft - document.body.clientLeft,
y:event.clientY + document.body.scrollTop - document.body.clientTop
x: event.clientX + document.body.scrollLeft - document.body.clientLeft,
y: event.clientY + document.body.scrollTop - document.body.clientTop
};
};
......@@ -519,7 +519,7 @@ Drupal.tableDrag.prototype.getMouseOffset = function(target, event) {
*/
Drupal.tableDrag.prototype.findDropTargetRow = function(x, y) {
var rows = this.table.tBodies[0].rows;
for (var n=0; n<rows.length; n++) {
for (var n = 0; n < rows.length; n++) {
var row = rows[n];
var indentDiff = 0;