1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189 |
- (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) {
-
-
-
-
- var clientX = event.clientX || event.originalEvent.clientX;
- var clientY = event.clientY || event.originalEvent.clientY;
- if (event.pageX || event.pageY) {
- return { x: event.pageX, y: event.pageY };
- }
- return {
- x: clientX + document.body.scrollLeft - document.body.clientLeft,
- y: clientY + document.body.scrollTop - document.body.clientTop
- };
- };
- 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);
|