Files
@ f43d1a4680a9
Branch filter:
Location: hot67beta/media/system/js/combobox.js
f43d1a4680a9
3.4 KiB
text/javascript
menubar 0 to 10
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | /**
* @version $Id: modal.js 5263 2006-10-02 01:25:24Z webImagery $
* @copyright Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
* @license GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/
/**
* JCombobox javascript behavior
*
* Used for transforming <input type="text" ... /> tags into combobox dropdowns with appropriate <noscript> tag following
* for dropdown list information
*
* @package Joomla
* @since 1.5
* @version 1.0
*/
var JCombobox = function() { this.constructor.apply(this, arguments);}
JCombobox.prototype = {
constructor: function()
{
var agt = navigator.userAgent.toLowerCase();
this.is_ie = (agt.indexOf("msie") != -1);
this.is_opera = (agt.indexOf("opera") != -1);
this.is_safari = (agt.indexOf("safari") != -1);
var boxes = document.getElements('.combobox');
for ( var i=0; i < boxes.length; i++) {
if (boxes[i].tagName == 'INPUT' && boxes[i].type == 'text') {
this.populate(boxes[i]);
}
}
},
populate: function(element)
{
var list = document.getElementById('combobox-'+element.id).getElementsByTagName('LI');
var select = document.createElement("select");
for ( var i=0; i < list.length; i++) {
// Do population bit here
var o = document.createElement('option');
o.value = list[i].innerHTML;
o.innerHTML = list[i].innerHTML;
if (o.value == element.value) {
o.selected = selected;
}
select.appendChild(o);
}
select.inputbox = element.id;
select.onchange = function(){ var input = document.getElementById(this.inputbox); input.value = this.options[this.selectedIndex].value; }
element.parentNode.insertBefore(select, element);
var coords = this.getCoords(select);
var widthOffset = 20;
var heightOffset = 4;
if (this.is_ie) {
coords.x = coords.x + 2;
widthOffset = 22;
heightOffset = 5;
}
if (this.is_opera) {
widthOffset = 19;
heightOffset = 4;
}
if (this.is_safari) {
coords.y = coords.y - 2;
coords.x = coords.x + 2;
widthOffset = 18;
heightOffset = 0;
}
// Set text field properties based on the select box
element.style.position = 'absolute';
element.style.top = coords.y + 'px';
element.style.left = coords.x + 'px';
element.style.width = select.offsetWidth - widthOffset + 'px';
element.style.height = select.offsetHeight - heightOffset + 'px';
element.style.zIndex = 1000;
// Add iFrame for IE
if (this.is_ie) {
var iframe = document.createElement('iframe');
iframe.src = 'about:blank';
iframe.scrolling = 'no';
iframe.frameborder = '0';
iframe.style.position = 'absolute';
iframe.style.top = coords.y + 'px';
iframe.style.left = coords.x + 'px';
iframe.style.width = element.offsetWidth + 'px';
iframe.style.height = element.offsetHeight + 'px';
element.parentNode.insertBefore(iframe, element);
}
},
getCoords: function(el) {
var coords = { x: 0, y: 0 };
while (el) {
coords.x += el.offsetLeft;
coords.y += el.offsetTop;
el = el.offsetParent;
}
return coords;
}
}
document.combobox = null
Window.onDomReady(function(){
var combobox = new JCombobox()
document.combobox = combobox
});
|