Merge branch 'develop' of github.com:humhub/humhub into develop

This commit is contained in:
Lucas Bartholemy 2014-05-15 21:41:34 +02:00
commit 2f75088d04
2 changed files with 69 additions and 92 deletions

View File

@ -1,8 +1,3 @@
/*
* http://www.webdeveloperjuice.com/2010/02/24/create-infinte-scroll-effect-using-jquery-with-demo/
*/
/**
* Click on an Activity wall Entry
*/
@ -17,105 +12,81 @@ function activityShowItem(wallEntryId) {
}
$(document).ready(function() {
$(document).ready(function () {
var activityLastLoadedEntryId = 0;
$.fn.scrollLoad = function(options) {
var defaults = {
url: '',
data: '',
ScrollAfterHeight: 90,
onload: function(data, itsMe) {
alert(data);
},
getUrl: function(data, itsMe) {
return '';
},
start: function(itsMe, x) {
},
continueWhile: function() {
return true;
},
getData: function(itsMe) {
return '';
}
};
// set the ID for the last loaded activity entry to 1
var activityLastLoadedEntryId = 1;
$('#activityContents').scroll(function () {
// save height of the overflow container
var _containerHeight = $("#activityContents").height();
// save scroll height
var _scrollHeight = $("#activityContents").prop("scrollHeight");
// save current scrollbar position
var _currentScrollPosition = $('#activityContents').scrollTop();
// load more activites if current scroll position is near scroll height
if (_currentScrollPosition >= (_scrollHeight - _containerHeight - 1)) {
console.log('last id: ' + activityLastLoadedEntryId);
loadMore();
for (var eachProperty in defaults) {
if (options[ eachProperty ]) {
defaults[ eachProperty ] = options[ eachProperty ];
}
}
return this.each(function() {
});
/**
* load new activities
*/
function loadMore() {
// save url for activity reloads
var _url = activityReloadUrl.replace('lastEntryId', activityLastLoadedEntryId);
if (activityLastLoadedEntryId == 1) {
// save url for the first loading
_url = activityStartUrl;
}
// show loader
$("#activityLoader").show();
// load json
jQuery.getJSON(_url, function (json) {
// hide loader
$("#activityLoader").hide();
if (activityLastLoadedEntryId == 1 && json.counter == 0) {
// show placeholder if no results exists
$("#activityEmpty").show();
} else {
this.scrolling = false;
this.scrollPrev = this.onscroll ? this.onscroll : null;
$(this).bind('scroll', function(e) {
if (this.scrollPrev) {
this.scrollPrev();
}
// add new activities
$('#activityContents').prepend(json.output);
if (this.scrolling)
return;
if (Math.round($(this).prop('scrollTop') / ($(this).prop('scrollHeight') - $(this).prop('clientHeight')) * 100) > defaults.ScrollAfterHeight) {
$this = $(this);
defaults.start.call(this, $this);
this.scrolling = true;
jQuery.getJSON(defaults.getUrl.call(), function(json) {
$this[ 0 ].scrolling = false;
defaults.onload.call($this[ 0 ], json, $this[ 0 ]);
if (!defaults.continueWhile.call($this[ 0 ], json)) {
$this.unbind('scroll');
}
});
// save the last activity id for the next reload
activityLastLoadedEntryId = json.lastEntryId;
}
}
});
});
}
// First Load Request
jQuery.getJSON(activityStartUrl, function(json) {
$("#activityLoader").hide();
//$(json.output).appendTo('#activityContents').fadeIn('fast');
$('#activityContents').append(json.output);
activityLastLoadedEntryId = json.lastEntryId;
// load the first activities
loadMore();
if (json.counter == 0) {
$("#activityEmpty").show();
return;
}
// Install autoloader
$('#activityStream').scrollLoad({
ScrollAfterHeight: 75,
getUrl: function( ) {
url = activityReloadUrl;
url = url.replace('lastEntryId', activityLastLoadedEntryId);
return url;
},
start: function() {
$("#activityLoader").show();
},
onload: function(json) {
//$(json.output).appendTo('#activityContents').fadeIn('fast');
$('#activityContents').append(json.output);
activityLastLoadedEntryId = json.lastEntryId;
},
continueWhile: function(json) {
if (json.counter == 0) {
$("#activityLoader").hide();
return false;
}
return true;
}
});
});
});

View File

@ -17,8 +17,9 @@
<div class="placeholder"><?php echo Yii::t('ActivityModule.base', 'There are no activities yet.'); ?></div>
</div>
<ul id="activityContents" class="media-list activities">
<li class="loader" id="activityLoader"></li>
</ul>
<div class="loader" id="activityLoader"></div>
</div>
</div>
@ -33,6 +34,11 @@
railpadding:{top:0,right:3,left:0,bottom:0}
});
// update nicescroll object with new content height after ajax request
$(document).ajaxComplete(function(event, xhr, settings) {
$("#activityContents").getNiceScroll().resize();
})
</script>