(url, metadata, push)
| 341 | |
| 342 | let bittyLink = undefined; |
| 343 | function updateLink(url, metadata, push) { |
| 344 | |
| 345 | let title = metadata.title; |
| 346 | |
| 347 | let includeMetadata = !metadata.includeMetadata; |
| 348 | let path = includeMetadata ? "/" : bitty.metadataToPath(metadata) ?? "/"; |
| 349 | let prefix = includeMetadata ? bitty.encodePrettyComponent(title) : ""; |
| 350 | |
| 351 | if (url.length) { |
| 352 | url = path + "#" + prefix + "/" + url; |
| 353 | } else { |
| 354 | url = "/edit"; |
| 355 | } |
| 356 | |
| 357 | document.getElementById("doc-title-text").innerText = title.length ? title : ""; |
| 358 | |
| 359 | bittyLink = new URL(url, document.location).href; |
| 360 | |
| 361 | document.getElementById("canonical").href = bittyLink; |
| 362 | |
| 363 | if(previewContent) { |
| 364 | console.log("previewing", bittyLink); |
| 365 | QS("#preview-frame").src = bittyLink; |
| 366 | } |
| 367 | |
| 368 | var hash = location.hash; |
| 369 | if (true) { |
| 370 | if (push || !hash || !hash.length) { |
| 371 | window.history.pushState(null, null, bittyLink); |
| 372 | } else { |
| 373 | window.history.replaceState(null, null, bittyLink); |
| 374 | } |
| 375 | } |
| 376 | |
| 377 | var length = bittyLink.length; |
| 378 | |
| 379 | QS("#length").innerText = length + " bytes"; |
| 380 | QS("#length").onclick = () => { |
| 381 | window.open(bittyLink, "_blank"); |
| 382 | } |
| 383 | for (var key in maxLengths) { |
| 384 | var maxLength = maxLengths[key]; |
| 385 | if (length > maxLength) { |
| 386 | QS(key).classList.add("invalid"); |
| 387 | } else { |
| 388 | QS(key).classList.remove("invalid"); |
| 389 | } |
| 390 | } |
| 391 | } |
| 392 | |
| 393 | function share() { |
| 394 | navigator.share({ |
no test coverage detected