PageSourceSearch

https://www.teflonline.net/js/jquery.discusloader.js

js teflonline.net collected 2026-09-29 15:48:52 UTC 2,190 bytes, 87 lines download raw bytes

1/*
2	disqusLoader.js v1.0
3	A JavaScript plugin for lazy-loading Disqus comments widget.
4	-
5	By Osvaldas Valutis, www.osvaldas.info
6	Available for use under the MIT License
7*/
8
9;( function( $, window, document, undefined )
10{
11	'use strict';
12
13	var $win			= $( window ),
14		throttle		= function(a,b){var c,d;return function(){var e=this,f=arguments,g=+new Date;c&&g<c+a?(clearTimeout(d),d=setTimeout(function(){c=g,b.apply(e,f)},a)):(c=g,b.apply(e,f))}},
15
16		throttleTO		= false,
17		laziness		= false,
18		disqusConfig	= false,
19		scriptUrl		= false,
20
21		scriptStatus	= 'unloaded',
22		$instance		= $(),
23
24		init = function()
25		{
26			if( !$instance.length || $instance.data( 'disqusLoaderStatus' ) == 'loaded' )
27				return true;
28
29			var winST = $win.scrollTop();
30
31			// if the element is too far below || too far above
32			if( $instance.offset().top - winST > $win.height() * laziness || winST - $instance.offset().top - $instance.outerHeight() - ( $win.height() * laziness ) > 0 )
33				return true;
34
35			$( '#disqus_thread' ).removeAttr( 'id' );
36			$instance.attr( 'id', 'disqus_thread' ).data( 'disqusLoaderStatus', 'loaded' );
37
38			if( scriptStatus == 'loaded' )
39			{
40				DISQUS.reset({ reload: true, config: disqusConfig });
41			}
42			else // unloaded | loading
43			{
44				window.disqus_config = disqusConfig;
45				if( scriptStatus == 'unloaded' )
46				{
47					scriptStatus = 'loading';
48					$.ajax(
49					{
50						url:		scriptUrl,
51						async:		true,
52						cache:		true,
53						dataType:	'script',
54						success:	function()
55						{
56							scriptStatus = 'loaded';
57						}
58					});
59				}
60			}
61		};
62
63	$win.on( 'scroll resize', throttle( throttleTO, init ));
64
65	$.disqusLoader = function( element, options )
66	{
67		options = $.extend({},
68		{
69			laziness:		1,
70			throttle:		250,
71			scriptUrl:		false,
72			disqusConfig:	false,
73
74		}, options );
75
76		laziness		= options.laziness + 1;
77		throttleTO		= options.throttle;
78		disqusConfig	= options.disqusConfig;
79		scriptUrl		= scriptUrl === false ? options.scriptUrl : scriptUrl; // set it only once
80		$instance		= ( typeof element == 'string' ? $( element ) : element ).eq( 0 );
81
82		$instance.data( 'disqusLoaderStatus', 'unloaded' );
83
84		init();
85	};
86
87})( jQuery, window, document );

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.