Sciter Architecture

Sciter is not using DOM model like W3C DOM as we have found it too complicated (76 different classes, sic!).

DOM and Window classes

Sciter provides following 8 DOM and Window specific classes accessible in script:

View, document, frame and the root element.

Window that Sciter is attached to is represented by the View objects in script.

Each view has root property - reference of the document loaded into the view. This is a root element of the loaded document. Root element in the Sciter is <html> element of the loaded document and there is no dedicated Document class. Document is really root node of element tree - <html> element and its children.

Frames and framesets.

Frames and framesets are also ordinary DOM elements. <frame> element has single child element - <html> element of the document loaded into it. parent  property of the root element of the document loaded in the frame refer to the <frame> element this document loaded into. Simple as it is.

Frames (<frame> elements) in the Sciter can appear in any part of the HTML (not only in <frameset>) so there is no difference between <frame> and <iframe> in the Sciter. Moreover any block element like <div> can be declared as a <frame> by declaring style="behavior:frame" for it.

Element object has method load that allows to (re)load content of any element and <frame> from external source - url or stream (including in-memory dynamic stream). So there is not too much difference between block element like <div> and frames in the Sciter. Use frames when you need to isolate different style systems or scripts on the same screen.

The same approach is used with <frameset>s - they are plain DOM elements and may appear at any place where block elements are acceptable. <frameset> can contain not only <frame> elements but any block elements thus <frameset> in the Sciter is a convenient way to define container with splitters. Morever any block element can be transformed into the frameset by declaring behavior:frameset in its style declaration.

Script evaluation.

Sciter knows and interprets only tiscript fragments and files. To include script block in the document use following elements:

<script type="text/tiscript" src="url-to-script-file" />

or for inline script inclusion:

<script type="text/tiscript">
  // script statements..
</script>

Global namespace, view and self objects.

Document establishes namespace for script execution. All classes and functions defined like this:

<script type="text/tiscript">
  function foo() { ... }
</script>

go to that global document namespace. self and view global variables are members of this namespace.

self
is a reference to the document (<html> node)
view
is a reference to the view object (usually it is a Sciter window)

Script execution

Sciter executes scripts as a last step of document loading - after </html> tag is being parsed. So at the moment of any script execution DOM is established and scripts can refer to it.

There are three major steps of script execution in the engine:

  1. execution of the scripts per se including declaration of classes and behaviors;
  2. assignment of behaviors to the elements that have prototype:somebehavior; declared in CSS and
  3. invocation of self.ready() method (if it was declared in the script).

When document needs to be unloaded from the view (e.g. sciter window have got request to close from the user) engine is calling self.closing() method (if it was declared). If that method returns exactly false value then unloading stops. This way document can cancel its own unloading.