Toggle project descriptions when you click on a project.
...
<script src="https://code.jquery.com/jquery.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/introHCI.js"></script>
</body>
</html>
$("a.thumbnail").click(projectClick);
function projectClick(e) {
// prevent the page from reloading
e.preventDefault();
// In an event handler, $(this) refers to
// the object that triggered the event
$(this).css("background-color", "#7fff00");
}
function projectClick(e) {
console.log("Project clicked");
e.preventDefault();
$(this).css("background-color", "#7fff00");
}
Why does the console say
event.returnValue is deprecated. Please use the standard event.preventDefault() instead.
Don't worry about this. It isn't our fault. We can safely ignore this warning.
function projectClick(e) {
// Cancel the default action, which prevents the page from reloading
e.preventDefault();
// In an event listener, $(this) is the leement that fired the event
var projectTitle = $(this).find("p").text();
var jumbotronHeader = $("#jumbotron h1");
jumbotronHeader.text(projectTitle);
}
var jumbotronHeader = $(".jumbotron h1");
...
var containingProject = $(this).closest(".project");
containingProject.append("<div class='project-description'><p>Description of the project.</p></div>");
}
...
var containingProject = $(this).closest(".project");
var description = $(containingProject).find(".project-description");
if (description.length == 0) {
$(containingProject).append("<div class='project-description'><p>Description of the project.</p></div>");
} else {
description.html("<p>Stop clicking on me! You just did it at " + (new Date()) + "</p>");
}
}
Wait, what am I doing on this slide?
The big blue button that says "Test Javascript". See it? When you click it, it's text should change to something else.
What should I change the text to?
Experience Chan! It's not a lot of questions.
Too many questions is the Chan disease.
The best way is just to observe the noise of the world.
The answer to your questions?
Ask your own heart.
$("#testjs").text("Please wait...");
$(".jumbotron p").addClass("active");
.jumbotron p.active {
color: #1f6ddd;
}
$(".jumbotron p").toggleClass("active");
...
<form id="projectForm" role="form">
<div class="form-group">
<label for="project">Please change the project:</label>
<select class="form-control" id="project">
<option value="#project1">Waiting in line</option>
<option value="#project2">Needfinding</option>
<option value="#project3">Prototyping</option>
<option value="#project4">Heuristic evaluation</option>
<option value="#project5">Visualization</option>
<option value="#project6">Social design</option>
<option value="#project7">Gestural interaction</option>
<option value="#project8">Design tools</option>
</select>
</div>
<div class="form-group">
<label for="width">To width (in pixels):</label>
<input type="number" class="form-control" id="width" placeholder="Width">
</div>
<div class="form-group">
<label for="description">And to description:</label>
<input type="text" class="form-control" id="description" placeholder="Project desicription">
</div>
<button id="submitBtn" type="button" class="btn btn-default">Submit</button>
</form>
<script src="https://code.jquery.com/jquery.js"></script>
...
function initializePage() {
...
$("#submitBtn").click(updateProject);
}
function updateProject(e) {
var projectID = $('#project').val();
$(projectID).animate({
width: $('#width').val()
});
var newText = $('#description').val();
$(projectID + " .project-description").text(newText);
}
git add static/index.html
git add static/js/introHCI.js
git add static/css/introHCI.css
git commit -m “javascript lab”
git push
heroku create
heroku apps:rename newapplicationname
git push heroku master