Commit f04a2e84 authored by Kjetil Thuen's avatar Kjetil Thuen

Small tweaks to prepare for reindroduction in nesstartouch

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