Commit f04a2e84 authored by Kjetil Thuen's avatar Kjetil Thuen

Small tweaks to prepare for reindroduction in nesstartouch

parent afc0caf8
......@@ -22,7 +22,7 @@
if (!execAsap) {
func.apply(obj, args);
}
timeout = null;
timeout = null;
}
if (timeout) {
......@@ -31,7 +31,7 @@
func.apply(obj, args);
}
timeout = setTimeout(delayed, threshold || timeout);
timeout = setTimeout(delayed, threshold || timeout);
};
};
......@@ -42,13 +42,13 @@
}
};
var showExpandedInfo = function () {
var showExpandedInfo = function() {
var listElem = peekedList.children("li." + settings.selectedClass),
details,
heightDiff,
marginDiff,
tarTop,
listTop,
positionRelativeToList,
scrollVal;
scrollListenersEnabled = false;
......@@ -60,11 +60,11 @@
$('#' + settings.sightScopeId).animate({height: listElem.height(),'margin-top': marginDiff + 'px'}, 'fast');
}
tarTop = $('#' + settings.sightScopeId).position().top;
listTop = listElem.offset().top;
scrollVal = listTop - settings.minTopDistance;
//positionRelativeToDocument = $('#' + settings.sightScopeId).position().top;
positionRelativeToList = listElem.offset().top;
scrollVal = positionRelativeToList - settings.minTopDistance + ($('#' + settings.sightScopeId).height() / 2);
$('body').animate({scrollTop: scrollVal}, 'fast', function () {
$('body').animate({scrollTop: scrollVal}, 'fast', function() {
scrollInProgress = false;
scrollListenersEnabled = true;
});
......@@ -89,6 +89,7 @@
}
if (element) {
$('#' + settings.sightScopeId).fadeIn();
listElem = $(element).closest('li');
if (listElem.is("LI") && listElem !== focusedListElement) {
$('#' + settings.itemInfoDivId + ':visible').slideUp(settings.timeout);
......@@ -98,7 +99,6 @@
if (typeof(sessionStorage) !=="undefined" && settings.rememberLastSelected) {
sessionStorage[sessionStorageKey] = listElem.attr('id');
}
if (asap) {
debounce(showExpandedInfo, 50, false)();
} else {
......@@ -111,16 +111,20 @@
};
var computeSightScopeOffset = function () {
return ((0) - (peekedList[0].getBoundingClientRect().height) + (settings.minTopDistance));
var offset = peekedList.find(':nth-child(2)').position().top;
console.log("offset: " + offset);
return offset;
// return parseInt(peekedList.position().top, 10) + 400;
//return ((0) - (peekedList[0].getBoundingClientRect().height) + (settings.minTopDistance));
};
var computeTargetOffset = function () {
var computeTargetOffset = function () {
var listCoords = peekedList[0].getBoundingClientRect();
var targetCoord = listCoords.top < 0 ? settings.minTopDistance : listCoords.top + settings.minTopDistance;
return targetCoord;
};
var resetGeometry = function () {
var resetGeometry = function() {
var alreadyFocusedListElement,
bodyHeight = 0,
distanceFromListEndToBodyEnd = 0,
......@@ -146,11 +150,13 @@
}
};
var findAndSelectElement = function () {
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');
......@@ -159,15 +165,15 @@
}
};
var registerEventHandlers = function () {
$(window).bind('scrollstart', function () {
var registerEventHandlers = function() {
$(window).bind('scrollstart', function(){
if (scrollListenersEnabled) {
scrollInProgress = true;
$('#' + settings.itemInfoDivId + ':visible').slideUp(settings.timeout);
}
});
$(window).bind('touchmove', function () {
$(window).bind('touchmove', function(){
//IOS specific touch event
if (scrollListenersEnabled) {
scrollInProgress = true;
......@@ -175,24 +181,24 @@
}
});
$(window).bind('scrollstop', function (e) {
$(window).bind('scrollstop', function(e){
if (scrollInProgress) {
findAndSelectElement();
}
});
peekedList.children("li").click(function () {
peekedList.children("li").click(function() {
setSelectedElement($(this).get(), true);
});
$(window).resize(function () {
$(window).resize(function() {
debounce(resetGeometry, 500, false)();
});
handlersRegistered = true;
handlersRegistered = true;
};
$.fn.listEntryInfo = function (options) {
$.fn.listEntryInfo = function(options) {
settings = $.extend({
selectedClass: "listEntryInfoSelected",
sightScopeId: "listSightScope",
......@@ -203,7 +209,7 @@
rememberLastSelected: false,
initialElement: undefined,
timeout: 100,
extendedInfoFunc: function (id) {defaultPopulateRevealDivFunc("<p><strong>" + id + "</strong> selected</p>");}
extendedInfoFunc: function(id){defaultPopulateRevealDivFunc("<p><strong>" + id + "</strong> selected</p>");}
}, options );
peekedList = this;
......@@ -255,13 +261,13 @@
}(jQuery));
/*
/*
* James Padolsey's scrollstart and scrollstop event implementation
* Lifted from http://james.padolsey.com/javascript/special-scroll-events-for-jquery/
*/
inScroll = false;
(function () {
(function(){
"use strict";
var special = $.event.special,
......@@ -269,9 +275,9 @@ inScroll = false;
uid2 = 'D' + (+new Date() + 1);
special.scrollstart = {
setup: function () {
setup: function() {
var timer,
handler = function (evt) {
handler = function(evt) {
var _self = this,
_args = arguments;
......@@ -283,7 +289,7 @@ inScroll = false;
$(this).trigger(evt.type, _args);
}
timer = setTimeout(function () {
timer = setTimeout( function(){
timer = null;
}, special.scrollstop.latency);
......@@ -294,16 +300,16 @@ inScroll = false;
}
},
teardown: function () {
teardown: function(){
$(this).unbind( 'scroll', $(this).data(uid1) );
}
};
special.scrollstop = {
latency: 100,
setup: function () {
setup: function() {
var timer,
handler = function (evt) {
handler = function(evt) {
var _self = this,
_args = arguments;
......@@ -312,7 +318,7 @@ inScroll = false;
}
if(inScroll) {
timer = setTimeout( function () {
timer = setTimeout( function(){
inScroll = false;
timer = null;
......@@ -326,7 +332,7 @@ inScroll = false;
$(this).bind('scroll', handler).data(uid2, handler);
},
teardown: function () {
teardown: function() {
$(this).unbind( 'scroll', $(this).data(uid2) );
}
};
......
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