/******************************************************************************* * This notice must be untouched at all times. * * This javascript library contains helper routines to assist with event * handling consinstently among browsers * * html5Widgets.js v.1.1 by Zoltan Hawryluk * latest version and documentation available at http://www.useragentman.com/ * * Changelog: * version 1.0: initial release * version 1.1: implemented oninput method for form elements for unsupported browsers * fix IE9 to ensure backspace and delete keys fire an oninput event. * version 1.2: Added Number Element Widget * * released under the MIT License: * http://www.opensource.org/licenses/mit-license.php * *******************************************************************************/ var html5Widgets=new function(){var me=this;var delayEventTimeout=null;me.inputNodes=new Array();me.outputNodes=new Array();me.formElements=null;me.placeholderNodes=new Array();me.dummyLink=document.createElement('input');var quoteRe=/\"/g;var dummyIDCount=0;var supportsNatively=new Object();var isBadChrome=navigator.userAgent.indexOf('Chrome');var valueRe=/this\.value/g;var varRe=/([a-zA-Z][a-zA-Z0-9]*\.value)/g;var isDebug;var isIE9=false;me.init=function(){if(EventHelpers.hasPageLoadHappened(arguments)){return}supportsNatively['oninput']=EventHelpers.isSupported('input','form');isDebug=CSSHelpers.isMemberOfClass(document.body,'html5Widgets-debug')me.type='text'me.dummyLink.style.position='absolute';me.dummyLink.style.top='-200px';document.body.appendChild(me.dummyLink)var inputSupport=Modernizr.input if(!inputSupport['placeholder']){setPlaceholders()}indexOutputNodes();insertElements();me.resolveOutputs()}function supports_input_placeholder(){var i=document.createElement('input');return'placeholder'in i}function setPlaceholders(){var nodes=[document.getElementsByTagName('input'),document.getElementsByTagName('textarea')];for(var i=0;i=0,cache:true,inputField:me.node.id,ifFormat:formatString,button:me.node.id});EventHelpers.addEvent(me.node,'click',forceCalToTop);EventHelpers.addEvent(me.node,'focus',focusEvent)EventHelpers.addEvent(me.node,'keypress',openCalendar);EventHelpers.addEvent(me.node,'blur',closeCalendar);EventHelpers.addEvent(me.node,'keypress',keydownEvent)if(window.$wf2){$wf2.callBeforeValidation.push(prepareForSubmission);$wf2.callAfterValidation.push(validationEvent)}}function placeUTCInfo(){var label=document.createElement('span');label.innerHTML="UTC";label.style.paddingLeft="5px";DOMHelpers.insertAfter(me.node,label);var width=label.offsetWidth;me.node.style.width=(me.node.offsetWidth-5-width)+'px'}function prepareForSubmission(){var splitVals;switch(me.type){case"datetime":case"datetime-local":originalVisibilityState=me.node.style.visibility;me.node.style.visibility='hidden';if(me.node.value.match(displayDateTimeValueRe)){splitVals=me.node.value.split(' ');me.node.value=splitVals[0]+"T"+splitVals[1]}switch(me.type){case"datetime-local":break;case"datetime":if(me.node.value!=""){me.node.value+="Z"}}}}function prepareForDisplay(){switch(me.type){case"datetime":case"datetime-local":if(me.node.value.match(badDateTimeValueRe)){me.node.value=me.node.value.replace(/T/,' ').replace(/Z/,'')}if(originalVisibilityState!=null){me.node.style.visibility=originalVisibilityState}}}function validationEvent(e,hasValidated){if(!hasValidated){prepareForDisplay()}}function forceCalToTop(e){var cal=window.calendar;cal.element.style.zIndex=100}function focusEvent(e){var el=EventHelpers.getEventTarget(e);EventHelpers.fireEvent(el,'click')}function openCalendar(e){var cal=window.calendar;cal.element.style.zIndex=100;if(cal.open!=undefined){cal.open()}}function closeCalendar(e){var cal=window.calendar;if(cal){cal.hide()}}function keydownEvent(e){var c=EventHelpers.getKey(e);switch(c){case 13:html5Widgets.dummyLink.focus();this.focus();EventHelpers.preventDefault(e);openCalendar(e);break;case 9:closeCalendar(e);break;default:EventHelpers.preventDefault(e);break}}function submitEvent(e){prepareForSubmission()}init()}function OutputElement(node){var me=this;me.node=node;var value;var valueFormula;var parentForm;function init(){parentForm=DOMHelpers.getAncestorByTagName(node,'form');if(!parentForm.id){parentForm.id=getNextDummyID()}valueFormula=html5Widgets.getValueFormula(DOMHelpers.getAttributeValue(me.node,'onforminput'),parentForm)}me.resolve=function(){if(valueFormula==null){return}else{eval(valueFormula);me.node.innerHTML=value;me.node.value=value}}init()}function ColorElement(node){var me=this;me.node=node;function init(){if(!window.jscolor){showError('jscolor script must be included in order for the color input type to work in this browser. See documentation for more details.')}CSSHelpers.addClass(me.node,'color');CSSHelpers.addClass(me.node,'{hash:true,caps:false}');me.node.type="text"}init()}function NumberElement(node){var me=this,min=parseFloat(DOMHelpers.getAttributeValue(node,'min')),max=parseFloat(DOMHelpers.getAttributeValue(node,'max')),step=parseFloat(DOMHelpers.getAttributeValue(node,'step'));me.node=node;if(isNaN(step)){return}EventHelpers.addEvent(node,'keyup',keyUpEvent);function keyUpEvent(){if(isNumeric(this.value)){}else if(this.value!=''){var val=parseFloat(this.value);if(isNaN(val)){this.value=''}else{this.value=val}}}function nearestValid(value,direction){var n=(value-min)/step,r;if(n==parseInt(n)){r=value}else{if(direction<0){n=Math.floor(n+1)}else{n=Math.ceil(n-1)}r=min+step*n}if(r>max){r-=step}else if(rmin||isNaN(min)))||(stepMult>0&&(node.value500)delayedOnce=true}else if((stepMult<0&&(node.value>min||isNaN(min)))||(stepMult>0&&(node.value')[0].match(typeRe);if(typeVal&&typeVal.length>=1){return typeVal[1].replace(quoteRe,'')}else{return null}}}me.insertAfter=function(refNode,nodeToInsert){var parent=refNode.parentNode;var nextSibling=refNode.nextSibling;if(nextSibling){parent.insertBefore(nodeToInsert,nextSibling)}else{parent.appendChild(nodeToInsert)}}me.getAncestorByTagName=function(obj,tagName){for(var node=obj.parentNode;node.nodeName.toLowerCase()!='body';node=node.parentNode){if(tagName.toLowerCase()==node.nodeName.toLowerCase()){return node}}return null}me.removeNode=function(node){var parentNode=node.parentNode;if(parentNode){parentNode.removeChild(node)}}}var StringHelpers=new function(){var me=this;me.sprintf=function(fstring){var pad=function(str,ch,len){var ps='';for(var i=0;i0?str+ps:ps+str}var processFlags=function(flags,width,rs,arg){var pn=function(flags,arg,rs){if(arg>=0){if(flags.indexOf(' ')>=0)rs=' '+rs;else if(flags.indexOf('+')>=0)rs='+'+rs}else rs='-'+rs;return rs}var iWidth=parseInt(width,10);if(width.charAt(0)=='0'){var ec=0;if(flags.indexOf(' ')>=0||flags.indexOf('+')>=0)ec++;if(rs.length<(iWidth-ec))rs=pad(rs,'0',rs.length-(iWidth-ec));return pn(flags,arg,rs)}rs=pn(flags,arg,rs);if(rs.length=0)rs=rs.replace(/^(.*)(e.*)$/,'$1.$2');return processFlags(flags,width,rs,arg)}converters['f']=function(flags,width,precision,arg){iPrecision=parseInt(precision);if(isNaN(iPrecision))iPrecision=6;rs=(Math.abs(arg)).toFixed(iPrecision);if(rs.indexOf('.')<0&&flags.indexOf('#')>=0)rs=rs+'.';return processFlags(flags,width,rs,arg)}converters['G']=function(flags,width,precision,arg){return(converters['g'](flags,width,precision,arg)).toUpperCase()}converters['g']=function(flags,width,precision,arg){iPrecision=parseInt(precision);absArg=Math.abs(arg);rse=absArg.toExponential();rsf=absArg.toFixed(6);if(!isNaN(iPrecision)){rsep=absArg.toExponential(iPrecision);rse=rsep.length=0)rse=rse.replace(/^(.*)(e.*)$/,'$1.$2');if(rsf.indexOf('.')<0&&flags.indexOf('#')>=0)rsf=rsf+'.';rs=rse.length=0)rs='0'+rs;return processFlags(flags,width,rs,arg)}converters['X']=function(flags,width,precision,arg){return(converters['x'](flags,width,precision,arg)).toUpperCase()}converters['x']=function(flags,width,precision,arg){var iPrecision=parseInt(precision);arg=Math.abs(arg);var rs=Math.round(arg).toString(16);if(rs.length=0)rs='0x'+rs;return processFlags(flags,width,rs,arg)}converters['s']=function(flags,width,precision,arg){var iPrecision=parseInt(precision);var rs=arg;if(rs.length>iPrecision)rs=rs.substring(0,iPrecision);return processFlags(flags,width,rs,0)}farr=fstring.split('%');retstr=farr[0];fpRE=/^([-+ #]*)(\d*)\.?(\d*)([cdieEfFgGosuxX])(.*)$/;for(var i=1;i")}}return r}}var placeholderCSS='color: #999999; font-style: italic';var placeholderRequiredCSS='color: #ffcccc !important;'var sb="";if(document.getElementsByTagName('body').length==0){sb='';document.write(sb)}}EventHelpers.addPageLoadEvent('html5Widgets.init');