Okey java is not my strong point, some of this may contain an error or a better method of doing it.
This is xoops.js from /include written in a JQuery method. It needs a check by someone oooh fay with JQuery.. please if someone can give me a hand i would appericate it.. These routines need to function with a JQuery method now it is included with xoops.
[size=x-large]/include/xoops.js[/size] /* $Id: xoops.js 4046 2009-12-19 20:22:21Z trabis $ */
function xoops$() {
var elements = new Array();
for (var i = 0; i < arguments.length; i++) {
var element = arguments[i];
if (typeof element == 'string')
element = $("#"+element).get(0);
if (arguments.length == 1)
return element;
elements.push(element);
}
return elements;
}
function xoopsGetElementById(id)
{
return $("#"+id).get(0);
}
function xoopsSetElementProp(name, prop, val)
{
$("#"+name).attr(prop, value);
}
function xoopsSetElementStyle(name, prop, val)
{
$("#"+name).css(prop, value);
}
function xoopsGetFormElement(fname, ctlname)
{
var frm = $("#"+fname+' :input');
return frm ? frm[ctlname] : null;
}
function justReturn()
{
return;
}
function openWithSelfMain(url,name, width, height, returnwindow)
{
var options = "width=" + width + ",height=" + height + ",toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no";
var new_window = window.open(url, name, options);
window.self.name = "main";
new_window.focus();
return (returnwindow != null ? new_window : void(0));
}
function setElementColor(id, color)
{
$("#"+id).css('color', color);
}
function setElementFont(id, font)
{
$("#"+id).css('fontFamily', font);
}
function setElementSize(id, size)
{
$("#"+id).css('fontSize', size);
}
function changeDisplay(id)
{
var elestyle = $("#"+id).css('display');
if (elestyle == "") {
$("#"+id).css('display', 'none');
} else {
$("#"+id).css('display', 'block');
}
}
function setVisible(id)
{
$("#"+id).css('visibility', 'visible');
}
function setHidden(id)
{
$("#"+id).css('visibility', 'hidden');
}
function appendSelectOption(selectMenuId, optionName, optionValue)
{
var newoption = new Option(optionName, optionValue);
newoption.selected = true;
$("#"+selectMenuId).append(newoption)
}
function disableElement(target)
{
var disabled = $("#"+target).attr('disable');
if (disabled != true) {
$("#"+target).attr('disable', true);
} else {
$("#"+target).attr('disable', false);
}
}
function xoopsCheckAll( form, switchId )
{
var eltSwitch = $(form+" :checkbox").get();
var eltSwitchBuffer = $("#"+switchId).get(0);
jQuery.each(eltSwitch, function() {
this.attr('checked', eltSwitchBuffer.attr('checked'));
});
}
function xoopsCheckGroup( form, switchId, groupName )
{
var eltSwitch = $(form+" :checkbox").get();
var eltSwitchBuffer = $("#"+switchId).get(0);
jQuery.each(eltSwitch, function() {
if (this.attr('name')==groupName) {
this.attr('checked', eltSwitchBuffer.attr('checked'));
this.click();
this.click();
}
});
}
function xoopsCheckAllElements(elementIds, switchId)
{
var switch_cbox = xoopsGetElementById(switchId);
jQuery.each(elementIds, function() {
var e = xoopsGetElementById(this);
if ((e.name != switch_cbox.name) && (e.type == 'checkbox')) {
e.checked = switch_cbox.checked;
}
});
}
function xoopsSavePosition(id)
{
var textareaDom = xoopsGetElementById(id);
if (textareaDom.createTextRange) {
textareaDom.caretPos = document.selection.createRange().duplicate();
}
}
function xoopsInsertText(domobj, text)
{
if (domobj.selectionEnd) {
var str1 = domobj.value.substring(0, domobj.selectionStart);
var str2 = domobj.value.substring(domobj.selectionEnd, domobj.value.length);
domobj.value = str1 + text + str2;
domobj.selectionEnd = domobj.selectionStart;
domobj.blur();
} else if (domobj.createTextRange && domobj.caretPos) {
var caretPos = domobj.caretPos;
caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
} else if (domobj.getSelection && domobj.caretPos) {
var caretPos = domobj.caretPos;
caretPos.text = caretPos.text.charat(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
} else {
domobj.value = domobj.value + text;
}
}
function xoopsCodeSmilie(id, smilieCode)
{
var revisedMessage;
var textareaDom = xoopsGetElementById(id);
xoopsInsertText(textareaDom, smilieCode);
textareaDom.focus();
return;
}
function showImgSelected(imgId, selectId, imgDir, extra, xoopsUrl)
{
if (xoopsUrl == null) {
xoopsUrl = "./";
}
imgDom = xoopsGetElementById(imgId);
selectDom = xoopsGetElementById(selectId);
if (selectDom.options[selectDom.selectedIndex].value != "") {
imgDom.src = xoopsUrl + "/"+ imgDir + "/" + selectDom.options[selectDom.selectedIndex].value + extra;
} else {
imgDom.src = xoopsUrl + "/images/blank.gif";
}
}
function xoopsExternalLinks()
{
if (!document.getElementsByTagName) return;
var anchors = document.getElementsByTagName("a");
for (var i = 0; i < anchors.length; i++) {
var anchor = anchors[i];
if (anchor.getAttribute("href") ) {
// Check rel value with extra rels, like "external noflow". No test for performance yet
var $pattern = new RegExp("external", "i");
if ($pattern.test(anchor.getAttribute("rel"))) {
/*anchor.onclick = function() {
window.open(this.href);
return false;
}*/
anchor.target = "_blank";
}
}
}
}
function xoopsOnloadEvent(func)
{
if (window.onload) {
xoopsAddEvent(window, 'load' , window.onload);
}
xoopsAddEvent(window, 'load' , func);
}
function xoopsAddEvent(obj, evType, fn)
{
if (obj.addEventListener) {
obj.addEventListener(evType, fn, true);
return true;
} else if (obj.attachEvent) {
var r = obj.attachEvent("on" + evType, fn);
return r;
} else {
return false;
}
}
xoopsOnloadEvent(xoopsExternalLinks);