1/*! 2 * jQuery & Zepto Lazy - AJAX Plugin - v1.4 3 * http://jquery.eisbehr.de/lazy/ 4 * 5 * Copyright 2012 - 2018, Daniel 'Eisbehr' Kern 6 * 7 * Dual licensed under the MIT and GPL-2.0 licenses: 8 * http://www.opensource.org/licenses/mit-license.php 9 * http://www.gnu.org/licenses/gpl-2.0.html 10 */ 11;(function($) { 12 // load data by ajax request and pass them to elements inner html, like: 13 // <div data-loader="ajaxonself" data-src="url.html" data-method="post" data-type="html"></div> 14 $.lazy('twigautoload', function(element, response) { 15 16 twigautoload(this, element, response, element.attr('data-method') ); 17 18 }); 19 20 /** 21 * execute ajax request and handle response 22 * @param {object} instance 23 * @param {jQuery|object} element 24 * @param {function} response 25 * @param {string} [method] 26 */ 27 function twigautoload( instance, element, response, method ) { 28 method = method ? method.toUpperCase() : 'POST'; 29 30 var data; 31 if ((method === 'POST' || method === 'PUT') && instance.config( 'ajaxCreateData') ) { 32 data = instance.config( 'ajaxCreateData' ).apply( instance, [ element ] ); 33 } 34 35 const $this = $(element); 36 37 const action = $this.data( 'action' ), 38 template = $this.data( 'template' ), 39 args = $this.data( 'args' ) || {}, 40 settings = $this.data( 'settings' ) || {} , 41 type = $this.data( 'type' ), 42 jsmethod = $this.data( 'jsmethod' ), 43 target = $this.data( 'target' ); 44 45 // hide the button we just clicked 46 $this.find( '.ts-load-more-text' ).addClass( 'uk-hidden' ); 47 // unhide the loading more div 48 $this.find( '.ts-load-more-whileloading' ).removeClass( 'uk-hidden' ); 49 50 console.log( settings ); 51 $.ajax( { 52 type: method, 53 url: `/wp-admin/admin-ajax.php?action=${action}&template=${template}`, 54 data: { ...settings , args: args }, 55 success: function (content) { 56 57 58 data = JSON.parse( content ); 59 // remove the loading more 60 //$loadingMore.remove(); 61 // remove the load more button 62 // add the data 63 if ( jsmethod === 'append' ) { 64 $( target ).append( data.data ); 65 $this.remove(); 66 } 67 if ( jsmethod === 'replace' ) { 68 // $( target ).replaceWith( data.data ); 69 $this.parent().append( data.data ); 70 $this.remove(); 71 // $(element).remove(); 72 // $('.lazy').lazy( {effect: "fadeIn", effectTime: 1000, threshold: 0 } ); 73 } 74 75 $('.lazy').lazy( {effect: "fadeIn", effectTime: 1000, threshold: 0 } ); 76 // use response function for Zepto 77 response(true); 78 79 // remove attributes 80 if ( instance.config('removeAttribute') ) { 81 element.removeAttr('data-src data-method data-type'); 82 } 83 84 }, 85 86 /** 87 * error callback 88 * @access private 89 * @return {void} 90 */ 91 error: function() { 92 // pass error state to lazy 93 // use response function for Zepto 94 response(false); 95 } 96 }); 97 98 99 // $.ajax({ 100 // url: element.attr('data-src'), 101 // type: method === 'POST' || method === 'PUT' ? method : 'GET', 102 // data: data, 103 // dataType: element.attr('data-type') || 'html', 104 105 // /** 106 // * success callback 107 // * @access private 108 // * @param {*} content 109 // * @return {void} 110 // */ 111 // success: function(content) { 112 // // set responded data to element's inner html 113 // $(element).parent().append(content); 114 // $(element).remove(); 115 // $('.lazy').lazy( {effect: "fadeIn", effectTime: 1000, threshold: 0 } ); 116 117 // // use response function for Zepto 118 // response(true); 119 120 // // remove attributes 121 // if ( instance.config('removeAttribute') ) { 122 // element.removeAttr('data-src data-method data-type'); 123 // } 124 // }, 125 126 // /** 127 // * error callback 128 // * @access private 129 // * @return {void} 130 // */ 131 // error: function() { 132 // // pass error state to lazy 133 // // use response function for Zepto 134 // response(false); 135 // } 136 // }); 137 } 138})(window.jQuery || window.Zepto);
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.