Permalink
Browse files

Merge branch 'master' of github.com:lucasefe/rubyconfar-2012

  • Loading branch information...
2 parents b190f42 + 4ea07d6 commit f3194a890485bfb2b6b93f7e2696d7683e2f0093 @n1cus n1cus committed May 7, 2012
Showing with 113 additions and 4 deletions.
  1. +10 −0 public/javascripts/app.js
  2. +98 −0 public/javascripts/jquery-scrollspy.js
  3. +4 −4 views/en/index.slim
  4. +1 −0 views/layout.slim
@@ -1,4 +1,14 @@
$(function() {
+ $('#wrapper section').scrollspy({
+ min: "40",
+ onEnter: function(element, position) {
+ console.log("IN " + element.id)
+
+ }, onLeave: function(element, position) {
+ console.log("OUT " + element.id)
+ }
+ });
+
$('#subscriber_container form').live('submit', function(){
$.post(this.action, $(this).serialize(), function(data, textStatus, jqXHR) {
$('#subscriber_container').html(data)
@@ -0,0 +1,98 @@
+/*!
+ * jQuery Scrollspy Plugin
+ * Author: @sxalexander
+ * Licensed under the MIT license
+ */
+
+
+;(function ( $, window, document, undefined ) {
+
+ $.fn.extend({
+ scrollspy: function ( options ) {
+
+ var defaults = {
+ min: 0,
+ max: 0,
+ mode: 'vertical',
+ buffer: 0,
+ container: window,
+ onEnter: options.onEnter ? options.onEnter : [],
+ onLeave: options.onLeave ? options.onLeave : [],
+ onTick: options.onTick ? options.onTick : []
+ }
+
+ var options = $.extend( {}, defaults, options );
+
+ return this.each(function (i) {
+
+ var element = this;
+ var o = options;
+ var $container = $(o.container);
+ var mode = o.mode;
+ var buffer = o.buffer;
+ var enters = leaves = 0;
+ var inside = false;
+
+ /* add listener to container */
+ $container.bind('scroll', function(e){
+ var position = {top: $(this).scrollTop(), left: $(this).scrollLeft()};
+ var xy = (mode == 'vertical') ? position.top + buffer : position.left + buffer;
+ var max = o.max;
+ var min = o.min;
+
+ /* fix max */
+ if($.isFunction(o.max)){
+ max = o.max();
+ }
+
+ /* fix max */
+ if($.isFunction(o.min)){
+ min = o.min();
+ }
+
+ if(max == 0){
+ max = (mode == 'vertical') ? $container.height() : $container.outerWidth() + $(element).outerWidth();
+ }
+
+ /* if we have reached the minimum bound but are below the max ... */
+ if(xy >= o.min && xy <= max){
+ /* trigger enter event */
+ if(!inside){
+ inside = true;
+ enters++;
+
+ /* fire enter event */
+ $(element).trigger('scrollEnter', {position: position})
+ if($.isFunction(o.onEnter)){
+ o.onEnter(element, position);
+ }
+
+ }
+
+ /* triger tick event */
+ $(element).trigger('scrollTick', {position: position, inside: inside, enters: enters, leaves: leaves})
+ if($.isFunction(o.onTick)){
+ o.onTick(element, position, inside, enters, leaves);
+ }
+ }else{
+
+ if(inside){
+ inside = false;
+ leaves++;
+ /* trigger leave event */
+ $(element).trigger('scrollLeave', {position: position, leaves:leaves})
+
+ if($.isFunction(o.onLeave)){
+ o.onLeave(element, position);
+ }
+ }
+ }
+ });
+
+ });
+ }
+
+ })
+
+
+})( jQuery, window );
View
@@ -37,15 +37,15 @@
#fix
nav
- a.active href="#home"
+ a href="#home"
span Evento
.separator
- a href="#videos"
+ a href="#videos"
span Videos
-#wrapper
+#wrapper
- section#home
+ section#home
== partial 'flashes'
View
@@ -11,6 +11,7 @@ html
script type="text/javascript" src="/javascripts/jquery.easing.1.3.min.js"
script type="text/javascript" src="/javascripts/fancybox/jquery.fancybox-1.3.4.js"
script type="text/javascript" src="/javascripts/fancybox/jquery.mousewheel-3.0.4.pack.js"
+ script type="text/javascript" src="/javascripts/jquery-scrollspy.js"
script type="text/javascript" src="/javascripts/app.js"
meta content='text/html; charset=UTF-8' http-equiv='Content-Type'

0 comments on commit f3194a8

Please sign in to comment.