1/** 2 * @param {string} templatePath The template path for the PHP view 3 * @param {Element} container 4 * @param {string} viewClass The FQN of a custom PHP view class 5 * @param {int} postId 6 */ 7function loadTemplate(templatePath, container, viewClass, postId) 8{ 9 var loading = false; 10 var aroundContainer = document.createElement('div'); 11 container.classList.add('ajax-container-inner'); 12 container.parentNode.insertBefore(aroundContainer, container); 13 aroundContainer.appendChild(container); 14 aroundContainer.classList.add('ajax-container'); 15 load(); 16 scrollHandler.doOnScroll(function () { 17 load(); 18 }); 19 20 function load() 21 { 22 /** 23 * Grab request data from global object set via wp_localize_script. 24 */ 25 var requestData = ToolkitTemplateAjaxData; 26 if (utils.isInView(container, true) && !loading) { 27 loading = true; 28 var data = { 29 'action': 'load_template', 30 'templatePath': templatePath, 31 'viewClass': viewClass, 32 'postId': postId, 33 }; 34 jQuery.post(requestData.ajaxUrl, data) 35 .done(function (response) { 36 container.classList.add('hidden'); 37 container.style.position = 'absolute'; 38 container.style.width = '100%'; 39 container.insertAdjacentHTML('afterend', response); 40 setTimeout(function () { 41 container.remove(); 42 }, 300) 43 }) 44 .error(function () { 45 console.error('Template Ajax request failed.'); 46 loading = false; 47 }) 48 } 49 } 50}
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.