|
| 1 | +{{ $url := .Get "url" | default "#" }} {{ $title := .Get "title" | default |
| 2 | +"Visit Website" }} {{ $time := .Get "time" | default 5 }} {{/* Generate a unique |
| 3 | +ID for each modal to avoid conflicts */}} {{ $modalId := printf "lb-modal-%d" |
| 4 | +(math.Counter) }} |
| 5 | + |
| 6 | +<button class="lb-btn" data-modal-target="#{{ $modalId }}"> |
| 7 | + <svg |
| 8 | + xmlns="http://www.w3.org/2000/svg" |
| 9 | + width="16" |
| 10 | + height="16" |
| 11 | + fill="currentColor" |
| 12 | + viewBox="0 0 16 16" |
| 13 | + > |
| 14 | + <path |
| 15 | + fill-rule="evenodd" |
| 16 | + d="M8.636 3.5a.5.5 0 0 0-.5-.5H1.5A1.5 1.5 0 0 0 0 4.5v10A1.5 1.5 0 0 0 1.5 16h10a1.5 1.5 0 0 0 1.5-1.5V7.864a.5.5 0 0 0-1 0V14.5a.5.5 0 0 1-.5-.5h-10a.5.5 0 0 1-.5-.5v-10a.5.5 0 0 1 .5-.5h6.636a.5.5 0 0 0 .5-.5z" |
| 17 | + /> |
| 18 | + <path |
| 19 | + fill-rule="evenodd" |
| 20 | + d="M16 1.5a.5.5 0 0 0-.5-.5h-5a.5.5 0 0 0 0 1h3.793L6.146 9.146a.5.5 0 1 0 .708.708L15 2.707V6.5a.5.5 0 0 0 1 0v-5z" |
| 21 | + /> |
| 22 | + </svg> |
| 23 | + {{ $title }} |
| 24 | +</button> |
| 25 | + |
| 26 | +<div |
| 27 | + class="lb-modal-overlay" |
| 28 | + id="{{ $modalId }}" |
| 29 | + data-url="{{ $url }}" |
| 30 | + data-time="{{ $time }}" |
| 31 | +> |
| 32 | + <div class="lb-modal-content"> |
| 33 | + {{ partial "google/blog-in-feed-ad.html" . }} |
| 34 | + <h2 class="lb-modal-title">{{ $title }}</h2> |
| 35 | + <p class="lb-timer-message">Please wait a moment before proceeding...</p> |
| 36 | + |
| 37 | + <div class="lb-timer-wrapper"> |
| 38 | + <svg class="lb-timer-svg" width="120" height="120" viewBox="0 0 120 120"> |
| 39 | + <circle class="lb-timer-bg" cx="60" cy="60" r="54" /> |
| 40 | + <circle class="lb-timer-progress" cx="60" cy="60" r="54" /> |
| 41 | + </svg> |
| 42 | + <span class="lb-timer-text">{{ $time }}</span> |
| 43 | + </div> |
| 44 | + |
| 45 | + <a |
| 46 | + href="{{ $url }}" |
| 47 | + class="lb-btn lb-proceed-btn lb-hidden" |
| 48 | + target="_blank" |
| 49 | + rel="noopener noreferrer" |
| 50 | + > |
| 51 | + Download Movie |
| 52 | + </a> |
| 53 | + |
| 54 | + <button class="lb-modal-close" aria-label="Close modal">×</button> |
| 55 | + </div> |
| 56 | +</div> |
| 57 | + |
| 58 | +<style> |
| 59 | + /* assets/css/link-button.css */ |
| 60 | + |
| 61 | + :root { |
| 62 | + --lb-primary-color: #563d7c; /* A nice purple */ |
| 63 | + --lb-primary-hover: #463265; |
| 64 | + --lb-light-gray: #f0f0f0; |
| 65 | + --lb-dark-gray: #4a4a4a; |
| 66 | + --lb-modal-bg: #ffffff; |
| 67 | + --lb-overlay-bg: rgba(0, 0, 0, 0.65); |
| 68 | + } |
| 69 | + |
| 70 | + /* --- The Main & Proceed Buttons --- */ |
| 71 | + .lb-btn { |
| 72 | + display: flex; |
| 73 | + align-items: center; |
| 74 | + justify-content: center; |
| 75 | + gap: 8px; |
| 76 | + padding: 12px 24px; |
| 77 | + font-size: 16px; |
| 78 | + font-weight: 600; |
| 79 | + color: white; |
| 80 | + background-color: var(--lb-primary-color); |
| 81 | + border: none; |
| 82 | + border-radius: 8px; |
| 83 | + cursor: pointer; |
| 84 | + text-decoration: none; /* For the <a> tag */ |
| 85 | + transition: background-color 0.3s ease, transform 0.2s ease; |
| 86 | + box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); |
| 87 | + margin-top: 1rem; |
| 88 | + } |
| 89 | + |
| 90 | + .lb-btn:hover { |
| 91 | + background-color: var(--lb-primary-hover); |
| 92 | + transform: translateY(-2px); |
| 93 | + } |
| 94 | + |
| 95 | + /* --- The Modal --- */ |
| 96 | + .lb-modal-overlay { |
| 97 | + position: fixed; |
| 98 | + top: 0; |
| 99 | + left: 0; |
| 100 | + width: 100%; |
| 101 | + height: 100%; |
| 102 | + background-color: var(--lb-overlay-bg); |
| 103 | + display: flex; |
| 104 | + justify-content: center; |
| 105 | + align-items: center; |
| 106 | + z-index: 1000; |
| 107 | + opacity: 0; |
| 108 | + visibility: hidden; |
| 109 | + transition: opacity 0.3s ease, visibility 0.3s ease; |
| 110 | + } |
| 111 | + |
| 112 | + .lb-modal-overlay.active { |
| 113 | + opacity: 1; |
| 114 | + visibility: visible; |
| 115 | + } |
| 116 | + |
| 117 | + .lb-modal-content { |
| 118 | + background-color: var(--lb-modal-bg); |
| 119 | + padding: 30px 40px; |
| 120 | + border-radius: 12px; |
| 121 | + box-shadow: 0 5px 20px rgba(0, 0, 0, 0.2); |
| 122 | + text-align: center; |
| 123 | + max-width: 400px; |
| 124 | + width: 90%; |
| 125 | + position: relative; |
| 126 | + transform: scale(0.9); |
| 127 | + transition: transform 0.3s ease; |
| 128 | + } |
| 129 | + |
| 130 | + .lb-modal-overlay.active .lb-modal-content { |
| 131 | + transform: scale(1); |
| 132 | + } |
| 133 | + |
| 134 | + .lb-modal-title { |
| 135 | + margin-top: 0; |
| 136 | + margin-bottom: 10px; |
| 137 | + color: var(--lb-dark-gray); |
| 138 | + } |
| 139 | + .lb-timer-message { |
| 140 | + color: #6c757d; |
| 141 | + margin-bottom: 25px; |
| 142 | + } |
| 143 | + |
| 144 | + /* --- The Circular Timer --- */ |
| 145 | + .lb-timer-wrapper { |
| 146 | + position: relative; |
| 147 | + width: 120px; |
| 148 | + height: 120px; |
| 149 | + margin: 0 auto; |
| 150 | + } |
| 151 | + .lb-timer-svg { |
| 152 | + transform: rotate(-90deg); |
| 153 | + } |
| 154 | + .lb-timer-bg { |
| 155 | + fill: none; |
| 156 | + stroke: var(--lb-light-gray); |
| 157 | + stroke-width: 12; |
| 158 | + } |
| 159 | + .lb-timer-progress { |
| 160 | + fill: none; |
| 161 | + stroke: var(--lb-primary-color); |
| 162 | + stroke-width: 12; |
| 163 | + stroke-linecap: round; |
| 164 | + stroke-dasharray: 339.29; |
| 165 | + stroke-dashoffset: 339.29; |
| 166 | + transition: stroke-dashoffset 1s linear; |
| 167 | + } |
| 168 | + .lb-timer-text { |
| 169 | + position: absolute; |
| 170 | + top: 50%; |
| 171 | + left: 50%; |
| 172 | + transform: translate(-50%, -50%); |
| 173 | + font-size: 36px; |
| 174 | + font-weight: bold; |
| 175 | + color: var(--lb-primary-color); |
| 176 | + } |
| 177 | + |
| 178 | + /* --- Utility and Animation classes --- */ |
| 179 | + .lb-hidden { |
| 180 | + display: none !important; |
| 181 | + } |
| 182 | + |
| 183 | + .lb-proceed-btn { |
| 184 | + animation: fadeIn 0.5s ease-in-out; |
| 185 | + } |
| 186 | + |
| 187 | + @keyframes fadeIn { |
| 188 | + from { |
| 189 | + opacity: 0; |
| 190 | + transform: translateY(10px); |
| 191 | + } |
| 192 | + to { |
| 193 | + opacity: 1; |
| 194 | + transform: translateY(0); |
| 195 | + } |
| 196 | + } |
| 197 | + |
| 198 | + /* --- Close Button --- */ |
| 199 | + .lb-modal-close { |
| 200 | + position: absolute; |
| 201 | + top: 10px; |
| 202 | + right: 15px; |
| 203 | + background: none; |
| 204 | + border: none; |
| 205 | + font-size: 28px; |
| 206 | + color: #aaa; |
| 207 | + cursor: pointer; |
| 208 | + transition: color 0.2s ease; |
| 209 | + } |
| 210 | + |
| 211 | + .lb-modal-close:hover { |
| 212 | + color: #333; |
| 213 | + } |
| 214 | +</style> |
| 215 | + |
| 216 | +<script> |
| 217 | + // assets/js/link-button.js |
| 218 | + document.addEventListener("DOMContentLoaded", () => { |
| 219 | + let timerInterval = null; |
| 220 | + |
| 221 | + const startTimer = (duration, modal) => { |
| 222 | + let timer = duration; |
| 223 | + const display = modal.querySelector(".lb-timer-text"); |
| 224 | + const progressCircle = modal.querySelector(".lb-timer-progress"); |
| 225 | + const circumference = progressCircle.r.baseVal.value * 2 * Math.PI; |
| 226 | + progressCircle.style.strokeDasharray = circumference; |
| 227 | + |
| 228 | + const timerWrapper = modal.querySelector(".lb-timer-wrapper"); |
| 229 | + const timerMessage = modal.querySelector(".lb-timer-message"); |
| 230 | + const proceedButton = modal.querySelector(".lb-proceed-btn"); |
| 231 | + |
| 232 | + const updateTimer = () => { |
| 233 | + display.textContent = timer; |
| 234 | + const offset = circumference - (timer / duration) * circumference; |
| 235 | + progressCircle.style.strokeDashoffset = offset; |
| 236 | + |
| 237 | + if (--timer < 0) { |
| 238 | + clearInterval(timerInterval); |
| 239 | + // Hide timer and message |
| 240 | + timerWrapper.classList.add("lb-hidden"); |
| 241 | + timerMessage.classList.add("lb-hidden"); |
| 242 | + // Show the final button |
| 243 | + proceedButton.classList.remove("lb-hidden"); |
| 244 | + } |
| 245 | + }; |
| 246 | + |
| 247 | + updateTimer(); |
| 248 | + timerInterval = setInterval(updateTimer, 1000); |
| 249 | + }; |
| 250 | + |
| 251 | + const openModal = (modal) => { |
| 252 | + if (!modal) return; |
| 253 | + modal.classList.add("active"); |
| 254 | + |
| 255 | + // Reset the state every time the modal opens |
| 256 | + modal.querySelector(".lb-timer-wrapper").classList.remove("lb-hidden"); |
| 257 | + modal.querySelector(".lb-timer-message").classList.remove("lb-hidden"); |
| 258 | + modal.querySelector(".lb-proceed-btn").classList.add("lb-hidden"); |
| 259 | + |
| 260 | + const time = parseInt(modal.dataset.time, 10); |
| 261 | + clearInterval(timerInterval); |
| 262 | + startTimer(time, modal); |
| 263 | + }; |
| 264 | + |
| 265 | + const closeModal = (modal) => { |
| 266 | + if (!modal) return; |
| 267 | + modal.classList.remove("active"); |
| 268 | + clearInterval(timerInterval); |
| 269 | + }; |
| 270 | + |
| 271 | + document |
| 272 | + .querySelectorAll(".lb-btn[data-modal-target]") |
| 273 | + .forEach((button) => { |
| 274 | + button.addEventListener("click", () => { |
| 275 | + const modal = document.querySelector(button.dataset.modalTarget); |
| 276 | + openModal(modal); |
| 277 | + }); |
| 278 | + }); |
| 279 | + |
| 280 | + document.querySelectorAll(".lb-modal-overlay").forEach((overlay) => { |
| 281 | + overlay.addEventListener("click", (e) => { |
| 282 | + if (e.target === overlay) { |
| 283 | + closeModal(overlay); |
| 284 | + } |
| 285 | + }); |
| 286 | + }); |
| 287 | + |
| 288 | + document.querySelectorAll(".lb-modal-close").forEach((button) => { |
| 289 | + button.addEventListener("click", () => { |
| 290 | + const modal = button.closest(".lb-modal-overlay"); |
| 291 | + closeModal(modal); |
| 292 | + }); |
| 293 | + }); |
| 294 | + }); |
| 295 | +</script> |
0 commit comments