Skip to content

Instantly share code, notes, and snippets.

@alchemycs
Created December 14, 2010 01:09
Show Gist options
  • Save alchemycs/739869 to your computer and use it in GitHub Desktop.
Save alchemycs/739869 to your computer and use it in GitHub Desktop.
Answer stupid questions easily - I get lots of dumb questions at work so I whacked this page together to stop people bothering me. Thanks to my 11yo son for the suggestion. Might clean this up later and convert it to a proper project.
<html>
<head>
<title>Stupid Questions</title>
<style>
.question {
font-size: 110%;
}
.question input[type=text] {
width: 60%;
font-size: 110%;
}
.answers {
font-size: 110%;
}
.answer {
background-color: silver;
margin: 1em 0;
color: white;
border: 1px solid silver;
}
.answerSubject {
font-size: 110%;
font-weight: bold;
float:left;
clear:left;
padding-left: .5em;
padding-top: .2em;
}
.answerCategory {
text-align:right;
padding-top: .2em;
padding-right: .2em;
}
.answerContent {
padding: 1em;
margin-top:1em;
background-color: #009EE0;
color: white;
text-shadow: gray 0px -1px 0px;
display: none;
}
.chosenAnswer {
clear: both;
margin-top: 1em;
padding: 1em;
color: black;
background-color: white;
}
.userPhoto {
clear: left;
float:left;
border: 1px solid grey;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
padding:5px;
-webkit-box-shadow: 5px 5px 5px gray;
-moz-box-shadow: 5px 5px 5px gray;
background-color: white;
display:none;
}
.donateToAlchemy {
font-size: 130%;
margin: 1em 0;
text-align: right;
float: right;
}
#thinking {
background-color: #FFFFBB;
border: 1px solid gray;
padding: 1em;
font-size: 120%;
margin: 1em 0;
display: none;
}
</style>
<script type="text/javascript"
src="http://yui.yahooapis.com/combo?2.8.2r1/build/yuiloader-dom-event/yuiloader-dom-event.js&2.8.2r1/build/json/json-min.js"></script>
</head>
<body>
<div class="donateToAlchemy">
<div>
Help Alchemy make this better
</div>
<div>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="R38ET9H42AKXL">
<input type="image" src="https://www.paypal.com/en_AU/i/btn/btn_donateCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online.">
<img alt="" border="0" src="https://www.paypal.com/en_AU/i/scr/pixel.gif" width="1" height="1">
</form>
</div>
</div>
<div class="question">
<h1>Ask A Question</h1>
<form action="#">
<input type="text" name="question" id="stupidQuestion"/>
<input id="ask" type="submit" value="Ask"/>
</form>
</div>
<div id="thinking">
Hmmm...let me see...
</div>
<div class="answers" id="answers">
</div>
<script type="text/javascript">
/*
This code relies on the YAHOO! YUI 2 library and assumes Dom, Event and the
YUILoader are available. Utilities.js does this.
It assumes two HTML elements exist:
* A <button> or some other clickable object with an id of 'ask'.
* An <input type="text"> element with an id of "stupidQuestion"
*/
/*
This code was written by AlchemyCS (github.com/alchemycs) on Sunday 5th December 2010 at home.
This code is copyright Alchemy Computer Solutions and licensed for private, non resale use.
*/
YAHOO.namespace('stupidQuestions');
(function() {
var $D = YAHOO.util.Dom;
var $E = YAHOO.util.Event;
YAHOO.util.Event.onDOMReady(function() {
YAHOO.util.Event.addListener('ask', 'click', askQuestion);
});
var failLoad = function() {
alert('Bummer - Failed to load questions module');
}
var stupidQuestions = YAHOO.stupidQuestions;
var askQuestion = function(event, object) {
$E.preventDefault(event);
$D.setStyle('thinking', 'display', 'block');
var stupidQuestionText = YAHOO.util.Dom.get('stupidQuestion').value;
if (stupidQuestionText.length == 0) {
document.location = "http://www.wikihow.com/Ask-a-Question-Intelligently";
} else {
while ($D.getFirstChild('answers')) { $D.get('answers').removeChild($D.getFirstChild('answers')); }
stupidQuestionText = stupidQuestionText.replace(/\"/g, '\\"');
var stupidSQL = 'SELECT * FROM answers.search where query="'+stupidQuestionText+'" and type="resolved"';
var yqlURL = "http://query.yahooapis.com/v1/public/yql?format=json&diagnostics=false&callback=YAHOO.stupidQuestions.callback&q="+encodeURIComponent(stupidSQL);
YAHOO.util.Get.script(yqlURL, {
onSuccess: function() { YAHOO.log('Query Success'); },
onFailure: function() { YAHOO.log('Query Failure'); },
});
}
}
stupidQuestions.callback = function(oData) {
$D.setStyle('thinking', 'display', 'none');
if (oData.query.count==0) {
alert("Couldn't find anything for your answer. Try re-phrasing it a different way.");
return;
}
try {
var questions = oData.query.results.Question;
for (var questionIndex=0; questionIndex < questions.length; questionIndex++) {
var answerEl = document.createElement('div');
$D.addClass(answerEl, 'answer');
var subjectEl = document.createElement('div');
$D.addClass(subjectEl, 'answerSubject');
subjectEl.innerHTML = questions[questionIndex].Subject;
var userPhotoEl = document.createElement('img');
$D.addClass(userPhotoEl, 'userPhoto');
userPhotoEl.setAttribute('src', questions[questionIndex].UserPhotoURL);
var contentEl = document.createElement('div');
$D.addClass(contentEl, 'answerContent');
contentEl.innerHTML = questions[questionIndex].Content;
var categoryEl = document.createElement('div');
$D.addClass(categoryEl, 'answerCategory');
categoryEl.innerHTML = 'Category: '+questions[questionIndex].Category.content;
var chosenAnswerEl = document.createElement('div');
$D.addClass(chosenAnswerEl, 'chosenAnswer');
chosenAnswerEl.innerHTML = questions[questionIndex].ChosenAnswer;
answerEl.appendChild(subjectEl);
answerEl.appendChild(categoryEl);
answerEl.appendChild(userPhotoEl);
answerEl.appendChild(contentEl);
answerEl.appendChild(chosenAnswerEl);
$D.get('answers').appendChild(answerEl);
}
} catch (e) {
alert(e);
}
}
})();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment