Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

more work on amd conversion (in progress)

  • Loading branch information...
commit 27a80d2b3e5141548d8286dcb51a351125dd41a0 1 parent 34bcc3a
@bvds authored
Showing with 24 additions and 135 deletions.
  1. +1 −1  web-UI/andes/drawing.js
  2. +5 −125 web-UI/andes/main.js
  3. +18 −9 web-UI/andes/menu.js
View
2  web-UI/andes/drawing.js
@@ -1,5 +1,5 @@
// Pre-AMD version had a function wrapper.
-define(["dojo/cookie"],function(cookie){
+define(["dojo/cookie","andes/startup"],function(cookie){
cookie("mikeDev", null, { expires: -1 });
View
130 web-UI/andes/main.js
@@ -1,7 +1,5 @@
-// Pre-AMD version had "andes.drawing.load();" at very end of the file.
define([
- "andes/WordTip",
- // In the pre-AMD version, these were all at the end of the file:
+ // In the pre-AMD version, these were all after the body of main.js:
"andes/defaults",
"andes/PreferenceRegistry",
"andes/convert",
@@ -11,126 +9,8 @@ define([
"andes/api",
"andes/error",
"andes/variablename"
-],function(){ // Pre-AMD version had a function wrapper.
-
-
- // summary:
- // Handles loading of app and the timing of how items load.
-
- var devMode = true, query;
- if(!window.location.search){
- query = {
- p:"s2e",
- //p:"s2esolved",
- u:"joe1"
- };
- }else{
- query = dojo.queryToObject(window.location.search.substring(1));
- }
- if(!query.u || !query.p){
- dojo.addOnLoad(function(){
- console.error("FIXME: Finalize the error message for needing to return to WebAssign.");
- andes.error({
- title: "Fatal Error",
- message: "No user and/or problem data was provided; cannot continue. Please click on your browser's back button.",
- dialogType: andes.error.FATAL
- });
- });
- };
- // FNV-1a for string, 32 bit version, returning hex.
- var FNV1aHash = function(x){
- var hash = 0x811c9dc5; // 2166136261
- for (i = 0; i < x.length; i++) {
- hash ^= x.charCodeAt(i);
- hash *= 0x01000193; // 16777619
- }
- hash &= hash; // restrict to lower 32 bits.
- // javascript doesn't handle negatives correctly
- // when converting to hex.
- if(hash<0){
- hash = 0xffffffff + hash + 1;
- }
- return Number(hash).toString(16);
- };
- var setCookie = function(){
- // Andes database requires that clientID be 50 characters.
- andes.sessionId = FNV1aHash(andes.userId+andes.projectId) +
- '_' + new Date().getTime();
- var andesCookie = {
- u:andes.userId,
- p:andes.projectId,
- sid:andes.sessionId,
- closed:false
- };
- dojo.cookie("andes", dojo.toJson(andesCookie), { expires: 999 });
- };
-
- andes.closeFirst = false;
- andes.userId = query.u;
- andes.projectId = query.p;
- andes.sectionId = query.s || 1234;
- andes.extra = query.e; //extra field for Raj
- var ck = dojo.cookie("andes");
- if(ck && ck.u){
- // There was already a cookie here
- if(ck.u==andes.userId && ck.p==andes.projectId){
- // we can continue the same session
- andes.sessionId = ck.sid;
- }else{
- andes.closeFirst = true;
- console.warn("Closing previous session", ck.u, andes.userId, ck.p, andes.projectId)
- setCookie();
- }
- }else{
- setCookie();
- }
-
- dojo.addOnUnload(function(){
- andes.api.close({});
- // but don't clear cookie
- });
-
- dojo.addOnLoad(function(){
- // WordTip needs to be added before conEdit is removed by drawing
- andes.WordTip = new andes.WordTip();
-
- // Problem close actions set
- dojo.connect(dojo.byId("submitButton"), "click", function(){
- // Needs to be non-blocking
- var closer = andes.api.close({});
- closer.then(function(result){
- // console.log("Made the trip", result);
- // Look for url from server, if it doesn't
- // exist, default takes user back one page
- var url, found = false;
- dojo.forEach(result, function(entry){
- if(entry.url){
- found = true;
- //console.log("Found url: ",entry.url);
- url = entry.url;
- }
- });
-
- found ? window.location = url : history.go(-1);
- }, function(error){
- console.warn("Server Error", error);
- console.log("Returning to previous page");
- history.go(-1);
- });
- dojo.cookie("andes", null, { expires: -1 });
- // should look for url from server that
- // can overrride default.
- });
-
- // Splash animation
- var splashNode = dojo.byId("splashOverlay"),
- anim = dojo.fadeOut({node:dojo.byId("splashOverlay")}),
- _h = dojo.connect(anim, "onEnd", function(){
- dojo.disconnect(_h);
- dojo.style(splashNode, "display", "none");
- console.log("andes.main loaded");
- });
- anim.play();
- });
-
+],function(){
+ // Pre-AMD body of main.js moved to startup.js.
+ // Pre-AMD version had "andes.drawing.load();" at very end of the file.
+ andes.drawing.load();
});
View
27 web-UI/andes/menu.js
@@ -1,18 +1,21 @@
define([
- "dijit/registry",
+ "dojo/dom",
+ "dijit/registry",
+ "andes/startup",
"andes/options",
"dijit/Menu",
- "dijit/MenuSeparator"
-],function(registry){
+ "dijit/MenuSeparator",
+ "dojo/domReady!"
+],function(dom,registry,andes){
// In the pre-AMD version, the body was wrapped
// in "dojo.addOnLoad(function(){ ... })
-
+
// Add problem name to menu
- registry.byId("problemName").innerHTML = andes.projectId;
+ dom.byId("problemName").innerHTML = andes.projectId;
// shortcut for adding an onClick handler to a dijit
function wireItem(item, fn){
- var o = registry.byId(item);
+ var o = dom.byId(item);
if(o){
// Wrapper function which adds logging to server
// when menu item is selected.
@@ -80,14 +83,20 @@ define([
// Setup contextMenu and children
andes.contextMenu = new dijit.Menu();
+ require(["dojo/ready","dijit/registry","andes/startup"],
+ function(ready,registry,andes){
+ ready(function(){
+ // parser.parse();
var contextOptions = {};
for(var i in spec){
wireItem(i, spec[i]);
contextItem(i, spec[i]);
}
+ });
+ });
- function contextItem(desc, fn){
- var label = dijit.byId(desc).get("label");
+ function contextItem(desc, fn){
+ var label = registry.byId(desc).get("label");
// Hack I'll fix later
if(label=="Options" || label=="Introduction"){
andes.contextMenu.addChild(new dijit.MenuSeparator());
@@ -101,7 +110,7 @@ define([
// Set up option menu and right click menu
andes.options = new andes.options();
- var _drawing = dijit.byId("drawing");
+ var _drawing = dom.byId("drawing");
// Setup the menu onScreen
var cn = dojo.connect(_drawing, "onSurfaceReady", function(){
Please sign in to comment.
Something went wrong with that request. Please try again.