actionQueue in practice
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Like Button</title> | |
<!-- just getting this stuff out of the way --> | |
<style type="text/css" media="screen"> | |
body {width: 750px;margin: 0 auto;} | |
p { margin: 10px 0 5px 0;} | |
.like-button{padding:5px 10px 5px 5px;border-radius:3px;background-color:#eee;color:#000;text-decoration:none;} | |
.like-button .star{text-shadow:magenta 1px 1px,magenta 2px 2px,magenta 3px 3px;} | |
.un-liked .star,.liked:hover .star{color:#fff;} | |
.liked .star,.un-liked:hover .star{color:#000;} | |
</style> | |
<script type="text/javascript"> | |
// build your global we can use to contain all our code | |
var A = {}; | |
</script> | |
<!-- actionQueue --> | |
<script src="https://raw.github.com/gist/1398040/098b5d6388e0b05ca28bbf7e95849fa208b36f17/actionQueue.js" type="text/javascript"></script> | |
<script type="text/javascript" charset="utf-8"> | |
A.actionQueue.register( | |
'like-button', | |
{ | |
interim: function(id){ | |
var element = document.getElementById(id); | |
element.className = 'like-button liked'; | |
}, | |
cleanup: function(id){ | |
var element = document.getElementById('like-button-text'); | |
element.innerHTML = 'Done!'; | |
} | |
}, | |
'like-handler' | |
); | |
</script> | |
</head> | |
<body> | |
<h1>A Simple Like Button</h1> | |
<p> | |
<a href='#' id='like-button' class='like-button un-liked' onclick='A.actionQueue.queue_click(this.id);'> | |
<span class='star'>★</span> | |
<span id='like-button-text' class='text'>Like</span> | |
</a> | |
</p> | |
<br/><br/><br/><br/> | |
<p><a href='#' onclick='A.actionQueue.module_loaded("like-handler");'>Load the module</a> | |
<div class='qunit-output'> | |
<h1 id="qunit-header">QUnit example</h1> | |
<h2 id="qunit-banner"></h2> | |
<h2 id="qunit-userAgent"></h2> | |
<ol id="qunit-tests"></ol> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment