1 |
// ----------------------------------------------------------------------------- |
// ========================================================================= |
2 |
// IWF - Interactive Website Framework. Javascript library for creating |
/// IWF - Interactive Website Framework. Javascript library for creating |
3 |
// responsive thin client interfaces. |
/// responsive thin client interfaces. |
4 |
|
/// |
5 |
|
/// Copyright (C) 2005 Brock Weaver brockweaver@users.sourceforge.net |
6 |
|
/// |
7 |
|
/// This library is free software; you can redistribute it and/or modify |
8 |
|
/// it under the terms of the GNU Lesser General Public License as published |
9 |
|
/// by the Free Software Foundation; either version 2.1 of the License, or |
10 |
|
/// (at your option) any later version. |
11 |
|
/// |
12 |
|
/// This library is distributed in the hope that it will be useful, but |
13 |
|
/// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
14 |
|
/// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public |
15 |
|
/// License for more details. |
16 |
|
/// |
17 |
|
/// You should have received a copy of the GNU Lesser General Public License |
18 |
|
/// along with this library; if not, write to the Free Software Foundation, |
19 |
|
/// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
20 |
|
/// |
21 |
|
/// Brock Weaver |
22 |
|
/// brockweaver@users.sourceforge.net |
23 |
|
/// 1605 NW Maple Pl |
24 |
|
/// Ankeny, IA 50021 |
25 |
|
/// |
26 |
|
//! http://iwf.sourceforge.net/ |
27 |
|
// ========================================================================= |
28 |
|
//! NOTE: To minimize file size, strip all fluffy comments (except the LGPL, of course!) |
29 |
|
//! using the following regex (global flag and multiline on): |
30 |
|
//! ^\t*//([^/!].*|$) |
31 |
// |
// |
32 |
// Copyright (C) 2005 Brock Weaver brockweaver@gmail.com |
// This reduces file size by about 30%, give or take. |
33 |
// |
// |
34 |
// This library is free software; you can redistribute it and/or modify |
//! To rip out only logging statements (commented or uncommented): |
35 |
// it under the terms of the GNU Lesser General Public License as published |
//! ^/{0,2}iwfLog.* |
36 |
// by the Free Software Foundation; either version 2.1 of the License, or |
// ========================================================================= |
|
// (at your option) any later version. |
|
|
// |
|
|
// This library is distributed in the hope that it will be useful, but |
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
|
|
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public |
|
|
// License for more details. |
|
|
// |
|
|
// You should have received a copy of the GNU Lesser General Public License |
|
|
// along with this library; if not, write to the Free Software Foundation, |
|
|
// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
|
// |
|
|
// Brock Weaver |
|
|
// brockweaver@gmail.com |
|
|
// 1605 NW Maple Pl |
|
|
// Ankeny, IA 50021 |
|
|
// ----------------------------------------------------------------------------- |
|
37 |
|
|
38 |
// -------------------------------------------------------------------------- |
// -------------------------------------------------------------------------- |
39 |
// iwfcore.js |
//! iwfcore.js |
40 |
// |
// |
41 |
// Core functions |
// Core functions |
42 |
// |
// |
43 |
// Dependencies: |
//! Dependencies: |
44 |
// (none) |
//! (none) |
45 |
// |
// |
46 |
// Brock Weaver - brockweaver@sourceforge.net - iwf.sourceforge.net |
//! Brock Weaver - brockweaver@users.sourceforge.net |
47 |
// v 0.1 - 2005-06-05 |
//! v 0.2 - 2005-11-14 |
48 |
// Initial release. |
//! iwfcore bug patch |
49 |
// -------------------------------------------------------------------------- |
//! -------------------------------------------------------------------------- |
50 |
|
//! - fixed iwfAttribute to return most current value instead of initial value |
51 |
|
//! |
52 |
|
//! v 0.1 - 2005-06-05 |
53 |
|
//! Initial release. |
54 |
|
//! -------------------------------------------------------------------------- |
55 |
|
|
56 |
// ----------------------------------- |
// ----------------------------------- |
57 |
// Begin: Configurable variables |
// Begin: Configurable variables |
58 |
// ----------------------------------- |
// ----------------------------------- |
59 |
|
|
60 |
// set to true to enable logging. Logging simply means certain values are appended to a string. nothing is written out or communicated over the wire anywhere. |
// set to true to enable logging. Logging simply means certain values are appended to a string. nothing is written out or communicated over the wire anywhere. |
61 |
var iwfLoggingEnabled = true; |
var _iwfLoggingEnabled = true; |
62 |
|
|
63 |
|
|
64 |
// ----------------------------------- |
// ----------------------------------- |
96 |
return frm; |
return frm; |
97 |
} |
} |
98 |
|
|
99 |
function iwfGetByIdWithinForm(form, id){ |
function iwfGetByNameWithinForm(form, nm){ |
100 |
var frm = iwfGetForm(form); |
var frm = iwfGetForm(form); |
101 |
if (!frm){ |
if (!frm){ |
102 |
iwfLog("IWF Core Error: Could not locate form by id, document.forms, or document[] named '" + form + "'", true); |
iwfLog("IWF Core Error: Could not locate form by id, document.forms, or document[] named '" + form + "'", true); |
104 |
} else { |
} else { |
105 |
// find element within this form with given id. |
// find element within this form with given id. |
106 |
var el = null; |
var el = null; |
107 |
if (iwfIsString(id) || iwfIsNumber(id)) { |
if (iwfIsString(nm) || iwfIsNumber(nm)) { |
108 |
for(var i=0;i<frm.elements.length;i++){ |
for(var i=0;i<frm.elements.length;i++){ |
109 |
if (frm.elements[i].name == id || frm.elements[i].id == id){ |
if (frm.elements[i].name == nm || frm.elements[i].id == nm){ |
110 |
el = frm.elements[i]; |
el = frm.elements[i]; |
111 |
break; |
break; |
112 |
} |
} |
114 |
} else { |
} else { |
115 |
el = id; |
el = id; |
116 |
} |
} |
117 |
//iwfLog('iwfGetByIdWithinForm returning:\n\n' + iwfElementToString(el), true); |
//iwfLog('iwfGetByNameWithinForm returning:\n\n' + iwfElementToString(el), true); |
118 |
return el; |
return el; |
119 |
} |
} |
120 |
} |
} |
121 |
|
|
122 |
function iwfGetOrCreateWithinForm(form, id, tagNameOrHtml, typeAtt){ |
function iwfGetOrCreateByNameWithinForm(form, nm, tagNameOrHtml, typeAtt){ |
123 |
var elFrm = iwfGetForm(form); |
var elFrm = iwfGetForm(form); |
124 |
|
|
125 |
if (!elFrm){ |
if (!elFrm){ |
127 |
return; |
return; |
128 |
} |
} |
129 |
|
|
130 |
var el = iwfGetByIdWithinForm(form, id); |
var el = iwfGetByNameWithinForm(form, nm); |
131 |
if (!el){ |
if (!el){ |
132 |
// element does not exist. create it. |
// element does not exist. create it. |
133 |
el = document.createElement(tagNameOrHtml); |
el = document.createElement(tagNameOrHtml); |
134 |
iwfAttribute(el, 'name', id); |
iwfAttribute(el, 'name', nm); |
135 |
|
|
136 |
if (typeAtt){ |
if (typeAtt){ |
137 |
iwfAttribute(el, 'type', typeAtt); |
iwfAttribute(el, 'type', typeAtt); |
165 |
if (parentNodeId){ |
if (parentNodeId){ |
166 |
var elParent = iwfGetById(parentNodeId); |
var elParent = iwfGetById(parentNodeId); |
167 |
if (elParent){ |
if (elParent){ |
168 |
iwfAppendChild(elParent, el); |
iwfAddChild(elParent, el); |
169 |
} else if (parentNodeId.toLowerCase() == 'body'){ |
} else if (parentNodeId.toLowerCase() == 'body'){ |
170 |
iwfAppendChild(document.body, el); |
iwfAddChild(document.body, el); |
171 |
} |
} |
172 |
} |
} |
173 |
|
|
176 |
return el; |
return el; |
177 |
} |
} |
178 |
|
|
179 |
function iwfAppendChild(parentNodeId, childNodeId){ |
function iwfAddChild(parentNodeId, childNodeId, atFront){ |
180 |
|
|
181 |
var elChild = iwfGetById(childNodeId); |
var elChild = iwfGetById(childNodeId); |
182 |
if (!elChild) return null; |
if (!elChild) return null; |
198 |
|
|
199 |
|
|
200 |
|
|
201 |
// append the element to the parent |
if (!atFront || !elParent.hasChildNodes()){ |
202 |
elParent.appendChild(elChild); |
// append as last child of elParent |
203 |
|
elParent.appendChild(elChild); |
204 |
|
} else { |
205 |
|
// append as first child of elParent |
206 |
|
elParent.insertBefore(elChild, elParent.childNodes[0]); |
207 |
|
} |
208 |
|
|
209 |
return elParent; |
return elParent; |
210 |
} |
} |
211 |
|
|
212 |
function iwfRemoveNode(id){ |
function iwfRemoveNode(id){ |
213 |
var el = iwfGetById(id); |
var el = iwfGetById(id); |
214 |
if (!el) return; |
if (!el) return false; |
215 |
document.removeNode(el); |
document.removeNode(el); |
216 |
|
return true; |
217 |
} |
} |
218 |
|
|
219 |
function iwfElementToString(id){ |
function iwfElementToString(id){ |
224 |
if (el.attributes){ |
if (el.attributes){ |
225 |
for(var i=0;i<el.attributes.length;i++){ |
for(var i=0;i<el.attributes.length;i++){ |
226 |
var att = el.attributes[i]; |
var att = el.attributes[i]; |
227 |
s += ' ' + att.nodeName + '=' + att.nodeValue + ' '; |
s += ' ' + att.nodeName + '="' + att.nodeValue + '" '; |
228 |
} |
} |
229 |
} |
} |
230 |
if (el.innerHTML == ''){ |
if (el.innerHTML == ''){ |
280 |
el.setAttribute(attName, newval); |
el.setAttribute(attName, newval); |
281 |
} |
} |
282 |
} |
} |
283 |
val = el.getAttribute(attName); |
// 2005-11-14 Brock Weaver |
284 |
|
// added check for attribute on el before trying getAttribute method |
285 |
|
// (Thanks J.P. Jarolim!) |
286 |
|
if (el[attName]){ |
287 |
|
val = el[attName]; |
288 |
|
} else if (el.getAttribute) { |
289 |
|
val = el.getAttribute(attName); |
290 |
|
} |
291 |
return val; |
return val; |
292 |
} |
} |
293 |
|
|
354 |
return ret; |
return ret; |
355 |
} |
} |
356 |
// ----------------------------------- |
// ----------------------------------- |
357 |
// End: Xml Utility Functions |
// End: Encoding Utility Functions |
358 |
// ----------------------------------- |
// ----------------------------------- |
359 |
|
|
360 |
|
|
387 |
return false; |
return false; |
388 |
} else { |
} else { |
389 |
// determine if the month/day makes sense. |
// determine if the month/day makes sense. |
390 |
var mo = parseInt(dt.substring(0,2), 10); |
var mo = iwfToInt(dt.substring(0,2)); |
391 |
var dy = parseInt(dt.substring(3,2), 10); |
var dy = iwfToInt(dt.substring(3,2)); |
392 |
var yr = parseInt(dt.substring(6,4), 10); |
var yr = iwfToInt(dt.substring(6,4)); |
393 |
var maxdy = 28; |
var maxdy = 28; |
394 |
switch(mo){ |
switch(mo){ |
395 |
case 4: |
case 4: |
426 |
var arr = val.split(delim); |
var arr = val.split(delim); |
427 |
switch(arr.length){ |
switch(arr.length){ |
428 |
case 2: |
case 2: |
429 |
// possibles: 9/2, 9/2004, 09/06, |
//! possibles: 9/2, 9/2004, 09/06, |
430 |
// assume first is always month |
//! assume first is always month |
431 |
mo = '00' + arr[0]; |
mo = '00' + arr[0]; |
432 |
if (arr[1].length == 4){ |
if (arr[1].length == 4){ |
433 |
// assume second is year. |
//! assume second is year. |
434 |
yr = arr[1]; |
yr = arr[1]; |
435 |
} else { |
} else { |
436 |
// assume second is date. |
//! assume second is date. |
437 |
dy = '00' + arr[1]; |
dy = '00' + arr[1]; |
438 |
} |
} |
439 |
break; |
break; |
440 |
case 3: |
case 3: |
441 |
// possibles: 9/2/1, 9/02/04, 09/02/2004, 9/2/2004 |
//! possibles: 9/2/1, 9/02/04, 09/02/2004, 9/2/2004 |
442 |
mo = '00' + arr[0]; |
mo = '00' + arr[0]; |
443 |
dy = '00' + arr[1]; |
dy = '00' + arr[1]; |
444 |
switch(arr[2].length){ |
switch(arr[2].length){ |
453 |
} |
} |
454 |
break; |
break; |
455 |
case 3: |
case 3: |
456 |
// 3 digits... assume 2000 I guess |
//! 3 digits... assume 2000 I guess |
457 |
yr = '2' + arr[2]; |
yr = '2' + arr[2]; |
458 |
break; |
break; |
459 |
case 4: |
case 4: |
515 |
// Begin: Form Submittal Utility Functions |
// Begin: Form Submittal Utility Functions |
516 |
// ----------------------------------- |
// ----------------------------------- |
517 |
function iwfDoAction(act, frm, id, targetElement){ |
function iwfDoAction(act, frm, id, targetElement){ |
|
//alert('action=' + act + '\nfrm=' + frm + '\nid=' + id + '\ntargetElement=' + targetElement); |
|
518 |
// validate the form first |
// validate the form first |
519 |
if (window.iwfOnFormValidate){ |
if (window.iwfOnFormValidate){ |
520 |
if (!iwfOnFormValidate(act)){ |
if (!iwfOnFormValidate(act)){ |
544 |
if (!iwfGetParent(elId)){ |
if (!iwfGetParent(elId)){ |
545 |
// our element has not been added to the document yet. |
// our element has not been added to the document yet. |
546 |
iwfAttribute(elId, 'type', 'hidden'); |
iwfAttribute(elId, 'type', 'hidden'); |
547 |
if (!iwfAppendChild(frm, elId)){ |
if (!iwfAddChild(frm, elId)){ |
548 |
iwfLog('IWF Core Error: Created iwfId element, but could not append to form ' + frm.outerHTML, true); |
iwfLog('IWF Core Error: Created iwfId element, but could not append to form ' + frm.outerHTML, true); |
549 |
return; |
return; |
550 |
} |
} |
551 |
} |
} |
|
//alert(iwfElementToString(elId) + '\n\ndisabled=' + iwfAttribute(elId, 'disabled') + '\n\n' + elId.disabled); |
|
552 |
} |
} |
553 |
|
|
554 |
|
|
563 |
if (!iwfGetParent(elMode)){ |
if (!iwfGetParent(elMode)){ |
564 |
// our element has not been added to the document yet. |
// our element has not been added to the document yet. |
565 |
iwfAttribute(elMode, 'type', 'hidden'); |
iwfAttribute(elMode, 'type', 'hidden'); |
566 |
if (!iwfAppendChild(frm, elMode)){ |
if (!iwfAddChild(frm, elMode)){ |
567 |
iwfLog('IWF Core Error: Created iwfMode element, but could not append to form ' + frm.outerHTML, true); |
iwfLog('IWF Core Error: Created iwfMode element, but could not append to form ' + frm.outerHTML, true); |
568 |
return; |
return; |
569 |
} |
} |
586 |
if (!iwfGetParent(elTarget)){ |
if (!iwfGetParent(elTarget)){ |
587 |
// our element has not been added to the document yet. |
// our element has not been added to the document yet. |
588 |
iwfAttribute(elTarget, 'type', 'hidden'); |
iwfAttribute(elTarget, 'type', 'hidden'); |
589 |
if (!iwfAppendChild(frm, elTarget)){ |
if (!iwfAddChild(frm, elTarget)){ |
590 |
iwfLog('IWF Core Error: Created iwfTarget element, but could not append to form ' + frm.outerHTML, true); |
iwfLog('IWF Core Error: Created iwfTarget element, but could not append to form ' + frm.outerHTML, true); |
591 |
return; |
return; |
592 |
} |
} |
601 |
} |
} |
602 |
} else { |
} else { |
603 |
// do a normal html submit, since they didn't specify a particular target |
// do a normal html submit, since they didn't specify a particular target |
604 |
alert('doing frm.submit()'); |
iwfLog('doing frm.submit()', true); |
605 |
frm.submit(); |
frm.submit(); |
606 |
} |
} |
607 |
} |
} |
628 |
function iwfMailTo(uid, host){ |
function iwfMailTo(uid, host){ |
629 |
// this is just so an email doesn't have to be output to the browser in raw text for |
// this is just so an email doesn't have to be output to the browser in raw text for |
630 |
// email harvesters to grab... |
// email harvesters to grab... |
631 |
return 'mailto:' + uid + '@' + host; |
location.href = 'mailto:' + uid + '@' + host; |
632 |
} |
} |
633 |
|
|
634 |
function iwfClickLink(id){ |
function iwfClickLink(id){ |
663 |
|
|
664 |
var _iwfLoggedItems = ""; |
var _iwfLoggedItems = ""; |
665 |
function iwfLog(txt, showAlert){ |
function iwfLog(txt, showAlert){ |
666 |
if (iwfLoggingEnabled){ |
if (_iwfLoggingEnabled){ |
667 |
_iwfLoggedItems += txt + '\n'; |
_iwfLoggedItems += txt + '\n'; |
668 |
} else { |
} else { |
669 |
// send to big bit bucket in the sky |
//! send to big bit bucket in the sky (/dev/null) |
|
// | /dev/null |
|
670 |
} |
} |
671 |
if (showAlert){ |
if (showAlert){ |
672 |
alert(txt); |
alert(txt); |
688 |
} |
} |
689 |
|
|
690 |
function iwfShowLog(){ |
function iwfShowLog(){ |
691 |
if (!iwfLoggingEnabled){ |
if (!_iwfLoggingEnabled){ |
692 |
alert("Logging for IWF has been disabled.\nSet the iwfLoggingEnabled variable located in the iwfcore.js file to true to enable logging."); |
alert("Logging for IWF has been disabled.\nSet the _iwfLoggingEnabled variable located in the iwfcore.js (or iwfconfig.js) file to true to enable logging."); |
693 |
} else { |
} else { |
694 |
var el = iwfGetOrCreateById('iwfLog', 'div', 'body'); |
var el = iwfGetOrCreateById('iwfLog', 'div', 'body'); |
695 |
if (!el){ |
if (!el){ |