📄 listpicker_cforms.js
字号:
/*
* Copyright 2001-2007 Hippo (www.hippo.nl)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
//http://www.devx.com/getHelpOn/10MinuteSolution/16372/1954?pf=true
var dialogsize = {width:800, height:500 };
var myArguments=parent.params;
var jsrsBrowser = jsrsBrowserSniff();
function jsrsBrowserSniff(){
if (document.layers) return "NS";
if (document.all) {
// But is it really IE?
// convert all characters to lowercase to simplify testing
var agt=navigator.userAgent.toLowerCase();
var is_opera = (agt.indexOf("opera") != -1);
var is_konq = (agt.indexOf("konqueror") != -1);
if(is_opera) {
return "OPR";
} else {
if(is_konq) {
return "KONQ";
} else {
// Really is IE
return "IE";
}
}
}
if (document.getElementById) return "MOZ";
return "OTHER";
}
function passToXopus( ) {
var i=0;
var txt='';
var selectedList = document.getElementById('list');
for (i=0; i<selectedList.options.length; i++){
if (selectedList.options[i].selected){
if(txt!='') txt+=',';
txt+=selectedList.options[i].text;
}
}
window.top.choose(txt, txt, "");
window.close();
}
function myEscape(str){
var arr=null;
if (str != null && str != '')
var arr=str.match(",");
if (arr!=null) str='"'+str+'"';
return str;
}
function myUnescape(str){
// if (str.indexOf('"')==1 && str.lastIndexOf('"')==str.length && str.length > 1)
// str=str.substring(2,str.length-1);
return str;
}
function passSelectedItemsToXopus() {
var i=0;
var txt='';
var ids='';
var selectedList = document.getElementById('selectedlist');
for (i=0; i<selectedList.options.length; i++){
txt+=myEscape(selectedList.options[i].text);
ids+=getId(selectedList.options[i].value,selectedList.options[i].text);
if (i!=selectedList.options.length-1){ txt+=',';ids+=',';};
}
window.top.choose(ids, txt, "");
window.close();
}
function passFirstTermToXopus(){
if (document.forms['Form1']['list'].options.length!=0)
passTermToXopus(document.forms['Form1']['list'].options[0].value,document.forms['Form1']['list'].options[0].text);
}
function getId(id,term){
if (id == '') return myEscape(term); else return myEscape(id);
}
function passTermToXopus(id,term) {
window.top.choose(getId(id,term), myEscape(term), "");
window.close();
}
function passSelectedToXopus(){
var list=document.forms['Form1']['list'];
if(list.selectedIndex > -1) {
passTermToXopus(list.value,list.options[list.selectedIndex].text);
}else {
passTermToXopus("","");
}
}
function initSelectedTerms(){
if (document.getElementById('selectedlist') != null){
var terms=myArguments.value;
var keys=myArguments.key;
var arr;
var terms_arr=new Array();
if (keys!=null) str=keys; else str=terms;
var i;
var temp;
while (str.length >0){
if (str.indexOf('"') == 0){
while(str.indexOf('"') == 0){
str=str.substring(1,str.length);
temp=str.substring(0,str.indexOf('"'));
terms_arr[terms_arr.length]=temp;
str=str.substring(temp.length,str.length);
str=str=str.substring(1,str.length);
if (str.indexOf(',')==0) str=str.substring(1,str.length);
}
} else {
arr=str.split(/,/);
for (i=0; i < arr.length; i++){
if (arr[i].indexOf('"') == 0)
break;
else {
if (str.indexOf(',')>=0){
temp=str.substring(0,str.indexOf(','));
} else
temp=str;
terms_arr[terms_arr.length]=temp;
str=str.substring(temp.length,str.length);
if (str.indexOf(',')==0) str=str.substring(1,str.length);
}
}
if (str.indexOf(',')==0) str=str.substring(1,str.length);
}
}
for (i=0; i<terms_arr.length;i++)
if (terms_arr[i] != ''){
if (key2item[terms_arr[i]] == null)
addItem(terms_arr[i],terms_arr[i]);
else
addItem(terms_arr[i],getId(key2item[terms_arr[i]]));
}
}
}
function adjustContentsAfterResize(new_width,new_height){
if (dialogsize.width != new_width || dialogsize.height != new_height){
switch(jsrsBrowser){
case 'IE':
// mastertable.style.width='100%';
var mastertable=document.getElementById('master_table');
var header=document.getElementById('header');
mastertable.style.height=new_height-header.offsetHeight-30+"px";
mastertable.style.width=new_width-5+'px';
var src_list = document.getElementById('list');
var dest_list = document.getElementById('selectedlist');
if (single_item){
src_list.style.width = new_width+"px";
} else {
src_list.style.width = Math.round( new_width / 2) + "px";
dest_list.style.width = Math.round(new_width / 2) - 70 + "px";
}
//alert(dest_list.style.width);
// dest_list.style.height='100%';
break;
case 'MOZ':
// mastertable.style.width='100%';
var mastertable=document.getElementById('master_table');
var header=document.getElementById('header');
mastertable.style.height=new_height-header.offsetHeight-30+"px";
mastertable.style.width=new_width-5+'px';
var src_list = document.getElementById('list');
var dest_list = document.getElementById('selectedlist');
if (single_item){
src_list.style.width = new_width+"px";
} else {
src_list.style.width = Math.round( new_width / 2) + "px";
dest_list.style.width = Math.round(new_width / 2) - 70 + "px";
}
// dest_list.style.height='100%';
break;
case 'OPR':
break;
}
dialogsize.width = new_width;
dialogsize.height = new_height;
}
}
function init() {
switch(jsrsBrowser){
case 'IE':
var mastertable=document.getElementById('master_table');
var header=document.getElementById('header');
var tmpHeight = mastertable.offsetHeight+header.offsetHeight+35;
var tmpWidth = dialogsize.width+10;
var src_list = document.getElementById('list');
var dest_list = document.getElementById('selectedlist');
parent.window.resizeTo(dialogsize.width+10,tmpHeight);
var iframes=parent.document.getElementsByTagName('iframe');
iframes[0].style.width=tmpWidth+"px";
iframes[0].style.height=tmpHeight+"px";
/* var iframes=parent.document.getElementsByTagName('iframe');
iframes[0].style.width="100%";
iframes[0].style.height="100%"; */
header.style.height="20px";
mastertable.style.height=iframes[0].clientHeight-header.offsetHeight-30+"px";
// mastertable.style.height=parent.document.body.clientHeight-header.offsetHeight-3;
mastertable.style.width='100%';
if (single_item){
src_list.style.width = tmpWidth+"px";
} else {
src_list.style.width = Math.round(tmpWidth / 2) -10 + "px";
dest_list.style.width = Math.round(tmpWidth / 2) - 60 + "px";
}
selectHeight = 10;
break;
case 'MOZ':
var mastertable=document.getElementById('master_table');
var header=document.getElementById('header');
var tmpHeight = mastertable.offsetHeight+header.offsetHeight+20;
var tmpWidth = dialogsize.width;
var src_list = document.getElementById('list');
var dest_list = document.getElementById('selectedlist');
var iframes=parent.document.getElementsByTagName('iframe');
iframes[0].style.width=tmpWidth+15+"px";
iframes[0].style.height=tmpHeight+"px";
header.style.height="20px";
mastertable.style.height=iframes[0].clientHeight-header.offsetHeight-30+"px";
mastertable.width='100%';
if (single_item){
src_list.style.width = tmpWidth+"px";
} else {
src_list.style.width = Math.round( tmpWidth / 2) + "px";
dest_list.style.width = Math.round(tmpWidth / 2) - 50 + "px";
}
selectHeight = 10;
break;
case 'OPR':
break;
}
initSelectedTerms();
}
/* START Moving items in a selection list
Ref: http://javascript.internet.com/forms/selection-order.html
*/
function move(index,to) {
var list = document.termsform.selectedlist;
var total = list.options.length-1;
if (index == -1) return false;
if (to == +1 && index == total) return false;
if (to == -1 && index == 0) return false;
var items = new Array;
var values = new Array;
for (i = total; i >= 0; i--) {
items[i] = list.options[i].text;
values[i] = list.options[i].value;
}
for (i = total; i >= 0; i--) {
if (index == i) {
list.options[i + to] = new Option(items[i],values[i], 0, 1);
list.options[i] = new Option(items[i + to], values[i + to]);
i--;
}
else {
list.options[i] = new Option(items[i], values[i]);
}
}
list.focus();
}
/* END Moving items in a selection list */
function addItem(id,item){
/*
Adds a thesaurus term to the selection list.
useParentWindow => true: function is called from the iframe
false: function is called from the same window as the term selection list
*/
if (item != ''){
selectedList = document.getElementById('selectedlist');
var numItems=selectedList.length;
var addOption = new Option(item,id);
var found=false;
var i=0;
while((!found) && (i < numItems)){
if (selectedList.options[i].text==item) found=true;
i++;
}
if (found==false)
selectedList.options[numItems]=addOption;
}
}
function addItemByKey(id){
/*
Adds a thesaurus term to the selection list.
useParentWindow => true: function is called from the iframe
false: function is called from the same window as the term selection list
*/
var i=0;
for(i=0;i<keys.length; i++){
if (keys[i]==id){
addItem(keys[i],items[i]);
break;
}
}
}
function getSelected(){
var i=0;
var list=document.forms['Form1']['list'];
for (i=0; i<list.length; i++){
if (list.options[i].selected)
addItem(list.options[i].value,list.options[i].text);
}
// document.getElementById('searchText').focus();
}
function selectFirst(){
document.forms['Form1']['list'].options[0].selected = true;
document.forms['Form1']['list'].focus();
}
function formatTextValue(text) {
text = unescape(text);
text = new String(text).replace(/&/g,'&');
text = new String(text).replace(/>/g,'>');
text = new String(text).replace(/</g,'<');
return text
}
function narrowList(searchString){
resultsFound = 0;
searchString = searchString.toLowerCase();
// if beneden zorgt ervoor dat niet hele select opnieuw wordt gevuld, dit veroorzaakt nl vertraging!
var mHTML = '';
found=false;
var list=document.getElementById("list");
list.innerHTML='';
var addOption;
for(i=0;i<items.length;i++) {
zLink = items[i].toLowerCase();
if( (zLink.indexOf(searchString) == 0 )) {
found=true;
resultsFound++;
addOption = new Option(formatTextValue(items[i]),ids[i]);
list.options[list.options.length]=addOption;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -