Advertisement
Guest User

Untitled

a guest
Sep 25th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.93 KB | None | 0 0
  1. $.fn.textWidth = function(text, font) {
  2.  
  3. if (!$.fn.textWidth.fakeEl) $.fn.textWidth.fakeEl = $('<span>').hide().appendTo(document.body);
  4. $.fn.textWidth.fakeEl.text(text || this.val() || this.text()).css('font', font || this.css('font'));
  5. return $.fn.textWidth.fakeEl.width();
  6. };
  7.  
  8. $(function(){
  9. $('#filter_price_range_from, #filter_price_range_to').keyup(function(){
  10. var value = $(this).val();
  11. $(this).val($(this).val().replace(/[^0-9]/g, ''));
  12. value = $(this).val();
  13. var in_width = $.fn.textWidth(value, '13px Arial');
  14. $(this).width(in_width+12);
  15. })
  16. $('#filter_price_range_from, #filter_price_range_to').keyup();
  17. })
  18.  
  19.  
  20.  
  21.  
  22. app_shop.run(function(){
  23. $('._mobile #menu_filter h3').live('click',function(){
  24. $this = $(this);
  25. $this.next().slideToggle(function(){
  26. if($this.next().is(':visible')){
  27. $this.addClass('openList');
  28. }else{
  29. $this.removeClass('openList');
  30. }
  31. });
  32. });
  33.  
  34. app_shop.vars.sendFilter = false;
  35. $('#menu_filter div.filter_item.list_type input, #menu_filter div.filter_item.dual_type input').click(function(){
  36. app_shop.vars.sendFilter = true;
  37. })
  38.  
  39.  
  40. $('._mobile #filter_form').live('submit',function(){
  41. if(!app_shop.vars.sendFilter){
  42. $('html').removeClass('filter_on');
  43. }
  44.  
  45. return app_shop.vars.sendFilter;
  46. });
  47.  
  48. $('#select_top_sort').removeAttr('onchange');
  49. $('#select_top_sort').live('change',function(){
  50.  
  51.  
  52. if(app_shop.vars.view == 1){
  53. $.getJSON('/settings.php?sort_order=' + $(this).val());
  54. app_shop.vars.sendFilter = true;
  55. }else{
  56. $(this).parents('form').submit();
  57. }
  58.  
  59.  
  60. })
  61.  
  62. },'all','#menu_filter');
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74. /*** JS - V5 ***/
  75.  
  76. /* Deklaracja callback */
  77. var filtering_callback = function() { /* void */ }
  78. /* callback po tym jak form został uzupełniony/a , czyli po click a przed wysłaniem AJAX*/
  79. var filtering_callback_click = function() { /* void */ }
  80.  
  81. /* filtrownie V5 - ajax */
  82. var xhr = '';
  83. var v66412_ajax_off = <iai:variable vid="v66412_ajax_off" description="true - brak AJAX" />
  84. var v66412_suwaczek_on = <iai:variable vid="v66412_suwaczek_on" description="true - włącz suwak" />
  85.  
  86. var filter_active_ajax = function(global, global_status, filter_id) {
  87.  
  88. if ( !global ) {
  89. if ( $('#'+filter_id+'_toggle').is(':visible') ) {
  90. $('#'+filter_id+'_toggle').hide(); $('#'+filter_id+'_loader').show();
  91. } else {
  92. $('#'+filter_id+'_toggle').show(); $('#'+filter_id+'_loader').hide();
  93. }
  94. }
  95. else {
  96. if ( global_status == true ) {
  97. $('a.filter_toggle[id != "filter_text_toggle"]').hide(); $('span.filter_loader[id != "filter_text_loader"]').show();
  98. } else {
  99. $('a.filter_toggle[id != "filter_text_toggle"]').show(); $('span.filter_loader[id != "filter_text_loader"]').hide();
  100. }
  101. }
  102. }
  103.  
  104. var filter_response_ajax = function(xml) {
  105. // dla każdego filtra
  106. //for (n=0;filterJSON.filter.length;n++) {
  107. $('navigation>filtering>filter', xml).each(function(){
  108. var $this = $(this);
  109. var filter_id = $this.attr('id').replace('[','').replace(']','');
  110. if ( $('#'+filter_id).length && filter_id != 'filter_text' ) {
  111. $this.find('>item').each(function(){
  112. var $this = $(this);
  113. var quantity = $this.attr('quantity');
  114. var value = $this.attr('value');
  115.  
  116. if ( quantity ) {
  117. if ( quantity > 0 ) {
  118. // oznacz jako dostępny z quantity
  119. $('#'+filter_id+'_val'+value+'_quantity').show();
  120. $('#'+filter_id+'_val'+value+'_quantity span.filter_quantity_value').html(quantity);
  121. $('#'+filter_id+'_val'+value).removeAttr('disabled');
  122. $('#'+filter_id+'_'+value+'_box').removeClass('disabled');
  123. }else{
  124. // oznacz jako dostępny z quantity == 0
  125. $('#'+filter_id+'_val'+value+'_quantity').show();
  126. $('#'+filter_id+'_val'+value+'_quantity span.filter_quantity_value').html(quantity);
  127. $('#'+filter_id+'_val'+value).attr('disabled','disabled');
  128. $('#'+filter_id+'_'+value+'_box').addClass('disabled');
  129. }
  130. }else{
  131. // oznacz jako dostępny bez quantity
  132. $('#'+filter_id+'_val'+value+'_quantity').hide();
  133. $('#'+filter_id+'_val'+value).removeAttr('disabled');
  134. $('#'+filter_id+'_'+value+'_box').removeClass('disabled');
  135. }
  136.  
  137. });
  138. $('div.filter_item.list_type').each(function(){
  139. if($(this).find('li').not('.disabled').length){
  140. $(this).find('h3 a').removeClass('active');
  141. }else{
  142. $(this).find('h3 a').addClass('active');
  143. }
  144. });
  145. filter_active_ajax(true, false);
  146. }else{
  147. // nie ma takiego filtra
  148. }
  149. })
  150. }
  151.  
  152.  
  153. var filter_prepare_ajaxfilter = function() {
  154.  
  155. filter_fill_form();
  156.  
  157. if(v66412_ajax_off==='true'){filter_submit();return false;}
  158.  
  159. var filter_data = $('#filter_form').serialize();
  160. var filter_url = $('#filter_form').attr('action');
  161.  
  162. if($('#viewType').width() > 1) loadAjaxFilter(xhr, filter_data, filter_url);
  163.  
  164. //xhr = filter_send_ajaxfilter(xhr, filter_data);
  165. //filter_active_ajax(true, true);
  166.  
  167. }
  168.  
  169. var stateObj = {foo: "bar"};
  170. function change_my_url(url) {
  171. if (history.pushState) {
  172. history.pushState(stateObj, "", url);
  173. }
  174. }
  175.  
  176. function fadeLoaderOnOff(czy) {
  177. if(czy) $('#content').addClass('load-content');
  178. else $('#content').removeClass('load-content');
  179. }
  180.  
  181. var xhr = '';
  182. function loadAjaxFilter(xhr, dataFilter, urlFilter) {
  183.  
  184. fadeLoaderOnOff(1);
  185.  
  186. xhr = xhr;
  187. urlFilter = urlFilter.replace('lang=pol&', '');
  188. if (xhr && xhr.readystate != 4) xhr.abort();
  189. xhr = $.ajax({url: urlFilter, data: dataFilter, timeout: 15000,
  190. success: function (data, textStatus, jqXHR) {
  191. if(jqXHR.status == 200) {
  192.  
  193. $('#layout > #menu_buttons3').remove();
  194. $('#content').html($(data).find('#content > *'));
  195. $('.search_page #layout').prepend($('#menu_buttons3'));
  196. app_shop.fn.init_mb11_bx();
  197. app_shop.fn.init_fs();
  198.  
  199. $('img.b-lazy').parents('a').addClass('loading');
  200. var bLazy = new Blazy({
  201. breakpoints: [{
  202. width: 420, src: 'data-src-small'
  203. }], success: function(element){
  204. setTimeout(function(){
  205. $(element).parents('.loading').removeClass('loading');
  206. }, 200);
  207. }
  208. });
  209.  
  210. $('#search .align_row').iai_align();
  211. $('#search').wrappTableLayout({numCol: app_shop.vars.view==1?2:3});
  212. change_my_url(this.url);
  213. fadeLoaderOnOff(0);
  214. }
  215. }, error: function (data) {
  216. window.location.href = this.url;
  217. fadeLoaderOnOff(0);
  218. }});
  219. return xhr;
  220. }
  221.  
  222. var filter_send_ajaxfilter = function(xhr, filter_data) {
  223.  
  224. xhr = xhr;
  225. if(xhr && xhr.readystate != 4){
  226. xhr.abort();
  227. filter_active_ajax(true, false);
  228. }
  229.  
  230. xhr = $.ajax({
  231. type: 'GET',
  232. //timeout: 8000,
  233. url: '/search.php?'+filter_data+'&getProductXML=true&xmlType=filtering',
  234. //dataType: 'xml',
  235. dataType: 'text',
  236. success: function(xml){
  237. filter_response_ajax(xml);
  238. },
  239. error: function(xml, sTextStatus, oErrorThrown) {
  240. filter_active_ajax(true, false);
  241. }
  242. });
  243. return xhr;
  244. }
  245. /* /filtrownie V5 - ajax */
  246.  
  247. /* Literały */
  248. var txt_66412_008_001 = <iai:variable vid="66412_008_001" description="wybierz datę" />
  249.  
  250. /* Wyrównanie */
  251. $.fn.setOneHeight=function(){var a=0;$(this).each(function(){if($(this).height()>a){a=$(this).height();}});$(this).css('height',a);}
  252.  
  253. var align_filter_gfx = function(id) {
  254. if ( id ) { $('#'+id+' li').setOneHeight(); }
  255. else {
  256. $('#menu_filter div.filter_gfxonly').each(function() { if ( $(this).is(':visible') ) {$(this).find('li').setOneHeight(); } });
  257. }
  258. }
  259.  
  260. /* Wyrównanie */
  261. function set_filter_cookie() {
  262. var filter_hidden_list = new Array();
  263. $('#menu_filter a.filter_toggle.active').each(function() {
  264. filter_hidden_list.push($(this).attr('href').substring(8));
  265. });
  266. $.cookie('filter_hidden', '', { expires: 355 });
  267. $.cookie('filter_hidden', filter_hidden_list, { expires: 355 });
  268. }
  269.  
  270. function get_filter_cookie() {
  271. var flistA = $.cookie('filter_hidden');
  272. if ( !!flistA ) {
  273. var flist = flistA.split(',');
  274. for(var i=0;i < flist.length;i++) {
  275. $('#menu_filter a.filter_toggle[href="#toggle_'+flist[i]+'"]').addClass('active');
  276. $('#'+flist[i]).hide();
  277. }
  278. }
  279. }
  280. /* /Ukrywanie filtrów */
  281.  
  282. /* Button - zastosuj */
  283. var show_options = function() {
  284. $('#menu_filter div.list_type, #menu_filter div.dual_type').each(function() {
  285. if ( $(this).find('input').is(':checked') ) {
  286. //$('a.filter_submit[data-filter="'+$(this).attr('id')+'"]').show('fast');
  287. $('#filter_buttons').show('fast');
  288. }
  289. });
  290. }
  291. /* /Button - zastosuj */
  292.  
  293. /* Button - pokaż wszystkie */
  294. var filter_showall = function(obj) {
  295. if ( obj.hasClass('active') ) {
  296. obj.removeClass('active');
  297. obj.html(filter_pokaz);
  298. $('#'+obj.attr('data-filter')+' li.filterhidden').removeClass('showhidden');
  299. } else {
  300. obj.addClass('active');
  301. obj.html(filter_ukryj);
  302. $('#'+obj.attr('data-filter')+' li.filterhidden').addClass('showhidden');
  303. }
  304. }
  305.  
  306.  
  307. /* /Button - pokaż wszystkie */
  308.  
  309. /* Wypełnienie formularza na starcie */
  310. var filter_fill_form = function() {
  311.  
  312.  
  313. /* list_type */
  314. $('#menu_filter div.filter_item.list_type').each(function() {
  315. var fID = $(this).attr('id');
  316. var fvt = new Array();
  317. $('#'+fID+'_content input[type=checkbox]:checked').each(function() {
  318. if ($(this).attr('disabled') != 'disabled' ) { fvt.push($(this).val()); }
  319. });
  320. $('#'+fID+'_form').val(fvt);
  321. });
  322.  
  323. if(!$('#filter_price_content input[type="checkbox"]:checked').size()){
  324. /* range */
  325. $('#menu_filter div.filter_range').each(function() {
  326. var fV = $('#'+$(this).attr('data-filter')+'_range_from').val()+'-'+$('#'+$(this).attr('data-filter')+'_range_to').val();
  327. if ( fV != '-' ) { $('#'+$(this).attr('data-filter')+'_form').val(fV); }
  328. });
  329. }
  330.  
  331. /* dual_type */
  332. $('#menu_filter div.filter_item.dual_type input').each(function() {
  333. if ( $(this).is(':checked') && $(this).attr('disabled') != 'disabled') { $('#'+$(this).attr('id')+'_form').val('y'); }
  334. else { $('#'+$(this).attr('id')+'_form').val('') }
  335. });
  336.  
  337. /* text */
  338. if ( $('#filter_text_input').length && $('#filter_text_input').val() != $('#filter_text_input').attr('data-filter') ) { $('#filter_text_form').val($('#filter_text_input').val()); }
  339.  
  340.  
  341.  
  342.  
  343. filtering_callback_click();
  344. }
  345. /* /Wypełnienie formularza na starcie */
  346.  
  347. /* Wysłanie formularza */
  348. var filter_submit = function() {
  349.  
  350. //Wypełnienie formularza
  351. filter_fill_form();
  352.  
  353. //Wysłanie formularza
  354. $('#filter_form').submit();
  355.  
  356. }
  357. /* /Wysłanie formularza */
  358.  
  359. /* oznaczenie aktywnych filtrów na starcie */
  360. var mark_active = function(obj) {
  361. if ( $('#filter_dual #'+obj).length ) {
  362. obj_box = obj+'_y_box';
  363. if ( $('#'+obj).is(':checked') ) { $('#'+obj_box).addClass('enabled'); } else { $('#'+obj_box).removeClass('enabled'); }
  364. } else {
  365. obj_box = obj.replace('_val','_')+'_box';
  366. if ( $('#'+obj).is(':checked') ) { $('#'+obj_box).addClass('enabled'); } else { $('#'+obj_box).removeClass('enabled'); }
  367. }
  368. }
  369.  
  370. /* Korekta dla buga pod IE 7 i 8 - brak zaznaczenia dla 'label img'
  371. if( (navigator.appVersion.indexOf("MSIE 8.")>-1 || navigator.appVersion.indexOf("MSIE 7.")>-1) && navigator.appVersion.indexOf("Windows")>-1 )
  372. {
  373. $("label img").live("click", function() {
  374. $("#" + $(this).parents("label").attr("for")).click();
  375. });
  376. }
  377. */
  378.  
  379.  
  380. function menu_filter_init() {
  381.  
  382. /* Scroll do góry strony po przeładowaniu */
  383. // if ( $('#menu_filter').length ) { $(this).scrollTop(0); }
  384.  
  385. /* Oznacz jako zaznaczony filtr na starcie */
  386. $('#menu_filter div.menu_filter_wrapper input[type=checkbox]').each(function() { mark_active($(this).attr('id')); });
  387. $('#menu_filter div.menu_filter_wrapper input[type=checkbox]').change(function() { mark_active($(this).attr('id')); });
  388.  
  389. /* Wypełnienie formularza na starcie */
  390. filter_fill_form();
  391.  
  392. /* Wysłanie formularza na enter w input[text] */
  393. $('#menu_filter input[type=text]').on('keyup', function(e) {
  394. if (e.which == 13) { filter_submit(); }
  395. });
  396.  
  397. /* Filtr list_type - click */
  398. $('#menu_filter div.filter_item.list_type input[type="checkbox"]').click(function() {
  399. var fID = String($(this).attr('id')).substring(0, String($(this).attr('id')).indexOf('_val'));
  400. //$('a.filter_submit[data-filter="'+fID+'"]').show('fast');
  401. $('#filter_buttons').show('fast');
  402. var fvt = new Array();
  403. $('#'+fID+'_content input[type="checkbox"]').each(function() {
  404. if ( $(this).is(':checked') ) { fvt.push($(this).val()); }
  405. });
  406. $('#'+fID+'_form').val(fvt);
  407. if ( $(this).attr('id') != 'filter_price_range_from' && $(this).attr('id') != 'filter_price_range_to' && $(this).attr('id') != 'filter_text_input' && $(this).attr('id') != 'filter_date_datepicker' && $(this).attr('data-filter') != 'filter_date_option' ) {
  408. filter_prepare_ajaxfilter();
  409. }
  410. });
  411.  
  412. /* Filtr dual_type - click */
  413. $('#menu_filter div.filter_item.dual_type input').click(function() {
  414. if ( $(this).is(':checked') ) { $('#'+$(this).attr('id')+'_form').val('y'); }
  415. else { $('#'+$(this).attr('id')+'_form').val('') }
  416. //$('a.filter_submit[data-filter="filter_dual"]').show('fast');
  417. $('#filter_buttons').show('fast');
  418. filter_prepare_ajaxfilter();
  419. });
  420.  
  421. /* Filtr text - click */
  422. $('#filter_text_input').focus(function() { if ( $(this).val() == $(this).attr('data-filter') ) { $(this).val('');} });
  423. $('#filter_text_submit').click(function() { filter_submit(); });
  424. $('#filter_text_input').keyup(function() { $('#filter_text_form').val($('#filter_text_input').val()); });
  425.  
  426. /* Filtr - range */
  427. $('#menu_filter a.filter_submit_range').click (function() {
  428.  
  429. $('#menu_filter div.filter_range').each(function() {
  430. //$('#'+$(this).attr('data-filter').replace('_range','_content')+' input[type="checkbox"]').prop('checked',false);
  431. var fV = $('#'+$(this).attr('data-filter')+'_range_from').val()+'-'+$('#'+$(this).attr('data-filter')+'_range_to').val();
  432. if ( fV != '-' ) { $('#'+$(this).attr('data-filter')+'_form').val(fV); }
  433. });
  434.  
  435. filter_submit();
  436. });
  437.  
  438. /* Filter - data dodania */
  439. if ( $('#filter_date').length ) {
  440. $('#filter_date input[type="checkbox"]').click(function() {
  441. var tP = $(this).prop('checked');
  442. $('#filter_date input').prop('checked',false);
  443. if ( !tP ) { $(this).prop('checked',false); } else { $(this).prop('checked',true); }
  444. if ( $(this).attr('id') != 'filter_date_calendar_picker' ) {
  445. $('#filter_date_calendar_picker').val('');
  446. $(this).parents('ul').find('span.filter_calendar_from').hide();
  447. $('#filter_date_datepicker').val(txt_66412_008_001);
  448. }
  449. filter_prepare_ajaxfilter();
  450. });
  451.  
  452. $('.filter_datepicker').datepicker({
  453. onSelect: function(dateText, inst) {
  454. $(this).parent().find('span.filter_calendar_from').show();
  455. $('#'+$(this).attr('id').replace('_datepicker','')+' input[type="checkbox"]').prop('checked',false);
  456. $(this).parent().find('input.filter_calendar').val($(this).val());
  457. $(this).parent().find('input.filter_calendar').prop('checked',true);
  458. $('#'+$(this).attr('id').replace('_datepicker','_submit')).show('fast');
  459. },
  460. dateFormat: iaical_dateFormat,
  461. dayNamesMin: iaical_daysShort,
  462. monthNames: iaical_monthNames,
  463. nextText: iaical_monthNext,
  464. firstDay: iaical_firstDay,
  465. prevText: iaical_monthPrev
  466. });
  467.  
  468. $('.filter_datepicker').datepicker( "option", "dateFormat", "yy-mm-dd" );
  469. datepicker_min_year = parseInt(datepicker_min.substring(0, 4)); datepicker_min_month = parseInt(datepicker_min.substring(5, 7)); datepicker_min_day = parseInt(datepicker_min.substring(8, 10));
  470. datepicker_max_year = parseInt(datepicker_max.substring(0, 4)); datepicker_max_month = parseInt(datepicker_max.substring(5, 7)); datepicker_max_day = parseInt(datepicker_max.substring(8, 10));
  471. var minDate = $( ".filter_datepicker" ).datepicker( "option", "minDate" );
  472. $( ".filter_datepicker" ).datepicker( "option", "minDate", new Date(datepicker_min_year, datepicker_min_month - 1, datepicker_min_day) );
  473. var maxDate = $( ".filter_datepicker" ).datepicker( "option", "maxDate" );
  474. $( ".filter_datepicker" ).datepicker( "option", "maxDate", new Date(datepicker_max_year, datepicker_max_month - 1, datepicker_max_day) );
  475. $('.filter_datepicker').each(function() { $(this).val($(this).attr('data-filter')); });
  476. }
  477.  
  478. if ( $('#menu_filter').length ) {
  479. $('#ui-datepicker-div a').live('click', function() { filter_prepare_ajaxfilter(); });
  480. }
  481. /* /Filter - data dodania */
  482.  
  483. /* Ukrycie filtrów oznaczonych jak ukryte */
  484. get_filter_cookie();
  485.  
  486. /* Button zastosuj - przypisanie na starcie */
  487. //show_options();
  488. $('a.filter_submit').click(function() { filter_submit(); });
  489. $('a.show_all').click(function() { filter_showall($(this)); });
  490.  
  491. /* Pokaż/Ukryj filtr - click */
  492. $('#menu_filter a.filter_toggle').click(function() {
  493.  
  494. if ( $(this).hasClass('active') ) {
  495. $(this).removeClass('active');
  496. $('#'+$(this).attr('href').substring(8)).slideToggle('fast', function(){$('body').resize()});
  497. set_filter_cookie();
  498. if ( $('#'+$(this).attr('id').replace('_toggle','_content')).hasClass('filter_gfxonly') ) { align_filter_gfx($(this).attr('id').replace('_toggle','')); }
  499. } else {
  500. $(this).addClass('active');
  501. $('#'+$(this).attr('href').substring(8)).slideToggle('fast', function(){$('body').resize()});
  502. set_filter_cookie();
  503. }
  504.  
  505. return false;
  506. });
  507.  
  508. /* Filtr gfxonly */
  509. $('#menu_filter div.filter_item.list_type label').click(function() {
  510. if ( !$('#'+$(this).attr('for').replace('_val','_')+'_box').hasClass('disabled') ) {
  511. if ( $('#'+$(this).attr('for')).prop('checked') ) { $(this).removeClass('active'); }
  512. else { $(this).addClass('active'); }
  513. }
  514. });
  515. simple_tooltip("div.filter_gfxonly img","filter_tooltip");
  516.  
  517. /* Zastosuj wybrane filtry - click */
  518. $('#filter_buttons a.filters_submit').click(function() { filter_submit(); });
  519.  
  520. /* Filter top */
  521. // if ( $.cookie("filterTop" )){ $(window).scrollTop($.cookie("filterTop")); $.cookie("filterTop", null); }
  522. $('#menu_filter form').submit(function(){ $.cookie("filterTop", $(window).scrollTop()); return true; });
  523. /* /Filter top */
  524.  
  525. /*suwaczek*/
  526. if(v66412_suwaczek_on)
  527. $("#slider-price").slider({
  528. range: true,
  529. min: parseInt($("#min_price_start").val()),
  530. max: parseInt($("#max_price_start").val()),
  531. values: [parseInt($("#min_price_start").val()), parseInt($("#max_price_start").val())],
  532. slide: function(event, ui) {
  533. $("#filter_price_range_from").val(ui.values[0]);
  534. $("#filter_price_range_to").val(ui.values[1]);
  535. },
  536.  
  537. stop: function(event, ui) {
  538.  
  539. $("#filter_price_range_from").val(ui.values[0]);
  540. $("#filter_price_range_to").val(ui.values[1]);
  541. }
  542. });
  543.  
  544.  
  545. }
  546.  
  547.  
  548.  
  549. $(window).load(function() {
  550. /* Wyrównanie - gfxonly i gfx */
  551. align_filter_gfx();
  552.  
  553. /* Scroll do góry strony po przeładowaniu */
  554. // if ( $('#menu_filter').length ) { $(this).scrollTop(0); }
  555. });
  556.  
  557. /*** JS - V5 END ***/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement