Commit 19cf5e30 authored by James Thomas's avatar James Thomas

Fix line-endings.

parent e623e86f
define([ define([
"dojo/_base/array", "dojo/_base/array",
"dojo/_base/declare", "dojo/_base/declare",
"dojo/_base/lang", "dojo/_base/lang",
"dojo/dom-class", "dojo/dom-class",
"dijit/_WidgetBase" "dijit/_WidgetBase"
], function(array, declare, lang, domClass, _WidgetBase){ ], function(array, declare, lang, domClass, _WidgetBase){
return declare(_WidgetBase, { return declare(_WidgetBase, {
// summary: // summary:
// Widget supporting widget attributes with classExists type. // Widget supporting widget attributes with classExists type.
// classExists type allows boolean value of an attribute to reflect existence of a CSS class in a DOM node in the widget. // classExists type allows boolean value of an attribute to reflect existence of a CSS class in a DOM node in the widget.
// example: // example:
// In this example, the text will be bold when the check box is checked. // In this example, the text will be bold when the check box is checked.
// | <html> // | <html>
// | <head> // | <head>
// | <script src="/path/to/dojo-toolkit/dojo/dojo.js" type="text/javascript" // | <script src="/path/to/dojo-toolkit/dojo/dojo.js" type="text/javascript"
// | data-dojo-config="parseOnLoad: 1, // | data-dojo-config="parseOnLoad: 1,
// | packages: [{name: 'todo', location: '/path/to/todo-package'}], // | packages: [{name: 'todo', location: '/path/to/todo-package'}],
// | deps: ['dojo/parser', 'dojo/domReady!']"></script> // | deps: ['dojo/parser', 'dojo/domReady!']"></script>
// | <style type="text/css"> // | <style type="text/css">
// | .boldText { // | .boldText {
// | font-weight: bold; // | font-weight: bold;
// | } // | }
// | </style> // | </style>
// | </head> // | </head>
// | <body> // | <body>
// | <script type="dojo/require">at: "dojox/mvc/at"</script> // | <script type="dojo/require">at: "dojox/mvc/at"</script>
// | <input id="checkbox" data-dojo-type="dijit/form/CheckBox"> // | <input id="checkbox" data-dojo-type="dijit/form/CheckBox">
// | <div data-dojo-type="todo/CssToggleWidget" // | <div data-dojo-type="todo/CssToggleWidget"
// | data-dojo-props="_setBoldAttr: {type: 'classExists', className: 'boldText'}, // | data-dojo-props="_setBoldAttr: {type: 'classExists', className: 'boldText'},
// | bold: at('widget:checkbox', 'checked')">This text will be bold when above check box is checked.</div> // | bold: at('widget:checkbox', 'checked')">This text will be bold when above check box is checked.</div>
// | </body> // | </body>
// | </html> // | </html>
_attrToDom: function(/*String*/ attr, /*String*/ value, /*Object?*/ commands){ _attrToDom: function(/*String*/ attr, /*String*/ value, /*Object?*/ commands){
// summary: // summary:
// Handle widget attribute with classExists type. // Handle widget attribute with classExists type.
// See dijit/_WidgetBase._attrToDom() for more details. // See dijit/_WidgetBase._attrToDom() for more details.
var callee = arguments.callee; var callee = arguments.callee;
array.forEach((function(){ return lang.isArray(commands) ? commands.slice(0) : [commands]; })(arguments.length >= 3 ? commands : this.attributeMap[attr]), function(command){ array.forEach((function(){ return lang.isArray(commands) ? commands.slice(0) : [commands]; })(arguments.length >= 3 ? commands : this.attributeMap[attr]), function(command){
command.type != "classExists" ? command.type != "classExists" ?
this.inherited("_attrToDom", lang.mixin([attr, value, command], {callee: callee})) : this.inherited("_attrToDom", lang.mixin([attr, value, command], {callee: callee})) :
domClass.toggle(this[command.node || "domNode"], command.className || attr, value); domClass.toggle(this[command.node || "domNode"], command.className || attr, value);
}, this); }, this);
} }
}); });
}); });
define([ define([
"dojo/_base/declare", "dojo/_base/declare",
"dijit/_TemplatedMixin", "dijit/_TemplatedMixin",
"dijit/_WidgetsInTemplateMixin", "dijit/_WidgetsInTemplateMixin",
"dojox/mvc/WidgetList", "dojox/mvc/WidgetList",
"dojox/mvc/_InlineTemplateMixin", "dojox/mvc/_InlineTemplateMixin",
"todo/CssToggleWidget", "todo/CssToggleWidget",
"todo/ctrl/_HashCompletedMixin" "todo/ctrl/_HashCompletedMixin"
], function(declare, _TemplatedMixin, _WidgetsInTemplateMixin, WidgetList, _InlineTemplateMixin, CssToggleWidget, _HashCompletedMixin){ ], function(declare, _TemplatedMixin, _WidgetsInTemplateMixin, WidgetList, _InlineTemplateMixin, CssToggleWidget, _HashCompletedMixin){
return declare([WidgetList, _InlineTemplateMixin], { return declare([WidgetList, _InlineTemplateMixin], {
childClz: declare([CssToggleWidget, _TemplatedMixin, _WidgetsInTemplateMixin, _HashCompletedMixin], { childClz: declare([CssToggleWidget, _TemplatedMixin, _WidgetsInTemplateMixin, _HashCompletedMixin], {
_setCompletedAttr: {type: "classExists", className: "completed"}, _setCompletedAttr: {type: "classExists", className: "completed"},
_setHiddenAttr: {type: "classExists", className: "hidden"}, _setHiddenAttr: {type: "classExists", className: "hidden"},
onRemoveClick: function(){ onRemoveClick: function(){
this.parent.listCtrl.removeItem(this.uniqueId); this.parent.listCtrl.removeItem(this.uniqueId);
}, },
onEditBoxChange: function(){ onEditBoxChange: function(){
if(!this.editBox.value){ if(!this.editBox.value){
this.parent.listCtrl.removeItem(this.uniqueId); this.parent.listCtrl.removeItem(this.uniqueId);
} }
} }
}) })
}); });
}); });
define([ define([
"dojo/_base/declare", "dojo/_base/declare",
"dojo/router", "dojo/router",
"dijit/Destroyable", "dijit/Destroyable",
"dojox/mvc/_Controller" "dojox/mvc/_Controller"
], function(declare, router, Destroyable, _Controller){ ], function(declare, router, Destroyable, _Controller){
return declare([_Controller, Destroyable], { return declare([_Controller, Destroyable], {
// summary: // summary:
// A controller that maintains hash attribute in sync with location.hash. // A controller that maintains hash attribute in sync with location.hash.
// example: // example:
// In this example, the text box is in sync with the URL hash. // In this example, the text box is in sync with the URL hash.
// (The change in URL hash is reflected to the text box, and the edit in text box will be reflected to the URL hash) // (The change in URL hash is reflected to the text box, and the edit in text box will be reflected to the URL hash)
// | <html> // | <html>
// | <head> // | <head>
// | <script src="/path/to/dojo-toolkit/dojo/dojo.js" type="text/javascript" // | <script src="/path/to/dojo-toolkit/dojo/dojo.js" type="text/javascript"
// | data-dojo-config="parseOnLoad: 1, // | data-dojo-config="parseOnLoad: 1,
// | packages: [{name: 'todo', location: '/path/to/todo-package'}], // | packages: [{name: 'todo', location: '/path/to/todo-package'}],
// | deps: ['dojo/parser', 'dojo/domReady!']"></script> // | deps: ['dojo/parser', 'dojo/domReady!']"></script>
// | </head> // | </head>
// | <body> // | <body>
// | <script type="dojo/require">at: "dojox/mvc/at"</script> // | <script type="dojo/require">at: "dojox/mvc/at"</script>
// | <span id="routeCtrl" data-dojo-type="todo/ctrl/RouteController"></span> // | <span id="routeCtrl" data-dojo-type="todo/ctrl/RouteController"></span>
// | <input data-dojo-type="dijit/form/TextBox" // | <input data-dojo-type="dijit/form/TextBox"
// | data-dojo-props="value: at('widget:routeCtrl', 'hash')"> // | data-dojo-props="value: at('widget:routeCtrl', 'hash')">
// | </body> // | </body>
// | </html> // | </html>
postscript: function(/*Object?*/ params, /*DOMNode?*/ srcNodeRef){ postscript: function(/*Object?*/ params, /*DOMNode?*/ srcNodeRef){
// summary: // summary:
// Kicks off instantiation of this controller, in a similar manner as dijit/_WidgetBase.postscript(). // Kicks off instantiation of this controller, in a similar manner as dijit/_WidgetBase.postscript().
// params: Object? // params: Object?
// The optional parameters for this controller. // The optional parameters for this controller.
// srcNodeRef: DOMNode? // srcNodeRef: DOMNode?
// The DOM node declaring this controller. Set if this controller is created via Dojo parser. // The DOM node declaring this controller. Set if this controller is created via Dojo parser.
this.inherited(arguments); 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 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(){ startup: function(){
// summary: // summary:
// A function called after the DOM fragment declaring this controller is added to the document, in a similar manner as dijit/_WidgetBase.startup(). // A function called after the DOM fragment declaring this controller is added to the document, in a similar manner as dijit/_WidgetBase.startup().
var _self = this; var _self = this;
this.own(router.register(/.*/, function(e){ // Register a route handling callback for any route, make sure it's cleaned up upon this controller being destroyed this.own(router.register(/.*/, function(e){ // Register a route handling callback for any route, make sure it's cleaned up upon this controller being destroyed
_self._set("hash", e.newPath); // Update hash property _self._set("hash", e.newPath); // Update hash property
})); }));
router.startup(); // Activate dojo/router router.startup(); // Activate dojo/router
this.set("hash", router._currentPath); // Set the inital value of hash property this.set("hash", router._currentPath); // Set the inital value of hash property
}, },
_setHashAttr: function(value){ _setHashAttr: function(value){
// summary: // summary:
// Handler for calls to set("hash", val). // Handler for calls to set("hash", val).
// description: // description:
// If the new value is different from location.hash, updates location.hash. // If the new value is different from location.hash, updates location.hash.
if(this.hash != value){ if(this.hash != value){
router.go(value); // If the new value is different from location.hash, updates location.hash router.go(value); // If the new value is different from location.hash, updates location.hash
} }
this._set("hash", value); // Assign the new value to the property this._set("hash", value); // Assign the new value to the property
} }
}); });
}) })
define([ define([
"dojo/_base/array", "dojo/_base/array",
"dojo/_base/declare", "dojo/_base/declare",
"dojo/Stateful", "dojo/Stateful",
"dojox/mvc/ModelRefController" "dojox/mvc/ModelRefController"
], function(array, declare, Stateful, ModelRefController){ ], function(array, declare, Stateful, ModelRefController){
return declare(ModelRefController, { return declare(ModelRefController, {
// summary: // summary:
// Our custom controller that does: // Our custom controller that does:
// //
// - Handle actions like adding/removing/marking // - Handle actions like adding/removing/marking
// - Provide references to the todo list in data model, whose data comes from above Dojo Object Store // - Provide references to the todo list in data model, whose data comes from above Dojo Object Store
// //
// description: // description:
// The todo list in the data model, which is based on dojox/mvc/StatefulArray, can be referred via this[this._refModelProp]. // The todo list in the data model, which is based on dojox/mvc/StatefulArray, can be referred via this[this._refModelProp].
// Actions are implemented in the manner of manipulating array. // Actions are implemented in the manner of manipulating array.
// The change will automatically be reflected to the UI via the notification system of dojox/mvc/StatefulArray. // The change will automatically be reflected to the UI via the notification system of dojox/mvc/StatefulArray.
addItem: function(/*String*/ title){ addItem: function(/*String*/ title){
// summary: // summary:
// Adds a todo item with the given title. // Adds a todo item with the given title.
// title: String // title: String
// The title of todo item. // The title of todo item.
this[this._refModelProp].push(new Stateful({title: title, completed: false})); this[this._refModelProp].push(new Stateful({title: title, completed: false}));
}, },
removeItem: function(/*String*/ uniqueId){ removeItem: function(/*String*/ uniqueId){
// summary: // summary:
// Removes a todo item having the given unique ID. // Removes a todo item having the given unique ID.
// uniqueId: String // uniqueId: String
// The unique ID of the todo item to be removed. // The unique ID of the todo item to be removed.
var model = this[this._refModelProp], var model = this[this._refModelProp],
indices = array.filter(array.map(model, function(item, idx){ return item.uniqueId == uniqueId ? idx : -1; }), function(idx){ return idx >= 0; }); // The array index of the todo item to bd removed indices = array.filter(array.map(model, function(item, idx){ return item.uniqueId == uniqueId ? idx : -1; }), function(idx){ return idx >= 0; }); // The array index of the todo item to bd removed
if(indices.length > 0){ if(indices.length > 0){
model.splice(indices[0], 1); model.splice(indices[0], 1);
} }
}, },
removeCompletedItems: function(){ removeCompletedItems: function(){
// summary: // summary:
// Removes todo items that have been marked as complete. // Removes todo items that have been marked as complete.
var model = this[this._refModelProp]; var model = this[this._refModelProp];
for(var i = model.length - 1; i >= 0; --i){ for(var i = model.length - 1; i >= 0; --i){
if(model[i].get("completed")){ if(model[i].get("completed")){
model.splice(i, 1); model.splice(i, 1);
} }
} }
}, },
markAll: function(/*Boolean*/ markComplete){ markAll: function(/*Boolean*/ markComplete){
// summary: // summary:
// Mark all todo items as complete or incomplete. // Mark all todo items as complete or incomplete.
// markComplete: Boolean // markComplete: Boolean
// True to mark all todo items as complete. Otherwise to mark all todo items as incomplete. // True to mark all todo items as complete. Otherwise to mark all todo items as incomplete.
array.forEach(this[this._refModelProp], function(item){ array.forEach(this[this._refModelProp], function(item){
item.set("completed", markComplete); item.set("completed", markComplete);
}); });
} }
}); });
}); });
define(["dojo/_base/declare"], function(declare){ define(["dojo/_base/declare"], function(declare){
var ACTIVE = "/active", var ACTIVE = "/active",
COMPLETED = "/completed"; COMPLETED = "/completed";
function getHiddenState(/*Object*/ props){ function getHiddenState(/*Object*/ props){
// summary: // summary:
// Returns the new hidden state of todo item, given the URL hash and the completed state of todo item. // Returns the new hidden state of todo item, given the URL hash and the completed state of todo item.
// props: Object // props: Object
// An object containing the URL hash and the completed state of todo item. // An object containing the URL hash and the completed state of todo item.
return props.hash == ACTIVE ? props.completed : return props.hash == ACTIVE ? props.completed :
props.hash == COMPLETED ? !props.completed : props.hash == COMPLETED ? !props.completed :
false; false;
} }
return declare(null, { return declare(null, {
// summary: // summary:
// 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. // 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.
// description: // description:
// A todo item should be hidden if: // A todo item should be hidden if:
// //
// - URL hash is "/active" and the todo item is complete -OR- // - URL hash is "/active" and the todo item is complete -OR-
// - URL hash is "/copleted" and the todo item is incomplete // - URL hash is "/copleted" and the todo item is incomplete
_setHashAttr: function(/*String*/ value){ _setHashAttr: function(/*String*/ value){
// summary: // summary:
// Handler for calls to set("hash", val), to update hidden state given the new value and the completed state. // Handler for calls to set("hash", val), to update hidden state given the new value and the completed state.
this.set("hidden", getHiddenState({hash: value, completed: this.completed})); // Update hidden state given the new value and the completed state this.set("hidden", getHiddenState({hash: value, completed: this.completed})); // Update hidden state given the new value and the completed state
this._set("hash", value); // Assign the new value to the attribute this._set("hash", value); // Assign the new value to the attribute
}, },
_setCompletedAttr: function(/*Boolean*/ value){ _setCompletedAttr: function(/*Boolean*/ value){
// summary: // summary:
// Handler for calls to set("completed", val), to update hidden state given the new value and the hash. // Handler for calls to set("completed", val), to update hidden state given the new value and the hash.
this.set("hidden", getHiddenState({hash: this.hash, completed: value})); // Update hidden state given the new value and the hash this.set("hidden", getHiddenState({hash: this.hash, completed: value})); // Update hidden state given the new value and the hash
this._set("completed", value); // Assign the new value to the attribute this._set("completed", value); // Assign the new value to the attribute
} }
}); });
}); });
define({ define({
// summary: // summary:
// A dojox/mvc data converter, that runs between todo/ctrl/HashController and a widget having <a> tag as its DOM node. // A dojox/mvc data converter, that runs between todo/ctrl/HashController and a widget having <a> tag as its DOM node.
// It does one-way conversion from URL hash to boolean state of whether the URL hash matches href attribute of the widget's DOM node. // It does one-way conversion from URL hash to boolean state of whether the URL hash matches href attribute of the widget's DOM node.
format: function(/*String*/ value){ format: function(/*String*/ value){
// summary: // summary:
// Returns whether given value matches href attribute of the widget's DOM node. // Returns whether given value matches href attribute of the widget's DOM node.
return this.target.domNode.getAttribute("href").substr(1) == (value || "/"); return this.target.domNode.getAttribute("href").substr(1) == (value || "/");
}, },
parse: function(/*Boolean*/ value){ parse: function(/*Boolean*/ value){
// summary: // summary:
// This functions throws an error so that the new value won't be reflected. // This functions throws an error so that the new value won't be reflected.
throw new Error(); throw new Error();
} }
}); });
define({ define({
// summary: // summary:
// A dojox/mvc data converter, that does one-way conversion that returns whether we have less than n todo items in a specific state, where n is the given number in data converter options. // A dojox/mvc data converter, that does one-way conversion that returns whether we have less than n todo items in a specific state, where n is the given number in data converter options.
// Data converter options can be specified by setting constraints property in one of data binding endpoints. // Data converter options can be specified by setting constraints property in one of data binding endpoints.
// See data converter section of dojox/mvc/sync library's documentation for more details. // See data converter section of dojox/mvc/sync library's documentation for more details.
format: function(/*Number*/ value, /*Object*/ constraints){ format: function(/*Number*/ value, /*Object*/ constraints){
// summary: // summary:
// Returns whether given value is less than or equal to the given number in data converter options (default zero). // Returns whether given value is less than or equal to the given number in data converter options (default zero).
return value <= (constraints.lessThanOrEqualTo || 0); return value <= (constraints.lessThanOrEqualTo || 0);
}, },
parse: function(/*Boolean*/ value){ parse: function(/*Boolean*/ value){
// summary: // summary:
// This functions throws an error so that the new value won't be reflected. // This functions throws an error so that the new value won't be reflected.
throw new Error(); throw new Error();
} }
}); });
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment