X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=site.js;h=17599e495e4bcafda481ef71f87b8bd63c632774;hb=aa687c72a815bb0c10a1f2040e4a53e4395d3605;hp=1a7c3680bd6cc09a16ab386dc3c924d2e1717a83;hpb=98be686d2e65698f502c6ab4521bc0535216d7e1;p=mingw%2Fwebsite.git diff --git a/site.js b/site.js index 1a7c368..17599e4 100644 --- a/site.js +++ b/site.js @@ -7,7 +7,7 @@ * $Id$ * * Written by Keith Marshall - * Copyright (C) 2020, MinGW.org Project + * Copyright (C) 2020, 2021, MinGW.OSDN Project * * * Permission is hereby granted, free of charge, to any person obtaining a @@ -37,25 +37,18 @@ function set_content( item, value ) */ var element = document.getElementById( item ); if( element ) element.innerHTML = value; + return element; } -function no_break( text ) -{ /* Helper function to replace all occurrences of ASCII hyphen-minus, - * within "text", by substitution of HTML non-breaking hyphen. +function set_page( title, text ) +{ /* Helper function, for use in overlay page scripts, to update + * the "title" and "subtitle" fields within the page header; note + * that "text" may, and should, use ASCII hyphen-minus where any + * hyphen is to be represented; these will be replaced by HTML + * non-breaking hyphen entities, on header field assignment. */ - return text.replace( /-/g, "‑" ); -} - -function update_page_content_header( tag ) -{ /* Update the "page-title" and "page-subtitle" content-header text, - * by substitution into the "as-page-title" and "as-page-subtitle" - * place-holder elements, respectively. - */ - var element = document.getElementById( "page-".concat( tag )); - if( element ) - { if( tag == "title" ) document.title = element.innerHTML; - set_content( "as-page-".concat( tag ), no_break( element.innerHTML )); - } + if( title == "title" ) document.title = text; + set_content( "page-".concat( title ), text.replace( /-/g, "‑" )); } function load_content( container, src ) @@ -69,10 +62,18 @@ function load_content( container, src ) { if( this.readyState == this.DONE ) switch( this.status ) { case 200: - set_content( container, this.responseText ); - update_page_content_header( "title" ); - update_page_content_header( "subtitle" ); + var element = set_content( container, this.responseText ); + var idx; element = element.getElementsByTagName( "script" ); set_content( "e404-missing-page", document.URL ); + for( idx = 0; idx < element.length; idx++ ) + { var onload_action = Function( element[idx].innerHTML ); + onload_action(); + } + if( src.includes("#") ) + { src = src.substring( src.indexOf("#") + 1, src.length ); + element = document.getElementById( src ); + if( element ) element.scrollIntoView(); + } break; case 404: load_content( container, "missing.html" );