OSDN Git Service

Move charset assignment to valid file offset.
[mingw/website.git] / site.js
1 /*
2  * site.js
3  *
4  * General purpose functions for manipulation of page content.
5  *
6  *
7  * $Id$
8  *
9  * Written by Keith Marshall <keith@users.osdn.me>
10  * Copyright (C) 2020, MinGW.org Project
11  *
12  *
13  * Permission is hereby granted, free of charge, to any person obtaining a
14  * copy of this software and associated documentation files (the "Software"),
15  * to deal in the Software without restriction, including without limitation
16  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
17  * and/or sell copies of the Software, and to permit persons to whom the
18  * Software is furnished to do so, subject to the following conditions:
19  *
20  * The above copyright notice, this permission notice, and the following
21  * disclaimer shall be included in all copies or substantial portions of
22  * the Software.
23  *
24  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
27  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OF OR OTHER
30  * DEALINGS IN THE SOFTWARE.
31  *
32  */
33 function set_content( item, value )
34 { /* Replace the existing content, if any, of the HTML element with
35    * id attribute named "item", (if such an element exists), with new
36    * content as specified by "value".
37    */
38   var element = document.getElementById( item );
39   if( element ) element.innerHTML = value;
40 }
41
42 function load_content( container, src )
43 { /* Set the content of the specified HTML "container" element, by
44    * injection of the entire contents of an external file which is
45    * fetched by http server request; (either an http, or an https,
46    * server connection is required; does not work for local files).
47    */
48   var request_handler = new XMLHttpRequest();
49   request_handler.onreadystatechange = function()
50   { if( this.readyState == this.DONE )
51       switch( this.status )
52       { case 200:
53           set_content( container, this.responseText );
54           break;
55         case 404:
56           load_content( container, "missing.html" );
57       }
58   }
59   request_handler.open( "GET", src, true );
60   request_handler.send();
61 }
62
63 function load_page_content( src, subtitle )
64 { /* Propagate the HTML document title to the "masthead" display,
65    * update the displayed page subtitle, (which may be null), and
66    * load the page content from the specified "src" file.
67    */
68   set_content( "page-content", null );
69   set_content( "page-title", document.title );
70   set_content( "page-subtitle", subtitle );
71   load_content( "page-content", src );
72 }
73
74 function load_page_overlay( src, title, subtitle )
75 { /* Replace the existing page content from the specified overlay
76    * "src" file, updating the page title, and subtitle, as may be
77    * appropriate.
78    */
79   if( title ) document.title = title;
80   load_page_content( src, subtitle );
81 }
82
83 function new_page( src, subtitle )
84 { /* Create a new page display, starting from scratch; assign the
85    * displayed title from the HTML document title attribute, adding
86    * the specified subtitle, lay out the standard page header block,
87    * and load the page content from the "src" file.
88    */
89   load_content( "header", "header.html" );
90   load_page_content( src, subtitle );
91 }
92
93 /* $RCSfile$: end of file */