Deploy 868d31c from main
This commit is contained in:
387
assets/css/peptide-search.css
Executable file
387
assets/css/peptide-search.css
Executable file
@@ -0,0 +1,387 @@
|
||||
/* ==========================================================================
|
||||
Peptide Search AI — Frontend Styles
|
||||
========================================================================== */
|
||||
|
||||
/* --- Search Form --- */
|
||||
.psa-search-wrap {
|
||||
max-width: 720px;
|
||||
margin: 2rem auto;
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
|
||||
}
|
||||
|
||||
.psa-search-form {
|
||||
margin-bottom: 1.5rem;
|
||||
}
|
||||
|
||||
.psa-search-input-wrap {
|
||||
display: flex;
|
||||
gap: 0;
|
||||
border: 2px solid #2563eb;
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
transition: border-color 0.2s;
|
||||
}
|
||||
|
||||
.psa-search-input-wrap:focus-within {
|
||||
border-color: #1d4ed8;
|
||||
box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
|
||||
}
|
||||
|
||||
.psa-search-input {
|
||||
flex: 1;
|
||||
padding: 14px 18px;
|
||||
font-size: 16px;
|
||||
border: none;
|
||||
outline: none;
|
||||
background: #fff;
|
||||
color: #1e293b;
|
||||
}
|
||||
|
||||
.psa-search-input::placeholder {
|
||||
color: #94a3b8;
|
||||
}
|
||||
|
||||
.psa-search-input:focus {
|
||||
outline: 2px solid #2563eb;
|
||||
outline-offset: 2px;
|
||||
}
|
||||
|
||||
.psa-search-btn {
|
||||
padding: 14px 24px;
|
||||
background: #2563eb;
|
||||
color: #fff;
|
||||
border: none;
|
||||
font-size: 15px;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
transition: background 0.2s;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.psa-search-btn:hover {
|
||||
background: #1d4ed8;
|
||||
}
|
||||
|
||||
.psa-search-btn:focus-visible {
|
||||
outline: 2px solid #fff;
|
||||
outline-offset: -2px;
|
||||
}
|
||||
|
||||
.psa-search-icon {
|
||||
margin-right: 4px;
|
||||
}
|
||||
|
||||
/* --- Search Results --- */
|
||||
.psa-search-results {
|
||||
margin-top: 1rem;
|
||||
}
|
||||
|
||||
.psa-result-count {
|
||||
font-size: 14px;
|
||||
color: #64748b;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.psa-result-item {
|
||||
display: block;
|
||||
padding: 16px 20px;
|
||||
margin-bottom: 8px;
|
||||
background: #fff;
|
||||
border: 1px solid #e2e8f0;
|
||||
border-radius: 8px;
|
||||
text-decoration: none;
|
||||
color: inherit;
|
||||
transition: border-color 0.2s, box-shadow 0.2s;
|
||||
}
|
||||
|
||||
.psa-result-item:hover {
|
||||
border-color: #2563eb;
|
||||
box-shadow: 0 2px 8px rgba(37, 99, 235, 0.1);
|
||||
}
|
||||
|
||||
.psa-result-title {
|
||||
font-size: 18px;
|
||||
font-weight: 600;
|
||||
color: #1e293b;
|
||||
margin: 0 0 6px;
|
||||
}
|
||||
|
||||
.psa-result-meta {
|
||||
font-size: 13px;
|
||||
color: #64748b;
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
|
||||
.psa-result-meta span {
|
||||
margin-right: 16px;
|
||||
}
|
||||
|
||||
.psa-result-excerpt {
|
||||
font-size: 14px;
|
||||
color: #475569;
|
||||
line-height: 1.5;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.psa-result-badge {
|
||||
display: inline-block;
|
||||
font-size: 11px;
|
||||
font-weight: 600;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.5px;
|
||||
padding: 2px 8px;
|
||||
border-radius: 4px;
|
||||
margin-left: 8px;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.psa-badge-ai {
|
||||
background: #fef3c7;
|
||||
color: #92400e;
|
||||
}
|
||||
|
||||
.psa-badge-verified {
|
||||
background: #d1fae5;
|
||||
color: #065f46;
|
||||
}
|
||||
|
||||
.psa-badge-manual {
|
||||
background: #dbeafe;
|
||||
color: #1e40af;
|
||||
}
|
||||
|
||||
/* --- Checking / Loading State --- */
|
||||
.psa-checking {
|
||||
margin-top: 1.5rem;
|
||||
}
|
||||
|
||||
.psa-checking-inner {
|
||||
text-align: center;
|
||||
padding: 32px 24px;
|
||||
background: #f8fafc;
|
||||
border: 1px solid #e2e8f0;
|
||||
border-radius: 12px;
|
||||
}
|
||||
|
||||
.psa-checking-inner p {
|
||||
margin: 12px 0 0;
|
||||
font-size: 15px;
|
||||
color: #64748b;
|
||||
}
|
||||
|
||||
/* --- Spinner --- */
|
||||
.psa-spinner {
|
||||
display: inline-block;
|
||||
width: 36px;
|
||||
height: 36px;
|
||||
border: 4px solid #bfdbfe;
|
||||
border-top-color: #2563eb;
|
||||
border-radius: 50%;
|
||||
animation: psa-spin 0.8s linear infinite;
|
||||
}
|
||||
|
||||
@keyframes psa-spin {
|
||||
to { transform: rotate(360deg); }
|
||||
}
|
||||
|
||||
/* --- Pending / Being Added Page --- */
|
||||
.psa-pending {
|
||||
margin-top: 1.5rem;
|
||||
}
|
||||
|
||||
.psa-pending-inner {
|
||||
text-align: center;
|
||||
padding: 40px 32px;
|
||||
background: linear-gradient(135deg, #eff6ff 0%, #f0f9ff 100%);
|
||||
border: 1px solid #bfdbfe;
|
||||
border-radius: 16px;
|
||||
}
|
||||
|
||||
.psa-pending-icon {
|
||||
font-size: 48px;
|
||||
line-height: 1;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.psa-pending-inner h3 {
|
||||
margin: 0 0 12px;
|
||||
font-size: 21px;
|
||||
color: #1e40af;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.psa-pending-inner > p {
|
||||
margin: 0 0 28px;
|
||||
font-size: 15px;
|
||||
color: #3b82f6;
|
||||
max-width: 500px;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
|
||||
/* --- Invalid Peptide --- */
|
||||
.psa-invalid {
|
||||
margin-top: 1.5rem;
|
||||
}
|
||||
|
||||
.psa-invalid-inner {
|
||||
text-align: center;
|
||||
padding: 32px 24px;
|
||||
background: #fafafa;
|
||||
border: 1px solid #e2e8f0;
|
||||
border-radius: 12px;
|
||||
}
|
||||
|
||||
.psa-invalid-inner h3 {
|
||||
margin: 0 0 12px;
|
||||
font-size: 20px;
|
||||
color: #334155;
|
||||
}
|
||||
|
||||
.psa-invalid-inner p {
|
||||
margin: 0;
|
||||
font-size: 15px;
|
||||
color: #64748b;
|
||||
max-width: 500px;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
/* --- Error State --- */
|
||||
.psa-error {
|
||||
margin-top: 1.5rem;
|
||||
padding: 16px 20px;
|
||||
background: #fef2f2;
|
||||
border: 1px solid #fca5a5;
|
||||
border-radius: 8px;
|
||||
color: #991b1b;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
/* --- Single Peptide Page Data --- */
|
||||
.psa-peptide-data {
|
||||
margin-top: 2rem;
|
||||
}
|
||||
|
||||
.psa-quick-facts {
|
||||
background: #f8fafc;
|
||||
border: 1px solid #e2e8f0;
|
||||
border-radius: 10px;
|
||||
padding: 20px 24px;
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
|
||||
.psa-quick-facts h3 {
|
||||
margin: 0 0 12px;
|
||||
font-size: 16px;
|
||||
font-weight: 700;
|
||||
color: #334155;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.5px;
|
||||
}
|
||||
|
||||
.psa-facts-table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
|
||||
.psa-facts-table th {
|
||||
text-align: left;
|
||||
padding: 8px 16px 8px 0;
|
||||
font-weight: 600;
|
||||
color: #475569;
|
||||
width: 180px;
|
||||
vertical-align: top;
|
||||
border-bottom: 1px solid #e2e8f0;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.psa-facts-table td {
|
||||
padding: 8px 0;
|
||||
color: #1e293b;
|
||||
border-bottom: 1px solid #e2e8f0;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.psa-facts-table tr:last-child th,
|
||||
.psa-facts-table tr:last-child td {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.psa-sequence {
|
||||
font-family: "SF Mono", "Fira Code", "Fira Mono", Menlo, Consolas, monospace;
|
||||
font-size: 13px;
|
||||
word-break: break-all;
|
||||
background: #f1f5f9;
|
||||
padding: 4px 8px;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.psa-section {
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
|
||||
.psa-section h3 {
|
||||
font-size: 18px;
|
||||
font-weight: 700;
|
||||
color: #1e293b;
|
||||
margin: 0 0 12px;
|
||||
padding-bottom: 8px;
|
||||
border-bottom: 2px solid #2563eb;
|
||||
}
|
||||
|
||||
.psa-section-content {
|
||||
font-size: 15px;
|
||||
line-height: 1.77;
|
||||
color: #334155;
|
||||
}
|
||||
|
||||
.psa-source-badge {
|
||||
margin-top: 2rem;
|
||||
padding: 12px 16px;
|
||||
border-radius: 8px;
|
||||
font-size: 13px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.psa-source-badge.psa-badge-ai {
|
||||
background: #fffbeb;
|
||||
border: 1px solid #fde68a;
|
||||
color: #92400e;
|
||||
}
|
||||
|
||||
.psa-source-badge.psa-badge-verified {
|
||||
background: #ecfdf5;
|
||||
border: 1px solid #6ee7b7;
|
||||
color: #065f46;
|
||||
}
|
||||
|
||||
.psa-source-badge.psa-badge-manual {
|
||||
background: #eff6ff;
|
||||
border: 1px solid #93c5fd;
|
||||
color: #1e40af;
|
||||
}
|
||||
|
||||
/* --- Responsive --- */
|
||||
@media (max-width: 600px) {
|
||||
.psa-search-input-wrap,
|
||||
.psa-notify-input-wrap {
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.psa-search-btn,
|
||||
.psa-notify-btn {
|
||||
border-radius: 0;
|
||||
}
|
||||
|
||||
.psa-facts-table th {
|
||||
width: 120px;
|
||||
}
|
||||
|
||||
.psa-pending-inner {
|
||||
padding: 28px 20px;
|
||||
}
|
||||
}
|
||||
621
assets/css/psa-directory.css
Executable file
621
assets/css/psa-directory.css
Executable file
@@ -0,0 +1,621 @@
|
||||
/* ==========================================================================
|
||||
Peptide Directory — Card Grid, Filters, and Detail Modal
|
||||
Namespace: .psa-dir-* (BEM)
|
||||
========================================================================== */
|
||||
|
||||
/* --- CSS Custom Properties for category badge colors (reusable by other plugins) --- */
|
||||
:root {
|
||||
--psa-cat-tissue-repair-bg: #d4edda;
|
||||
--psa-cat-tissue-repair-fg: #155724;
|
||||
--psa-cat-lipid-metabolism-bg: #d1ecf1;
|
||||
--psa-cat-lipid-metabolism-fg: #0c5460;
|
||||
--psa-cat-aging-research-bg: #e2d5f1;
|
||||
--psa-cat-aging-research-fg: #432874;
|
||||
--psa-cat-dermatological-bg: #fce4d6;
|
||||
--psa-cat-dermatological-fg: #7c4a1a;
|
||||
--psa-cat-metabolic-bg: #fff3cd;
|
||||
--psa-cat-metabolic-fg: #856404;
|
||||
--psa-cat-growth-hormone-bg: #cce5ff;
|
||||
--psa-cat-growth-hormone-fg: #004085;
|
||||
--psa-cat-immunology-bg: #f5c6cb;
|
||||
--psa-cat-immunology-fg: #721c24;
|
||||
--psa-cat-endocrine-bg: #c3e6cb;
|
||||
--psa-cat-endocrine-fg: #1b5e20;
|
||||
}
|
||||
|
||||
/* --- Wrapper --- */
|
||||
.psa-dir-wrap {
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
padding: 2rem 1rem;
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
|
||||
}
|
||||
|
||||
/* --- Header --- */
|
||||
.psa-dir-header {
|
||||
text-align: center;
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
|
||||
.psa-dir-title {
|
||||
font-size: 2rem;
|
||||
font-weight: 700;
|
||||
color: #1e293b;
|
||||
margin: 0 0 0.5rem;
|
||||
}
|
||||
|
||||
.psa-dir-subtitle {
|
||||
font-size: 1.05rem;
|
||||
color: #64748b;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
/* --- Search --- */
|
||||
.psa-dir-search-wrap {
|
||||
max-width: 480px;
|
||||
margin: 0 auto 1.5rem;
|
||||
}
|
||||
|
||||
.psa-dir-search {
|
||||
width: 100%;
|
||||
padding: 12px 16px;
|
||||
font-size: 15px;
|
||||
border: 2px solid #e2e8f0;
|
||||
border-radius: 8px;
|
||||
outline: none;
|
||||
transition: border-color 0.2s;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.psa-dir-search:focus {
|
||||
border-color: #2563eb;
|
||||
box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
|
||||
}
|
||||
|
||||
/* --- Tabs --- */
|
||||
.psa-dir-tabs {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
gap: 4px;
|
||||
margin-bottom: 1.5rem;
|
||||
}
|
||||
|
||||
.psa-dir-tab {
|
||||
padding: 8px 20px;
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
border: 1px solid #e2e8f0;
|
||||
border-radius: 6px;
|
||||
background: #fff;
|
||||
color: #64748b;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.psa-dir-tab:hover {
|
||||
background: #f8fafc;
|
||||
}
|
||||
|
||||
.psa-dir-tab--active {
|
||||
background: #2563eb;
|
||||
color: #fff;
|
||||
border-color: #2563eb;
|
||||
}
|
||||
|
||||
/* --- Category Filters --- */
|
||||
.psa-dir-filters {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
justify-content: center;
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
|
||||
.psa-dir-filter {
|
||||
padding: 6px 16px;
|
||||
font-size: 13px;
|
||||
font-weight: 500;
|
||||
border: 1px solid #e2e8f0;
|
||||
border-radius: 20px;
|
||||
background: #fff;
|
||||
color: #475569;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.psa-dir-filter:hover {
|
||||
border-color: #2563eb;
|
||||
color: #2563eb;
|
||||
}
|
||||
|
||||
.psa-dir-filter--active {
|
||||
background: #2563eb;
|
||||
color: #fff;
|
||||
border-color: #2563eb;
|
||||
}
|
||||
|
||||
/* --- Grid --- */
|
||||
.psa-dir-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, 1fr);
|
||||
gap: 1.25rem;
|
||||
}
|
||||
|
||||
/* --- Card --- */
|
||||
.psa-dir-card {
|
||||
background: #fff;
|
||||
border: 1px solid #e2e8f0;
|
||||
border-radius: 12px;
|
||||
padding: 1.25rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
transition: border-color 0.2s, box-shadow 0.2s;
|
||||
}
|
||||
|
||||
.psa-dir-card:hover {
|
||||
border-color: #2563eb;
|
||||
box-shadow: 0 4px 12px rgba(37, 99, 235, 0.08);
|
||||
}
|
||||
|
||||
.psa-dir-card__header {
|
||||
margin-bottom: 0.75rem;
|
||||
}
|
||||
|
||||
.psa-dir-card__title {
|
||||
font-size: 1.1rem;
|
||||
font-weight: 700;
|
||||
color: #1e293b;
|
||||
margin: 0 0 0.5rem;
|
||||
}
|
||||
|
||||
.psa-dir-card__badge {
|
||||
display: inline-block;
|
||||
font-size: 11px;
|
||||
font-weight: 600;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.5px;
|
||||
padding: 2px 10px;
|
||||
border-radius: 12px;
|
||||
}
|
||||
|
||||
.psa-dir-card__meta {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
margin-bottom: 1rem;
|
||||
flex-grow: 1;
|
||||
}
|
||||
|
||||
.psa-dir-card__meta-item {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.psa-dir-card__meta-label {
|
||||
color: #64748b;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.psa-dir-card__meta-value {
|
||||
color: #1e293b;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.psa-dir-card__btn {
|
||||
width: 100%;
|
||||
padding: 10px;
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
background: #2563eb;
|
||||
color: #fff;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
cursor: pointer;
|
||||
transition: background 0.2s;
|
||||
margin-top: auto;
|
||||
}
|
||||
|
||||
.psa-dir-card__btn:hover {
|
||||
background: #1d4ed8;
|
||||
}
|
||||
|
||||
/* --- Category Badge Colors --- */
|
||||
.psa-dir-badge--tissue-repair { background: var(--psa-cat-tissue-repair-bg); color: var(--psa-cat-tissue-repair-fg); }
|
||||
.psa-dir-badge--lipid-metabolism { background: var(--psa-cat-lipid-metabolism-bg); color: var(--psa-cat-lipid-metabolism-fg); }
|
||||
.psa-dir-badge--aging-research { background: var(--psa-cat-aging-research-bg); color: var(--psa-cat-aging-research-fg); }
|
||||
.psa-dir-badge--dermatological { background: var(--psa-cat-dermatological-bg); color: var(--psa-cat-dermatological-fg); }
|
||||
.psa-dir-badge--metabolic { background: var(--psa-cat-metabolic-bg); color: var(--psa-cat-metabolic-fg); }
|
||||
.psa-dir-badge--growth-hormone { background: var(--psa-cat-growth-hormone-bg); color: var(--psa-cat-growth-hormone-fg); }
|
||||
.psa-dir-badge--immunology { background: var(--psa-cat-immunology-bg); color: var(--psa-cat-immunology-fg); }
|
||||
.psa-dir-badge--endocrine { background: var(--psa-cat-endocrine-bg); color: var(--psa-cat-endocrine-fg); }
|
||||
|
||||
/* --- Empty State --- */
|
||||
.psa-dir-empty,
|
||||
.psa-dir-coming-soon {
|
||||
text-align: center;
|
||||
padding: 3rem 1rem;
|
||||
color: #64748b;
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
/* --- Loader --- */
|
||||
.psa-dir-loader {
|
||||
text-align: center;
|
||||
padding: 3rem 1rem;
|
||||
}
|
||||
|
||||
.psa-dir-loader p {
|
||||
color: #64748b;
|
||||
margin-top: 1rem;
|
||||
}
|
||||
|
||||
/* --- Load More --- */
|
||||
.psa-dir-load-more-wrap {
|
||||
text-align: center;
|
||||
margin-top: 2rem;
|
||||
}
|
||||
|
||||
.psa-dir-load-more {
|
||||
padding: 12px 32px;
|
||||
font-size: 15px;
|
||||
font-weight: 600;
|
||||
background: #fff;
|
||||
color: #2563eb;
|
||||
border: 2px solid #2563eb;
|
||||
border-radius: 8px;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.psa-dir-load-more:hover {
|
||||
background: #2563eb;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.psa-dir-load-more:disabled {
|
||||
opacity: 0.5;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
/* --- Error --- */
|
||||
.psa-dir-error {
|
||||
text-align: center;
|
||||
color: #991b1b;
|
||||
padding: 2rem;
|
||||
}
|
||||
|
||||
/* ==========================================================================
|
||||
Detail Modal
|
||||
========================================================================== */
|
||||
|
||||
.psa-dir-modal {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
z-index: 99999;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.psa-dir-modal__backdrop {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background: rgba(0, 0, 0, 0.5);
|
||||
}
|
||||
|
||||
.psa-dir-modal__content {
|
||||
position: relative;
|
||||
background: #fff;
|
||||
border-radius: 16px;
|
||||
padding: 2rem;
|
||||
max-width: 700px;
|
||||
width: 90%;
|
||||
max-height: 85vh;
|
||||
overflow-y: auto;
|
||||
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
|
||||
.psa-dir-modal__close {
|
||||
position: absolute;
|
||||
top: 12px;
|
||||
right: 16px;
|
||||
font-size: 28px;
|
||||
background: none;
|
||||
border: none;
|
||||
color: #94a3b8;
|
||||
cursor: pointer;
|
||||
line-height: 1;
|
||||
padding: 4px;
|
||||
}
|
||||
|
||||
.psa-dir-modal__close:hover {
|
||||
color: #1e293b;
|
||||
}
|
||||
|
||||
.psa-dir-modal__title {
|
||||
font-size: 1.5rem;
|
||||
font-weight: 700;
|
||||
color: #1e293b;
|
||||
margin: 0 0 0.5rem;
|
||||
padding-right: 2rem;
|
||||
}
|
||||
|
||||
.psa-dir-modal__badges {
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.psa-dir-modal__desc {
|
||||
font-size: 15px;
|
||||
line-height: 1.65;
|
||||
color: #475569;
|
||||
margin-bottom: 1.5rem;
|
||||
}
|
||||
|
||||
/* --- Sequence --- */
|
||||
.psa-dir-modal__sequence-wrap {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 8px;
|
||||
background: #f1f5f9;
|
||||
padding: 12px;
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.psa-dir-modal__sequence {
|
||||
font-family: "SF Mono", "Fira Code", Menlo, Consolas, monospace;
|
||||
font-size: 13px;
|
||||
word-break: break-all;
|
||||
flex: 1;
|
||||
color: #334155;
|
||||
}
|
||||
|
||||
.psa-dir-modal__copy {
|
||||
padding: 4px 12px;
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
background: #2563eb;
|
||||
color: #fff;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.psa-dir-modal__copy:hover {
|
||||
background: #1d4ed8;
|
||||
}
|
||||
|
||||
/* --- Data Grid --- */
|
||||
.psa-dir-modal__data-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, 1fr);
|
||||
gap: 12px;
|
||||
margin-bottom: 1.5rem;
|
||||
padding: 1rem;
|
||||
background: #f8fafc;
|
||||
border-radius: 10px;
|
||||
border: 1px solid #e2e8f0;
|
||||
}
|
||||
|
||||
.psa-dir-modal__data-item {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
}
|
||||
|
||||
.psa-dir-modal__data-label {
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.3px;
|
||||
color: #64748b;
|
||||
}
|
||||
|
||||
.psa-dir-modal__data-value {
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
color: #1e293b;
|
||||
}
|
||||
|
||||
/* --- Modal Sections --- */
|
||||
.psa-dir-modal__section {
|
||||
margin-bottom: 1.5rem;
|
||||
}
|
||||
|
||||
.psa-dir-modal__section h4 {
|
||||
font-size: 15px;
|
||||
font-weight: 700;
|
||||
color: #1e293b;
|
||||
margin: 0 0 0.5rem;
|
||||
padding-bottom: 6px;
|
||||
border-bottom: 2px solid #2563eb;
|
||||
}
|
||||
|
||||
.psa-dir-modal__section p {
|
||||
font-size: 14px;
|
||||
line-height: 1.6;
|
||||
color: #475569;
|
||||
margin: 0 0 0.5rem;
|
||||
}
|
||||
|
||||
/* --- PubChem Link --- */
|
||||
.psa-dir-modal__pubchem {
|
||||
display: inline-block;
|
||||
font-size: 13px;
|
||||
color: #2563eb;
|
||||
text-decoration: none;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.psa-dir-modal__pubchem:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
/* --- Full Page Link --- */
|
||||
.psa-dir-modal__full-link {
|
||||
display: inline-block;
|
||||
padding: 10px 24px;
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
background: #f1f5f9;
|
||||
color: #2563eb;
|
||||
text-decoration: none;
|
||||
border-radius: 8px;
|
||||
transition: background 0.2s;
|
||||
}
|
||||
|
||||
.psa-dir-modal__full-link:hover {
|
||||
background: #e2e8f0;
|
||||
}
|
||||
|
||||
/* ==========================================================================
|
||||
Responsive
|
||||
========================================================================== */
|
||||
|
||||
/* Tablet: 2 columns */
|
||||
@media (max-width: 900px) {
|
||||
.psa-dir-grid {
|
||||
grid-template-columns: repeat(2, 1fr);
|
||||
}
|
||||
}
|
||||
|
||||
/* Mobile: 1 column */
|
||||
@media (max-width: 600px) {
|
||||
.psa-dir-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.psa-dir-title {
|
||||
font-size: 1.5rem;
|
||||
}
|
||||
|
||||
.psa-dir-modal__content {
|
||||
width: 95%;
|
||||
padding: 1.25rem;
|
||||
max-height: 90vh;
|
||||
}
|
||||
|
||||
.psa-dir-modal__data-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.psa-dir-filters {
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.psa-dir-filter {
|
||||
font-size: 12px;
|
||||
padding: 5px 12px;
|
||||
}
|
||||
}
|
||||
|
||||
/* ==========================================================================
|
||||
Dark Mode Support
|
||||
Uses the theme's data-theme="dark" attribute and CSS custom properties.
|
||||
========================================================================== */
|
||||
|
||||
[data-theme="dark"] .psa-dir-wrap {
|
||||
color: #e2e8f0;
|
||||
}
|
||||
|
||||
[data-theme="dark"] .psa-dir-title {
|
||||
color: #f1f5f9;
|
||||
}
|
||||
|
||||
[data-theme="dark"] .psa-dir-subtitle {
|
||||
color: #94a3b8;
|
||||
}
|
||||
|
||||
[data-theme="dark"] .psa-dir-search {
|
||||
background: #1e293b;
|
||||
border-color: #334155;
|
||||
color: #f1f5f9;
|
||||
}
|
||||
|
||||
[data-theme="dark"] .psa-dir-tab {
|
||||
background: #1e293b;
|
||||
border-color: #334155;
|
||||
color: #94a3b8;
|
||||
}
|
||||
|
||||
[data-theme="dark"] .psa-dir-tab--active {
|
||||
background: #2563eb;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
[data-theme="dark"] .psa-dir-filter {
|
||||
background: #1e293b;
|
||||
border-color: #334155;
|
||||
color: #94a3b8;
|
||||
}
|
||||
|
||||
[data-theme="dark"] .psa-dir-filter--active {
|
||||
background: #2563eb;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
[data-theme="dark"] .psa-dir-card {
|
||||
background: #1e293b;
|
||||
border-color: #334155;
|
||||
}
|
||||
|
||||
[data-theme="dark"] .psa-dir-card__title {
|
||||
color: #f1f5f9;
|
||||
}
|
||||
|
||||
[data-theme="dark"] .psa-dir-card__meta-label {
|
||||
color: #94a3b8;
|
||||
}
|
||||
|
||||
[data-theme="dark"] .psa-dir-card__meta-value {
|
||||
color: #e2e8f0;
|
||||
}
|
||||
|
||||
[data-theme="dark"] .psa-dir-modal__content {
|
||||
background: #0f172a;
|
||||
color: #e2e8f0;
|
||||
}
|
||||
|
||||
[data-theme="dark"] .psa-dir-modal__title {
|
||||
color: #f1f5f9;
|
||||
}
|
||||
|
||||
[data-theme="dark"] .psa-dir-modal__desc {
|
||||
color: #94a3b8;
|
||||
}
|
||||
|
||||
[data-theme="dark"] .psa-dir-modal__data-grid {
|
||||
background: #1e293b;
|
||||
border-color: #334155;
|
||||
}
|
||||
|
||||
[data-theme="dark"] .psa-dir-modal__data-label {
|
||||
color: #94a3b8;
|
||||
}
|
||||
|
||||
[data-theme="dark"] .psa-dir-modal__data-value {
|
||||
color: #e2e8f0;
|
||||
}
|
||||
|
||||
[data-theme="dark"] .psa-dir-modal__sequence-wrap {
|
||||
background: #1e293b;
|
||||
}
|
||||
|
||||
[data-theme="dark"] .psa-dir-modal__sequence {
|
||||
color: #e2e8f0;
|
||||
}
|
||||
|
||||
[data-theme="dark"] .psa-dir-modal__close {
|
||||
color: #64748b;
|
||||
}
|
||||
|
||||
[data-theme="dark"] .psa-dir-modal__close:hover {
|
||||
color: #f1f5f9;
|
||||
}
|
||||
213
assets/js/peptide-search.js
Executable file
213
assets/js/peptide-search.js
Executable file
@@ -0,0 +1,213 @@
|
||||
/**
|
||||
* Peptide Search AI — Frontend JavaScript
|
||||
*
|
||||
* Supports multiple shortcode instances on the same page by using
|
||||
* class-based selectors scoped to each .psa-search-wrap container.
|
||||
*
|
||||
* Flow:
|
||||
* 1. User searches -> AJAX call to backend
|
||||
* 2. If found -> show results
|
||||
* 3. If not found -> backend automatically validates + queues generation
|
||||
* -> user sees "pending" page
|
||||
* 4. If invalid peptide name -> show "not recognized" message
|
||||
*/
|
||||
(function ($) {
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Initialize a single search instance scoped to its .psa-search-wrap container.
|
||||
*/
|
||||
function initSearchInstance($wrap) {
|
||||
var $form = $wrap.find('.psa-search-form');
|
||||
var $input = $wrap.find('.psa-search-input');
|
||||
var $results = $wrap.find('.psa-search-results');
|
||||
var $checking = $wrap.find('.psa-checking');
|
||||
var $pending = $wrap.find('.psa-pending');
|
||||
var $invalid = $wrap.find('.psa-invalid');
|
||||
var $error = $wrap.find('.psa-error');
|
||||
|
||||
function debounce(fn, delay) {
|
||||
var timer;
|
||||
return function () {
|
||||
var args = arguments, ctx = this;
|
||||
clearTimeout(timer);
|
||||
timer = setTimeout(function () { fn.apply(ctx, args); }, delay);
|
||||
};
|
||||
}
|
||||
|
||||
function hideAll() {
|
||||
$results.hide();
|
||||
$results.attr('aria-busy', 'false');
|
||||
$checking.hide();
|
||||
$pending.hide();
|
||||
$invalid.hide();
|
||||
$error.hide();
|
||||
}
|
||||
|
||||
function showError(msg) {
|
||||
hideAll();
|
||||
$error.html('<strong>' + esc(psaAjax.i18n.error) + '</strong> ' + esc(msg)).show();
|
||||
$error.attr('role', 'alert');
|
||||
}
|
||||
|
||||
function esc(str) {
|
||||
var d = document.createElement('div');
|
||||
d.appendChild(document.createTextNode(str));
|
||||
return d.innerHTML;
|
||||
}
|
||||
|
||||
function sourceBadge(source) {
|
||||
var map = {
|
||||
'pubchem': { label: psaAjax.i18n.verified, cls: 'psa-badge-verified' },
|
||||
'manual': { label: psaAjax.i18n.curated, cls: 'psa-badge-manual' }
|
||||
};
|
||||
var b = map[source];
|
||||
if (!b) return '';
|
||||
return '<span class="psa-result-badge ' + b.cls + '">' + esc(b.label) + '</span>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Render search results.
|
||||
*/
|
||||
function renderResults(data) {
|
||||
hideAll();
|
||||
|
||||
var html = '<p class="psa-result-count">' + data.total + ' ' + esc(psaAjax.i18n.peptidesFound) + '</p>';
|
||||
|
||||
data.results.forEach(function (item) {
|
||||
html += '<a href="' + esc(item.url) + '" class="psa-result-item">';
|
||||
html += '<h4 class="psa-result-title">' + esc(item.title);
|
||||
if (item.source) html += sourceBadge(item.source);
|
||||
html += '</h4>';
|
||||
|
||||
var meta = [];
|
||||
if (item.molecular_weight) meta.push('<span>MW: ' + esc(item.molecular_weight) + '</span>');
|
||||
if (item.molecular_formula) meta.push('<span>Formula: ' + esc(item.molecular_formula) + '</span>');
|
||||
if (item.sequence && item.sequence.length <= 40) meta.push('<span>Seq: <code>' + esc(item.sequence) + '</code></span>');
|
||||
if (meta.length) html += '<div class="psa-result-meta">' + meta.join('') + '</div>';
|
||||
|
||||
if (item.excerpt) html += '<p class="psa-result-excerpt">' + esc(item.excerpt) + '</p>';
|
||||
html += '</a>';
|
||||
});
|
||||
|
||||
$results.html(html).show();
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the pending/in-progress message.
|
||||
*/
|
||||
function showPending(name) {
|
||||
hideAll();
|
||||
$pending.find('.psa-pending-inner p').html(
|
||||
'<strong>' + esc(name) + '</strong> ' + esc(psaAjax.i18n.pendingMsg)
|
||||
);
|
||||
$pending.show();
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the invalid peptide message.
|
||||
*/
|
||||
function showInvalid(name, reason) {
|
||||
hideAll();
|
||||
$invalid.find('.psa-invalid-text').html(
|
||||
'<strong>' + esc(name) + '</strong> ' + esc(psaAjax.i18n.invalidMsg)
|
||||
);
|
||||
$invalid.show();
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform the search. The backend handles everything:
|
||||
* - If found: returns results
|
||||
* - If not found + valid peptide: validates, creates placeholder, queues generation
|
||||
* - If not found + invalid: returns invalid status
|
||||
*/
|
||||
function doSearch(query) {
|
||||
if (query.length < 2) {
|
||||
hideAll();
|
||||
return;
|
||||
}
|
||||
|
||||
hideAll();
|
||||
$checking.show();
|
||||
$results.attr('aria-busy', 'true');
|
||||
|
||||
$.ajax({
|
||||
url: psaAjax.ajaxurl,
|
||||
method: 'GET',
|
||||
data: {
|
||||
action: 'psa_search',
|
||||
nonce: psaAjax.nonce,
|
||||
q: query
|
||||
},
|
||||
timeout: 30000,
|
||||
success: function (response) {
|
||||
$results.attr('aria-busy', 'false');
|
||||
if (!response.success) {
|
||||
showError(response.data || psaAjax.i18n.searchFailed);
|
||||
return;
|
||||
}
|
||||
var d = response.data;
|
||||
switch (d.status) {
|
||||
case 'found':
|
||||
renderResults(d.data);
|
||||
break;
|
||||
case 'pending':
|
||||
showPending(d.peptide_name);
|
||||
break;
|
||||
case 'invalid':
|
||||
showInvalid(query, d.message);
|
||||
break;
|
||||
case 'rate_limited':
|
||||
showError(d.message || psaAjax.i18n.rateLimited);
|
||||
break;
|
||||
default:
|
||||
showError(psaAjax.i18n.unexpected);
|
||||
}
|
||||
},
|
||||
error: function (jqXHR, textStatus) {
|
||||
$results.attr('aria-busy', 'false');
|
||||
var errorMsg = psaAjax.i18n.networkError;
|
||||
if (textStatus === 'timeout') {
|
||||
errorMsg = psaAjax.i18n.timeout;
|
||||
} else if (textStatus === 'error') {
|
||||
if (jqXHR.status === 0) {
|
||||
errorMsg = psaAjax.i18n.connectionError;
|
||||
} else if (jqXHR.status === 500) {
|
||||
errorMsg = psaAjax.i18n.serverError;
|
||||
} else if (jqXHR.status === 503) {
|
||||
errorMsg = psaAjax.i18n.unavailable;
|
||||
}
|
||||
}
|
||||
showError(errorMsg);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// --- Event Handlers (scoped to this instance) ---
|
||||
|
||||
$form.on('submit', function (e) {
|
||||
e.preventDefault();
|
||||
doSearch($input.val().trim());
|
||||
});
|
||||
|
||||
var debouncedSearch = debounce(function () {
|
||||
var q = $input.val().trim();
|
||||
if (q.length >= 2) {
|
||||
doSearch(q);
|
||||
} else {
|
||||
hideAll();
|
||||
}
|
||||
}, 400);
|
||||
|
||||
$input.on('input', debouncedSearch);
|
||||
}
|
||||
|
||||
// --- Initialize all search instances on page ---
|
||||
|
||||
$(document).ready(function () {
|
||||
$('.psa-search-wrap').each(function () {
|
||||
initSearchInstance($(this));
|
||||
});
|
||||
});
|
||||
|
||||
})(jQuery);
|
||||
172
assets/js/psa-batch-enrich.js
Executable file
172
assets/js/psa-batch-enrich.js
Executable file
@@ -0,0 +1,172 @@
|
||||
/**
|
||||
* Batch enrichment UI controller for the Peptide Search AI admin page.
|
||||
*
|
||||
* What: Drives the AJAX polling loop that enriches one peptide at a time with a progress bar.
|
||||
* Who loads it: PSA_Admin::enqueue_batch_scripts() on the PSA settings page.
|
||||
* Dependencies: jQuery (WP core), wp.ajax (WP admin AJAX helper), psaBatchEnrich localized data.
|
||||
*
|
||||
* @see includes/class-psa-batch-enrichment.php
|
||||
* @see includes/class-psa-admin.php
|
||||
*/
|
||||
/* global jQuery, psaBatchEnrich */
|
||||
(function ($) {
|
||||
'use strict';
|
||||
|
||||
var isRunning = false;
|
||||
var processed = 0;
|
||||
var errors = 0;
|
||||
var total = 0;
|
||||
var remaining = 0;
|
||||
|
||||
/**
|
||||
* Initialize: bind the start button and fetch initial status.
|
||||
*/
|
||||
function init() {
|
||||
var $btn = $('#psa-batch-enrich-start');
|
||||
if (!$btn.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
$btn.on('click', function (e) {
|
||||
e.preventDefault();
|
||||
if (isRunning) {
|
||||
return;
|
||||
}
|
||||
startEnrichment();
|
||||
});
|
||||
|
||||
// Fetch initial count on page load.
|
||||
fetchStatus();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the current enrichment status (how many need enrichment).
|
||||
*/
|
||||
function fetchStatus() {
|
||||
$.post(psaBatchEnrich.ajaxUrl, {
|
||||
action: 'psa_batch_enrich_status',
|
||||
_nonce: psaBatchEnrich.nonce
|
||||
}, function (response) {
|
||||
if (response.success) {
|
||||
remaining = response.data.remaining;
|
||||
total = response.data.remaining; // Total to process this run.
|
||||
updateStatusText(response.data.remaining + ' peptides need enrichment');
|
||||
|
||||
if (response.data.remaining === 0) {
|
||||
$('#psa-batch-enrich-start').prop('disabled', true).text('All enriched');
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Start the enrichment loop.
|
||||
*/
|
||||
function startEnrichment() {
|
||||
isRunning = true;
|
||||
processed = 0;
|
||||
errors = 0;
|
||||
|
||||
$('#psa-batch-enrich-start').prop('disabled', true).text('Running...');
|
||||
$('#psa-batch-enrich-progress').show();
|
||||
$('#psa-batch-enrich-log').empty().show();
|
||||
|
||||
updateProgress(0, total);
|
||||
processNext();
|
||||
}
|
||||
|
||||
/**
|
||||
* Process one peptide, then loop.
|
||||
*/
|
||||
function processNext() {
|
||||
if (!isRunning) {
|
||||
return;
|
||||
}
|
||||
|
||||
$.post(psaBatchEnrich.ajaxUrl, {
|
||||
action: 'psa_batch_enrich_next',
|
||||
_nonce: psaBatchEnrich.nonce
|
||||
}, function (response) {
|
||||
if (!response.success) {
|
||||
appendLog('Server error: ' + (response.data || 'Unknown'), 'error');
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
var data = response.data;
|
||||
|
||||
if (data.status === 'done') {
|
||||
appendLog('All peptides enriched!', 'success');
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
if (data.status === 'cap_reached') {
|
||||
appendLog(data.message, 'warning');
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
processed++;
|
||||
remaining = data.remaining;
|
||||
|
||||
if (data.status === 'ok') {
|
||||
appendLog('Enriched: ' + data.name, 'success');
|
||||
} else if (data.status === 'error') {
|
||||
errors++;
|
||||
appendLog('Failed: ' + data.name + ' — ' + data.message, 'error');
|
||||
}
|
||||
|
||||
updateProgress(processed, processed + remaining);
|
||||
|
||||
// Brief delay to avoid hammering the server — 2 seconds between requests.
|
||||
setTimeout(processNext, 2000);
|
||||
|
||||
}).fail(function (xhr) {
|
||||
appendLog('Request failed (HTTP ' + xhr.status + '). Retrying in 10s...', 'warning');
|
||||
setTimeout(processNext, 10000);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the progress bar.
|
||||
*/
|
||||
function updateProgress(done, total) {
|
||||
var pct = total > 0 ? Math.round((done / total) * 100) : 0;
|
||||
$('#psa-batch-enrich-bar').css('width', pct + '%');
|
||||
$('#psa-batch-enrich-pct').text(pct + '% (' + done + '/' + total + ')');
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the status text below the button.
|
||||
*/
|
||||
function updateStatusText(text) {
|
||||
$('#psa-batch-enrich-status').text(text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Append a line to the log.
|
||||
*/
|
||||
function appendLog(message, type) {
|
||||
var color = type === 'error' ? '#dc3232' : type === 'warning' ? '#dba617' : '#46b450';
|
||||
var icon = type === 'error' ? '✗' : type === 'warning' ? '⚠' : '✓';
|
||||
$('#psa-batch-enrich-log').prepend(
|
||||
'<div style="color:' + color + ';margin:2px 0;font-size:13px;">' +
|
||||
icon + ' ' + $('<span>').text(message).html() +
|
||||
'</div>'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* End the run.
|
||||
*/
|
||||
function finish() {
|
||||
isRunning = false;
|
||||
$('#psa-batch-enrich-start').prop('disabled', false).text('Re-enrich Peptides');
|
||||
|
||||
var summary = 'Done. ' + processed + ' processed, ' + errors + ' errors, ' + remaining + ' remaining.';
|
||||
updateStatusText(summary);
|
||||
}
|
||||
|
||||
$(document).ready(init);
|
||||
})(jQuery);
|
||||
501
assets/js/psa-directory.js
Executable file
501
assets/js/psa-directory.js
Executable file
@@ -0,0 +1,501 @@
|
||||
/**
|
||||
* Peptide Directory — Frontend JavaScript
|
||||
*
|
||||
* Renders the browsable directory grid with category filters, search,
|
||||
* pagination, and detail modal. Uses vanilla JS (no build step required).
|
||||
*
|
||||
* Data source: REST API at /wp-json/peptide-search-ai/v1/compounds
|
||||
* Config: psaDirectory global (localized from class-psa-directory.php)
|
||||
*
|
||||
* @see includes/class-psa-directory.php — shortcode + REST endpoint
|
||||
* @see assets/css/psa-directory.css — all .psa-dir-* styles
|
||||
*/
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
var config = window.psaDirectory;
|
||||
if (!config) return;
|
||||
|
||||
var root = document.getElementById('psa-directory-root');
|
||||
if (!root) return;
|
||||
|
||||
var state = {
|
||||
compounds: [],
|
||||
page: 1,
|
||||
totalPages: 0,
|
||||
total: 0,
|
||||
category: '',
|
||||
search: '',
|
||||
loading: false,
|
||||
activeTab: 'single',
|
||||
modalData: null
|
||||
};
|
||||
|
||||
var i18n = config.i18n;
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Utility
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
function esc(str) {
|
||||
if (!str) return '';
|
||||
var d = document.createElement('div');
|
||||
d.appendChild(document.createTextNode(str));
|
||||
return d.innerHTML;
|
||||
}
|
||||
|
||||
function debounce(fn, delay) {
|
||||
var timer;
|
||||
return function () {
|
||||
var args = arguments, ctx = this;
|
||||
clearTimeout(timer);
|
||||
timer = setTimeout(function () { fn.apply(ctx, args); }, delay);
|
||||
};
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// API
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
function fetchCompounds(append) {
|
||||
if (state.loading) return;
|
||||
state.loading = true;
|
||||
updateLoadMoreBtn();
|
||||
|
||||
var url = config.restUrl +
|
||||
'?page=' + state.page +
|
||||
'&per_page=' + config.perPage;
|
||||
|
||||
if (state.search) url += '&search=' + encodeURIComponent(state.search);
|
||||
if (state.category) url += '&category=' + encodeURIComponent(state.category);
|
||||
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', url, true);
|
||||
xhr.setRequestHeader('X-WP-Nonce', config.nonce);
|
||||
xhr.onload = function () {
|
||||
state.loading = false;
|
||||
if (xhr.status === 200) {
|
||||
var data = JSON.parse(xhr.responseText);
|
||||
if (append) {
|
||||
state.compounds = state.compounds.concat(data.compounds);
|
||||
} else {
|
||||
state.compounds = data.compounds;
|
||||
}
|
||||
state.total = data.total;
|
||||
state.totalPages = data.total_pages;
|
||||
renderGrid();
|
||||
} else {
|
||||
renderError();
|
||||
}
|
||||
};
|
||||
xhr.onerror = function () {
|
||||
state.loading = false;
|
||||
renderError();
|
||||
};
|
||||
xhr.send();
|
||||
}
|
||||
|
||||
function fetchCompoundDetail(id, callback) {
|
||||
var url = config.restUrl + '?search=&per_page=1&page=1&fields=full';
|
||||
/* Find by iterating existing data first to avoid extra API call. */
|
||||
var existing = null;
|
||||
for (var i = 0; i < state.compounds.length; i++) {
|
||||
if (state.compounds[i].id === id) {
|
||||
existing = state.compounds[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (existing && existing.sequence !== undefined) {
|
||||
callback(existing);
|
||||
return;
|
||||
}
|
||||
/* Fallback: fetch from API (shouldn't normally be needed for full fields). */
|
||||
callback(existing);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Render — Shell
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
function renderShell() {
|
||||
root.innerHTML =
|
||||
'<div class="psa-dir-header">' +
|
||||
'<h2 class="psa-dir-title">' + esc(i18n.title) + '</h2>' +
|
||||
'<p class="psa-dir-subtitle">' + esc(i18n.subtitle) + '</p>' +
|
||||
'</div>' +
|
||||
'<div class="psa-dir-search-wrap">' +
|
||||
'<input type="text" class="psa-dir-search" placeholder="' + esc(i18n.searchPlaceholder) + '" aria-label="' + esc(i18n.searchPlaceholder) + '" />' +
|
||||
'</div>' +
|
||||
'<div class="psa-dir-tabs" role="tablist">' +
|
||||
'<button class="psa-dir-tab psa-dir-tab--active" data-tab="single" role="tab" aria-selected="true">' + esc(i18n.singleReagents) + '</button>' +
|
||||
'<button class="psa-dir-tab" data-tab="protocols" role="tab" aria-selected="false">' + esc(i18n.protocolModels) + '</button>' +
|
||||
'</div>' +
|
||||
'<div class="psa-dir-filters" role="group" aria-label="Category filter"></div>' +
|
||||
'<div class="psa-dir-content">' +
|
||||
'<div class="psa-dir-grid" role="list"></div>' +
|
||||
'<div class="psa-dir-coming-soon" style="display:none;">' +
|
||||
'<p>' + esc(i18n.comingSoon) + '</p>' +
|
||||
'</div>' +
|
||||
'<div class="psa-dir-empty" style="display:none;">' +
|
||||
'<p>' + esc(i18n.noResults) + '</p>' +
|
||||
'</div>' +
|
||||
'<div class="psa-dir-loader" style="display:none;">' +
|
||||
'<div class="psa-spinner"></div>' +
|
||||
'<p>' + esc(i18n.loading) + '</p>' +
|
||||
'</div>' +
|
||||
'</div>' +
|
||||
'<div class="psa-dir-load-more-wrap" style="display:none;">' +
|
||||
'<button class="psa-dir-load-more">' + esc(i18n.loadMore) + '</button>' +
|
||||
'</div>' +
|
||||
'<div class="psa-dir-modal" role="dialog" aria-modal="true" aria-label="Peptide details" style="display:none;">' +
|
||||
'<div class="psa-dir-modal__backdrop"></div>' +
|
||||
'<div class="psa-dir-modal__content" tabindex="-1"></div>' +
|
||||
'</div>';
|
||||
|
||||
renderFilters();
|
||||
bindEvents();
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Render — Filters
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
function renderFilters() {
|
||||
var wrap = root.querySelector('.psa-dir-filters');
|
||||
var html = '<button class="psa-dir-filter psa-dir-filter--active" data-category="">' + esc(i18n.showAll) + '</button>';
|
||||
config.categories.forEach(function (cat) {
|
||||
html += '<button class="psa-dir-filter" data-category="' + esc(cat.slug) + '">' + esc(cat.name) + '</button>';
|
||||
});
|
||||
wrap.innerHTML = html;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Render — Grid
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
function renderGrid() {
|
||||
var grid = root.querySelector('.psa-dir-grid');
|
||||
var empty = root.querySelector('.psa-dir-empty');
|
||||
var loader = root.querySelector('.psa-dir-loader');
|
||||
var coming = root.querySelector('.psa-dir-coming-soon');
|
||||
|
||||
loader.style.display = 'none';
|
||||
coming.style.display = 'none';
|
||||
|
||||
if (state.activeTab === 'protocols') {
|
||||
grid.style.display = 'none';
|
||||
empty.style.display = 'none';
|
||||
coming.style.display = 'block';
|
||||
updateLoadMoreBtn();
|
||||
return;
|
||||
}
|
||||
|
||||
grid.style.display = '';
|
||||
|
||||
if (state.compounds.length === 0 && !state.loading) {
|
||||
empty.style.display = 'block';
|
||||
grid.innerHTML = '';
|
||||
updateLoadMoreBtn();
|
||||
return;
|
||||
}
|
||||
|
||||
empty.style.display = 'none';
|
||||
|
||||
var html = '';
|
||||
state.compounds.forEach(function (c) {
|
||||
var catBadge = '';
|
||||
if (c.categories && c.categories.length > 0) {
|
||||
catBadge = '<span class="psa-dir-card__badge psa-dir-badge--' + esc(c.categories[0].slug) + '">' + esc(c.categories[0].name) + '</span>';
|
||||
}
|
||||
|
||||
var metaHtml = '';
|
||||
if (c.half_life) {
|
||||
metaHtml += '<div class="psa-dir-card__meta-item"><span class="psa-dir-card__meta-label">' + esc(i18n.halfLife) + '</span><span class="psa-dir-card__meta-value">' + esc(c.half_life) + '</span></div>';
|
||||
}
|
||||
if (c.stability) {
|
||||
metaHtml += '<div class="psa-dir-card__meta-item"><span class="psa-dir-card__meta-label">' + esc(i18n.stability) + '</span><span class="psa-dir-card__meta-value">' + esc(c.stability) + '</span></div>';
|
||||
}
|
||||
|
||||
var extrasHtml = c.extras ? c.extras : '';
|
||||
|
||||
html += '<div class="psa-dir-card" role="listitem" data-id="' + c.id + '">' +
|
||||
'<div class="psa-dir-card__header">' +
|
||||
'<h3 class="psa-dir-card__title">' + esc(c.name) + '</h3>' +
|
||||
catBadge +
|
||||
'</div>' +
|
||||
(metaHtml ? '<div class="psa-dir-card__meta">' + metaHtml + '</div>' : '') +
|
||||
extrasHtml +
|
||||
'<button class="psa-dir-card__btn" data-id="' + c.id + '">' + esc(i18n.viewDetails) + '</button>' +
|
||||
'</div>';
|
||||
});
|
||||
|
||||
grid.innerHTML = html;
|
||||
updateLoadMoreBtn();
|
||||
}
|
||||
|
||||
function updateLoadMoreBtn() {
|
||||
var wrap = root.querySelector('.psa-dir-load-more-wrap');
|
||||
var btn = root.querySelector('.psa-dir-load-more');
|
||||
|
||||
if (state.activeTab === 'protocols' || state.page >= state.totalPages || state.compounds.length === 0) {
|
||||
wrap.style.display = 'none';
|
||||
} else {
|
||||
wrap.style.display = 'block';
|
||||
btn.textContent = state.loading ? i18n.loading : i18n.loadMore;
|
||||
btn.disabled = state.loading;
|
||||
}
|
||||
}
|
||||
|
||||
function renderError() {
|
||||
state.loading = false;
|
||||
var grid = root.querySelector('.psa-dir-grid');
|
||||
grid.innerHTML = '<p class="psa-dir-error">Failed to load directory. Please try again.</p>';
|
||||
root.querySelector('.psa-dir-loader').style.display = 'none';
|
||||
updateLoadMoreBtn();
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Render — Modal
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
function openModal(compound) {
|
||||
state.modalData = compound;
|
||||
var modal = root.querySelector('.psa-dir-modal');
|
||||
var content = root.querySelector('.psa-dir-modal__content');
|
||||
|
||||
var catBadges = '';
|
||||
if (compound.categories) {
|
||||
compound.categories.forEach(function (cat) {
|
||||
catBadges += '<span class="psa-dir-card__badge psa-dir-badge--' + esc(cat.slug) + '">' + esc(cat.name) + '</span> ';
|
||||
});
|
||||
}
|
||||
|
||||
var dataGrid = '';
|
||||
var fields = [
|
||||
{ label: i18n.solubility, value: compound.solubility },
|
||||
{ label: i18n.vialSize, value: compound.vial_size_mg ? compound.vial_size_mg + ' mg' : '' },
|
||||
{ label: i18n.storageLyo, value: compound.storage_lyophilized },
|
||||
{ label: i18n.storageRecon, value: compound.storage_reconstituted },
|
||||
{ label: i18n.halfLife, value: compound.half_life },
|
||||
{ label: i18n.stability, value: compound.stability },
|
||||
{ label: i18n.molecularWeight, value: compound.molecular_weight },
|
||||
{ label: i18n.formula, value: compound.molecular_formula }
|
||||
];
|
||||
fields.forEach(function (f) {
|
||||
if (f.value) {
|
||||
dataGrid += '<div class="psa-dir-modal__data-item">' +
|
||||
'<span class="psa-dir-modal__data-label">' + esc(f.label) + '</span>' +
|
||||
'<span class="psa-dir-modal__data-value">' + esc(f.value) + '</span>' +
|
||||
'</div>';
|
||||
}
|
||||
});
|
||||
|
||||
var researchHtml = '';
|
||||
if (compound.typical_dose_mcg || compound.cycle_parameters) {
|
||||
researchHtml = '<div class="psa-dir-modal__section">' +
|
||||
'<h4>' + esc(i18n.researchParams) + '</h4>';
|
||||
if (compound.typical_dose_mcg) {
|
||||
researchHtml += '<p><strong>' + esc(i18n.typicalDose) + ':</strong> ' + esc(compound.typical_dose_mcg) + '</p>';
|
||||
}
|
||||
if (compound.cycle_parameters) {
|
||||
researchHtml += '<p><strong>' + esc(i18n.cycleParams) + ':</strong> ' + esc(compound.cycle_parameters) + '</p>';
|
||||
}
|
||||
researchHtml += '</div>';
|
||||
}
|
||||
|
||||
var pubchemHtml = '';
|
||||
if (compound.pubchem_cid) {
|
||||
pubchemHtml = '<a class="psa-dir-modal__pubchem" href="https://pubchem.ncbi.nlm.nih.gov/compound/' + parseInt(compound.pubchem_cid, 10) + '" target="_blank" rel="noopener">' + esc(i18n.pubchemLink) + '</a>';
|
||||
}
|
||||
|
||||
var sequenceHtml = '';
|
||||
if (compound.sequence) {
|
||||
sequenceHtml = '<div class="psa-dir-modal__section">' +
|
||||
'<h4>' + esc(i18n.sequence) + '</h4>' +
|
||||
'<div class="psa-dir-modal__sequence-wrap">' +
|
||||
'<code class="psa-dir-modal__sequence">' + esc(compound.sequence) + '</code>' +
|
||||
'<button class="psa-dir-modal__copy" data-seq="' + esc(compound.sequence) + '">' + esc(i18n.copySequence) + '</button>' +
|
||||
'</div>' +
|
||||
'</div>';
|
||||
}
|
||||
|
||||
var mechanismHtml = '';
|
||||
if (compound.mechanism) {
|
||||
mechanismHtml = '<div class="psa-dir-modal__section">' +
|
||||
'<h4>Mechanism of Action</h4>' +
|
||||
'<p>' + esc(compound.mechanism).replace(/\n\n/g, '</p><p>').replace(/\n/g, '<br>') + '</p>' + // Safe: esc() HTML-encodes all user content before structural tags are inserted.
|
||||
|
||||
'</div>';
|
||||
}
|
||||
|
||||
content.innerHTML =
|
||||
'<button class="psa-dir-modal__close" aria-label="' + esc(i18n.close) + '">×</button>' +
|
||||
'<h2 class="psa-dir-modal__title">' + esc(compound.name) + '</h2>' +
|
||||
'<div class="psa-dir-modal__badges">' + catBadges + '</div>' +
|
||||
(compound.description ? '<p class="psa-dir-modal__desc">' + esc(compound.description) + '</p>' : '') +
|
||||
sequenceHtml +
|
||||
(dataGrid ? '<div class="psa-dir-modal__data-grid">' + dataGrid + '</div>' : '') +
|
||||
researchHtml +
|
||||
mechanismHtml +
|
||||
pubchemHtml +
|
||||
'<a class="psa-dir-modal__full-link" href="' + esc(compound.url) + '">' + esc(i18n.viewFullPage) + '</a>';
|
||||
|
||||
modal.style.display = 'flex';
|
||||
content.focus();
|
||||
|
||||
// Update URL hash for direct linking.
|
||||
if (compound.slug) {
|
||||
history.replaceState(null, '', '#' + compound.slug);
|
||||
}
|
||||
|
||||
// Fire integration hook for Peptide Community.
|
||||
document.dispatchEvent(new CustomEvent('psa_after_peptide_detail', {
|
||||
detail: { postId: compound.id }
|
||||
}));
|
||||
}
|
||||
|
||||
function closeModal() {
|
||||
var modal = root.querySelector('.psa-dir-modal');
|
||||
modal.style.display = 'none';
|
||||
state.modalData = null;
|
||||
history.replaceState(null, '', window.location.pathname + window.location.search);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Events
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
function bindEvents() {
|
||||
// Search input.
|
||||
var searchInput = root.querySelector('.psa-dir-search');
|
||||
var debouncedSearch = debounce(function () {
|
||||
state.search = searchInput.value.trim();
|
||||
state.page = 1;
|
||||
showLoader();
|
||||
fetchCompounds(false);
|
||||
}, 400);
|
||||
searchInput.addEventListener('input', debouncedSearch);
|
||||
|
||||
// Category filter buttons.
|
||||
root.querySelector('.psa-dir-filters').addEventListener('click', function (e) {
|
||||
var btn = e.target.closest('.psa-dir-filter');
|
||||
if (!btn) return;
|
||||
|
||||
root.querySelectorAll('.psa-dir-filter').forEach(function (b) {
|
||||
b.classList.remove('psa-dir-filter--active');
|
||||
});
|
||||
btn.classList.add('psa-dir-filter--active');
|
||||
|
||||
state.category = btn.getAttribute('data-category');
|
||||
state.page = 1;
|
||||
showLoader();
|
||||
fetchCompounds(false);
|
||||
});
|
||||
|
||||
// Tab buttons.
|
||||
root.querySelector('.psa-dir-tabs').addEventListener('click', function (e) {
|
||||
var btn = e.target.closest('.psa-dir-tab');
|
||||
if (!btn) return;
|
||||
|
||||
root.querySelectorAll('.psa-dir-tab').forEach(function (b) {
|
||||
b.classList.remove('psa-dir-tab--active');
|
||||
b.setAttribute('aria-selected', 'false');
|
||||
});
|
||||
btn.classList.add('psa-dir-tab--active');
|
||||
btn.setAttribute('aria-selected', 'true');
|
||||
|
||||
state.activeTab = btn.getAttribute('data-tab');
|
||||
renderGrid();
|
||||
});
|
||||
|
||||
// Load More button.
|
||||
root.querySelector('.psa-dir-load-more').addEventListener('click', function () {
|
||||
state.page++;
|
||||
fetchCompounds(true);
|
||||
});
|
||||
|
||||
// Card "View Research Details" button — delegate on grid.
|
||||
root.querySelector('.psa-dir-grid').addEventListener('click', function (e) {
|
||||
var btn = e.target.closest('.psa-dir-card__btn');
|
||||
if (!btn) return;
|
||||
var id = parseInt(btn.getAttribute('data-id'), 10);
|
||||
fetchCompoundDetail(id, function (compound) {
|
||||
if (compound) openModal(compound);
|
||||
});
|
||||
});
|
||||
|
||||
// Modal close: X button, backdrop click, Escape key.
|
||||
root.querySelector('.psa-dir-modal').addEventListener('click', function (e) {
|
||||
if (e.target.classList.contains('psa-dir-modal__backdrop') || e.target.classList.contains('psa-dir-modal__close')) {
|
||||
closeModal();
|
||||
}
|
||||
});
|
||||
|
||||
document.addEventListener('keydown', function (e) {
|
||||
if (e.key === 'Escape' && state.modalData) {
|
||||
closeModal();
|
||||
}
|
||||
});
|
||||
|
||||
// Copy sequence button.
|
||||
root.addEventListener('click', function (e) {
|
||||
var copyBtn = e.target.closest('.psa-dir-modal__copy');
|
||||
if (!copyBtn) return;
|
||||
var seq = copyBtn.getAttribute('data-seq');
|
||||
navigator.clipboard.writeText(seq).then(function () {
|
||||
copyBtn.textContent = i18n.copied;
|
||||
setTimeout(function () { copyBtn.textContent = i18n.copySequence; }, 2000);
|
||||
});
|
||||
});
|
||||
|
||||
// Check URL hash on load for direct modal linking.
|
||||
checkUrlHash();
|
||||
}
|
||||
|
||||
function showLoader() {
|
||||
var grid = root.querySelector('.psa-dir-grid');
|
||||
var loader = root.querySelector('.psa-dir-loader');
|
||||
var empty = root.querySelector('.psa-dir-empty');
|
||||
grid.innerHTML = '';
|
||||
empty.style.display = 'none';
|
||||
loader.style.display = 'block';
|
||||
}
|
||||
|
||||
/**
|
||||
* If URL has a hash like #bpc-157, find the matching compound and open modal.
|
||||
*/
|
||||
function checkUrlHash() {
|
||||
var hash = window.location.hash.replace('#', '');
|
||||
if (!hash) return;
|
||||
/* Wait for initial load, then look for matching slug. */
|
||||
var checkInterval = setInterval(function () {
|
||||
if (state.loading) return;
|
||||
clearInterval(checkInterval);
|
||||
for (var i = 0; i < state.compounds.length; i++) {
|
||||
if (state.compounds[i].slug === hash) {
|
||||
openModal(state.compounds[i]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}, 200);
|
||||
/* Safety: stop checking after 5 seconds. */
|
||||
setTimeout(function () { clearInterval(checkInterval); }, 5000);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Init
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
if (document.readyState === 'loading') {
|
||||
document.addEventListener('DOMContentLoaded', init);
|
||||
} else {
|
||||
init();
|
||||
}
|
||||
|
||||
function init() {
|
||||
renderShell();
|
||||
showLoader();
|
||||
fetchCompounds(false);
|
||||
}
|
||||
|
||||
})();
|
||||
Reference in New Issue
Block a user