home *** CD-ROM | disk | FTP | other *** search
- // style.js: JavaScript file which uses Document Object Model
- // to set style of text in htmlpres HTML presentation template.
- // Created by Eric Krock, Netscape Communications.
- // Permission is granted to freely reuse and distribute this file.
- // Changes:
- // - 30 July 1997 backward compatibility with Nav3.0.
- // - 11 Sept 1997 font scaling in speakerNotes and tutorial modes
-
-
- // Calculates font size to be used for element, which is
- // the maximum of specified*sizeMultiplier and minAllowed.
- // Returns as string for storage in data structure fontSizeOf.
- function calcSize (specified, sizeMult, minOK)
- { return ( Math.max (Math.round(specified*sizeMult), minOK) + "pt" )
- }
-
-
- // Constructor function for object type fontSizeOf.
- // This object type holds the per-element size data
- // for the current screen size. A global variable,
- // fontSizeOf, is set to this object so that style
- // sheets in individual HTML pages can retrieve and
- // use this data.
-
- function constructFontSizeOf (h1, h2, h3, h4, h5, h6, titlepage, p, li, ul, ol, dl, dt, dd, blockquote, th, td, pre, tt, small, medium, large, sizeMult, minOK)
- { this.h1 = calcSize(h1, sizeMult, minOK)
- this.h2 = calcSize(h2, sizeMult, minOK)
- this.h3 = calcSize(h3, sizeMult, minOK)
- this.h4 = calcSize(h4, sizeMult, minOK)
- this.h5 = calcSize(h5, sizeMult, minOK)
- this.h6 = calcSize(h6, sizeMult, minOK)
- this.titlepage = calcSize(titlepage, sizeMult, minOK)
- this.p = calcSize(p, sizeMult, minOK)
- this.li = calcSize(li, sizeMult, minOK)
- /* BUG WORKAROUND: Shouldn't be necessary to set fontSize on UL and OL as
- well as LI, but setting LI fontSize doesn't work now. Setting on UL and OL
- is the workaround. */
- this.ul = calcSize(ul, sizeMult, minOK)
- this.ol = calcSize(ol, sizeMult, minOK)
- this.dl = calcSize(dl, sizeMult, minOK)
- this.dt = calcSize(dt, sizeMult, minOK)
- this.dd = calcSize(dd, sizeMult, minOK)
- this.blockquote = calcSize(blockquote, sizeMult, minOK)
- this.th = calcSize(th, sizeMult, minOK)
- this.td = calcSize(td, sizeMult, minOK)
- this.pre = calcSize(pre, sizeMult, minOK)
- this.tt = calcSize(tt, sizeMult, minOK)
- this.small = calcSize(small, sizeMult, minOK)
- this.medium = calcSize(medium, sizeMult, minOK)
- this.large = calcSize(large, sizeMult, minOK)
- }
-
-
- function setFontSizes (h1, h2, h3, h4, h5, h6, titlepage, p, li, ul, ol, dl, dt, dd, blockquote, th, td, pre, tt, small, medium, large, sizeMultiplier, minFontSize)
- { var fontSizeOf = new constructFontSizeOf (h1, h2, h3, h4, h5, h6, titlepage, p, li, ul, ol, dl, dt, dd, blockquote, th, td, pre, tt, small, medium, large, sizeMultiplier, minFontSize)
-
- document.tags.H1.fontSize = fontSizeOf.h1
- document.tags.H2.fontSize = fontSizeOf.h2
- document.tags.H3.fontSize = fontSizeOf.h3
- document.tags.H4.fontSize = fontSizeOf.h4
- document.tags.H5.fontSize = fontSizeOf.h5
- document.tags.H6.fontSize = fontSizeOf.h6
-
- document.tags.PRE.fontSize = fontSizeOf.pre
-
- document.tags.P.fontSize = fontSizeOf.p
-
- /* BUG WORKAROUND: Shouldn't be necessary to set fontSize on UL and OL as
- well as LI, but setting LI fontSize doesn't work now. Setting on UL and OL
- is the workaround. */
- document.tags.LI.fontSize = fontSizeOf.li
- document.tags.UL.fontSize = fontSizeOf.ul
- document.tags.OL.fontSize = fontSizeOf.ol
- document.tags.DL.fontSize = fontSizeOf.dl
- document.tags.DT.fontSize = fontSizeOf.dt
- document.tags.DD.fontSize = fontSizeOf.dd
- document.tags.BLOCKQUOTE.fontSize = fontSizeOf.blockquote
- document.tags.TH.fontSize = fontSizeOf.th
- document.tags.TD.fontSize = fontSizeOf.td
-
- document.classes.titlepage.all.fontSize = fontSizeOf.titlepage
-
- document.classes.small.all.fontSize = fontSizeOf.small
- document.classes.medium.all.fontSize = fontSizeOf.medium
- document.classes.large.all.fontSize = fontSizeOf.large
-
- document.classes.footnote.all.fontSize = fontSizeOf.small
-
- return fontSizeOf
- }
-
-
- // Global variables speakerNotesMode and tutorialMode determines
- // whether we are in:
- //
- // * speaker notes display mode (speaker mode text visible, all
- // text in smaller fonts so speaker notes fit on screen)
- // * tutorial mode (tutorial mode text visible, text in slightly
- // larger fonts for online viewing)
- // * normal mode (speaker mode text invisible because color is same
- // as backgroundcolor, all text in large fonts appropriate
- // for overhead display).
-
- var speakerNotesMode = false
- var tutorialMode = false
-
-
- // Adjust font sizes downward in speakerNotes and tutorial modes.
- var sizeMultiplier = 1.0 // default
- if (tutorialMode) sizeMultiplier = 0.79 // online viewing
- if (speakerNotesMode) sizeMultiplier = 0.55 // speaker preparation with notes
- var minFontSize = 12 // smallest ever displayed
-
-
- // Global variable fontSizeOf will store the per-element size data
- // for the current screen size so that style
- // sheets in individual HTML pages can retrieve and
- // use this data.
-
- var fontSizeOf
-
-
- // onLoad method
- function moveSpeakerNotes ()
- { if (speakerNotesMode && !tutorialMode && document.speakernotessection)
- { if (document.tutorialsection)
- { document.speakernotessection.moveToAbsolute(document.tutorialsection.pageX,
- document.tutorialsection.pageY) }
- document.speakernotessection.visibility="visible"
- }
- }
-
-
- // Workaround for Nav3.x bug in which JavaScript files
- // with <SCRIPT LANGUAGE="JavaScript1.2" SRC=...> are
- // loaded, even though they should be ignored.
- // Make sure this code is only executed by 4.x and later.
- if (parseInt(navigator.appVersion) > 3) {
-
-
- var screenWidth = screen.width
-
-
- /* 640x480 is 0.8 times the size of 800x600, so scale down by 20%. */
- if (screenWidth < 700) {
- fontSizeOf = setFontSizes (27, 27, 27, 27, 27, 27, 27, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 10, 14, 17, sizeMultiplier, minFontSize) }
-
- /* 12" monitor of 800x600 pixels is the size which we consider "base";
- all other sizes are designed to scale so that their content will fit
- within an 800x600 pixel size area. This is the pixel size used by 12"
- laptop monitors as well as many overhead display systems. */
- else if (screenWidth < 900) {
- fontSizeOf = setFontSizes (34, 34, 34, 34, 34, 34, 34, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 12, 18, 21, sizeMultiplier, minFontSize) }
-
- /* 17" monitor of 1024x768 pixels is 1.28 times larger than 12",
- so scale up by 28% to make sure HTML still fits on smaller page. */
- else if (screenWidth < 1050) {
- fontSizeOf = setFontSizes (44, 44, 44, 44, 44, 44, 44, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 18, 23, 27, sizeMultiplier, minFontSize) }
-
- /* 20" monitor of 1280x1024 pixels is 1.7 times larger than 800x600,
- so scale up by 70% to make sure HTML still fits on smaller page. */
- else if (screenWidth < 1300) {
- fontSizeOf = setFontSizes (58, 58, 58, 58, 58, 58, 58, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 21, 31, 36, sizeMultiplier, minFontSize) }
-
- /* 21" monitor of 1600x1200 pixels is 2.0 times larger than 800x600,
- so scale up by 100% to make sure HTML still fits on smaller page. */
- else {
- fontSizeOf = setFontSizes (68, 68, 68, 68, 68, 68, 68, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 24, 36, 42, sizeMultiplier, minFontSize) }
-
-
- // properties which don't depend on current screen size
-
- // global variables used to set text and background color
- var presentationTextColor = "black"
- var presentationBackgroundColor = "white"
-
-
- document.tags.BODY.color = presentationTextColor
- document.tags.BODY.backgroundColor = presentationBackgroundColor
-
-
- if (speakerNotesMode) {
- document.contextual(document.ids.speakernotessection, document.tags.H1).textDecoration = "underline"
- document.contextual(document.ids.speakernotessection, document.tags.H1).marginTop = "1em"
- self.onLoad = moveSpeakerNotes;
- }
-
-
- if (tutorialMode) {
- // properties added for tutorial
- // document.ids.tutorialsection.marginTop = "3em"
- document.ids.tutorialsection.marginRight = "40px"
- document.ids.tutorialsection.borderStyle = "solid"
- document.ids.tutorialsection.borderColor = "gray"
- document.ids.tutorialsection.borderWidths("2px")
- document.ids.tutorialsection.paddings("1em")
- }
-
- document.tags.H1.fontWeight = "bold"
-
- // enhance readability of source code by making it bold
- document.tags.PRE.fontWeight = "bold"
-
- document.classes.titlepage.all.fontWeight = "bold"
- document.classes.titlepage.all.textAlign = "center"
-
- document.classes.footnote.all.textAlign = "right"
-
- // An example of defining classes to create a visual effect
- // which can be used across many slides. All elements which have
- // CLASS="agendahilite" in their start tag will display in red
- // text on a yellow background.
- document.classes.agendahilite.all.color = "red"
- document.classes.agendahilite.all.backgroundColor = "yellow"
-
-
- // Hack to keep backward compatibility with pages which have
- // per-page style settings (setting inside a STYLE element
- // in the page's HEAD) made using older version (1.0) of template.
- // Set variable v1CompatibilityMode to true to use v1.0 pages
- // with this version without having to update those per-page settings.
-
- var v1CompatibilityMode = false
- if (v1CompatibilityMode) {
- var currentScreen = 0
- var theFontSizes = new Array(1)
- theFontSizes[currentScreen] = fontSizeOf
- }
-
-
- } // end of Nav4+ only if for style sheet code
-
-
-
- // SLIDE PAGE CHANGE CODE (copied from basefile\navbar.js)
- // to enable keyboard-triggered page changes in Nav4+
-
- function
- goto_slide(slide_num, caller_in_main_directory)
- { var filename_prefix = ""
- if (caller_in_main_directory == null) { filename_prefix = "../" }
- if(slide_num < 1 || slide_num > top.last_slide){
- alert("Please enter number between 1 and " + top.last_slide);
- }
- else {
- top.current_slide = Math.abs(slide_num);
- top.frames["slide"].location = filename_prefix + top.filename[slide_num];
- // update displayed page count in goto field
- top.frames["next"].document.forms["gotoform"].slidenum.value = top.current_slide;
- }
- }
-
- function
- prev_slide(caller_in_main_directory)
- {
- if(top.current_slide == 1){
- alert("You are already at the first slide.\nThere is no previous slide.");
- }
- else goto_slide(top.current_slide - 1, caller_in_main_directory);
- }
-
-
- // Display next slide in sequence.
- function
- next_slide(caller_in_main_directory)
- {
-
- if (top.current_slide == top.last_slide){
- alert("You are already at the last slide.\nThere is no next slide.");
- } else goto_slide(top.current_slide + 1, caller_in_main_directory);
- }
-
-
-
-
- // KEYBOARD CONTROL IN NAV4
-
- // support SPACE key codes (*not* RETURN because of Goto field!)
- var nextKeys = new String("nN ")
- var prevKeys = new String("pP")
-
- function handleKeys(e) {
- var keyChar = String.fromCharCode(e.which);
- if (prevKeys.indexOf(keyChar) != -1)
- { prev_slide(true); return false }
- else if(nextKeys.indexOf(keyChar) != -1)
- { next_slide(true); return false }
- else return true;
- }
-
-
-
- // Workaround for Nav3.x bug in which JavaScript files
- // with <SCRIPT LANGUAGE="JavaScript1.2" SRC=...> are
- // loaded, even though they should be ignored.
- // Make sure this code is only executed by 4.x and later.
- if (parseInt(navigator.appVersion) > 3) {
-
- // support ESC key code (*not* BS because of Goto field!)
- prevKeys.concat(String.fromCharCode(27))
- document.captureEvents(Event.KEYPRESS);
- document.onkeypress = handleKeys;
-
- } // end of Nav4+ only if
-
-
-
- // end of file
-
-
-