Author: vmolotkov
Date: 2007-11-06 11:59:46 -0500 (Tue, 06 Nov 2007)
New Revision: 3799
Modified:
trunk/sandbox/ui/orderingList/src/main/resources/org/richfaces/renderkit/html/scripts/OrderingList.js
Log:
implementation of items : "Keyboard usage for elements section", "Keyboard
usage for elements reordering"
Modified:
trunk/sandbox/ui/orderingList/src/main/resources/org/richfaces/renderkit/html/scripts/OrderingList.js
===================================================================
---
trunk/sandbox/ui/orderingList/src/main/resources/org/richfaces/renderkit/html/scripts/OrderingList.js 2007-11-06
16:15:34 UTC (rev 3798)
+++
trunk/sandbox/ui/orderingList/src/main/resources/org/richfaces/renderkit/html/scripts/OrderingList.js 2007-11-06
16:59:46 UTC (rev 3799)
@@ -163,8 +163,7 @@
return extremeItem;
}
-Shuttle.prototype.onclickHandler = function(event) {
- //var activeElem = event.target || event.srcElement;
+Shuttle.prototype.getEventTargetRow = function(event) {
var activeElem;
if (event.rangeParent) {
activeElem = event.rangeParent.parentNode;
@@ -183,39 +182,101 @@
}
}
- var key = event.keyCode || event.which;
+ return activeElem;
+}
+
+Shuttle.prototype.onclickHandler = function(event) {
+ var activeElem = this.getEventTargetRow(event);
+ if (activeElem == null) {
+ return;
+ }
if (event.ctrlKey) {
- if (key == 65) {
- //Ctrl + A
- this.selectAll();
- } else {
- this.addSelectedItem(activeElem);
- this.activeItem = activeElem;
- }
+ this.addSelectedItem(activeElem);
+ this.activeItem = activeElem;
} else if (event.shiftKey) {
this.selectItemGroup(activeElem);
- } else if (key == 13) {
- //space
} else {
this.selectionItem(activeElem);
this.activeItem = activeElem;
}
this.activeItem.className = Shuttle.ACTIVE_ITEM_CLASS;
-
this.saveState();
}
Shuttle.prototype.onkeydownHandler = function(event) {
switch (event.keyCode) {
case 34 : this.moveSelectedItems('last'); break; //page down
- case 33: this.moveSelectedItems('first'); break; //page up
- case 38 : this.moveSelectedItems('up'); break; //up arrow
- case 40 : this.moveSelectedItems('down'); break; //down arrow
+ case 33 : this.moveSelectedItems('first'); break; //page up
+ case 38 : //up arrow
+ if (event.ctrlKey) {
+ this.moveSelectedItems('up');
+ } else {
+ this.moveActiveItem('up');
+ }
+ break;
+ case 40 : //down arrow
+ if (event.ctrlKey) {
+ this.moveSelectedItems('down');
+ } else {
+ this.moveActiveItem('down');
+ }
+ break;
+ case 65 : // Ctrl + A
+ if (event.ctrlKey) {
+ this.selectAll();
+ if (event.stopPropagation) {
+ event.preventDefault();
+ event.stopPropagation();
+ } else {
+ event.cancelBubble = true;
+ }
+ }
+ this.activeItem.className = Shuttle.ACTIVE_ITEM_CLASS;
+ this.saveState();
+ break;
+ case 32 : this.invertSelection(event); break; //blank
}
+ this.saveState();
}
+Shuttle.prototype.invertSelection = function(event) {
+ var eventItem = this.activeItem;
+ var eventShuttleItem = this.getSelectItemByNode(eventItem);
+ if (eventShuttleItem._selected) {
+ eventShuttleItem._selected = false;
+ this.selectedItems.remove(eventShuttleItem);
+ } else {
+ eventShuttleItem._selected = true;
+ this.selectedItems.push(eventShuttleItem);
+ }
+}
+
+Shuttle.prototype.moveActiveItem = function(action) {
+ var item = this.activeItem;
+ var rows = this.shuttleTbody.rows;
+ if ((action == 'up') && (item.rowIndex > 0)) {
+ this.changeActiveItems(rows[item.rowIndex - 1], item);
+ } else if ((action == 'down') && (item.rowIndex <
this.shuttleItems.length - 1)) {
+ this.changeActiveItems(rows[item.rowIndex + 1], item);
+ }
+}
+
+Shuttle.prototype.changeActiveItems = function(newItem, item) {
+ var shuttleItem = this.getSelectItemByNode(item);
+ var newShuttleItem = this.getSelectItemByNode(newItem);
+
+ this.resetMarked();
+
+ newItem.className = Shuttle.ACTIVE_ITEM_CLASS;
+ newItem._selected = true;
+ this.activeItem = newItem;
+ this.selectedItems.push(newItem);
+}
+
Shuttle.prototype.selectAll = function() {
+ var startIndex = 0;
+ var endIndex = this.shuttleItems.length - 1;
this.selectItemRange(startIndex, endIndex);
}