Commit c79aeb05 authored by Kjetil Thuen's avatar Kjetil Thuen

Automatically select first element on init.

parent f661baaf
......@@ -82,9 +82,9 @@
element = $('#' + peekedList.attr('id') + ' li[id=\'' + sessionStorage[sessionStorageKey] + '\']').get();
} else if (settings.initialElement) {
element = $('#' + peekedList.attr('id') + ' li[id=\'' + settings.initialElement + '\']').get();
if (element.length < 1) {
element = peekedList.children('li:first-child').get();
}
}
if (!element || element.length < 1) {
element = peekedList.children('li:first-child').get();
}
}
......@@ -124,6 +124,21 @@
return targetCoord;
};
var findAndSelectElement = function() {
if (peekedList[0].getBoundingClientRect().top < settings.minTopDistance) {
$('#' + settings.sightScopeId).fadeIn();
} else {
$('#' + settings.sightScopeId).fadeOut();
$('.' + settings.selectedClass).removeClass(settings.selectedClass);
return;
}
var newFocusedListElement = $(document.elementFromPoint(horizontalCenter, computeTargetOffset())).closest('li');
if (newFocusedListElement.length > 0 && newFocusedListElement.attr('id') !== focusedListElement.attr('id')) {
setSelectedElement(newFocusedListElement);
}
};
var resetGeometry = function() {
var alreadyFocusedListElement,
bodyHeight = 0,
......@@ -134,11 +149,6 @@
alreadyFocusedListElement = peekedList.children("li." + settings.selectedClass);
if (alreadyFocusedListElement.length > 0) {
setSelectedElement(alreadyFocusedListElement[0]);
} else {
setSelectedElement();
}
listHeight = peekedList.outerHeight();
bodyHeight = $('body').outerHeight();
viewPortHeight = $(window).height();
......@@ -148,23 +158,15 @@
if (distanceFromListEndToBodyEnd < distanceFromTargetToViewportEnd) {
peekedList.css("padding-bottom", "+=" + (distanceFromTargetToViewportEnd - distanceFromListEndToBodyEnd));
}
};
var findAndSelectElement = function() {
if (peekedList[0].getBoundingClientRect().top < settings.minTopDistance) {
$('#' + settings.sightScopeId).fadeIn();
if (alreadyFocusedListElement.length > 0) {
setSelectedElement(alreadyFocusedListElement[0]);
} else {
$('#' + settings.sightScopeId).fadeOut();
$('.' + settings.selectedClass).removeClass(settings.selectedClass);
return;
}
var newFocusedListElement = $(document.elementFromPoint(horizontalCenter, computeTargetOffset())).closest('li');
if (newFocusedListElement.length > 0 && newFocusedListElement.attr('id') !== focusedListElement.attr('id')) {
setSelectedElement(newFocusedListElement);
setSelectedElement();
}
};
var registerEventHandlers = function() {
$(window).bind('scrollstart', function(){
if (scrollListenersEnabled) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment