$(function(){ //AJAXでダウンロード表示 $(document).on('change', '#main.download .select select, #main.download .select input', function(){ _maker = $('select#maker option:selected').val(); _products = $('select#products option:selected').val(); _solution = $('select#solution option:selected').val(); _s = $('input#s').val(); _dl = $('#tgt.select').attr('data-dw'); pn = 1; godl(_maker,_products,_solution,_s,_dl,pn); }); /**page nation**/ $(document).stop().on('click','#pagenation .pn span',function (e) { e.preventDefault(); _maker = $('select#maker option:selected').val(); _products = $('select#products option:selected').val(); _solution = $('select#solution option:selected').val(); _s = $('input#s').val(); _dl = $('#tgt.select').attr('data-dw'); pn = $(this).attr('data-page'); var target = $('#tgt'); var position = target.offset().top; $('body,html').animate({scrollTop:position}, 500, 'swing'); godl(_maker,_products,_solution,_s,_dl,pn); }); function godl(_maker,_products,_solution,_s,_dl,pn){ if(!_maker && !_products && !_solution && !_s ){ $('#main.download table#results tbody').empty(); $('#main.download div#pagenation').empty(); $('#main.download #counts').empty(); $('#main.download #counts').append('0件が見つかりました。'); return false; } $('#main.download #counts').empty(); $('#main.download #counts').append('検索中です・・・'); $.ajax({ type: 'POST', url: ajaxurl, data: { 'maker' : _maker, 'products' : _products, 'solution' : _solution, 's' : _s, 'dl': _dl, 'pn' : pn, 'action' : 'download', }, success: function( response ){ // jsonData受け取る jsonData = JSON.parse( response ); if ( response == 'false' || !jsonData[0]) { // 投稿がなかったら $('#main.download table#results tbody').empty(); $('#main.download div#pagenation').empty(); $('#main.download #counts').empty(); $('#main.download #counts').append('0件が見つかりました。'); // wrapperなども含めて初期化前の状態に戻す //$('#results_wrapper').remove(); // テーブルごと削除 $('#table-container').empty(); // 空の新しいテーブルを追加(構造を再構築) if($('#results.wp').length){ $('#table-container').append(`
カタログ画像 タイトル メーカー 製品カテゴリ ソリューション
カテゴリ
技術コラム ダウンロード
`); }else{ $('#table-container').append(`
種別 タイトル メーカー 製品カテゴリ ダウンロード
`); } } else { jsonData = JSON.parse( response ); if($('#results.wp').length){ //初期化   $('#results').DataTable().destroy(); $('#main.download table#results tbody').empty(); $('#main.download table#results tbody').append(jsonData[0]); $('#main.download #counts').empty(); $('#main.download #counts').append(jsonData[2] + '件が見つかりました。'); let dtbl = $('#results').DataTable({ "language": { "url": "/wp/wp-content/themes/kmecs/js/ja.json" } }); dtbl.on('page.dt', function () { $('html, body').animate({ scrollTop: $('#results').offset().top - 150 }, 300); }); }else{ //初期化   $('#results').DataTable().destroy(); $('#main.download table#results tbody').empty(); $('#main.download table#results tbody').append(jsonData[0]); $('#main.download #counts').empty(); $('#main.download #counts').append(jsonData[2] + '件が見つかりました。'); let dtbl = $('#results').DataTable({ "language": { "url": "/wp/wp-content/themes/kmecs/js/ja.json" } }); dtbl.on('page.dt', function () { $('html, body').animate({ scrollTop: $('#results').offset().top - 150 }, 300); }); /* $('#main.download table#results tbody').empty(); $('#main.download table#results tbody').append(jsonData[0]); $('#main.download div#pagenation').empty(); $('#main.download div#pagenation').append(jsonData[1]); $('#main.download #counts').empty(); $('#main.download #counts').append(jsonData[2] + '件が見つかりました。'); */ } } } }); return false; } }); $(window).on('load',function(){ }); $(window).on('resize',function () { }); $(window).on('orientationchange', function(){ }); function setwp(_maker){ $('select#maker').val(_maker); var target = $('#dlinfo'); var mrg = $("#f-header").outerHeight() + 10; var position = target.offset().top - mrg; $('body,html').animate({scrollTop:position}, 500, 'swing'); _products = ''; _solution = ''; _s = $('input#s').val(); _dl = 'wp'; pn = 1; if(!_maker && !_products && !_solution && !_s ){ $('#main.download table#results tbody').empty(); $('#main.download div#pagenation').empty(); $('#main.download #counts').empty(); $('#main.download #counts').append('0件が見つかりました。'); return false; } $('#main.download #counts').empty(); $('#main.download #counts').append('検索中です・・・'); $.ajax({ type: 'POST', url: ajaxurl, data: { 'maker' : _maker, 'products' : _products, 'solution' : _solution, 's' : _s, 'dl': _dl, 'pn' : pn, 'action' : 'download', }, success: function( response ){ // jsonData受け取る jsonData = JSON.parse( response ); if ( response == 'false' || !jsonData[0]) { // 投稿がなかったら $('#main.download table#results tbody').empty(); $('#main.download div#pagenation').empty(); $('#main.download #counts').empty(); $('#main.download #counts').append('0件が見つかりました。'); } else { jsonData = JSON.parse( response ); if($('#results.wp').length){ $('#main.download table#results tbody').empty(); $('#main.download table#results tbody').append(jsonData[0]); $('#main.download #counts').empty(); $('#main.download #counts').append(jsonData[2] + '件が見つかりました。'); if ( $.fn.dataTable.isDataTable('#results') ) { $('#results').DataTable().destroy(); } $('#results').DataTable({ "language": { "url": "/wp/wp-content/themes/kmecs/js/ja.json" } }); }else{ $('#main.download table#results tbody').empty(); $('#main.download table#results tbody').append(jsonData[0]); $('#main.download div#pagenation').empty(); $('#main.download div#pagenation').append(jsonData[1]); $('#main.download #counts').empty(); $('#main.download #counts').append(jsonData[2] + '件が見つかりました。'); } } } }); return false; }