1var ASSSSClass = function(element, options) { 2 'use strict'; 3 4 var voliaConfig = vConfig; 5 if(typeof voliaConfig !== 'undefined') { 6 voliaConfig = voliaConfig; 7 } 8 9 var elem = $(element), 10 obj = this; 11 12 var result_data = ''; 13 14 // Set the Out put style of the search reasult 15 var output_style = 'list'; 16 if(options.output && options.output.groups && options.output.groups.length > 1) { 17 output_style = 'group'; 18 } 19 20 //load nunjucks template engine 21 $.ajaxSetup({ 22 async: false, 23 cache: true 24 }); 25 $.getScript('https://cdn.rawgit.com/mozilla/nunjucks/v2.4.2/browser/nunjucks.min.js', function () { 26 console.info('nunjuicks successfully loaded'); 27 nunjucks.configure({ autoescape: false }); 28 }); 29 30 // while(!loaded) { 31 // setTimeout(function() {console.log('wait')}, 100); 32 // } 33 34 // Merge options with defaults 35 obj.settings = $.extend({ 36 currlang: 'DE', 37 dbpfad: '/fdi/web.nsf/', 38 protokolldb: '/fdi/statistiken.nsf/', 39 gobutton: '#searchgo', 40 searchfield: '#searchfield', 41 content_area: '#content', 42 content_area_modal: false, 43 content_area_modal_root: '#content', 44 headline_area: '#content', 45 search_headline: 'Suchergebnisse', 46 search_headline_template: '', 47 urlschema: '%%db%%id/%%newpageurl%%#%%hashtagval%%', // '%%db%%id/%%newpageurl%%#%%hashtagval%%' 48 show_dummy_elements: '', //this elements are hidden for some issues (dummyelements 4 example) 49 hide_elements: '', //this can hide some elements post-search if u need 50 search_fuzzy: 1, 51 char_min: 2, 52 max_results: 20, 53 skip_media: false, 54 skip_department: false, 55 skip_teaser: false, 56 autoscroll: true, 57 typeahead: true, 58 awesome_spinner: false, 59 fuzzysearch: 1, 60 output:{ 61 group:{} 62 }, 63 trigger: 'gobutton', // one of ['gobutton', 'hashtag'] 64 hashtag: { 65 prefix: 'suche', 66 separator: '~' 67 }, 68 custom_fields: { 69 datefromfield: '', 70 datetofield: '', 71 maincatfield: '', 72 subcatfield: '' 73 }, 74 v_group_filter: '', 75 prev_button_text: 'Die vorherigen Ergebnisse anzeigen', 76 next_button_text: 'Die nächsten Ergebnisse anzeigen', 77 ajax_cb: function() { 78 ajaxsearch_cb(); 79 }, 80 display_cb: function(data) { 81 switch (output_style) { 82 case 'group': 83 displayresult_group_cb(data); 84 break; 85 case 'list': 86 displayresult_list_cb(data); 87 break; 88 } 89 }, 90 typeahead_cb: function() { 91 typeahead_cb(); 92 }, 93 display_ta_cb: function(data) { 94 if (jquery_ui_defined()) { 95 display_jquery_ui_ta_cb(data); 96 } else { 97 display_ta_cb(data); 98 } 99 }, 100 debug: false 101 }, options || {}); 102 103 104 //set default templates 105 if(!obj.settings.output.content_template) { 106 obj.settings.output.content_template = '<ol id="search-{{id}}" role="tabpane" class="tab-pane fade {{active}}" data-start="{{start}}">' + 107 '{% for result in results %}' + 108 '<li style="display: {% if result.display %} list-item {% else %} none {% endif %}"><a href="{{result.url}}">{{result.bezeichnung}}</a></li>' + 109 '{% endfor %}' + 110 '</ol>'; 111 } 112 113 if(!obj.settings.output.list_template) { 114 obj.settings.output.list_template = "{{headline}}<div><p>Zu Ihrer Suche nach '<strong>{{searchvalue}}</strong>' wurden {{counter}} Ergebnisse gefunden.</p>" + 115 "<div id='suche_statistiken'><div class='suchergebnisse'>{{content}}</div></div>" + 116 "<div id='showMoreResults' class=''>" + 117 "{% if showButtons %}" + 118 '<a href="#" id="showPreviousResults" class="btn btn-primary">Die vorherigen Ergebnisse anzeigen</a>' + 119 '<a href="#" id="showNextResults" class="btn btn-primary">Die nächsten Ergebnisse anzeigen</a>' + 120 "{% endif %}" + 121 "</div></div>"; 122 } 123 124 if(!obj.settings.output.group_template) { 125 obj.settings.output.group_template = '{{headline}}' + 126 '<div>' + 127 '<p>Zu ihrer Suche nach <strong>{{searchvalue}}</strong> wurden ({{counter}}) Ergebnisse gefunden</p>' + 128 '<div id="suche_statistiken">' + 129 '<div class="suchergebnisse">' + 130 '<ul class="search-menu nav nav-tabs m-b-2" role="tablist">' + 131 '{% for group in groups %}' + 132 '<li class="nav-item"><a href="#search-{{group.id}}" role="tab" data-toggle="tab" class="nav-link {{group.active}}">{{ group.name }} ({{group.resultcount}})</a></li>' + 133 '{% endfor %}' + 134 '</ul>' + 135 '<div class="tab-content">' + 136 '{% for group in groups %}' + 137 '{{group.content}}' + 138 '{% if group.showButton %}' + 139 '<a class="show-more-results" href="#" data-toggleelement="search-{{group.id}}" >Die nächsten Ergebnisse anzeigen</a>' + 140 '{% endif %}' + 141 '{% endfor %}' + 142 '</div>' + 143 '</div>' + 144 '</div>' + 145 '</div>'; 146 } 147 148 149 150 var gobutton = elem.find(obj.settings.gobutton).css('cursor', 'pointer'); 151 var searchfield = elem.find(obj.settings.searchfield); 152 var tmp_headline = ""; 153 var allowed_triggers = ['gobutton', 'hashtag'];
154 // var trigger = allowed_triggers[0]; 155 var trigger = obj.settings.trigger; 156 157 var searchGoEvent = new Event('searchgo'); 158 159 //init jquerui autocomplete 160 if (jquery_ui_defined() && obj.settings.typeahead) { 161 searchfield.autocomplete({ 162 source: function(request, response) { 163 response(result_data.data); 164 }, 165 minLength: 2, 166 focus: function(event, ui) { 167 var decoded = $("<div/>").html(ui.item.bezeichnung).text(); 168 searchfield.val(decoded); 169 return false; 170 }, 171 select: function(event, ui) { 172 var decoded = $("<div/>").html(ui.item.bezeichnung).text(); 173 searchfield.val(decoded); 174 gobutton.trigger('click'); 175 return false; 176 } 177 }).autocomplete("instance")._renderItem = function(ul, item) { 178 ul.attr('id', 'ta'); 179 return $("<li>") 180 .append(item.bezeichnung) 181 .append('<span class="pull-xs-right">' + item.score + '</span>') 182 .appendTo(ul); 183 }; 184 } 185 186 187 obj.searchfield_safe = searchfield.val().replace(/<(?:.|\n)*?>/gm, ''); 188 189 if ($.inArray(obj.settings.trigger, allowed_triggers)) { 190 trigger = obj.settings.trigger; 191 } 192 193 if (obj.settings.debug) { 194 console.info('Starting ASSSS in ' + trigger + '-Mode!'); 195 console.log('loaded this settings:'); 196 console.log(obj.settings); 197 } 198 199 if (trigger !== 'gobutton' && trigger !== 'hashtag') { 200 if (obj.settings.debug) { 201 console.error('The setting "trigger" must be one of ["gobutton", "hashtag"]'); 202 } 203 return; 204 } 205 206 if (obj.settings.awesome_spinner) { 207 var search_spinner = $('#search_spinner'); 208 if (search_spinner.length) { 209 search_spinner.hide(); 210 if (obj.settings.debug) { 211 console.log('Found existing #search_spinner, will use it as "awesome_spinner"'); 212 } 213 } else { 214 search_spinner = $('<i id="search_spinner" class="fa fa-refresh fa-spin"></i>'); 215 search_spinner.hide().prependTo(elem); 216 if (obj.settings.debug) { 217 console.log('No #search_spinner found, added new one to the search-container'); 218 } 219 } 220 } 221 222 if (obj.settings.typeahead && !jquery_ui_defined()) { 223 // Initzialize TA Markup ... 224 elem.append('<div id="typeAhead" style="display:none"><div id="ta_pointer"></div><div id="ta_content"></div></div>'); 225 var layerTA = $("#typeAhead"); 226 var layerTAContent = $("#ta_content"); 227 228 // Typeahead doesnt work with autocomplete! 229 searchfield.prop('autocomplete', 'off'); 230 231 // Hide Typeahead on Background Click..... 232 $('html').click(function() { 233 $('#typeAhead').hide(); 234 }); 235 } 236 237 238 /* --- Define Event Handlers --- */ 239 elem.on('click', obj.settings.gobutton, function(e) { 240 e.preventDefault(); 241 if (searchfield.val().length >= obj.settings.char_min) { 242 if (obj.settings.awesome_spinner) { 243 search_spinner.fadeIn(); 244 } 245 if (obj.settings.typeahead && !jquery_ui_defined()) { 246 layerTA.fadeOut(); 247 } 248 249 var hashValue = obj.settings.hashtag.prefix + obj.settings.hashtag.separator + searchfield.val().replace(/<(?:.|\n)*?>/gm, ''); 250 251 // set custom fields to url 252 var custom_fields_ext = ""; 253 $.each(obj.settings.custom_fields, function (fieldname, fieldselector) { 254 if(elem.find(fieldselector).length > 0) { 255 custom_fields_ext += obj.settings.hashtag.separator + elem.find(fieldselector).val(); 256 } 257 }); 258 259 hashValue += custom_fields_ext; 260 261 // set v group val to url 262 if(typeof obj.settings.v_group !== 'undefined') { 263 hashValue += obj.settings.hashtag.separator + elem.find(obj.settings.v_group.selector).val(); 264 } 265 266 267 if (trigger === 'gobutton') { 268 if (obj.settings.newpageurl != "" & obj.settings.newpageurl != vConfig.currPageURL) { 269 if(vConfig.seourlmode === 1) { 270 window.location.href = obj.settings.newpageurl + '#' + hashValue; 271 } else { 272 window.location.href = voliaConfig.db + 'id/' + obj.settings.newpageurl + '#' + hashValue; 273 } 274 275 } else if (typeof obj.settings.ajax_cb === 'function') { 276 obj.settings.ajax_cb.call(this); 277 } else if (obj.settings.debug) { 278 console.warn('No valid AJAX Callback function!'); 279 } 280 } else if (trigger === 'hashtag') { 281 var oldHash = window.location.hash; 282 var newHash = hashValue; 283 if (obj.settings.newpageurl != "" & obj.settings.newpageurl != vC
283onfig.currPageURL) { 284 var url = obj.settings.urlschema.replace(/%%db%%/gi, voliaConfig.db).replace(/%%newpageurl%%/gi, obj.settings.newpageurl).replace(/%%hashtagval%%/gi, newHash); 285 window.location.href = url; 286 } else if (oldHash === newHash) { 287 start_hashtag_search(); 288 } else { 289 window.location.hash = newHash; 290 } 291 } 292 } else if (obj.settings.debug) { 293 console.warn('Mindestens ' + obj.settings.char_min + ' Buchstaben eingeben! Eingabe: "' + searchfield.val().replace(/<(?:.|\n)*?>/gm, '') + '"'); 294 } 295 }); 296 297 // Start search with Enter 298 elem.on('keyup', obj.settings.searchfield, function(e) { 299 if (e.keyCode === 13) { 300 e.preventDefault(); 301 gobutton.trigger('click'); 302 } else { 303 if (obj.settings.typeahead && typeof obj.settings.typeahead_cb === 'function') { 304 if (searchfield.val().length >= obj.settings.char_min) { 305 obj.settings.typeahead_cb.call(this); 306 } else { 307 if (!jquery_ui_defined) { 308 layerTA.fadeOut(); 309 } 310 311 if (obj.settings.debug) { 312 console.info('TypeAhead suche startet ab ' + obj.settings.char_min + ' Zeichen! Eingabe: "' + searchfield.val().replace(/<(?:.|\n)*?>/gm, '') + '"'); 313 } 314 } 315 } else if (obj.settings.typeahead && obj.settings.debug) { 316 console.warn('No valid TypeAhead Callback function!'); 317 } 318 } 319 }); 320 321 322 // Display AJAX Results Callback - Private method 323 var displayresult_list_cb = function(response) { 324 var i = 0, 325 counter = 0; 326 var tmp = ""; 327 var orgValue = searchfield.val().replace(/<(?:.|\n)*?>/gm, ''); 328 var standOutStr = ''; 329 330 if (obj.settings.debug) { 331 console.log("Ergebnisse: " + response.data.length); 332 } 333 334 335 var tmpContent= []; 336 // *** Ausgabedefinition *** 337 /* 338 if(obj.settings.output.groups[0].type == 'condition') { 339 for(var i = response.data.length-1; i>=0; i--) { 340 var d = response.data[i]; 341 342 if(obj.settings.output.groups[0].condition(d)) { 343 tmpContent.push(d); 344 counter++; 345 } 346 347 } 348 } else if(obj.settings.output.groups[0].type == 'adresses') { 349 tmpContent.results = searchAdresses_cb(orgValue); 350 counter += tmpContent.length; 351 } 352 353 */ 354 355 for(i=0;i<response.data.length; i++){ 356 counter++; 357 tmpContent.push(response.data[i]); 358 } 359 360 361 362 var hide_result = typeof obj.settings.max_results === 'number' && tmpContent.length > obj.settings.max_results; 363 364 365 //Update Typeahead Statistik 366 if (obj.settings.typeahead) { 367 logSearchQuery(orgValue, counter); 368 } 369 370 var tmpCounter = 0; 371 $.each(tmpContent, function() { 372 this.display = !(hide_result && tmpCounter >= obj.settings.max_results); 373 tmpCounter++; 374 }); 375 376 // *** Gesamtausgabe "Statistiksuche" u. "Standardsuche" *** 377 if ($(obj.settings.headline_area).length > 0) { 378 $(obj.settings.headline_area).html(obj.settings.search_headline); 379 } else { 380 tmp_headline = obj.settings.search_headline_template.replace(/%%HEADLINE%%/gi, obj.settings.search_headline); 381 } 382 383 384 tmp = nunjucks.renderString(obj.settings.output.list_template, { 385 headline: tmp_headline, 386 counter: counter, 387 searchvalue: orgValue, 388 showButtons: hide_result, 389 content: nunjucks.renderString(obj.settings.output.content_template, { 390 results: tmpContent, 391 active: 'in', 392 start: 1, 393 id: 'list' 394 }) 395 }); 396 397 //set content 398 $(obj.settings.content_area).html(tmp); 399 400 401 if (hide_result) { 402 403 var less_ln = $('#showPreviousResults'); 404 var more_ln = $('#showNextResults'); 405 406 var previous_next_func = function(e, type) { 407 e.preventDefault(); 408 if (type === 'next') { 409 $('#search-list').data('start', parseInt($('#search-list').data('start')) + obj.settings.max_results); 410 411 } else if (type === 'previous') { 412 $('#search-list').data('start', parseInt($('#search-list').data('start')) - obj.settings.max_results); 413 414 } 415 416 $('#search-list').attr("start", parseInt($('#search-list').data('start'))); 417 418 $('#search-list').children().hide(); 419 var actPosition = parseInt($('#search-list').data('start')) - 1; 420 var objs = $('#search-list').children().slice(actPosition, actPosition + obj.settings.max_results); 421 objs.fadeIn(); 422 if (actPosition + obj.settings.max_results >= $('#search-list').children().length) { 423 $('#showNextResults').hide(); 424 } else { 425 $('#showNextResults').show(); 426 } 427 428 if (actPosition <= 0) { 429 $('#showPreviousResults').hide(); 430 } else { 431 $('#showPreviousResults').show(); 432 } 433 }; 434 more_ln.click(function(e) { 435 previous_next_func(e, 'next'); 436 }); 437 less_ln.click(function(e) { 438 previous_next_func(e, 'previous'); 439 }); 440 441 442 $('#showMoreResults').append(less_ln).append(more_ln); 443 less_ln.hide(); 444 } 445 446 447 // *** SHOW MODAL WINDOW *** 448 if (obj.settings.content_area_modal) { 449 $(obj.settings.content_area_modal_root).modal('show'); 450 } 451 452 // *** SHOW DUMMY ELEMENTS ** 453 if (obj.settings.show_dummy_elements !== "") { 454 $(obj.settings.show_dummy_elements).show(); 455 } 456
457 // *** HIDE ELEMENTS ** 458 if (obj.settings.hide_elements !== "") { 459 $(obj.settings.hide_elements).hide(); 460 } 461 462 // *** Back to Top - Link *** 463 /**if (obj.settings.autoscroll) { 464 if ($(obj.settings.content_area).height() > 450) { 465 $("#backToTop").show(); 466 } 467 $('html, body').animate({ 468 scrollTop: $(obj.settings.content_area).offset().top 469 }, 1000); 470 }*/ 471 }; 472 473 // Display result as groups for bootstrap tabs or accordion 474 var displayresult_group_cb = function(response) { 475 var counter = 0; 476 var tmp = "", 477 tmpContent = []; 478 var orgValue = searchfield.val().replace(/<(?:.|\n)*?>/gm, ''); 479 480 if (obj.settings.debug) { 481 console.log("Ungefilterte Ergebnisse: " + response.data.length); 482 } 483 484 if(!Array.isArray(obj.settings.output.groups)) { 485 console.error("Output groups needs to be an array!"); 486 return; 487 } 488 489 490 var abort = false; 491 //set the default counter and output array (tmpContent) values 492 $.each(obj.settings.output.groups, function() { 493 if(typeof this.group_name !== 'undefined' && this.group_name != "") { 494 var keyname = this.group_name.toLowerCase().replace(/[^0-9a-z]/ig, ''); 495 tmpContent[keyname] = []; 496 497 // if search for adresses need to do extra ajax query 498 if (this.type == 'adresses') { 499 tmpContent[keyname] = searchAdresses_cb(orgValue); 500 counter += tmpContent[keyname].length; 501 } 502 } else { 503 console.error('Output as tabs requires a group_name!'); 504 abort = true; 505 return; 506 } 507 }); 508 509 if(abort) { 510 return; 511 } 512 513 514 // select data to output 515 for (var i = response.data.length-1; i >= 0; i--) { 516 var d = response.data[i]; 517 518 // break if result element has no name 519 if (d.bezeichnung == "") { 520 continue; 521 } 522 523 $.each(obj.settings.output.groups, function() { 524 525 if (this.type != 'adresse') { 526 527 if(typeof this.condition === 'function') { 528 if (this.condition(d)) { 529 var keyname = this.group_name.toLowerCase().replace(/[^0-9a-z]/ig, ''); 530 tmpContent[keyname].push(d); 531 counter++; 532 } 533 } else { 534 console.error('Condition has to be a function with the data parameter'); 535 } 536 537 } 538 539 }); 540 541 542 } 543 544 // *** Gesamtausgabe "Statistiksuche" u. "Standardsuche" *** 545 if ($(obj.settings.headline_area).length > 0) { 546 $(obj.settings.headline_area).html(obj.settings.search_headline); 547 } else { 548 tmp_headline = obj.settings.search_headline_template.replace(/%%HEADLINE%%/gi, obj.settings.search_headline); 549 } 550 551 // output the data 552 var output_data = { 553 headline: tmp_headline, 554 counter: counter, 555 groups: [] 556 }; 557 558 559 if(typeof obj.settings.output.list_template !== 'undefined' && obj.settings.output.list_template != '') { 560 var previous_tab_key_name = null; 561 $.each(obj.settings.output.groups, function() { 562 var keyname = this.group_name.toLowerCase().replace(/[^0-9a-z]/ig, ''); 563 564 var hide_result = typeof obj.settings.max_results === 'number' && tmpContent[keyname].length > obj.settings.max_results; 565 566 // calculate the display variable 567 var tmpCounter = 0; 568 $.each(tmpContent[keyname], function() { 569 this.display = !(hide_result && tmpCounter > obj.settings.max_results); 570 tmpCounter++; 571 }); 572 573 if (tmpContent[keyname].length > 0) { 574 var active = !previous_tab_key_name || tmpContent[previous_tab_key_name].length == 0; 575 output_data.groups.push({ 576 id: keyname, 577 name: this.group_name, 578 active: active, 579 resultcount: tmpContent[keyname].length, 580 showButton: hide_result, 581 //group result 582 content: nunjucks.renderString(obj.settings.output.content_template, { 583 results:tmpContent[keyname], 584 id: keyname, 585 active: active, 586 start: obj.settings.max_results 587 }) 588 }); 589 } 590 }); 591 } else { 592 console.error('No output list template specified!'); 593 return; 594 } 595 596 if(typeof obj.settings.output.group_template !== 'undefined' && obj.settings.output.group_template != '') { 597 tmp = nunjucks.renderString(obj.settings.output.group_template, output_data); 598 } else { 599 console.error('No output group template specified!'); 600 return; 601 } 602 603 604 605 $(document).on('click', '.show-more-results', function(e) { 606 e.preventDefault(); 607 var toggleelem = $('#' + $(this).data('toggleelement')); 608 609 var num_elements_to_show = toggleelem.data('start') + obj.settings.max_results; 610 611 612 toggleelem.children().each(function(index) { 613 if (index < num_elements_to_show) { 614 $(this).show(); 615 } 616 }); 617 618 toggleelem.data('start', num_elements_to_show); 619 620 if (num_elements_to_show >= toggleelem.children().length) { 621 $(this).hide(); 622 } 623 624 }); 625 626 627 //UpdatesTypeahead Statistik
628 console.log(counter); 629 if (obj.settings.typeahead) { 630 logSearchQuery(orgValue, counter); 631 } 632 633 634 // set content 635 $(obj.settings.content_area).html(tmp); 636 637 // *** SHOW MODAL WINDOW *** 638 if (obj.settings.content_area_modal) { 639 $(obj.settings.content_area_modal_root).modal('show'); 640 } 641 642 // *** SHOW DUMMY ELEMENTS ** 643 if (obj.settings.show_dummy_elements !== "") { 644 $(obj.settings.show_dummy_elements).show(); 645 } 646 647 // *** HIDE ELEMENTS ** 648 if (obj.settings.hide_elements !== "") { 649 $(obj.settings.hide_elements).hide(); 650 } 651 652 // *** Back to Top - Link *** 653 if (obj.settings.autoscroll) { 654 if ($(obj.settings.content_area).height() > 450) { 655 $("#backToTop").show(); 656 } 657 $('html, body').animate({ 658 scrollTop: $(obj.settings.content_area).offset().top 659 }, 1000); 660 } 661 }; 662 663 var searchAdresses_cb = function(query_value) { 664 var adresses = []; 665 666 $.ajax({ 667 url: obj.settings.dbpfad.replace('web', 'adressbuch') + 'address_search', 668 dataType: 'text', 669 data: 'OpenAgent&q=' + query_value + '&l=' + obj.settings.currlang + '&' + Math.random(), 670 async: false, 671 }) 672 .done(function(response) { 673 adresses = JSON.parse(response); 674 }) 675 .fail(function(response) { 676 obj.settings.debug && console.warn("ERROR IN REQUEST\n" + response.responseText); 677 }); 678 679 return adresses; 680 }; 681 682 // Fill the var for the jQuery UI autocomplete 683 var display_jquery_ui_ta_cb = function(data) { 684 result_data = data; 685 }; 686 687 // Display Typeahead Results - Private method 688 var display_ta_cb = function(data) { 689 var tmp = $('<table class=""><tbody></tbody></table>'); 690 layerTAContent.html(tmp); 691 layerTA.fadeIn('fast'); 692 693 $(data.data).each( 694 function(index) { 695 var d = data.data[index]; 696 if (d.bezeichnung === "") { 697 return; 698 } 699 700 var row = $("<tr>"); 701 var cell1 = $("<td>"); 702 var ln = $('<a href="#">' + d.bezeichnung + '</a>'); 703 ln.click(function(e) { 704 e.preventDefault(); 705 searchfield.val($(this).text()); 706 gobutton.trigger('click'); 707 }); 708 cell1.append(ln); 709 var cell2 = $("<td>" + d.score + "</td>"); 710 row.append(cell1).append(cell2); 711 layerTAContent.find('tbody').append(row); 712 } 713 ); 714 }; 715 716 717 718 // AJAX Typeahead callback - Private method 719 var typeahead_cb = function() { 720 var theValue = searchfield.val(); 721 var protokollSuchTA = obj.settings.protokolldb + "web_suche_typeahead"; 722 var protokollSuchURL = obj.settings.protokolldb + "statistiken_suche_begriffe"; 723 724 if (obj.settings.awesome_spinner) { 725 search_spinner.fadeIn(); 726 } 727 728 $.ajax({ 729 url: protokollSuchTA, 730 dataType: 'text', // Should be 'json' if the Webserver sent correct MIME Typ 731 data: 'OpenAgent&sprache=' + obj.settings.currlang + '&query=' + theValue + '&ns=0&rnd=' + Math.random(), 732 async: true 733 }) 734 .done(function(response) { 735 response = JSON.parse(response); 736 if (response.data.length < 1) { 737 $('#typeAhead').fadeOut(); 738 return true; 739 } else if (!$('#typeAhead').is(":visible")) { 740 $('#typeAhead').fadeIn(); 741 } 742 743 if (typeof obj.settings.display_ta_cb === 'function') { 744 obj.settings.display_ta_cb.call(this, response); 745 } else if (obj.settings.debug) { 746 console.warn('No valid AJAX Callback function!'); 747 } 748 }) 749 .fail(function(response) { 750 obj.settings.debug && console.warn("ERROR IN REQUEST\n" + response.responseText); 751 }) 752 .always(function(response) { 753 if (obj.settings.awesome_spinner) { 754 search_spinner.fadeOut('Slow'); 755 } 756 }); 757 }; 758 759 760 // AJAX Search Request - Private method 761 var ajaxsearch_cb = function() { 762 var result = getSearchValueFromHash(); 763 console.log(result); 764 var orgValue = result.value; 765 var protokollSuchURL = obj.settings.protokolldb + "statistiken_suche_begriffe"; 766 var vCMSSuchURL = obj.settings.dbpfad + "web_suche_ft_ajax"; 767 var cat = '', 768 subcat = '', 769 datefrom = '', 770 dateto = ''; 771 772 if(result.custom_fields) { 773 if(result.custom_fields.maincatfield && result.custom_fields.maincatfield != "") 774 cat = result.custom_fields.maincatfield; 775 776 if(result.custom_fields.subcatfield && result.custom_fields.subcatfield != "") 777 subcat = result.custom_fields.subcatfield; 778 779 if(result.custom_fields.datefromfield && result.custom_fields.datefromfield != "") 780 datefrom = result.custom_fields.datefromfield; 781 782 if(result.custom_fields.datetofield && result.custom_fields.datetofield != "") 783 dateto = result.custom_fields.datetofield; 784 785 } 786 787 if(result.v_group && result.v_group != "") { 788 elem.find(obj.settings.v_group.selector).val(result.v_group); 789 } 790 791 792 // Volltextsuche auf die voila Instanz 793 $.ajax({
794 // url: vCMSSuchURL, 795 url: vCMSSuchURL, 796 dataType: 'text', // Should be 'json' if the Webserver sent correct MIME Typ 797 data: 'OpenAgent&sprache=' + obj.settings.currlang + '&oua=0&query=' + orgValue + '&ns=0&scat=' + cat + '&ssubcat=' + subcat + '&sfromdate=' + datefrom + '&stilldate=' + dateto + '&sort=&ftsearch=' + obj.settings.fuzzysearch + '&rnd=' + Math.random(), 798 async: true 799 }) 800 .done(function(response) { 801 response = JSON.parse(response); 802 803 // filter empty result 804 response.data = response.data.filter(function (result) { 805 return result.bezeichnung != ""; 806 }); 807 808 if (typeof obj.settings.v_group !== "undefined") { 809 if (typeof obj.settings.v_group.filter === 'function') { 810 console.info("vGruppe Filter wird angewendet") 811 response.data = response.data.filter(obj.settings.v_group.filter); 812 } else { 813 console.warn("vGroup Filter hast to be a function"); 814 } 815 } 816 817 818 if (typeof obj.settings.display_cb === 'function') { 819 obj.settings.display_cb.call(obj, response); 820 } else if (obj.settings.debug) { 821 console.warn('No valid Display Callback function!'); 822 } 823 if (obj.settings.awesome_spinner) { 824 search_spinner.fadeOut('slow'); 825 } 826 }) 827 .fail(function(json) { 828 if (obj.settings.debug) { 829 console.warn("ERROR IN REQUEST\n" + json.responseText); 830 } 831 }); 832 }; 833 834 // Handle hashtag-trigger events 835 if (trigger === 'hashtag') { 836 var start_hashtag_search = function() { 837 var hash = window.location.hash; 838 var hashParts = hash.split(obj.settings.hashtag.separator); 839 if (hashParts[0].toLowerCase() === "#" + obj.settings.hashtag.prefix && typeof hashParts[1] !== 'undefined') { 840 var suche = hashParts[1]; 841 842 // Decode URL-HashTag-Part 843 suche = decodeURI(suche); 844 845 if (suche.length >= 0) { 846 searchfield.val(suche); 847 848 if (typeof obj.settings.ajax_cb === 'function') { 849 obj.settings.ajax_cb.call(this); 850 } else if (obj.settings.debug) { 851 console.warn('No valid AJAX Callback function!'); 852 } 853 } else if (obj.settings.debug) { 854 console.info('No search-String given!'); 855 } 856 } else if (obj.settings.debug) { 857 console.warn('Hash "' + hash + '" doesn\'t start with "#' + obj.settings.hashtag.prefix + obj.settings.hashtag.separator + '"!'); 858 } 859 }; 860 861 if (window.location.hash.length > 0) { 862 start_hashtag_search(); 863 } 864 865 $(window).bind('hashchange', function(e) { 866 start_hashtag_search(); 867 }); 868 869 if (obj.settings.content_area_modal) { 870 $(obj.settings.content_area_modal_root).on('hidden.bs.modal', function() { 871 window.location.hash = '#'; 872 }); 873 } 874 } 875 876 /* Alle Suchanfragen, die Ergebnisse liefern (z. Zt. > 1, da vCMS ein Fake-Ergebnis zur Suchanfrage hinzufügt), 877 werden protokolliert (für die Type-Ahead-Funktion) */ 878 function logSearchQuery(theValue, theCount) { 879 var logsearchimg = obj.settings.protokolldb + "suchvorgang.gif?OpenForm&sprache=" + obj.settings.currlang + "&begriff=" + theValue.replace(/<(?:.|\n)*?>/gm, '') + "&score=" + theCount; 880 881 if (theCount > 1) { 882 if ($('logsearchimg').length > 0) { 883 $('logsearchimg').prop('src', logsearchimg); 884 } else { 885 $(document.body).append("<img id=\"logsearchquery\" style=\"display:none;\" src=\"" + logsearchimg + "\" width=\"1\" height=\"1\">"); 886 } 887 } 888 }; 889 890 function getSearchValueFromHash() { 891 var result = {}; 892 var hashParts = window.location.hash.split(obj.settings.hashtag.separator); 893 894 if (hashParts[0].toLowerCase() === "#" + obj.settings.hashtag.prefix && typeof hashParts[1] !== 'undefined') { 895 result.value = decodeURIComponent(hashParts[1]).replace(/<(?:.|\n)*?>/gm, ''); 896 897 var index = 2; 898 result.custom_fields = []; 899 900 $.each(obj.settings.custom_fields, function (fieldname, fieldselector) { 901 result.custom_fields[fieldname] = hashParts[index]; 902 console.log(fieldname); 903 index++; 904 }); 905 906 907 if(hashParts[index]) 908 result.v_group = hashParts[index]; 909 910 911 } 912 913 return result; 914 } 915}; 916 917 918/* ============= MAIN ASSSS ============= */ 919$.fn.assss = function(options) { 920 // if nothing is selected, return nothing; can't chain anyway 921 if (!this.length) { 922 if (options && options.debug && window.console) { 923 console.warn("no objects found, returning nothing."); 924 } 925 return; 926 } 927 928 929 return this.each(function() { 930 var element = $(this); 931 // Return early if this element already has a plugin instance 932 if (element.data('assss')) { 933 return; 934 } 935 var assss = new ASSSSClass(this, options); 936 // Store plugin object in this element's data 937 element.data('assss', assss); 938 }); 939} 940 941function jquery_ui_defined() { 942 return typeof jQuery.ui === "object"; 943} 944 945jQuery.cachedScript = function( url, options ) { 946 947 // Allow user to set any option except for dataType, cache, and url 948 options = $.extend( options || {}, { 949 dataType: "script", 950 cache: true, 951 url: url, 952 async: false 953 }); 954 // console.log(options); 955 956 // Use $.ajax() since it is more flexible than $.getScript 957 // Return the jqXHR object so we can chain callbacks 958 return jQuery.ajax( options ); 959};
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.