Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Это файлики для моего второго скринкаста. Они еще проще, чем первые. Подробности можно http://shrtdb.com:8432/
<html>
<head>
<title>Girls gone wild!</title>
<link rel="stylesheet" type="text/css" href="/static/style.css">
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script type="text/javascript" src="http://localhost:8080/application.js"></script>
<script type="text/javascript">
$(document).ready(function () {
var jug = new Juggernaut;
jug.subscribe('babes', function (data) {
changeValue(data);
});
$('li').click(function () {
var mash = $('li');
for (var i = mash.length - 1; i >= 0; i--) {
if (this == mash[i]) {
$.ajax({
url: '/vote/' + i,
method: 'POST',
success: function (data) {
changeValue(data)
}
})
};
};
})
});
function changeValue(data) {
$('.votescounter')[data.babe].innerHTML = data.result;
};
</script>
</head>
<body>
<ul>
<li><img src="/static/babes/1.jpeg"/><span class="votescounter"></span></li>
<li><img src="/static/babes/2.jpeg"/><span class="votescounter"></span></li>
<li><img src="/static/babes/3.jpeg"/><span class="votescounter"></span></li>
<li><img src="/static/babes/4.jpeg"/><span class="votescounter"></span></li>
<li><img src="/static/babes/5.jpeg"/><span class="votescounter"></span></li>
</ul>
</body>
</html>
from flask import Flask, redirect, jsonify
from juggernaut import Juggernaut
from redis import Redis
app = Flask(__name__)
app.debug = True
db = Redis()
jug = Juggernaut()
@app.route('/')
def hello():
return redirect('/static/index.html')
@app.route('/vote/<int:voteid>', methods=['POST'])
def vote(voteid):
if voteid < 0 or voteid > 4:
return jsonify({'error': 'strange vote?!'})
res = db.incr('babes:vote:' + str(voteid))
result = {'result': res, 'babe': voteid}
jug.publish('babes', result)
return jsonify(result)
if __name__ == '__main__':
app.run()
body {
background-color: #f0f0f0;
}
ul {
list-style-type: none;
}
.votescounter {
font-size: 200px;
margin-left: 100px;
color: #505050;
}
@nomolosvulgaris

Ишь какая кадавра на jQuery: я аж пароль от гитхаба вспомнил! Кажется, мои маленькие исправления (в форке) функциональность не рушат. Спасибо за скринкаст!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.