mirror of
https://github.com/vale981/Vulcan
synced 2025-03-08 19:11:38 -05:00
finally got it to work! (I hope…)
This commit is contained in:
parent
d576fd3ac4
commit
4c1f6595a3
3 changed files with 37 additions and 54 deletions
|
@ -255,14 +255,14 @@ PostsListController = RouteController.extend({
|
||||||
Session.set('postsLimit', limit);
|
Session.set('postsLimit', limit);
|
||||||
|
|
||||||
// get posts and decorate them with rank property
|
// get posts and decorate them with rank property
|
||||||
// note: not actually used; find better way
|
// note: not actually used;
|
||||||
// posts = posts.map(function (post, index) {
|
// posts = posts.map(function (post, index) {
|
||||||
// post.rank = index;
|
// post.rank = index;
|
||||||
// return post;
|
// return post;
|
||||||
// });
|
// });
|
||||||
|
|
||||||
return {
|
return {
|
||||||
posts: posts
|
postsList: posts
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
after: function() {
|
after: function() {
|
||||||
|
|
|
@ -77,54 +77,38 @@ Template.post_item.helpers({
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// var recalculatePosition = function ($object) {
|
var recalculatePosition = function ($object, pArray) {
|
||||||
// var pArray = $object.data('positionsArray'),
|
// delta is the difference between the last two positions in the array
|
||||||
// top = $object.position().top;
|
var delta = pArray[pArray.length-2] - pArray[pArray.length-1];
|
||||||
|
|
||||||
// if(typeof pArray !== 'undefined'){
|
// if new position is different from previous position
|
||||||
|
if(delta != 0){
|
||||||
|
// send object back to previous position
|
||||||
|
$object.removeClass('animate').css("top", delta + "px");
|
||||||
|
// then wait a little and animate it to new one
|
||||||
|
setTimeout(function() {
|
||||||
|
$object.addClass('animate').css("top", "0px")
|
||||||
|
}, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// // if current position is different from the last position in the array, add current position
|
Template.post_item.rendered = function(){
|
||||||
// if(top != pArray[pArray.length-1]){
|
var instance = this,
|
||||||
// pArray.push(top);
|
$instance = $(instance.firstNode.nextSibling),
|
||||||
// $object.data('positionsArray', pArray);
|
top = $instance.position().top;
|
||||||
// }
|
|
||||||
|
|
||||||
// // delta is the difference between the last two positions in the array
|
// if this is the first render, initialize array, else push current position
|
||||||
// var delta = pArray[pArray.length-2] - pArray[pArray.length-1];
|
if(typeof instance.pArray === 'undefined'){
|
||||||
|
instance.pArray = [top]
|
||||||
|
}else{
|
||||||
|
instance.pArray.push(top);
|
||||||
|
}
|
||||||
|
|
||||||
// // if new position is different from previous position
|
// if this is *not* the first render, recalculate positions
|
||||||
// if(delta != 0){
|
if(instance.pArray.length>1)
|
||||||
|
recalculatePosition($instance, instance.pArray);
|
||||||
|
|
||||||
// // send object back to previous position
|
};
|
||||||
// $object.removeClass('animate').css("top", delta + "px").addClass('animate');
|
|
||||||
|
|
||||||
// // then wait a little and animate it to new one
|
|
||||||
// setTimeout(function() {
|
|
||||||
// $object.css("top", "0px")
|
|
||||||
// }, 1500);
|
|
||||||
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// Template.post_item.rendered = function(){
|
|
||||||
|
|
||||||
// var instance = this,
|
|
||||||
// $instance = $(instance.firstNode.nextSibling),
|
|
||||||
// top = $instance.position().top;
|
|
||||||
|
|
||||||
// instance.renderCount = (typeof instance.renderCount === 'undefined') ? 1 : instance.renderCount+1;
|
|
||||||
|
|
||||||
// if(instance.renderCount>1){
|
|
||||||
// // when one post re-renders, force all of them to recalculate their position
|
|
||||||
// $('.post').each(function(index, item){
|
|
||||||
// recalculatePosition($(item));
|
|
||||||
// });
|
|
||||||
// }else{
|
|
||||||
// $instance.data('positionsArray', [top]);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// };
|
|
||||||
|
|
||||||
Template.post_item.events = {
|
Template.post_item.events = {
|
||||||
'click .upvote-link': function(e, instance){
|
'click .upvote-link': function(e, instance){
|
||||||
|
|
|
@ -1,13 +1,12 @@
|
||||||
Template.posts_list.helpers({
|
Template.posts_list.helpers({
|
||||||
// posts : function () {
|
posts : function () {
|
||||||
// not used, forces multiple re-renders
|
this.postsList.rewind();
|
||||||
// this.postsList.rewind();
|
var posts = this.postsList.map(function (post, index, cursor) {
|
||||||
// var posts = this.postsList.map(function (post, index, cursor) {
|
post.rank = index;
|
||||||
// post.rank = index;
|
return post;
|
||||||
// return post;
|
});
|
||||||
// });
|
return posts;
|
||||||
// return posts;
|
},
|
||||||
// },
|
|
||||||
allPostsLoaded: function(){
|
allPostsLoaded: function(){
|
||||||
return false;
|
return false;
|
||||||
// TODO: find out when all posts have been loaded
|
// TODO: find out when all posts have been loaded
|
||||||
|
|
Loading…
Add table
Reference in a new issue