vendor/assets/javascripts/jquery-sticky/plugin.js in jquery-sticky-rails-0.0.2 vs vendor/assets/javascripts/jquery-sticky/plugin.js in jquery-sticky-rails-0.0.3
- old
+ new
@@ -1,268 +1,98 @@
-// Sticky Plugin v1.0.3 for jQuery
-// =============
-// Author: Anthony Garand
-// Improvements by German M. Bravo (Kronuz) and Ruud Kamphuis (ruudk)
-// Improvements by Leonardo C. Daronco (daronco)
-// Created: 02/14/2011
-// Date: 07/20/2015
-// Website: http://stickyjs.com/
-// Description: Makes an element on the page stick on the screen as you scroll
-// It will only set the 'top' and 'position' of your element, you
-// might need to adjust the width in some cases.
+var big_image;
+$().ready(function() {
+ $('.selector').click(function() {
+ SelectColor(this);
+ });
+ var selectCol = 0;
+ if (selectCol == 0) {
+ if ($('body').hasClass('landing-page1')) {
-(function (factory) {
- if (typeof define === 'function' && define.amd) {
- // AMD. Register as an anonymous module.
- define(['jquery'], factory);
- } else if (typeof module === 'object' && module.exports) {
- // Node/CommonJS
- module.exports = factory(require('jquery'));
- } else {
- // Browser globals
- factory(jQuery);
}
-}(function ($) {
- var slice = Array.prototype.slice; // save ref to original slice()
- var splice = Array.prototype.splice; // save ref to original slice()
+ }
- var defaults = {
- topSpacing: 0,
- bottomSpacing: 0,
- className: 'is-sticky',
- wrapperClassName: 'sticky-wrapper',
- center: false,
- getWidthFrom: '',
- widthFromWrapper: true, // works only when .getWidthFrom is empty
- responsiveWidth: false
- },
- $window = $(window),
- $document = $(document),
- sticked = [],
- windowHeight = $window.height(),
- scroller = function() {
- var scrollTop = $window.scrollTop(),
- documentHeight = $document.height(),
- dwh = documentHeight - windowHeight,
- extra = (scrollTop > dwh) ? dwh - scrollTop : 0;
+});
- for (var i = 0, l = sticked.length; i < l; i++) {
- var s = sticked[i],
- elementTop = s.stickyWrapper.offset().top,
- etse = elementTop - s.topSpacing - extra;
+$(window).on('scroll', function() {
+ responsive = $(window).width();
+ if (responsive >= 768) {
+ parallax();
+ }
+});
- //update height in case of dynamic content
- s.stickyWrapper.css('height', s.stickyElement.outerHeight());
+function SelectColor(btn) {
+ oldColor = $('.filter-gradient').attr('data-color');
+ newColor = $(btn).attr('data-color');
- if (scrollTop <= etse) {
- if (s.currentTop !== null) {
- s.stickyElement
- .css({
- 'width': '',
- 'position': '',
- 'top': ''
- });
- s.stickyElement.parent().removeClass(s.className);
- s.stickyElement.trigger('sticky-end', [s]);
- s.currentTop = null;
- }
- }
- else {
- var newTop = documentHeight - s.stickyElement.outerHeight()
- - s.topSpacing - s.bottomSpacing - scrollTop - extra;
- if (newTop < 0) {
- newTop = newTop + s.topSpacing;
- } else {
- newTop = s.topSpacing;
- }
- if (s.currentTop !== newTop) {
- var newWidth;
- if (s.getWidthFrom) {
- newWidth = $(s.getWidthFrom).width() || null;
- } else if (s.widthFromWrapper) {
- newWidth = s.stickyWrapper.width();
- }
- if (newWidth == null) {
- newWidth = s.stickyElement.width();
- }
- s.stickyElement
- .css('width', newWidth)
- .css('position', 'fixed')
- .css('top', newTop);
+ oldButton = $('a[id^="Demo"]').attr('data-button');
+ newButton = $(btn).attr('data-button');
- s.stickyElement.parent().addClass(s.className);
+ $('.filter-gradient').removeClass(oldColor).addClass(newColor).attr('data-color', newColor);
- if (s.currentTop === null) {
- s.stickyElement.trigger('sticky-start', [s]);
- } else {
- // sticky is started but it have to be repositioned
- s.stickyElement.trigger('sticky-update', [s]);
- }
+ $('a[id^="Demo"]').removeClass("btn-" + oldButton).addClass("btn-" + newButton).attr('data-button', newButton);
- if (s.currentTop === s.topSpacing && s.currentTop > newTop || s.currentTop === null && newTop < s.topSpacing) {
- // just reached bottom || just started to stick but bottom is already reached
- s.stickyElement.trigger('sticky-bottom-reached', [s]);
- } else if(s.currentTop !== null && newTop === s.topSpacing && s.currentTop < newTop) {
- // sticky is started && sticked at topSpacing && overflowing from top just finished
- s.stickyElement.trigger('sticky-bottom-unreached', [s]);
- }
+ $('.carousel-indicators').removeClass("carousel-indicators-" + oldColor).addClass("carousel-indicators-" + newColor);
- s.currentTop = newTop;
- }
+ $('.card').removeClass("card-" + oldColor).addClass("card-" + newColor);
- // Check if sticky has reached end of container and stop sticking
- var stickyWrapperContainer = s.stickyWrapper.parent();
- var unstick = (s.stickyElement.offset().top + s.stickyElement.outerHeight() >= stickyWrapperContainer.offset().top + stickyWrapperContainer.outerHeight()) && (s.stickyElement.offset().top <= s.topSpacing);
+ $('.selector').removeClass('active');
+ $(btn).addClass('active');
+}
- if( unstick ) {
- s.stickyElement
- .css('position', 'absolute')
- .css('top', '')
- .css('bottom', 0);
- } else {
- s.stickyElement
- .css('position', 'fixed')
- .css('top', newTop)
- .css('bottom', '');
- }
- }
- }
- },
- resizer = function() {
- windowHeight = $window.height();
+$('.switch').each(function() {
+ var selector = $(this).parent('li')
+ $(this).click(function() {
+ if (selector.siblings().hasClass('active')) {
+ selector.addClass('active');
+ selector.siblings().removeClass('active');
+ var slide = $(this).attr('data-slide')
+ var lastClass = $('body').attr('class').split(' ').pop();
+ $('body').removeClass(lastClass);
+ $('body').addClass('landing-page' + slide);
+ }
+ });
+});
- for (var i = 0, l = sticked.length; i < l; i++) {
- var s = sticked[i];
- var newWidth = null;
- if (s.getWidthFrom) {
- if (s.responsiveWidth) {
- newWidth = $(s.getWidthFrom).width();
- }
- } else if(s.widthFromWrapper) {
- newWidth = s.stickyWrapper.width();
- }
- if (newWidth != null) {
- s.stickyElement.css('width', newWidth);
- }
- }
- },
- methods = {
- init: function(options) {
- var o = $.extend({}, defaults, options);
- return this.each(function() {
- var stickyElement = $(this);
+var parallax = debounce(function() {
+ no_of_elements = 0;
+ $('.parallax').each(function() {
+ var $elem = $(this);
- var stickyId = stickyElement.attr('id');
- var wrapperId = stickyId ? stickyId + '-' + defaults.wrapperClassName : defaults.wrapperClassName;
- var wrapper = $('<div></div>')
- .attr('id', wrapperId)
- .addClass(o.wrapperClassName);
+ if (isElementInViewport($elem)) {
+ var parent_top = $elem.offset().top;
+ var window_bottom = $(window).scrollTop();
+ var $image = $elem.find('.parallax-background-image')
+ var $oVal = ((window_bottom - parent_top) / 3);
+ $image.css('margin-top', $oVal + 'px');
+ }
+ });
+}, 6)
- stickyElement.wrapAll(wrapper);
+function debounce(func, wait, immediate) {
+ var timeout;
+ return function() {
+ var context = this,
+ args = arguments;
+ clearTimeout(timeout);
+ timeout = setTimeout(function() {
+ timeout = null;
+ if (!immediate) func.apply(context, args);
+ }, wait);
+ if (immediate && !timeout) func.apply(context, args);
+ };
+};
- var stickyWrapper = stickyElement.parent();
- if (o.center) {
- stickyWrapper.css({width:stickyElement.outerWidth(),marginLeft:"auto",marginRight:"auto"});
- }
+function isElementInViewport(elem) {
+ var $elem = $(elem);
- if (stickyElement.css("float") === "right") {
- stickyElement.css({"float":"none"}).parent().css({"float":"right"});
- }
+ // Get the scroll position of the page.
+ var scrollElem = ((navigator.userAgent.toLowerCase().indexOf('webkit') != -1) ? 'body' : 'html');
+ var viewportTop = $(scrollElem).scrollTop();
+ var viewportBottom = viewportTop + $(window).height();
- o.stickyElement = stickyElement;
- o.stickyWrapper = stickyWrapper;
- o.currentTop = null;
+ // Get the position of the element on the page.
+ var elemTop = Math.round($elem.offset().top);
+ var elemBottom = elemTop + $elem.height();
- sticked.push(o);
-
- methods.setWrapperHeight(this);
- methods.setupChangeListeners(this);
- });
- },
-
- setWrapperHeight: function(stickyElement) {
- var element = $(stickyElement);
- var stickyWrapper = element.parent();
- if (stickyWrapper) {
- stickyWrapper.css('height', element.outerHeight());
- }
- },
-
- setupChangeListeners: function(stickyElement) {
- if (window.MutationObserver) {
- var mutationObserver = new window.MutationObserver(function(mutations) {
- if (mutations[0].addedNodes.length || mutations[0].removedNodes.length) {
- methods.setWrapperHeight(stickyElement);
- }
- });
- mutationObserver.observe(stickyElement, {subtree: true, childList: true});
- } else {
- stickyElement.addEventListener('DOMNodeInserted', function() {
- methods.setWrapperHeight(stickyElement);
- }, false);
- stickyElement.addEventListener('DOMNodeRemoved', function() {
- methods.setWrapperHeight(stickyElement);
- }, false);
- }
- },
- update: scroller,
- unstick: function(options) {
- return this.each(function() {
- var that = this;
- var unstickyElement = $(that);
-
- var removeIdx = -1;
- var i = sticked.length;
- while (i-- > 0) {
- if (sticked[i].stickyElement.get(0) === that) {
- splice.call(sticked,i,1);
- removeIdx = i;
- }
- }
- if(removeIdx !== -1) {
- unstickyElement.unwrap();
- unstickyElement
- .css({
- 'width': '',
- 'position': '',
- 'top': '',
- 'float': ''
- })
- ;
- }
- });
- }
- };
-
- // should be more efficient than using $window.scroll(scroller) and $window.resize(resizer):
- if (window.addEventListener) {
- window.addEventListener('scroll', scroller, false);
- window.addEventListener('resize', resizer, false);
- } else if (window.attachEvent) {
- window.attachEvent('onscroll', scroller);
- window.attachEvent('onresize', resizer);
- }
-
- $.fn.sticky = function(method) {
- if (methods[method]) {
- return methods[method].apply(this, slice.call(arguments, 1));
- } else if (typeof method === 'object' || !method ) {
- return methods.init.apply( this, arguments );
- } else {
- $.error('Method ' + method + ' does not exist on jQuery.sticky');
- }
- };
-
- $.fn.unstick = function(method) {
- if (methods[method]) {
- return methods[method].apply(this, slice.call(arguments, 1));
- } else if (typeof method === 'object' || !method ) {
- return methods.unstick.apply( this, arguments );
- } else {
- $.error('Method ' + method + ' does not exist on jQuery.sticky');
- }
- };
- $(function() {
- setTimeout(scroller, 0);
- });
-}));
+ return ((elemTop < viewportBottom) && (elemBottom > viewportTop));
+}
\ No newline at end of file