annotate public/javascripts/select_list_move.js @ 1478:5ca1f4a47171 bibplugin_db_migrations

Close obsolete branch bibplugin_db_migrations
author Chris Cannam
date Fri, 30 Nov 2012 14:40:50 +0000
parents 513646585e45
children 433d4f72a19b
rev   line source
Chris@0 1 var NS4 = (navigator.appName == "Netscape" && parseInt(navigator.appVersion) < 5);
Chris@0 2
Chris@0 3 function addOption(theSel, theText, theValue)
Chris@0 4 {
Chris@0 5 var newOpt = new Option(theText, theValue);
Chris@0 6 var selLength = theSel.length;
Chris@0 7 theSel.options[selLength] = newOpt;
Chris@0 8 }
Chris@0 9
Chris@0 10 function swapOptions(theSel, index1, index2)
Chris@0 11 {
Chris@0 12 var text, value;
Chris@0 13 text = theSel.options[index1].text;
Chris@0 14 value = theSel.options[index1].value;
Chris@0 15 theSel.options[index1].text = theSel.options[index2].text;
Chris@0 16 theSel.options[index1].value = theSel.options[index2].value;
Chris@0 17 theSel.options[index2].text = text;
Chris@0 18 theSel.options[index2].value = value;
Chris@0 19 }
Chris@0 20
Chris@0 21 function deleteOption(theSel, theIndex)
Chris@0 22 {
Chris@0 23 var selLength = theSel.length;
Chris@0 24 if(selLength>0)
Chris@0 25 {
Chris@0 26 theSel.options[theIndex] = null;
Chris@0 27 }
Chris@0 28 }
Chris@0 29
Chris@0 30 function moveOptions(theSelFrom, theSelTo)
Chris@0 31 {
Chris@0 32
Chris@0 33 var selLength = theSelFrom.length;
Chris@0 34 var selectedText = new Array();
Chris@0 35 var selectedValues = new Array();
Chris@0 36 var selectedCount = 0;
Chris@0 37
Chris@0 38 var i;
Chris@0 39
Chris@0 40 for(i=selLength-1; i>=0; i--)
Chris@0 41 {
Chris@0 42 if(theSelFrom.options[i].selected)
Chris@0 43 {
Chris@0 44 selectedText[selectedCount] = theSelFrom.options[i].text;
Chris@0 45 selectedValues[selectedCount] = theSelFrom.options[i].value;
Chris@0 46 deleteOption(theSelFrom, i);
Chris@0 47 selectedCount++;
Chris@0 48 }
Chris@0 49 }
Chris@0 50
Chris@0 51 for(i=selectedCount-1; i>=0; i--)
Chris@0 52 {
Chris@0 53 addOption(theSelTo, selectedText[i], selectedValues[i]);
Chris@0 54 }
Chris@0 55
Chris@0 56 if(NS4) history.go(0);
Chris@0 57 }
Chris@0 58
Chris@0 59 function moveOptionUp(theSel) {
Chris@0 60 var index = theSel.selectedIndex;
Chris@0 61 if (index > 0) {
Chris@0 62 swapOptions(theSel, index-1, index);
Chris@0 63 theSel.selectedIndex = index-1;
Chris@0 64 }
Chris@0 65 }
Chris@0 66
Chris@0 67 function moveOptionDown(theSel) {
Chris@0 68 var index = theSel.selectedIndex;
Chris@0 69 if (index < theSel.length - 1) {
Chris@0 70 swapOptions(theSel, index, index+1);
Chris@0 71 theSel.selectedIndex = index+1;
Chris@0 72 }
Chris@0 73 }
Chris@0 74
Chris@0 75 function selectAllOptions(id)
Chris@0 76 {
Chris@0 77 var select = $(id);
Chris@0 78 for (var i=0; i<select.options.length; i++) {
Chris@0 79 select.options[i].selected = true;
Chris@0 80 }
Chris@0 81 }
Chris@0 82