// A templated widget, mostly the same as dijit/_Templated, but without deprecated features in it.
// bindings: Object
// The data binding declaration for child widgets.
bindings:null,
startup:function(){
// Code to support childBindings property in dojox/mvc/WidgetList, etc.
// This implementation makes sure childBindings is set before this widget starts up, as dijit/_WidgetsInTemplatedMixin starts up child widgets before it starts itself up.
// A mix-in class for widgets-in-template for todo item, that looks at URL hash and completed state of todo item, and updates the hidden state.
// The widgets-in-template for todo item.
// description:
// A todo item should be hidden if:
// Defines data bindings for uniqueId/completed, and the mapping between several widget attributes to CSS classes (using todo/_CssToggleMixin).
// Also, looks at URL hash and completed state of todo item, and updates the hidden state. A todo item should be hidden if:
//
// - URL hash is "/active" and the todo item is complete -OR-
// - URL hash is "/copleted" and the todo item is incomplete
// _setStrikeAttr: Object
// A object used by todo/_CssToggleMixin to reflect true/false state of "strike" attribute to existence of "completed" CSS class in this widget's root DOM.
// A object used by todo/_CssToggleMixin to reflect true/false state of "hidden" attribute to existence of "hidden" CSS class in this widget's root DOM.
this._set("completed",value);// Assign the new value to the attribute
},
startup:function(){
// summary:
// A function called after the DOM fragment declaring this controller is added to the document, in a similar manner as dijit/_WidgetBase.startup().
// description:
// Defines data binding for uniqueId/completed.
this.set("uniqueId",at(this.target,"uniqueId"));// Bind its uniqueId attribute to the data model for the todo item, so that the action handler for removing a todo item can specify which todo item should be removed
this.set("completed",at(this.target,"completed"));// Bind its completed attribute to the data model for the todo item, so that todo/ctrl/_HashCompletedMixin code can determine the shown/hidden state with the URL hash
data-dojo-id creates object reference of the widget. Though TodoMVC application does not have multiple instances of this widgets-in-template, "${id}_" prefix is added to data-dojo-id attribute to avoid ID duplication.
-->
<!--
This <script> tag assigns module references to variables that can be used in this template. The modules used here are:
This <script> tag assigns module references to variables that can be used in this template, as well as the parameter file for the data binding setting, etc. (app18bindings.json) for this template.
The modules used here are:
- dojo/_base/lang: A utility library containing a function to control what object "this" in a function points to
- dojox/mvc/at: Function to create a pointer to dojo/Stateful, for the purpose of data binding
- todo/model/SimpleTodoModel: The data model class for TodoMVC data
- todo/misc/HashSelectedConverter: dojox/mvc data converter for widgets of the <a> tags for All/Active/Completed, for the selected state of the <a> tags
- todo/misc/LessThanOrEqualToConverter: dojox/mvc data converter for the shown/hidden state of "s" in "items left", as well as for the check box to mark all todo items complete/incomplete
<!-- A Dojo Object Store for fetching/saving data from/to localStorage -->
<spandata-dojo-id="${id}_localStorage"
data-dojo-type="todo/store/LocalStorage"></span>
<!--
Our custom controller, based on dojox/mvc/EditStoreRefController, that loads and saves data using a Dojo Object Store, and provides references to the data model (from the Dojo Object Store).
The complete attribute (count of completed todo items, coming as a reference in the data model) is bound to the parent widgets-in-template, so that it can update a CSS class in its root DOM node.
-->
<spandata-dojo-id="${id}_ctrl"
<!-- Our custom controller, based on dojox/mvc/EditStoreRefController, that loads and saves data using a Dojo Object Store, and provides references to the data model (from the Dojo Object Store). -->
Our custom controller, based on dojox/mvc/ModelRefController, that provides references to the todo list in data model, and handles actions like adding/removing/marking.
The model attribute (the todo list in data model) is bound to above todo/ctrl/TodoRefController instance, so that it's updated as soon as todo/ctrl/TodoRefController obtains the data from Dojo Object Store.
The length attribute (count of all todo items, coming as a reference in the todo list in the data model) is bound to the parent widgets-in-template, so that it can update a CSS class in its root DOM node.
-->
data-dojo-props="store: ${id}_localStorage,
modelClass: SimpleTodoModel,
defaultId: 'todos-dojo'"></span>
<!-- Our custom controller, based on dojox/mvc/ModelRefController, that provides references to the todo list in data model, and handles actions like adding/removing/marking. -->
<spanclass="ui-tooltip-top"style="display:none;">Press Enter to save this task</span>
</header>
<sectionid="main">
<!--
The check box to mark todo items complete/incomplete.
It's automatically checked when there is no incomplete items, by the data binding to the count of incomplete todo items (via the todo/ctrl/TodoRefController instance), which is converted to a boolean state representing whether there is no incomplete todo items.
<labelfor="toggle-all">Mark all as complete</label>
<!--
The todo list UI, composed by repeating <li> for each todo item with dojox/mvc/WidgetList.
The children attribute (the list of the todo items) is bound to the todo/ctrl/TodoListRefController instance, so that it's updated as soon as todo/ctrl/TodoRefController obtains the data from Dojo Object Store.
The todo UI, composed by repeating <li> for each todo item with dojox/mvc/WidgetList.
Each <li> is created along with a widgets-in-template associated with it.
Each widgets-in-template here does:
- Associate completed attribute to the existence of "completed" CSS class of its root DOM node (Such association is used by todo/_CssToggleMixin code)
- Associate hidden attribute to the existence of "hidden" CSS class of its root DOM node (Such association is used by todo/_CssToggleMixin code)
- Mix-in in todo/_CssToggleMixin as well as todo/ctrl/_HashCompletedMixin, so that the combination of URL hash and todo item's completed state will end up with the shown/hidden states being updated (by adding/removing "hidden" CSS class)
- Bind its uniqueId attribute to the data model for the todo item, so that the action handler for removing a todo item can specify which todo item should be removed
- Bind its completed attribute to the data model for the todo item, so that todo/ctrl/_HashCompletedMixin code can determine the shown/hidden state with the URL hash
- Bind its hash attribute to the todo/ctrl/RouteController instance, so that todo/ctrl/_HashCompletedMixin code can determine the shown/hidden state with the completed state
The value attribute is associated with the text in this widget, and bound to the todo/ctrl/TodoRefController instance, so that the count of incomplete todo items is updated as soon as todo/ctrl/TodoRefController obtains the data from Dojo Object Store.
The single attribute is associated with the existence of "plural" CSS class of its root DOM node. (Such association is used by todo/_CssToggleMixin code)
The single attribute is bound to the todo/ctrl/TodoRefController instance, so that the state whether the count of incomplete todo item is less than or equal to 1 is updated as soon as todo/ctrl/TodoRefController obtains the data from Dojo Object Store.
<!-- Remove this if you don't implement routing -->
<ulid="filters">
<li>
<!--
The link to show all todo items.
The selected attribute is associated with the existence of "selected" CSS class of its root DOM node. (Such association is used by todo/_CssToggleMixin code)
The selected attribute is bound to todo/ctrl/RouteController instance, so that change in URL hash will be reflected here.
The URL hash is converted to the state whether the hash matches to the href here, by HashSelectedConverter (a dojox/mvc data converter).
The selected attribute is associated with the existence of "selected" CSS class of its root DOM node. (Such association is used by todo/_CssToggleMixin code)
The selected attribute is bound to todo/ctrl/RouteController instance, so that change in URL hash will be reflected here.
The URL hash is converted to the state whether the hash matches to the href here, by HashSelectedConverter (a dojox/mvc data converter).
The selected attribute is associated with the existence of "selected" CSS class of its root DOM node. (Such association is used by todo/_CssToggleMixin code)
The selected attribute is bound to todo/ctrl/RouteController instance, so that change in URL hash will be reflected here.
The URL hash is converted to the state whether the hash matches to the href here, by HashSelectedConverter (a dojox/mvc data converter).
The value attribute is associated with the text in this widget, and bound to the todo/ctrl/TodoRefController instance, so that the count of completed todo items is updated as soon as todo/ctrl/TodoRefController obtains the data from Dojo Object Store.
functionrunEval(js){returneval(js);}// To let eval script point to app18 instance as "this"
returndeclare([Templated,_CssToggleMixin],{
// summary:
// A widgets-in-template widget that composes the application UI of TodoMVC (Dojo 1.8 version).
// Also, this class inherits todo/_CssToggleMixin so that it can react to change in "present"/"complete" attributes and add/remove CSS class to the root DOM node of this widget.
...
...
@@ -49,6 +49,7 @@ define([
// See documentation for dijit/_WidgetBase.startup() for more details.
// Kicks off instantiation of this controller, in a similar manner as dijit/_WidgetBase.postscript().
// params: Object?
// The optional parameters for this controller.
// srcNodeRef: DOMNode?
// The DOM node declaring this controller. Set if this controller is created via Dojo parser.
this.inherited(arguments);
srcNodeRef&&srcNodeRef.setAttribute("widgetId",this.id);// If this is created via Dojo parser, set widgetId attribute so that destroyDescendants() of parent widget works
},
startup:function(){
// summary:
// A function called after the DOM fragment declaring this controller is added to the document, in a similar manner as dijit/_WidgetBase.startup().