1(function (document, window, $, undefined) { 2 'use strict'; 3 4 var pluginName = 'overflowScroller'; 5 var defaults = { 6 // selectors 7 scrollerContent: '.js-overflow-scroller__content', 8 scrollerLeftButton: '.js-scroller--scroll-left', 9 scrollerRightButton: '.js-scroller--scroll-right', 10 11 // state classes 12 overflowLeftClass: 'overflowing--left', 13 overflowRightClass: 'overflowing--right', 14 }; 15 16 var Plugin = function (element, options) { 17 var _public = {}; 18 var _private = {}; 19 20 var settings = $.extend({}, defaults, options); 21 _public.element = element; 22 _public.$element = $(element); 23 _public.$content = $(settings.scrollerContent, _public.$element); 24 if (_public.$content.length == 0) { 25 return; 26 } 27 var _init = function () { 28 /** 29 * Bind Actions 30 */ 31 // Navigation buttons 32 $(element).on('click', settings.scrollerLeftButton, scrollerScrollLeft) 33 $(element).on('click', settings.scrollerRightButton, scrollerScrollRight) 34 // scroller states 35 $(window).on('resize', checkScrollerContainer); 36 $(settings.scrollerContent).on('scroll', checkScrollerContainer); 37 38 checkScrollerContainer(); 39 }; 40 41 function checkScrollerContainer() { 42 var scrollLeft = _public.$content.scrollLeft(); 43 var scrollRight = _public.$content.width() + scrollLeft; 44 var scrollWidth = _public.$content[0].scrollWidth; 45 46 if (scrollLeft > 0) { 47 _public.$element.addClass(settings.overflowLeftClass); 48 } else { 49 _public.$element.removeClass(settings.overflowLeftClass); 50 } 51 52 if (scrollRight < scrollWidth) { 53 _public.$element.addClass(settings.overflowRightClass); 54 } else { 55 _public.$element.removeClass(settings.overflowRightClass); 56 } 57 } 58 59 function scrollerScrollLeft() { 60 _public.$content.animate({ 61 scrollLeft: _public.$content.scrollLeft() - _public.$content.find('>*:first-child').outerWidth() 62 }, 300); 63 } 64 65 function scrollerScrollRight() { 66 _public.$content.animate({ 67 scrollLeft: _public.$content.scrollLeft() + _public.$content.find('>*:first-child').outerWidth() 68 }, 300); 69 } 70 71 _init(); 72 73 return _public; 74 }; 75 76 77 // jQuery plugin wrapper 78 $.fn[pluginName] = function (options) { 79 return this.each(function () { 80 if (!$.data(this, 'plugin_' + pluginName)) { 81 $.data(this, 'plugin_' + pluginName); 82 new Plugin(this, options); 83 } 84 }); 85 }; 86 87})(document, window, jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.