Copy-friendly!



Click for Navigation    (Press  Home / Pos1-key to scroll back!):
Handling | Coding (Style | Title | Contents | Buttons | Duration |  onopen  |  onclose  | RETURN | KEY | Graphic Buttons)
Requirements (Hardware | Browser | include | call)
Appendix 1: Keyword Parameters | Appendix 2: Indirect Coding | Keywords, Text Metrics 


SubDlg() -
Universal Vehicle to Present User Interactivity

Providing user interactivity in an online document is a trade-off: Not too little, so the users can make real  hands-on experience . Not too much, so the author does not have to detract too much time from writing the text, just for making the message vivid. This article will show you a way to make it an easy job.

When talking about providing user interactivity in your online documents - let's not forget that this is taking quite some effort!

Except for very basic user interactivity (such as  alert() ,  confirm() ,  prompt() ) it's quite laborious if you want to implement it from scratch. (For simple operations, see my article How to Provide User Interactivity. For more complicated dialogs, see Dialog - Easy User Interactivity Anytime.)

What's needed is a software component that is easy to use like an  alert() , yet flexible like a full dialog. I developed such a software component: SubDlg() . With it you can have:

  1. different styles (details + demo [IE browser only]: section Coding - Style)
  2. none or different titles (details + demo [IE browser only]: section Coding - Title)
  3. different contents (details + demo [IE browser only]: section Coding - Contents)
  4. different buttons (details + demo [IE browser only]: section Coding - Buttons)
  5. permanent or temporary display (details + demo [IE browser only]: section Coding - Duration)
  6. custom actions  before  display (details + demo [IE browser only]: section Coding -  onopen )
  7. custom actions  after  display (details + demo [IE browser only]: section Coding -  onclose )
  8. easy coding of return value (details + demo [IE browser only]: section Coding - RETURN)
  9. SubDlg  usage by keyboard (details + demo [IE browser only]: section Coding - KEY)
  10. using images instead of buttons (details + demo [IE browser only]: section Coding - Graphic Buttons)
But before going into details, let's look into its handling.

Handling

If you ever wanted to implement user interactivity in an online document, you will have encountered it: You had a clear idea of what dialog you wanted to present. It would be easy to implement by a few line of HTML code. But the presentation itself would have required an enormous effort. What you needed was a "vehicle" handling all that effort but giving you any freedom as to the contents.

A  SubDlg()  is such a vehicle. It can be called any time similar to a standard  alert() . By default, it behaves just like that. For a detailed comparison of  SubDlg()  and standard  alert()  look into this footnote updated.gif.

A major edge of  SubDlg()  is the fact that you can implement a complete online document - including all user-interactivity - in one HTML-file, even for rather complex dialogs. Before there was  SubDlg() , you could have

Now, with  SubDlg() , you have the best of both worlds.

Coding

 SubDlg()  can be applied similar to e.g.  alert()  in standard JavaScript. For a detailed comparison, look into this footnote.
SubDlg([@]contents[options])
Click on the parameter you want to know more about! - In addition, some custom HTML attributes have been introduced.
parametermeaning
contents or @contents Obligatory parameter: HTML code of what the contents of the sub-dialog should be.
Details + demo: section Coding - Contents
Prefix  @ : Identifier of any  DIV  whose  innerHTML  is to be taken for contents.)
Details + example: section Appendix 2: Indirect Coding

Coding - SubDlg

options Optional parameter: String of options yielding flexible control over  SubDlg() . For general help on options coding see Appendix 1: Keyword Params
Currently the following options and HTML attributes are available:
buttons= or buttons=@ HTML-code of buttons to display in  SubDlg() 
Details + demo: section Coding - Buttons
Value prefix  @ : Identifier of any  DIV  whose  innerHTML  is to be taken for buttons.  Details + example: section Appendix 2: Indirect Coding
duration= Number of seconds to display  SubDlg(), then it will be closed automatically. Can be any positive number (1, 2, …) Details + demo: section Coding - Duration
esc Simple keyword to have not only  OK-button but also  Esc-button in sub-dialog. Details + demo: section Coding - Buttons
onclose= JavaScript code of action to perform after closing the sub-dialog.
Details + demo: section Coding - onclose=
onopen= JavaScript code of action to perform before opening the sub-dialog.
Details + demo: section Coding - onopen=
style= JavaScript code of styles to apply in display of the sub-dialog.
Details + demo: section Coding - Style
title= or title=@ HTML-code of title to display in  SubDlg() 
Details + demo: section Coding - Title
Value prefix  @ : Identifier of any  DIV  whose  innerHTML  is to be taken for title. Details + example: section Appendix 2: Indirect Coding
width= Number of pixels the sub-dialog box should be wide.
Details + demo: section Coding - Title

Coding - SubDlg

To make  SubDlg()  more programmer-friendly, not only  keyword parameters  have been introduced but also  custom HTML attributes . That is, coding some attributes within the normal HTML code  that are not defined in the context of standard HTML. (Still, they are accepted by the browser and can be handled by an application.)
For clarity, custom HTML attributes are written in uppercase letters in this documentation (though they could be coded in lowercase as well).

Currently the following custom HTML attributes are defined for  SubDlg()  applications:

KEY HTML attribute for usage of a sub-dialog by keyboard.
Details + demo: section Coding - KEY
RETURN HTML attribute for simple coding of a sub-dialog's return value when pressing one of its buttons. Details + demo: section Coding - RETURN

Coding - Style

By default, a  SubDlg  is presented just like a standard  alert  box (grey background, outset border). If you want to have a more sophisticated layout, you can achieve that in two ways:
  1. Semi-permanent Style Change: For your  corporate identity  you might want to have a uniform default layout, every time a  SubDlg()  is launched in an application. Then you should change the Semi-permanent Style Sheet (look into this footnote).
  2. Temporary Style Change: If you feel, a  SubDlg  should give a different impression, then you should use the option  style=  to have a different layout for this launch only. (For details look into this footnote.)
In the following demos you can see different  SubDlg  layouts. You might be interested to spy on the source code:

Coding - Title

By default, a  SubDlg  is presented just like a standard  alert  box - but without a title bar.

You can include a title bar by using option  title= . It can hold plain text (with some HTML tags intermingled, if you want) and/or any HTML construction. By default, its style is controlled by the line introduced by  .tempmsgTitle  in file  OnlineComm.css  You can modify that style semi-permanently, uniformly for all  SubDlg  within the document.

For text and rather simple HTML constructions, a linear string will be all you need. For more complicated HTML constructions, however, you will prefer  Indirect Coding  (see Appendix 2: Indirect Coding).

By the following demos you can see what this option is good for. (If you want to spy on the source code, search for  <!-- demo 22 --> . In the next lines you will see the source code of the following demos.)

Coding - Contents

This is the only parameter that will be needed in every call of  SubDlg .

Just like the title bar, the contents can be plain text (with some HTML tags intermingled, if you want) and/or any HTML construction. Usually this will be a collection of standard HTML  <INPUT>  tags, combined with some text. Such a "custom SubDlg" will be useful if you want to prompt the readers for their inputs to a user interaction.

For text and rather simple HTML constructions, a linear string will be all you need. For more complicated HTML constructions, however, you will prefer  Indirect Coding  (see Appendix 2: Indirect Coding).

EContents can be coded as linear strings for standard HTML inputs only. If you have  user inputs  (see User Inputs & Pedagogical Background of Online Communication) in your custom SubDlg, you should use Indirect Coding.
EAdditionally, for a custom SubDlg you will usually need an option  onclose= , sometimes also an option  onopen= 

The following demos will show you what the contents can be.

If you want to spy on the source code, search for  <!-- demo 23 --> . In the next lines you will see the source code of the following demos.

Coding - Buttons

By default, a SubDlg is presented just like a standard  alert  box (one button "OK").

In many applications you will want to have a minor modification: two buttons ("OK", "Esc"). You can have that by simply adding the option:

esc

If you want a more complex array of buttons, you can implement it by the option:

buttons=…
or
buttons='… …'
or
buttons="… …"
or
buttons=«… …»

 … …  can be any HTML-code you want to implement your buttons - e.g.  <INPUT TYPE=Button … >  or whatever you like.

EIf you feel not sure which of the four notations given above is best for you, you might want to have a look into Appendix 1: Keyword Params
EUsually you will want to have the SubDlg closed and any value returned, indicating which of the buttons was clicked. This can be done by adding an attribute  ONCLICK="SubDlg_Close(…)"  to each of the buttons. If you use Indirect Coding for the buttons, you can define each button's return value simply by  RETURN=… . (… is the numeric or string value you want to have returned when the button is clicked.)
In order to apply the return value once the SubDlg is closed, use the option  onclose= 

A sample SubDlg with three buttons ( Yes ,  Don't know ,  No ) you can see when you click on the following buttons. (If you want to spy on the source code, search for  <!-- demo 24 --> . In the next lines you will see the source code of the following demos.)

Coding - Duration

One thing that is not very user-friendly about standard  alert()  is that all the application is stopped once it is launched. The user can do nothing else but click the  OK-button or change to another application.

In contrast to that, a  SubDlg  can be limited to be on screen only a certain number of seconds. This will be useful for:

The remaining number of seconds is counted down in the bottom-right corner. After this time, the sub-dialog is closed automatically. Whatever the duration - if the user clicks any of the keys, the  SubDlg  is closed immediately.

By a  no-button sub-dialog  with any  duration  you can add more user-friendliness to your application:
A frequent problem in online communication is, you want to give the users a minor information, relevant for the moment only. With standard  alert()  the users are forced to click the  OK-button, or the alert box would stay on screen forever. With a timed  SubDlg() , however, the users need to do nothing. - Try the second demo! (Notice the blank space in the option  buttons=« »  !)

If you want to spy on the source code, search for  <!-- demo 25 --> . In the next lines you will see the source code of the following demos.

(When the duration is counted down, the SubDlg will close automatically.
If you don't want to wait that time, you can close it by clicking  OK .)

Coding - onopen=

When the contents of your SubDlg are a custom dialog, you might want some action to be taken before the SubDlg pops up on screen. (A typical example would be, to have an input set to any default value - prompting the users to overwrite it.)

This can be done by the option

onopen=…
or
onopen='… …'
or
onopen="… …"
or
onopen=«… …»

 … … : JavaScript code implementing the action to take before the SubDlg will be opened.

EFeeling uncertain which one of these four notations is best for you? Have a look into Appendix 1: Keyword Params!
EYou can have more than one operations done upon opening a  SubDlg() : Just code them as you would in JavaScript, separating them by ';'. (Spy on the first  SubDlg()  of demo 26!)

The following demo will show you how to set an input to any default value before it is open to the user's inputs.

If you want to spy on the source code, search for  <!-- demo 26 --> . In the next lines you will see the source code of the following demos.

Coding - onclose=

When the contents of your SubDlg are a custom dialog, you will usually want some action to be taken after the SubDlg is closed. (In most cases, this will be any process depending on the return value of the SubDlg - accessible by the global variable  subRetVal .)

This can be done by the option

onclose=…
or
onclose='… …'
or
onclose="… …"
or
onclose=«… …»

 … … : JavaScript code implementing the action to be taken when the SubDlg is closed.

EIf you feel not sure which of the four notations given above is best for you, you might want to have a look into Appendix 1: Keyword Params

The following demo will show you how a simple example of how to process the return value of a SubDlg.

If you want to spy on the source code, search for  <!-- demo 27 --> . In the next lines you will see the source code of the following demos.

Coding - RETURN

It's actually quite a complicated procedure when a  SubDlg()'s button is pressed, resulting in closing the  SubDlg()  and returning any value that can be further processed by using the global variable  subRetVal .

To make it more programmer-friendly, all that complicated stuff is kept away from you. All you have to do is coding a custom HTML attribute:

RETURN=… or RETURN='…' or RETURN="…"

E… is the numerical or string value to be stored to global variable  subRetVal  before closing the  SubDlg() . It should be bracketed within  ''  or    if it comprises any blank space (just like any standard HTML attribute).

The following demo will demonstrate you how simple it is to code return values for  SubDlg .

If you want to spy on the source code, search for  <!-- demo 28 --> . In the next lines you will see the source code of the following demo.

Coding - KEY

What kind of people is your application aimed at? Are they familiar with computers, will they like fine-pointing with the mouse? Then you will have an easy job. However, many people tend to dislike computers, just because they are required to do that. They would prefer to press any key on the keyboard instead.

Well, you can give them what they want. To you, that's only a minor coding effort:

  1. At the end of your online document, between </BODY> and </HTML>, insert a code line:
    <SCRIPT>SubDlg_Init()</SCRIPT>
  2. To each closing button of your  SubDlg()  add an attribute:
    <INPUT TYPE="Button" KEY=…>
    E… is the character represented by the intended key. To avoid any problems with confusing keys, in the current  SubDlg()  version they are limited to printable chars only.

Typing the key characters will be interpreted like closing only if a keyed  SubDlg()  is on screen. If not, they have the usual effect. - Obviously, a SubDlg() prompting for typing inputs should not have keyed buttons.

The following demo will give you a simple example of how to implement key handling for  SubDlg . If you want to spy on the source code, search for  <!-- demo 29 --> . In the next lines you will see the demo's source code.

Coding - Graphic Buttons

The preceding demos were all implemented by real buttons whenever we were talking about "buttons" - just for clarity. If you want to give your  SubDlg()  application some extra user-friendliness, however, you will want to design graphic faces for your buttons. Thus perhaps even creating sort of  corporate identity : all software coming from you has a special look-and-feel!

To that end, all you have to do is

  1. prepare the button faces in form of  .jpg  or  .gif  images
  2. store those images in the same directory as that of your online document
  3. declare the images in place of buttons

All the rest will be done automatically.

The following demo will illustrate how to implement graphic buttons for a  SubDlg . In this demo, also the RETURN custom attribute (see Coding - RETURN) has been used.

If you want to spy on the source code, search for  <!-- demo 210 --> . In the next lines you will see the source code of the following demo.

Requirements

What are you interested in?: Click the item you want to know more about!

Requirements - Hardware

In order to make full use of Custom Inputs, you should be sure of the following hardware at your users':

Requirements - Browser

The Custom Inputs are applicable under IE browsers only.
Will all your users have an IE browser?

Requirements - include

Anywhere in your HTML-file, before the first call of a Custom Input, you should have the following code line:

<SCRIPT SRC="Input.js"></SCRIPT>

Of course, you should make sure that the JavaScript-File  Input.js  really is in the current working directory on your server. If not, you might have to alter the path, e.g. <SCRIPT SRC="../JS/Input.js"></SCRIPT>

If you want to combine SubDlg()  with any of the other software components described in the other articles of these archives, you should declare them one after the other. E.g.:

<SCRIPT SRC="OnlineComm.js"></SCRIPT> <SCRIPT SRC="Input.js"></SCRIPT>

Requirements - call

SubDlg()  should be called within <SCRIPT>-brackets, e.g.
<SCRIPT>SubDlg( … )</SCRIPT>
If you want to have several related calls, they may be combined within a common bracket and must be separated by a semicolon - e.g.
<SCRIPT>SubDlg( … );
    :
SubDlg( … );
    :
SubDlg( … )</SCRIPT>
If you have more than one application in your HTML-file, they all share a common namespace. I.e. all identifiers must be unique over all the applications.

Appendix 1: Keyword Params

SubDlg()  is based on a software technology that is different to standard programming languages (such as  JavaScript ).

In standard programming languages you can control a function only by  positional parameters . That is, the significance of a parameter is given by its position in the parameter list: the first parameter, the second parameter, etc.

To the human programmer, that's fine as long as there are not more than some 6-10 parameters. Beyond that, it's but too easy to overlook a parameter. Consequently, all the following parameters would be interpreted incorrectly.

That's going to be a problem especially when you have a significant parameter at, say, position 29 - whereas the parameters of position 21 to 28 are not significant. So, to the human mind the most obvious thing would be to leave them out. Alas, then your significant parameter of position 29 would be interpreted as if it were at position 21. Not exactly what you want!

Therefore, the options of  SubDlg()  (and all the other software components presented in these archives) use a software technology called  keyword parameters  (Exact formalism: see this footnote.)

Appendix 2: Indirect Coding

SubDlg()  is very powerful. For title, contents and buttons it can display anything from plain text up to the most complicated HTML constructions. This is more, in fact, than what can be coded simply as a linear string (holding the HTML code of the construction).

Therefore the concept of  Indirect Coding  was introduced:

By  Indirect Coding  you can even achieve some special effects. For an example look into this footnote.

Footnote: updated.gif
User-friendliness  SubDlg()  ← →  alert() 

  1. By  SubDlg()  any dialog contents can be presented that can be implemented in HTML: text (any font/style/color), standard inputs, UserInputs (see my article: Pedagogical Background of Online Communication), images, …
    By standard  alert()  only plain text can be presented.
  2. Similarly, any text or HTML construction can be presented in the title bar of a  SubDlg() .
    In standard  alert()  the title bar cannot be used productively.
  3. As well, any combination of standard buttons (or any other HTML construction) can be presented in the buttons bar of a  SubDlg() .
    In standard  alert()  you have only one button,  OK . If you want a combination of  OK  and  Esc  button, you have to change to  confirm() . Other button combinations are not possible in standard message boxes.
  4. The  SubDlg()  box can be presented in any style (color, borders, … ). By the mere look of a dialog box a sense of the message can be conveyed.
    A standard  alert()  or  confirm()  box always looks the same: light-grey, with plain text in the default font.
  5. Technically,  SubDlg()  is a  modeless dialog  - meaning that the user can continue with the application as usual. Even when another  SubDlg()  is launched later - the old dialog box just changes its layout but stays on screen.
    Standard  alert() , however, is a  modal dialog . The application is completely halted, not even the main window can be minimized or closed. The user has to click the  OK  or  Esc  button first, thus closing the dialog.
  6. The display of a  SubDlg()  can be limited to any duration, then it will be closed automatically. By clicking any of its buttons, the user can close it before.
    Whereas a standard  alert() , remains open all the time, until the user clicks any of its buttons or presses the  ENTER- or  Esc-key.
  7. SubDlg()  can be moved across the screen by dragging at any place where the cursor is . That is, at any place within the dialog box except the title, the contents or the buttons.
    Standard  alert()  can be moved only by dragging in the title bar.
  8. SubDlg()  at first will pop up in the center of the screen. From there it can be moved to any other place on screen, and it will stay there: If some other  SubDlg()  will be launched later, the dialog box will change but at the same place as before. (Except if the main document has been scrolled meanwhile - then  SubDlg()  will follow suit.)
    Standard  alert()  always pops up in the center of the screen.
  9. new.gif
    SubDlg()  can be resized when the cursor is of any of the  …-resize  types: Within a margin of some 20 pixels inside the sub-dialog box, the cursor turns to any of these types. Which one, is depending on the place within the box: Horizontal/vertical arrow inside of a vertical/horizontal edge, slant arrow inside of a corner. By dragging the sub-dialog box will be resized then, as indicated by the cursor type.
    Farther inside than some 20 pixels, the cursor turns to the  move  type (). Dragging means moving the sub-dialog box then.

Footnote:
Programmer-friendliness  SubDlg()  ← →  alert() 

  1. SubDlg()  is a JavaScript function with (currently) 9 parameters, only one will of which be used every time. The others will be needed only if you want to implement a certain effect. Therefore,  SubDlg()  is based on keyword parameters. (For details on keyword parameters, look at Appendix 1: Keyword Params.)
  2. Some of the parameters ( contens ,  title ,  buttons ) can get quite complicated to implement as strings, requiring a delicate nesting of  '' ,  ""  and  «»  brackets. Therefore  indirect coding  was introduced:
    • Within brackets of  <DIV ID="…" STYLE="display:none">  and  </DIV> , code it in the usual way.
    • In  SubDlg() , code a reference to it by  @…  (preceded by the keyword, if needed). "…" is the identifier of the  <DIV id=…> </DIV>  where you coded it in the previous step.
  3. The contents of a  SubDlg()  can be plain text and/or any HTML construction. You can use that to give your messages a more communicative layout. E.g. important words could be bold, a subject comprising several points could be a bulleted list, etc.
  4. You can use option  style=  to convey a subtle message. For example, neutral information boxes could be in default (lightgrey) color, warnings in pink color, error messages in red.
  5. You can have your own construction of the title bar. Thus the title could be e.g. text (with HTML tags intermingled, if you want), combined with buttons. For an example, look at the close-button of section Coding - Title
  6. You can have your own combination of buttons (or any other HTML construction you want to use instead). For example, look at section Coding - Buttons
  7. You can give your applications an extra user friendliness by making sure that the dialog box is closed automatically. Though the user can close it before, by clicking any of the buttons. (See  Coding Duration )
  8. You don't have to make the dialog box close every time.  SubDlg()  implements a modeless dialog: Even if another  SubDlg()  is launched while the old dialog box is still open - the box's layout changes, nothing else.

Footnote:
Semi-permanent Style Change


Footnote:
Temporary Style Change

Code the parameter value in the usual JavaScript notation - without the prefix  style. , separated by  ;  if you want to change several styles. Example:
style=«backgroundColor='yellow'; fontFamily='Verdana'»

Footnote:
Keyword Parameters - Formalisms

  1. Keyword parameters may be coded in any order.
  2. The significance of a parameter is given by its prefix (the "keyword").
  3. Insignificant parameters can simply be left out.
  4. Keywords are case-sensitive. They must be coded exactly as given in the documentation.
  5. Keyword parameters ("options") can be simple  keyword  or pairs of  keyword  and  value , separated by  = .
  6. Individual keyword parameters must be separated by at least one blank space, if the preceding  value  is not bracketed.
  7. In some cases, a keyword parameter might have a few positional parameters. (Their order is significant!)
  8. A parameter value may be coded with or without brackets. If it comprises a blank space, however, it must be bracketed in  '' ,  ""  or  «» .
  9. The outermost brackets of an option string must be those standard to JavaScript ( ''  or  "" ).
  10. If the symbols  «  and  »  are not on your keyboard, you can enter them by:
    • Press the  ALT -key, and
    • on the numeric keypad type "174" (for  « ) or "175" (for  » ).
    EDeciding on how to nest  "" ,  ''  and  «»  brackets, to code a single apostrophe, or to factor out an expression, can be quite a hairy matter sometimes. For a good example of that, look at the coding of  close_button  in the sample of section Coding - Title
  11. The closing apostrophe of the last keyword parameter (be it  ' ,  "  or  » ) may be omitted.
    (Not recommended, however: If the option string is expanded some time later, it is too easy to overlook that!)

Footnote:
Using Indirect Coding to Protect Contents

In some applications you will want to display some contents, but make sure that the users cannot copy them to clipboard. Thus protecting them from being further processed.

You can do that simply by Indirect Coding of a nested <DIV> which is disabled for selection:

<DIV ID="noselect" STYLE="display:none">
<DIV onselectstart="return false"> … (contents to protect) … </DIV>
</DIV>
:
SubDlg('@noselect');
ENote however that this is no definitive protection against abuse of your contents. It just pushes the price for downloading so high that some would-be code pirates might feel discouraged.(See my article Protect your Contents - …, in particular section Preventing (Physical) Downloading
-------------------------------------------------------------------------------------------------------------------------
Article by Gunter Gerdenitsch, international IT-specialist with focus on Communication. IT service providers - looking for a freelancer for peaks in your workload, want to get your ideas across? Then you should visit http://www.ITspecial.org or mail to gg@ITspecial.org
-------------------------------------------------------------------------------------------------------------------------

This article is free to be re-printed, if complete with this resource box. It can be included in a web site if the URL mentioned above is linked to www.ITspecial.org.

Keywords: user interactivity, presentation vehicle, Style, Title, Contents, Buttons, Duration, onopen, onclose, RETURN, KEY, Graphic Buttons
Word count: 3609
File size
(incl. demos):
75kB