|
Post by Wormopolis on Sept 19, 2011 20:05:42 GMT -8
browsers tested: IE and FF placement: global or more likely board footer
stemming from a support request to have members add selectable dates added to the thread title when posting.
variables for customization include: var subjectTemplate='$MONTH/$DAY/$YEAR'; allows you to style how the date appears
var datePlacement='after'; allows you to choose if date appears before or after thread title. if you choose after it might get truncated of the subject is too long
var makeOptional=false; allows members to click a checkbox if they want to include a date
var worksOnReplies=false; designated whether replies will also get date drop downs
this will dynamically change the available days in the days drop down based on month/year for leap years
<script type="text/javascript"> <!-- // date dropdowns into subject v1.5 // by Wormopolis // keep header intact
var subjectTemplate='$MONTH/$DAY/$YEAR'; //configure how you want it added to subject line on submit. var datePlacement='after'; // set to before or after var makeOptional=false; //true=user can choose to insert date or not var worksOnReplies=false;
var mnthArray=['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']; var dysArray=[31,28,31,30,31,30,31,31,30,31,30,31];
if (document.postForm && !pb_action.match(/pmsend|modifypost/) && (worksOnReplies || !location.href.match(/thread=/))) { var subline=document.postForm.subject.parentNode.parentNode; var dline=subline.cloneNode(true); dline.firstChild.firstChild.innerHTML='Date:'; dline.firstChild.nextSibling.innerHTML=(makeOptional ? '<input type="checkbox" id="usedate" onclick="whisker(); "> ' : '')+ 'Year: <input cols="5" id="ddYear" onkeyup="leapcheck()" '+(makeOptional? 'disabled="true"' : '') +'> Month: <select id="ddMonth" onchange="dayfill()"'+(makeOptional? 'disabled="true"' : '') +'></select> Day: <select id="ddDay"'+(makeOptional? 'disabled="true"' : '') +'></select>';
subline.parentNode.insertBefore(dline, subline.nextSibling); for (i=0; i<mnthArray.length; i++) document.getElementById('ddMonth').innerHTML+='<option value="' +mnthArray[i]+ '">' +mnthArray[i]+ '</option>'; dayfill();
function checkNadd() { var tmp3= subjectTemplate.replace('$YEAR', document.getElementById('ddYear').value).replace('$MONTH', document.getElementById('ddMonth').value).replace('$DAY', document.getElementById('ddDay').value); if (!makeOptional || document.getElementById('usedate').checked) { document.postForm.subject.value=(datePlacement=='before' ? tmp3+ ' ' : '') + document.postForm.subject.value + (datePlacement=='after' ? ' ' +tmp3 : ''); } }
if (document.postForm.addEventListener) { document.postForm.addEventListener('submit',checkNadd, true); } else { document.postForm.attachEvent('onsubmit',checkNadd); }
function whisker() { res=!document.getElementById('usedate').checked; document.getElementById('ddYear').disabled = document.getElementById('ddMonth').disabled = document.getElementById('ddDay').disabled = res; }
}
function leapcheck() { var tmp=parseInt(document.getElementById('ddYear').value); dysArray[1]=28+(tmp%4==0?1:0)+(tmp%100==0?-1:0)+(tmp%400==0?1:0); dayfill(); } function dayfill() { var tmp=dysArray[document.getElementById('ddMonth').selectedIndex], tmp2=''; for (i=1; i<=tmp; i++) tmp2+='<option value="' +i+ '">' +i+ '</option>'; document.getElementById('ddDay').innerHTML=tmp2; document.getElementById('ddDay').selectedIndex=0; } //--> </script>
|
|