// Search field autocomplete
jQuery.autocomplete = function(input, options) {
(function($){
// Create a link to self
var me = this;
// Create jQuery object for input element
var $input = $(input).attr("autocomplete", "off");
// Apply inputClass if necessary
if (options.inputClass) $input.addClass(options.inputClass);
// Create results
var results = document.createElement("div");
// Create jQuery object for results
var $results = $(results);
$results.hide().addClass(options.resultsClass).css("position", "absolute");
if( options.width > 0 ) $results.css("width", options.width);
// Add to body element
$("body").append(results);
input.autocompleter = me;
var timeout = null;
var prev = "";
var active = -1;
var cache = {};
var keyb = false;
var hasFocus = false;
var lastKeyPressCode = null;
// flush cache
function flushCache(){
cache = {};
cache.data = {};
cache.length = 0;
};
// flush cache
flushCache();
// if there is a data array supplied
if( options.data != null ){
var sFirstChar = "", stMatchSets = {}, row = [];
// no url was specified, we need to adjust the cache length to make sure it fits the local data store
if( typeof options.url != "string" ) options.cacheLength = 1;
// loop through the array and create a lookup structure
for( var i=0; i < options.data.length; i++ ){
// if row is a string, make an array otherwise just reference the array
row = ((typeof options.data[i] == "string") ? [options.data[i]] : options.data[i]);
// if the length is zero, don't add to list
if( row[0].length > 0 ){
// get the first character
sFirstChar = row[0].substring(0, 1).toLowerCase();
// if no lookup array for this character exists, look it up now
if( !stMatchSets[sFirstChar] ) stMatchSets[sFirstChar] = [];
// if the match is a string
stMatchSets[sFirstChar].push(row);
}
}
// add the data items to the cache
for( var k in stMatchSets ){
// increase the cache size
options.cacheLength++;
// add to the cache
addToCache(k, stMatchSets[k]);
}
}
$input
.keydown(function(e) {
// track last key pressed
lastKeyPressCode = e.keyCode;
switch(e.keyCode) {
case 38: // up
e.preventDefault();
moveSelect(-1);
break;
case 40: // down
e.preventDefault();
moveSelect(1);
break;
case 9: // tab
case 13: // return
if( selectCurrent() ){
// make sure to blur off the current field
$input.get(0).blur();
e.preventDefault();
if (autocompleteEnter){
autocompleteEnter();
}
}
break;
default:
active = -1;
if (timeout) clearTimeout(timeout);
timeout = setTimeout(function(){onChange();}, options.delay);
break;
}
})
.focus(function(){
// track whether the field has focus, we shouldn't process any results if the field no longer has focus
hasFocus = true;
})
.blur(function() {
// track whether the field has focus
hasFocus = false;
hideResults();
});
hideResultsNow();
function onChange() {
// ignore if the following keys are pressed: [del] [shift] [capslock]
if( lastKeyPressCode == 46 || (lastKeyPressCode > 8 && lastKeyPressCode < 32) ) return $results.hide();
var v = $input.val();
if (v == prev) return;
prev = v;
if (v.length >= options.minChars) {
$input.addClass(options.loadingClass);
requestData(v);
} else {
$input.removeClass(options.loadingClass);
$results.hide();
}
};
function moveSelect(step) {
var lis = $("li", results);
if (!lis) return;
active += step;
if (active < 0) {
active = 0;
} else if (active >= lis.size()) {
active = lis.size() - 1;
}
lis.removeClass("ac-over");
$(lis[active]).addClass("ac-over");
// Weird behaviour in IE
// if (lis[active] && lis[active].scrollIntoView) {
// lis[active].scrollIntoView(false);
// }
};
function selectCurrent() {
var li = $("li.ac-over", results)[0];
if (!li) {
var $li = $("li", results);
if (options.selectOnly) {
if ($li.length == 1) li = $li[0];
} else if (options.selectFirst) {
li = $li[0];
}
}
if (li) {
selectItem(li);
return true;
} else {
return false;
}
};
function selectItem(li) {
if (!li) {
li = document.createElement("li");
li.extra = [];
li.selectValue = "";
}
var v = $.trim(li.selectValue ? li.selectValue : li.innerHTML);
input.lastSelected = v;
prev = v;
$results.html("");
$input.val(v);
hideResultsNow();
if (options.onItemSelect) setTimeout(function() { options.onItemSelect(li) }, 1);
};
// selects a portion of the input string
function createSelection(start, end){
// get a reference to the input element
var field = $input.get(0);
if( field.createTextRange ){
var selRange = field.createTextRange();
selRange.collapse(true);
selRange.moveStart("character", start);
selRange.moveEnd("character", end);
selRange.select();
} else if( field.setSelectionRange ){
field.setSelectionRange(start, end);
} else {
if( field.selectionStart ){
field.selectionStart = start;
field.selectionEnd = end;
}
}
field.focus();
};
// fills in the input box w/the first match (assumed to be the best match)
function autoFill(sValue){
// if the last user key pressed was backspace, don't autofill
if( lastKeyPressCode != 8 ){
// fill in the value (keep the case the user has typed)
$input.val($input.val() + sValue.substring(prev.length));
// select the portion of the value not typed by the user (so the next character will erase)
createSelection(prev.length, sValue.length);
}
};
function showResults() {
// get the position of the input field right now (in case the DOM is shifted)
var pos = findPos(input);
// either use the specified width, or autocalculate based on form element
var iWidth = $('.top-search').width()-2;
// reposition
$results.css({
width: parseInt(iWidth) + "px",
top: (pos.y + input.offsetHeight) + "px",
left: pos.x + "px"
}).show();
};
function hideResults() {
if (timeout) clearTimeout(timeout);
timeout = setTimeout(hideResultsNow, 200);
};
function hideResultsNow() {
if (timeout) clearTimeout(timeout);
$input.removeClass(options.loadingClass);
if ($results.is(":visible")) {
$results.hide();
}
if (options.mustMatch) {
var v = $input.val();
if (v != input.lastSelected) {
selectItem(null);
}
}
};
function receiveData(q, data) {
if (data) {
$input.removeClass(options.loadingClass);
results.innerHTML = "";
// if the field no longer has focus or if there are no matches, do not display the drop down
if( !hasFocus || data.length == 0 ) return hideResultsNow();
if ($.browser.msie) {
// we put a styled iframe behind the calendar so HTML SELECT elements don't show through
$results.append(document.createElement('iframe'));
}
results.appendChild(dataToDom(data));
// autofill in the complete box w/the first match as long as the user hasn't entered in more data
if( options.autoFill && ($input.val().toLowerCase() == q.toLowerCase()) ) autoFill(data[0][0]);
showResults();
} else {
hideResultsNow();
}
};
function parseData(data) {
if (!data) return null;
var parsed = [];
var rows = data.split(options.lineSeparator);
for (var i=0; i < rows.length; i++) {
var row = $.trim(rows[i]);
if (row) {
parsed[parsed.length] = row.split(options.cellSeparator);
}
}
return parsed;
};
function dataToDom(data) {
var ul = document.createElement("ul");
var num = data.length;
// limited results to a max number
if( (options.maxItemsToShow > 0) && (options.maxItemsToShow < num) ) num = options.maxItemsToShow;
for (var i=0; i < num; i++) {
var row = data[i];
if (!row) continue;
var li = document.createElement("li");
if (options.formatItem) {
li.innerHTML = options.formatItem(row, i, num);
li.selectValue = row[0];
} else {
li.innerHTML = row[0];
li.selectValue = row[0];
}
var extra = null;
if (row.length > 1) {
extra = [];
for (var j=1; j < row.length; j++) {
extra[extra.length] = row[j];
}
}
li.extra = extra;
ul.appendChild(li);
$(li).hover(
function() { $("li", ul).removeClass("ac-over"); $(this).addClass("ac-over"); active = $("li", ul).indexOf($(this).get(0)); },
function() { $(this).removeClass("ac-over"); }
).click(function(e) { e.preventDefault(); e.stopPropagation(); selectItem(this) });
}
return ul;
};
function requestData(q) {
if (!options.matchCase) q = q.toLowerCase();
var data = options.cacheLength ? loadFromCache(q) : null;
// recieve the cached data
if (data) {
receiveData(q, data);
// if an AJAX url has been supplied, try loading the data now
} else if( (typeof options.url == "string") && (options.url.length > 0) ){
$.get(makeUrl(q), function(data) {
data = parseData(data);
addToCache(q, data);
receiveData(q, data);
});
// if there's been no data found, remove the loading class
} else {
$input.removeClass(options.loadingClass);
}
};
function makeUrl(q) {
var url = options.url + "?q=" + encodeURI(q);
for (var i in options.extraParams) {
url += "&" + i + "=" + encodeURI(options.extraParams[i]);
}
return url;
};
function loadFromCache(q) {
if (!q) return null;
if (cache.data[q]) return cache.data[q];
if (options.matchSubset) {
for (var i = q.length - 1; i >= options.minChars; i--) {
var qs = q.substr(0, i);
var c = cache.data[qs];
if (c) {
var csub = [];
for (var j = 0; j < c.length; j++) {
var x = c[j];
var x0 = x[0];
if (matchSubset(x0, q)) {
csub[csub.length] = x;
}
}
return csub;
}
}
}
return null;
};
function matchSubset(s, sub) {
if (!options.matchCase) s = s.toLowerCase();
var i = s.indexOf(sub);
if (i == -1) return false;
return i == 0 || options.matchContains;
};
this.flushCache = function() {
flushCache();
};
this.setExtraParams = function(p) {
options.extraParams = p;
};
this.findValue = function(){
var q = $input.val();
if (!options.matchCase) q = q.toLowerCase();
var data = options.cacheLength ? loadFromCache(q) : null;
if (data) {
findValueCallback(q, data);
} else if( (typeof options.url == "string") && (options.url.length > 0) ){
$.get(makeUrl(q), function(data) {
data = parseData(data)
addToCache(q, data);
findValueCallback(q, data);
});
} else {
// no matches
findValueCallback(q, null);
}
}
function findValueCallback(q, data){
if (data) $input.removeClass(options.loadingClass);
var num = (data) ? data.length : 0;
var li = null;
for (var i=0; i < num; i++) {
var row = data[i];
if( row[0].toLowerCase() == q.toLowerCase() ){
li = document.createElement("li");
if (options.formatItem) {
li.innerHTML = options.formatItem(row, i, num);
li.selectValue = row[0];
} else {
li.innerHTML = row[0];
li.selectValue = row[0];
}
var extra = null;
if( row.length > 1 ){
extra = [];
for (var j=1; j < row.length; j++) {
extra[extra.length] = row[j];
}
}
li.extra = extra;
}
}
if( options.onFindValue ) setTimeout(function() { options.onFindValue(li) }, 1);
}
function addToCache(q, data) {
if (!data || !q || !options.cacheLength) return;
if (!cache.length || cache.length > options.cacheLength) {
flushCache();
cache.length++;
} else if (!cache[q]) {
cache.length++;
}
cache.data[q] = data;
};
function findPos(obj) {
var curleft = obj.offsetLeft || 0;
var curtop = obj.offsetTop || 0;
while (obj = obj.offsetParent) {
curleft += obj.offsetLeft
curtop += obj.offsetTop
}
return {x:curleft,y:curtop};
}
})(jQuery)
}
jQuery.fn.autocomplete = function(url, options, data) {
// Make sure options exists
options = options || {};
// Set url as option
options.url = url;
// set some bulk local data
options.data = ((typeof data == "object") && (data.constructor == Array)) ? data : null;
// Set default values for required options
options.inputClass = options.inputClass || "ac-input";
options.resultsClass = options.resultsClass || "ac-results";
options.lineSeparator = options.lineSeparator || "\n";
options.cellSeparator = options.cellSeparator || "|";
options.minChars = options.minChars || 1;
options.delay = options.delay || 400;
options.matchCase = options.matchCase || 0;
options.matchSubset = options.matchSubset || 1;
options.matchContains = options.matchContains || 0;
options.cacheLength = options.cacheLength || 1;
options.mustMatch = options.mustMatch || 0;
options.extraParams = options.extraParams || {};
options.loadingClass = options.loadingClass || "ac-loading";
options.selectFirst = options.selectFirst || false;
options.selectOnly = options.selectOnly || false;
options.maxItemsToShow = options.maxItemsToShow || -1;
options.autoFill = options.autoFill || false;
options.width = parseInt(options.width, 10) || 0;
this.each(function() {
var input = this;
new jQuery.autocomplete(input, options);
});
// Don't break the chain
return this;
}
jQuery.fn.autocompleteArray = function(data, options) {
return this.autocomplete(null, options, data);
}
jQuery.fn.indexOf = function(e){
for( var i=0; i element
this.select = select;
if (!this.select || this.select.tagName.toLowerCase() != 'select' || this.select.isInitialized)
return;
// puts current dropdown list into global collection
var i = 0;
while (i< DropDownList.selects.length) {
if (DropDownList.selects[i].select.id == elementID) {
DropDownList.selects[i] = this;
break;
}
i++;
}
if (i == DropDownList.selects.length)
DropDownList.selects.push(this);
options.width = options.width || getDimensions(this.select).width;
// hide the select field
this.select.style.display = 'none';
this.options = this.select.options;
// initialize options
this._initializeOptions(options);
this.select.isInitialized = true;
// create and build div structure
this.selectArea = document.createElement('div');
var leftDiv = document.createElement('div');
var rightDiv = document.createElement('div');
this.textContainer = document.createElement('div');
this.textContainer.id = this.select.id + 'Text';
this.textContainer.style.paddingLeft = '4px';
this.textContainer.style.cssFloat = 'left';
var text = document.createTextNode(this.emptyText);
this.selectArea.id = this.select.id + 'SelectArea';
this.selectArea.style.width = parseInt(this.width) + 'px';
this.selectArea.style.height = parseInt(this.height) + 'px';
addClass(this.selectArea, this.selectAreaStyle);
addClass(leftDiv, this.selectAreaLeftStyle);
addClass(rightDiv, this.selectAreaRightStyle);
addClass(this.textContainer, this.selectAreaCenterStyle)
this.textContainer.appendChild(text);
this.selectArea.appendChild(leftDiv);
this.selectArea.appendChild(rightDiv);
this.selectArea.appendChild(this.textContainer);
//insert select div
this.select.parentNode.insertBefore(this.selectArea, this.select);
var padding = 4;
if (navigator.appVersion.indexOf('MSIE 6') > 0)
padding = 10;
// fix IE6 bug
var containerWidth = this.width - padding - getDimensions(leftDiv).width - getDimensions(rightDiv).width;
this.textContainer.style.width = (containerWidth > 0) ? containerWidth + 'px': '0';
//build & place options div
this.optionsArea = document.createElement('ul');
this.optionsArea.id = this.select.id + 'Options';
if (this.dropDownSize > 0 && this.options.length > this.dropDownSize) {
this.optionsArea.style.height = (this.dropDownSize + 4) * this.optionHeight + 'px';
}
this.optionsArea.style.width = parseInt(this.width) - 2 + 'px';
this.optionsArea.className = this.optionsInvisibleStyle;
//get select's options and add to options div
for(var w = 0; w < this.options.length; w++) {
var optionHolder = document.createElement('li');
optionHolder.id = this.select.id + 'Option' + w;
optionHolder.style.paddingLeft = '4px';
if (this.options[w].text.length == 0)
this.options[w].text = this.emptyText;
if (w == 0)
this.defaultValue = this.options[w].text;
var optionTxt = document.createTextNode(this.options[w].text);
optionHolder.position = w;
optionHolder.onclick = function() {
self.selectOption(this.position);
self.close();
}
optionHolder.onmouseover = function() {
self.unhoverOption(self.hoveredIndex);
self.hoveredIndex = this.position;
self.hoverOption(self.hoveredIndex);
}
optionHolder.onmouseout = function() {
self.unhoverOption(this.position);
self.hoveredIndex = -1;
}
optionHolder.appendChild(optionTxt);
this.optionsArea.appendChild(optionHolder);
//check for pre-selected items
//r.aboltin disabled the pre-selected
//select behaviour
// because it was a redirection. And redirects on page refresh is not wanted
this.selectOption(0);
if(this.options[w].selected) {
//this.selectOption(w);
addClass(optionHolder, this.optionSelectedStyle);
}
}
//insert options div
//this.selectArea.appendChild(this.optionsArea);
this.select.parentNode.insertBefore(this.optionsArea, this.select);
// disables dropdown if it was disabled before creation
i = 0;
while (i< DropDownList.disable.length){
if (DropDownList.disable[i] == elementID){
this.disable();
DropDownList.disable.splice(i,1);
break;
}
i++;
}
this._initializeEventHandlers();
}
if (!DropDownList.selects)
DropDownList.selects = new Array();
if (!DropDownList.disable)
DropDownList.disable = new Array();
/*
* @description Returnd select entity.
* @method findControl
* @return {DropDownList entity}
*/
DropDownList.findControl = function(selectId){
for (var i = 0; i< DropDownList.selects.length; i++){
if (DropDownList.selects[i].select.id == selectId){
return DropDownList.selects[i];
}
}
return null;
};
/*
* @description disable select entity.
* @method disableControl
* @return {void}
*/
DropDownList.disableControl = function(selectId){
for (var i = 0; i< DropDownList.selects.length; i++){
if (DropDownList.selects[i].select.id == selectId){
DropDownList.selects[i].disable();
}
}
DropDownList.disable.push(selectId);
};
DropDownList.prototype = {
/**
* @description Initializes options.
* @method _initializeOptions
* @param {Array} options The options to initialize from.
* @return {void}
* @private
*/
_initializeOptions: function(options) {
// initialize CSS styles
var options = options || {};
this.selectAreaStyle = options.selectAreaStyle || 'select-area';
this.selectAreaOpenedStyle = options.selectAreaOpenedStyle || 'select-area-opened';
this.selectAreaLeftStyle = options.selectAreaLeftStyle || 'select-area-left';
this.selectAreaRightStyle = options.selectAreaRightStyle || 'select-area-right';
this.selectAreaCenterStyle = options.selectAreaCenterStyle || 'select-area-center';
this.optionsVisibleStyle = options.optionsVisibleStyle || 'select-options-visible';
this.optionsInvisibleStyle = options.optionsInvisibleStyle || 'select-options-invisible';
this.optionSelectedStyle = options.optionSelectedStyle || 'select-option-selected';
this.optionHoveredStyle = options.optionHoveredStyle || 'select-option-hovered';
// initialize other options
this.emptyText = options.emptyText || '-- Select --';
this.pleaseSelectText = options.pleaseSelectText || '';
this.optionsSeparator = options.optionsSeparator || ',';
this.optionsOverlap = options.optionsOverlap || 1;
this.width = options.width;
this.height = options.selectHeight || 21;
this.optionHeight = parseInt(options.optionHeight) || 15;
this.opened = false;
this.hoveredIndex = -1;
this.dropDownSize = parseInt(options.dropDownSize) || 0;
},
/**
* @description Initializes select event handlers.
* @method _initializeEventHandlers
* @return {void}
* @private
*/
_initializeEventHandlers: function() {
var self = this;
var body = document.getElementsByTagName('body')[0];
var selectKeyDownHandler = function(e) {
var e = e || window.event;
self._handleKeyDownEvent(e);
}
var bodyClickHandler = function() {
self.close();
if (self.addedKeyDownHandler) {
removeEventHandler(document, 'keydown', selectKeyDownHandler);
self.addedKeyDownHandler = false;
}
}
var selectAreaClickHandler = function() {
self.toggle();
if (self.opened) {
if (!self.addedKeyDownHandler) {
addEventHandler(document, 'keydown', selectKeyDownHandler);
self.addedKeyDownHandler = true;
}
}
else {
if (self.addedKeyDownHandler) {
removeEventHandler(document, 'keydown', selectKeyDownHandler);
self.addedKeyDownHandler = false;
}
}
}
var selectMouseOutHandler = function() {
if (!self.addedbodyClickHandler) {
addEventHandler(body, 'click', bodyClickHandler);
self.addedbodyClickHandler = true;
}
}
var selectMouseOverHandler = function() {
if (self.addedbodyClickHandler) {
removeEventHandler(body, 'click', bodyClickHandler);
self.addedbodyClickHandler = false;
}
}
addEventHandler(this.selectArea, 'click', selectAreaClickHandler);
addEventHandler(this.selectArea, 'mouseover', selectMouseOverHandler);
addEventHandler(this.selectArea, 'mouseout', selectMouseOutHandler);
addEventHandler(this.optionsArea, 'mouseover', selectMouseOverHandler);
addEventHandler(this.optionsArea, 'mouseout', selectMouseOutHandler);
},
/**
* @description Handles select key down events.
* @method _handleKeyDownEvent
* @param {Event} e The event to be handled from.
* @return {void}
* @private
*/
_handleKeyDownEvent: function(e) {
var keyCode = e.keyCode;
switch (keyCode) {
case 40: // down
this.unhoverOption(this.hoveredIndex);
this.hoveredIndex++;
if (this.hoveredIndex >= this.options.length)
this.hoveredIndex = 0;
this.hoverOption(this.hoveredIndex);
break;
case 38: // up
this.unhoverOption(this.hoveredIndex);
this.hoveredIndex--;
if (this.hoveredIndex < 0)
this.hoveredIndex = this.options.length - 1;
this.hoverOption(this.hoveredIndex);
break;
case 27: // escape
this.close();
break;
case 32: // space
this.selectOption(this.hoveredIndex);
break;
case 13: // enter
if (!this.options[this.hoveredIndex].selected)
this.selectOption(this.hoveredIndex);
this.close();
break;
default:
break;
}
},
/**
* @description Opens select.
* @method open
* @return {void}
*/
open: function() {
if (!this.disabled){
if (hasClass(this.optionsArea, this.optionsInvisibleStyle))
replaceClass(this.optionsArea, this.optionsInvisibleStyle, this.optionsVisibleStyle);
addClass(this.selectArea, this.selectAreaOpenedStyle);
if(this.pleaseSelectText)
{ this.textContainer.childNodes[0].nodeValue = this.pleaseSelectText; }
this.opened = true;
}
},
/**
* @description Closes select.
* @method close
* @return {void}
*/
close: function() {
if (hasClass(this.optionsArea, this.optionsVisibleStyle))
replaceClass(this.optionsArea, this.optionsVisibleStyle, this.optionsInvisibleStyle);
removeClass(this.selectArea, this.selectAreaOpenedStyle);
if(this.pleaseSelectText)
{
var text = '';
for (var k = 0; k < this.options.length; k++) {
if (this.options[k].selected)
text += this.options[k].text + this.optionsSeparator;
}
if (text.length > this.optionsSeparator.length)
text = text.substring(0, text.length - this.optionsSeparator.length);
else if (text.length == 0)
text = this.emptyText;
var newText = document.createTextNode(text);
this.textContainer.replaceChild(newText, this.textContainer.childNodes[0]);
}
this.opened = false;
},
/**
* @description Disables select.
* @method disable
* @return {void}
*/
disable: function(){
this.disabled = true;
this.textContainer.innerHTML = this.defaultValue;
},
/*
* @description Enables select.
* @method enable
* @return {void}
*/
enable: function(){
this.disabled = false;
},
/**
* @description Toggle select.
* @method toggle
* @return {void}
*/
toggle: function() {
this.opened ? this.close() : this.open();
},
/**
* @description Selects specified option.
* @method selectOption
* @param {int} selectedIndex The option index to be selected.
* @return {void}
*/
selectOption: function(selectedIndex) {
//feed selected option to the actual select field
if (this.select.multiple) {
var option = document.getElementById(this.select.id + 'Option' + selectedIndex);
if (option) {
this.options[selectedIndex].selected = !this.options[selectedIndex].selected;
this.options[selectedIndex].selected ? addClass(option, this.optionSelectedStyle) : removeClass(option, this.optionSelectedStyle);
}
// modify selected option
var text = '';
for (var k = 0; k < this.options.length; k++) {
if (this.options[k].selected)
text += this.options[k].text + this.optionsSeparator;
}
if (text.length > this.optionsSeparator.length)
text = text.substring(0, text.length - this.optionsSeparator.length);
else if (text.length == 0)
text = this.emptyText;
var newText = document.createTextNode(text);
this.textContainer.replaceChild(newText, this.textContainer.childNodes[0]);
if((selectedIndex>0)&&(this.options[selectedIndex].attributes["value"]))
document.location.href=this.options[selectedIndex].attributes["value"].nodeValue;
//open(his.options[selectedIndex].attributes["value"].nodeValue);
}
else {
for (var k = 0; k < this.options.length; k++) {
if (k == selectedIndex) {
this.options[k].selected = true;
this.select.selectedIndex = selectedIndex;
var option = document.getElementById(this.select.id + 'Option' + k);
if (option)
addClass(option, this.optionSelectedStyle);
}
else {
this.options[k].selected = false;
var option = document.getElementById(this.select.id + 'Option' + k);
if (option)
removeClass(option, this.optionSelectedStyle);
}
//show selected option
var newText = document.createTextNode(this.options[selectedIndex].text);
this.textContainer.replaceChild(newText, this.textContainer.childNodes[0]);
}
}
if((selectedIndex>0)&&(this.options[selectedIndex].attributes["value"]))
document.location.href=this.options[selectedIndex].attributes["value"].nodeValue;
//open(this.options[selectedIndex].attributes["value"].nodeValue);
if (this.select.onchange){
var oldDisplay = this.select.style.display;
this.select.style.display = 'block';
if ( this.select.fireEvent ) // IE 5.5(WIN)
{
this.select.fireEvent("onChange");
}
else // Mozilla, Safari etc.
{
var evt = document.createEvent("HTMLEvents");
evt.initEvent("change",true,true);
this.select.dispatchEvent( evt );
}
this.select.style.display = oldDisplay;
}
},
/**
* @description Hovers specified option.
* @method hoverOption
* @param {int} hoveredIndex The option index to be hovered.
* @return {void}
*/
hoverOption: function(hoveredIndex) {
if (hoveredIndex >= 0 && hoveredIndex < this.options.length) {
var hoveredOption = document.getElementById(this.select.id + 'Option' + hoveredIndex);
addClass(hoveredOption, this.optionHoveredStyle);
}
},
/**
* @description Unhovers specified option.
* @method unhoverOption
* @param {int} hoveredIndex The option index to be unhovered.
* @return {void}
*/
unhoverOption: function(hoveredIndex) {
if (hoveredIndex >= 0 && hoveredIndex < this.options.length) {
var hoveredOption = document.getElementById(this.select.id + 'Option' + hoveredIndex);
removeClass(hoveredOption, this.optionHoveredStyle);
}
}
}
//Useful functions
/**
* @description Returns element dimensions.
* @method getDimensions
* @param {HTMLElement} el The DOM elementement to get dimensions of.
* @return {Array} HTMLElement offset.
*/
function getDimensions(el) {
if (el.style.display != 'none' && el.style.display != null) // Safari bug
return {width: el.offsetWidth, height: el.offsetHeight};
// All *Width and *Height properties give 0 on els with display none,
// so enable the el temporarily
var els = el.style;
var originalVisibility = els.visibility;
var originalPosition = els.position;
var originalDisplay = els.display;
els.visibility = 'hidden';
els.position = 'absolute';
els.display = 'block';
var originalWidth = el.clientWidth;
var originalHeight = el.clientHeight;
els.display = originalDisplay;
els.position = originalPosition;
els.visibility = originalVisibility;
return {width: originalWidth, height: originalHeight};
}
/**
* @description Returns an HTMLElement offset.
* @method getOffset
* @param {HTMLElement} el The DOM element to get offset of.
* @return {Array} HTMLElement offset.
*/
function getOffset(el) {
var valueT = 0, valueL = 0;
do {
valueT += el.offsetTop || 0;
valueL += el.offsetLeft || 0;
el = el.offsetParent;
if (el) {
if (el.tagName.toLowerCase() == 'body')
break;
var pos = el.style.position;
if (pos == 'relative' || pos == 'absolute')
break;
}
} while (el);
return {left: valueL, top: valueT};
}
/**
* @description Determines whether an HTMLElement has the given className.
* @method hasClass
* @param {HTMLElement} el The DOM element to test.
* @param {String} className The class name to search for.
* @return {Boolean | Array} A boolean value or array of boolean values.
*/
function hasClass(el, className) {
var elClassName = el.className;
return (elClassName.length > 0 && (elClassName == className || new RegExp("(^|\\s)" + className + "(\\s|$)").test(elClassName)));
}
/**
* @description Adds a class name to a given el.
* @method addClass
* @param {HTMLElement} el The DOM element to add the class to.
* @param {String} className The class name to add to the class attribute.
* @return {void}
*/
function addClass(el, className) {
if (!hasClass(el, className))
el.className += (el.className ? ' ' : '') + className;
}
/**
* @description Removes a class name from a given el.
* @method removeClass
* @param {HTMLElement} el The DOM element or to remove the class from.
* @param {String} className The class name to remove from the class attribute.
* @return {void}
*/
function removeClass(el, className) {
el.className = el.className.replace(new RegExp("(^|\\s+)" + className + "(\\s+|$)"), ' ').replace(/^\s+/, '').replace(/\s+$/, '');
}
/**
* @description Replaces a class name fom a given el.
* @method removeClass
* @param {HTMLElement} el The DOM elementement to remove the class from.
* @param {String} oldClassName The class name to remove from the class attribute.
* @param {String} newClassName The class name to add to the class attribute.
* @return {void}
*/
function replaceClass(el, oldClassName, newClassName) {
removeClass(el, oldClassName);
addClass(el, newClassName);
}
/**
* @description Adds a DOM event directly without the caching, cleanup, scope adj, etc.
* @method addEventHandler
* @param {HTMLElement} el The DOM element to bind the handler to.
* @param {String} name The name of event handler.
* @param {function} handler The callback to invoke.
* @return {void}
*/
function addEventHandler(el, name, handler) {
el.addEventListener ? el.addEventListener(name, handler, false) : el.attachEvent('on' + name, handler);
}
/**
* @description Removes a DOM event.
* @method removeEventHandler
* @param {HTMLElement} el The DOM element to bind the handler to.
* @param {String} name The name of event handler.
* @param {function} handler The callback to invoke.
* @return {void}
*/
function removeEventHandler(el, name, handler) {
el.removeEventListener ? el.removeEventListener(name, handler, false) : el.detachEvent('on' + name, handler);
}
// MainMenu
(function($){
var Menu = function( el, settings ){
var $menu = $(el);
var $container = $( settings.container );
var menuLeftOffset = $menu.offset().left;
var menuTopOffset = $menu.offset().top;
// add hover classes
$('li', $menu).hover(function(){ $(this).addClass('hover'); },function(){ $(this).removeClass('hover') });
//$menu.children().hover(function(){ $(this).addClass('hover') },function(){ $(this).removeClass('hover') });
// fix bottom li
$('ul', $menu).each(function(){
$(this).children('li:last').addClass('last');
});
var showInner = function(){
var self = this;
var $parent = $(this).parent();
var $inner = $(this).children('ul');
this.position = function(){
var deltaX = settings.relatived ? -($parent.offset().left) : 0;
var deltaY = settings.relatived ? 0 : $(self).offset().top;
var vertical = false;
for( var i = 0; i < settings.vertical.length; i++ ){
if( $inner.is( settings.vertical[i] ) ){
vertical = true;
}
}
if( ! vertical ){
for( var i = 0; i < settings.horizontal.length; i++ ){
if( $inner.is( settings.horizontal[i] ) ){
if( ($inner.width() + $(self).width() + $(self).offset().left) > $container.width() + $container.offset().left )
$inner.css({ left: -( $inner.width() + settings.rightOffset + 1 ), top: $(self).offset().top - $parent.offset().top });
else
$inner.css({ left: $parent.width() + settings.leftOffset , top: $(self).offset().top - $parent.offset().top });
}
}
}
};
if(typeof this.timer != 'undefined' && typeof this.$inner != 'undefined'){
clearTimeout( this.timer );
}else{
self.$inner = $inner;
this.timer = false;
this.resized = false;
var width = self.$inner.width();
$inner.children('li').each(function(){
$(this).width( width );
$(this).children('a').each(function(){
$(this).width( width - 34 );
});
});
this.position();
$inner.mousemove( function(){ showInner.apply( self ) } );
}
if( typeof this.resized == 'undefined' || this.resized ){
this.resized = false;
this.position();
}
this.$inner.css('visibility','visible');
if( settings.showAnimation )
this.$inner.fadeIn( settings.showAnimation );
else
this.$inner.show();
};
var hideInner = function( ){
var self = this;
var $inner = this.$inner;
if( ! $inner )
return;
var hide = function(){
if( settings.hideAnimation )
$inner.fadeOut( settings.hideAnimation, function(){ $(this).css('visibility','hidden') } );
else {
$inner.hide().css('visibility','hidden');
}
};
this.timer = setTimeout( hide, settings.hideTimeout );
};
// show inner on hover
$('li:has(ul)', $menu).mousemove( showInner ).mouseout( hideInner );
$(window).resize(function(){
$('li:has(ul)', $menu).each(function(){
this.resized = true;
});
});
};
$.extend($.fn, {
menu: function( settings ){
var settings = $.extend({
showAnimation: false,
hideAnimation: 100,
hideTimeout: 100,
container: 'body',
horizontal: [],
vertical: [],
relatived: false,
rightOffset: -1,
leftOffset: 0
}, settings);
return $(this).each(function(){ new Menu( this, settings); });
}
});
// provide backwards compability
$.fn.Menu = $.fn.menu;
})(jQuery);
(function($) {
$(function(){
if ($.browser.msie || $.browser.opera) {
$('input.searchinput').keydown (checkForSearchEnter);
$('input.searchinput').keypress ( function () {
// Opera is fun
}
);
} else {
$('input.searchinput').keypress (checkForSearchEnter);
}
function checkForSearchEnter (event) {
if (event.keyCode == 13){
if ($.browser.opera){
$('form').submit(function(){
return false; });
}
event.preventDefault();
$('input.searchbutton').click();
return false;
}
}
});
})
(jQuery);
function autocompleteEnter () {
jQuery('input.searchbutton').click();
}
// Other files are attached here
// sifr/sifr.js
/* sIFR 2.0.2
Copyright 2004 - 2006 Mike Davidson, Shaun Inman, Tomas Jogin and Mark Wubben
This software is licensed under the CC-GNU LGPL
*/