יצירת איזור בעמוד המוגן בסיסמא
במדריך זה נלמד איך ליצור חלק תוכן בעמוד המוגן בסיסמא
לדוגמא אם אנחנו רוצים לתת גישה לצפייה בתמונה או בתוכן מסוים רק למי שמחזיק בסיסמא או בקוד קופון
בדוגמא הבאה יש סרטון וידאו שיוצר רק למי שיזין את הסיסמא 1234
נסו זאת כאן:

להלן הסקריפט יש לשנות את הסיסמא בשורה 5
וכן יש לתת לאלמנט או לקונטיינר שרוצים להסתיר את הקלאס "hide-kedem"
// קוד הגנה בסיסמא לווידג'טים באלמנטור
document.addEventListener('DOMContentLoaded', function() {
// הגדרות בסיסיות
const correctPassword = '1234'; // שנה את הסיסמא כאן
const protectedClass = 'hide-kedem'; // הקלאס של הווידג'טים המוגנים
// מוצא את כל הווידג'טים המוגנים
const protectedWidgets = document.querySelectorAll('.' + protectedClass);
protectedWidgets.forEach(function(widget, index) {
// שומר את התוכן המקורי של הווידג'ט
const originalContent = widget.innerHTML;
// יוצר טופס סיסמא במקום התוכן
const passwordFormHTML = `
🔒 תוכן מוגן
יש להזין סיסמא כדי לצפות בתוכן
הסיסמא שגויה - נסה שוב
`;
// מחליף את התוכן בטופס
widget.innerHTML = passwordFormHTML;
// מוסיף אפשרות ללחוץ Enter
const passwordInput = widget.querySelector(`#password-input-${index}`);
passwordInput.addEventListener('keypress', function(e) {
if (e.key === 'Enter') {
checkPasswordKedem(index);
}
});
// שומר את הנתונים בגלובל
window.kedemProtectedData = window.kedemProtectedData || {};
window.kedemProtectedData[index] = {
widget: widget,
originalContent: originalContent,
correctPassword: correctPassword
};
});
});
// פונקציה לבדיקת הסיסמא
function checkPasswordKedem(index) {
const data = window.kedemProtectedData[index];
const passwordInput = data.widget.querySelector(`#password-input-${index}`);
const errorMessage = data.widget.querySelector(`#error-message-${index}`);
const enteredPassword = passwordInput.value.trim();
// מסתיר הודעת שגיאה קודמת
errorMessage.style.display = 'none';
if (enteredPassword === data.correctPassword) {
// הסיסמא נכונה - מחזיר את התוכן המקורי
data.widget.innerHTML = data.originalContent;
// אפקט הופעה חלקה
data.widget.style.opacity = '0';
setTimeout(function() {
data.widget.style.transition = 'opacity 0.6s ease-in-out';
data.widget.style.opacity = '1';
}, 100);
} else {
// הסיסמא שגויה
errorMessage.style.display = 'block';
passwordInput.value = '';
passwordInput.focus();
// אפקט רעידה
passwordInput.style.animation = 'kedem-shake 0.6s ease-in-out';
setTimeout(function() {
passwordInput.style.animation = '';
}, 600);
}
}
// מוסיף CSS לאנימציה
const shakeCSS = document.createElement('style');
shakeCSS.textContent = `
@keyframes kedem-shake {
0%, 100% { transform: translateX(0); }
10%, 30%, 50%, 70%, 90% { transform: translateX(-8px); }
20%, 40%, 60%, 80% { transform: translateX(8px); }
}
`;
document.head.appendChild(shakeCSS);