* $Id$
*
* Written by Keith Marshall <keith@users.osdn.me>
- * 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
*/
var element = document.getElementById( item );
if( element ) element.innerHTML = value;
+ return element;
+}
+
+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.
+ */
+ if( title == "title" ) document.title = text;
+ set_content( "page-".concat( title ), text.replace( /-/g, "‑" ));
}
function load_content( container, src )
{ if( this.readyState == this.DONE )
switch( this.status )
{ case 200:
- set_content( container, this.responseText );
+ 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" );
request_handler.send();
}
-function load_page_content( src, subtitle )
-{ /* Propagate the HTML document title to the "masthead" display,
- * update the displayed page subtitle, (which may be null), and
- * load the page content from the specified "src" file.
- */
- set_content( "page-content", null );
- set_content( "page-title", document.title );
- set_content( "page-subtitle", subtitle );
- load_content( "page-content", src );
-}
-
-function load_page_overlay( src, title, subtitle )
-{ /* Replace the existing page content from the specified overlay
- * "src" file, updating the page title, and subtitle, as may be
- * appropriate.
- */
- if( title ) document.title = title;
- load_page_content( src, subtitle );
-}
-
-function new_page( src, subtitle )
-{ /* Create a new page display, starting from scratch; assign the
- * displayed title from the HTML document title attribute, adding
- * the specified subtitle, lay out the standard page header block,
- * and load the page content from the "src" file.
+function load_page( src )
+{ /* Load page content from the HTML fragment file, as determined
+ * from the specified "src" URL; if no alternative fragment name
+ * is specified, fall back to loading "about.html".
*/
+ const ref = "?page=";
+ const div = "page-content";
+ set_content( div, null );
load_content( "header", "header.html" );
- load_page_content( src, subtitle );
+ if( src.includes( ref ) )
+ src = src.substring( src.indexOf( ref ) + ref.length, src.length );
+ else src = "about.html";
+ load_content( div, src );
}
/* $RCSfile$: end of file */