1(function($, RexTemplate) { 2 /* ========================================================================== 3 Setup Globals 4 ========================================================================== */ 5 if (!RexTemplate.query.args.paged) { 6 RexTemplate.query.args.paged = { 7 value: 1 8 }; 9 } 10 11 RexTemplate.getBounds = function(data) { 12 var defaults = { 13 action: 'get_bounds', 14 query: data 15 }; 16 17 return RexTemplate.sendAjax(defaults).then( 18 function(response) { 19 return response; 20 }, 21 function(response) { 22 return response; 23 } 24 ); 25 } 26 27 RexTemplate.sendAjax = function(data) { 28 var promise = new jQuery.Deferred(); 29 return $.when($.post(RexTemplate.ajaxurl, data)) 30 .then( 31 function(response) { 32 if (response == "-1") { 33 response = { 34 "success": false, 35 "data": { 36 'message': "Invalid request" 37 } 38 }; 39 } 40 // Request is not registered with wordpress 41 else if (response == "0") { 42 response = { 43 "success": false, 44 "data": { 45 'message': "Invalid request" 46 } 47 }; 48 } 49 50 return response; 51 }, 52 function(response) { 53 console.log("Ajax Error: ", response); 54 55 return { 56 "success": false, 57 "data": { 58 'message': "Ajax Error", 59 'error': response 60 } 61 }; 62 } 63 ) 64 } 65 66 RexTemplate.getTemplate = function(template, options) { 67 var defaults = { 68 action: 'get_template', 69 template: template, 70 selector: null, 71 query: null, 72 innerHTML: true,
73 found_rows: false 74 }; 75 76 data = $.extend({}, defaults, options); 77 78 return RexTemplate.sendAjax(data) 79 .then( 80 function(response) { 81 return response; 82 }, 83 function(response) { 84 return response; 85 } 86 ); 87 } 88 89 RexTemplate.Template = function(selector, template, options) { 90 return RexTemplate.getTemplate(template, options) 91 .then(function(response) { 92 $(selector).html($(response.data.template)); 93 return response; 94 }); 95 } 96 97 RexTemplate.replaceTemplate = function(selector, template, options) { 98 return RexTemplate.getTemplate(template, options) 99 .then(function(response) { 100 101 // replace data 102 $(selector).html($(response.data.template)); 103 return response; 104 }); 105 } 106 107 RexTemplate.mountTemplate = function(selector, template, options, mountOnTop) { 108 var mountDirectionFn = mountOnTop ? 'prepend' : 'append'; 109 return RexTemplate.getTemplate(template, options) 110 .then(function(response) { 111 var $template = $(response.data.template).not('.loadmore-trigger'); 112 // Restore scroll position after adding this to the top of a particular 113 // container. Added because could not add to higher level logic in ScrollablePagination 114 var restoreScrollData = {}; 115 if (mountOnTop) { 116 restoreScrollData.lastContentHeight = $('#archive-listing-content').height(); 117 restoreScrollData.lastScrollPosition = $('#scroller').scrollTop(); 118 } 119 120 $(selector)[mountDirectionFn]($template); 121 $(selector + ' .loadmore-trigger').appendTo(selector); 122 123 if (mountOnTop) { 124 restoreScrollData.currentContentHeight = $('#archive-listing-content').height(); 125 restoreScrollData.heightDiff = restoreScrollData.currentContentHeight - restoreScrollData.lastContentHeight; 126 $('#scroller').scrollTop(restoreScrollData.lastScrollPosition + restoreScrollData.heightDiff); 127 } 128 129 return $template; 130 }); 131 } 132 133 RexTemplate.appendTemplateMasonry = function(selector, template, options) { 134 return RexTemplate.getTemplate(template, options) 135 .then(function(response) { 136 var $template = $(response.data.template).not('.loadmore-trigger'); 137 $(selector).append($template) 138 .masonry('appended', $template); 139 140 $(selector + ' .loadmore-trigger').appendTo(selector); 141 142 return $template; 143 }); 144 } 145 146 RexTemplate.getFormByName = function(form_name, options) { 147 if (form_name == 'sales_appraisal') { 148 form_name = 'sales_market_appraisal' 149 } 150 var defaults = { 151 action: 'get_form', 152 name: form_name, 153 }; 154 155 data = $.extend({}, defaults, options); 156 return RexTemplate.sendAjax(data) 157 .then( 158 function(response) { 159 return response; 160 }, 161 function(response) { 162 return response; 163 } 164 ) 165 } 166 167 RexTemplate.getFormByLocation = function(location_name, options) { 168 if (location_name == 'sales_appraisal') { 169 location_name = 'sales_market_appraisal' 170 } 171 var defaults = { 172 action: 'get_form', 173 location: location_name, 174 }; 175 176 data = $.extend({}, defaults, options); 177 return RexTemplate.sendAjax(data) 178 .then( 179 function(response) { 180 return response; 181 }, 182 function(response) { 183 return response; 184 } 185 ) 186 } 187 188 RexTemplate.showLoadMore = function(selector, globalClass, mountOnTop) { 189 var mountDirectionFn = mountOnTop ? 'prepend' : 'append'; 190 var loadMoreTemplate = "<div class='loadmore-wrapper loadmore-" + mountDirectionFn + " " + globalClass + "'> <div class='spinner-overlay is-active'> <div class='spinner brand-bg'></div> </div> </div> "; 191 192 if ($(selector + " .loadmore-" + mountDirectionFn).length == 0) { 193 $(selector)[mountDirectionFn](loadMoreTemplate); 194 } 195 } 196 197 RexTemplate.hideLoadMore = function(selector, mountOnTop) { 198 var mountDirectionFn = mountOnTop ? 'prepend' : 'append'; 199 $(selector).find('.loadmore-wrapper.loadmore-' + mountDirectionFn).remove(); 200 } 201})(jQuery, RexTemplate);
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.