| 1 |
<style type="text/css"> |
| 2 |
.multipleSelectBoxControl span{ /* Labels above select boxes*/ |
| 3 |
font-family:arial; |
| 4 |
font-size:11px; |
| 5 |
font-weight:bold; |
| 6 |
} |
| 7 |
.multipleSelectBoxControl div select{ /* Select box layout */ |
| 8 |
font-family:arial; |
| 9 |
height:100%; |
| 10 |
} |
| 11 |
.multipleSelectBoxControl input{ /* Small butons */ |
| 12 |
width:25px; |
| 13 |
} |
| 14 |
|
| 15 |
.multipleSelectBoxControl div{ |
| 16 |
float:left; |
| 17 |
} |
| 18 |
</style> |
| 19 |
<script type="text/javascript"> |
| 20 |
|
| 21 |
var fromBoxArray = new Array(); |
| 22 |
var toBoxArray = new Array(); |
| 23 |
var selectBoxIndex = 0; |
| 24 |
var arrayOfItemsToSelect = new Array(); |
| 25 |
|
| 26 |
function moveSingleElement() |
| 27 |
{ |
| 28 |
var selectBoxIndex = this.parentNode.parentNode.id.replace(/[^\d]/g,''); |
| 29 |
var tmpFromBox; |
| 30 |
var tmpToBox; |
| 31 |
if(this.tagName.toLowerCase()=='select'){ |
| 32 |
tmpFromBox = this; |
| 33 |
if(tmpFromBox==fromBoxArray[selectBoxIndex])tmpToBox = toBoxArray[selectBoxIndex]; else tmpToBox = fromBoxArray[selectBoxIndex]; |
| 34 |
}else{ |
| 35 |
|
| 36 |
if(this.value.indexOf('>')>=0){ |
| 37 |
tmpFromBox = fromBoxArray[selectBoxIndex]; |
| 38 |
tmpToBox = toBoxArray[selectBoxIndex]; |
| 39 |
}else{ |
| 40 |
tmpFromBox = toBoxArray[selectBoxIndex]; |
| 41 |
tmpToBox = fromBoxArray[selectBoxIndex]; |
| 42 |
} |
| 43 |
} |
| 44 |
|
| 45 |
for(var no=0;no<tmpFromBox.options.length;no++){ |
| 46 |
if(tmpFromBox.options[no].selected){ |
| 47 |
tmpFromBox.options[no].selected = false; |
| 48 |
tmpToBox.options[tmpToBox.options.length] = new Option(tmpFromBox.options[no].text,tmpFromBox.options[no].value); |
| 49 |
|
| 50 |
for(var no2=no;no2<(tmpFromBox.options.length-1);no2++){ |
| 51 |
tmpFromBox.options[no2].value = tmpFromBox.options[no2+1].value; |
| 52 |
tmpFromBox.options[no2].text = tmpFromBox.options[no2+1].text; |
| 53 |
tmpFromBox.options[no2].selected = tmpFromBox.options[no2+1].selected; |
| 54 |
} |
| 55 |
no = no -1; |
| 56 |
tmpFromBox.options.length = tmpFromBox.options.length-1; |
| 57 |
|
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
|
| 62 |
var tmpTextArray = new Array(); |
| 63 |
for(var no=0;no<tmpFromBox.options.length;no++){ |
| 64 |
tmpTextArray.push(tmpFromBox.options[no].text + '___' + tmpFromBox.options[no].value); |
| 65 |
} |
| 66 |
tmpTextArray.sort(); |
| 67 |
var tmpTextArray2 = new Array(); |
| 68 |
for(var no=0;no<tmpToBox.options.length;no++){ |
| 69 |
tmpTextArray2.push(tmpToBox.options[no].text + '___' + tmpToBox.options[no].value); |
| 70 |
} |
| 71 |
tmpTextArray2.sort(); |
| 72 |
|
| 73 |
for(var no=0;no<tmpTextArray.length;no++){ |
| 74 |
var items = tmpTextArray[no].split('___'); |
| 75 |
tmpFromBox.options[no] = new Option(items[0],items[1]); |
| 76 |
|
| 77 |
} |
| 78 |
|
| 79 |
for(var no=0;no<tmpTextArray2.length;no++){ |
| 80 |
var items = tmpTextArray2[no].split('___'); |
| 81 |
tmpToBox.options[no] = new Option(items[0],items[1]); |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
function sortAllElement(boxRef) |
| 86 |
{ |
| 87 |
var tmpTextArray2 = new Array(); |
| 88 |
for(var no=0;no<boxRef.options.length;no++){ |
| 89 |
tmpTextArray2.push(boxRef.options[no].text + '___' + boxRef.options[no].value); |
| 90 |
} |
| 91 |
tmpTextArray2.sort(); |
| 92 |
for(var no=0;no<tmpTextArray2.length;no++){ |
| 93 |
var items = tmpTextArray2[no].split('___'); |
| 94 |
boxRef.options[no] = new Option(items[0],items[1]); |
| 95 |
} |
| 96 |
|
| 97 |
} |
| 98 |
function moveAllElements() |
| 99 |
{ |
| 100 |
var selectBoxIndex = this.parentNode.parentNode.id.replace(/[^\d]/g,''); |
| 101 |
var tmpFromBox; |
| 102 |
var tmpToBox; |
| 103 |
if(this.value.indexOf('>')>=0){ |
| 104 |
tmpFromBox = fromBoxArray[selectBoxIndex]; |
| 105 |
tmpToBox = toBoxArray[selectBoxIndex]; |
| 106 |
}else{ |
| 107 |
tmpFromBox = toBoxArray[selectBoxIndex]; |
| 108 |
tmpToBox = fromBoxArray[selectBoxIndex]; |
| 109 |
} |
| 110 |
|
| 111 |
for(var no=0;no<tmpFromBox.options.length;no++){ |
| 112 |
tmpToBox.options[tmpToBox.options.length] = new Option(tmpFromBox.options[no].text,tmpFromBox.options[no].value); |
| 113 |
} |
| 114 |
|
| 115 |
tmpFromBox.options.length=0; |
| 116 |
sortAllElement(tmpToBox); |
| 117 |
|
| 118 |
} |
| 119 |
|
| 120 |
|
| 121 |
function createMovableOptions(fromBox,toBox,totalWidth,totalHeight,labelLeft,labelRight) |
| 122 |
{ |
| 123 |
fromObj = document.getElementById(fromBox); |
| 124 |
toObj = document.getElementById(toBox); |
| 125 |
|
| 126 |
arrayOfItemsToSelect[arrayOfItemsToSelect.length] = toObj; |
| 127 |
|
| 128 |
|
| 129 |
fromObj.ondblclick = moveSingleElement; |
| 130 |
toObj.ondblclick = moveSingleElement; |
| 131 |
|
| 132 |
|
| 133 |
fromBoxArray.push(fromObj); |
| 134 |
toBoxArray.push(toObj); |
| 135 |
|
| 136 |
var parentEl = fromObj.parentNode; |
| 137 |
|
| 138 |
var parentDiv = document.createElement('DIV'); |
| 139 |
parentDiv.className='multipleSelectBoxControl'; |
| 140 |
parentDiv.id = 'selectBoxGroup' + selectBoxIndex; |
| 141 |
parentDiv.style.width = totalWidth + 'px'; |
| 142 |
parentDiv.style.height = totalHeight + 'px'; |
| 143 |
parentEl.insertBefore(parentDiv,fromObj); |
| 144 |
|
| 145 |
|
| 146 |
var subDiv = document.createElement('DIV'); |
| 147 |
subDiv.style.width = (Math.floor(totalWidth/2) - 15) + 'px'; |
| 148 |
fromObj.style.width = (Math.floor(totalWidth/2) - 15) + 'px'; |
| 149 |
|
| 150 |
var label = document.createElement('SPAN'); |
| 151 |
label.innerHTML = labelLeft; |
| 152 |
subDiv.appendChild(label); |
| 153 |
|
| 154 |
subDiv.appendChild(fromObj); |
| 155 |
subDiv.className = 'multipleSelectBoxDiv'; |
| 156 |
parentDiv.appendChild(subDiv); |
| 157 |
|
| 158 |
|
| 159 |
var buttonDiv = document.createElement('DIV'); |
| 160 |
buttonDiv.style.verticalAlign = 'middle'; |
| 161 |
buttonDiv.style.paddingTop = (totalHeight/2) - 50 + 'px'; |
| 162 |
buttonDiv.style.width = '30px'; |
| 163 |
buttonDiv.style.textAlign = 'center'; |
| 164 |
parentDiv.appendChild(buttonDiv); |
| 165 |
|
| 166 |
var buttonRight = document.createElement('INPUT'); |
| 167 |
buttonRight.type='button'; |
| 168 |
buttonRight.value = '>'; |
| 169 |
buttonDiv.appendChild(buttonRight); |
| 170 |
buttonRight.onclick = moveSingleElement; |
| 171 |
|
| 172 |
var buttonAllRight = document.createElement('INPUT'); |
| 173 |
buttonAllRight.type='button'; |
| 174 |
buttonAllRight.value = '>>'; |
| 175 |
buttonAllRight.onclick = moveAllElements; |
| 176 |
buttonDiv.appendChild(buttonAllRight); |
| 177 |
|
| 178 |
var buttonLeft = document.createElement('INPUT'); |
| 179 |
buttonLeft.style.marginTop='10px'; |
| 180 |
buttonLeft.type='button'; |
| 181 |
buttonLeft.value = '<'; |
| 182 |
buttonLeft.onclick = moveSingleElement; |
| 183 |
buttonDiv.appendChild(buttonLeft); |
| 184 |
|
| 185 |
var buttonAllLeft = document.createElement('INPUT'); |
| 186 |
buttonAllLeft.type='button'; |
| 187 |
buttonAllLeft.value = '<<'; |
| 188 |
buttonAllLeft.onclick = moveAllElements; |
| 189 |
buttonDiv.appendChild(buttonAllLeft); |
| 190 |
|
| 191 |
var subDiv = document.createElement('DIV'); |
| 192 |
subDiv.style.width = (Math.floor(totalWidth/2) - 15) + 'px'; |
| 193 |
toObj.style.width = (Math.floor(totalWidth/2) - 15) + 'px'; |
| 194 |
|
| 195 |
var label = document.createElement('SPAN'); |
| 196 |
label.innerHTML = labelRight; |
| 197 |
subDiv.appendChild(label); |
| 198 |
|
| 199 |
subDiv.appendChild(toObj); |
| 200 |
parentDiv.appendChild(subDiv); |
| 201 |
|
| 202 |
toObj.style.height = (totalHeight - label.offsetHeight) + 'px'; |
| 203 |
fromObj.style.height = (totalHeight - label.offsetHeight) + 'px'; |
| 204 |
|
| 205 |
|
| 206 |
selectBoxIndex++; |
| 207 |
|
| 208 |
} |
| 209 |
|
| 210 |
function SavePostPicker(sender) { |
| 211 |
var count = 0; |
| 212 |
var value = ''; |
| 213 |
var list = document.getElementById('toBox'); |
| 214 |
for(var i = 0; i < list.options.length; ++i) { |
| 215 |
if(count > 0) { value += ',' + list.options[i].value; } |
| 216 |
else { value += list.options[i].value; } |
| 217 |
count++; |
| 218 |
} |
| 219 |
document.getElementById(sender).value = value; |
| 220 |
|
| 221 |
ClosePopup(); |
| 222 |
} |
| 223 |
|
| 224 |
function ShowPostPicker(sender) { |
| 225 |
sender = document.getElementById(sender); |
| 226 |
GreyOutScreen(); |
| 227 |
divPopup = CreatePopUp("Select Posts/Pages", 525, 390, YPos(sender) - 375, XPos(sender) + 150); |
| 228 |
|
| 229 |
<?php |
| 230 |
$count = 0; |
| 231 |
$pages = get_pages('sort_column=menu_order'); |
| 232 |
$posts = get_posts('numberposts=-1&sort_column=desc'); |
| 233 |
$allposts = "<select multiple name='fromBox' id='fromBox'>"; |
| 234 |
$selectedposts = "<select multiple name='toBox' id='toBox'></select>"; |
| 235 |
foreach($pages as $page) { |
| 236 |
if($count < 100) { |
| 237 |
$allposts .= "<option value='".$page->ID."'>".$page->post_title."</option>"; |
| 238 |
} |
| 239 |
$count++; |
| 240 |
} |
| 241 |
foreach($posts as $post) { |
| 242 |
if($count < 100) { |
| 243 |
$allposts .= "<option value='".$post->ID."'>".$post->post_title."</option>"; |
| 244 |
} |
| 245 |
$count++; |
| 246 |
} |
| 247 |
$allposts .= "</select>"; |
| 248 |
echo 'divPopup.innerHTML = "'.$allposts.$selectedposts.'";'; |
| 249 |
?> |
| 250 |
divPopup.innerHTML += "<p class='submit'><input class='button-primary' type='button' value='OK' style='float:right;' onclick='SavePostPicker(\"" + sender.id + "\")' /></p>"; |
| 251 |
createMovableOptions('fromBox','toBox',500,300,'All Posts/Pages','Selected Posts/Pages'); |
| 252 |
for(var counter = 0; counter < 1000; counter++) { void(0); } |
| 253 |
SelectedPosts = sender.value.split(","); |
| 254 |
for (var counter = 0; counter < SelectedPosts.length; counter++) { |
| 255 |
var list = document.getElementById('fromBox'); |
| 256 |
for(var i = 0; i < list.options.length; ++i) { |
| 257 |
if(list.options[i].value == SelectedPosts[counter]) { |
| 258 |
var toBox = document.createElement('option'); |
| 259 |
toBox.value = SelectedPosts[counter]; |
| 260 |
toBox.innerHTML = moveAllElements; |
| 261 |
toBox.innerHTML = list.options[i].innerHTML; |
| 262 |
document.getElementById("toBox").appendChild(toBox); |
| 263 |
break; |
| 264 |
} |
| 265 |
} |
| 266 |
} |
| 267 |
document.getElementById('fromBox').focus(); |
| 268 |
return false; |
| 269 |
} |
| 270 |
</script> |
| 271 |
|