|
Post by Wormopolis on Aug 11, 2012 17:41:54 GMT -8
Browsers tested: IE, FF, and chrome placement: board footer and main footer
Did you ever play MadLibs as a kid? you take a story and replace certain words with blanks, then provide the blanks to someone with descriptions of what kind of word it is.. like a noun or a verb or an adjective. they fill out the blanks with whatever words they think of, and you put them back into the story. Sillyness ensues!
This code will let you turn a story into your very own madlib. it has a drop down in the post editor of default style word definitions (you can edit the array to add more), as well as letting you add a custom word part into your story. the drop down will insert a madlib tag into your story, and you just delete the word it replaces. when members go to view the thread, they are presented with 2 choices - to play the madlib or see the replies. if they choose to just read replies, they cannot play that madlib since they know which words get replaced. if they play, they get a list of inputs that they fill out. each input has the definition of the word part on hovering the label. when they finish and submit, they see their reply as well as everyone elses in the thread. their words will be inserted into the story with underlines. I will post examples after the code
BOARD FOOTER
<script type="text/javascript"> <!-- // MadLibs // v 1.0 // by Wormopolis - www.wormocodes.com // do not repost - keep header intact
/* --------------------------------------------------- */ // admin variables
var numberOfStoriesToKeepOpen=12; // when "show replies" is hit, it remembers the thread id. this variable is how many it remembers
var playButton='http://i197.photobucket.com/albums/aa250/WORMOPOLIS/mlplay.gif'; // image url to a custom "play" button. leave blank to use "quote" image
var seeRepliesButton='http://i197.photobucket.com/albums/aa250/WORMOPOLIS/seereplies.gif'; // image url to "See Replies" button when there are replies
var hideQuickReply=true; //true or false
var dropdownDefaults=[ ['NOUN','A noun is an object - a person, place or thing'], ['VERB','A verb is an action - something that a noun does'], ['ADJECTIVE','An adjective describes a noun'], ['ADVERB','An adverb describes a verb'], ['PERSON\'S NAME','The name of a person'], ['NUMBER','A quantity of something'], ['PRONOUN','A pronoun replaces a noun in third person, like he or she or it'], ['EXCLAMATION WORD','An exclamation is a word like YAHOO! or ZOINKS!'], ['CUSTOM','create your own option'] //leave this option last ]; // these will be the default items in the dropdown. the second item is a description that pops up // when hovered in the drop down, or over the input title. // custom will let poster add a description in themselves. // add however many defaults you want following the format // leave the custom one to be last /* --------------------------------------------------- */ // No need to edit below
function MLadd() { var ddobj=document.postForm.madlibsdrop; var MLopt=ddobj.options[ddobj.selectedIndex].value; var MLdesc=ddobj.options[ddobj.selectedIndex].title; if (!MLopt) return; if (MLopt!='CUSTOM') { add('[MadLib=','',MLopt); } else { add('[MadLib=','Enter description[/MadLib]','Enter Word Type'); } ddobj.selectedIndex=0; }
if (document.postForm && pb_action=='post' && !location.href.match(/thread=/)) { //new thread. add in new row with dropdown var ctrrow=document.postForm.counter.parentNode.parentNode; var MLrow=ctrrow.cloneNode(true); MLrow.firstChild.firstChild.innerHTML='<font size="5" title="Original on www.wormocodes.com">MadLibs!</font>'; var nwDropdown='<select name="madlibsdrop" onchange="MLadd()"><option></option>'; for (dd=0; dd<dropdownDefaults.length; dd++) { nwDropdown+='<option value="'+ dropdownDefaults[dd][0] + '" title="'+ dropdownDefaults[dd][1] +'">'+ dropdownDefaults[dd][0] +'</option>'; } nwDropdown+='</select>'; MLrow.firstChild.nextSibling.innerHTML=nwDropdown; ctrrow.parentNode.insertBefore(MLrow,ctrrow.nextSibling); }
if (document.postForm && pb_action=='post' && location.href.match(/thread=/) && document.postForm.message.value.match(/\[MadLib=/)) { // user is playing. reformat posting page var explArray=new Array(); for (dd=0; dd<dropdownDefaults.length; dd++) { explArray[dropdownDefaults[dd][0]]=dropdownDefaults[dd][1]; } var subj=document.postForm.subject; subj.value=subj.value.replace(/re: /i,''); var nxtrw=subj.parentNode.parentNode.nextSibling; var headrw=subj.parentNode.parentNode.cloneNode(true); headrw.firstChild.firstChild.innerHTML='Word Type (hover for definition)'; headrw.firstChild.nextSibling.innerHTML='<font size="2">Your Word</font>'; subj.disabled=true; var pftbody=subj.parentNode.parentNode.parentNode; for (pftr=pftbody.childNodes, pp=0; pp<pftr.length-1; pp++) pftr[pp].style.display='none'; subj.parentNode.parentNode.parentNode.insertBefore(headrw, subj.parentNode.parentNode.nextSibling); subj.parentNode.parentNode.style.display=''; var summtable=document.postForm.nextSibling.nextSibling.nextSibling; for (pftr=summtable.rows, pp=0; pp<pftr.length; pp++) pftr[pp].style.display='none'; var pmsg=document.postForm.message; pmsg.value=pmsg.value.replace(/\[\/?quote(.*?)\]/g,''); var rescount=0; while (pmsg.value.match(/\[MadLib=/i)) { var currmatch=pmsg.value.match(/\[MadLib=(.*?)\](((\w|\d|\s)*?)\[\/MadLib\])?/i); var nwrw=subj.parentNode.parentNode.cloneNode(true); nwrw.firstChild.firstChild.innerHTML=currmatch[1].toUpperCase(); var expl=explArray[currmatch[1].toUpperCase()] || currmatch[3]; nwrw.firstChild.firstChild.title=expl; nwrw.firstChild.nextSibling.innerHTML='<input name="MLresult' + rescount + '">'; subj.parentNode.parentNode.parentNode.insertBefore(nwrw, nxtrw); pmsg.value=pmsg.value.replace(/\[MadLib=(.*?)\](((\w|\d|\s)*?)\[\/MadLib\])?/i,'[RESULT'+(rescount++)+']'); } var lastrw=pftbody.lastChild; lastrw.firstChild.firstChild.style.display='none'; for (inps=lastrw.getElementsByTagName('input'), ii=0; ii<inps.length; ii++) if (inps[ii].value!='Post Reply') inps[ii].style.display='none';
function submitInputs(eventObject) { if (eventObject.preventDefault) { eventObject.preventDefault(); } else if (window.event) /* for ie */ { window.event.returnValue = false; } document.postForm.subject.disabled=false; var inpcheck=true; for (inps=document.postForm.getElementsByTagName('input'),ii=0; ii<inps.length; ii++) { if (inps[ii].name.match(/MLresult/) && inps[ii].value=='') { alert ("You need to fill out all the word boxes in order to continue!"); inpcheck=false; break; } } if (!inpcheck) return false; while (document.postForm.message.value.match(/\[RESULT/)) { var MLtemp=document.postForm.message.value.match(/\[RESULT(\d+)\]/); var MLtemp2=eval("document.postForm.MLresult"+MLtemp[1]); document.postForm.message.value=document.postForm.message.value.replace(MLtemp[0], '[b][u]'+MLtemp2.value+'[/u][/b]'); } document.postForm.submit(); }
if (document.postForm.addEventListener) { document.postForm.addEventListener('submit',submitInputs,false); } else { document.postForm.attachEvent('onsubmit',submitInputs); } }
if (pb_action=='display') { // display hidden original post and hide all replies // unless by the username var revealok=false; var thisthread=location.href.split('thread=')[1].split('&')[0]; if (document.cookie.match(/MadLib=/)) { var MLcookie=document.cookie.match(/MadLib=(.*?)(;|$)/); var MLcookiethreads=MLcookie[1].split(','); for (c=0; c<MLcookiethreads.length; c++) if (MLcookiethreads[c]==thisthread) {revealok=true; break;} } for (td=document.getElementsByTagName('td'), tt=0; tt<td.length; tt++) { if (td[tt].width=='80%' && td[tt].className.match(/windowbg/) && td[tt].vAlign=='top') { //hide all rows first var MLtabletop=td[tt].parentNode.parentNode.parentNode; if (MLtabletop.innerHTML.match(/\[MadLib/)) { for (rr=0; rr<MLtabletop.rows.length; rr++) MLtabletop.rows[rr].style.display='none'; break; } } } if (hideQuickReply) { for (qr=document.getElementsByTagName('td'), qq=0; qq<qr.length; qq++) { if (qr[qq].className.match('titlebg') && qr[qq].innerHTML.match(/Quick Reply/)) { qrtable = qr[qq].parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode; qrtable.style.display='none'; break; } } } for (td=document.getElementsByTagName('td'), tt=0; tt<td.length; tt++) { if (td[tt].width=='80%' && td[tt].className.match(/windowbg/) && td[tt].vAlign=='top') { if (td[tt].innerHTML.match(/\[MadLib=/) && td[tt].innerHTML.match(/Thread Started/)) { var tbldrows=td[tt].parentNode.parentNode.rows; firstpostrow=td[tt].parentNode; for (rr=0; rr<tbldrows.length; rr++) tbldrows[rr].style.display='none'; firstpostrow.style.display=''; var additionalpages=tbldrows[0].getElementsByTagName('font')[0]; td[tt].previousSibling.style.display='none'; var uname=(td[tt].previousSibling.getElementsByTagName('b')[0] || document.createTextNode('Guest')); var aftstuff=document.createElement('font'); aftstuff.size=3; aftstuff.appendChild(document.createTextNode('a MadLib by ')); aftstuff.appendChild(uname); var brtag=document.createElement('br'); td[tt].firstChild.rows[0].cells[0].style.display='none'; td[tt].firstChild.rows[0].cells[2].style.display='none'; td[tt].firstChild.rows[0].cells[1].lastChild.style.display='none'; for (bb=0; bb<5; bb++) td[tt].firstChild.rows[0].cells[1].appendChild(brtag); td[tt].firstChild.rows[0].cells[1].appendChild(aftstuff); td[tt].firstChild.rows[0].cells[1].align='center'; var btns=td[tt].firstChild.rows[0].cells[2].firstChild; btns.id='buttontray'; for (bb=0; bb<btns.getElementsByTagName('a').length; bb++) { if (btns.getElementsByTagName('a')[bb].href.match(/quote/)) { if (revealok) btns.getElementsByTagName('a')[bb].style.display='none'; if (btns.getElementsByTagName('a')[bb].firstChild.nodeName.match(/img/i)) btns.getElementsByTagName('a')[bb].firstChild.src = playButton; else btns.getElementsByTagName('a')[bb].firstChild.innerHTML='Play!'; } }
function showMadLibReplies() { var thisthread=location.href.split('thread=')[1].split('&')[0]; var newMLcookie='', MLcookiethreads=new Array(); if (document.cookie.match(/MadLib=/)) { var MLcookie=document.cookie.match(/MadLib=(.*?)(;|$)/); var MLcookiethreads=MLcookie[1].split(','); for (c=0; c<MLcookiethreads.length; c++) if (MLcookiethreads[c]==thisthread) {MLcookiethreads.splice(c,1); break;} } MLcookiethreads.push(thisthread); if (MLcookiethreads.length>numberOfStoriesToKeepOpen) MLcookiethreads.pop(); newMLcookie=MLcookiethreads.join(','); var dt=new Date(); dt.setFullYear(dt.getFullYear()+1); document.cookie='MadLib='+newMLcookie+';expires='+dt; location.href=location.href; } td[tt].firstChild.rows[0].cells[1].firstChild.size='10'; if (td[tt].firstChild.rows[2]) td[tt].firstChild.rows[2].style.display='none'; for (cn=td[tt].firstChild.rows[1].cells[0].childNodes, ccn=0; ccn<cn.length; ccn++) cn[ccn].style.display='none'; td[tt].firstChild.rows[1].cells[0].firstChild.style.display=''; td[tt].firstChild.rows[1].cells[0].appendChild(btns); td[tt].firstChild.rows[1].cells[0].appendChild(document.createElement('br')); var seerepbtn=document.createElement('a'); seerepbtn.href="javascript: showMadLibReplies();"; tempimg=document.createElement('img'); tempimg.border="0"; tempimg.src=seeRepliesButton; seerepbtn.appendChild(tempimg); if (!revealok) td[tt].firstChild.rows[1].cells[0].appendChild(seerepbtn); if (revealok && additionalpages) td[tt].firstChild.rows[1].cells[0].appendChild(additionalpages); td[tt].colSpan=2; } if (td[tt].innerHTML.match(/Reply #/)) { for (lnks2=td[tt].getElementsByTagName('a'), ll2=0; ll2<lnks2.length; ll2++) { if (pb_username!='admin') if (lnks2[ll2].href.match(/modifypost/)) lnks2[ll2].style.display='none'; } ucheck=td[tt].previousSibling.getElementsByTagName('b')[0]; if (revealok || (ucheck && ucheck.firstChild.href && ucheck.firstChild.href.match(new RegExp('user='+ pb_username +'($|&)','')))) { td[tt].parentNode.style.display=''; td[tt].innerHTML=td[tt].innerHTML.replace(/\[MadLib\]/,''); if (document.getElementById('buttontray')) { //page 1 has play button document.getElementById('buttontray').firstChild.style.display='none'; } else { var nr=document.createElement('tr'); nr.appendChild(document.createElement('td')); nr.firstChild.className="windowbg"; nr.firstChild.colSpan=2; nr.firstChild.id='buttontray'; nr.firstChild.appendChild(document.createElement('br')); nr.firstChild.appendChild(td[tt].parentNode.parentNode.getElementsByTagName('font')[0]); td[tt].parentNode.parentNode.insertBefore(nr, td[tt].parentNode.parentNode.firstChild); } } } } } }
// --> </script>
MAIN FOOTER
<script type="text/javascript"> <!-- // MadLibs recent post safety piece // Main Footers.
if (pb_action.match(/search2|recent/)) { for (tds=document.getElementsByTagName('td'), tt=0; tt<tds.length; tt++) { if (tds[tt].className.match(/windowbg/) && tds[tt].width=='80%' && tds[tt].vAlign=='top' && tds[tt].innerHTML.match(/\[MadLib=/)) { tds[tt].innerHTML='<center><font size="5">Post contents hidden.<br>Play MadLibs in its own board!</font></center>'; } } }
// --> </script>
|
|
|
Post by Wormopolis on Aug 11, 2012 20:57:43 GMT -8
so this is what the post would look like that you wanted madlibs to run on...
Once upon a time there were [MadLib=NUMBER] little pigs and the time came for them to leave home and seek their [MadLib=NOUN].
Before they left, their [MadLib=NOUN] told them " Whatever you do , do it the best that you can because that's the way to get along in the world.
The first little pig built his [MadLib=NOUN] out of [MadLib=plural NOUN]same as noun but more then 1[/MadLib] because it was the [MadLib=ADJECTIVE] thing to do.
The second little pig built his [MadLib=NOUN] out of [MadLib=plural NOUN]same as noun but more then 1[/MadLib]. This was a little bit [MadLib=ADJECTIVE] than a straw house.
and after someone replies and fills in the inputs, their post would look like:
Once upon a time there were 12 little pigs and the time came for them to leave home and seek their teacher.
Before they left, their library told them " Whatever you do , do it the best that you can because that's the way to get along in the world.
The first little pig built his box out of cities because it was the elegant thing to do.
The second little pig built his book out of echoes. This was a little bit helpful than a straw house.
|
|