Skip to content

Page Initialization and Templates

JonFerraiolo edited this page May 26, 2012 · 1 revision

This wiki page provides source code notes on how new pages get initialized across these scenarios:

  • Multiple tabs, and you switch tabs
  • New blank page
  • Open existing page

Switch tabs

When different existing editor tab is selected, "-selectChild" callback is executed in EditorContainer.js, which calls editor.setContent() (PageEditor.js:setContent), which calls:

  • ModelEditor.js:setContent (which end up parsing template.html into the model)
  • VisualEditor.js:setContent (), which calls
    • this._setContent(), which calls:
      • this._setContentRaw(), which calls:
        • (If first time) Context contructor passing the model
        • (always) Context.js:_setSource() passing the model, which calls:
          • data = this._parse(model), which returns a "data" structure where data.content is the result of calling getElementText() on the model's body element
          • If not first time (this.frameNode has a value), just call this._continueLoading (data, )
          • Else (first time), set up an initial document (head, etc), which does a substitution on template (different than template.html!) and a doc.write on template. After browser processes doc.write, "loading" logic does this: (1) set body attributes and styles (2) other stuff, (3) call this._continueLoading(data)

Context.js._continueLoading(data, ...)

  • Calls this._setSourceData(data), which calls:
    • this.getGlobal()'require'.set(containerNode, content, {
    • this._processWidgets(containerNode), which
      • converts dom nodes into widgets

New blank HTML

When a new html file is created:

  • Workbench.js._createEditor calls tab.setEditor(), which becomes an a call to EditorContainer.js:setEditor().
    • After various deferreds happen, called editor.getDefaultContent() (i.e., PageEditor.getDefaultContent())
      • which ends up getting to VisualEditor.js:getTemplate(), which returns the default page template (template.html)
      • and then calls editor.setContent (PageEditor.js:setContent - see top of this page for that process)

Lessons learned

  • ve/resources/template.html isn't really used. It does indeed get loaded, and parsed, and various routines in Context.js currently get called and do various initialization tasks on it, but that all gets overridden by subsequently called logic in Context.js:_setSource().
  • Note: I tried to have template.html be an empty string, but things died in Context.js in several places where various routines assume the model has a HEAD in it.
Clone this wiki locally