1(function($){ 2 "use strict"; 3 4 var Autoload = function(element, options) 5 { 6 this.content_container = '.post-wrapper'; 7 this.content_class = '.post-autoload'; 8 this.current_url = window.location.href; 9 this.post_cache = []; 10 this.is_sidefeed = $("#jeg_sidecontent").length ? true : false; 11 this.sidefeed = $(".jeg_sidefeed"); 12 this.change_url_locked = false; 13 14 $(document).bind('jnews-sidefeed-ajax', $.proxy(this.clear_post_cache, this)); 15 $(document).bind('jnews-sidefeed-ajax-begin', $.proxy(this.lock_change_url, this)); 16 this.init(); 17 }; 18 19 Autoload.DEFAULTS = {}; 20 21 Autoload.prototype.lock_change_url = function() 22 { 23 this.change_url_locked = true; 24 }; 25 26 Autoload.prototype.init = function() 27 { 28 var base = this; 29 30 base.initialise_waypoint(); 31 }; 32 33 Autoload.prototype.clear_post_cache = function() 34 { 35 var base = this; 36 base.change_url_locked = false; 37 base.post_cache = []; 38 base.initialise_waypoint(); 39 40 }; 41 42 Autoload.prototype.find_prev_post = function(element) 43 { 44 var base = this; 45 element = $(element).next(); 46 47 if(element.length) 48 { 49 if(element.hasClass('jeg_post')) { 50 return element; 51 } else { 52 return base.find_prev_post(element); 53 } 54 } else { 55 return null; 56 } 57 }; 58 59 Autoload.prototype.get_previous_url = function(element, post_id) 60 { 61 var base = this; 62 63 if(base.is_sidefeed) 64 { 65 var post = base.sidefeed.find('[data-id="' + post_id + '"]'); 66 var prev_post = base.find_prev_post(post); 67 68 if(prev_post) { 69 return $(prev_post).find('a.ajax').attr('href'); 70 } else { 71 return null; 72 } 73 } else { 74 return $(element).data('prev'); 75 } 76 }; 77 78 Autoload.prototype.initialise_waypoint = function() 79 { 80 var base = this; 81 82 $( base.content_class ).each(function() 83 { 84 if(!$(this).hasClass('loaded')) 85 { 86 $(this).addClass('loaded').waypoint(function(direction) 87 { 88 if( ! base.change_url_locked ) 89 { 90 var waypoint = this; 91 var func = $.proxy(base.change_url, base, waypoint.element, direction); 92 func.call(); 93 } 94 }, { 95 offset: '0%', 96 context: window 97 }); 98 99 $(this).find('.jnews-autoload-splitter').waypoint(function(direction) 100 { 101 if( ! base.change_url_locked ) 102 { 103 var waypoint = $(this.element).parents('.post-wrap'); 104 var func = $.proxy(base.change_url, base, waypoint, direction); 105 func.call(); 106 } 107 },{ 108 offset: '0%', 109 context: window 110 }); 111 } 112 }); 113 }; 114 115 Autoload.prototype.strip_html = function(html){ 116 var tmp = document.createElement("DIV"); 117 tmp.innerHTML = html; 118 return tmp.textContent || tmp.innerText || ""; 119 }; 120 121 Autoload.prototype.change_url = function(element, direction) 122 { 123 var base = this; 124 var el = $(element); 125 var url = el.data('url'); 126 var title = el.data('title'); 127 var post_id = el.data('id'); 128 var prev_url = base.get_previous_url(el, post_id); 129 130 // If exiting or entering from top, change URL 131 if (base.current_url != url) 132 { 133 base.current_url = url; 134 135 if(history && history.pushState) 136 { 137 history.pushState(null, title, url); 138 document.title = base.strip_html(title); 139 } 140 141 // update analytic 142 if(window.jnews && window.jnews.ajax_analytic) 143 { 144 jnews.ajax_analytic.update(url, post_id); 145 } 146 147 $(document).trigger('jnews-autoload-change-id', [post_id]); 148 } 149 150 // Look for the next post to load if any. 151 if (prev_url && direction === 'down') 152 { 153 base.auto_load_prev_post(prev_url, post_id); 154 } 155 }; 156 157 Autoload.prototype.check_loaded = function(post_id) 158 { 159 var base = this; 160 return base.post_cache.indexOf(post_id) > -1; 161 }; 162 163 Autoload.prototype.push_post_id = function(post_id) 164 { 165 var base = this; 166 base.post_cache.push(post_id); 167 }; 168 169 Autoload.prototype.auto_load_prev_post = function(post_url, post_id) 170 { 171 var base = this, 172 np_url = null; 173 174 if ( !post_url || base.check_loaded(post_id) ) 175 { 176 return; 177 } else { 178 base.push_post_id(post_id); 179 } 180 181 // Check to see if pretty permalinks, if not then add partial=1 182 if ( post_url.indexOf( '?p=' ) > -1 ) 183 { 184 np_url = post_url + '&autoload=1' 185 } else { 186 var partial_endpoint = 'autoload/'; 187 188 if ( post_url.charAt(post_url.length - 1) != '/' ) 189 partial_endpoint = '/' + partial_endpoint; 190 191 np_url = post_url + partial_endpoint; 192 } 193 194 $.get( np_url , function( data ) 195 { 196 $(base.content_container).append(data); 197 198 // need to set up ScrollSpy on new content 199 base.initialise_waypoint(); 200 201 // trigger load 202 $(document).trigger('jnews-ajax-load', [ $(base.content_container).find(base.content_class).last(
202) ]); 203 }); 204 }; 205 206 function Plugin(option) 207 { 208 return $(this).each(function() 209 { 210 var $this = $(this); 211 var options = $.extend({}, Autoload.DEFAULTS, $this.data(), typeof option == 'object' && option); 212 var data = $this.data('jeg.autoload'); 213 214 if (!data) $this.data('jeg.autoload', (data = new Autoload(options))); 215 }); 216 } 217 218 var old = $.fn.jautoload; 219 220 $.fn.jautoload = Plugin; 221 $.fn.jautoload.Constructor = Autoload; 222 223 $.fn.jautoload.noConflict = function () { 224 $.fn.jautoload = old; 225 return this 226 }; 227 228 $(document).ready(function(){ 229 $('body').jautoload(); 230 }); 231 232})(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.