qfamsHandler-min.js 5.1 KB

1
  1. if(typeof QFAMS==="undefined"||!QFAMS){var QFAMS={}}QFAMS.env=QFAMS.env||{persistantSelection:false,persistantMove:true};QFAMS.updateCounter=function(c,v){var i;var nodeText=null;if(c!==null){if(c.childNodes){for(i=0;i<c.childNodes.length;i++){c.removeChild(c.childNodes[i])}}nodeText=document.createTextNode(v);c.appendChild(nodeText)}};QFAMS.updateLiveCounter=function(){var lbl=this.parentNode;var selectedCount=0;var div=lbl.parentNode;var inputs=div.getElementsByTagName('input');for(var i=0;i<inputs.length;i++){if(inputs[i].checked==1){selectedCount++}}var e=div.id;var qfamsName=e.substring(e.indexOf('_',0)+1,e.length);var span=document.getElementById(qfamsName+'_selected');QFAMS.updateCounter(span,selectedCount+'/'+inputs.length)};QFAMS.editSelection=function(qfamsName,selectMode){if(selectMode!==0&&selectMode!==1&&selectMode!==2){return}var selectedCount=0;var ams=document.getElementById('qfams_'+qfamsName);var inputs=ams.getElementsByTagName('input');for(var i=0;i<inputs.length;i++){if(selectMode===2){if(inputs[i].checked==0){inputs[i].checked=1}else if(inputs[i].checked==1){inputs[i].checked=0}}else{inputs[i].checked=selectMode}if(inputs[i].checked==1){selectedCount++}}var span=document.getElementById(qfamsName+'_selected');QFAMS.updateCounter(span,selectedCount+'/'+inputs.length)};QFAMS.moveSelection=function(qfamsName,selectLeft,selectRight,selectHidden,action,arrange){var isIE=/*@cc_on!@*/false;var source=null;var target=null;var option;var c=null;var s=null;var i;var maxFrom,maxTo;if(action==='add'||action==='all'||action==='toggle'){source=selectLeft;target=selectRight}else{source=selectRight;target=selectLeft}if(source.selectedIndex===-1&&(action==='add'||action==='remove')){return}maxFrom=source.options.length;maxTo=target.options.length;if(maxTo>0&&target.options[0].value===""){target.removeAttribute("disabled");target.options[0]=null}for(i=(maxFrom-1);i>=0;i--){if(action==='all'||action==='none'||action==='toggle'||source.options[i].selected===true){if(source.options[i].disabled===false){if(isIE){option=source.options[i].removeNode(true);option.selected=QFAMS.env.persistantSelection;target.appendChild(option)}else{option=source.options[i].cloneNode(true);option.selected=QFAMS.env.persistantSelection;target.options[target.options.length]=option}}}}if(!isIE){for(i=(maxFrom-1);i>=0;i--){if(action==='all'||action==='none'||action==='toggle'||source.options[i].selected===true){if(source.options[i].disabled===false){source.options[i]=null}}}}if(action==='toggle'){for(i=(maxTo-1);i>=0;i--){if(target.options[i].disabled===false){if(isIE){option=target.options[i].removeNode(true);option.selected=QFAMS.env.persistantSelection;source.appendChild(option)}else{option=target.options[i].cloneNode(true);option.selected=QFAMS.env.persistantSelection;source.options[source.options.length]=option}}}if(!isIE){for(i=(maxTo-1);i>=0;i--){if(target.options[i].disabled===false){target.options[i]=null}}}}c=document.getElementById(qfamsName+'_unselected');s=document.getElementById(qfamsName+'-f');QFAMS.updateCounter(c,s.length);c=document.getElementById(qfamsName+'_selected');s=document.getElementById(qfamsName+'-t');QFAMS.updateCounter(c,s.length);if(arrange!=='none'){QFAMS.sortList(target,QFAMS.compareText,arrange)}QFAMS.updateHidden(selectHidden,selectRight)};QFAMS.sortList=function(list,compareFunction,arrange){var i;var options=new Array(list.options.length);for(i=0;i<options.length;i++){options[i]=new Option(list.options[i].text,list.options[i].value,list.options[i].defaultSelected,list.options[i].selected)}options.sort(compareFunction);if(arrange==='desc'){options.reverse()}list.options.length=0;for(i=0;i<options.length;i++){list.options[i]=options[i]}};QFAMS.compareText=function(option1,option2){if(option1.text===option2.text){return 0}return option1.text<option2.text?-1:1};QFAMS.updateHidden=function(h,r){var i;for(i=0;i<h.length;i++){h.options[i].selected=false}for(i=0;i<r.length;i++){h.options[h.length]=new Option(r.options[i].text,r.options[i].value);h.options[h.length-1].selected=true}};QFAMS.moveUp=function(l,h){var indice=l.selectedIndex;if(indice<0){return}if(indice>0){QFAMS.moveSwap(l,indice,indice-1);QFAMS.updateHidden(h,l)}};QFAMS.moveDown=function(l,h){var indice=l.selectedIndex;if(indice<0){return}if(indice<l.options.length-1){QFAMS.moveSwap(l,indice,indice+1);QFAMS.updateHidden(h,l)}};QFAMS.moveTop=function(l,h){var indice=l.selectedIndex;if(indice<0){return}while(indice>0){QFAMS.moveSwap(l,indice,indice-1);QFAMS.updateHidden(h,l);indice--}};QFAMS.moveBottom=function(l,h){var indice=l.selectedIndex;if(indice<0){return}while(indice<l.options.length-1){QFAMS.moveSwap(l,indice,indice+1);QFAMS.updateHidden(h,l);indice++}};QFAMS.moveSwap=function(l,i,j){var node;node=l.replaceChild(l.options[i],l.options[j]);if(i>j){l.insertBefore(node,l.options[j].nextSibling)}else{l.insertBefore(node,l.options[i])}if(QFAMS.env.persistantMove){l.selectedIndex=j}else{l.selectedIndex=-1}};QFAMS.init=function(elm){var e,i;for(e=0;e<elm.length;e++){var div=document.getElementById('qfams_'+elm[e]);if(div!==null){var inputs=div.getElementsByTagName('input');if(inputs!==null){for(i=0;i<inputs.length;i++){inputs[i].onclick=QFAMS.updateLiveCounter}}}}};