Commit b29cfbc1 authored by Kjetil Thuen's avatar Kjetil Thuen

Use camel case consistently

parent e1251e6b
/*jshint browser:true jquery:true */
inScroll = false;
(function(){
"use strict";
var special = $.event.special,
uid1 = 'D' + (+new Date()),
uid2 = 'D' + (+new Date() + 1);
special.scrollstart = {
setup: function() {
var timer,
handler = function(evt) {
var _self = this,
_args = arguments;
if (timer) {
clearTimeout(timer);
} else {
inScroll = true;
evt.type = 'scrollstart';
$(this).trigger(evt.type, _args);
}
timer = setTimeout( function(){
timer = null;
}, special.scrollstop.latency);
};
if (!inScroll) {
$(this).bind('scroll', handler).data(uid1, handler);
}
},
teardown: function(){
$(this).unbind( 'scroll', $(this).data(uid1) );
}
};
special.scrollstop = {
latency: 100,
setup: function() {
var timer,
handler = function(evt) {
var _self = this,
_args = arguments;
if (timer) {
clearTimeout(timer);
}
if(inScroll) {
timer = setTimeout( function(){
inScroll = false;
timer = null;
evt.type = 'scrollstop';
$(this).trigger(evt.type, _args);
}, special.scrollstop.latency);
}
};
$(this).bind('scroll', handler).data(uid2, handler);
},
teardown: function() {
$(this).unbind( 'scroll', $(this).data(uid2) );
}
};
}());
(function ($) {
"use strict";
var settings = {};
......@@ -85,7 +8,9 @@ inScroll = false;
var horizontalCenter = Math.floor(window.innerWidth/2),
centerOfHeadline = 0,
focusedListElement = null,
target_top = 0,
targetTop = 0,
documentHeight = 0;
listHeight = 0;
scrollListenersEnabled = false,
scrollInProgress = false,
handlersRegistered = false;
......@@ -100,21 +25,25 @@ inScroll = false;
extendedInfoFunc: function(id){ return "<strong>" + id + "</strong>";}
}, options );
//TODO: Create the target and revealDiv elements
peekedList = this;
target_top = peekedList.position().top;
targetTop = peekedList.position().top;
peekedList.after('<div id="' + settings.targetId + '"></div>');
peekedList.after('<div id="' + settings.revealDivId + '"></div>');
peekedList.after('<div id="' + settings.targetId + '"></div>');
//TODO: Add padding under list to enable scrolling to the end
listHeight = peekedList.height();
docuementHeight = $(document).height();
$('#' + settings.targetId).css({top: target_top});
$('#' + settings.targetId).css({top: targetTop});
horizontalCenter = Math.floor(window.innerWidth/2);
$('#' + settings.revealDivId).css({top: target_top + $('#' + settings.targetId).height()});
$('#' + settings.revealDivId).css({top: targetTop + $('#' + settings.targetId).height()});
centerOfHeadline = $('#' + settings.targetId).offset().top - $(window).scrollTop() + ($('#' + settings.targetId).height() / 2);
if (!handlersRegistered) {
register_event_handlers();
registerEventHandlers();
}
set_selected_element(focusedListElement);
setSelectedElement(focusedListElement);
return this;
};
......@@ -141,7 +70,7 @@ inScroll = false;
};
};
var show_expanded_info = function() {
var showExpandedInfo = function() {
// console.log("expanding");
var listElem = peekedList.children("li." + settings.selectedClass),
......@@ -150,8 +79,15 @@ inScroll = false;
marginDiff;
scrollListenersEnabled = false;
heightDiff = $('#' + settings.targetId).height() - listElem.height();
marginDiff = parseInt($('#' + settings.targetId).css('margin-top'), 0) + heightDiff;
console.log("target height: " + $('#' + settings.targetId).height());
console.log("listElem height: " + listElem.height());
console.log("marginDiff: " + marginDiff);
console.log("heightDiff: " + heightDiff);
if (heightDiff !== 0) {
$('#' + settings.targetId).animate({height: listElem.height(),'margin-top': marginDiff + 'px'}, 'fast');
}
......@@ -160,10 +96,6 @@ inScroll = false;
var listTop = listElem.offset().top;
var scrollVal = listTop - tarTop - marginDiff;
// console.log("target top: " + tarTop);
// console.log("list top: " + listTop);
// console.log("Debouncing expand function at " + scrollVal);
$('body').animate({scrollTop: scrollVal}, 'fast');
details = settings.extendedInfoFunc(listElem.attr('id'));
......@@ -178,7 +110,7 @@ inScroll = false;
}
};
var set_selected_element = function (element, asap) {
var setSelectedElement = function (element, asap) {
if (!element) {
element = peekedList.children('li:first-child').get();
}
......@@ -190,9 +122,9 @@ inScroll = false;
listElem.addClass(settings.selectedClass);
focusedListElement = listElem;
if (asap) {
debounce(show_expanded_info, 50, false)();
debounce(showExpandedInfo, 50, false)();
} else {
debounce(show_expanded_info, 500, false)();
debounce(showExpandedInfo, 500, false)();
}
} else {
$('#' + settings.revealDivId).hide();
......@@ -200,19 +132,19 @@ inScroll = false;
}
};
var find_and_select_element = function() {
var findAndSelectElement = function() {
var newFocusedListElement = document.elementFromPoint(horizontalCenter, centerOfHeadline);
if (newFocusedListElement !== focusedListElement) {
set_selected_element(newFocusedListElement);
setSelectedElement(newFocusedListElement);
}
};
var reset_geometry = function() {
var resetGeometry = function() {
var alreadyFocusedListElement = peekedList.children("li." + settings.selectedClass);
set_selected_element(alreadyFocusedListElement);
setSelectedElement(alreadyFocusedListElement);
};
var register_event_handlers = function() {
var registerEventHandlers = function() {
$(window).bind('scrollstart', function(){
if (scrollListenersEnabled) {
scrollInProgress = true;
......@@ -236,17 +168,17 @@ inScroll = false;
$(window).bind('scrollstop', function(e){
if (scrollInProgress) {
// console.log("scrollstop");
find_and_select_element();
findAndSelectElement();
}
});
peekedList.children("li").click(function() {
// console.log("click");
set_selected_element($(this).get(), true);
setSelectedElement($(this).get(), true);
});
$(window).resize(function() {
debounce(reset_geometry, 500, false)();
debounce(resetGeometry, 500, false)();
});
handlersRegistered = true;
......@@ -254,3 +186,83 @@ inScroll = false;
}(jQuery));
/*
* James Padolsey's scrollstart and scrollstop event implementation
* Lifted from http://james.padolsey.com/javascript/special-scroll-events-for-jquery/
*/
inScroll = false;
(function(){
"use strict";
var special = $.event.special,
uid1 = 'D' + (+new Date()),
uid2 = 'D' + (+new Date() + 1);
special.scrollstart = {
setup: function() {
var timer,
handler = function(evt) {
var _self = this,
_args = arguments;
if (timer) {
clearTimeout(timer);
} else {
inScroll = true;
evt.type = 'scrollstart';
$(this).trigger(evt.type, _args);
}
timer = setTimeout( function(){
timer = null;
}, special.scrollstop.latency);
};
if (!inScroll) {
$(this).bind('scroll', handler).data(uid1, handler);
}
},
teardown: function(){
$(this).unbind( 'scroll', $(this).data(uid1) );
}
};
special.scrollstop = {
latency: 100,
setup: function() {
var timer,
handler = function(evt) {
var _self = this,
_args = arguments;
if (timer) {
clearTimeout(timer);
}
if(inScroll) {
timer = setTimeout( function(){
inScroll = false;
timer = null;
evt.type = 'scrollstop';
$(this).trigger(evt.type, _args);
}, special.scrollstop.latency);
}
};
$(this).bind('scroll', handler).data(uid2, handler);
},
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