1// page init 2jQuery(function(){ 3 initLoadMore(); 4}); 5 6// load more init 7function initLoadMore() { 8 jQuery('.load-more-holder').loadMore({ 9 linkSelector: 'a.load-more', 10 additionBottomOffset: 50 11 }); 12} 13 14/* 15 * jQuery Load More plugin 16 */ 17 ;(function($, $win) { 18 'use strict'; 19 20 var ScrollLoader = { 21 attachEvents: function() { 22 var self = this; 23 24 $win.on('load.ScrollLoader resize.ScrollLoader orientationchange.ScrollLoader', function() { self.onResizeHandler(); }); 25 $win.on('scroll.ScrollLoader', function() { self.onScrollHandler(); }); 26 this.$holder.on('ContentLoader/loaded.ScrollLoader', function() { self.onResizeHandler(); }); 27 28 this.winProps = {}; 29 this.holderProps = {}; 30 this.onResizeHandler(); 31 }, 32 33 onResizeHandler: function() { 34 this.winProps.height = $win.height(); 35 this.holderProps.height = this.$holder.outerHeight(); 36 this.holderProps.offset = this.$holder.offset().top; 37 38 this.onScrollHandler(); 39 }, 40 41 onScrollHandler: function() { 42 this.winProps.scroll = $win.scrollTop(); 43 44 if (this.winProps.scroll + this.winProps.height + Math.min(1, this.options.additionBottomOffset) > this.holderProps.height + this.holderProps.offset) { 45 this.loadInclude(); 46 } 47 }, 48 49 destroySubEvents: function() { 50 $win.off('.ScrollLoader'); 51 this.$holder.off('.ScrollLoader'); 52 } 53 }; 54 55 var ClickLoader = { 56 attachEvents: function() { 57 var self = this; 58 59 this.$holder.on('click.ClickLoader', this.options.linkSelector, function(e) { self.onClickHandler(e); }); 60 }, 61 62 onClickHandler: function(e) { 63 e.preventDefault(); 64 65 this.loadInclude(); 66 }, 67 68 destroySubEvents: function() { 69 this.$holder.off('.ClickLoader'); 70 } 71 }; 72 73 var ContentLoader = function($holder, options) { 74 this.$holder = $holder; 75 this.options = options; 76 77 this.init(); 78 }; 79 80 var ContentLoaderProto = { 81 init: function() { 82 this.$link = this.$holder.find(this.options.linkSelector); 83 this.$newContentTarget = this.options.newContentTarget ? this.$holder.find(this.options.newContentTarget) : this.$holder; 84 85 if (!this.$link.length) { 86 this.removeInstance(); 87 return; 88 } 89 90 this.attachEvents(); 91 }, 92 93 loadInclude: function() { 94 if (this.isBusy) { 95 return; 96 } 97 98 var self = this; 99 100 this.toggleBusyMode(true); 101 102 $.get(self.$link.attr('href'), function(source) { self.successHandler(source); }); 103 }, 104 105 successHandler: function(include) { 106 var $tmpDiv = jQuery('<div>').html(include); 107 var $nextIncludeLink = $tmpDiv.find(this.options.linkSelector); 108 109 if ($nextIncludeLink.length) { 110 this.refreshLink($nextIncludeLink); 111 } else { 112 this.destroy(); 113 } 114 115 this.appendItems($tmpDiv.children()); 116 }, 117 118 appendItems: function($newItems) { 119 var self = this; 120 121 this.$newContentTarget.append($newItems.addClass(this.options.preAppendClass)); 122 123 setTimeout(function() { // need this timeout coz need some time for css preAppendClass applied to the new items 124 $newItems.removeClass(self.options.preAppendClass); 125 126 self.$holder.trigger('ContentLoader/loaded'); 127 self.toggleBusyMode(false); 128 }, 100); 129 130 if (window.picturefill) { 131 window.picturefill(); 132 } 133 }, 134 135 refreshLink: function($nextIncludeLink) { 136 this.$link.attr('href', $nextIncludeLink.attr('href')); 137 $nextIncludeLink.remove(); 138 }, 139 140 toggleBusyMode: function(state) { 141 this.$holder.toggleClass(this.options.busyClass, state); 142 this.isBusy = state; 143 }, 144 145 removeInstance: function() { 146 this.$holder.removeData('ContentLoader'); 147 }, 148 149 destroy: function() { 150 this.removeInstance(); 151 this.destroySubEvents(); 152 153 this.$link.remove(); 154 } 155 }; 156 157 $.fn.loadMore = function(options) { 158 options = $.extend({ 159 scroll: false, 160 linkSelector: '.load-more', 161 newContentTarget: '.community-news-block', 162 busyClass: 'is-busy', 163 additionBottomOffset: 50, 164 preAppendClass: 'new-item' 165 }, options); 166 167 return this.each(function() { 168 var $holder = $(this); 169 170 ContentLoader.prototype = $.extend(options.scroll ? ScrollLoader : ClickLoader, ContentLoaderProto); 171 172 $holder.data('ContentLoader', new ContentLoader($holder, options)); 173 }); 174 }; 175 }(jQuery, jQuery(window)));
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.