Skip to content

Commit

Permalink
채널 접속 편하게
Browse files Browse the repository at this point in the history
  • Loading branch information
sim0629 committed May 8, 2012
1 parent b49cb95 commit ef5b8c5
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 19 deletions.
17 changes: 9 additions & 8 deletions render/channel.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
<a id="dummy" name=""></a>
<div id="wrapper" data-role="page">
<div data-role="header" data-position="fixed" data-theme="d">
<h1 id="channel">How to use SIRC</h1>
<a href="/" data-role="button" data-icon="home" data-iconpos="notext">home</a>
<h1 id="channel">SIRC</h1>
<a id="setting" data-role="button" data-icon="gear" data-iconpos="notext">setting</a>
<div id="menu" style="display:none;">
<ul data-role="listview">
Expand All @@ -31,18 +32,18 @@ <h1 id="channel">How to use SIRC</h1>
</div>
</div>
<div data-role="content" data-theme="d">
<ul id="log" data-role="listview">
<li><strong>Append the channel name to URL</strong> (as hash fragment) where you want to join.</li>
<li>(Ex) sirc.domain.com/<strong>#sgm</strong></li>
<li>That's all.</li>
<li>Welcome, <strong>{{ account }}</strong>!</li>
<li>Enjoy your <strong>irc</strong>ing!</li>
<ul id="log" data-role="listview" data-split-theme="d" data-split-icon="delete">
<li><a href="https://github.com/sim0629/sirc/wiki" target="_blank">https://github.com/sim0629/sirc/wiki</a></li>
<li><a>Welcome, <strong>{{ account }}</strong>!</a></li>
<li><a>Enjoy your <strong>irc</strong>ing!</a></li>
{% for channel in channels %}
<li><a href="{{ channel['channel'] }}"><strong>{{ channel['channel'] }}</strong></a><a sirc="delete" channel="{{ channel['channel'] }}">delete</a></li>
{% endfor %}
</ul>
</div>
<div data-role="footer" data-position="fixed" data-theme="d">
<form id="send" method="get" onsubmit="return false;">
<input id="message" name="message" type="text" />
<input id="message" name="message" type="text" value="#sgm" />
</form>
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions render/preauth.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=no" />
<title>SIRC</title>
<script type="text/javascript">
<!--
Expand Down
4 changes: 2 additions & 2 deletions static/css/sirc.css
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
@charset "utf-8";

div.datetime { font-size:8px; text-align:center; float:left; letter-spacing:-1px; line-height:1; }
div.datetime { font-size:8px; text-align:center; float:left; line-height:1; color:#666666; }
div.source { float:left; margin:0px 5px; }
span.nick { font-weight:bold; }
div.message { word-wrap:break-word; }
ul#log li { padding:5px !important; font-weight:normal; border-color:#efefef; }
label { float:left; padding-top:7px; }
input#message.disabled { color:#cdcdcd; }

44 changes: 36 additions & 8 deletions static/js/sirc.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ var scroll = function(pos, duration) {
$('body,html,document').animate({scrollTop: pos}, duration);
};

var trim = function(str){
return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
};

// Ajax Calls

var sirc_update = function() {
Expand Down Expand Up @@ -107,25 +111,32 @@ var sirc_downdate = function(callback) {
};

var sirc_send = function() {
if(channel == '') return false;
var message = $('input#message').val();
if(message == '') return false;
var message = trim($('input#message').val());
if(message.length < 1) return false;
if(channel == '') {
window.location.hash = (message.substr(0, 1) == '#' ? '' : '#') + message;
$('input#message').val('');
return false;
}
$.ajax({
type: 'GET',
url: '/send/',
data: 'channel=' + encodeURIComponent(channel) + '&message=' + encodeURIComponent($('input#message').val()),
dataType: 'xml',
success: function(xml) {
add_process(xml, 'send');
$('input#message').removeAttr('disabled');
$('input#message').removeClass('disabled');
$('input#message').val('');
$('form#send').removeAttr('disabled');
add_process(xml, 'send');
},
error: function(xhr) {
//alert('send: ' + xhr.responseText);
$('form#send').removeAttr('disabled');
$('input#message').removeAttr('disabled');
$('input#message').removeClass('disabled');
}
});
$('form#send').attr('disabled', 'disabled');
$('input#message').attr('disabled', 'disabled');
$('input#message').addClass('disabled');
return false;
};

Expand All @@ -136,18 +147,35 @@ var sirc_join = function() {
$('title').html(channel + ' - SIRC');
$('h1#channel').html(channel);
$('ul#log').empty();
$('input#message').val('');
last_update = last_downdate = datetime_now();
sirc_downdate(function() { scroll(SCROLL_END, 1000); });
setTimeout("sirc_update();", 500);
return false;
};

var sirc_delete = function(a) {
$.ajax({
type: 'GET',
url: '/delete/',
data: 'channel=' + encodeURIComponent($(a).attr('channel')),
success: function() {
$(a).parent().remove();
},
error: function(xhr) {
//alert('delete: ' + xhr.responseText);
}
});
return false;
};

// Main

$(document).ready(function() {
$('a#setting').click(function() { $('div#menu').toggle(); return false; });
$('a[sirc="delete"]').click(function() { return sirc_delete(this); });
$('form#send').submit(function() { return sirc_send(); });
$('input#message').keydown(function (e) { if(e.keyCode == 13) return sirc_send(); });
$(window).hashchange(function() { transition_id++; return sirc_join(); });
$(window).hashchange(function() { if(window.location.hash == '') window.location.reload(); transition_id++; return sirc_join(); });
sirc_join();
});
16 changes: 15 additions & 1 deletion wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ def application(environ, start_response):
return downdate(environ, start_response, session, parameters)
elif path.startswith('/send/'):
return send(environ, start_response, session, parameters)
elif path.startswith('/delete/'):
return delete(environ, start_response, session, parameters)
elif path == '/':
return default(environ, start_response, session, parameters)
else:
Expand Down Expand Up @@ -132,6 +134,8 @@ def update(environ, start_response, session, parameters):
return error(start_response, message = 'no transition_id')
channel = parameters['channel'][0].decode('utf-8').lower()
transition_id = parameters['transition_id'][0].decode('utf-8')
if db[session['account']].find({'channel': channel}).count() == 0:
db[session['account']].insert({'channel': channel})
context['channel'] = channel
context['transition_id'] = transition_id
logs = []
Expand Down Expand Up @@ -199,8 +203,18 @@ def send(environ, start_response, session, parameters):
start_response('200 OK', [('Content-Type', 'text/xml; charset=utf-8')])
return [render('result.xml', context)]

def delete(environ, start_response, session, parameters):
if 'channel' not in parameters:
return error(start_response, message = 'no channel')
channel = parameters['channel'][0].decode('utf-8').lower()
db[session['account']].remove({'channel': channel})
start_response('200 OK', [])
return []

def default(environ, start_response, session, parameters):
context = {'account': session['account']}
context = {}
context['account'] = session['account']
context['channels'] = db[session['account']].find(fields = ['channel'])
db.session.remove({'datetime': {'$lt': datetime.datetime.now() - datetime.timedelta(1)}})
start_response('200 OK', [('Content-Type', 'text/html; charset=utf-8')])
return [render('channel.html', context)]
Expand Down

0 comments on commit ef5b8c5

Please sign in to comment.