1 2class RemoteLoader { 3 4 /* 5 */ 6 constructor( jquery_instance ) 7 { 8 //console.log('Init remoteLoader on : ', jquery_instance ); 9 this.instance = jquery_instance; 10 11 // 12 var remote_url = this.instance.data('remote-url'); 13 if( remote_url.length > 0 ){ 14 15 // 16 var mode = this.instance.data('mode'); 17 var size = this.instance.data('size'); 18 var lang = this.instance.data('lang'); 19 20 // 21 this.sendRequest( remote_url, mode, size, lang ); 22 } 23 } 24 25 26 /* 27 :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 28 */ 29 30 /* 31 */ 32 sendRequest( url, mode, size, lang ){ 33 34 //console.log('### | SEND REQUEST : ' + url ); 35 36 // 37 var form_data = new FormData(); 38 form_data.append('action', 'request_remote_block'); 39 form_data.append('remote-url', url ); 40 form_data.append('mode', mode ); 41 form_data.append('size', size ); 42 form_data.append('lang', lang ); 43 44 45 var self = this; 46 // Send request
47 var ajax_url = this.getAjaxUrl(); 48 jQuery.ajax({ 49 url: ajax_url, 50 type: 'POST', 51 contentType: false, 52 processData: false, 53 data: form_data, 54 beforeSend: function() { 55 //self.addLoader(); 56 }, 57 success: function (response) { 58 //console.log("Resultado raw: ", response); 59 //console.log("Resultado html: ", response.data ); 60 // 61 if(response.status == 'success'){ 62 self.buildResponse( response.data ); 63 } 64 }, 65 complete: function() { 66 //self.removeLoader(); 67 }, 68 error: function (request, error) { 69 console.log( 'Error request : ' + error ); 70 }, 71 }); 72 73 } 74 75 /* 76 :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 77 */ 78 79 /* 80 */ 81 buildResponse ( data ) 82 { 83 var destiny = this.instance.find('.layout'); 84 //console.log('### | Ok destiny : ' + destiny ); 85 if( destiny.length > 0 ){ 86 // Load new data 87 destiny.html( data ); 88 89 // Remove preview 90 destiny.removeClass( 'preview' ); 91 } 92 } 93 94 /* 95 */ 96 addLoader () 97 { 98 //var spinner = '<div class="spinner-grow center margin-auto" role="status"></div>'; 99 var spinner = '<div class="spinner-border center margin-auto" role="status"></div>'; 100 this.instance.append( spinner ); 101 } 102 103 /* 104 */ 105 removeLoader () 106 { 107 //var spinner = this.instance.find('.spinner-grow'); 108 var spinner = this.instance.find('.spinner-border'); 109 jQuery(spinner).remove(); 110 } 111 112 /* 113 :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 114 */ 115 116 /* 117 */
118 getAjaxUrl() 119 { 120 var getUrl = window.location; 121 var host_url = origin; 122 //console.log('Host: ', host_url ); 123 124 // 125 var ajax_url_gl = wp_crawler_script_vars.ajaxurl; 126 var ajax_url_es = wp_crawler_script_vars.ajaxurl_es; 127 var ajax_url = ajax_url_gl; 128 129 // 130 if( host_url.length > 0 ){ 131 if( host_url.indexOf('.es') >= 0 ){ 132 ajax_url = ajax_url_es; 133 if( host_url.indexOf('www.') >= 0 ){ 134 ajax_url = ajax_url_es.replace( 'campogalego.es' , 'www.campogalego.es' ); 135 } 136 } 137 } 138 return ajax_url; 139 } 140 141//_____________________________________________________________________________________________ 142} 143//_____________________________________________________________________________________________ 144 145jQuery(document).ready(function ($) { 146 //var instance = new Instance(); 147});
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.