Widget:UPDateOnline: Difference between revisions
Appearance
No edit summary |
No edit summary |
||
| Line 51: | Line 51: | ||
/* | /* | ||
* Get the latest UPDate Online article. | * Get the latest UPDate Online article. | ||
*/ | */ | ||
| Line 88: | Line 84: | ||
/* | /* | ||
* ----------------------------- | * -------------------------------- | ||
* TITLE | * TITLE | ||
* ----------------------------- | * -------------------------------- | ||
*/ | */ | ||
| Line 100: | Line 96: | ||
/* | /* | ||
* ----------------------------- | * -------------------------------- | ||
* EXCERPT | * EXCERPT | ||
* ----------------------------- | * -------------------------------- | ||
*/ | */ | ||
| Line 112: | Line 108: | ||
/* | /* | ||
* ----------------------------- | * -------------------------------- | ||
* ARTICLE LINK | * ARTICLE LINK | ||
* ----------------------------- | * -------------------------------- | ||
*/ | */ | ||
| Line 124: | Line 120: | ||
/* | /* | ||
* ----------------------------- | * -------------------------------- | ||
* DATE | * DATE | ||
* ----------------------------- | * -------------------------------- | ||
*/ | */ | ||
| Line 145: | Line 141: | ||
/* | /* | ||
* ----------------------------- | * -------------------------------- | ||
* FIND FIRST | * FIND FIRST IMAGE AFTER | ||
* ----------------------------- | * THE FIRST PARAGRAPH | ||
* -------------------------------- | |||
*/ | */ | ||
| Line 157: | Line 154: | ||
var firstImage = | /* | ||
* Find the first paragraph | |||
*/ | |||
var firstParagraph = | |||
temp.querySelector('p'); | |||
var firstImage = null; | |||
if (firstParagraph) { | |||
/* | |||
* Look through everything that | |||
* comes AFTER the first paragraph. | |||
*/ | |||
var current = | |||
firstParagraph.nextElementSibling; | |||
while (current) { | |||
/* | |||
* Check whether this element | |||
* itself contains an image. | |||
*/ | |||
if ( | |||
current.tagName && | |||
current.tagName.toLowerCase() === 'img' | |||
) { | |||
firstImage = | |||
current; | |||
break; | |||
} | |||
/* | |||
* Check for an image inside | |||
* this element. | |||
*/ | |||
var image = | |||
current.querySelector('img'); | |||
if (image) { | |||
firstImage = | |||
image; | |||
break; | |||
} | |||
current = | |||
current.nextElementSibling; | |||
} | |||
} | |||
/* | |||
* -------------------------------- | |||
* DISPLAY THE IMAGE | |||
* -------------------------------- | |||
*/ | |||
if (firstImage) { | if (firstImage) { | ||
| Line 170: | Line 236: | ||
/* | /* | ||
* | * Use the actual image URL. | ||
*/ | */ | ||
| Line 178: | Line 244: | ||
/* | /* | ||
* Use | * Use existing alt text if | ||
* | * available. | ||
*/ | */ | ||
| Line 186: | Line 252: | ||
post.title.rendered; | post.title.rendered; | ||
} | |||
else { | |||
/* | /* | ||
* No image found | * No image found after the | ||
* | * opening paragraph. | ||
*/ | */ | ||
| Line 203: | Line 270: | ||
/* | /* | ||
* ----------------------------- | * -------------------------------- | ||
* SHOW ARTICLE | * SHOW ARTICLE | ||
* ----------------------------- | * -------------------------------- | ||
*/ | */ | ||
| Line 223: | Line 290: | ||
/* | /* | ||
* ----------------------------- | * -------------------------------- | ||
* ERROR HANDLING | * ERROR HANDLING | ||
* ----------------------------- | * -------------------------------- | ||
*/ | */ | ||
| Line 243: | Line 310: | ||
</includeonly> | </includeonly> | ||
<noinclude> | <noinclude> | ||
| Line 249: | Line 317: | ||
Displays the latest UPDate Online article and | Displays the latest UPDate Online article and | ||
the first image appearing | the first image appearing after the opening paragraph. | ||
=== Usage === | === Usage === | ||
Revision as of 23:18, 6 October 2026
UPDate Online Widget
Displays the latest UPDate Online article and the first image appearing after the opening paragraph.
Usage
{{#widget:UPDateOnline}}