(function($){ $(document).ready(function(){ var varGlobal = { itemCode:'' }, configs = { cookieName:'shopping_list', cookieOption:{ set:{ expires:7, path:'/', secure:true }, unset:{ expires:-1, path:'/', secure:true } } }, funcInit = () => { var mchItemCode = location.href.match(/\/fs\/alamode\/([a-z0-9_\-]+)/); if(mchItemCode === null){ console.log('error:shopping list => get url item code'); funcDestructor(); return false; } varGlobal.itemCode = mchItemCode[1]; funcPutHtml(); funcAddEventListener(); funcAddPlugin(); funcDestructor(); }, funcDestructor = () => { funcInit = funcConfirmDevice = funcPutHtml = funcAddEventListener = funcDestructor = void 0; }, funcConfirmDevice = () => { var nav = navigator.userAgent.toLowerCase(); return nav.indexOf('iphone') > 0 || nav.indexOf('ipad') > 0 || nav.indexOf('android') > 0 || nav.indexOf('mobile') > 0?'sp':'pc'; }, funcPutHtml = () => { if(funcConfirmDevice() === 'sp'){ $('#FS2_layout_body').eq(0).append('\ \ '); $('#add_favorite_button') .after('\
\
\ \ \ \ \ \ \
\

\ お買い物リストは1週間でリセット(削除)されます。\

\
\ '); }else{ $('.layout_body').eq(0).append('\ \ '); $('#benefits_info_list') .before('\
\
\ \ \ \ \ \ \
\

\ お買い物リストは1週間でリセット(削除)されます。\

\
\ '); } }, funcCookieGetItemJson = () => { var cookie = $.cookie(configs.cookieName); if(typeof cookie === 'undefined') return false; try{ var obj = JSON.parse(cookie); }catch(e){ console.log(e); return false; } return obj; }, funcAddEventListener = () => { var eleAddShoppingListTrigger = $('#add_shopping_list_trigger'), eleRemoveShoppingListTrigger = $('#remove_shopping_list_trigger'); eleAddShoppingListTrigger .on({ 'click':function(){ funcAddItemList(); } }); eleRemoveShoppingListTrigger .on({ 'click':function(){ funcRemoveItemList(); } }); }, funcAddPlugin = () => { var elePopupShoppingList = $('#popup_shopping_list'); elePopupShoppingList.popup({ overlayClassName:'popup_shopping_list_overlay' }); }, funcAddItemList = () => { var elePopupShoppingList = $('#popup_shopping_list'), elePopupShoppingListInner = $('#popup_shopping_list_inner'), arrItemList = [], jsonItemList = funcCookieGetItemJson(); elePopupShoppingListInner.empty(); if(jsonItemList !== false){ if($.inArray(varGlobal.itemCode, jsonItemList) !== -1){ elePopupShoppingListInner.html('既に登録済みです。'); elePopupShoppingList.trigger('popup.show'); return false; }else{ arrItemList = jsonItemList; } } arrItemList.push(varGlobal.itemCode); $.cookie(configs.cookieName, JSON.stringify(arrItemList), configs.cookieOption.set); elePopupShoppingListInner.html('お買い物リストに登録しました。'); elePopupShoppingList.trigger('popup.show'); }, funcRemoveItemList = () => { var arrItemList = [], jsonItemList = funcCookieGetItemJson(); if(jsonItemList === false) return false; arrItemList = jsonItemList.filter(v => v !== varGlobal.itemCode); if(arrItemList.length === 0){ $.cookie(configs.cookieName, '', configs.cookieOption.unset); }else{ $.cookie(configs.cookieName, JSON.stringify(arrItemList), configs.cookieOption.set); } }; funcInit(); }); })(jQuery);