/[drupal]/contributions/modules/nodequeue/nodequeue_dragdrop.js
ViewVC logotype

Contents of /contributions/modules/nodequeue/nodequeue_dragdrop.js

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.2 - (show annotations) (download) (as text)
Mon Aug 17 21:37:06 2009 UTC (3 months, 1 week ago) by ezrag
Branch: MAIN
CVS Tags: DRUPAL-6--2-5, DRUPAL-6--2-4, HEAD
Changes since 1.1: +141 -15 lines
File MIME type: text/javascript
feature #234004 by wulff and ezra-g: drag and drop node ordering
1 // $Id$
2
3 Drupal.behaviors.nodequeueDrag = function(context) {
4 var tableDrag = Drupal.tableDrag['nodequeue-dragdrop'];
5
6 tableDrag.onDrop = function() {
7 $('td.position').each(function(i){
8 $(this).html(i + 1);
9 });
10 }
11 }
12
13 Drupal.behaviors.nodequeueReverse = function(context) {
14 $('#edit-reverse').click(function(){
15 // reverse table rows...
16 $('tr.draggable').each(function(i){
17 $('.nodequeue-dragdrop tbody').prepend(this);
18 });
19
20 // ...and update node positions
21 var size = $('.node-position').size();
22 $('.node-position').each(function(i){
23 var val = $(this).val();
24 $(this).val(size - val + 1);
25 });
26
27 nodequeueInsertChangedWarning();
28 nodequeueRestripeTable();
29
30 return false;
31 });
32 };
33
34 Drupal.behaviors.nodequeueShuffle = function(context) {
35 $('#edit-shuffle').click(function(){
36 // randomize table rows...
37 var rows = $('table.nodequeue-dragdrop tbody tr:not(:hidden)').get();
38 rows.sort(function(){return (Math.round(Math.random())-0.5);});
39 $.each(rows, function(i, row) {
40 $('.nodequeue-dragdrop tbody').prepend(this);
41 });
42
43 var reverse = Drupal.settings.nodequeue.reverse;
44
45 // ...and update node positions
46 var size = reverse ? $('.node-position').size() : 1;
47 $('.node-position').each(function(i){
48 var val = $(this).val();
49 $(this).val(size);
50 reverse ? size-- : size++;
51 });
52
53 nodequeueInsertChangedWarning();
54 nodequeueRestripeTable();
55
56 return false;
57 });
58 };
59
60 Drupal.behaviors.nodequeueClear = function(context) {
61 $('#edit-clear').click(function(){
62 // mark nodes for removal
63 $('.node-position').each(function(i){
64 $(this).val('r');
65 });
66
67 // remove table rows...
68 rows = $('table.nodequeue-dragdrop tbody tr:not(:hidden)').hide();
69
70 nodequeuePrependEmptyMessage();
71 nodequeueInsertChangedWarning();
72
73 return false;
74 });
75 };
76
77 Drupal.behaviors.nodequeueRemoveNode = function(context) {
78 $('a.nodequeue-remove').css('display', 'block');
79 $('a.nodequeue-remove').click(function() {
80 a = $(this).attr('id');
81 a = '#' + a.replace('nodequeue-remove-', 'edit-') + '-position';
82 $(a).val('r');
83
84 // hide the current row
85 $(this).parent().parent().fadeOut('fast', function(){
86 if ($('table.nodequeue-dragdrop tbody tr:not(:hidden)').size() == 0) {
87 nodequeuePrependEmptyMessage();
88 }
89 else {
90 nodequeueRestripeTable()
91 nodequeueInsertChangedWarning();
92 }
93 });
94
95 return false;
96 });
97 }
98
99 Drupal.behaviors.nodequeueClearTitle = function(context) {
100 $('#edit-add-nid').focus(function(){
101 if (this.value == this.defaultValue) {
102 this.value = '';
103 $(this).css('color', '#000');
104 }
105 }).blur(function(){
106 if (!this.value.length) {
107 $(this).css('color', '#999');
108 this.value = this.defaultValue;
109 }
110 });
111 }
112
113 /**
114 * Restripe the nodequeue table after removing an element or changing the
115 * order of the elements.
116 */
117 function nodequeueRestripeTable() {
118 $('table.nodequeue-dragdrop tbody tr:not(:hidden)')
119 .filter(':odd')
120 .removeClass('odd').addClass('even')
121 .end()
122 .filter(':even')
123 .removeClass('even').addClass('odd')
124 .end();
125
126 $('tr:visible td.position').each(function(i){
127 $(this).html(i + 1);
128 });
129 }
130
131 /**
132 * Add a row to the nodequeue table explaining that the queue is empty.
133 */
134 function nodequeuePrependEmptyMessage() {
135 $('.nodequeue-dragdrop tbody').prepend('<tr class="odd"><td colspan="6">No nodes in this queue.</td></tr>');
136 }
137
138 /**
139 * Display a warning reminding the user to save the nodequeue.
140 */
141 function nodequeueInsertChangedWarning() {
142 if (Drupal.tableDrag['nodequeue-dragdrop'].changed == false) {
143 $(Drupal.theme('tableDragChangedWarning')).insertAfter('.nodequeue-dragdrop').hide().fadeIn('slow');
144 Drupal.tableDrag['nodequeue-dragdrop'].changed = true;
145 }
146 }

  ViewVC Help
Powered by ViewVC 1.1.2