actuality JS
Signed-off-by: bachy <git@g-u-i.net>
This commit is contained in:
parent
f8af96a85b
commit
493d3bf780
File diff suppressed because one or more lines are too long
@ -6,7 +6,9 @@ MaterioSearchApiAjax = function(){
|
||||
|
||||
var _History = window.History,
|
||||
_isloadingresults = false;
|
||||
_$content = $('#content');
|
||||
_$content = $('#content'),
|
||||
isExplore = $('.search-results', _$content).length,
|
||||
isActuality = $('.actuality-items', _$content).length;
|
||||
// TODO: define $content by module settings
|
||||
/**
|
||||
* init()
|
||||
@ -44,27 +46,29 @@ MaterioSearchApiAjax = function(){
|
||||
|
||||
_$content
|
||||
.bind('jsp-initialised', function(event, isScrollable){
|
||||
// trace('isScrollable = '+isScrollable);
|
||||
trace('isScrollable = '+isScrollable);
|
||||
// TODO: better to check scroll-y than isscrollable, load next page before the end of scroll
|
||||
if(!isScrollable)
|
||||
loadNextResultsPage();
|
||||
infinitScrollPager();
|
||||
// TODO: what happend when there is no more page
|
||||
})
|
||||
.bind('jsp-scroll-y', function(event, scrollPositionY, isAtTop, isAtBottom){
|
||||
if(isAtBottom)
|
||||
loadNextResultsPage();
|
||||
infinitScrollPager();
|
||||
});
|
||||
|
||||
// trigger updated event on search results for direct html loading
|
||||
if($('.search-results', _$content).length){
|
||||
// trigger updated event for direct html loading
|
||||
setTimeout(function(){
|
||||
var event = jQuery.Event('resultsupdated');
|
||||
event.container = $('.search-results', _$content);
|
||||
$(window).trigger(event);
|
||||
var event = jQuery.Event('resultschanged');
|
||||
|
||||
if(isExplore)
|
||||
event.container = $('.search-results', _$content);
|
||||
|
||||
if(isActuality)
|
||||
event.container = $('.actuality-items', _$content);
|
||||
|
||||
$.event.trigger(event);
|
||||
}, 10);
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
@ -134,38 +138,63 @@ MaterioSearchApiAjax = function(){
|
||||
/**
|
||||
* infinit scroll
|
||||
*/
|
||||
function loadNextResultsPage(){
|
||||
function infinitScrollPager(){
|
||||
var $nextpage = $('ul.pager .pager-current', _$content).next(),
|
||||
href = $('a', $nextpage).attr('href');
|
||||
|
||||
if(href){
|
||||
var keys = href.match(/explore\/([^\/|\?]+)/);
|
||||
var page = href.match(/\?page=([0-9]+)/);
|
||||
if (isExplore)
|
||||
loadNextResultsPage(href);
|
||||
|
||||
if(!_isloadingresults){
|
||||
_isloadingresults = true;
|
||||
$('.materiobase-results', _$content).addClass('loading');
|
||||
$.getJSON('/materio_search_api_ajax/search/'+keys[1]+'/'+page[1], function(json){
|
||||
// trace('json', json);
|
||||
_isloadingresults = false;
|
||||
$('.materiobase-results', _$content).removeClass('loading');
|
||||
addNextpage(json);
|
||||
});
|
||||
}
|
||||
if(isActuality)
|
||||
loadNextActualityPage(href);
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
function addNextpage(json){
|
||||
function loadNextResultsPage(href){
|
||||
// trace('loadNextResultsPage');
|
||||
if(!_isloadingresults){
|
||||
var keys = href.match(/explore\/([^\/|\?]+)/);
|
||||
var page = href.match(/\?page=([0-9]+)/);
|
||||
var url = Drupal.settings.basePath+Drupal.settings.pathPrefix+'materio_search_api_ajax/search/'+keys[1]+'/'+page[1];
|
||||
|
||||
loadNextPage(url, $('.materiobase-results', _$content), '.search-results');
|
||||
}
|
||||
};
|
||||
|
||||
function loadNextActualityPage(href){
|
||||
// trace('loadNextActualityPage');
|
||||
if(!_isloadingresults){
|
||||
var page = href.match(/\?page=([0-9]+)/);
|
||||
var url = Drupal.settings.basePath+Drupal.settings.pathPrefix+'materio_search_api_ajax/actuality/'+page[1];
|
||||
|
||||
loadNextPage(url, $('.materiobase-actuality', _$content), '.actuality-items');
|
||||
}
|
||||
};
|
||||
|
||||
function loadNextPage(url, $container, target){
|
||||
trace('loadNextPage');
|
||||
_isloadingresults = true;
|
||||
$container.addClass('loading');
|
||||
$.getJSON(url, function(json){
|
||||
trace('json', json);
|
||||
_isloadingresults = false;
|
||||
$container.removeClass('loading');
|
||||
addNextpage(json, target);
|
||||
});
|
||||
};
|
||||
|
||||
function addNextpage(json, container_class){
|
||||
var $newcontent = $(json.return),
|
||||
$newresults = $('.search-results', $newcontent).children('article').addClass('just-added'),
|
||||
$newitems = $(container_class, $newcontent).children('article').addClass('just-added'),
|
||||
$newpager = $('ul.pager', $newcontent);
|
||||
|
||||
$('.search-results', _$content).append($newresults);
|
||||
$(container_class, _$content).append($newitems);
|
||||
$('ul.pager', _$content).replaceWith($newpager);
|
||||
|
||||
$('.search-results', _$content).children('.just-added').each(function(i){
|
||||
$(container_class, _$content).children('.just-added').each(function(i){
|
||||
// $(this).delay(5000*i).removeClass('just-added');
|
||||
var $this = $(this);
|
||||
setTimeout(function(){
|
||||
@ -174,8 +203,8 @@ MaterioSearchApiAjax = function(){
|
||||
});
|
||||
|
||||
var event = jQuery.Event('resultscompleted');
|
||||
event.container = $('.search-results', _$content);
|
||||
$(window).trigger(event);
|
||||
event.container = $(container_class, _$content);
|
||||
$.event.trigger(event);
|
||||
};
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user