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 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
|
var toShow = new Array();
var toHide = new Array();
var COOKIE_PREFIX = "PatternEdit";
var COOKIE_EXPIRES = 365; // days
var EDITBOX_ID = "topic";
var SIGNATURE_BOX_ID = "sig";
var EDITBOX_HOLDER_ID = "formHolder";
// edit box rows
var EDITBOX_COOKIE_ROWS_ID = "TextareaRows";
var EDITBOX_CHANGE_STEP_SIZE = 4;
var EDITBOX_MIN_ROWCOUNT = 4;
// edit box font style
var EDITBOX_COOKIE_FONTSTYLE_ID = "TextareaFontStyle";
var EDITBOX_FONTSTYLE_MONO = "mono";
var EDITBOX_FONTSTYLE_PROPORTIONAL = "proportional";
var EDITBOX_FONTSTYLE_MONO_STYLE = "twikiEditboxStyleMono";
var EDITBOX_FONTSTYLE_PROPORTIONAL_STYLE = "twikiEditboxStyleProportional";
var EDITBOX_COOKIE_FONTSTYLE_ID = "TextareaFontstyle";
function initForm() {
try { document.main.text.focus(); } catch (er) {}
initTextAreaHeight();
initTextAreaFontStyle();
unhideTextArea();
var i, ilen = toShow.length;
var elem;
for (i = 0; i < ilen; ++i) {
if (dom) {
elem = document.getElementById(toShow[i]);
if (elem) elem.style.display="inline";
} else if (ie4) {
document.all[toShow[i]].style.display="inline";
} else if (ns4) {
document.layers[toShow[i]].style.display="inline";
}
}
ilen = toHide.length;
for ( i = 0; i < toHide.length; ++i) {
if (dom) {
elem = document.getElementById(toHide[i]);
if (elem) elem.style.display="none";
} else if (ie4) {
document.all[toHide[i]].style.display="none";
} else if (ns4) {
document.layers[toHide[i]].style.display="none";
}
}
}
/**
Sets the height of the edit box to height read from cookie.
*/
function initTextAreaHeight() {
var cookie = readCookie(COOKIE_PREFIX + EDITBOX_COOKIE_ROWS_ID);
if (!cookie) return;
setEditBoxHeight( parseInt(cookie) );
}
/**
Sets the font style (monospace or proportional space) of the edit box to style read from cookie.
*/
function initTextAreaFontStyle() {
var cookie = readCookie(COOKIE_PREFIX + EDITBOX_COOKIE_FONTSTYLE_ID);
if (!cookie) return;
setEditBoxFontStyle( cookie );
}
/**
Now that all edit box properties have been set, the hidden text area holder may unhide.
*/
function unhideTextArea() {
var elem = document.getElementById(EDITBOX_HOLDER_ID);
if (elem) elem.style.display = "block";
}
/**
Disables the use of ESCAPE in the edit box, because some browsers will interpret this as cancel and will remove all changes.
*/
function handleKeyDown(e) {
if (!e) e = window.event;
var code;
if (e.keyCode) code = e.keyCode;
if (code==27) return false;
return true;
}
function checkAll( theButton, theButtonOffset, theNum, theCheck ) {
// find button element index
var i, j = 0;
for (i = 0; i <= document.main.length; ++i) {
if( theButton == document.main.elements[i] ) {
j = i;
break;
}
}
// set/clear all checkboxes
var last = j+theButtonOffset+theNum;
for(i = last-theNum; i < last; ++i) {
document.main.elements[i].checked = theCheck;
}
}
/**
Changes the height of the editbox textarea.
param inDirection : -1 (decrease) or 1 (increase).
If the new height is smaller than EDITBOX_MIN_ROWCOUNT the height will become EDITBOX_MIN_ROWCOUNT.
Each change is written to a cookie.
*/
function changeEditBox(inDirection) {
var rowCount = document.getElementById(EDITBOX_ID).rows;
rowCount += (inDirection * EDITBOX_CHANGE_STEP_SIZE);
rowCount = (rowCount < EDITBOX_MIN_ROWCOUNT) ? EDITBOX_MIN_ROWCOUNT : rowCount;
setEditBoxHeight(rowCount);
writeCookie(COOKIE_PREFIX + EDITBOX_COOKIE_ROWS_ID, rowCount, COOKIE_EXPIRES);
return false;
}
/**
Sets the height of the exit box text area.
param inRowCount: the number of rows
*/
function setEditBoxHeight(inRowCount) {
document.getElementById(EDITBOX_ID).rows = inRowCount;
}
/**
Sets the font style of the edit box and the signature box. The change is written to a cookie.
param inFontStyle: either EDITBOX_FONTSTYLE_MONO or EDITBOX_FONTSTYLE_PROPORTIONAL
*/
function setEditBoxFontStyle(inFontStyle) {
if (inFontStyle == EDITBOX_FONTSTYLE_MONO) {
replaceClass(document.getElementById(EDITBOX_ID), EDITBOX_FONTSTYLE_PROPORTIONAL_STYLE, EDITBOX_FONTSTYLE_MONO_STYLE);
replaceClass(document.getElementById(SIGNATURE_BOX_ID), EDITBOX_FONTSTYLE_PROPORTIONAL_STYLE, EDITBOX_FONTSTYLE_MONO_STYLE);
writeCookie(COOKIE_PREFIX + EDITBOX_COOKIE_FONTSTYLE_ID, inFontStyle, COOKIE_EXPIRES);
return;
}
if (inFontStyle == EDITBOX_FONTSTYLE_PROPORTIONAL) {
replaceClass(document.getElementById(EDITBOX_ID), EDITBOX_FONTSTYLE_MONO_STYLE, EDITBOX_FONTSTYLE_PROPORTIONAL_STYLE);
replaceClass(document.getElementById(SIGNATURE_BOX_ID), EDITBOX_FONTSTYLE_MONO_STYLE, EDITBOX_FONTSTYLE_PROPORTIONAL_STYLE);
writeCookie(COOKIE_PREFIX + EDITBOX_COOKIE_FONTSTYLE_ID, inFontStyle, COOKIE_EXPIRES);
return;
}
}
addLoadEvent(initForm);
|