tabledrag.js 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212
  1. (function ($) {
  2. /**
  3. * Drag and drop table rows with field manipulation.
  4. *
  5. * Using the drupal_add_tabledrag() function, any table with weights or parent
  6. * relationships may be made into draggable tables. Columns containing a field
  7. * may optionally be hidden, providing a better user experience.
  8. *
  9. * Created tableDrag instances may be modified with custom behaviors by
  10. * overriding the .onDrag, .onDrop, .row.onSwap, and .row.onIndent methods.
  11. * See blocks.js for an example of adding additional functionality to tableDrag.
  12. */
  13. Drupal.behaviors.tableDrag = {
  14. attach: function (context, settings) {
  15. for (var base in settings.tableDrag) {
  16. $('#' + base, context).once('tabledrag', function () {
  17. // Create the new tableDrag instance. Save in the Drupal variable
  18. // to allow other scripts access to the object.
  19. Drupal.tableDrag[base] = new Drupal.tableDrag(this, settings.tableDrag[base]);
  20. });
  21. }
  22. }
  23. };
  24. /**
  25. * Constructor for the tableDrag object. Provides table and field manipulation.
  26. *
  27. * @param table
  28. * DOM object for the table to be made draggable.
  29. * @param tableSettings
  30. * Settings for the table added via drupal_add_dragtable().
  31. */
  32. Drupal.tableDrag = function (table, tableSettings) {
  33. var self = this;
  34. // Required object variables.
  35. this.table = table;
  36. this.tableSettings = tableSettings;
  37. this.dragObject = null; // Used to hold information about a current drag operation.
  38. this.rowObject = null; // Provides operations for row manipulation.
  39. this.oldRowElement = null; // Remember the previous element.
  40. this.oldY = 0; // Used to determine up or down direction from last mouse move.
  41. this.changed = false; // Whether anything in the entire table has changed.
  42. this.maxDepth = 0; // Maximum amount of allowed parenting.
  43. this.rtl = $(this.table).css('direction') == 'rtl' ? -1 : 1; // Direction of the table.
  44. // Configure the scroll settings.
  45. this.scrollSettings = { amount: 4, interval: 50, trigger: 70 };
  46. this.scrollInterval = null;
  47. this.scrollY = 0;
  48. this.windowHeight = 0;
  49. // Check this table's settings to see if there are parent relationships in
  50. // this table. For efficiency, large sections of code can be skipped if we
  51. // don't need to track horizontal movement and indentations.
  52. this.indentEnabled = false;
  53. for (var group in tableSettings) {
  54. for (var n in tableSettings[group]) {
  55. if (tableSettings[group][n].relationship == 'parent') {
  56. this.indentEnabled = true;
  57. }
  58. if (tableSettings[group][n].limit > 0) {
  59. this.maxDepth = tableSettings[group][n].limit;
  60. }
  61. }
  62. }
  63. if (this.indentEnabled) {
  64. this.indentCount = 1; // Total width of indents, set in makeDraggable.
  65. // Find the width of indentations to measure mouse movements against.
  66. // Because the table doesn't need to start with any indentations, we
  67. // manually append 2 indentations in the first draggable row, measure
  68. // the offset, then remove.
  69. var indent = Drupal.theme('tableDragIndentation');
  70. var testRow = $('<tr/>').addClass('draggable').appendTo(table);
  71. var testCell = $('<td/>').appendTo(testRow).prepend(indent).prepend(indent);
  72. this.indentAmount = $('.indentation', testCell).get(1).offsetLeft - $('.indentation', testCell).get(0).offsetLeft;
  73. testRow.remove();
  74. }
  75. // Make each applicable row draggable.
  76. // Match immediate children of the parent element to allow nesting.
  77. $('> tr.draggable, > tbody > tr.draggable', table).each(function () { self.makeDraggable(this); });
  78. // Add a link before the table for users to show or hide weight columns.
  79. $(table).before($('<a href="#" class="tabledrag-toggle-weight"></a>')
  80. .attr('title', Drupal.t('Re-order rows by numerical weight instead of dragging.'))
  81. .click(function () {
  82. if ($.cookie('Drupal.tableDrag.showWeight') == 1) {
  83. self.hideColumns();
  84. }
  85. else {
  86. self.showColumns();
  87. }
  88. return false;
  89. })
  90. .wrap('<div class="tabledrag-toggle-weight-wrapper"></div>')
  91. .parent()
  92. );
  93. // Initialize the specified columns (for example, weight or parent columns)
  94. // to show or hide according to user preference. This aids accessibility
  95. // so that, e.g., screen reader users can choose to enter weight values and
  96. // manipulate form elements directly, rather than using drag-and-drop..
  97. self.initColumns();
  98. // Add mouse bindings to the document. The self variable is passed along
  99. // as event handlers do not have direct access to the tableDrag object.
  100. $(document).bind('mousemove pointermove', function (event) { return self.dragRow(event, self); });
  101. $(document).bind('mouseup pointerup', function (event) { return self.dropRow(event, self); });
  102. $(document).bind('touchmove', function (event) { return self.dragRow(event.originalEvent.touches[0], self); });
  103. $(document).bind('touchend', function (event) { return self.dropRow(event.originalEvent.touches[0], self); });
  104. };
  105. /**
  106. * Initialize columns containing form elements to be hidden by default,
  107. * according to the settings for this tableDrag instance.
  108. *
  109. * Identify and mark each cell with a CSS class so we can easily toggle
  110. * show/hide it. Finally, hide columns if user does not have a
  111. * 'Drupal.tableDrag.showWeight' cookie.
  112. */
  113. Drupal.tableDrag.prototype.initColumns = function () {
  114. for (var group in this.tableSettings) {
  115. // Find the first field in this group.
  116. for (var d in this.tableSettings[group]) {
  117. var field = $('.' + this.tableSettings[group][d].target + ':first', this.table);
  118. if (field.length && this.tableSettings[group][d].hidden) {
  119. var hidden = this.tableSettings[group][d].hidden;
  120. var cell = field.closest('td');
  121. break;
  122. }
  123. }
  124. // Mark the column containing this field so it can be hidden.
  125. if (hidden && cell[0]) {
  126. // Add 1 to our indexes. The nth-child selector is 1 based, not 0 based.
  127. // Match immediate children of the parent element to allow nesting.
  128. var columnIndex = $('> td', cell.parent()).index(cell.get(0)) + 1;
  129. $('> thead > tr, > tbody > tr, > tr', this.table).each(function () {
  130. // Get the columnIndex and adjust for any colspans in this row.
  131. var index = columnIndex;
  132. var cells = $(this).children();
  133. cells.each(function (n) {
  134. if (n < index && this.colSpan && this.colSpan > 1) {
  135. index -= this.colSpan - 1;
  136. }
  137. });
  138. if (index > 0) {
  139. cell = cells.filter(':nth-child(' + index + ')');
  140. if (cell[0].colSpan && cell[0].colSpan > 1) {
  141. // If this cell has a colspan, mark it so we can reduce the colspan.
  142. cell.addClass('tabledrag-has-colspan');
  143. }
  144. else {
  145. // Mark this cell so we can hide it.
  146. cell.addClass('tabledrag-hide');
  147. }
  148. }
  149. });
  150. }
  151. }
  152. // Now hide cells and reduce colspans unless cookie indicates previous choice.
  153. // Set a cookie if it is not already present.
  154. if ($.cookie('Drupal.tableDrag.showWeight') === null) {
  155. $.cookie('Drupal.tableDrag.showWeight', 0, {
  156. // Workaround lack of support for the SameSite attribute in jQuery Cookie.
  157. path: Drupal.settings.basePath + '; SameSite=Lax',
  158. // The cookie expires in one year.
  159. expires: 365
  160. });
  161. this.hideColumns();
  162. }
  163. // Check cookie value and show/hide weight columns accordingly.
  164. else {
  165. if ($.cookie('Drupal.tableDrag.showWeight') == 1) {
  166. this.showColumns();
  167. }
  168. else {
  169. this.hideColumns();
  170. }
  171. }
  172. };
  173. /**
  174. * Hide the columns containing weight/parent form elements.
  175. * Undo showColumns().
  176. */
  177. Drupal.tableDrag.prototype.hideColumns = function () {
  178. // Hide weight/parent cells and headers.
  179. $('.tabledrag-hide', 'table.tabledrag-processed').css('display', 'none');
  180. // Show TableDrag handles.
  181. $('.tabledrag-handle', 'table.tabledrag-processed').css('display', '');
  182. // Reduce the colspan of any effected multi-span columns.
  183. $('.tabledrag-has-colspan', 'table.tabledrag-processed').each(function () {
  184. this.colSpan = this.colSpan - 1;
  185. });
  186. // Change link text.
  187. $('.tabledrag-toggle-weight').text(Drupal.t('Show row weights'));
  188. // Change cookie (including workaround for SameSite attribute).
  189. $.cookie('Drupal.tableDrag.showWeight', 0, {
  190. path: Drupal.settings.basePath + '; SameSite=Lax',
  191. // The cookie expires in one year.
  192. expires: 365
  193. });
  194. // Trigger an event to allow other scripts to react to this display change.
  195. $('table.tabledrag-processed').trigger('columnschange', 'hide');
  196. };
  197. /**
  198. * Show the columns containing weight/parent form elements
  199. * Undo hideColumns().
  200. */
  201. Drupal.tableDrag.prototype.showColumns = function () {
  202. // Show weight/parent cells and headers.
  203. $('.tabledrag-hide', 'table.tabledrag-processed').css('display', '');
  204. // Hide TableDrag handles.
  205. $('.tabledrag-handle', 'table.tabledrag-processed').css('display', 'none');
  206. // Increase the colspan for any columns where it was previously reduced.
  207. $('.tabledrag-has-colspan', 'table.tabledrag-processed').each(function () {
  208. this.colSpan = this.colSpan + 1;
  209. });
  210. // Change link text.
  211. $('.tabledrag-toggle-weight').text(Drupal.t('Hide row weights'));
  212. // Change cookie (including workaround for SameSite attribute).
  213. $.cookie('Drupal.tableDrag.showWeight', 1, {
  214. path: Drupal.settings.basePath + '; SameSite=Lax',
  215. // The cookie expires in one year.
  216. expires: 365
  217. });
  218. // Trigger an event to allow other scripts to react to this display change.
  219. $('table.tabledrag-processed').trigger('columnschange', 'show');
  220. };
  221. /**
  222. * Find the target used within a particular row and group.
  223. */
  224. Drupal.tableDrag.prototype.rowSettings = function (group, row) {
  225. var field = $('.' + group, row);
  226. for (var delta in this.tableSettings[group]) {
  227. var targetClass = this.tableSettings[group][delta].target;
  228. if (field.is('.' + targetClass)) {
  229. // Return a copy of the row settings.
  230. var rowSettings = {};
  231. for (var n in this.tableSettings[group][delta]) {
  232. rowSettings[n] = this.tableSettings[group][delta][n];
  233. }
  234. return rowSettings;
  235. }
  236. }
  237. };
  238. /**
  239. * Take an item and add event handlers to make it become draggable.
  240. */
  241. Drupal.tableDrag.prototype.makeDraggable = function (item) {
  242. var self = this;
  243. // Create the handle.
  244. var handle = $('<a href="#" class="tabledrag-handle"><div class="handle">&nbsp;</div></a>').attr('title', Drupal.t('Drag to re-order'));
  245. // Insert the handle after indentations (if any).
  246. if ($('td:first .indentation:last', item).length) {
  247. $('td:first .indentation:last', item).after(handle);
  248. // Update the total width of indentation in this entire table.
  249. self.indentCount = Math.max($('.indentation', item).length, self.indentCount);
  250. }
  251. else {
  252. $('td:first', item).prepend(handle);
  253. }
  254. // Add hover action for the handle.
  255. handle.hover(function () {
  256. self.dragObject == null ? $(this).addClass('tabledrag-handle-hover') : null;
  257. }, function () {
  258. self.dragObject == null ? $(this).removeClass('tabledrag-handle-hover') : null;
  259. });
  260. // Add the mousedown action for the handle.
  261. handle.bind('mousedown touchstart pointerdown', function (event) {
  262. if (event.originalEvent.type == "touchstart") {
  263. event = event.originalEvent.touches[0];
  264. }
  265. // Create a new dragObject recording the event information.
  266. self.dragObject = {};
  267. self.dragObject.initMouseOffset = self.getMouseOffset(item, event);
  268. self.dragObject.initMouseCoords = self.mouseCoords(event);
  269. if (self.indentEnabled) {
  270. self.dragObject.indentMousePos = self.dragObject.initMouseCoords;
  271. }
  272. // If there's a lingering row object from the keyboard, remove its focus.
  273. if (self.rowObject) {
  274. $('a.tabledrag-handle', self.rowObject.element).blur();
  275. }
  276. // Create a new rowObject for manipulation of this row.
  277. self.rowObject = new self.row(item, 'mouse', self.indentEnabled, self.maxDepth, true);
  278. // Save the position of the table.
  279. self.table.topY = $(self.table).offset().top;
  280. self.table.bottomY = self.table.topY + self.table.offsetHeight;
  281. // Add classes to the handle and row.
  282. $(this).addClass('tabledrag-handle-hover');
  283. $(item).addClass('drag');
  284. // Set the document to use the move cursor during drag.
  285. $('body').addClass('drag');
  286. if (self.oldRowElement) {
  287. $(self.oldRowElement).removeClass('drag-previous');
  288. }
  289. // Hack for IE6 that flickers uncontrollably if select lists are moved.
  290. if (navigator.userAgent.indexOf('MSIE 6.') != -1) {
  291. $('select', this.table).css('display', 'none');
  292. }
  293. // Hack for Konqueror, prevent the blur handler from firing.
  294. // Konqueror always gives links focus, even after returning false on mousedown.
  295. self.safeBlur = false;
  296. // Call optional placeholder function.
  297. self.onDrag();
  298. return false;
  299. });
  300. // Prevent the anchor tag from jumping us to the top of the page.
  301. handle.click(function () {
  302. return false;
  303. });
  304. // Similar to the hover event, add a class when the handle is focused.
  305. handle.focus(function () {
  306. $(this).addClass('tabledrag-handle-hover');
  307. self.safeBlur = true;
  308. });
  309. // Remove the handle class on blur and fire the same function as a mouseup.
  310. handle.blur(function (event) {
  311. $(this).removeClass('tabledrag-handle-hover');
  312. if (self.rowObject && self.safeBlur) {
  313. self.dropRow(event, self);
  314. }
  315. });
  316. // Add arrow-key support to the handle.
  317. handle.keydown(function (event) {
  318. // If a rowObject doesn't yet exist and this isn't the tab key.
  319. if (event.keyCode != 9 && !self.rowObject) {
  320. self.rowObject = new self.row(item, 'keyboard', self.indentEnabled, self.maxDepth, true);
  321. }
  322. var keyChange = false;
  323. switch (event.keyCode) {
  324. case 37: // Left arrow.
  325. case 63234: // Safari left arrow.
  326. keyChange = true;
  327. self.rowObject.indent(-1 * self.rtl);
  328. break;
  329. case 38: // Up arrow.
  330. case 63232: // Safari up arrow.
  331. var previousRow = $(self.rowObject.element).prev('tr').get(0);
  332. while (previousRow && $(previousRow).is(':hidden')) {
  333. previousRow = $(previousRow).prev('tr').get(0);
  334. }
  335. if (previousRow) {
  336. self.safeBlur = false; // Do not allow the onBlur cleanup.
  337. self.rowObject.direction = 'up';
  338. keyChange = true;
  339. if ($(item).is('.tabledrag-root')) {
  340. // Swap with the previous top-level row.
  341. var groupHeight = 0;
  342. while (previousRow && $('.indentation', previousRow).length) {
  343. previousRow = $(previousRow).prev('tr').get(0);
  344. groupHeight += $(previousRow).is(':hidden') ? 0 : previousRow.offsetHeight;
  345. }
  346. if (previousRow) {
  347. self.rowObject.swap('before', previousRow);
  348. // No need to check for indentation, 0 is the only valid one.
  349. window.scrollBy(0, -groupHeight);
  350. }
  351. }
  352. else if (self.table.tBodies[0].rows[0] != previousRow || $(previousRow).is('.draggable')) {
  353. // Swap with the previous row (unless previous row is the first one
  354. // and undraggable).
  355. self.rowObject.swap('before', previousRow);
  356. self.rowObject.interval = null;
  357. self.rowObject.indent(0);
  358. window.scrollBy(0, -parseInt(item.offsetHeight, 10));
  359. }
  360. handle.get(0).focus(); // Regain focus after the DOM manipulation.
  361. }
  362. break;
  363. case 39: // Right arrow.
  364. case 63235: // Safari right arrow.
  365. keyChange = true;
  366. self.rowObject.indent(1 * self.rtl);
  367. break;
  368. case 40: // Down arrow.
  369. case 63233: // Safari down arrow.
  370. var nextRow = $(self.rowObject.group).filter(':last').next('tr').get(0);
  371. while (nextRow && $(nextRow).is(':hidden')) {
  372. nextRow = $(nextRow).next('tr').get(0);
  373. }
  374. if (nextRow) {
  375. self.safeBlur = false; // Do not allow the onBlur cleanup.
  376. self.rowObject.direction = 'down';
  377. keyChange = true;
  378. if ($(item).is('.tabledrag-root')) {
  379. // Swap with the next group (necessarily a top-level one).
  380. var groupHeight = 0;
  381. var nextGroup = new self.row(nextRow, 'keyboard', self.indentEnabled, self.maxDepth, false);
  382. if (nextGroup) {
  383. $(nextGroup.group).each(function () {
  384. groupHeight += $(this).is(':hidden') ? 0 : this.offsetHeight;
  385. });
  386. var nextGroupRow = $(nextGroup.group).filter(':last').get(0);
  387. self.rowObject.swap('after', nextGroupRow);
  388. // No need to check for indentation, 0 is the only valid one.
  389. window.scrollBy(0, parseInt(groupHeight, 10));
  390. }
  391. }
  392. else {
  393. // Swap with the next row.
  394. self.rowObject.swap('after', nextRow);
  395. self.rowObject.interval = null;
  396. self.rowObject.indent(0);
  397. window.scrollBy(0, parseInt(item.offsetHeight, 10));
  398. }
  399. handle.get(0).focus(); // Regain focus after the DOM manipulation.
  400. }
  401. break;
  402. }
  403. if (self.rowObject && self.rowObject.changed == true) {
  404. $(item).addClass('drag');
  405. if (self.oldRowElement) {
  406. $(self.oldRowElement).removeClass('drag-previous');
  407. }
  408. self.oldRowElement = item;
  409. self.restripeTable();
  410. self.onDrag();
  411. }
  412. // Returning false if we have an arrow key to prevent scrolling.
  413. if (keyChange) {
  414. return false;
  415. }
  416. });
  417. // Compatibility addition, return false on keypress to prevent unwanted scrolling.
  418. // IE and Safari will suppress scrolling on keydown, but all other browsers
  419. // need to return false on keypress. http://www.quirksmode.org/js/keys.html
  420. handle.keypress(function (event) {
  421. switch (event.keyCode) {
  422. case 37: // Left arrow.
  423. case 38: // Up arrow.
  424. case 39: // Right arrow.
  425. case 40: // Down arrow.
  426. return false;
  427. }
  428. });
  429. };
  430. /**
  431. * Mousemove event handler, bound to document.
  432. */
  433. Drupal.tableDrag.prototype.dragRow = function (event, self) {
  434. if (self.dragObject) {
  435. self.currentMouseCoords = self.mouseCoords(event);
  436. var y = self.currentMouseCoords.y - self.dragObject.initMouseOffset.y;
  437. var x = self.currentMouseCoords.x - self.dragObject.initMouseOffset.x;
  438. // Check for row swapping and vertical scrolling.
  439. if (y != self.oldY) {
  440. self.rowObject.direction = y > self.oldY ? 'down' : 'up';
  441. self.oldY = y; // Update the old value.
  442. // Check if the window should be scrolled (and how fast).
  443. var scrollAmount = self.checkScroll(self.currentMouseCoords.y);
  444. // Stop any current scrolling.
  445. clearInterval(self.scrollInterval);
  446. // Continue scrolling if the mouse has moved in the scroll direction.
  447. if (scrollAmount > 0 && self.rowObject.direction == 'down' || scrollAmount < 0 && self.rowObject.direction == 'up') {
  448. self.setScroll(scrollAmount);
  449. }
  450. // If we have a valid target, perform the swap and restripe the table.
  451. var currentRow = self.findDropTargetRow(x, y);
  452. if (currentRow) {
  453. if (self.rowObject.direction == 'down') {
  454. self.rowObject.swap('after', currentRow, self);
  455. }
  456. else {
  457. self.rowObject.swap('before', currentRow, self);
  458. }
  459. self.restripeTable();
  460. }
  461. }
  462. // Similar to row swapping, handle indentations.
  463. if (self.indentEnabled) {
  464. var xDiff = self.currentMouseCoords.x - self.dragObject.indentMousePos.x;
  465. // Set the number of indentations the mouse has been moved left or right.
  466. var indentDiff = Math.round(xDiff / self.indentAmount);
  467. // Indent the row with our estimated diff, which may be further
  468. // restricted according to the rows around this row.
  469. var indentChange = self.rowObject.indent(indentDiff);
  470. // Update table and mouse indentations.
  471. self.dragObject.indentMousePos.x += self.indentAmount * indentChange * self.rtl;
  472. self.indentCount = Math.max(self.indentCount, self.rowObject.indents);
  473. }
  474. return false;
  475. }
  476. };
  477. /**
  478. * Mouseup event handler, bound to document.
  479. * Blur event handler, bound to drag handle for keyboard support.
  480. */
  481. Drupal.tableDrag.prototype.dropRow = function (event, self) {
  482. // Drop row functionality shared between mouseup and blur events.
  483. if (self.rowObject != null) {
  484. var droppedRow = self.rowObject.element;
  485. // The row is already in the right place so we just release it.
  486. if (self.rowObject.changed == true) {
  487. // Update the fields in the dropped row.
  488. self.updateFields(droppedRow);
  489. // If a setting exists for affecting the entire group, update all the
  490. // fields in the entire dragged group.
  491. for (var group in self.tableSettings) {
  492. var rowSettings = self.rowSettings(group, droppedRow);
  493. if (rowSettings.relationship == 'group') {
  494. for (var n in self.rowObject.children) {
  495. self.updateField(self.rowObject.children[n], group);
  496. }
  497. }
  498. }
  499. self.rowObject.markChanged();
  500. if (self.changed == false) {
  501. $(Drupal.theme('tableDragChangedWarning')).insertBefore(self.table).hide().fadeIn('slow');
  502. self.changed = true;
  503. }
  504. }
  505. if (self.indentEnabled) {
  506. self.rowObject.removeIndentClasses();
  507. }
  508. if (self.oldRowElement) {
  509. $(self.oldRowElement).removeClass('drag-previous');
  510. }
  511. $(droppedRow).removeClass('drag').addClass('drag-previous');
  512. self.oldRowElement = droppedRow;
  513. self.onDrop();
  514. self.rowObject = null;
  515. }
  516. // Functionality specific only to mouseup event.
  517. if (self.dragObject != null) {
  518. $('.tabledrag-handle', droppedRow).removeClass('tabledrag-handle-hover');
  519. self.dragObject = null;
  520. $('body').removeClass('drag');
  521. clearInterval(self.scrollInterval);
  522. // Hack for IE6 that flickers uncontrollably if select lists are moved.
  523. if (navigator.userAgent.indexOf('MSIE 6.') != -1) {
  524. $('select', this.table).css('display', 'block');
  525. }
  526. }
  527. };
  528. /**
  529. * Get the mouse coordinates from the event (allowing for browser differences).
  530. */
  531. Drupal.tableDrag.prototype.mouseCoords = function (event) {
  532. // Match both null and undefined, but not zero, by using != null.
  533. // See https://stackoverflow.com/questions/2647867/how-to-determine-if-variable-is-undefined-or-null
  534. if (event.pageX != null && event.pageY != null) {
  535. return {x: event.pageX, y: event.pageY};
  536. }
  537. // Complete support for pointer events was only introduced to jQuery in
  538. // version 1.11.1; between versions 1.7 and 1.11.0 pointer events have the
  539. // pageX and pageY properties undefined. In those cases, the properties must
  540. // be retrieved from the event.originalEvent object instead.
  541. if (event.originalEvent && event.originalEvent.pageX != null && event.originalEvent.pageY != null) {
  542. return {x: event.originalEvent.pageX, y: event.originalEvent.pageY};
  543. }
  544. // Some old browsers do not support MouseEvent.pageX and *.pageY at all.
  545. // See https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/pageY
  546. // For those, we look at event.clientX and event.clientY instead.
  547. if (event.clientX == null || event.clientY == null) {
  548. // In some jQuery versions, some events created by jQuery do not have
  549. // clientX and clientY. But the original event might have.
  550. if (!event.originalEvent) {
  551. throw new Error("The event has no coordinates, and no event.originalEvent.");
  552. }
  553. event = event.originalEvent;
  554. if (event.clientX == null || event.clientY == null) {
  555. throw new Error("The original event has no coordinates.");
  556. }
  557. }
  558. // Copied from jQuery.event.fix() in jQuery 1.4.1.
  559. // In newer jQuery versions, this code is in jQuery.event.mouseHooks.filter().
  560. var doc = document.documentElement, body = document.body;
  561. var pageX = event.clientX + ( doc && doc.scrollLeft || body && body.scrollLeft || 0 ) - ( doc && doc.clientLeft || body && body.clientLeft || 0 );
  562. var pageY = event.clientY + ( doc && doc.scrollTop || body && body.scrollTop || 0 ) - ( doc && doc.clientTop || body && body.clientTop || 0 );
  563. return {x: pageX, y: pageY};
  564. };
  565. /**
  566. * Given a target element and a mouse event, get the mouse offset from that
  567. * element. To do this we need the element's position and the mouse position.
  568. */
  569. Drupal.tableDrag.prototype.getMouseOffset = function (target, event) {
  570. var docPos = $(target).offset();
  571. var mousePos = this.mouseCoords(event);
  572. return { x: mousePos.x - docPos.left, y: mousePos.y - docPos.top };
  573. };
  574. /**
  575. * Find the row the mouse is currently over. This row is then taken and swapped
  576. * with the one being dragged.
  577. *
  578. * @param x
  579. * The x coordinate of the mouse on the page (not the screen).
  580. * @param y
  581. * The y coordinate of the mouse on the page (not the screen).
  582. */
  583. Drupal.tableDrag.prototype.findDropTargetRow = function (x, y) {
  584. var rows = $(this.table.tBodies[0].rows).not(':hidden');
  585. for (var n = 0; n < rows.length; n++) {
  586. var row = rows[n];
  587. var indentDiff = 0;
  588. var rowY = $(row).offset().top;
  589. // Because Safari does not report offsetHeight on table rows, but does on
  590. // table cells, grab the firstChild of the row and use that instead.
  591. // http://jacob.peargrove.com/blog/2006/technical/table-row-offsettop-bug-in-safari.
  592. if (row.offsetHeight == 0) {
  593. var rowHeight = parseInt(row.firstChild.offsetHeight, 10) / 2;
  594. }
  595. // Other browsers.
  596. else {
  597. var rowHeight = parseInt(row.offsetHeight, 10) / 2;
  598. }
  599. // Because we always insert before, we need to offset the height a bit.
  600. if ((y > (rowY - rowHeight)) && (y < (rowY + rowHeight))) {
  601. if (this.indentEnabled) {
  602. // Check that this row is not a child of the row being dragged.
  603. for (var n in this.rowObject.group) {
  604. if (this.rowObject.group[n] == row) {
  605. return null;
  606. }
  607. }
  608. }
  609. else {
  610. // Do not allow a row to be swapped with itself.
  611. if (row == this.rowObject.element) {
  612. return null;
  613. }
  614. }
  615. // Check that swapping with this row is allowed.
  616. if (!this.rowObject.isValidSwap(row)) {
  617. return null;
  618. }
  619. // We may have found the row the mouse just passed over, but it doesn't
  620. // take into account hidden rows. Skip backwards until we find a draggable
  621. // row.
  622. while ($(row).is(':hidden') && $(row).prev('tr').is(':hidden')) {
  623. row = $(row).prev('tr').get(0);
  624. }
  625. return row;
  626. }
  627. }
  628. return null;
  629. };
  630. /**
  631. * After the row is dropped, update the table fields according to the settings
  632. * set for this table.
  633. *
  634. * @param changedRow
  635. * DOM object for the row that was just dropped.
  636. */
  637. Drupal.tableDrag.prototype.updateFields = function (changedRow) {
  638. for (var group in this.tableSettings) {
  639. // Each group may have a different setting for relationship, so we find
  640. // the source rows for each separately.
  641. this.updateField(changedRow, group);
  642. }
  643. };
  644. /**
  645. * After the row is dropped, update a single table field according to specific
  646. * settings.
  647. *
  648. * @param changedRow
  649. * DOM object for the row that was just dropped.
  650. * @param group
  651. * The settings group on which field updates will occur.
  652. */
  653. Drupal.tableDrag.prototype.updateField = function (changedRow, group) {
  654. var rowSettings = this.rowSettings(group, changedRow);
  655. // Set the row as its own target.
  656. if (rowSettings.relationship == 'self' || rowSettings.relationship == 'group') {
  657. var sourceRow = changedRow;
  658. }
  659. // Siblings are easy, check previous and next rows.
  660. else if (rowSettings.relationship == 'sibling') {
  661. var previousRow = $(changedRow).prev('tr').get(0);
  662. var nextRow = $(changedRow).next('tr').get(0);
  663. var sourceRow = changedRow;
  664. if ($(previousRow).is('.draggable') && $('.' + group, previousRow).length) {
  665. if (this.indentEnabled) {
  666. if ($('.indentations', previousRow).length == $('.indentations', changedRow)) {
  667. sourceRow = previousRow;
  668. }
  669. }
  670. else {
  671. sourceRow = previousRow;
  672. }
  673. }
  674. else if ($(nextRow).is('.draggable') && $('.' + group, nextRow).length) {
  675. if (this.indentEnabled) {
  676. if ($('.indentations', nextRow).length == $('.indentations', changedRow)) {
  677. sourceRow = nextRow;
  678. }
  679. }
  680. else {
  681. sourceRow = nextRow;
  682. }
  683. }
  684. }
  685. // Parents, look up the tree until we find a field not in this group.
  686. // Go up as many parents as indentations in the changed row.
  687. else if (rowSettings.relationship == 'parent') {
  688. var previousRow = $(changedRow).prev('tr');
  689. while (previousRow.length && $('.indentation', previousRow).length >= this.rowObject.indents) {
  690. previousRow = previousRow.prev('tr');
  691. }
  692. // If we found a row.
  693. if (previousRow.length) {
  694. sourceRow = previousRow[0];
  695. }
  696. // Otherwise we went all the way to the left of the table without finding
  697. // a parent, meaning this item has been placed at the root level.
  698. else {
  699. // Use the first row in the table as source, because it's guaranteed to
  700. // be at the root level. Find the first item, then compare this row
  701. // against it as a sibling.
  702. sourceRow = $(this.table).find('tr.draggable:first').get(0);
  703. if (sourceRow == this.rowObject.element) {
  704. sourceRow = $(this.rowObject.group[this.rowObject.group.length - 1]).next('tr.draggable').get(0);
  705. }
  706. var useSibling = true;
  707. }
  708. }
  709. // Because we may have moved the row from one category to another,
  710. // take a look at our sibling and borrow its sources and targets.
  711. this.copyDragClasses(sourceRow, changedRow, group);
  712. rowSettings = this.rowSettings(group, changedRow);
  713. // In the case that we're looking for a parent, but the row is at the top
  714. // of the tree, copy our sibling's values.
  715. if (useSibling) {
  716. rowSettings.relationship = 'sibling';
  717. rowSettings.source = rowSettings.target;
  718. }
  719. var targetClass = '.' + rowSettings.target;
  720. var targetElement = $(targetClass, changedRow).get(0);
  721. // Check if a target element exists in this row.
  722. if (targetElement) {
  723. var sourceClass = '.' + rowSettings.source;
  724. var sourceElement = $(sourceClass, sourceRow).get(0);
  725. switch (rowSettings.action) {
  726. case 'depth':
  727. // Get the depth of the target row.
  728. targetElement.value = $('.indentation', $(sourceElement).closest('tr')).length;
  729. break;
  730. case 'match':
  731. // Update the value.
  732. targetElement.value = sourceElement.value;
  733. break;
  734. case 'order':
  735. var siblings = this.rowObject.findSiblings(rowSettings);
  736. if ($(targetElement).is('select')) {
  737. // Get a list of acceptable values.
  738. var values = [];
  739. $('option', targetElement).each(function () {
  740. values.push(this.value);
  741. });
  742. var maxVal = values[values.length - 1];
  743. // Populate the values in the siblings.
  744. $(targetClass, siblings).each(function () {
  745. // If there are more items than possible values, assign the maximum value to the row.
  746. if (values.length > 0) {
  747. this.value = values.shift();
  748. }
  749. else {
  750. this.value = maxVal;
  751. }
  752. });
  753. }
  754. else {
  755. // Assume a numeric input field.
  756. var weight = parseInt($(targetClass, siblings[0]).val(), 10) || 0;
  757. $(targetClass, siblings).each(function () {
  758. this.value = weight;
  759. weight++;
  760. });
  761. }
  762. break;
  763. }
  764. }
  765. };
  766. /**
  767. * Copy all special tableDrag classes from one row's form elements to a
  768. * different one, removing any special classes that the destination row
  769. * may have had.
  770. */
  771. Drupal.tableDrag.prototype.copyDragClasses = function (sourceRow, targetRow, group) {
  772. var sourceElement = $('.' + group, sourceRow);
  773. var targetElement = $('.' + group, targetRow);
  774. if (sourceElement.length && targetElement.length) {
  775. targetElement[0].className = sourceElement[0].className;
  776. }
  777. };
  778. Drupal.tableDrag.prototype.checkScroll = function (cursorY) {
  779. var de = document.documentElement;
  780. var b = document.body;
  781. var windowHeight = this.windowHeight = window.innerHeight || (de.clientHeight && de.clientWidth != 0 ? de.clientHeight : b.offsetHeight);
  782. var scrollY = this.scrollY = (document.all ? (!de.scrollTop ? b.scrollTop : de.scrollTop) : (window.pageYOffset ? window.pageYOffset : window.scrollY));
  783. var trigger = this.scrollSettings.trigger;
  784. var delta = 0;
  785. // Return a scroll speed relative to the edge of the screen.
  786. if (cursorY - scrollY > windowHeight - trigger) {
  787. delta = trigger / (windowHeight + scrollY - cursorY);
  788. delta = (delta > 0 && delta < trigger) ? delta : trigger;
  789. return delta * this.scrollSettings.amount;
  790. }
  791. else if (cursorY - scrollY < trigger) {
  792. delta = trigger / (cursorY - scrollY);
  793. delta = (delta > 0 && delta < trigger) ? delta : trigger;
  794. return -delta * this.scrollSettings.amount;
  795. }
  796. };
  797. Drupal.tableDrag.prototype.setScroll = function (scrollAmount) {
  798. var self = this;
  799. this.scrollInterval = setInterval(function () {
  800. // Update the scroll values stored in the object.
  801. self.checkScroll(self.currentMouseCoords.y);
  802. var aboveTable = self.scrollY > self.table.topY;
  803. var belowTable = self.scrollY + self.windowHeight < self.table.bottomY;
  804. if (scrollAmount > 0 && belowTable || scrollAmount < 0 && aboveTable) {
  805. window.scrollBy(0, scrollAmount);
  806. }
  807. }, this.scrollSettings.interval);
  808. };
  809. Drupal.tableDrag.prototype.restripeTable = function () {
  810. // :even and :odd are reversed because jQuery counts from 0 and
  811. // we count from 1, so we're out of sync.
  812. // Match immediate children of the parent element to allow nesting.
  813. $('> tbody > tr.draggable:visible, > tr.draggable:visible', this.table)
  814. .removeClass('odd even')
  815. .filter(':odd').addClass('even').end()
  816. .filter(':even').addClass('odd');
  817. };
  818. /**
  819. * Stub function. Allows a custom handler when a row begins dragging.
  820. */
  821. Drupal.tableDrag.prototype.onDrag = function () {
  822. return null;
  823. };
  824. /**
  825. * Stub function. Allows a custom handler when a row is dropped.
  826. */
  827. Drupal.tableDrag.prototype.onDrop = function () {
  828. return null;
  829. };
  830. /**
  831. * Constructor to make a new object to manipulate a table row.
  832. *
  833. * @param tableRow
  834. * The DOM element for the table row we will be manipulating.
  835. * @param method
  836. * The method in which this row is being moved. Either 'keyboard' or 'mouse'.
  837. * @param indentEnabled
  838. * Whether the containing table uses indentations. Used for optimizations.
  839. * @param maxDepth
  840. * The maximum amount of indentations this row may contain.
  841. * @param addClasses
  842. * Whether we want to add classes to this row to indicate child relationships.
  843. */
  844. Drupal.tableDrag.prototype.row = function (tableRow, method, indentEnabled, maxDepth, addClasses) {
  845. this.element = tableRow;
  846. this.method = method;
  847. this.group = [tableRow];
  848. this.groupDepth = $('.indentation', tableRow).length;
  849. this.changed = false;
  850. this.table = $(tableRow).closest('table').get(0);
  851. this.indentEnabled = indentEnabled;
  852. this.maxDepth = maxDepth;
  853. this.direction = ''; // Direction the row is being moved.
  854. if (this.indentEnabled) {
  855. this.indents = $('.indentation', tableRow).length;
  856. this.children = this.findChildren(addClasses);
  857. this.group = $.merge(this.group, this.children);
  858. // Find the depth of this entire group.
  859. for (var n = 0; n < this.group.length; n++) {
  860. this.groupDepth = Math.max($('.indentation', this.group[n]).length, this.groupDepth);
  861. }
  862. }
  863. };
  864. /**
  865. * Find all children of rowObject by indentation.
  866. *
  867. * @param addClasses
  868. * Whether we want to add classes to this row to indicate child relationships.
  869. */
  870. Drupal.tableDrag.prototype.row.prototype.findChildren = function (addClasses) {
  871. var parentIndentation = this.indents;
  872. var currentRow = $(this.element, this.table).next('tr.draggable');
  873. var rows = [];
  874. var child = 0;
  875. while (currentRow.length) {
  876. var rowIndentation = $('.indentation', currentRow).length;
  877. // A greater indentation indicates this is a child.
  878. if (rowIndentation > parentIndentation) {
  879. child++;
  880. rows.push(currentRow[0]);
  881. if (addClasses) {
  882. $('.indentation', currentRow).each(function (indentNum) {
  883. if (child == 1 && (indentNum == parentIndentation)) {
  884. $(this).addClass('tree-child-first');
  885. }
  886. if (indentNum == parentIndentation) {
  887. $(this).addClass('tree-child');
  888. }
  889. else if (indentNum > parentIndentation) {
  890. $(this).addClass('tree-child-horizontal');
  891. }
  892. });
  893. }
  894. }
  895. else {
  896. break;
  897. }
  898. currentRow = currentRow.next('tr.draggable');
  899. }
  900. if (addClasses && rows.length) {
  901. $('.indentation:nth-child(' + (parentIndentation + 1) + ')', rows[rows.length - 1]).addClass('tree-child-last');
  902. }
  903. return rows;
  904. };
  905. /**
  906. * Ensure that two rows are allowed to be swapped.
  907. *
  908. * @param row
  909. * DOM object for the row being considered for swapping.
  910. */
  911. Drupal.tableDrag.prototype.row.prototype.isValidSwap = function (row) {
  912. if (this.indentEnabled) {
  913. var prevRow, nextRow;
  914. if (this.direction == 'down') {
  915. prevRow = row;
  916. nextRow = $(row).next('tr').get(0);
  917. }
  918. else {
  919. prevRow = $(row).prev('tr').get(0);
  920. nextRow = row;
  921. }
  922. this.interval = this.validIndentInterval(prevRow, nextRow);
  923. // We have an invalid swap if the valid indentations interval is empty.
  924. if (this.interval.min > this.interval.max) {
  925. return false;
  926. }
  927. }
  928. // Do not let an un-draggable first row have anything put before it.
  929. if (this.table.tBodies[0].rows[0] == row && $(row).is(':not(.draggable)')) {
  930. return false;
  931. }
  932. return true;
  933. };
  934. /**
  935. * Perform the swap between two rows.
  936. *
  937. * @param position
  938. * Whether the swap will occur 'before' or 'after' the given row.
  939. * @param row
  940. * DOM element what will be swapped with the row group.
  941. */
  942. Drupal.tableDrag.prototype.row.prototype.swap = function (position, row) {
  943. Drupal.detachBehaviors(this.group, Drupal.settings, 'move');
  944. $(row)[position](this.group);
  945. Drupal.attachBehaviors(this.group, Drupal.settings);
  946. this.changed = true;
  947. this.onSwap(row);
  948. };
  949. /**
  950. * Determine the valid indentations interval for the row at a given position
  951. * in the table.
  952. *
  953. * @param prevRow
  954. * DOM object for the row before the tested position
  955. * (or null for first position in the table).
  956. * @param nextRow
  957. * DOM object for the row after the tested position
  958. * (or null for last position in the table).
  959. */
  960. Drupal.tableDrag.prototype.row.prototype.validIndentInterval = function (prevRow, nextRow) {
  961. var minIndent, maxIndent;
  962. // Minimum indentation:
  963. // Do not orphan the next row.
  964. minIndent = nextRow ? $('.indentation', nextRow).length : 0;
  965. // Maximum indentation:
  966. if (!prevRow || $(prevRow).is(':not(.draggable)') || $(this.element).is('.tabledrag-root')) {
  967. // Do not indent:
  968. // - the first row in the table,
  969. // - rows dragged below a non-draggable row,
  970. // - 'root' rows.
  971. maxIndent = 0;
  972. }
  973. else {
  974. // Do not go deeper than as a child of the previous row.
  975. maxIndent = $('.indentation', prevRow).length + ($(prevRow).is('.tabledrag-leaf') ? 0 : 1);
  976. // Limit by the maximum allowed depth for the table.
  977. if (this.maxDepth) {
  978. maxIndent = Math.min(maxIndent, this.maxDepth - (this.groupDepth - this.indents));
  979. }
  980. }
  981. return { 'min': minIndent, 'max': maxIndent };
  982. };
  983. /**
  984. * Indent a row within the legal bounds of the table.
  985. *
  986. * @param indentDiff
  987. * The number of additional indentations proposed for the row (can be
  988. * positive or negative). This number will be adjusted to nearest valid
  989. * indentation level for the row.
  990. */
  991. Drupal.tableDrag.prototype.row.prototype.indent = function (indentDiff) {
  992. // Determine the valid indentations interval if not available yet.
  993. if (!this.interval) {
  994. var prevRow = $(this.element).prev('tr').get(0);
  995. var nextRow = $(this.group).filter(':last').next('tr').get(0);
  996. this.interval = this.validIndentInterval(prevRow, nextRow);
  997. }
  998. // Adjust to the nearest valid indentation.
  999. var indent = this.indents + indentDiff;
  1000. indent = Math.max(indent, this.interval.min);
  1001. indent = Math.min(indent, this.interval.max);
  1002. indentDiff = indent - this.indents;
  1003. for (var n = 1; n <= Math.abs(indentDiff); n++) {
  1004. // Add or remove indentations.
  1005. if (indentDiff < 0) {
  1006. $('.indentation:first', this.group).remove();
  1007. this.indents--;
  1008. }
  1009. else {
  1010. $('td:first', this.group).prepend(Drupal.theme('tableDragIndentation'));
  1011. this.indents++;
  1012. }
  1013. }
  1014. if (indentDiff) {
  1015. // Update indentation for this row.
  1016. this.changed = true;
  1017. this.groupDepth += indentDiff;
  1018. this.onIndent();
  1019. }
  1020. return indentDiff;
  1021. };
  1022. /**
  1023. * Find all siblings for a row, either according to its subgroup or indentation.
  1024. * Note that the passed-in row is included in the list of siblings.
  1025. *
  1026. * @param settings
  1027. * The field settings we're using to identify what constitutes a sibling.
  1028. */
  1029. Drupal.tableDrag.prototype.row.prototype.findSiblings = function (rowSettings) {
  1030. var siblings = [];
  1031. var directions = ['prev', 'next'];
  1032. var rowIndentation = this.indents;
  1033. for (var d = 0; d < directions.length; d++) {
  1034. var checkRow = $(this.element)[directions[d]]();
  1035. while (checkRow.length) {
  1036. // Check that the sibling contains a similar target field.
  1037. if ($('.' + rowSettings.target, checkRow)) {
  1038. // Either add immediately if this is a flat table, or check to ensure
  1039. // that this row has the same level of indentation.
  1040. if (this.indentEnabled) {
  1041. var checkRowIndentation = $('.indentation', checkRow).length;
  1042. }
  1043. if (!(this.indentEnabled) || (checkRowIndentation == rowIndentation)) {
  1044. siblings.push(checkRow[0]);
  1045. }
  1046. else if (checkRowIndentation < rowIndentation) {
  1047. // No need to keep looking for siblings when we get to a parent.
  1048. break;
  1049. }
  1050. }
  1051. else {
  1052. break;
  1053. }
  1054. checkRow = $(checkRow)[directions[d]]();
  1055. }
  1056. // Since siblings are added in reverse order for previous, reverse the
  1057. // completed list of previous siblings. Add the current row and continue.
  1058. if (directions[d] == 'prev') {
  1059. siblings.reverse();
  1060. siblings.push(this.element);
  1061. }
  1062. }
  1063. return siblings;
  1064. };
  1065. /**
  1066. * Remove indentation helper classes from the current row group.
  1067. */
  1068. Drupal.tableDrag.prototype.row.prototype.removeIndentClasses = function () {
  1069. for (var n in this.children) {
  1070. $('.indentation', this.children[n])
  1071. .removeClass('tree-child')
  1072. .removeClass('tree-child-first')
  1073. .removeClass('tree-child-last')
  1074. .removeClass('tree-child-horizontal');
  1075. }
  1076. };
  1077. /**
  1078. * Add an asterisk or other marker to the changed row.
  1079. */
  1080. Drupal.tableDrag.prototype.row.prototype.markChanged = function () {
  1081. var marker = Drupal.theme('tableDragChangedMarker');
  1082. var cell = $('td:first', this.element);
  1083. if ($('span.tabledrag-changed', cell).length == 0) {
  1084. cell.append(marker);
  1085. }
  1086. };
  1087. /**
  1088. * Stub function. Allows a custom handler when a row is indented.
  1089. */
  1090. Drupal.tableDrag.prototype.row.prototype.onIndent = function () {
  1091. return null;
  1092. };
  1093. /**
  1094. * Stub function. Allows a custom handler when a row is swapped.
  1095. */
  1096. Drupal.tableDrag.prototype.row.prototype.onSwap = function (swappedRow) {
  1097. return null;
  1098. };
  1099. Drupal.theme.prototype.tableDragChangedMarker = function () {
  1100. return '<span class="warning tabledrag-changed">*</span>';
  1101. };
  1102. Drupal.theme.prototype.tableDragIndentation = function () {
  1103. return '<div class="indentation">&nbsp;</div>';
  1104. };
  1105. Drupal.theme.prototype.tableDragChangedWarning = function () {
  1106. 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>';
  1107. };
  1108. })(jQuery);