/** * * 最近見た女性 * **/ var girlsRecent = { data_name : "recent", //データ名 load_elem : ".load_recent", //読み込み先 max_len : 30, //保存数 resp : new Responsive(), //common.js Responsive api_url : "/recent/recent.php", /** * api url変える場合のセット */ setApiUrl : function(url){ this.api_url = url return this }, /** * ロードclass名変える場合のセット */ setLoadElem : function(emel){ this.load_elem = emel return this }, isData : function(){ var recent_data = localStorage.getItem(this.data_name); if(recent_data){ return true; } }, /** * データセット */ setRecent : function(shop,girl){ const girl_id = shop + '__' + girl; //localstrage使えるか var ls_check = this.lsCheck(); if(!ls_check){return false;} var strage_data; if(strage_data = this.getRecent()){ var is_girl; //女性がセットされているかチェック is_girl = this.isGirl(strage_data,girl_id); //女性がセットされてなければセット if(!is_girl){ strage_data.unshift(girl_id); const slice_data = strage_data.slice(0,this.max_len); this.setLocalStorage(slice_data); } }else{ //データがなければ新規登録 this.setLocalStorage([girl_id]); } }, //----------------- //setItem //----------------- setLocalStorage : function(data){ 'usr strict'; localStorage.setItem(this.data_name,JSON.stringify(data)); }, //----------------- //get データを取得 //----------------- getRecent : function(){ 'usr strict'; var data = localStorage.getItem(this.data_name); if(data){ return JSON.parse(data); } //return JSON.parse(localStorage.getItem(this.data_name)); }, //----------------- //isGirl 女性が登録されているか //----------------- isGirl : function(data,girl_id){ 'usr strict'; var girl_boole = new Boolean(false); for(var key in data){ if(data[key] === girl_id){ girl_boole = true; break; } } if(girl_boole === true){ return true; } }, //----------------- //ajax データを表示 //----------------- writeRecent : function(){ var strage_data; var that = this; if(strage_data = this.getRecent()){ return new Promise(function(resolve,reject) { var send_data = { mode : "get_recent", data : strage_data }; $.post( that.api_url, send_data, function(result){ $(that.load_elem).html(result); that.deleteMoveData(result); //that.setSlick(); resolve(); } ).fail(function(err){ reject() }); }); } }, //------------------ //setSlick //------------------ setSlick : function(){ $(".recent_slider").slick({ //dots: true, infinite: false, slidesToShow: 9, slidesToScroll: 9, responsive: [ { breakpoint: this.resp.windowL, settings: { slidesToShow: 9, slidesToScroll: 9, infinite: false, } }, { breakpoint: this.resp.windowM, settings: { slidesToShow: 6, slidesToScroll: 6 } }, { breakpoint: this.resp.windowS, settings: { slidesToShow: 4, slidesToScroll:4 } } ] }); }, //------------------ //退店者削除 //------------------ deleteMoveData : function(data){ 'usr strict'; var strage_data = this.getRecent(this.data_name); for(var key in strage_data){ if(data.indexOf(strage_data[key]) === -1){ delete strage_data[key]; } } this.setLocalStorage(strage_data); }, //------------------ //localstrage使えるか //------------------ lsCheck : function(){ 'usr strict'; try{ if(typeof localStorage == 'undefined'){ return false; }else if(window.localStorage){ //detect IE10 and private mode } }catch(e){ return false; } return true; } }