Skip to content

Commit

Permalink
Fixed bug at streamCache[options.label].options.message causing data …
Browse files Browse the repository at this point in the history
…transfers to be incorrectly assigned
  • Loading branch information
rwaldron committed Aug 26, 2010
1 parent 6815b8e commit 43e8e64
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 18 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ unit-tests/test.js
demo/jawz-scrape.php
demo/yakyak-chat.arc
demo/yakyak-chat.json
demo/yakyak-online.json
jquery-ui-1.9m2/
19 changes: 10 additions & 9 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<title>yak-yak-face - chat with jquery.eventsource.js</title>


<link rel="stylesheet" href="http://github.com/joshuaclayton/blueprint-css/raw/master/blueprint/screen.css" />

<link rel="stylesheet" href="/jquery-ui-1.9m2/themes/base/jquery.ui.all.css" />
<link rel="stylesheet" href="yakyak.css" />

Expand All @@ -27,21 +27,22 @@

</head>
<body>
<ul id="yak-currentusers-ul">

</ul>
<div id="container">
<div id="twitter-connect-placeholder"></div>


<header>
<h1>Yak-Yak</h1>
<p>
<a href="http://github.com/rwldrn/jquery.eventsource">Source Available At Github</a>


<span id="twitter-connect-placeholder"></span>
<span id="hint">Hint: type ?gb</span>
<a href="http://github.com/rwldrn/jquery.eventsource">Source Available At Github</a>
</p>

</header>
<section>
<article class="shadow-box">
<ul>
<ul id="yak-messages-ul">

</ul>
</article>
Expand All @@ -56,7 +57,7 @@ <h1>Yak-Yak</h1>
</form>
</span>
</footer>


<script src="yakyak-twitter.js"></script>

Expand Down
46 changes: 39 additions & 7 deletions demo/yakyak.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
var _Twttr = {};
var Yak = {
Twttr: {}
};

$(function () {

var $article = $('article');
var $article = $('article'),
$footer = $('footer');

$article.filter(':first').css({
width: $('#container').width(),
Expand All @@ -15,6 +18,9 @@ $(function () {
display:'none'
});





$.eventsource({
label: 'yakyak-messages',
Expand All @@ -29,7 +35,7 @@ $(function () {
$('<li/>', {
'data-message-id': message.id,
'html': ( message.avatar ? '<img src="'+message.avatar+'"> ' : '' ) + message.from + ' : ' + message.message
}).appendTo('ul');
}).appendTo('ul#yak-messages-ul');

$article.scrollTop($('ul').height());
}
Expand All @@ -51,16 +57,40 @@ $(function () {
dataType: 'json',
data: $.param({
'yak-message' : messageStr,
'yak-from' : _Twttr.screenName,
'yak-avatar' : _Twttr.profileImage
'yak-from' : Yak.Twttr.screenName,
'yak-avatar' : Yak.Twttr.profileImage
}),
success: function (data) {
//placeholder
}
})

});


$.eventsource({
label: 'yakyak-currentusers',
url: 'yakyak-currentusers.php',
dataType: 'json',
message: function (data) {

if ( data ) {
// this is stupid, change to check if exists
$('ul#yak-currentusers-ul').empty();

$.each(data, function (i, user) {

console.log(user);

$('<li/>', {
'data-id': user.id,
'html': '<img src="'+user.avatar+'"> ' + user.screenName
}).appendTo('ul#yak-currentusers-ul');
});
//$.eventsource('close', 'yakyak-currentusers');
}
}
});

$('#yak-message').trigger('focus');

$('#hint').hide();
Expand All @@ -71,6 +101,8 @@ $(function () {
$('#hint').hide();
});

$('footer').hide();
$footer.css({
opacity: 0
});

});
4 changes: 2 additions & 2 deletions jquery.eventsource.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@

if ( streamCache[options.label] ) {
streamCache[options.label].lastEventId++;

options.message.call(this, parsedData[0] ? parsedData[0] : null, {
streamCache[options.label].options.message.call(this, parsedData[0] ? parsedData[0] : null, {
data: parsedData,
lastEventId: streamCache[options.label].lastEventId
});
Expand Down

0 comments on commit 43e8e64

Please sign in to comment.