月間アーカイブ 12月 2025

'); } $('.my-bookmark-subtitle').text('現在保存中:' + $('.bookmark-card').length + '件'); } }); }); $(document).on('click', '.my-custom-bookmark-button', function() { const $btn = $(this); const postId = $btn.data('post-id'); const isBookmarked = $btn.data('bookmarked') === true; const actionType = isBookmarked ? 'remove' : 'add'; $.ajax({ url: myBookmarkAjax.ajax_url, type: 'POST', data: { action: 'my_custom_bookmark_action', nonce: myBookmarkAjax.nonce, post_id: postId, action_type: actionType }, beforeSend: () => { $btn.prop('disabled', true).find('.bookmark-text').text('処理中...'); }, success: (res) => { if (res.success) { $btn.data('bookmarked', !isBookmarked); $btn.toggleClass('bookmarked', !isBookmarked); $btn.find('.bookmark-text').text(!isBookmarked ? 'マイリスト済み' : 'この記事をマイリスト'); $btn.find('.bookmark-count').text('(' + res.data.bookmark_count + ')'); } }, complete: () => $btn.prop('disabled', false) }); }); const $modal = $('#auth-modal'), $form = $('#auth-form'), $msg = $('#auth-message'); const hasKey = false; $(document).on('click', '#open-auth-modal, .modal-close', e => { e.preventDefault(); $modal.toggleClass('active'); if ($modal.hasClass('active')) { $('#auth-password').val('').focus(); $msg.empty(); } }); $modal.on('click', e => { if (e.target === e.currentTarget) $modal.removeClass('active'); }); $form.on('submit', e => { e.preventDefault(); const pwd = $('#auth-password').val().trim(); if (!pwd) { $msg.html('パスワードを入力してください'); return; } const action = hasKey ? 'my_custom_bookmark_set_password' : 'my_custom_bookmark_restore_by_password'; $.post(myBookmarkAjax.ajax_url, { action, nonce: myBookmarkAjax.nonce, password: pwd }, res => { if (res.success) { $msg.html('' + res.data.message + ''); setTimeout(() => location.reload(), 1500); } else { $msg.html('' + (res.data || 'エラーが発生しました') + ''); } }); }); });

記事検索