12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211 |
- (function ($) {
- Drupal.behaviors.tableDrag = {
- attach: function (context, settings) {
- for (var base in settings.tableDrag) {
- $('#' + base, context).once('tabledrag', function () {
-
-
- Drupal.tableDrag[base] = new Drupal.tableDrag(this, settings.tableDrag[base]);
- });
- }
- }
- };
- Drupal.tableDrag = function (table, tableSettings) {
- var self = this;
-
- this.table = table;
- this.tableSettings = tableSettings;
- this.dragObject = null;
- this.rowObject = null;
- this.oldRowElement = null;
- this.oldY = 0;
- this.changed = false;
- this.maxDepth = 0;
- this.rtl = $(this.table).css('direction') == 'rtl' ? -1 : 1;
-
- this.scrollSettings = { amount: 4, interval: 50, trigger: 70 };
- this.scrollInterval = null;
- this.scrollY = 0;
- this.windowHeight = 0;
-
-
-
- this.indentEnabled = false;
- for (var group in tableSettings) {
- for (var n in tableSettings[group]) {
- if (tableSettings[group][n].relationship == 'parent') {
- this.indentEnabled = true;
- }
- if (tableSettings[group][n].limit > 0) {
- this.maxDepth = tableSettings[group][n].limit;
- }
- }
- }
- if (this.indentEnabled) {
- this.indentCount = 1;
-
-
-
-
- var indent = Drupal.theme('tableDragIndentation');
- var testRow = $('<tr/>').addClass('draggable').appendTo(table);
- var testCell = $('<td/>').appendTo(testRow).prepend(indent).prepend(indent);
- this.indentAmount = $('.indentation', testCell).get(1).offsetLeft - $('.indentation', testCell).get(0).offsetLeft;
- testRow.remove();
- }
-
-
- $('> tr.draggable, > tbody > tr.draggable', table).each(function () { self.makeDraggable(this); });
-
- $(table).before($('<a href="#" class="tabledrag-toggle-weight"></a>')
- .attr('title', Drupal.t('Re-order rows by numerical weight instead of dragging.'))
- .click(function () {
- if ($.cookie('Drupal.tableDrag.showWeight') == 1) {
- self.hideColumns();
- }
- else {
- self.showColumns();
- }
- return false;
- })
- .wrap('<div class="tabledrag-toggle-weight-wrapper"></div>')
- .parent()
- );
-
-
-
-
- self.initColumns();
-
-
- $(document).bind('mousemove pointermove', function (event) { return self.dragRow(event, self); });
- $(document).bind('mouseup pointerup', function (event) { return self.dropRow(event, self); });
- $(document).bind('touchmove', function (event) { return self.dragRow(event.originalEvent.touches[0], self); });
- $(document).bind('touchend', function (event) { return self.dropRow(event.originalEvent.touches[0], self); });
- };
- Drupal.tableDrag.prototype.initColumns = function () {
- for (var group in this.tableSettings) {
-
- for (var d in this.tableSettings[group]) {
- var field = $('.' + this.tableSettings[group][d].target + ':first', this.table);
- if (field.length && this.tableSettings[group][d].hidden) {
- var hidden = this.tableSettings[group][d].hidden;
- var cell = field.closest('td');
- break;
- }
- }
-
- if (hidden && cell[0]) {
-
-
- var columnIndex = $('> td', cell.parent()).index(cell.get(0)) + 1;
- $('> thead > tr, > tbody > tr, > tr', this.table).each(function () {
-
- var index = columnIndex;
- var cells = $(this).children();
- cells.each(function (n) {
- if (n < index && this.colSpan && this.colSpan > 1) {
- index -= this.colSpan - 1;
- }
- });
- if (index > 0) {
- cell = cells.filter(':nth-child(' + index + ')');
- if (cell[0].colSpan && cell[0].colSpan > 1) {
-
- cell.addClass('tabledrag-has-colspan');
- }
- else {
-
- cell.addClass('tabledrag-hide');
- }
- }
- });
- }
- }
-
-
- if ($.cookie('Drupal.tableDrag.showWeight') === null) {
- $.cookie('Drupal.tableDrag.showWeight', 0, {
- path: Drupal.settings.basePath,
-
- expires: 365
- });
- this.hideColumns();
- }
-
- else {
- if ($.cookie('Drupal.tableDrag.showWeight') == 1) {
- this.showColumns();
- }
- else {
- this.hideColumns();
- }
- }
- };
- Drupal.tableDrag.prototype.hideColumns = function () {
-
- $('.tabledrag-hide', 'table.tabledrag-processed').css('display', 'none');
-
- $('.tabledrag-handle', 'table.tabledrag-processed').css('display', '');
-
- $('.tabledrag-has-colspan', 'table.tabledrag-processed').each(function () {
- this.colSpan = this.colSpan - 1;
- });
-
- $('.tabledrag-toggle-weight').text(Drupal.t('Show row weights'));
-
- $.cookie('Drupal.tableDrag.showWeight', 0, {
- path: Drupal.settings.basePath,
-
- expires: 365
- });
-
- $('table.tabledrag-processed').trigger('columnschange', 'hide');
- };
- Drupal.tableDrag.prototype.showColumns = function () {
-
- $('.tabledrag-hide', 'table.tabledrag-processed').css('display', '');
-
- $('.tabledrag-handle', 'table.tabledrag-processed').css('display', 'none');
-
- $('.tabledrag-has-colspan', 'table.tabledrag-processed').each(function () {
- this.colSpan = this.colSpan + 1;
- });
-
- $('.tabledrag-toggle-weight').text(Drupal.t('Hide row weights'));
-
- $.cookie('Drupal.tableDrag.showWeight', 1, {
- path: Drupal.settings.basePath,
-
- expires: 365
- });
-
- $('table.tabledrag-processed').trigger('columnschange', 'show');
- };
- Drupal.tableDrag.prototype.rowSettings = function (group, row) {
- var field = $('.' + group, row);
- for (var delta in this.tableSettings[group]) {
- var targetClass = this.tableSettings[group][delta].target;
- if (field.is('.' + targetClass)) {
-
- var rowSettings = {};
- for (var n in this.tableSettings[group][delta]) {
- rowSettings[n] = this.tableSettings[group][delta][n];
- }
- return rowSettings;
- }
- }
- };
- Drupal.tableDrag.prototype.makeDraggable = function (item) {
- var self = this;
-
- var handle = $('<a href="#" class="tabledrag-handle"><div class="handle"> </div></a>').attr('title', Drupal.t('Drag to re-order'));
-
- if ($('td:first .indentation:last', item).length) {
- $('td:first .indentation:last', item).after(handle);
-
- self.indentCount = Math.max($('.indentation', item).length, self.indentCount);
- }
- else {
- $('td:first', item).prepend(handle);
- }
-
- handle.hover(function () {
- self.dragObject == null ? $(this).addClass('tabledrag-handle-hover') : null;
- }, function () {
- self.dragObject == null ? $(this).removeClass('tabledrag-handle-hover') : null;
- });
-
- handle.bind('mousedown touchstart pointerdown', function (event) {
- if (event.originalEvent.type == "touchstart") {
- event = event.originalEvent.touches[0];
- }
-
- self.dragObject = {};
- self.dragObject.initMouseOffset = self.getMouseOffset(item, event);
- self.dragObject.initMouseCoords = self.mouseCoords(event);
- if (self.indentEnabled) {
- self.dragObject.indentMousePos = self.dragObject.initMouseCoords;
- }
-
- if (self.rowObject) {
- $('a.tabledrag-handle', self.rowObject.element).blur();
- }
-
- self.rowObject = new self.row(item, 'mouse', self.indentEnabled, self.maxDepth, true);
-
- self.table.topY = $(self.table).offset().top;
- self.table.bottomY = self.table.topY + self.table.offsetHeight;
-
- $(this).addClass('tabledrag-handle-hover');
- $(item).addClass('drag');
-
- $('body').addClass('drag');
- if (self.oldRowElement) {
- $(self.oldRowElement).removeClass('drag-previous');
- }
-
- if (navigator.userAgent.indexOf('MSIE 6.') != -1) {
- $('select', this.table).css('display', 'none');
- }
-
-
- self.safeBlur = false;
-
- self.onDrag();
- return false;
- });
-
- handle.click(function () {
- return false;
- });
-
- handle.focus(function () {
- $(this).addClass('tabledrag-handle-hover');
- self.safeBlur = true;
- });
-
- handle.blur(function (event) {
- $(this).removeClass('tabledrag-handle-hover');
- if (self.rowObject && self.safeBlur) {
- self.dropRow(event, self);
- }
- });
-
- handle.keydown(function (event) {
-
- if (event.keyCode != 9 && !self.rowObject) {
- self.rowObject = new self.row(item, 'keyboard', self.indentEnabled, self.maxDepth, true);
- }
- var keyChange = false;
- switch (event.keyCode) {
- case 37:
- case 63234:
- keyChange = true;
- self.rowObject.indent(-1 * self.rtl);
- break;
- case 38:
- case 63232:
- var previousRow = $(self.rowObject.element).prev('tr').get(0);
- while (previousRow && $(previousRow).is(':hidden')) {
- previousRow = $(previousRow).prev('tr').get(0);
- }
- if (previousRow) {
- self.safeBlur = false;
- self.rowObject.direction = 'up';
- keyChange = true;
- if ($(item).is('.tabledrag-root')) {
-
- var groupHeight = 0;
- while (previousRow && $('.indentation', previousRow).length) {
- previousRow = $(previousRow).prev('tr').get(0);
- groupHeight += $(previousRow).is(':hidden') ? 0 : previousRow.offsetHeight;
- }
- if (previousRow) {
- self.rowObject.swap('before', previousRow);
-
- window.scrollBy(0, -groupHeight);
- }
- }
- else if (self.table.tBodies[0].rows[0] != previousRow || $(previousRow).is('.draggable')) {
-
-
- self.rowObject.swap('before', previousRow);
- self.rowObject.interval = null;
- self.rowObject.indent(0);
- window.scrollBy(0, -parseInt(item.offsetHeight, 10));
- }
- handle.get(0).focus();
- }
- break;
- case 39:
- case 63235:
- keyChange = true;
- self.rowObject.indent(1 * self.rtl);
- break;
- case 40:
- case 63233:
- var nextRow = $(self.rowObject.group).filter(':last').next('tr').get(0);
- while (nextRow && $(nextRow).is(':hidden')) {
- nextRow = $(nextRow).next('tr').get(0);
- }
- if (nextRow) {
- self.safeBlur = false;
- self.rowObject.direction = 'down';
- keyChange = true;
- if ($(item).is('.tabledrag-root')) {
-
- var groupHeight = 0;
- 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;
- });
- var nextGroupRow = $(nextGroup.group).filter(':last').get(0);
- self.rowObject.swap('after', nextGroupRow);
-
- window.scrollBy(0, parseInt(groupHeight, 10));
- }
- }
- else {
-
- self.rowObject.swap('after', nextRow);
- self.rowObject.interval = null;
- self.rowObject.indent(0);
- window.scrollBy(0, parseInt(item.offsetHeight, 10));
- }
- handle.get(0).focus();
- }
- break;
- }
- if (self.rowObject && self.rowObject.changed == true) {
- $(item).addClass('drag');
- if (self.oldRowElement) {
- $(self.oldRowElement).removeClass('drag-previous');
- }
- self.oldRowElement = item;
- self.restripeTable();
- self.onDrag();
- }
-
- if (keyChange) {
- return false;
- }
- });
-
-
-
- handle.keypress(function (event) {
- switch (event.keyCode) {
- case 37:
- case 38:
- case 39:
- case 40:
- return false;
- }
- });
- };
- Drupal.tableDrag.prototype.dragRow = function (event, self) {
- if (self.dragObject) {
- self.currentMouseCoords = self.mouseCoords(event);
- var y = self.currentMouseCoords.y - self.dragObject.initMouseOffset.y;
- var x = self.currentMouseCoords.x - self.dragObject.initMouseOffset.x;
-
- if (y != self.oldY) {
- self.rowObject.direction = y > self.oldY ? 'down' : 'up';
- self.oldY = y;
-
- var scrollAmount = self.checkScroll(self.currentMouseCoords.y);
-
- clearInterval(self.scrollInterval);
-
- if (scrollAmount > 0 && self.rowObject.direction == 'down' || scrollAmount < 0 && self.rowObject.direction == 'up') {
- self.setScroll(scrollAmount);
- }
-
- var currentRow = self.findDropTargetRow(x, y);
- if (currentRow) {
- if (self.rowObject.direction == 'down') {
- self.rowObject.swap('after', currentRow, self);
- }
- else {
- self.rowObject.swap('before', currentRow, self);
- }
- self.restripeTable();
- }
- }
-
- if (self.indentEnabled) {
- var xDiff = self.currentMouseCoords.x - self.dragObject.indentMousePos.x;
-
- var indentDiff = Math.round(xDiff / self.indentAmount);
-
-
- var indentChange = self.rowObject.indent(indentDiff);
-
- self.dragObject.indentMousePos.x += self.indentAmount * indentChange * self.rtl;
- self.indentCount = Math.max(self.indentCount, self.rowObject.indents);
- }
- return false;
- }
- };
- Drupal.tableDrag.prototype.dropRow = function (event, self) {
-
- if (self.rowObject != null) {
- var droppedRow = self.rowObject.element;
-
- if (self.rowObject.changed == true) {
-
- self.updateFields(droppedRow);
-
-
- for (var group in self.tableSettings) {
- var rowSettings = self.rowSettings(group, droppedRow);
- if (rowSettings.relationship == 'group') {
- for (var n in self.rowObject.children) {
- self.updateField(self.rowObject.children[n], group);
- }
- }
- }
- self.rowObject.markChanged();
- if (self.changed == false) {
- $(Drupal.theme('tableDragChangedWarning')).insertBefore(self.table).hide().fadeIn('slow');
- self.changed = true;
- }
- }
- if (self.indentEnabled) {
- self.rowObject.removeIndentClasses();
- }
- if (self.oldRowElement) {
- $(self.oldRowElement).removeClass('drag-previous');
- }
- $(droppedRow).removeClass('drag').addClass('drag-previous');
- self.oldRowElement = droppedRow;
- self.onDrop();
- self.rowObject = null;
- }
-
- if (self.dragObject != null) {
- $('.tabledrag-handle', droppedRow).removeClass('tabledrag-handle-hover');
- self.dragObject = null;
- $('body').removeClass('drag');
- clearInterval(self.scrollInterval);
-
- if (navigator.userAgent.indexOf('MSIE 6.') != -1) {
- $('select', this.table).css('display', 'block');
- }
- }
- };
- Drupal.tableDrag.prototype.mouseCoords = function (event) {
-
-
- if (event.pageX != null && event.pageY != null) {
- return {x: event.pageX, y: event.pageY};
- }
-
-
-
-
- if (event.originalEvent && event.originalEvent.pageX != null && event.originalEvent.pageY != null) {
- return {x: event.originalEvent.pageX, y: event.originalEvent.pageY};
- }
-
-
-
- if (event.clientX == null || event.clientY == null) {
-
-
- if (!event.originalEvent) {
- throw new Error("The event has no coordinates, and no event.originalEvent.");
- }
- event = event.originalEvent;
- if (event.clientX == null || event.clientY == null) {
- throw new Error("The original event has no coordinates.");
- }
- }
-
-
- var doc = document.documentElement, body = document.body;
- var pageX = event.clientX + ( doc && doc.scrollLeft || body && body.scrollLeft || 0 ) - ( doc && doc.clientLeft || body && body.clientLeft || 0 );
- var pageY = event.clientY + ( doc && doc.scrollTop || body && body.scrollTop || 0 ) - ( doc && doc.clientTop || body && body.clientTop || 0 );
- return {x: pageX, y: pageY};
- };
- Drupal.tableDrag.prototype.getMouseOffset = function (target, event) {
- var docPos = $(target).offset();
- var mousePos = this.mouseCoords(event);
- return { x: mousePos.x - docPos.left, y: mousePos.y - docPos.top };
- };
- Drupal.tableDrag.prototype.findDropTargetRow = function (x, y) {
- var rows = $(this.table.tBodies[0].rows).not(':hidden');
- for (var n = 0; n < rows.length; n++) {
- var row = rows[n];
- var indentDiff = 0;
- var rowY = $(row).offset().top;
-
-
-
- if (row.offsetHeight == 0) {
- var rowHeight = parseInt(row.firstChild.offsetHeight, 10) / 2;
- }
-
- else {
- var rowHeight = parseInt(row.offsetHeight, 10) / 2;
- }
-
- if ((y > (rowY - rowHeight)) && (y < (rowY + rowHeight))) {
- if (this.indentEnabled) {
-
- for (var n in this.rowObject.group) {
- if (this.rowObject.group[n] == row) {
- return null;
- }
- }
- }
- else {
-
- if (row == this.rowObject.element) {
- return null;
- }
- }
-
- if (!this.rowObject.isValidSwap(row)) {
- return null;
- }
-
-
-
- while ($(row).is(':hidden') && $(row).prev('tr').is(':hidden')) {
- row = $(row).prev('tr').get(0);
- }
- return row;
- }
- }
- return null;
- };
- Drupal.tableDrag.prototype.updateFields = function (changedRow) {
- for (var group in this.tableSettings) {
-
-
- this.updateField(changedRow, group);
- }
- };
- Drupal.tableDrag.prototype.updateField = function (changedRow, group) {
- var rowSettings = this.rowSettings(group, changedRow);
-
- if (rowSettings.relationship == 'self' || rowSettings.relationship == 'group') {
- var sourceRow = changedRow;
- }
-
- else if (rowSettings.relationship == 'sibling') {
- var previousRow = $(changedRow).prev('tr').get(0);
- var nextRow = $(changedRow).next('tr').get(0);
- var sourceRow = changedRow;
- if ($(previousRow).is('.draggable') && $('.' + group, previousRow).length) {
- if (this.indentEnabled) {
- if ($('.indentations', previousRow).length == $('.indentations', changedRow)) {
- sourceRow = previousRow;
- }
- }
- else {
- sourceRow = previousRow;
- }
- }
- else if ($(nextRow).is('.draggable') && $('.' + group, nextRow).length) {
- if (this.indentEnabled) {
- if ($('.indentations', nextRow).length == $('.indentations', changedRow)) {
- sourceRow = nextRow;
- }
- }
- else {
- sourceRow = nextRow;
- }
- }
- }
-
-
- else if (rowSettings.relationship == 'parent') {
- var previousRow = $(changedRow).prev('tr');
- while (previousRow.length && $('.indentation', previousRow).length >= this.rowObject.indents) {
- previousRow = previousRow.prev('tr');
- }
-
- if (previousRow.length) {
- sourceRow = previousRow[0];
- }
-
-
- else {
-
-
-
- sourceRow = $(this.table).find('tr.draggable:first').get(0);
- if (sourceRow == this.rowObject.element) {
- sourceRow = $(this.rowObject.group[this.rowObject.group.length - 1]).next('tr.draggable').get(0);
- }
- var useSibling = true;
- }
- }
-
-
- this.copyDragClasses(sourceRow, changedRow, group);
- rowSettings = this.rowSettings(group, changedRow);
-
-
- if (useSibling) {
- rowSettings.relationship = 'sibling';
- rowSettings.source = rowSettings.target;
- }
- var targetClass = '.' + rowSettings.target;
- var targetElement = $(targetClass, changedRow).get(0);
-
- if (targetElement) {
- var sourceClass = '.' + rowSettings.source;
- var sourceElement = $(sourceClass, sourceRow).get(0);
- switch (rowSettings.action) {
- case 'depth':
-
- targetElement.value = $('.indentation', $(sourceElement).closest('tr')).length;
- break;
- case 'match':
-
- targetElement.value = sourceElement.value;
- break;
- case 'order':
- var siblings = this.rowObject.findSiblings(rowSettings);
- if ($(targetElement).is('select')) {
-
- var values = [];
- $('option', targetElement).each(function () {
- values.push(this.value);
- });
- var maxVal = values[values.length - 1];
-
- $(targetClass, siblings).each(function () {
-
- if (values.length > 0) {
- this.value = values.shift();
- }
- else {
- this.value = maxVal;
- }
- });
- }
- else {
-
- var weight = parseInt($(targetClass, siblings[0]).val(), 10) || 0;
- $(targetClass, siblings).each(function () {
- this.value = weight;
- weight++;
- });
- }
- break;
- }
- }
- };
- Drupal.tableDrag.prototype.copyDragClasses = function (sourceRow, targetRow, group) {
- var sourceElement = $('.' + group, sourceRow);
- var targetElement = $('.' + group, targetRow);
- if (sourceElement.length && targetElement.length) {
- targetElement[0].className = sourceElement[0].className;
- }
- };
- Drupal.tableDrag.prototype.checkScroll = function (cursorY) {
- var de = document.documentElement;
- var b = document.body;
- var windowHeight = this.windowHeight = window.innerHeight || (de.clientHeight && de.clientWidth != 0 ? de.clientHeight : b.offsetHeight);
- var scrollY = this.scrollY = (document.all ? (!de.scrollTop ? b.scrollTop : de.scrollTop) : (window.pageYOffset ? window.pageYOffset : window.scrollY));
- var trigger = this.scrollSettings.trigger;
- var delta = 0;
-
- if (cursorY - scrollY > windowHeight - trigger) {
- delta = trigger / (windowHeight + scrollY - cursorY);
- delta = (delta > 0 && delta < trigger) ? delta : trigger;
- return delta * this.scrollSettings.amount;
- }
- else if (cursorY - scrollY < trigger) {
- delta = trigger / (cursorY - scrollY);
- delta = (delta > 0 && delta < trigger) ? delta : trigger;
- return -delta * this.scrollSettings.amount;
- }
- };
- Drupal.tableDrag.prototype.setScroll = function (scrollAmount) {
- var self = this;
- this.scrollInterval = setInterval(function () {
-
- self.checkScroll(self.currentMouseCoords.y);
- var aboveTable = self.scrollY > self.table.topY;
- var belowTable = self.scrollY + self.windowHeight < self.table.bottomY;
- if (scrollAmount > 0 && belowTable || scrollAmount < 0 && aboveTable) {
- window.scrollBy(0, scrollAmount);
- }
- }, this.scrollSettings.interval);
- };
- Drupal.tableDrag.prototype.restripeTable = function () {
-
-
-
- $('> tbody > tr.draggable:visible, > tr.draggable:visible', this.table)
- .removeClass('odd even')
- .filter(':odd').addClass('even').end()
- .filter(':even').addClass('odd');
- };
- Drupal.tableDrag.prototype.onDrag = function () {
- return null;
- };
- Drupal.tableDrag.prototype.onDrop = function () {
- return null;
- };
- Drupal.tableDrag.prototype.row = function (tableRow, method, indentEnabled, maxDepth, addClasses) {
- this.element = tableRow;
- this.method = method;
- this.group = [tableRow];
- this.groupDepth = $('.indentation', tableRow).length;
- this.changed = false;
- this.table = $(tableRow).closest('table').get(0);
- this.indentEnabled = indentEnabled;
- this.maxDepth = maxDepth;
- this.direction = '';
- if (this.indentEnabled) {
- this.indents = $('.indentation', tableRow).length;
- this.children = this.findChildren(addClasses);
- this.group = $.merge(this.group, this.children);
-
- for (var n = 0; n < this.group.length; n++) {
- this.groupDepth = Math.max($('.indentation', this.group[n]).length, this.groupDepth);
- }
- }
- };
- Drupal.tableDrag.prototype.row.prototype.findChildren = function (addClasses) {
- var parentIndentation = this.indents;
- var currentRow = $(this.element, this.table).next('tr.draggable');
- var rows = [];
- var child = 0;
- while (currentRow.length) {
- var rowIndentation = $('.indentation', currentRow).length;
-
- if (rowIndentation > parentIndentation) {
- child++;
- rows.push(currentRow[0]);
- if (addClasses) {
- $('.indentation', currentRow).each(function (indentNum) {
- if (child == 1 && (indentNum == parentIndentation)) {
- $(this).addClass('tree-child-first');
- }
- if (indentNum == parentIndentation) {
- $(this).addClass('tree-child');
- }
- else if (indentNum > parentIndentation) {
- $(this).addClass('tree-child-horizontal');
- }
- });
- }
- }
- else {
- break;
- }
- currentRow = currentRow.next('tr.draggable');
- }
- if (addClasses && rows.length) {
- $('.indentation:nth-child(' + (parentIndentation + 1) + ')', rows[rows.length - 1]).addClass('tree-child-last');
- }
- return rows;
- };
- Drupal.tableDrag.prototype.row.prototype.isValidSwap = function (row) {
- if (this.indentEnabled) {
- var prevRow, nextRow;
- if (this.direction == 'down') {
- prevRow = row;
- nextRow = $(row).next('tr').get(0);
- }
- else {
- prevRow = $(row).prev('tr').get(0);
- nextRow = row;
- }
- this.interval = this.validIndentInterval(prevRow, nextRow);
-
- if (this.interval.min > this.interval.max) {
- return false;
- }
- }
-
- if (this.table.tBodies[0].rows[0] == row && $(row).is(':not(.draggable)')) {
- return false;
- }
- return true;
- };
- Drupal.tableDrag.prototype.row.prototype.swap = function (position, row) {
- Drupal.detachBehaviors(this.group, Drupal.settings, 'move');
- $(row)[position](this.group);
- Drupal.attachBehaviors(this.group, Drupal.settings);
- this.changed = true;
- this.onSwap(row);
- };
- Drupal.tableDrag.prototype.row.prototype.validIndentInterval = function (prevRow, nextRow) {
- var minIndent, maxIndent;
-
-
- minIndent = nextRow ? $('.indentation', nextRow).length : 0;
-
- if (!prevRow || $(prevRow).is(':not(.draggable)') || $(this.element).is('.tabledrag-root')) {
-
-
-
-
- maxIndent = 0;
- }
- else {
-
- maxIndent = $('.indentation', prevRow).length + ($(prevRow).is('.tabledrag-leaf') ? 0 : 1);
-
- if (this.maxDepth) {
- maxIndent = Math.min(maxIndent, this.maxDepth - (this.groupDepth - this.indents));
- }
- }
- return { 'min': minIndent, 'max': maxIndent };
- };
- Drupal.tableDrag.prototype.row.prototype.indent = function (indentDiff) {
-
- if (!this.interval) {
- var prevRow = $(this.element).prev('tr').get(0);
- var nextRow = $(this.group).filter(':last').next('tr').get(0);
- this.interval = this.validIndentInterval(prevRow, nextRow);
- }
-
- var indent = this.indents + indentDiff;
- indent = Math.max(indent, this.interval.min);
- indent = Math.min(indent, this.interval.max);
- indentDiff = indent - this.indents;
- for (var n = 1; n <= Math.abs(indentDiff); n++) {
-
- if (indentDiff < 0) {
- $('.indentation:first', this.group).remove();
- this.indents--;
- }
- else {
- $('td:first', this.group).prepend(Drupal.theme('tableDragIndentation'));
- this.indents++;
- }
- }
- if (indentDiff) {
-
- this.changed = true;
- this.groupDepth += indentDiff;
- this.onIndent();
- }
- return indentDiff;
- };
- Drupal.tableDrag.prototype.row.prototype.findSiblings = function (rowSettings) {
- var siblings = [];
- var directions = ['prev', 'next'];
- var rowIndentation = this.indents;
- for (var d = 0; d < directions.length; d++) {
- var checkRow = $(this.element)[directions[d]]();
- while (checkRow.length) {
-
- if ($('.' + rowSettings.target, checkRow)) {
-
-
- if (this.indentEnabled) {
- var checkRowIndentation = $('.indentation', checkRow).length;
- }
- if (!(this.indentEnabled) || (checkRowIndentation == rowIndentation)) {
- siblings.push(checkRow[0]);
- }
- else if (checkRowIndentation < rowIndentation) {
-
- break;
- }
- }
- else {
- break;
- }
- checkRow = $(checkRow)[directions[d]]();
- }
-
-
- if (directions[d] == 'prev') {
- siblings.reverse();
- siblings.push(this.element);
- }
- }
- return siblings;
- };
- Drupal.tableDrag.prototype.row.prototype.removeIndentClasses = function () {
- for (var n in this.children) {
- $('.indentation', this.children[n])
- .removeClass('tree-child')
- .removeClass('tree-child-first')
- .removeClass('tree-child-last')
- .removeClass('tree-child-horizontal');
- }
- };
- Drupal.tableDrag.prototype.row.prototype.markChanged = function () {
- var marker = Drupal.theme('tableDragChangedMarker');
- var cell = $('td:first', this.element);
- if ($('span.tabledrag-changed', cell).length == 0) {
- cell.append(marker);
- }
- };
- Drupal.tableDrag.prototype.row.prototype.onIndent = function () {
- return null;
- };
- Drupal.tableDrag.prototype.row.prototype.onSwap = function (swappedRow) {
- return null;
- };
- Drupal.theme.prototype.tableDragChangedMarker = function () {
- return '<span class="warning tabledrag-changed">*</span>';
- };
- Drupal.theme.prototype.tableDragIndentation = function () {
- return '<div class="indentation"> </div>';
- };
- Drupal.theme.prototype.tableDragChangedWarning = function () {
- return '<div class="tabledrag-changed-warning messages warning">' + Drupal.theme('tableDragChangedMarker') + ' ' + Drupal.t('Changes made in this table will not be saved until the form is submitted.') + '</div>';
- };
- })(jQuery);
|