Permalink
Browse files

More work in progress on amd/dojo 2.0 conversion

  • Loading branch information...
1 parent 80aca8a commit 8b1f4977acd910edbc2f5a7a45cd942fb2a90ab6 @bvds committed Dec 26, 2013
Showing with 73 additions and 59 deletions.
  1. +4 −45 web-UI/andes/drawing.js
  2. +7 −4 web-UI/andes/error.js
  3. +7 −2 web-UI/andes/main.js
  4. +10 −7 web-UI/andes/options.js
  5. +44 −0 web-UI/andes/tracking.js
  6. +1 −1 web-UI/index.html
View
@@ -1,22 +1,17 @@
// Pre-AMD version had a function wrapper.
define([
"dojo/_base/declare",
+ "dojo/Evented",
"dojo/cookie",
"andes/startup",
"dojo/on",
"dijit/registry",
- "andes/PreferenceRegistry",
- "dojo/Evented"
-],function(declare,cookie,andes,on,registry,preferenceRegistry,Evented){
-
- // It would be better that this module returns an object called "drawing."
- // This is just to get things working with minimal changes to the pre-AMD version.
- andes.drawing={};
+ "andes/PreferenceRegistry"
+],function(declare,Evented,cookie,andes,on,registry,preferenceRegistry){
cookie("mikeDev", null, { expires: -1 });
// the html ID in index for the drawing app
- var drawingId = "drawing";
var _drawing;
var _surfaceLoaded = false;
@@ -72,44 +67,8 @@ define([
var items = {};
var masterMap = {};
-
- dojo.addOnLoad(function(){
- _drawing = registry.byId(drawingId);
- console.log("got drawing widget: ",_drawing);
- var cn = on(_drawing, "onSurfaceReady", function(){
- cn.remove();
- andes.WordTip.add(_drawing);
- andes.drawing.onSurfaceReady();
- if(_drawing.stencils){
- console.warn("Label double click connected");
- on(_drawing.stencils, "onLabelDoubleClick", andes.drawing, "onLabelDoubleClick");
- }
- });
- on(_drawing, "onRenderStencil", andes.drawing, "onRenderStencil");
-
- // Track user's focus on Andes. So far only whether they are using the window/tab
- // or have left to use another program
- if(dojo.isIE){
- on(dojo.global, "onfocus", andes.drawing, "onWindowFocus");
- // on(dojo.global, "onfocusin", andes.drawing, "onWindowFocus");
- on(dojo.doc, "onfocusout", this, function() {
- if (this._activeElement != document.activeElement){
- this._activeElement = document.activeElement;
- }else{
- andes.drawing.onWindowBlur();
- }
- });
- }else if(dojo.isSafari){
- on(window, "onblur", andes.drawing, "onWindowBlur");
- on(window, "onfocus", andes.drawing, "onWindowFocus");
- }else{
- on(dojo.doc, "onblur", andes.drawing, "onWindowBlur");
- on(dojo.doc, "onfocus", andes.drawing, "onWindowFocus");
- }
- });
-
- return declare([Evented],{
+ return declare(Evented,{
// summary:
// The master object that controls behavior of Drawing items
// and handles transfer of data between server and client
View
@@ -2,9 +2,11 @@
// Pre-AMD version had a function wrapper.
define([
"andes/startup",
+ "dojo/ready",
+ "dojo/_base/declare",
"dijit/Dialog",
"dijit/form/Button"
-],function(andes){
+],function(andes,ready,declare,dialog){
var dialog = null;
@@ -40,7 +42,8 @@ define([
andes.error.FATAL = 0;
andes.error.OK = 1;
- dojo.declare("andes.error._Error", dijit.Dialog, {
+ // In pre-AMD version, nothing outside this file uses _Error.
+ var _Error = declare(dialog, {
postCreate: function(){
this.inherited(arguments);
var container = dojo.create("div", {className:"dijitDialogPaneContent", style:"border-top:none;"});
@@ -92,8 +95,8 @@ define([
}
});
- dojo.addOnLoad(function(){
- dialog = new andes.error._Error({
+ ready(function(){
+ dialog = new _Error({
id: "andesErrorDialog",
title: "Error",
style: "width:400px"
View
@@ -9,9 +9,14 @@ define([
"andes/help",
"andes/api",
"andes/error",
- "andes/variablename"
+ "andes/variablename",
+ // new: pulled out of drawing.js
+ "andes/tracking"
],function(drawing){
// Pre-AMD body of main.js moved to startup.js.
// Pre-AMD version had "andes.drawing.load();" at very end of the file.
- drawing.load();
+ console.log("object returned by andes/drawing: ",drawing);
+ d= new drawing();
+ d.load();
+ return d;
});
View
@@ -3,8 +3,10 @@ define([
"dojo/on",
"dojo/_base/declare",
"andes/PreferenceRegistry",
+ "andes/defaults",
"dijit/ColorPalette"
-],function(andes,on,declare,preferenceRegistry){
+],function(andes,on,declare,preferenceRegistry,defaults){
+// pre-AMD version used myDrawing.defaults for defaults.
return declare(null,{
// Summary:
@@ -55,12 +57,11 @@ return declare(null,{
preferenceRegistry.registerPref(nm, this[this._prefs[nm]], this);
}
- // Initialize values -- myDrawing is a GLOBAL
- this.angleSnap.set('value', myDrawing.defaults.angleSnap);
- this.clickMode.set('label', myDrawing.defaults.clickMode ? "enabled" : "disabled");
+ this.angleSnap.set('value', defaults.angleSnap);
+ this.clickMode.set('label', defaults.clickMode ? "enabled" : "disabled");
this.showTimer.set('label', andes.timer.display ? "enabled" : "disabled");
- dojo.style(this.correct, "background", myDrawing.defaults.correct.color);
- dojo.style(this.incorrect, "background", myDrawing.defaults.incorrect.color);
+ dojo.style(this.correct, "background", defaults.correct.color);
+ dojo.style(this.incorrect, "background", defaults.incorrect.color);
var ops = this;
this.picker = new dijit.ColorPalette({
@@ -174,7 +175,9 @@ return declare(null,{
if(!f){
var o = {};
o[name] = value;
- myDrawing.changeDefaults(o, true);
+ // changeDefaults defined in dojox/drawing
+ console.log("at call to changeDefaults, defaults=",defaults);
+ defaults.changeDefaults(o, true);
}else{
f.call(s, value);
}
View
@@ -0,0 +1,44 @@
+define([
+ "andes/drawing",
+ "andes/startup",
+ "dojo/on",
+ "dijit/registry",
+ "dojo/ready"
+],function(drawing,andes,on,registry,ready){
+ // New to AMD version: this was pulled out of drawing.js
+
+ ready(function(){
+ _drawing = registry.byId("drawing");
+ console.log("got drawing widget: ",_drawing);
+ var cn = on(_drawing, "onSurfaceReady", function(){
+ cn.remove();
+ andes.WordTip.add(_drawing);
+ drawing.onSurfaceReady();
+ if(_drawing.stencils){
+ console.warn("Label double click connected");
+ on(_drawing.stencils, "onLabelDoubleClick", drawing, "onLabelDoubleClick");
+ }
+ });
+ on(_drawing, "onRenderStencil", drawing, "onRenderStencil");
+
+ // Track user's focus on Andes. So far only whether they are using the window/tab
+ // or have left to use another program
+ if(dojo.isIE){
+ on(dojo.global, "onfocus", drawing, "onWindowFocus");
+ // on(dojo.global, "onfocusin", drawing, "onWindowFocus");
+ on(dojo.doc, "onfocusout", this, function() {
+ if (this._activeElement != document.activeElement){
+ this._activeElement = document.activeElement;
+ }else{
+ drawing.onWindowBlur();
+ }
+ });
+ }else if(dojo.isSafari){
+ on(window, "onblur", drawing, "onWindowBlur");
+ on(window, "onfocus", drawing, "onWindowFocus");
+ }else{
+ on(dojo.doc, "onblur", drawing, "onWindowBlur");
+ on(dojo.doc, "onfocus", drawing, "onWindowFocus");
+ }
+ });
+});
View
@@ -80,7 +80,7 @@
<div data-dojo-type="dojox.drawing.ui.Toolbar" id="gfxToolbarNode" drawingId="drawing" class="gfxToolbar" orient="V" tools="line,rect,ellipse,textBlock,equation,vector,axes" plugs="all" selected=""></div>
</div>
<div id="drawingPane" data-dojo-type="dijit.layout.ContentPane" region="center" >
- <div data-dojo-type="dojox.drawing.Drawing" id="drawing" jsId="myDrawing" class="drawing" defaults="andes.defaults">
+ <div data-dojo-type="dojox.drawing.Drawing" id="drawing" data-dojo-id="myDrawing" class="drawing" defaults="andes.defaults">
</div>
</div>

0 comments on commit 8b1f497

Please sign in to comment.