Commit c79aeb05 authored by Kjetil Thuen's avatar Kjetil Thuen

Automatically select first element on init.

parent f661baaf
...@@ -82,9 +82,9 @@ ...@@ -82,9 +82,9 @@
element = $('#' + peekedList.attr('id') + ' li[id=\'' + sessionStorage[sessionStorageKey] + '\']').get(); element = $('#' + peekedList.attr('id') + ' li[id=\'' + sessionStorage[sessionStorageKey] + '\']').get();
} else if (settings.initialElement) { } else if (settings.initialElement) {
element = $('#' + peekedList.attr('id') + ' li[id=\'' + settings.initialElement + '\']').get(); 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 @@ ...@@ -124,6 +124,21 @@
return targetCoord; 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 resetGeometry = function() {
var alreadyFocusedListElement, var alreadyFocusedListElement,
bodyHeight = 0, bodyHeight = 0,
...@@ -134,11 +149,6 @@ ...@@ -134,11 +149,6 @@
alreadyFocusedListElement = peekedList.children("li." + settings.selectedClass); alreadyFocusedListElement = peekedList.children("li." + settings.selectedClass);
if (alreadyFocusedListElement.length > 0) {
setSelectedElement(alreadyFocusedListElement[0]);
} else {
setSelectedElement();
}
listHeight = peekedList.outerHeight(); listHeight = peekedList.outerHeight();
bodyHeight = $('body').outerHeight(); bodyHeight = $('body').outerHeight();
viewPortHeight = $(window).height(); viewPortHeight = $(window).height();
...@@ -148,23 +158,15 @@ ...@@ -148,23 +158,15 @@
if (distanceFromListEndToBodyEnd < distanceFromTargetToViewportEnd) { if (distanceFromListEndToBodyEnd < distanceFromTargetToViewportEnd) {
peekedList.css("padding-bottom", "+=" + (distanceFromTargetToViewportEnd - distanceFromListEndToBodyEnd)); peekedList.css("padding-bottom", "+=" + (distanceFromTargetToViewportEnd - distanceFromListEndToBodyEnd));
} }
};
var findAndSelectElement = function() { if (alreadyFocusedListElement.length > 0) {
if (peekedList[0].getBoundingClientRect().top < settings.minTopDistance) { setSelectedElement(alreadyFocusedListElement[0]);
$('#' + settings.sightScopeId).fadeIn();
} else { } else {
$('#' + settings.sightScopeId).fadeOut(); setSelectedElement();
$('.' + 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 registerEventHandlers = function() { var registerEventHandlers = function() {
$(window).bind('scrollstart', function(){ $(window).bind('scrollstart', function(){
if (scrollListenersEnabled) { 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