1/** 2 * Go To wrapper. 3 * 4 * @author Htmlstream 5 * @version 1.0 6 * 7 */ 8;(function ($) { 9 'use strict'; 10 $.HSCore.components.HSGoTo = { 11 /** 12 * 13 * 14 * @var Object _baseConfig 15 */ 16 _baseConfig: {}, 17 18 /** 19 * 20 * 21 * @var jQuery pageCollection 22 */ 23 pageCollection: $(), 24 25 /** 26 * Initialization of Go To wrapper. 27 * 28 * @param String selector (optional) 29 * @param Object config (optional) 30 * 31 * @return jQuery pageCollection - collection of initialized items. 32 */ 33 34 init: function (selector, config) { 35 this.collection = selector && $(selector).length ? $(selector) : $(); 36 if (!$(selector).length) return; 37 38 this.config = config && $.isPlainObject(config) ? 39 $.extend({}, this._baseConfig, config) : this._baseConfig; 40 41 this.config.itemSelector = selector; 42 43 this.initGoTo(); 44 45 return this.pageCollection; 46 }, 47 48 initGoTo: function () { 49 //Variables 50 var $self = this, 51 collection = $self.pageCollection; 52 53 //Actions 54 this.collection.each(function (i, el) { 55 //Variables 56 var $this = $(el), 57 $target = $this.data('target'), 58 isReferencedToPage = Boolean($this.data('is-referenced-to-page')), 59 type = $this.data('type'), 60 showEffect = $this.data('show-effect'), 61 hideEffect = $this.data('hide-effect'), 62 position = JSON.parse(el.getAttribute('data-position')), 63 compensation = $($this.data('compensation')).outerHeight(), 64 offsetTop = $this.data('offset-top'), 65 targetOffsetTop = function () { 66 if (compensation) { 67 return $target ? $($target).offset().top - compensation : 0; 68 } else { 69 return $target ? $($target).offset().top : 0; 70 } 71 }; 72 73 if (type === 'static') { 74 $this.css({ 75 'display': 'inline-block' 76 }); 77 } else { 78 $this.addClass('animated').css({ 79 'display': 'inline-block', 80 'position': type, 81 'opacity': 0 82 }); 83 } 84 85 if (type === 'fixed' || type === 'absolute') { 86 $this.css(position); 87 } 88 89 $this.on('click', function (e) { 90 if(!isReferencedToPage) { 91 e.preventDefault(); 92 93 $('html, body').stop().animate({ 94 'scrollTop': targetOffsetTop() 95 }, 800); 96 } 97 }); 98 99 if (!$this.data('offset-top') && !$this.hasClass('js-animation-was-fired') && type !== 'static') { 100 if ($this.offset().top <= $(window).height()) { 101 $this.show(); 102 103 setTimeout(function () { 104 $this.addClass('js-animation-was-fired ' + showEffect).css({ 105 'opacity': '' 106 }); 107 }); 108 } 109 } 110 111 if (type !== 'static') { 112 $(window).on('scroll', function () { 113 if ($this.data('offset-top')) { 114 if ($(window).scrollTop() >= offsetTop && !$this.hasClass('js-animation-was-fired')) { 115 $this.show(); 116 117 setTimeout(function () { 118 $this.addClass('js-animation-was-fired ' + showEffect).css({ 119 'opacity': '' 120 }); 121 }); 122 } else if ($(window).scrollTop() <= offsetTop && $this.hasClass('js-animation-was-fired')) { 123 $this.removeClass('js-animation-was-fired ' + showEffect); 124 125 setTimeout(function () { 126 $this.addClass(hideEffect).css({ 127 'opacity': 0 128 }); 129 }, 100); 130 131 setTimeout(function () { 132 $this.removeClass(hideEffect).hide(); 133 }, 400); 134 } 135 } else { 136 var thisOffsetTop = $this.offset().top; 137 138 if (!$this.hasClass('js-animation-was-fired')) { 139 if ($(window).scrollTop() >= thisOffsetTop - $(window).height()) { 140 $this.show(); 141 142 setTimeout(function () { 143 $this.addClass('js-animation-was-fired ' + showEffect).css({ 144 'opacity': '' 145 }); 146 }); 147 } 148 } 149 } 150 }); 151 152 $(window).trigger('scroll'); 153 } 154 155 //Actions 156 collection = collection.add($this); 157 }); 158 } 159 }; 160})(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.