1 2/* 3 EC 4 Simple Search 5 Date: 2021.06 6*/ 7 8; (function ($) { 9 10 'use strict'; 11 12 var defaults = { 13 input_element: undefined, 14 loader_element: undefined, 15 results_element: undefined, 16 level_element: undefined, 17 max_level: undefined, 18 load_more_place_holder_element:undefined 19 }; 20 21 $.fn.ecSimpleSearch = function (options) { 22 23 if (this.length === 0) { 24 return this; 25 } 26 else if (this.length > 1) { 27 this.each(function () { $(this).ecSimpleSearch(options) }); 28 return this; 29 } 30 31 var plugin = {}; 32 plugin.elem = this; 33 plugin.namespace = "ec_smplsrch_"; 34 plugin.settings = $.extend({}, defaults, options); 35 36 plugin.lock = false; 37 plugin.submit_trigger = undefined; 38 39 var clear_results = function () { 40 $(plugin.settings.results_element).children().remove(); 41 } 42 43 var reset = function () { 44 clear_results(); 45 $(plugin.settings.loader_element).hide(); 46 $(plugin.settings.input_element).focus(); 47 plugin.submit_trigger = undefined; 48 plugin.lock = false; 49 if (typeof (plugin.settings.level_element) != "undefined") { 50 $(plugin.settings.level_element).val(1); 51 } 52 } 53 54 var is_close_to_view = function (elem) { 55 var pageTop = $(window).scrollTop(); 56 var pageBottom = pageTop + $(window).height(); 57 var elementTop = $(elem).offset().top; 58 return pageBottom >= elementTop; 59 } 60 61 var get_current_level = function () { 62 var current_level = 1; 63 if (typeof (plugin.settings.level_element) != "undefined") { 64 current_level = $(plugin.settings.level_element).val() * 1; 65 } 66 if (isNaN(current_level) || current_level < 1) 67 { 68 current_level = 1; 69 } 70 return current_level; 71 } 72 73 var run_next_level = function () { 74 if (typeof (plugin.settings.load_more_place_holder_element) != "undefined") { 75 if (!plugin.lock && $(plugin.settings.input_element).val() != "") { 76 if (get_current_level() < plugin.settings.max_level) { 77 plugin.submit_trigger = "lazy"; 78 $(plugin.settings.level_element).val(get_current_level() + 1); 79 $(plugin.settings.load_more_place_holder_element).find(".loader").show(); 80 $(plugin.elem).submit(); 81 } 82 else { 83 $(plugin.settings.load_more_place_holder_element).find(".loader").hide(); 84 } 85 } 86 } 87 } 88 89 var init = function () { 90 91 $(plugin.elem).on("submit", function (e) { 92 if (!plugin.lock) { 93 plugin.lock = true; 94 if (typeof (plugin.submit_trigger) == "undefined") { 95 clear_results(); 96 } 97 else if (plugin.submit_trigger == "lazy") { 98 } 99 $(plugin.settings.loader_element).show(); 100 } 101 }).on("ec_form_submit_completed", function (e) { 102 if (typeof (plugin.submit_trigger) == "undefined") { 103 clear_results(); 104 } 105 //var run_next_level_immediately = false; 106 if (typeof (e.detail) != "undefined" && typeof (e.detail.response) != "undefined") { 107 var data = e.detail.response; 108 if (queryString("q") != data.q) { 109 history.pushState({ 110 q: data.q, 111 scrollTop: $(window).scrollTop() 112 }, "", ["/?q=", encodeURI(data.q)].join("")); 113 } 114 //if (typeof (data.results) == "undefined" || data.results.length == 0) { 115 // run_next_level_immediately = true; 116 //} 117 console.log(data.results.length); 118 if ((typeof (plugin.submit_trigger) == "undefined" && typeof (data.results) != "undefined" && data.results.length > 0) 119 || (typeof (plugin.submit_trigger) != "undefined" && plugin.submit_trigger == "lazy" && typeof (data.results) != "undefined")) { 120 121 let count_ref = $(plugin.settings.results_element).find(".count"); 122 if (count_ref.length == 0) { 123 count_ref = $("<div></div>").addClass("count").appendTo(plugin.settings.results_element) 124 .append($("<span/>").text("× ×צ×× ")) 125 .append($("<span/>").addClass("count-inner").text("0")) 126 .append($("<span/>").text([" ××תר×× ×××פ×ש '", data.q, "'"].join(""))); 127 128 // Manager-only: export search results to Excel. 129 // Sends the ORIGINAL search params (q + level) to the 130 // server, which re-runs the search over the full result 131 // set (not just what's currently rendered in the DOM). 132 if (typeof isAdmin !== "undefined" && isAdmin) { 133 $("<button></button>") 134 .addClass("export-search-excel") 135 .attr("type", "button") 136 .css({ "margin-inline-start": "15px", "padding": "4px 12px", "background": "#8a6d3b", "color": "#fff", "border": "none", "border-radius": "3px", "cursor": "pointer" }) 137 .text("××צ×× ×ª×צ××ת ××קס×") 138 .on("click", function () { 139 var q = data.q || $(plugin.settings.input_element).val() || ""; 140 var lvl = $(plugin.settings.level_element).val() || plugin.settings.max_level || 2; 141 if (!q) { alert("××× ×ª×צ××ת ×××צ××."); return; } 142 var $f = $("<form></form>").attr({ method: "POST", action: "/management/books/export-excel" }); 143 $("<input>").attr({ type: "hidden", name: "mode", value: "simple" }).appendTo($f); 144 $("<input>").attr({ type: "hidden", name: "q", value: q }).appendTo($f); 145 $("<input>").attr({ type: "hidden", name: "level", value: lvl }).appendTo($f); 146 $f.appendTo(document.body).submit(); 147 $f.remove(); 148 }) 149 .appendTo(count_ref); 150 } 151 } 152 const count_inner_ref = $(count_ref).find(".count-inner"); 153 $(count_inner_ref).text(parseFloat($(count_inner_ref).text()) + data.results.length); 154 //$("<div></div>").addClass("count").text(["× ×צ×× ", data.results.length, " ××תר×× ", ($(plugin.settings.results_element).find(".kotar-row:not(.header-kotar-row)").length > 0 ? "× ×ספ×× " : ""), "×××פ×ש '", data.q, "'"].join("")).appendTo(plugin.settings.results_element); 155 } 156 if (typeof (data.results) != "undefined" && data.results.length > 0) { 157 158 if ($(plugin.settings.results_element).find(".header-kotar-row").length == 0) { 159 $(["<div class=\"kotar-row header-kotar-row\">", 160 "<span class=\"kotar-title\">ש×</span>", 161 "<span class=\"kotar-authors\">×××ר</span>", 162 "<span class=\"kotar-content\">ת×××</span>", 163 "<span class=\"kotar-location\">×××§××</span>", 164 "<span class=\"kotar-isexist\">×××× ×ת</span>", 165 "</div>"].join("")).appendTo(plugin.settings.results_element); 166 } 167 $(data.results).each(function () { 168 var x = this; 169 var row = $("<div></div>").addClass("kotar-row").attr("data-book-id", x.book_id).appendTo(plugin.settings.results_element); 170 if (x.is_archive) row.addClass("kotar-row-archive"); 171 var title = $("<div></div>").addClass("kotar-title").appendTo(row);
172 $("<a></a>").prop("href", x.url).prop("target", "_blank").text(x.kotar_name).appendTo(title); 173 var authors = $("<div></div>").addClass("kotar-authors").appendTo(row); 174 if (typeof (x.kotar_authors_name) != "undefined" && x.kotar_authors_name != null && x.kotar_authors_name.length > 0) { 175 x.kotar_authors_name.map(author => { 176 $("<div></div>").addClass("kotar-author").text(author).appendTo(authors); 177 }); 178 } 179 $("<div></div>").addClass("kotar-content").text(x.kotar_content).appendTo(row); 180 var location = $("<div></div>").addClass("kotar-location").appendTo(row); 181 $("<button></button>").addClass("map-button").attr("data-location", x.book_location).attr("data-kotar-name", x.kotar_name).attr("alt", ["×××¤× ××××§×× ", x.book_location].join("")).prop("title", ["×××¤× ××××§×× ", x.book_location].join("")).prop("target", "_blank").append($("<i></i>").addClass("icofont-search-map")).append($("<span></span>").text(x.book_location)).appendTo(location); 182 var availability = $("<div></div>").addClass("kotar-isexist").appendTo(row); 183 $("<div></div>").addClass(x.is_book_available ? "book-exists-check" : "book-exists-close").append($("<i></i>").addClass(x.is_book_available ? "icofont-check-circled" : "icofont-close-circled")).append($("<span></span>").text(x.is_book_available ? "××××" : "×× ××××")).appendTo(availability); 184 }); 185 $(plugin.settings.results_element).children(".kotar-row").first().find("a").first().focus(); 186 } 187 } 188 $(plugin.settings.loader_element).hide(); 189 plugin.submit_trigger = undefined; 190 plugin.lock = false; 191 //window.scrollTo(window.scrollX, window.scrollY - 1); 192 //window.scrollTo(window.scrollX, window.scrollY + 1); 193 //if (run_next_level_immediately) { 194 if (is_close_to_view(plugin.settings.load_more_place_holder_element)) { 195 run_next_level(); 196 } 197 }).on("reset", function () { 198 reset(); 199 }).find("input[type='submit']").on("click",function(){ 200 clear_results(); 201 if (typeof (plugin.settings.level_element != "undefined")) { 202 $(plugin.settings.level_element).val(1); 203 } 204 }); 205 206 $(plugin.settings.input_element).on("search", function (e) { 207 if ($(plugin.settings.input_element).val() == "") {//x button 208 reset(); 209 } 210 }); 211 212 var q_url = queryString("q"); 213 if (typeof (q_url) != "undefined" && q_url != null && q_url != "") { 214 $(plugin.settings.input_element).val(q_url); 215 $(plugin.elem).submit(); 216 } 217 218 if (typeof (plugin.settings.load_more_place_holder_element) != "undefined") { 219 var func = function () { 220 if (is_close_to_view(plugin.settings.load_more_place_holder_element)) { 221 run_next_level(); 222 } 223 } 224 $(window).on("scroll", func); 225 } 226 227 $(plugin.settings.input_element).focus(); 228 229 }; 230 231 init(); 232 233 return this; 234 } 235 236 237})(jQuery);
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.