Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $.fn.textWidth = function(text, font) {
- if (!$.fn.textWidth.fakeEl) $.fn.textWidth.fakeEl = $('<span>').hide().appendTo(document.body);
- $.fn.textWidth.fakeEl.text(text || this.val() || this.text()).css('font', font || this.css('font'));
- return $.fn.textWidth.fakeEl.width();
- };
- $(function(){
- $('#filter_price_range_from, #filter_price_range_to').keyup(function(){
- var value = $(this).val();
- $(this).val($(this).val().replace(/[^0-9]/g, ''));
- value = $(this).val();
- var in_width = $.fn.textWidth(value, '13px Arial');
- $(this).width(in_width+12);
- })
- $('#filter_price_range_from, #filter_price_range_to').keyup();
- })
- app_shop.run(function(){
- $('._mobile #menu_filter h3').live('click',function(){
- $this = $(this);
- $this.next().slideToggle(function(){
- if($this.next().is(':visible')){
- $this.addClass('openList');
- }else{
- $this.removeClass('openList');
- }
- });
- });
- app_shop.vars.sendFilter = false;
- $('#menu_filter div.filter_item.list_type input, #menu_filter div.filter_item.dual_type input').click(function(){
- app_shop.vars.sendFilter = true;
- })
- $('._mobile #filter_form').live('submit',function(){
- if(!app_shop.vars.sendFilter){
- $('html').removeClass('filter_on');
- }
- return app_shop.vars.sendFilter;
- });
- $('#select_top_sort').removeAttr('onchange');
- $('#select_top_sort').live('change',function(){
- if(app_shop.vars.view == 1){
- $.getJSON('/settings.php?sort_order=' + $(this).val());
- app_shop.vars.sendFilter = true;
- }else{
- $(this).parents('form').submit();
- }
- })
- },'all','#menu_filter');
- /*** JS - V5 ***/
- /* Deklaracja callback */
- var filtering_callback = function() { /* void */ }
- /* callback po tym jak form został uzupełniony/a , czyli po click a przed wysłaniem AJAX*/
- var filtering_callback_click = function() { /* void */ }
- /* filtrownie V5 - ajax */
- var xhr = '';
- var v66412_ajax_off = <iai:variable vid="v66412_ajax_off" description="true - brak AJAX" />
- var v66412_suwaczek_on = <iai:variable vid="v66412_suwaczek_on" description="true - włącz suwak" />
- var filter_active_ajax = function(global, global_status, filter_id) {
- if ( !global ) {
- if ( $('#'+filter_id+'_toggle').is(':visible') ) {
- $('#'+filter_id+'_toggle').hide(); $('#'+filter_id+'_loader').show();
- } else {
- $('#'+filter_id+'_toggle').show(); $('#'+filter_id+'_loader').hide();
- }
- }
- else {
- if ( global_status == true ) {
- $('a.filter_toggle[id != "filter_text_toggle"]').hide(); $('span.filter_loader[id != "filter_text_loader"]').show();
- } else {
- $('a.filter_toggle[id != "filter_text_toggle"]').show(); $('span.filter_loader[id != "filter_text_loader"]').hide();
- }
- }
- }
- var filter_response_ajax = function(xml) {
- // dla każdego filtra
- //for (n=0;filterJSON.filter.length;n++) {
- $('navigation>filtering>filter', xml).each(function(){
- var $this = $(this);
- var filter_id = $this.attr('id').replace('[','').replace(']','');
- if ( $('#'+filter_id).length && filter_id != 'filter_text' ) {
- $this.find('>item').each(function(){
- var $this = $(this);
- var quantity = $this.attr('quantity');
- var value = $this.attr('value');
- if ( quantity ) {
- if ( quantity > 0 ) {
- // oznacz jako dostępny z quantity
- $('#'+filter_id+'_val'+value+'_quantity').show();
- $('#'+filter_id+'_val'+value+'_quantity span.filter_quantity_value').html(quantity);
- $('#'+filter_id+'_val'+value).removeAttr('disabled');
- $('#'+filter_id+'_'+value+'_box').removeClass('disabled');
- }else{
- // oznacz jako dostępny z quantity == 0
- $('#'+filter_id+'_val'+value+'_quantity').show();
- $('#'+filter_id+'_val'+value+'_quantity span.filter_quantity_value').html(quantity);
- $('#'+filter_id+'_val'+value).attr('disabled','disabled');
- $('#'+filter_id+'_'+value+'_box').addClass('disabled');
- }
- }else{
- // oznacz jako dostępny bez quantity
- $('#'+filter_id+'_val'+value+'_quantity').hide();
- $('#'+filter_id+'_val'+value).removeAttr('disabled');
- $('#'+filter_id+'_'+value+'_box').removeClass('disabled');
- }
- });
- $('div.filter_item.list_type').each(function(){
- if($(this).find('li').not('.disabled').length){
- $(this).find('h3 a').removeClass('active');
- }else{
- $(this).find('h3 a').addClass('active');
- }
- });
- filter_active_ajax(true, false);
- }else{
- // nie ma takiego filtra
- }
- })
- }
- var filter_prepare_ajaxfilter = function() {
- filter_fill_form();
- if(v66412_ajax_off==='true'){filter_submit();return false;}
- var filter_data = $('#filter_form').serialize();
- var filter_url = $('#filter_form').attr('action');
- if($('#viewType').width() > 1) loadAjaxFilter(xhr, filter_data, filter_url);
- //xhr = filter_send_ajaxfilter(xhr, filter_data);
- //filter_active_ajax(true, true);
- }
- var stateObj = {foo: "bar"};
- function change_my_url(url) {
- if (history.pushState) {
- history.pushState(stateObj, "", url);
- }
- }
- function fadeLoaderOnOff(czy) {
- if(czy) $('#content').addClass('load-content');
- else $('#content').removeClass('load-content');
- }
- var xhr = '';
- function loadAjaxFilter(xhr, dataFilter, urlFilter) {
- fadeLoaderOnOff(1);
- xhr = xhr;
- urlFilter = urlFilter.replace('lang=pol&', '');
- if (xhr && xhr.readystate != 4) xhr.abort();
- xhr = $.ajax({url: urlFilter, data: dataFilter, timeout: 15000,
- success: function (data, textStatus, jqXHR) {
- if(jqXHR.status == 200) {
- $('#layout > #menu_buttons3').remove();
- $('#content').html($(data).find('#content > *'));
- $('.search_page #layout').prepend($('#menu_buttons3'));
- app_shop.fn.init_mb11_bx();
- app_shop.fn.init_fs();
- $('img.b-lazy').parents('a').addClass('loading');
- var bLazy = new Blazy({
- breakpoints: [{
- width: 420, src: 'data-src-small'
- }], success: function(element){
- setTimeout(function(){
- $(element).parents('.loading').removeClass('loading');
- }, 200);
- }
- });
- $('#search .align_row').iai_align();
- $('#search').wrappTableLayout({numCol: app_shop.vars.view==1?2:3});
- change_my_url(this.url);
- fadeLoaderOnOff(0);
- }
- }, error: function (data) {
- window.location.href = this.url;
- fadeLoaderOnOff(0);
- }});
- return xhr;
- }
- var filter_send_ajaxfilter = function(xhr, filter_data) {
- xhr = xhr;
- if(xhr && xhr.readystate != 4){
- xhr.abort();
- filter_active_ajax(true, false);
- }
- xhr = $.ajax({
- type: 'GET',
- //timeout: 8000,
- url: '/search.php?'+filter_data+'&getProductXML=true&xmlType=filtering',
- //dataType: 'xml',
- dataType: 'text',
- success: function(xml){
- filter_response_ajax(xml);
- },
- error: function(xml, sTextStatus, oErrorThrown) {
- filter_active_ajax(true, false);
- }
- });
- return xhr;
- }
- /* /filtrownie V5 - ajax */
- /* Literały */
- var txt_66412_008_001 = <iai:variable vid="66412_008_001" description="wybierz datę" />
- /* Wyrównanie */
- $.fn.setOneHeight=function(){var a=0;$(this).each(function(){if($(this).height()>a){a=$(this).height();}});$(this).css('height',a);}
- var align_filter_gfx = function(id) {
- if ( id ) { $('#'+id+' li').setOneHeight(); }
- else {
- $('#menu_filter div.filter_gfxonly').each(function() { if ( $(this).is(':visible') ) {$(this).find('li').setOneHeight(); } });
- }
- }
- /* Wyrównanie */
- function set_filter_cookie() {
- var filter_hidden_list = new Array();
- $('#menu_filter a.filter_toggle.active').each(function() {
- filter_hidden_list.push($(this).attr('href').substring(8));
- });
- $.cookie('filter_hidden', '', { expires: 355 });
- $.cookie('filter_hidden', filter_hidden_list, { expires: 355 });
- }
- function get_filter_cookie() {
- var flistA = $.cookie('filter_hidden');
- if ( !!flistA ) {
- var flist = flistA.split(',');
- for(var i=0;i < flist.length;i++) {
- $('#menu_filter a.filter_toggle[href="#toggle_'+flist[i]+'"]').addClass('active');
- $('#'+flist[i]).hide();
- }
- }
- }
- /* /Ukrywanie filtrów */
- /* Button - zastosuj */
- var show_options = function() {
- $('#menu_filter div.list_type, #menu_filter div.dual_type').each(function() {
- if ( $(this).find('input').is(':checked') ) {
- //$('a.filter_submit[data-filter="'+$(this).attr('id')+'"]').show('fast');
- $('#filter_buttons').show('fast');
- }
- });
- }
- /* /Button - zastosuj */
- /* Button - pokaż wszystkie */
- var filter_showall = function(obj) {
- if ( obj.hasClass('active') ) {
- obj.removeClass('active');
- obj.html(filter_pokaz);
- $('#'+obj.attr('data-filter')+' li.filterhidden').removeClass('showhidden');
- } else {
- obj.addClass('active');
- obj.html(filter_ukryj);
- $('#'+obj.attr('data-filter')+' li.filterhidden').addClass('showhidden');
- }
- }
- /* /Button - pokaż wszystkie */
- /* Wypełnienie formularza na starcie */
- var filter_fill_form = function() {
- /* list_type */
- $('#menu_filter div.filter_item.list_type').each(function() {
- var fID = $(this).attr('id');
- var fvt = new Array();
- $('#'+fID+'_content input[type=checkbox]:checked').each(function() {
- if ($(this).attr('disabled') != 'disabled' ) { fvt.push($(this).val()); }
- });
- $('#'+fID+'_form').val(fvt);
- });
- if(!$('#filter_price_content input[type="checkbox"]:checked').size()){
- /* range */
- $('#menu_filter div.filter_range').each(function() {
- var fV = $('#'+$(this).attr('data-filter')+'_range_from').val()+'-'+$('#'+$(this).attr('data-filter')+'_range_to').val();
- if ( fV != '-' ) { $('#'+$(this).attr('data-filter')+'_form').val(fV); }
- });
- }
- /* dual_type */
- $('#menu_filter div.filter_item.dual_type input').each(function() {
- if ( $(this).is(':checked') && $(this).attr('disabled') != 'disabled') { $('#'+$(this).attr('id')+'_form').val('y'); }
- else { $('#'+$(this).attr('id')+'_form').val('') }
- });
- /* text */
- if ( $('#filter_text_input').length && $('#filter_text_input').val() != $('#filter_text_input').attr('data-filter') ) { $('#filter_text_form').val($('#filter_text_input').val()); }
- filtering_callback_click();
- }
- /* /Wypełnienie formularza na starcie */
- /* Wysłanie formularza */
- var filter_submit = function() {
- //Wypełnienie formularza
- filter_fill_form();
- //Wysłanie formularza
- $('#filter_form').submit();
- }
- /* /Wysłanie formularza */
- /* oznaczenie aktywnych filtrów na starcie */
- var mark_active = function(obj) {
- if ( $('#filter_dual #'+obj).length ) {
- obj_box = obj+'_y_box';
- if ( $('#'+obj).is(':checked') ) { $('#'+obj_box).addClass('enabled'); } else { $('#'+obj_box).removeClass('enabled'); }
- } else {
- obj_box = obj.replace('_val','_')+'_box';
- if ( $('#'+obj).is(':checked') ) { $('#'+obj_box).addClass('enabled'); } else { $('#'+obj_box).removeClass('enabled'); }
- }
- }
- /* Korekta dla buga pod IE 7 i 8 - brak zaznaczenia dla 'label img'
- if( (navigator.appVersion.indexOf("MSIE 8.")>-1 || navigator.appVersion.indexOf("MSIE 7.")>-1) && navigator.appVersion.indexOf("Windows")>-1 )
- {
- $("label img").live("click", function() {
- $("#" + $(this).parents("label").attr("for")).click();
- });
- }
- */
- function menu_filter_init() {
- /* Scroll do góry strony po przeładowaniu */
- // if ( $('#menu_filter').length ) { $(this).scrollTop(0); }
- /* Oznacz jako zaznaczony filtr na starcie */
- $('#menu_filter div.menu_filter_wrapper input[type=checkbox]').each(function() { mark_active($(this).attr('id')); });
- $('#menu_filter div.menu_filter_wrapper input[type=checkbox]').change(function() { mark_active($(this).attr('id')); });
- /* Wypełnienie formularza na starcie */
- filter_fill_form();
- /* Wysłanie formularza na enter w input[text] */
- $('#menu_filter input[type=text]').on('keyup', function(e) {
- if (e.which == 13) { filter_submit(); }
- });
- /* Filtr list_type - click */
- $('#menu_filter div.filter_item.list_type input[type="checkbox"]').click(function() {
- var fID = String($(this).attr('id')).substring(0, String($(this).attr('id')).indexOf('_val'));
- //$('a.filter_submit[data-filter="'+fID+'"]').show('fast');
- $('#filter_buttons').show('fast');
- var fvt = new Array();
- $('#'+fID+'_content input[type="checkbox"]').each(function() {
- if ( $(this).is(':checked') ) { fvt.push($(this).val()); }
- });
- $('#'+fID+'_form').val(fvt);
- 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' ) {
- filter_prepare_ajaxfilter();
- }
- });
- /* Filtr dual_type - click */
- $('#menu_filter div.filter_item.dual_type input').click(function() {
- if ( $(this).is(':checked') ) { $('#'+$(this).attr('id')+'_form').val('y'); }
- else { $('#'+$(this).attr('id')+'_form').val('') }
- //$('a.filter_submit[data-filter="filter_dual"]').show('fast');
- $('#filter_buttons').show('fast');
- filter_prepare_ajaxfilter();
- });
- /* Filtr text - click */
- $('#filter_text_input').focus(function() { if ( $(this).val() == $(this).attr('data-filter') ) { $(this).val('');} });
- $('#filter_text_submit').click(function() { filter_submit(); });
- $('#filter_text_input').keyup(function() { $('#filter_text_form').val($('#filter_text_input').val()); });
- /* Filtr - range */
- $('#menu_filter a.filter_submit_range').click (function() {
- $('#menu_filter div.filter_range').each(function() {
- //$('#'+$(this).attr('data-filter').replace('_range','_content')+' input[type="checkbox"]').prop('checked',false);
- var fV = $('#'+$(this).attr('data-filter')+'_range_from').val()+'-'+$('#'+$(this).attr('data-filter')+'_range_to').val();
- if ( fV != '-' ) { $('#'+$(this).attr('data-filter')+'_form').val(fV); }
- });
- filter_submit();
- });
- /* Filter - data dodania */
- if ( $('#filter_date').length ) {
- $('#filter_date input[type="checkbox"]').click(function() {
- var tP = $(this).prop('checked');
- $('#filter_date input').prop('checked',false);
- if ( !tP ) { $(this).prop('checked',false); } else { $(this).prop('checked',true); }
- if ( $(this).attr('id') != 'filter_date_calendar_picker' ) {
- $('#filter_date_calendar_picker').val('');
- $(this).parents('ul').find('span.filter_calendar_from').hide();
- $('#filter_date_datepicker').val(txt_66412_008_001);
- }
- filter_prepare_ajaxfilter();
- });
- $('.filter_datepicker').datepicker({
- onSelect: function(dateText, inst) {
- $(this).parent().find('span.filter_calendar_from').show();
- $('#'+$(this).attr('id').replace('_datepicker','')+' input[type="checkbox"]').prop('checked',false);
- $(this).parent().find('input.filter_calendar').val($(this).val());
- $(this).parent().find('input.filter_calendar').prop('checked',true);
- $('#'+$(this).attr('id').replace('_datepicker','_submit')).show('fast');
- },
- dateFormat: iaical_dateFormat,
- dayNamesMin: iaical_daysShort,
- monthNames: iaical_monthNames,
- nextText: iaical_monthNext,
- firstDay: iaical_firstDay,
- prevText: iaical_monthPrev
- });
- $('.filter_datepicker').datepicker( "option", "dateFormat", "yy-mm-dd" );
- 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));
- 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));
- var minDate = $( ".filter_datepicker" ).datepicker( "option", "minDate" );
- $( ".filter_datepicker" ).datepicker( "option", "minDate", new Date(datepicker_min_year, datepicker_min_month - 1, datepicker_min_day) );
- var maxDate = $( ".filter_datepicker" ).datepicker( "option", "maxDate" );
- $( ".filter_datepicker" ).datepicker( "option", "maxDate", new Date(datepicker_max_year, datepicker_max_month - 1, datepicker_max_day) );
- $('.filter_datepicker').each(function() { $(this).val($(this).attr('data-filter')); });
- }
- if ( $('#menu_filter').length ) {
- $('#ui-datepicker-div a').live('click', function() { filter_prepare_ajaxfilter(); });
- }
- /* /Filter - data dodania */
- /* Ukrycie filtrów oznaczonych jak ukryte */
- get_filter_cookie();
- /* Button zastosuj - przypisanie na starcie */
- //show_options();
- $('a.filter_submit').click(function() { filter_submit(); });
- $('a.show_all').click(function() { filter_showall($(this)); });
- /* Pokaż/Ukryj filtr - click */
- $('#menu_filter a.filter_toggle').click(function() {
- if ( $(this).hasClass('active') ) {
- $(this).removeClass('active');
- $('#'+$(this).attr('href').substring(8)).slideToggle('fast', function(){$('body').resize()});
- set_filter_cookie();
- if ( $('#'+$(this).attr('id').replace('_toggle','_content')).hasClass('filter_gfxonly') ) { align_filter_gfx($(this).attr('id').replace('_toggle','')); }
- } else {
- $(this).addClass('active');
- $('#'+$(this).attr('href').substring(8)).slideToggle('fast', function(){$('body').resize()});
- set_filter_cookie();
- }
- return false;
- });
- /* Filtr gfxonly */
- $('#menu_filter div.filter_item.list_type label').click(function() {
- if ( !$('#'+$(this).attr('for').replace('_val','_')+'_box').hasClass('disabled') ) {
- if ( $('#'+$(this).attr('for')).prop('checked') ) { $(this).removeClass('active'); }
- else { $(this).addClass('active'); }
- }
- });
- simple_tooltip("div.filter_gfxonly img","filter_tooltip");
- /* Zastosuj wybrane filtry - click */
- $('#filter_buttons a.filters_submit').click(function() { filter_submit(); });
- /* Filter top */
- // if ( $.cookie("filterTop" )){ $(window).scrollTop($.cookie("filterTop")); $.cookie("filterTop", null); }
- $('#menu_filter form').submit(function(){ $.cookie("filterTop", $(window).scrollTop()); return true; });
- /* /Filter top */
- /*suwaczek*/
- if(v66412_suwaczek_on)
- $("#slider-price").slider({
- range: true,
- min: parseInt($("#min_price_start").val()),
- max: parseInt($("#max_price_start").val()),
- values: [parseInt($("#min_price_start").val()), parseInt($("#max_price_start").val())],
- slide: function(event, ui) {
- $("#filter_price_range_from").val(ui.values[0]);
- $("#filter_price_range_to").val(ui.values[1]);
- },
- stop: function(event, ui) {
- $("#filter_price_range_from").val(ui.values[0]);
- $("#filter_price_range_to").val(ui.values[1]);
- }
- });
- }
- $(window).load(function() {
- /* Wyrównanie - gfxonly i gfx */
- align_filter_gfx();
- /* Scroll do góry strony po przeładowaniu */
- // if ( $('#menu_filter').length ) { $(this).scrollTop(0); }
- });
- /*** JS - V5 END ***/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement