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,
|
var _History = window.History,
|
||||||
_isloadingresults = false;
|
_isloadingresults = false;
|
||||||
_$content = $('#content');
|
_$content = $('#content'),
|
||||||
|
isExplore = $('.search-results', _$content).length,
|
||||||
|
isActuality = $('.actuality-items', _$content).length;
|
||||||
// TODO: define $content by module settings
|
// TODO: define $content by module settings
|
||||||
/**
|
/**
|
||||||
* init()
|
* init()
|
||||||
@ -44,27 +46,29 @@ MaterioSearchApiAjax = function(){
|
|||||||
|
|
||||||
_$content
|
_$content
|
||||||
.bind('jsp-initialised', function(event, isScrollable){
|
.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
|
// TODO: better to check scroll-y than isscrollable, load next page before the end of scroll
|
||||||
if(!isScrollable)
|
if(!isScrollable)
|
||||||
loadNextResultsPage();
|
infinitScrollPager();
|
||||||
// TODO: what happend when there is no more page
|
// TODO: what happend when there is no more page
|
||||||
})
|
})
|
||||||
.bind('jsp-scroll-y', function(event, scrollPositionY, isAtTop, isAtBottom){
|
.bind('jsp-scroll-y', function(event, scrollPositionY, isAtTop, isAtBottom){
|
||||||
if(isAtBottom)
|
if(isAtBottom)
|
||||||
loadNextResultsPage();
|
infinitScrollPager();
|
||||||
});
|
});
|
||||||
|
|
||||||
// trigger updated event on search results for direct html loading
|
// trigger updated event for direct html loading
|
||||||
if($('.search-results', _$content).length){
|
|
||||||
setTimeout(function(){
|
setTimeout(function(){
|
||||||
var event = jQuery.Event('resultsupdated');
|
var event = jQuery.Event('resultschanged');
|
||||||
event.container = $('.search-results', _$content);
|
|
||||||
$(window).trigger(event);
|
if(isExplore)
|
||||||
|
event.container = $('.search-results', _$content);
|
||||||
|
|
||||||
|
if(isActuality)
|
||||||
|
event.container = $('.actuality-items', _$content);
|
||||||
|
|
||||||
|
$.event.trigger(event);
|
||||||
}, 10);
|
}, 10);
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -134,38 +138,63 @@ MaterioSearchApiAjax = function(){
|
|||||||
/**
|
/**
|
||||||
* infinit scroll
|
* infinit scroll
|
||||||
*/
|
*/
|
||||||
function loadNextResultsPage(){
|
function infinitScrollPager(){
|
||||||
var $nextpage = $('ul.pager .pager-current', _$content).next(),
|
var $nextpage = $('ul.pager .pager-current', _$content).next(),
|
||||||
href = $('a', $nextpage).attr('href');
|
href = $('a', $nextpage).attr('href');
|
||||||
|
|
||||||
if(href){
|
if(href){
|
||||||
var keys = href.match(/explore\/([^\/|\?]+)/);
|
if (isExplore)
|
||||||
var page = href.match(/\?page=([0-9]+)/);
|
loadNextResultsPage(href);
|
||||||
|
|
||||||
if(!_isloadingresults){
|
if(isActuality)
|
||||||
_isloadingresults = true;
|
loadNextActualityPage(href);
|
||||||
$('.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);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
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),
|
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);
|
$newpager = $('ul.pager', $newcontent);
|
||||||
|
|
||||||
$('.search-results', _$content).append($newresults);
|
$(container_class, _$content).append($newitems);
|
||||||
$('ul.pager', _$content).replaceWith($newpager);
|
$('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');
|
// $(this).delay(5000*i).removeClass('just-added');
|
||||||
var $this = $(this);
|
var $this = $(this);
|
||||||
setTimeout(function(){
|
setTimeout(function(){
|
||||||
@ -174,8 +203,8 @@ MaterioSearchApiAjax = function(){
|
|||||||
});
|
});
|
||||||
|
|
||||||
var event = jQuery.Event('resultscompleted');
|
var event = jQuery.Event('resultscompleted');
|
||||||
event.container = $('.search-results', _$content);
|
event.container = $(container_class, _$content);
|
||||||
$(window).trigger(event);
|
$.event.trigger(event);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user