diff --git a/Gruntfile.js b/Gruntfile.js
new file mode 100644
index 000000000..b92920a1d
--- /dev/null
+++ b/Gruntfile.js
@@ -0,0 +1,54 @@
+module.exports = function(grunt) {
+
+ // Project configuration.
+ grunt.initConfig({
+ uglify: {
+ options: {
+ banner: '/*! Sugarizer <%= grunt.template.today("yyyy-mm-dd") %> */\n'
+ },
+ dynamic_mappings: {
+ expand: true,
+ src: [
+ 'lib/*.js',
+ 'js/*.js',
+ 'activities/Abecedarium.Activity/**/*.js',
+ 'activities/Calculate.Activity/**/*.js',
+ 'activities/ChatPrototype.Activity/**/*.js',
+ 'activities/Clock.Activity/**/*.js',
+ 'activities/Cordova.Activity/**/*.js',
+ 'activities/Etoys.Activity/**/*.js',
+ 'activities/FoodChain.Activity/**/*.js',
+ 'activities/Gears.Activity/js/*.js', // TODO: lib/gearsketch dont work
+ 'activities/GetThingsDone.Activity/**/*.js',
+ 'activities/Gridpaint.Activity/**/*.js',
+ 'activities/LabyrinthJS.Activity/**/*.js',
+ 'activities/LastOneLoses.Activity/**/*.js',
+ 'activities/Markdown.Activity/**/*.js',
+ 'activities/MazeWeb.Activity/**/*.js',
+ 'activities/MediaViewer.Activity/**/*.js',
+ 'activities/Memorize.Activity/**/*.js',
+ 'activities/Moon.Activity/**/*.js',
+ 'activities/Paint.Activity/**/*.js',
+ 'activities/PhysicsJS.Activity/**/*.js',
+ 'activities/Record.Activity/lib/*.js', // TODO: js/recordrtc.js don't work
+ 'activities/SharedNotes.Activity/**/*.js',
+ 'activities/Speak.Activity/**/*.js',
+ 'activities/Stopwatch.Activity/**/*.js',
+ 'activities/TamTamMicro.Activity/**/*.js',
+ 'activities/TankOp.Activity/**/*.js',
+ 'activities/TurtleBlocksJS.Activity/**/*.js',
+ 'activities/VideoViewer.Activity/**/*.js',
+ 'activities/WelcomeWeb.Activity/**/*.js'
+ ],
+ dest: 'build/'
+ }
+ }
+ });
+
+ // Load the plugin that provides the "uglify" task.
+ grunt.loadNpmTasks('grunt-contrib-uglify');
+
+ // Default task(s).
+ grunt.registerTask('default', ['uglify']);
+
+};
diff --git a/README.md b/README.md
index c6af84483..0dcf8acce 100644
--- a/README.md
+++ b/README.md
@@ -487,6 +487,22 @@ The activity will look for media content on the server referenced in [activities
To remove resources for **Etoys**, remove directory [activities/Etoys.activities/resources](activities/Etoys.activities/resources) and replace the value `resources/etoys.image` in [activities/Etoys.activities/index.html](activities/Etoys.activities/index.html) by the remote location of the resources, for example `http://server.sugarizer.org/activities/Etoys.activity/resources/etoys.image`.
+# Optimize performance
+
+If you want to optimize JavaScript performance, you could generate an optimized version of Sugarizer with [Grunt](http://gruntjs.com). This optimized version will minimize and reduce size of all JavaScript files.
+
+The [Gruntfile.js](Grunfile.js) contains tasks settings to build an optimized version of Sugarizer. To do that, ensure first that grunt is installed:
+
+ npm install -g grunt-cli
+
+Then just launch:
+
+ grunt
+
+At the end of the process, the `build` directory will contain the optimized version of each file in a same directory that the initial one, so you could just copy files:
+
+ cp -r build/* .
+
# Localization
Sugarizer use [webL10n](https://github.com/fabi1cazenave/webL10n) localization system by Fabien Cazenave.
diff --git a/activities/Abecedarium.activity/js/activity.js b/activities/Abecedarium.activity/js/activity.js
index 8753ec90f..5017f1e34 100644
--- a/activities/Abecedarium.activity/js/activity.js
+++ b/activities/Abecedarium.activity/js/activity.js
@@ -1,30 +1,30 @@
-define(function (require) {
- Abcd.activity = require("sugar-web/activity/activity");
+define(["sugar-web/activity/activity"], function (activity) {
+ Abcd.activity = activity;
app = null;
- // Manipulate the DOM only when it is ready.
- require(['domReady!'], function (doc) {
+ // Manipulate the DOM only when it is ready.
+ require(['domReady!'], function (doc) {
// Initialize the activity
Abcd.activity.setup();
-
+
// Create sound component
Abcd.sound = new Abcd.Audio();
Abcd.sound.renderInto(document.getElementById("header"));
// Create and display first screen
app = new Abcd.App().renderInto(document.getElementById("body"));
-
+
// Load context
Abcd.loadContext(function() {
app.restartLastGame();
- });
+ });
- // Stop sound at end of game to sanitize media environment, specifically on Android
- document.getElementById("stop-button").addEventListener('click', function (event) {
+ // Stop sound at end of game to sanitize media environment, specifically on Android
+ document.getElementById("stop-button").addEventListener('click', function (event) {
Abcd.sound.pause();
- });
- });
+ });
+ });
});
diff --git a/activities/ActivityTemplate/js/activity.js b/activities/ActivityTemplate/js/activity.js
index ff8197175..4d33360a5 100644
--- a/activities/ActivityTemplate/js/activity.js
+++ b/activities/ActivityTemplate/js/activity.js
@@ -1,12 +1,11 @@
-define(function (require) {
- var activity = require("sugar-web/activity/activity");
+define(["sugar-web/activity/activity"], function (activity) {
- // Manipulate the DOM only when it is ready.
- require(['domReady!'], function (doc) {
+ // Manipulate the DOM only when it is ready.
+ require(['domReady!'], function (doc) {
- // Initialize the activity.
- activity.setup();
+ // Initialize the activity.
+ activity.setup();
- });
+ });
});
diff --git a/activities/Calculate.activity/js/activity.js b/activities/Calculate.activity/js/activity.js
index 49d39ce29..43d989de2 100644
--- a/activities/Calculate.activity/js/activity.js
+++ b/activities/Calculate.activity/js/activity.js
@@ -2,14 +2,8 @@
//Please look at calculateapp.js to see the related functions
/* Start of the app, we require everything that is needed */
-define(function(require) {
- var activity = require("sugar-web/activity/activity");
- require("activity/calculate-activity");
- require("activity/calculate-app");
- require("math");
- require("parser");
- require("nanomodal");
- CalculateApp.libs.palette = require("sugar-web/graphics/palette");
+define(["sugar-web/activity/activity","mustache","sugar-web/graphics/palette","activity/calculate-activity","activity/calculate-app","math","parser","nanomodal"], function (activity, mustache, calcpalette) {
+ CalculateApp.libs.palette = calcpalette;
//function-plot depends on d3.
require(["d3"], function(d) {
@@ -19,7 +13,7 @@ define(function(require) {
});
CalculateApp.libs.activity = activity;
- CalculateApp.libs.mustache = require("mustache");
+ CalculateApp.libs.mustache = mustache;
require(['domReady!', 'activity/trigo-palette', 'activity/algebra-palette', 'webL10n', 'sugar-web/datastore'], function(doc, trigoPaletteLib, algebraPaletteLib, webL10n, datastore) {
CalculateApp.libs.webL10n = webL10n;
diff --git a/activities/ChatPrototype.activity/js/activity.js b/activities/ChatPrototype.activity/js/activity.js
index c994be5a4..fd1803c47 100644
--- a/activities/ChatPrototype.activity/js/activity.js
+++ b/activities/ChatPrototype.activity/js/activity.js
@@ -1,8 +1,6 @@
-define(function (require) {
+define(["sugar-web/activity/activity","sugar-web/graphics/palette","sugar-web/graphics/presencepalette"], function (activity,palette,presencepalette) {
var activity = require("sugar-web/activity/activity");
- var palette = require("sugar-web/graphics/palette");
- var presencepalette = require("sugar-web/graphics/presencepalette");
-
+
// Manipulate the DOM only when it is ready.
require(['domReady!'], function (doc) {
@@ -14,7 +12,7 @@ define(function (require) {
var messagesList = document.getElementById('messages');
var socketStatus = document.getElementById('status');
var messageContent = document.getElementById('content');
-
+
var userSettings = null;
// Connect to network
@@ -23,17 +21,17 @@ define(function (require) {
presenceObject = activity.getPresenceObject(function (error, presence) {
// Unable to join
if (error) {
- socketStatus.innerHTML = 'Error';
+ socketStatus.innerHTML = 'Error';
socketStatus.className = 'error';
return;
}
-
+
// Store settings
userSettings = presence.getUserInfo();
socketStatus.innerHTML = 'Connected';
socketStatus.className = 'open';
messageField.readOnly = false;
-
+
// Not found, create a new shared activity
if (!window.top.sugar.environment.sharedId) {
presence.createSharedActivity('org.sugarlabs.ChatPrototype', function (groupId) {
@@ -46,19 +44,19 @@ define(function (require) {
socketStatus.innerHTML = 'Disconnected from WebSocket.';
socketStatus.className = 'closed';
});
-
+
// Display connection changed
presence.onSharedActivityUserChanged(function (msg) {
var userName = msg.user.name.replace('<','<').replace('>','>');
messagesList.innerHTML += '
' + userName + (msg.move>0?' join':' leave') + ' the chat';
});
-
+
// Handle messages received
presence.onDataReceived(function (msg) {
var text = msg.content;
var author = msg.user.name.replace('<','<').replace('>','>');
var colour = msg.user.colorvalue;
-
+
var authorElem = '' + author + '';
myElem = document.createElement('li');
@@ -77,22 +75,22 @@ define(function (require) {
var networkButton = document.getElementById("network-button");
presencepalette = new presencepalette.PresencePalette(networkButton, undefined);
presencepalette.addEventListener('shared', shareActivity);
-
+
// Launched with a shared id, activity is already shared
if (window.top.sugar.environment.sharedId) {
shareActivity();
presencepalette.setShared(true);
}
-
+
// Handle message text update
messageField.onkeydown = function (e) {
if (e.keyCode === 13) {
var message = messageField.value;
-
+
// Send the message through the WebSocket.
var toSend = {user: userSettings, content: message};
presenceObject.sendMessage(presenceObject.getSharedInfo().id, toSend);
-
+
// Clear out the message field
messageField.placeholder = "Write your message here...";
messageField.value = "";
@@ -103,4 +101,4 @@ define(function (require) {
});
-});
\ No newline at end of file
+});
diff --git a/activities/Clock.activity/js/activity.js b/activities/Clock.activity/js/activity.js
index aa5320cfe..37adf4e6a 100644
--- a/activities/Clock.activity/js/activity.js
+++ b/activities/Clock.activity/js/activity.js
@@ -1,8 +1,4 @@
-define(function (require) {
- var activity = require("sugar-web/activity/activity");
- var radioButtonsGroup = require("sugar-web/graphics/radiobuttonsgroup");
- var mustache = require("mustache");
- var moment = require("moment");
+define(["sugar-web/activity/activity","sugar-web/graphics/radiobuttonsgroup","mustache","moment"], function (activity,radioButtonsGroup,mustache,moment) {
// Manipulate the DOM only when it is ready.
require(['domReady!'], function (doc) {
@@ -85,7 +81,7 @@ define(function (require) {
this.clockCanvasElem.style.display='none';
this.clockCanvasElem.offsetHeight;
this.clockCanvasElem.style.display='block';
- }
+ }
}
requestAnimationFrame(this.tick.bind(this));
}
@@ -140,7 +136,7 @@ define(function (require) {
this.clockContainerElem.style.height = this.size + "px";
this.clockCanvasElem.style.width = (this.size+4) + "px";
-
+
this.margin = this.size * 0.02;
this.radius = (this.size - (2 * this.margin)) / 2;
diff --git a/activities/Cordova.activity/js/activity.js b/activities/Cordova.activity/js/activity.js
index ff8197175..64bce4b2e 100644
--- a/activities/Cordova.activity/js/activity.js
+++ b/activities/Cordova.activity/js/activity.js
@@ -1,5 +1,4 @@
-define(function (require) {
- var activity = require("sugar-web/activity/activity");
+define(["sugar-web/activity/activity"], function (activity) {
// Manipulate the DOM only when it is ready.
require(['domReady!'], function (doc) {
diff --git a/activities/FoodChain.activity/js/activity.js b/activities/FoodChain.activity/js/activity.js
index 30199eaa4..439ca60e3 100644
--- a/activities/FoodChain.activity/js/activity.js
+++ b/activities/FoodChain.activity/js/activity.js
@@ -1,10 +1,7 @@
-define(function (require) {
- l10n = require("webL10n");
- var activity = require("sugar-web/activity/activity");
- var radioButtonsGroup = require("sugar-web/graphics/radiobuttonsgroup");
- var datastore = require("sugar-web/datastore");
+define(["sugar-web/activity/activity","webL10n","sugar-web/graphics/radiobuttonsgroup","sugar-web/datastore"], function (activity, _l10n, radioButtonsGroup, datastore) {
+ l10n = _l10n;
var app = null;
var isFirefoxOS = (navigator.userAgent.indexOf('Mozilla/5.0 (Mobile') != -1);
@@ -13,7 +10,7 @@ define(function (require) {
// Initialize the activity
FoodChain.activity = activity;
FoodChain.activity.setup();
-
+
// Initialize buttons
var languageRadio = new radioButtonsGroup.RadioButtonsGroup([
document.getElementById("en-button"),
@@ -27,7 +24,7 @@ define(function (require) {
l10n.language.code = "fr";
FoodChain.setLocale();
};
-
+
// Wait for locale load
var localized_received = function() {
// Init activity
@@ -37,16 +34,16 @@ define(function (require) {
FoodChain.sound.renderInto(document.getElementById("header"));
// Create and display first screen
- FoodChain.context.home = app = new FoodChain.App().renderInto(document.getElementById("body"));
+ FoodChain.context.home = app = new FoodChain.App().renderInto(document.getElementById("body"));
FoodChain.setLocale();
-
+
// Load context
FoodChain.loadContext(function() {
app.playGame({
name: FoodChain.context.game.replace("FoodChain.", ""),
level: FoodChain.context.level
});
- });
+ });
} else {
// Just change locale
FoodChain.setLocale();
@@ -60,7 +57,7 @@ define(function (require) {
// Stop sound at end of game to sanitize media environment, specifically on Android
document.getElementById("stop-button").addEventListener('click', function (event) {
FoodChain.sound.pause();
- });
+ });
});
});
diff --git a/activities/Gears.activity/js/activity.js b/activities/Gears.activity/js/activity.js
index c219a3b11..5b41e7b79 100644
--- a/activities/Gears.activity/js/activity.js
+++ b/activities/Gears.activity/js/activity.js
@@ -1,7 +1,4 @@
-define(function (require) {
- var activity = require("sugar-web/activity/activity");
- var radioButtonsGroup = require("sugar-web/graphics/radiobuttonsgroup");
- require("gearsketch_main");
+define(["sugar-web/activity/activity","sugar-web/graphics/radiobuttonsgroup","gearsketch_main"], function (activity,radioButtonsGroup) {
// Manipulate the DOM only when it is ready.
require(['domReady!'], function (doc) {
diff --git a/activities/GetThingsDone.activity/js/activity.js b/activities/GetThingsDone.activity/js/activity.js
index 7666ffba0..411692b41 100644
--- a/activities/GetThingsDone.activity/js/activity.js
+++ b/activities/GetThingsDone.activity/js/activity.js
@@ -1,10 +1,4 @@
-define(function (require) {
- var activity = require("sugar-web/activity/activity");
- var datastore = require("sugar-web/datastore");
-
- var model = require("activity/model");
- var view = require("activity/view");
- var controller = require("activity/controller");
+define(["sugar-web/activity/activity","sugar-web/datastore","activity/model","activity/view","activity/controller"], function (activity,datastore,model,view,controller) {
// Manipulate the DOM only when it is ready.
require(['domReady!'], function (doc) {
diff --git a/activities/Gridpaint.activity/js/activity.js b/activities/Gridpaint.activity/js/activity.js
index fcff6c969..d2c4b7e7a 100644
--- a/activities/Gridpaint.activity/js/activity.js
+++ b/activities/Gridpaint.activity/js/activity.js
@@ -27,9 +27,8 @@
// If you want to add features please make a fork with a different name.
// Thanks in advance
-define(function (require) {
- activity = require("sugar-web/activity/activity");
- var datastore = require("sugar-web/datastore");
+define(["sugar-web/activity/activity","sugar-web/datastore"], function (_activity, datastore) {
+ activity = _activity;
// Manipulate the DOM only when it is ready.
require(['domReady!'], function (doc) {
@@ -39,7 +38,7 @@ define(function (require) {
// Init activity and launch it
loadGallery(null);
- appInit();
+ appInit();
// Load gallery from datastore
datastoreObject.loadAsText(function (error, metadata, data) {
diff --git a/activities/LabyrinthJS.activity/js/activity.js b/activities/LabyrinthJS.activity/js/activity.js
index 9c1518906..d732c4984 100644
--- a/activities/LabyrinthJS.activity/js/activity.js
+++ b/activities/LabyrinthJS.activity/js/activity.js
@@ -1,10 +1,4 @@
-define(function (require) {
- var l10n = require("webL10n");
- var activity = require("sugar-web/activity/activity");
- var datastore = require("sugar-web/datastore");
- var colorpalette = require("sugar-web/graphics/colorpalette");
- var zoompalette = require("zoompalette");
- var textpalette = require("fontpalette");
+define(["sugar-web/activity/activity","webL10n","sugar-web/datastore","sugar-web/graphics/colorpalette","zoompalette","fontpalette"], function (activity, l10n, datastore, colorpalette, zoompalette, textpalette) {
// Manipulate the DOM only when it is ready.
require(['domReady!'], function (doc) {
@@ -30,7 +24,7 @@ define(function (require) {
unselectAllNode();
lastSelected = null;
}
- }
+ }
nodetextButton.addEventListener('click', function () { switchMode(0); }, true);
linkButton.addEventListener('click', function () { switchMode(1); lastSelected = null; }, true);
removeButton.addEventListener('click', function () { switchMode(2); }, true);
@@ -70,7 +64,7 @@ define(function (require) {
console.log("export done.")
}, inputData);
});
-
+
// Handle sub toolbar
var subToolbar = document.getElementById("sub-toolbar");
var textValue = document.getElementById("textvalue");
@@ -88,7 +82,7 @@ define(function (require) {
var fontPlusButton = document.getElementById("fontplus-button");
var fontButton = document.getElementById("font-button");
fontPalette = new textpalette.TextPalette(fontButton);
-
+
foregroundPalette.addEventListener('colorChange', function(e) {
if (!ignoreForegroundEvent) {
lastSelected.style('color', e.detail.color);
@@ -97,7 +91,7 @@ define(function (require) {
}
ignoreForegroundEvent = false;
});
-
+
backgroundPalette.addEventListener('colorChange', function(e) {
if (!ignoreBackgroundEvent) {
lastSelected.style('background-color', e.detail.color);
@@ -106,7 +100,7 @@ define(function (require) {
}
ignoreBackgroundEvent = false;
});
-
+
fontPalette.addEventListener('fontChange', function(e) {
var newfont = e.detail.family;
lastSelected.data('font-family', newfont);
@@ -117,12 +111,12 @@ define(function (require) {
else if (newfont == 'Verdana') lastSelected.addClass('verdana-text');
pushState();
});
-
+
textValue.addEventListener('input', function() {
updateNodeText(lastSelected, textValue.value);
pushState();
});
-
+
boldButton.addEventListener('click', function () {
lastSelected.toggleClass('bold-text');
if (lastSelected.hasClass('bold-text')) {
@@ -138,24 +132,24 @@ define(function (require) {
if (lastSelected.hasClass('italic-text')) {
italicButton.classList.add('active');
} else {
- italicButton.classList.remove('active');
+ italicButton.classList.remove('active');
}
updateNodeText(lastSelected);
pushState();
});
-
+
fontMinusButton.addEventListener('click', function() {
lastSelected.data('font-size', Math.max(6, lastSelected.data('font-size')-2));
updateNodeText(lastSelected);
pushState();
});
-
+
fontPlusButton.addEventListener('click', function() {
lastSelected.data('font-size', Math.min(100, lastSelected.data('font-size')+2));
updateNodeText(lastSelected);
pushState();
});
-
+
var showSubToolbar = function(node) {
zoomPalette.popDown();
subToolbar.style.visibility = "visible";
@@ -182,7 +176,7 @@ define(function (require) {
foregroundPalette.popDown();
fontPalette.popDown();
}
-
+
// Handle graph save/world
var stopButton = document.getElementById("stop-button");
stopButton.addEventListener('click', function (event) {
@@ -196,7 +190,7 @@ define(function (require) {
}
});
});
-
+
// Handle localization
window.addEventListener('localized', function() {
var navigatorLanguage = navigator.language;
@@ -223,13 +217,13 @@ define(function (require) {
fontButton.title = l10n.get("fontButtonTitle");
pngButton.title = l10n.get("pngButtonTitle");
}, false);
-
+
// --- Cytoscape handling
-
+
// Initialize board
cy = cytoscape({
container: document.getElementById('cy'),
-
+
ready: function() {
// Create first node and select id
var firstNode = createNode(defaultText, getCenter());
@@ -238,11 +232,11 @@ define(function (require) {
lastSelected = firstNode;
showSubToolbar(firstNode);
pushState();
-
+
// Load world
loadGraph();
},
-
+
style: [
{
selector: '.standard-node',
@@ -251,7 +245,7 @@ define(function (require) {
'text-halign': 'center',
'border-color': 'darkgray',
'border-width': '1px',
- 'shape': 'roundrectangle'
+ 'shape': 'roundrectangle'
}
},
{
@@ -286,7 +280,7 @@ define(function (require) {
}
]
});
-
+
// Event: a node is selected
cy.on('tap', 'node', function() {
if (currentMode == 2) {
@@ -331,7 +325,7 @@ define(function (require) {
}
hideSubToolbar();
});
-
+
// Event: tap on the board
cy.on('tap', function(e){
if (e.cyTarget === cy) {
@@ -349,7 +343,7 @@ define(function (require) {
}
}
});
-
+
// Event: elements moved
cy.on('free', 'node', function(e) {
pushState();
@@ -362,7 +356,7 @@ define(function (require) {
var defaultFontSize = 16;
var lastSelected = null;
var defaultText = "";
-
+
// Create a new node with text and position
var createNode = function(text, position) {
var size = computeStringSize(text, defaultFontFamily, defaultFontSize, false, false);
@@ -399,7 +393,7 @@ define(function (require) {
newnode.addClass('standard-node');
return newnode;
}
-
+
// Update node text and change size
var updateNodeText = function(node, text) {
if (text === undefined) text = node.style()['content'];
@@ -413,14 +407,14 @@ define(function (require) {
'font-family': fontFamily,
'width': size.width,
'height': size.height
- });
+ });
}
-
+
// Test if node is selected
var isSelectedNode = function(node) {
return node.style()['border-style'] == 'dashed';
}
-
+
// Set node as selected
var selectNode = function(node) {
node.style({
@@ -429,16 +423,16 @@ define(function (require) {
'border-width': '4px'
});
}
-
+
// Set node as unselected
var unselectNode = function(node) {
node.style({
'border-color': 'darkgray',
'border-style': 'solid',
'border-width': '1px'
- });
+ });
}
-
+
// Unselect all node
var unselectAllNode = function() {
var nodes = cy.collection("node");
@@ -446,12 +440,12 @@ define(function (require) {
unselectNode(nodes[i]);
}
}
-
+
// Delete node, linked edges are removed too
var deleteNode = function(node) {
cy.remove(node);
}
-
+
// Create a new edge between two nodes
var createEdge = function(n1, n2) {
cy.add({
@@ -461,12 +455,12 @@ define(function (require) {
]
});
}
-
+
// Remove an edge
var deleteEdge = function(edge) {
cy.remove(edge);
}
-
+
// --- Utility functions
// HACK: dynamically compute need size putting the string in a hidden div element
var computeStringSize = function(text, fontfamily, fontsize, bold, italic) {
@@ -480,15 +474,15 @@ define(function (require) {
else computer.style.fontStyle = "normal";
return {width: (computer.clientWidth+fontsize)+"px", height: (computer.clientHeight+fontsize)+"px"};
}
-
+
// Get center of drawing zone
var getCenter = function() {
var canvas = document.getElementById("canvas");
var center = {x: canvas.clientWidth/2, y: canvas.clientHeight/2};
return center;
}
-
- // Load graph from datastore
+
+ // Load graph from datastore
var loadGraph = function() {
var datastoreObject = activity.getDatastoreObject();
datastoreObject.loadAsText(function (error, metadata, data) {
@@ -499,7 +493,7 @@ define(function (require) {
pushState();
});
}
-
+
// Save graph to datastore
var saveGraph = function(callback) {
var datastoreObject = activity.getDatastoreObject();
@@ -507,7 +501,7 @@ define(function (require) {
datastoreObject.setDataAsText(JSON.stringify(jsonData));
datastoreObject.save(callback);
}
-
+
// Get a deep copy of current Graph
var deepCopy = function(o) {
var copy = o,k;
@@ -522,7 +516,7 @@ define(function (require) {
var getGraph = function() {
return deepCopy(cy.json());
}
-
+
// Display a saved graph
var displayGraph = function(graph) {
// Destroy the graph
@@ -530,7 +524,7 @@ define(function (require) {
cy.remove("edge");
hideSubToolbar();
lastSelected = null;
-
+
// Recreate nodes and set styles and text
cy.add({
group: 'nodes',
@@ -547,7 +541,7 @@ define(function (require) {
if (id > maxCount) maxCount = id;
}
nodeCount = maxCount+1;
-
+
// Recreate edges
maxCount = 0;
if (graph.elements.edges) {
@@ -563,7 +557,7 @@ define(function (require) {
}
edgeCount = maxCount+1;
}
-
+
// Do/Undo handling
var stateHistory = [];
var stateIndex = 0;
@@ -577,7 +571,7 @@ define(function (require) {
stateHistory = [];
stateIndex = 0;
}
-
+
var pushState = function() {
if (stateIndex < stateHistory.length - 1) {
var stateCopy = [];
@@ -597,19 +591,19 @@ define(function (require) {
stateIndex = stateHistory.length - 1;
updateStateButtons();
}
-
+
var undoState = function() {
if (stateHistory.length < 1 || (stateHistory.length >= 1 && stateIndex == 0)) return;
displayGraph(stateHistory[--stateIndex]);
updateStateButtons();
}
-
+
var redoState = function() {
if (stateIndex+1 >= stateHistory.length) return;
displayGraph(stateHistory[++stateIndex]);
updateStateButtons();
}
-
+
var updateStateButtons = function() {
var stateLength = stateHistory.length;
undoButton.disabled = (stateHistory.length < 1 || (stateHistory.length >= 1 && stateIndex == 0));
diff --git a/activities/LastOneLoses.activity/js/activity.js b/activities/LastOneLoses.activity/js/activity.js
index c46fc3216..f44601ea4 100644
--- a/activities/LastOneLoses.activity/js/activity.js
+++ b/activities/LastOneLoses.activity/js/activity.js
@@ -1,7 +1,5 @@
-define(function (require) {
- var activity = require("sugar-web/activity/activity");
- var radioButtonsGroup = require("sugar-web/graphics/radiobuttonsgroup");
+define(["sugar-web/activity/activity", "sugar-web/graphics/radiobuttonsgroup"], function (activity, radioButtonsGroup) {
var app;
// Manipulate the DOM only when it is ready.
@@ -13,7 +11,7 @@ define(function (require) {
// Initialize buttons
document.getElementById("new-game-button").onclick = function() {
app.doRenew();
- };
+ };
var levelRadio = new radioButtonsGroup.RadioButtonsGroup([
document.getElementById("level-easy-button"),
document.getElementById("level-medium-button"),
@@ -22,7 +20,7 @@ define(function (require) {
document.getElementById("switch-player-button").onclick = function() {
app.switchPlayer();
};
-
+
// Initialize the game
app = new LOLGameApp({activity: activity});
app.load();
diff --git a/activities/Markdown.activity/js/activity.js b/activities/Markdown.activity/js/activity.js
index 4e8535d5f..1abd2010b 100644
--- a/activities/Markdown.activity/js/activity.js
+++ b/activities/Markdown.activity/js/activity.js
@@ -1,6 +1,4 @@
-define(function (require) {
- var activity = require("sugar-web/activity/activity");
- var datastore = require("sugar-web/datastore");
+define(["sugar-web/activity/activity","sugar-web/datastore"], function (activity, datastore) {
// Manipulate the DOM only when it is ready.
require(['domReady!'], function (doc) {
@@ -15,7 +13,7 @@ define(function (require) {
var datastoreObject = activity.getDatastoreObject();
inputTextContent.onblur = function () {
-
+
var jsonData = JSON.stringify((inputTextContent.value).toString());
datastoreObject.setDataAsText(jsonData);
datastoreObject.save(function () {});
@@ -34,7 +32,7 @@ define(function (require) {
//result1 = result.toString();
var datastoreObject2 = new datastore.DatastoreObject(result);
datastoreObject2.loadAsText(function (error, metadata, data) {
-
+
try {
textdata = JSON.parse(data);
} catch (e) {
@@ -91,4 +89,4 @@ define(function (require) {
});
-});
\ No newline at end of file
+});
diff --git a/activities/MazeWeb.activity/js/activity.js b/activities/MazeWeb.activity/js/activity.js
index a99ade3c5..ee9bee34b 100644
--- a/activities/MazeWeb.activity/js/activity.js
+++ b/activities/MazeWeb.activity/js/activity.js
@@ -1,10 +1,4 @@
-define(function (require) {
- var activity = require("sugar-web/activity/activity");
- var TWEEN = require("tween");
- require("rAF");
-
- var maze = require("activity/maze");
- var directions = require("activity/directions");
+define(["sugar-web/activity/activity","tween","rAF","activity/maze","activity/directions"], function (activity, TWEEN, rAF, maze, directions) {
require(['domReady!'], function (doc) {
activity.setup();
diff --git a/activities/MazeWeb.activity/js/maze.js b/activities/MazeWeb.activity/js/maze.js
index f4616e27b..795f6cabe 100644
--- a/activities/MazeWeb.activity/js/maze.js
+++ b/activities/MazeWeb.activity/js/maze.js
@@ -1,7 +1,4 @@
-define(function (require) {
- var ROT = require("rot");
-
- var directions = require("activity/directions");
+define(["rot","activity/directions"], function (ROT, directions) {
var maze = {};
diff --git a/activities/MediaViewer.activity/js/activity.js b/activities/MediaViewer.activity/js/activity.js
index 3e03f4422..71c17bb69 100644
--- a/activities/MediaViewer.activity/js/activity.js
+++ b/activities/MediaViewer.activity/js/activity.js
@@ -1,6 +1,5 @@
/* Start of the app, we require everything that is needed */
-define(function (require) {
- var activity = require("sugar-web/activity/activity");
+define(["sugar-web/activity/activity"], function (activity) {
require(['domReady!', 'sugar-web/datastore'], function (doc, datastore) {
activity.setup();
@@ -98,4 +97,4 @@ function displayImage(data) {
}
document.getElementById("media").appendChild(img);
-}
\ No newline at end of file
+}
diff --git a/activities/Moon.activity/js/activity.js b/activities/Moon.activity/js/activity.js
index 886154a89..6dd4d3a8a 100644
--- a/activities/Moon.activity/js/activity.js
+++ b/activities/Moon.activity/js/activity.js
@@ -1,7 +1,5 @@
-define(function (require) {
- var activity = require("sugar-web/activity/activity");
- var moonActivity = require("activity/moon-activity");
- var l10n = require("webL10n");
+
+define(["sugar-web/activity/activity","activity/moon-activity","webL10n"], function (activity, moonActivity, l10n) {
// Manipulate the DOM only when it is ready.
require(['domReady!'], function (doc) {
diff --git a/activities/Paint.activity/js/activity.js b/activities/Paint.activity/js/activity.js
index 64266c4f8..98ac5d2da 100644
--- a/activities/Paint.activity/js/activity.js
+++ b/activities/Paint.activity/js/activity.js
@@ -1,36 +1,33 @@
/* Start of the app, we require everything that is needed */
-define(function(require) {
- var activity = require("sugar-web/activity/activity");
-
- window.PaintApp = require("activity/paint-app");
- require("activity/paint-activity");
+define(["sugar-web/activity/activity","activity/paint-activity","activity/paint-app","sugar-web/graphics/presencepalette","activity/palettes/color-palette","activity/palettes/stamp-palette","activity/palettes/text-palette","activity/palettes/drawings-palette","activity/palettes/filters-palette","activity/buttons/size-button","activity/buttons/clear-button","activity/buttons/undo-button","activity/buttons/redo-button","activity/modes/modes-pen","activity/modes/modes-eraser","activity/modes/modes-bucket","activity/modes/modes-text","activity/modes/modes-stamp","activity/modes/modes-copy","activity/modes/modes-paste","activity/collaboration"], function (activity,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,p16,p17,p18,p19,p20) {
+ window.PaintApp = p2;
PaintApp.libs.activity = activity;
/* Fetching and storing of the palettes */
- PaintApp.palettes.presencePalette = require("sugar-web/graphics/presencepalette");
- PaintApp.palettes.colorPalette = require("activity/palettes/color-palette");
- PaintApp.palettes.stampPalette = require("activity/palettes/stamp-palette");
- PaintApp.palettes.textPalette = require("activity/palettes/text-palette");
- PaintApp.palettes.drawingsPalette = require("activity/palettes/drawings-palette");
- PaintApp.palettes.filtersPalette = require("activity/palettes/filters-palette");
+ PaintApp.palettes.presencePalette = p3;
+ PaintApp.palettes.colorPalette = p4;
+ PaintApp.palettes.stampPalette = p5;
+ PaintApp.palettes.textPalette = p6;
+ PaintApp.palettes.drawingsPalette = p7;
+ PaintApp.palettes.filtersPalette = p8;
/* Fetching and storing of the buttons */
- PaintApp.buttons.sizeButton = require("activity/buttons/size-button");
- PaintApp.buttons.clearButton = require("activity/buttons/clear-button");
- PaintApp.buttons.undoButton = require("activity/buttons/undo-button");
- PaintApp.buttons.redoButton = require("activity/buttons/redo-button");
+ PaintApp.buttons.sizeButton = p9;
+ PaintApp.buttons.clearButton = p10;
+ PaintApp.buttons.undoButton = p11;
+ PaintApp.buttons.redoButton = p12;
/* Fetching and storing of the modes */
- PaintApp.modes.Pen = require("activity/modes/modes-pen");
- PaintApp.modes.Eraser = require("activity/modes/modes-eraser");
- PaintApp.modes.Bucket = require("activity/modes/modes-bucket");
- PaintApp.modes.Text = require("activity/modes/modes-text");
- PaintApp.modes.Stamp = require("activity/modes/modes-stamp");
- PaintApp.modes.Copy = require("activity/modes/modes-copy");
- PaintApp.modes.Paste = require("activity/modes/modes-paste");
-
- PaintApp.collaboration = require("activity/collaboration");
+ PaintApp.modes.Pen = p13;
+ PaintApp.modes.Eraser = p14;
+ PaintApp.modes.Bucket = p15;
+ PaintApp.modes.Text = p16;
+ PaintApp.modes.Stamp = p17;
+ PaintApp.modes.Copy = p18;
+ PaintApp.modes.Paste = p19;
+
+ PaintApp.collaboration = p20;
require(['domReady!', 'sugar-web/datastore', 'paper-core', 'mustache', 'lzstring', 'humane'], function(doc, datastore, _paper, mustache, lzstring, humane) {
diff --git a/activities/PhysicsJS.activity/js/activity.js b/activities/PhysicsJS.activity/js/activity.js
index 1e07afbcb..a4941ca02 100644
--- a/activities/PhysicsJS.activity/js/activity.js
+++ b/activities/PhysicsJS.activity/js/activity.js
@@ -1,12 +1,11 @@
-define(function (require) {
- var activity = require("sugar-web/activity/activity");
+define(["sugar-web/activity/activity"], function (activity) {
- // Manipulate the DOM only when it is ready.
- require(['domReady!'], function (doc) {
+ // Manipulate the DOM only when it is ready.
+ require(['domReady!'], function (doc) {
+
+ // Initialize the activity
+ activity.setup();
- // Initialize the activity
- activity.setup();
-
// Initialize cordova
var useragent = navigator.userAgent.toLowerCase();
var sensorButton = document.getElementById("sensor-button");
@@ -24,7 +23,7 @@ define(function (require) {
} else {
sensorButton.disabled = true;
}
-
+
// Initialize the world
var body = document.getElementById("body");
var innerWidth = body.offsetWidth;
@@ -87,7 +86,7 @@ define(function (require) {
zoom();
}, true);
-
+
// handle toolbar buttons
document.getElementById("box-button").addEventListener('click', function (e) {
currentType = 1;
@@ -95,26 +94,26 @@ define(function (require) {
}, true);
document.getElementById("circle-button").addEventListener('click', function (e) {
currentType = 0;
- switchToType(currentType);
+ switchToType(currentType);
}, true);
-
+
document.getElementById("triangle-button").addEventListener('click', function (e) {
currentType = 2;
- switchToType(currentType);
+ switchToType(currentType);
}, true);
-
+
document.getElementById("polygon-button").addEventListener('click', function (e) {
currentType = 3;
- switchToType(currentType);
+ switchToType(currentType);
}, true);
-
+
gravityButton.addEventListener('click', function () {
setGravity((gravityMode + 1)%8);
}, true);
document.getElementById("clear-button").addEventListener('click', function () {
currentType = -1;
- switchToType(currentType);
+ switchToType(currentType);
}, true);
// Handle acceleration and gravity mode
@@ -125,7 +124,7 @@ define(function (require) {
else
sensorButton.classList.remove('active');
}, true);
-
+
appleButton.addEventListener('click', function () {
newtonMode = !newtonMode;
if (newtonMode) {
@@ -135,12 +134,12 @@ define(function (require) {
gravityButton.disabled = true;
} else {
world.remove(newton);
- world.add(gravity);
+ world.add(gravity);
appleButton.classList.remove('active');
gravityButton.disabled = false;
}
}, true);
-
+
function accelerationChanged(acceleration) {
if (!sensorMode) return;
if (acceleration.x < -4.5) {
@@ -149,12 +148,12 @@ define(function (require) {
else if (acceleration.y < -4.75)
setGravity(5);
else
- setGravity(4);
+ setGravity(4);
} else if (acceleration.x <= 4.5 && acceleration.x >= -4.5) {
if (acceleration.y > 4.75)
setGravity(2);
else if (acceleration.y < -4.75)
- setGravity(6);
+ setGravity(6);
} else if (acceleration.x > 4.5) {
if (acceleration.y > 4.75)
setGravity(1);
@@ -164,7 +163,7 @@ define(function (require) {
setGravity(0);
}
}
-
+
// Save/Load world
loadWorld();
var stopButton = document.getElementById("stop-button");
@@ -193,7 +192,7 @@ define(function (require) {
if (window.devicePixelRatio == 1) {
return;
}
- var canvas = document.getElementById("viewport").children[0];
+ var canvas = document.getElementById("viewport").children[0];
var zoom = 1.0 / window.devicePixelRatio;
canvas.style.zoom = zoom;
var useragent = navigator.userAgent.toLowerCase();
@@ -202,14 +201,14 @@ define(function (require) {
canvas.style.MozTransformOrigin = "0 0";
}
}
-
+
function random( min, max ){
return (Math.random() * (max-min) + min)|0;
}
function switchToType(newtype) {
- document.getElementById("box-button").classList.remove('active');
- document.getElementById("circle-button").classList.remove('active');
+ document.getElementById("box-button").classList.remove('active');
+ document.getElementById("circle-button").classList.remove('active');
document.getElementById("polygon-button").classList.remove('active');
document.getElementById("triangle-button").classList.remove('active');
document.getElementById("clear-button").classList.remove('active');
@@ -219,7 +218,7 @@ define(function (require) {
else if (newtype == 3) document.getElementById("polygon-button").classList.add('active');
else if (newtype == -1) document.getElementById("clear-button").classList.add('active');
}
-
+
function dropInBody(type, pos){
var body;
@@ -265,7 +264,7 @@ define(function (require) {
});
break;
-
+
// add a polygon
case 2:
case 3:
@@ -289,11 +288,11 @@ define(function (require) {
}
body.treatment = "static";
-
+
world.add( body );
return body;
}
-
+
// Save world to datastore
function saveWorld(callback) {
// Build bodies list
@@ -303,14 +302,14 @@ define(function (require) {
var object = serializeObject(bodies[i]);
objects.push(object);
}
-
+
// Save to datastore
var datastoreObject = activity.getDatastoreObject();
var jsonData = JSON.stringify({world: objects});
datastoreObject.setDataAsText(jsonData);
datastoreObject.save(callback);
}
-
+
function serializeObject(body) {
var object = {};
object.type = body.geometry.name;
@@ -324,11 +323,11 @@ define(function (require) {
}
object.restitution = body.restitution;
object.styles = body.styles;
- object.x = body.view.x;
+ object.x = body.view.x;
object.y = body.view.y;
return object;
}
-
+
// Load world from datastore
function loadWorld(objects) {
var datastoreObject = activity.getDatastoreObject();
@@ -336,7 +335,7 @@ define(function (require) {
var data = JSON.parse(data);
if (data == null)
return;
-
+
// Create bodies
var objects = data.world;
for(var i = 0 ; i < objects.length ; i++) {
@@ -345,7 +344,7 @@ define(function (require) {
}
});
}
-
+
function deserializeObject(savedObject) {
var newOptions = {
x: savedObject.x,
@@ -358,14 +357,14 @@ define(function (require) {
if (savedObject.type == "circle") {
newOptions.radius = savedObject.radius;
} else if (savedObject.type == "rectangle") {
- newOptions.width = savedObject.width;
- newOptions.height = savedObject.height;
+ newOptions.width = savedObject.width;
+ newOptions.height = savedObject.height;
} else if (savedObject.type = "convex-polygon") {
newOptions.vertices = savedObject.vertices;
}
return Physics.body(savedObject.type, newOptions);
}
-
+
// Change gravity value
function setGravity(value) {
if (gravityMode == value) return;
@@ -384,24 +383,24 @@ define(function (require) {
case 3:
acc = { x: 0.0004, y: -0.0004 };
break;
- case 4:
- acc = { x: 0, y: -0.0004 };
+ case 4:
+ acc = { x: 0, y: -0.0004 };
break;
- case 5:
- acc = { x: -0.0004, y: -0.0004 };
+ case 5:
+ acc = { x: -0.0004, y: -0.0004 };
break;
- case 6:
- acc = { x: -0.0004, y: 0 };
+ case 6:
+ acc = { x: -0.0004, y: 0 };
break;
- case 7:
- acc = { x: -0.0004, y: 0.0004 };
+ case 7:
+ acc = { x: -0.0004, y: 0.0004 };
break;
}
gravity.setAcceleration(acc);
- world.wakeUpAll();
+ world.wakeUpAll();
gravityMode = value;
}
-
+
// add some fun interaction
var createdBody = null;
var createdStart = null;
@@ -450,7 +449,7 @@ define(function (require) {
,'interact:grab': function ( data ) {
if (currentType == -1) {
world.remove(data.body);
- }
+ }
}
});
@@ -469,8 +468,8 @@ define(function (require) {
Physics.util.ticker.on(function( time ) {
// next step
world.step( time );
-
- // remove bodies out of
+
+ // remove bodies out of
var bodies = world.getBodies();
var limit = outerWidth / 2;
if (limit > 0) {
diff --git a/activities/Record.activity/js/activity.js b/activities/Record.activity/js/activity.js
index 6337dcb28..a7b6233e4 100644
--- a/activities/Record.activity/js/activity.js
+++ b/activities/Record.activity/js/activity.js
@@ -1,12 +1,5 @@
/* Start of the app, we require everything that is needed */
-define(function (require) {
- var activity = require("sugar-web/activity/activity");
- var presence = require("sugar-web/presence");
- var captureHelper = require("activity/capture-helper");
- var datastore = require("sugar-web/datastore");
- var webL10n = require("webL10n");
-
-
+define(["sugar-web/activity/activity","sugar-web/presence","activity/capture-helper","sugar-web/datastore","webL10n"], function (activity,presence,captureHelper,datastore,webL10n) {
require(['domReady!'], function (doc) {
diff --git a/activities/SharedNotes.activity/js/activity.js b/activities/SharedNotes.activity/js/activity.js
index 7093934fb..a397b3baa 100644
--- a/activities/SharedNotes.activity/js/activity.js
+++ b/activities/SharedNotes.activity/js/activity.js
@@ -1,11 +1,4 @@
-define(function (require) {
- var l10n = require("webL10n");
- var activity = require("sugar-web/activity/activity");
- var datastore = require("sugar-web/datastore");
- var notepalette = require("notepalette");
- var zoompalette = require("zoompalette");
- var presencepalette = require("sugar-web/graphics/presencepalette");
- var humane = require("humane");
+define(["sugar-web/activity/activity","webL10n","sugar-web/datastore","notepalette","zoompalette","sugar-web/graphics/presencepalette","humane"], function (activity,l10n,datastore,notepalette,zoompalette,presencepalette,humane) {
var defaultColor = '#FFF29F';
var isShared = false;
var isHost = false;
@@ -120,7 +113,7 @@ define(function (require) {
pngButton.title = l10n.get("pngButtonTitle");
networkButton.title = l10n.get("networkButtonTitle");
}, false);
-
+
// --- Node and edge handling functions
var defaultFontFamily = "Arial";
var defaultFontSize = 16;
@@ -490,9 +483,9 @@ define(function (require) {
// Handle messages received
network.onDataReceived(onNetworkDataReceived);
- });
+ });
}
-
+
var sendMessage = function(content) {
try {
network.sendMessage(network.getSharedInfo().id, {
@@ -501,7 +494,7 @@ define(function (require) {
});
} catch (e) {}
}
-
+
var onNetworkDataReceived = function(msg) {
// Ignore messages coming from ourselves
if (network.getUserInfo().networkId === msg.user.networkId) {
@@ -512,13 +505,13 @@ define(function (require) {
// Receive initial board from the host
initGraph(msg.content.data);
break;
-
+
case 'updateBoard':
// Board change received
doAction(msg.content.data.redo);
pushState(msg.content.data, true);
break
-
+
case 'undoBoard':
// Undo board
undoState(true);
@@ -527,7 +520,7 @@ define(function (require) {
case 'redoBoard':
// Redo board
redoState(true);
- break;
+ break;
}
}
var onNetworkUserChanged = function(msg) {
diff --git a/activities/Speak.activity/js/SpeakActivity.js b/activities/Speak.activity/js/SpeakActivity.js
index a7dec82f3..65d8e7fed 100644
--- a/activities/Speak.activity/js/SpeakActivity.js
+++ b/activities/Speak.activity/js/SpeakActivity.js
@@ -1,8 +1,4 @@
-define(function (require) {
-
- var palette = require("sugar-web/graphics/palette");
- var env = require("sugar-web/env");
- var l10n = require("webL10n");
+define(["sugar-web/graphics/palette","sugar-web/env","webL10n"], function (palette,env,l10n) {
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext('2d');
@@ -89,7 +85,7 @@ define(function (require) {
var loadedSettings = JSON.parse(values.sugar_settings);
chrome.storage.local.get('sugar_settings', function(values) {
callback(loadedSettings);
- });
+ });
} else {
var loadedSettings = JSON.parse(localStorage.sugar_settings);
callback(loadedSettings);
@@ -122,7 +118,7 @@ define(function (require) {
}
for(i=0;i