DHTML-skriplet - it is simple about simple
Introduction
In 1997, with occurrence Internet Explorer 4.0, Microsoft the skriplet-technology has presented new technology of creation COM a component received the name. This technology allows to create COM components means simple in use of languages of scripts. Such COM components are called skripletami. Initially skriplety were the component of the user interface for Web pages is focused on creation. If you know HTML and JavaScript you will easily master this technology.
At the description skripleta are used DHTML (expansion HTML) and any language of scripts supporting ActiveX Scripting interface. T. to. skriplet it is based on DHTML and it is used in HTML documents he has received name DHTML skriplet. DHTML skriplety are supported by browsers Internet Explorer since 4.0 on any platforms (Win, Mac, Unix), t. To. In open architecture skripleta there is nothing limiting it in limits Win32.
The Skriplet-technology has received development and later has appeared server skriplet, but in this clause{article} we shall stop on consideration DHTML skripleta and for economy of a place of it we shall name simply skripletom.
How to create skriplety
Skriplet it is described in usual HTML a file (*.htm, *.html). As component, skriplet can have properties and methods. Properties skripleta are global peremnnye, methods of function and procedure opredelnennym image described. For creation of shared property to a name of a global variable the prefix public_ increases. For creation of a shared method a prefix public_ pribavljatsja to a name of function or procedure. Any global variable with this prefix becomes public property skripleta, any function or procedure with this prefix becomes it public a method. We shall consider a simple example in which one property property1 and one method method1 is described:
<script language = "JavaScript">
public_property1 = ' Something '; // the Description of property
// property1
function public_method1 (param) {// and a method method1 ()
// some code
}
</script>
By a call of properties and methods the prefix public_ is not included. And the reference{manipulation} from the container will look as follows:
Scriplet1.property1 = ' Another ';
Scriplet1.method1 (param);
Events
DHTML skriplet can work with two types of events: onscripletevent event and standard window events. The first can be initiated at any time from skripleta. Standard window events, such as onclick, onkeypress, cannot be initiated skripletom, but skriplet has the mechanism notifying on event the container. Skriplet reacts to the following standard window events:
? onClick
? onDblClick
? onMouseDown
? onMouseUp
? onMouseMove
? onKeyPress
? onKeyUp
? onKeyDown
For job with standard window events from the container it is necessary to write obrabotchiki events in two places: one in skriplete for transfer of the notice on event to the container, for this purpose is caused a method bubbleEvent (), and another in the application using skriplet for, direct processing of event. The detailed information on event can be received through standard object event. We shall consider a simple example of transfer of the notice to the container about event onKeyUp for a field of input text1:
<input type = text onkeyup = " passKeyUp () " name = "text1" value = " ">
<script language = JavaScript>
function passKeyUp () {
window.external.bubbleEvent (); // transfer of the notice, about
// Event onKeyUp in // an element text1
}
</script>
There is one subtlety: by transfer of the message all over again it is necessary to be convinced that property skripleta frozen matters false, for confidence, that the container is capable to process event.
Note: Property frozen - read-only bulevo property skripleta; value true means, that at present event in the container will not be processed.
If skriplet does not contain obrabotchika the given event or inside obrabotchika the method bubbleEvent the notice on event will not be transferred{handed} is not caused.
Skriplet cooperates with the container by means of event onscripletevent, containing two parameters: a line and any way chosen object. Obrabotchik events can choose how to react to event depending on contents of lower case parameter, and the transmitted object contains the additional information.
Use skripleta
To use skripleta in HTML to page it is applied tag <OBJECT>:
<OBJECT width = 300 height = 300
ID = "Scriplet1"
TYPE = "text/x-scriplet"
DATA = " Scriplet's name "
</OBJECT>
? ID - a name components through which it is possible dostupat`sja up to properties and methods skripleta. In the example described above it Scriplet1.
? DATA - name HTML of a file containing the description skripleta if the file is located in other directory the relative way is underlined.
? TYPE - MIME type of object, in this case skriplet.
Pay attention, that in tage <OBJECT> it is not specified CLSID - Internet Explorer itself registers to a component when meets skriplet though at desire skriplet it is possible to register in system and to specify it CLSID in the obvious image. Internet Explorer distinguishes skriplet on MIME to type "text/x-scriplet".
Functionality skripleta can be realized in any languages of scripts supporting Microsoft ActiveX Scripting the interface. At the description skripleta some languages of scripts can be used, some blocks <script language = in this case are created...>.
Safety
Skriplet also it is safe, as HTML and a script. Besides, in skriplete there is an opportunity to distinguish in what container he is and if it is the container with increased requirements of safety (IE) skriplet works according to politics of safety of this container.
Generally for correct functioning it is necessary that skriplet the page (as well as JAVA applets) has been loaded from the same Web the server, as using it HTML.
Pop up menu
By development skripleta there is an opportunity to create own contextual menu "pop-up" by the right button of the mouse. For everyone skripleta the contextual menu can be realized.
For creation of the menu it is necessary to define{determine} a file of lines which is broken into pairs: in the first element the name of item{point} of the menu, and in the second function caused at his choice is underlined. For initialization of the menu the method setContextMenu () with a file is caused as parameter.
<script language = "VBScript">
sub window_onload
dim a (4)
a (0) = " Add Hello "
a (1) = "Hello"
a (2) = " Add Goodbye "
a (3) = "Goodbye"
window.setContextMenu (a)
end sub
</script>
At click by the right button of the mouse in the field of display skripleta the menu containing two items{points} emerges: " Add Hello " and " Add Goodbye ", at a choice of the first function Hello () is caused, at a choice of the second function Goodbye ().
Additional opportunities
Let's consider an example when at skripleta there is a property "color" and at change of value of this property it would be desirable, that color components too varied. Certainly, it would be more logical to realize a method by which call color changed, but generally we shall assume that a component is necessary to react immediately at change of any properties.
In skriplete there is an opportunity to describe some functions so they give out themselves for properties, and at change of property the code realized in these functions is carried out. Such functions only two: put and get. At change of value of property function put is caused, and at reception of value - get.
<script language=JScript>
property1 = ' some text ';
property1GetCount = 0;
property1PutCount = 0;
function public_get_property1 () {
property1GetCount ++;
}
public_put_property1 (new_value) {
property1PutCount ++;
property1 = new_value;
refresh ();
}
</script>
In this example in variables property1GetCount and property1PutCount store{keep} quantity{amount} of references{manipulations} to property property1 and his changes. In function public_put_property1 after new value is established, a component updates values. In the container you can refer on property1 as though it was usual property.
Scriplet1.property1 = ' Another ';
a = Scriplet1.property1;
With the help put_ and get_ functions it is possible to realize read-only and write-only properties. For creation read-only properties function get _, t is described only. To. Functions put_ no, value is changed cannot be, is similar with write-only.
If you write on JavaScript there is an alternative opportunity of the description of interface DHTML skripleta. At definition of object public_description in skriplete, properties and methods of this object are properties and methods skripleta. At such description of the interface the prefix public_ is not used. It is more convenient to describe all interface skripleta in one place as it is offered with use of object public_desription, than to disseminate the description on all code of a script. Further it is supposed to realize the similar mechanism and on VBScript.
In kachetstve demonstrations it is possible to add standard Microsoft examples DHTML skripletov. I have thrown a pair of the most simple and evident, it is possible to see also at Microsoft on www.microsoft.com/scripting/ <http: // www.microsoft.com/scripting/>.

|