Commit b29cfbc1 authored by Kjetil Thuen's avatar Kjetil Thuen
Browse files

Use camel case consistently

parent e1251e6b
/*jshint browser:true jquery:true */ /*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 ($) { (function ($) {
"use strict"; "use strict";
var settings = {}; var settings = {};
...@@ -85,7 +8,9 @@ inScroll = false; ...@@ -85,7 +8,9 @@ inScroll = false;
var horizontalCenter = Math.floor(window.innerWidth/2), var horizontalCenter = Math.floor(window.innerWidth/2),
centerOfHeadline = 0, centerOfHeadline = 0,
focusedListElement = null, focusedListElement = null,
target_top = 0, targetTop = 0,
documentHeight = 0;
listHeight = 0;
scrollListenersEnabled = false, scrollListenersEnabled = false,
scrollInProgress = false, scrollInProgress = false,
handlersRegistered = false; handlersRegistered = false;
...@@ -100,21 +25,25 @@ inScroll = false; ...@@ -100,21 +25,25 @@ inScroll = false;
extendedInfoFunc: function(id){ return "<strong>" + id + "</strong>";} extendedInfoFunc: function(id){ return "<strong>" + id + "</strong>";}
}, options ); }, options );
//TODO: Create the target and revealDiv elements
peekedList = this; 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.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); 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); centerOfHeadline = $('#' + settings.targetId).offset().top - $(window).scrollTop() + ($('#' + settings.targetId).height() / 2);
if (!handlersRegistered) { if (!handlersRegistered) {
register_event_handlers(); registerEventHandlers();
} }
set_selected_element(focusedListElement); setSelectedElement(focusedListElement);
return this; return this;
}; };
...@@ -141,7 +70,7 @@ inScroll = false; ...@@ -141,7 +70,7 @@ inScroll = false;
}; };
}; };
var show_expanded_info = function() { var showExpandedInfo = function() {
// console.log("expanding"); // console.log("expanding");
var listElem = peekedList.children("li." + settings.selectedClass), var listElem = peekedList.children("li." + settings.selectedClass),
...@@ -150,8 +79,15 @@ inScroll = false; ...@@ -150,8 +79,15 @@ inScroll = false;
marginDiff; marginDiff;
scrollListenersEnabled = false; scrollListenersEnabled = false;
heightDiff = $('#' + settings.targetId).height() - listElem.height(); heightDiff = $('#' + settings.targetId).height() - listElem.height();
marginDiff = parseInt($('#' + settings.targetId).css('margin-top'), 0) + heightDiff; 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) { if (heightDiff !== 0) {
$('#' + settings.targetId).animate({height: listElem.height(),'margin-top': marginDiff + 'px'}, 'fast'); $('#' + settings.targetId).animate({height: listElem.height(),'margin-top': marginDiff + 'px'}, 'fast');
} }
...@@ -160,10 +96,6 @@ inScroll = false; ...@@ -160,10 +96,6 @@ inScroll = false;
var listTop = listElem.offset().top; var listTop = listElem.offset().top;
var scrollVal = listTop - tarTop - marginDiff; 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'); $('body').animate({scrollTop: scrollVal}, 'fast');
details = settings.extendedInfoFunc(listElem.attr('id')); details = settings.extendedInfoFunc(listElem.attr('id'));
...@@ -178,7 +110,7 @@ inScroll = false; ...@@ -178,7 +110,7 @@ inScroll = false;
} }
}; };
var set_selected_element = function (element, asap) { var setSelectedElement = function (element, asap) {
if (!element) { if (!element) {
element = peekedList.children('li:first-child').get(); element = peekedList.children('li:first-child').get();
} }
...@@ -190,9 +122,9 @@ inScroll = false; ...@@ -190,9 +122,9 @@ inScroll = false;
listElem.addClass(settings.selectedClass); listElem.addClass(settings.selectedClass);
focusedListElement = listElem; focusedListElement = listElem;
if (asap) { if (asap) {
debounce(show_expanded_info, 50, false)(); debounce(showExpandedInfo, 50, false)();
} else { } else {
debounce(show_expanded_info, 500, false)(); debounce(showExpandedInfo, 500, false)();
} }
} else { } else {
$('#' + settings.revealDivId).hide(); $('#' + settings.revealDivId).hide();
...@@ -200,19 +132,19 @@ inScroll = false; ...@@ -200,19 +132,19 @@ inScroll = false;
} }
}; };
var find_and_select_element = function() { var findAndSelectElement = function() {
var newFocusedListElement = document.elementFromPoint(horizontalCenter, centerOfHeadline); var newFocusedListElement = document.elementFromPoint(horizontalCenter, centerOfHeadline);
if (newFocusedListElement !== focusedListElement) { if (newFocusedListElement !== focusedListElement) {
set_selected_element(newFocusedListElement); setSelectedElement(newFocusedListElement);
} }
}; };
var reset_geometry = function() { var resetGeometry = function() {
var alreadyFocusedListElement = peekedList.children("li." + settings.selectedClass); 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(){ $(window).bind('scrollstart', function(){
if (scrollListenersEnabled) { if (scrollListenersEnabled) {
scrollInProgress = true; scrollInProgress = true;
...@@ -236,17 +168,17 @@ inScroll = false; ...@@ -236,17 +168,17 @@ inScroll = false;
$(window).bind('scrollstop', function(e){ $(window).bind('scrollstop', function(e){
if (scrollInProgress) { if (scrollInProgress) {
// console.log("scrollstop"); // console.log("scrollstop");
find_and_select_element(); findAndSelectElement();
} }
}); });
peekedList.children("li").click(function() { peekedList.children("li").click(function() {
// console.log("click"); // console.log("click");
set_selected_element($(this).get(), true); setSelectedElement($(this).get(), true);
}); });
$(window).resize(function() { $(window).resize(function() {
debounce(reset_geometry, 500, false)(); debounce(resetGeometry, 500, false)();
}); });
handlersRegistered = true; handlersRegistered = true;
...@@ -254,3 +186,83 @@ inScroll = false; ...@@ -254,3 +186,83 @@ inScroll = false;
}(jQuery)); }(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