Skip to content
This repository has been archived by the owner on May 4, 2020. It is now read-only.
/ scenic Public archive

Commit

Permalink
Add client functions to load picture from server.
Browse files Browse the repository at this point in the history
On 'picture_changed', load picture and show in the
middle of the main view.
  • Loading branch information
HyeonJe Jun committed Nov 16, 2012
1 parent a5fa24b commit 4cc246f
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 1 deletion.
19 changes: 18 additions & 1 deletion client/css/scenic.css
Expand Up @@ -37,7 +37,11 @@ body {
#ChatButton.off .off-text { display: none; }

#content {
margin-top:80px;
margin-top:41px;
}

.container {
padding-top:40px;
}

.center-aligned {
Expand Down Expand Up @@ -244,6 +248,10 @@ body {
#Chat {
top: 51px;
}

#content {
margin-top:-20px;
}
}

@media(max-width: 767px) {
Expand Down Expand Up @@ -324,3 +332,12 @@ body {
background-position: -50px 0;
}
}

.picture-wrapper {
text-align: center;
}

.picture-wrapper .picture {
max-width: 100%;
max-height: 100%;
}
8 changes: 8 additions & 0 deletions client/js/socket.js
Expand Up @@ -73,6 +73,14 @@ function Socket(channel) {
window.chat_view.updateUserlist(data.userlist);
});

this.io.on('picture_changed', function(data) {
var pid = data.pid,
width = data.width,
height = data.height;

window.app_view.main_view.loadPicture(pid, width, height);
});

this.io.on('error', function(data) {
// log the error
console.log('Scenic socket exception: '+data.type);
Expand Down
3 changes: 3 additions & 0 deletions client/js/views/app-view.js
Expand Up @@ -6,6 +6,9 @@ var AppView = Backbone.View.extend({
// nothing to do!
},
render: function(router) {
// remove picture resize handler
$(window).unbind('resize.picture');

if(router && router.channel) {
this.channel = router.channel;
}
Expand Down
23 changes: 23 additions & 0 deletions client/js/views/channel-view.js
Expand Up @@ -9,5 +9,28 @@ var ChannelView = Backbone.View.extend({
var channel_content = ich.channel_template({channel: channel});

$('#content').html(channel_content);
},
loadPicture: function(pid, width, height) {
var picture = ich.picture_template({pid: pid});

$('#content').html(picture);

// function to adjust picture height
var adjustHeight = function() {
var max_height = $(window).height() - $(picture).offset().top;
$(picture).height(max_height);

// set vertical align center
if(max_height > height) {
$(picture).css({paddingTop: parseInt((max_height - height)/2)});
}
};
adjustHeight();

// set window.resize handler
$(window).unbind('resize.picture');
$(window).bind('resize.picture', function() {
adjustHeight();
});
}
});
4 changes: 4 additions & 0 deletions views/templates.jade
Expand Up @@ -128,3 +128,7 @@ script#upload_pic_template(type='text/html')
.modal-footer
button.btn(data-dismiss='modal', area-hidden='true') Close
button.btn.btn-primary.upload-pic Upload

script#picture_template(type='text/html')
.picture-wrapper
img.picture(src='/picture/{{ pid }}', alt='{{ pid }}')

0 comments on commit 4cc246f

Please sign in to comment.