1SdSelect = {}; 2SdSelect.recalc_count_go = false; 3SdSelect.init = function (el, version, opt) { 4 5 6 if ($(el).length == 0 || $(el).hasClass('init')) { 7 return; 8 } 9 10 $(el).addClass('init') 11 12 if (typeof (version) == 'undefined') { 13 version = 1; 14 } 15 16 if (typeof (opt.prechange) == 'undefined') { 17 opt.prechange = function () {}; 18 } 19 20 if (typeof (opt.afterinit) == 'undefined') { 21 opt.afterinit = function () {}; 22 } 23 24 25 26 27 28 29 30 var placeholder = el.data('placeholder'); 31 32 var unic_class = 'smartMultiSelect_input_' + el.attr('name').replace('[', '').replace(']', ''); 33 34 if ($('.' + unic_class).length) { 35 var input = $('.' + unic_class).first(); 36 } else { 37 var input = $('<input class="smartMultiSelect_input ' + unic_class + '" value="" autocomplete="off" placeholder="' + placeholder + '" type="text">').insertAfter(el); 38 } 39 40 el.data('input', input); 41 el.hide(); 42 43 var width = $(input).width() * 0.7; 44 if (width < 300) { 45 width = 300; 46 } 47 48 if (width > 400) { 49 width = 400; 50 } 51 52 var body_block = $('<div class="sdselect-body">\n\ 53 <div class="sdselect-list"><img src="/assets/image/preloader/preloader-64x64-2.svg"/></div>\n\ 54 </div>').insertAfter(input).hide(); 55 56 if (window.device.mobile == 1) { 57 //body_block.css('left', '0px'); 58 //body_block.css('top', '0px'); 59 } else { 60 body_block.width(width); 61 body_block.css('left', $(input).position().left); 62 body_block.css('top', $(input).position().top + $(input).outerHeight() - 1); 63 } 64 65 body_block.hover(function () { 66 $(this).addClass('hover') 67 }, function () { 68 $(this).removeClass('hover') 69 }); 70 71 72 73 74 75 var list_block = $(body_block).find('.sdselect-list'); 76 77 78 79 input.data('body_block', body_block); 80 el.data('body_block', body_block); 81 82 83 84//оÑкÑÑÑие ÑелекÑа 85 input.click(function () { 86 var input = this; 87 setTimeout(function () { 88 89 $(input).data('body_block').show(); 90 if (window.device.mobile == 0) { 91 $(input).data('body_block').css('left', $(input).position().left); 92 $(input).data('body_block').css('top', $(input).position().top + $(input).outerHeight() - 1); 93 } 94 95 }, 100); 96 97 98 return false; 99 }); 100 101 102 $('html').click(function () { 103 $('.smartMultiSelect_input').each(function () { 104 var input = $(this); 105 if (!input.data('body_block').hasClass('hover')) { 106 input.data('body_block').hide(); 107 } 108 }); 109 }); 110 111 112 113 114 input.focus(function () {
115 input.keyup(); 116 }).keyup(function (e) { 117 118 //оÑÐ»Ð°Ð²Ð»Ð¸Ð²Ð°Ñ ÐºÐ¾Ð½Ð¿ÐºÐ¸ ввеÑÑ Ð²Ð½Ð¸Ð· Ð´Ð»Ñ Ð½Ð°Ð²Ð¸Ð³Ð°Ñии по ÑпиÑÐºÑ 119 if (e.keyCode == 40 || e.keyCode == 38) { 120 var items = list_block.find('a'); 121 var start_item = e.keyCode == 40 ? 0 : items.length - 1; 122 var hover = false; 123 for (i = 0; i < items.length; i++) { 124 var next_item = e.keyCode == 40 ? i + 1 : i - 1; 125 if ($(items[i]).hasClass('hover') && next_item <= items.length - 1 && next_item >= 0) { 126 $(list_block).find('a').removeClass('hover') 127 $(items[next_item]).addClass('hover') 128 hover = true; 129 break; 130 } 131 } 132 if (!hover) { 133 $(list_block).find('a').removeClass('hover') 134 $(items[start_item]).addClass('hover'); 135 if (start_item == 0) { 136 list_block.scrollTop(0); 137 } else { 138 list_block.scrollTop(start_item * 30); 139 } 140 return; 141 } 142 if (e.keyCode == 40 && i >= 6) { 143 list_block.scrollTop((i + 2) * 30 - 210) 144 } 145 if (e.keyCode == 38) { 146 list_block.scrollTop((i - 1) * 30) 147 } 148 return; 149 } 150 if (e.keyCode == 13) { 151 list_block.find('a.hover').click(); 152 return false; 153 } 154 155 if ($(this).val().length < 3) { 156 //list_block.html('ÐведиÑе не менее 3-Ñ Ñимволов'); 157 //return; 158 } 159 var reg = typeof el.data('region') == 'undefined' ? '' : el.data('region'); 160 $.ajax({ 161 type: "GET", 162 url: "/api/smart_seearch/" + reg, 163 data: { 164 term: input.val(), 165 relation: el.data('relation'), 166 search_essence: el.data('search-essence'), 167 search_empty_essence: el.data('search-empty-essence'), 168 version: version, 169 }, 170 dataType: 'json', 171 success: function (json) { 172 173 174 175 176 var selected = el.val(); 177 if (json.result && json.result.length > 0) { 178 list_block.html(''); 179 for (var i in json.result) { 180 var class_name = selected && selected.indexOf(json.result[i].id + "") != -1 ? "selected" : ""; 181 182 //console.log(json.result[i].sub_text == null, json.result[i].sub_text, json.result[i].text); 183 184 //console.log(typeof json.result[i].city_id !== 'undefined'); 185 186 if (json.result[i].sub_text == null || json.result[i].sub_text == '') { 187 var text = (json.result[i].full_text ? json.result[i].full_text : json.result[i].text); 188 var text_source = text; 189 } else { 190 var text = json.result[i].text + "<span class='sub_text'>" + json.result[i].sub_text + "</span>"; 191 var text_source = json.result[i].text; 192 } 193 194 195 196 197 //вÑделение иÑкомой ÑÑÑоки в ÑпиÑке ваÑианÑов 198 if (input.val().toUpperCase() && text.toUpperCase().indexOf(input.val().toUpperCase()) != -1) { 199 var start = text.toUpperCase().indexOf(input.val().toUpperCase()); 200 var end = start + input.val().length - 1; 201 var t = ''; 202 for (var j = 0; j < text.length; j++) { 203 if (j == start) { 204 t = t + "<span>"; 205 } 206 t = t + text[j]; 207 if (j == end) { 208 t = t + "</span>"; 209 } 210 } 211 text = t; 212 } 213 214 var list_goup = $(list_block).find('[data-group="' + json.result[i].group + '"]'); 215 216 if (list_goup.length == 0) { 217 var list_goup = $('<div>').addClass('sdselect-group').attr('data-group', json.result[i].group).appendTo(list_block); 218 $('<div class="title title--' + json.result[i].group_style + '">' + json.result[i].group + '</div>').appendTo(list_goup); 219 } 220 221 var filter_row = $('<a data-id="' + json.result[i].id + '" class="' + class_name + '">
221' + text + '</a>').appendTo(list_goup); 222 223 filter_row.data('text_source', text_source); 224 225 if (typeof json.result[i].city_id !== 'undefined') { 226 filter_row.data('city_id', json.result[i].city_id); 227 } 228 229 filter_row.click(function () { 230 231 var link = $(this); 232 var value = link.data('id'); 233 234 235 opt.prechange(el, value); 236 237 if (link.hasClass('selected')) { 238 el.find('option[value="' + value + '"]').remove(); 239 240 var type = value.split(':')[0]; 241 if (type == 'c' || type == 'rd') { 242 el.find('option').remove(); 243 } 244 245 } else { 246 el.data('last_change', value); 247 $("<option value='" + value + "' selected='selected'>" + link.data('text_source') + "</option>").appendTo(el); 248 249 if (link.data('city_id')) { 250 var opts = el.find('option'); 251 var set_city_id = false; 252 var has_city_id = false; 253 opts.each(function () { 254 var opt = $(this); 255 var type = opt.attr('value').split(':')[0]; 256 257 if (type == 'c') { 258 has_city_id = true; 259 if (opt.attr('value') != link.data('city_id')) { 260 opt.remove(); 261 set_city_id = true; 262 } 263 } 264 }); 265 266 267 if (set_city_id || !has_city_id) { 268 el.data('last_change', link.data('city_id')); 269 $("<option value='" + link.data('city_id') + "' selected='selected'></option>").appendTo(el); 270 } 271 } 272 273 } 274 275 el.change(); 276 277 278 279 280 $(this).toggleClass('selected'); 281 282 input.val(''); 283 body_block.hide(); 284 285 286 }).hover(function () { 287 $(list_block).find('a').removeClass('hover') 288 $(this).addClass('hover') 289 }, function () { 290 $(list_block).find('a').removeClass('hover') 291 }); 292 293 } 294 } 295 } 296 }); 297 }).keydown(function (e) { 298 return; 299 if (e.keyCode == 27) { 300 body_block.hide(); 301 if (window.device.mobile == 1) { 302 skip_onhashchange = 1; 303 window.history.back(); 304 } 305 return false; 306 } 307 308 if (e.keyCode == 13) { 309 return false; 310 } 311 }); 312 313 314 315 316 317 318 319 el.mouseup(function () { 320 321 322 var selected = el.val(); 323 324 325 if (selected && selected.length > 0) { 326 console.log('go selected reload'); 327 328 var reg = typeof el.data('region') == 'undefined' ? '' : el.data('region'); 329 330 $.ajax({ 331 type: "GET", 332 url: "/api/smart_seearch/" + reg, 333 data: { 334 id: selected, 335 relation: el.data('relation'), 336 search_essence: el.data('search-essence'), 337 search_empty_essence: el.data('search-empty-essence'), 338 version: version, 339 }, 340 dataType: 'json', 341 success: function (json) { 342 343 344 345 346 347 if (json.result && json.result.length > 0) { 348 for (var item of json.result) { 349 350 el.find('[value="' + item.id + '"]').html(item.text); 351 continue; 352 353 var el_selected = $('<div><span data-id="' + json.result[i].id + '" class="delete">×</span><span class="label">' + json.result[i].full_text + '</span></div>').appendTo(selected_block); 354 355 el_selected.find('.delete').click(function () { 356 console.log('del click'); 357 358 el.find('option[value="' + $(this).data('id') + '"]').remove(); 359 360 //list_block.find('a[data-id="' + $(this).data('id') + '"]').toggleClass('selected'); 361 list_block.find('a[data-id="' + $(this).data('id') + '"]').click(); 362 363 el.mouseup(); 364 365 // 366 367 }); 368 } 369 } 370 371 372 opt.afterinit(); 373 el.change(); 374 } 375 }); 376 } 377 }); 378 379 el.mouseup(); 380 381 382 return; 383 384 el.mousedown(function () { 385 386 console.log('set val to ' + $(this).attr('name')); 387 388 var val = $(this).data('val'); 389 var add = $(this).data('add'); 390 $(this).data('val', ''); 391 $(this).data('add', ''); 392 if (add == 1) { 393 if (!el.prop('multiple')) { 394 $(this).html(''); 395 $(this).val(''); 396 } 397 $("<option value='" + val + "' selected='selected'></option>").appendTo($(this)); 398 } else { 399 $(this).find('option[value="' + val + '"]').remove(); 400 } 401 el.change(); 402 }); 403 404 405 406 407 input.click(function () { 408 409 var input = this; 410 setTimeout(function () { 411 412 413 $(input).data('body_block').show(); 414 if (window.device.mobile == 0) { 415 $(input).data('body_block').css('left', $(input).position().left); 416 $(input).data('body_block').css('top', $(input).position().top); 417 } 418 419 }, 100); 420 421 422 }).change(function () { 423 424 }); 425 426}
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.