function renderSeniorItem(item) { return '
' + showElementDisplaySearchFormatting(item, item.productname) + '' + (item.form ? ', ' + item.form + '' : '') + (item.dose ? ', ' + item.dose + '' : '') + (item.pack ? ', ' + item.pack + '
' : '') + (item.seniorprice ? '' + item.seniorprice + ' zł' : '') + (item.activesubstance ? '
' + showElementDisplaySearchFormatting(item, item.activesubstance) + '
' : '') + '
'; } function showElementRow(element, product, rowData, itemData) { return showElementRowPerform(element, product, rowData, itemData) } function showElementRowPerform(element, product, rowData, itemData) { if (itemData > '') { element.find(product + ' .' + rowData + ' .senior_display_value').html(itemData); } else { element.find(product + ' .' + rowData).css('display', 'none'); } return element; } function showElementDisplaySearchFormatting(item, itemData) { if (itemData > '') { return itemData.replace(new RegExp('(' + item.search_form + ')', 'gi'), '$1'); } return itemData; } function showElementGetDetails(itemFromList) { if(typeof itemFromList === 'object') { var packageid = itemFromList.packageid } else { packageid=itemFromList; } var item; $.ajax({ url: 'webservice/list.php', data: {detail: packageid}, success: function (data) { item = data[0]; }, async: false }); return item; } function showBanner() { bannerUrl = showBannerGetBanner(); $('#banner img').attr('src', bannerUrl); } function showBannerGetBanner() { var item; $.ajax({ url: 'webservice/list.php', data: {banner: $('.main-product .senior_display_substance .senior_display_value').text()}, success: function (data) { item = data; }, async: false }); return item; } function showElement(itemFromList) { $("#log").html(''); var item = showElementGetDetails(itemFromList); element = $('#senior_display_prototype .senior_display').clone(); element = showElementAdd(element, item, '.main-product'); if (item.replacement && item.replacement[0] && item.replacement[0].productlineid) { element = showElementAdd(element, item.replacement[0], '.replacement-product'); } element.prependTo("#log"); if (item.replacement && item.replacement[0] && item.replacement[0].productlineid) { $('.senior_display ul').css('display', 'inline-block'); $('.senior_display ul').css('margin', '5px'); $('.senior_display ul').css('width', '48%'); $('.senior_display h4').css('display', 'inline-block'); $('.senior_display h4').css('margin', '5px'); $('.senior_display h4').css('width', '48%'); $('.senior_display ul.replacement-product').css('background', '#e9e8e6'); } else { $('.senior_display ul').css('display', 'block'); $('.senior_display h4').css('display', 'block'); $('.senior_display ul.replacement-product').css('display', 'none'); $('.senior_display h4.senior_header_replacement').css('display', 'none'); $('.senior_display ul').css('margin', '5px'); $('.senior_display ul').css('width', 'auto'); $('.senior_display h4').css('width', 'auto'); } $("#searchId").val(item.packageid); showBanner(); } function showElementAdd(element, item, product) { element = showElementRow(element, product, 'senior_header', 'Opis leku:'); element = showElementRow(element, product, 'senior_display_title', item.productname); element = showElementRow(element, product, 'senior_display_substance', item.activesubstance); if (product == '.replacement-product') { mainProductActiveSubstance = element.find('.main-product' + ' .' + 'senior_display_substance' + ' .senior_display_value').html(); if (item.activesubstance != mainProductActiveSubstance) { element.find('.senior_header_replacement').text('Opis leku zawierającego tę samą substancję czynną lub substancję o podobnym działaniu:'); element.find(product + ' .' + 'senior_display_substance' + '').css('background', '#C6EA94'); } else { element.find('.senior_header_replacement').text('Opis leku (zamiennik):'); element.find(product + ' .' + 'senior_display_substance' + '').css('background', 'transparent'); } } element = showElementRow(element, product, 'senior_display_form', item.form); element = showElementRow(element, product, 'senior_display_dose', item.dose); element = showElementRow(element, product, 'senior_display_package', item.pack); element = showElementRow(element, product, 'senior_display_seniorprice', item.seniorprice); if (parseInt(item.seniorprice) > 0) { element.find(product + ' .' + 'senior_display_seniorprice' + '').css('background', '#C6EA94'); } else { element.find(product + ' .' + 'senior_display_seniorprice' + '').css('background', 'transparent'); } element.find('.senior_display_pharmindex_link .senior_display_value a'). attr('href', 'http://pharmindex.pl/searchResultsSingle.php?oper=dc.la&pkid=' + item.packageid); return element; } $(function () { function hideKeyboard() { var element = $('#search'); setTimeout(function () { element.attr('readonly', 'readonly'); // Force keyboard to hide on input field. element.attr('disabled', 'true'); // Force keyboard to hide on textarea field. element.blur(); //actually close the keyboard // Remove readonly attribute after keyboard is hidden. element.removeAttr('readonly'); element.removeAttr('disabled'); }, 100); } $('#search').on('tap', function () { setTimeout(function () { $('body').animate({ scrollTop: $("#search").offset().top - 30 }, 200); }, 100); }); $("#search").autocomplete({ open: function (event, ui) { $('.ui-autocomplete').off('menufocus hover mouseover mouseenter'); }, delay: 0, source: 'webservice/list.php', select: function (event, ui) { //event.preventDefault(); //showElement(ui.item ? ui.item : null); //hideKeyboard(); }, appendTo: '.menu-container', }).autocomplete("instance")._renderItem = function (ul, item) { if (item.promoted == 1) { var element = $("
  • "); } else { var element = $("
  • "); } return element .append(renderSeniorItem(item)) .appendTo(ul) }; senior_reset_log(); }); function senior_reset() { $('#searchId').val(''); $('#search').val(''); senior_reset_log(); } function senior_reset_log() { $('#log').html($('#log-prototype').html()); $('#log .pill-button-text').on('click', function () { $('#search').val($(this).text()); $('#search').trigger('keydown'); }); }