phpJSvForm
v11.11.12
Des classes PHP, des JavaScripts pour créer facilement un formulaire.
|
00001 /******************************************************************************* 00002 This file is part of 'phpJSvForm'. 00003 Copyright (C) 2010 Pierre POISSON (synanceia) 00004 00005 'phpJSvForm' is free software: you can redistribute it and/or modify 00006 it under the terms of the GNU General Public License as published by 00007 the Free Software Foundation, either version 3 of the License, or 00008 (at your option) any later version. 00009 00010 'phpJSvForm' is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU General Public License for more details. 00014 00015 You should have received a copy of the GNU General Public License 00016 along with 'phpJSvForm'. If not, see <http://www.gnu.org/licenses/>. 00017 00018 *******************************************************************************/ 00019 00026 /******************************************************************************* 00027 Historique : ------------------------------------------------------------------- 00028 04/08/2010 PP Création du fichier 00029 13/08/2010 PP Première version finalisée 00030 26/08/2010 PP Ajout de RecherchePrecedentTag 00031 xx/11/2011 PP Documentation au format doxygen 00032 *******************************************************************************/ 00033 00061 function jscss(a,o,c1,c2) 00062 { 00063 switch (a) 00064 { 00065 case 'swap': 00066 o.className=!jscss('check',o,c1)?o.className.replace(c2,c1): o.className.replace(c1,c2); 00067 break; 00068 case 'add': 00069 if(!jscss('check',o,c1)){o.className+=o.className?' '+c1:c1;} 00070 break; 00071 case 'remove': 00072 var rep=o.className.match(' '+c1)?' '+c1:c1; 00073 o.className=o.className.replace(rep,''); 00074 break; 00075 case 'check': 00076 return (new RegExp('\\b'+c1+'\\b').test(o.className) || (c2!=""?new RegExp('\\b'+c2+'\\b').test(o.className):false)) ; 00077 } 00078 return 0 ; 00079 } 00080 00081 00091 function RechercheParentTag(obj, strTag) { 00092 var objTag, test ; 00093 strTag=' '+strTag.toLowerCase()+' ' ; 00094 do 00095 { 00096 objTag=('tagName' in obj)?' '+obj.tagName.toLowerCase()+' ':' undefined ' ; 00097 test=(strTag.indexOf(objTag)==-1 && obj.parentNode !=null) ; 00098 if(test) obj=obj.parentNode ; 00099 } 00100 while(test) ; 00101 return obj ; 00102 } 00103 00113 function RechercheSuivantTag(obj, strTag) { 00114 var objTag, test ; 00115 strTag=' '+strTag.toLowerCase()+' ' ; 00116 do 00117 { 00118 objTag=('tagName' in obj)?' '+obj.tagName.toLowerCase()+' ':' undefined ' ; 00119 test=(strTag.indexOf(objTag)==-1 && obj.nextSibling !=null) ; 00120 if(test) obj=obj.nextSibling ; 00121 } 00122 while(test) ; 00123 return obj ; 00124 } 00125 00135 function RecherchePrecedentTag(obj, strTag) 00136 { 00137 var objTag, test ; 00138 strTag=' '+strTag.toLowerCase()+' ' ; 00139 do 00140 { 00141 objTag=('tagName' in obj)?' '+obj.tagName.toLowerCase()+' ':' undefined ' ; 00142 test=(strTag.indexOf(objTag)==-1 && obj.previousSibling !=null) ; 00143 if(test) obj=obj.previousSibling ; 00144 } 00145 while(test) ; 00146 return obj ; 00147 } 00148 00149 00150 00158 function addLoadEvent(func) { 00159 var oldonload = window.onload; 00160 if (typeof window.onload != 'function') { 00161 window.onload = func; 00162 } else { 00163 window.onload = function() { 00164 if (oldonload) { 00165 oldonload(); 00166 } 00167 func(); 00168 } 00169 } 00170 } 00171 00186 function add_Event(element, type, handler) { 00187 if (element.addEventListener) { 00188 element.addEventListener(type, handler, false); 00189 } else { 00190 // assign each event handler a unique ID 00191 if (!handler.$$guid) handler.$$guid = add_Event.guid++; 00192 // create a hash table of event types for the element 00193 if (!element.events) element.events = {}; 00194 // create a hash table of event handlers for each element/event pair 00195 var handlers = element.events[type]; 00196 if (!handlers) { 00197 handlers = element.events[type] = {}; 00198 // store the existing event handler (if there is one) 00199 if (element["on" + type]) { 00200 handlers[0] = element["on" + type]; 00201 } 00202 } 00203 // store the event handler in the hash table 00204 handlers[handler.$$guid] = handler; 00205 // assign a global event handler to do all the work 00206 element["on" + type] = handleEvent; 00207 } 00208 }; 00209 00210 var add_Event.guid = 1; 00211 00212 function removeEvent(element, type, handler) { 00213 if (element.removeEventListener) { 00214 element.removeEventListener(type, handler, false); 00215 } else { 00216 // delete the event handler from the hash table 00217 if (element.events && element.events[type]) { 00218 delete element.events[type][handler.$$guid]; 00219 } 00220 } 00221 }; 00222 00223 function handleEvent(event) { 00224 var returnValue = true; 00225 // grab the event object (IE uses a global event object) 00226 event = event || fixEvent(((this.ownerDocument || this.document || this).parentWindow || window).event); 00227 // get a reference to the hash table of event handlers 00228 var handlers = this.events[event.type]; 00229 // execute each event handler 00230 for (var i in handlers) { 00231 this.$$handleEvent = handlers[i]; 00232 if (this.$$handleEvent(event) === false) { 00233 returnValue = false; 00234 } 00235 } 00236 return returnValue; 00237 }; 00238 00239 function fixEvent(event) { 00240 // add W3C standard event methods 00241 event.preventDefault = fixEvent.preventDefault; 00242 event.stopPropagation = fixEvent.stopPropagation; 00243 return event; 00244 }; 00245 fixEvent.preventDefault = function() { 00246 this.returnValue = false; 00247 }; 00248 fixEvent.stopPropagation = function() { 00249 this.cancelBubble = true; 00250 }