/*----------------------------- wish_list -----------------------------*/ (($) => { $.wishList = class{ defaults = { shopKey:'alamode', domain:'www.copy98k.com', ssldomain:'www.copy98k.com', nameSpace:'wish_list', funcCallbackGetStart:(callback) => { callback(); }, funcCallbackGetEnd:( itemCodeList, callback ) => { callback(); }, funcCallbackAddStart:( itemCode, callback ) => { callback(); }, funcCallbackAddEnd:(itemCode) => {}, funcCallbackRemoveStart:( itemCode, callback ) => { callback(); }, funcCallbackRemoveEnd:(itemCode) => {} }; constructor(options){ this.configs = $.extend( {}, this.defaults, options ); } funcGetDevice = () => { const u = navigator.userAgent.toLowerCase(); return ( u.indexOf('iphone') > 0 || u.indexOf('ipod') > 0 || u.indexOf('android') > 0 && u.indexOf('mobile') > 0 )?'sp':'pc'; } funcAddAttrDataWishList0 = (itemCodeList) => { const nameSpace = this.configs.nameSpace, eleWishList = $('.' + this.configs.nameSpace); eleWishList.each(function(){ const attrDataIitemCode = $(this).attr('data-' + nameSpace + '_item_code'); $(this).attr( 'data-' + nameSpace + '_exists', $.inArray( attrDataIitemCode, itemCodeList ) !== -1?'1':'0' ); }); } funcAddAttrDataWishList1 = ( itemCode, value ) => { const eleWishList = $('.' + this.configs.nameSpace + '_' + itemCode); eleWishList.attr( 'data-' + this.configs.nameSpace + '_exists', value ); } funcGetWishList = (callback) => { let itemCodeList = []; const funcExecuteAjax = (page) => { $.ajax({ type:'GET', url:'/fs/' + this.configs.shopKey + '/WishList.html?pageno=' + page, dataType:'html', error:( jqXHR, textStatus, errorThrown ) => { console.log('wishList:error => ajax:' + textStatus); this.funcAddAttrDataWishList0(itemCodeList); this.configs.funcCallbackGetEnd( itemCodeList, callback ); }, success:( response, textStatus, jqXHR ) => { const shopKey = this.configs.shopKey; switch(this.funcGetDevice()){ case 'pc': $(response).find('.FS2_WishListDetail_td a').each(function(){ const itemCode = $(this).attr('href').match(eval('/\\/fs\\/' + shopKey + '\\/([a-z0-9_\-]+)$/')); if(itemCode === null) return true; itemCodeList.push(itemCode[1]); }); this.funcAddAttrDataWishList0(itemCodeList); this.configs.funcCallbackGetEnd( itemCodeList, callback ); break; case 'sp': $(response).find('.FS2_WishListContents').each(function(){ const eleAnchor = $(this).find('.FS2_Item_Name:eq(0) a:eq(0)'); if(!eleAnchor[0]) return true; const itemCode = eleAnchor.attr('href').match(eval('/\\/fs\\/' + shopKey + '\\/([a-z0-9_\-]+)$/')); if(itemCode === null) return true; itemCodeList.push(itemCode[1]); }); let flagNextPage = false; const nextPage = (parseInt(page) + 1).toString(), eleFs2PagenationListLi = $(response).find('.FS2_pagenationList:eq(0) > li'); eleFs2PagenationListLi.each(function(){ const eleAnchor = $(this).find('a').eq(0); if(!eleAnchor[0]) return true; const attrHrefAnchor = eleAnchor.attr('href'); if(typeof attrHrefAnchor !== 'string') return true; const splitAttrHrefAnchor = attrHrefAnchor.split('pageno='); if( typeof splitAttrHrefAnchor[1] !== 'string' || splitAttrHrefAnchor[1] !== nextPage ) return true; flagNextPage = true; funcExecuteAjax(nextPage); return false; }); if(flagNextPage === false){ this.funcAddAttrDataWishList0(itemCodeList); this.configs.funcCallbackGetEnd( itemCodeList, callback ); } break; } } }); }; this.configs.funcCallbackGetStart(() => { funcExecuteAjax('1'); }); } funcAddWishList = (itemCode) => { this.configs.funcCallbackAddStart( itemCode, () => { FS2.addWishList({ shopKey:this.configs.shopKey, domain:this.configs.domain, ssldomain:this.configs.ssldomain, data:{ goods_url:itemCode, url:encodeURIComponent('/fs/' + this.configs.shopKey + '/' + itemCode) }, done:() => { this.funcAddAttrDataWishList1( itemCode, '1' ); this.configs.funcCallbackAddEnd(itemCode); } }); } ); } funcRemoveWishList = (itemCode) => { this.configs.funcCallbackRemoveStart( itemCode, () => { FS2.removeWishList({ shopKey:this.configs.shopKey, domain:this.configs.domain, ssldomain:this.configs.ssldomain, data:{ goods_url:itemCode, url:encodeURIComponent('/fs/' + this.configs.shopKey + '/' + itemCode) }, done:() => { this.funcAddAttrDataWishList1( itemCode, '0' ); this.configs.funcCallbackRemoveEnd(itemCode); } }); } ); } funcAddEventListener = () => { const nameSpace = this.configs.nameSpace, funcAddWishList = this.funcAddWishList, funcRemoveWishList = this.funcRemoveWishList, eleWishList = $('.' + nameSpace); eleWishList.each(function(){ $(this).on({ 'click':function(){ const dataIitemCode = $(this).attr('data-' + nameSpace + '_item_code'), dataExists = $(this).attr('data-' + nameSpace + '_exists'); switch(dataExists){ case '0': funcAddWishList(dataIitemCode); break; case '1': funcRemoveWishList(dataIitemCode); break; } } }); }); } //実行用メソッド execute = () => { this.funcGetWishList(this.funcAddEventListener); } }; })(jQuery); /*----------------------------- /wish_list -----------------------------*/