Skip to content

Commit

Permalink
Standardize indentation in sugar-web activity.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Lionel Laské committed Apr 28, 2024
1 parent 924c807 commit 70facc1
Show file tree
Hide file tree
Showing 34 changed files with 99 additions and 1,147 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ define(["sugar-web/activity/shortcut",
"sugar-web/bus",
"sugar-web/env",
"sugar-web/datastore",
"sugar-web/presence",
"sugar-web/presence",
"sugar-web/graphics/icon",
"sugar-web/graphics/activitypalette"],
function (shortcut, bus, env, datastore, presence, icon, activitypalette) {

"sugar-web/graphics/activitypalette"], function (
shortcut, bus, env, datastore, presence, icon, activitypalette) {

'use strict';

Expand All @@ -22,8 +21,6 @@ define(["sugar-web/activity/shortcut",
activity.setup = function () {
bus.listen();



function sendPauseEvent() {
var pauseEvent = document.createEvent("CustomEvent");
pauseEvent.initCustomEvent('activityPause', false, false, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ define(["sugar-web/activity/shortcut",
activity.setup = function () {
bus.listen();


function sendPauseEvent() {
var pauseEvent = document.createEvent("CustomEvent");
pauseEvent.initCustomEvent('activityPause', false, false, {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
define([
"sugar-web/activity/shortcut",
define(["sugar-web/activity/shortcut",
"sugar-web/bus",
"sugar-web/env",
"sugar-web/datastore",
Expand All @@ -22,7 +21,6 @@ define([
activity.setup = function () {
bus.listen();


function sendPauseEvent() {
var pauseEvent = document.createEvent("CustomEvent");
pauseEvent.initCustomEvent('activityPause', false, false, {
Expand Down
5 changes: 2 additions & 3 deletions activities/Chat.activity/lib/sugar-web/activity/activity.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ define(["sugar-web/activity/shortcut",
"sugar-web/datastore",
"sugar-web/presence",
"sugar-web/graphics/icon",
"sugar-web/graphics/activitypalette"], function (shortcut, bus, env, datastore, presence, icon, activitypalette) {
"sugar-web/graphics/activitypalette"], function (
shortcut, bus, env, datastore, presence, icon, activitypalette) {

'use strict';

Expand All @@ -20,8 +21,6 @@ define(["sugar-web/activity/shortcut",
activity.setup = function () {
bus.listen();



function sendPauseEvent() {
var pauseEvent = document.createEvent("CustomEvent");
pauseEvent.initCustomEvent('activityPause', false, false, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ define(["sugar-web/activity/shortcut",
"sugar-web/presence",
"sugar-web/graphics/icon",
"sugar-web/graphics/activitypalette"], function (
shortcut, bus, env, datastore, presence, icon, activitypalette) {
shortcut, bus, env, datastore, presence, icon, activitypalette) {

'use strict';

Expand Down
4 changes: 2 additions & 2 deletions activities/Clock.activity/lib/sugar-web/activity/activity.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ define(["sugar-web/activity/shortcut",
"sugar-web/datastore",
"sugar-web/presence",
"sugar-web/graphics/icon",
"sugar-web/graphics/activitypalette"], function (shortcut, bus, env, datastore, presence, icon, activitypalette) {
"sugar-web/graphics/activitypalette"], function (
shortcut, bus, env, datastore, presence, icon, activitypalette) {

'use strict';

Expand All @@ -20,7 +21,6 @@ define(["sugar-web/activity/shortcut",
activity.setup = function () {
bus.listen();


function sendPauseEvent() {
var pauseEvent = document.createEvent("CustomEvent");
pauseEvent.initCustomEvent('activityPause', false, false, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ define(["sugar-web/activity/shortcut",
"sugar-web/datastore",
"sugar-web/presence",
"sugar-web/graphics/icon",
"sugar-web/graphics/activitypalette"], function (shortcut, bus, env, datastore, presence, icon, activitypalette) {
"sugar-web/graphics/activitypalette"], function (
shortcut, bus, env, datastore, presence, icon, activitypalette) {

'use strict';

Expand All @@ -20,7 +21,6 @@ define(["sugar-web/activity/shortcut",
activity.setup = function () {
bus.listen();


function sendPauseEvent() {
var pauseEvent = document.createEvent("CustomEvent");
pauseEvent.initCustomEvent('activityPause', false, false, {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
define([
"sugar-web/activity/shortcut",
define(["sugar-web/activity/shortcut",
"sugar-web/bus",
"sugar-web/env",
"sugar-web/datastore",
Expand All @@ -22,7 +21,6 @@ define([
activity.setup = function () {
bus.listen();


function sendPauseEvent() {
var pauseEvent = document.createEvent("CustomEvent");
pauseEvent.initCustomEvent('activityPause', false, false, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ define(["sugar-web/activity/shortcut",
"sugar-web/datastore",
"sugar-web/presence",
"sugar-web/graphics/icon",
"sugar-web/graphics/activitypalette"], function (shortcut, bus, env, datastore, presence, icon, activitypalette) {
"sugar-web/graphics/activitypalette"], function (
shortcut, bus, env, datastore, presence, icon, activitypalette) {

'use strict';

Expand All @@ -20,7 +21,6 @@ define(["sugar-web/activity/shortcut",
activity.setup = function () {
bus.listen();


function sendPauseEvent() {
var pauseEvent = document.createEvent("CustomEvent");
pauseEvent.initCustomEvent('activityPause', false, false, {
Expand Down
120 changes: 59 additions & 61 deletions activities/FoodChain.activity/lib/sugar-web/activity/activity.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
define([
"sugar-web/activity/shortcut",
"sugar-web/bus",
"sugar-web/env",
"sugar-web/datastore",
"sugar-web/presence",
"sugar-web/graphics/icon",
"sugar-web/graphics/activitypalette"], function (
shortcut, bus, env, datastore, presence, icon, activitypalette) {
define(["sugar-web/activity/shortcut",
"sugar-web/bus",
"sugar-web/env",
"sugar-web/datastore",
"sugar-web/presence",
"sugar-web/graphics/icon",
"sugar-web/graphics/activitypalette"], function (
shortcut, bus, env, datastore, presence, icon, activitypalette) {

'use strict';

var datastoreObject = null;

var presenceCallback = null;
var presenceResponse = null;
var presenceCallback = null;
var presenceResponse = null;

var activity = {};

Expand All @@ -22,12 +21,11 @@ define([
activity.setup = function () {
bus.listen();


function sendPauseEvent() {
var pauseEvent = document.createEvent("CustomEvent");
pauseEvent.initCustomEvent('activityPause', false, false, {
'cancelable': true
});
var pauseEvent = document.createEvent("CustomEvent");
pauseEvent.initCustomEvent('activityPause', false, false, {
'cancelable': true
});
window.dispatchEvent(pauseEvent);
}
bus.onNotification("activity.pause", sendPauseEvent);
Expand All @@ -37,14 +35,14 @@ define([
// call activity.close() after storing.

function sendStopEvent() {
var stopEvent = document.createEvent("CustomEvent");
stopEvent.initCustomEvent('activityStop', false, false, {
'cancelable': true
});
var stopEvent = document.createEvent("CustomEvent");
stopEvent.initCustomEvent('activityStop', false, false, {
'cancelable': true
});
var result = window.dispatchEvent(stopEvent);
if (result) {
datastoreObject.save(function () {
datastore.waitPendingSave(function () {
datastoreObject.save(function() {
datastore.waitPendingSave(function() {
activity.close();
});
});
Expand All @@ -65,21 +63,21 @@ define([
var invokerElem =
document.querySelector("#activity-palette .palette-invoker");
icon.colorize(invokerElem, colors);
var buddyIcon = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>\
var buddyIcon='<?xml version="1.0" encoding="UTF-8" standalone="no"?>\
<svg xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://creativecommons.org/ns#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" width="16" height="16" version="1.0" >\
<g transform="translate(37.943468,-309.4636)">\
<g transform="matrix(0.05011994,0,0,0.05012004,-41.76673,299.66011)" style="fill:&fill_color;;fill-opacity:1;stroke:&stroke_color;;stroke-opacity:1">\
<circle transform="matrix(0.969697,0,0,0.969697,-90.879133,125.06999)" style="fill:&fill_color;;fill-opacity:1;stroke:&stroke_color;;stroke-width:20.62502098;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" cx="331.38321" cy="134.2677" r="51.220825" />\
<path d="m 290.55846,302.47333 -58.81513,59.20058 -59.39461,-59.40024 c -25.19828,-24.48771 -62.7038,13.33148 -38.1941,37.98719 l 60.04451,58.9817 -59.73639,59.42563 c -24.83976,24.97559 12.91592,63.26505 37.66786,37.75282 l 59.95799,-59.28294 58.75912,59.21065 c 24.50656,25.09065 62.43116,-13.00322 37.87956,-37.85772 l -59.24184,-59.02842 58.87574,-59.14782 c 25.1689,-25.18348 -13.0489,-62.75154 -37.80271,-37.84143 z" style="fill:&fill_color;;fill-opacity:1;stroke:&stroke_color;;stroke-width:20.00002098;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" />\
</g></g></svg>';
var newicon = buddyIcon.replace(new RegExp("&fill_color;", "g"), colors.fill).replace(new RegExp("&stroke_color;", "g"), colors.stroke);
var newicon = buddyIcon.replace(new RegExp("&fill_color;","g"),colors.fill).replace(new RegExp("&stroke_color;","g"),colors.stroke);
var svg_xml = (new XMLSerializer()).serializeToString((new DOMParser()).parseFromString(newicon, "text/xml"));
var canvas = document.createElement('canvas');
canvas.width = canvas.height = 16;
var ctx = canvas.getContext('2d');
var img = new Image();
img.src = "data:image/svg+xml;base64," + btoa(svg_xml);
img.onload = function () {
img.onload = function() {
ctx.drawImage(img, 0, 0);
var link = document.querySelector("link[rel*='icon']") || document.createElement('link');
link.type = 'image/x-icon';
Expand All @@ -99,64 +97,64 @@ define([

env.getEnvironment(function (error, environment) {
user = environment.user;
var l10n = { "en": "{{name}} Activity", "fr": "Activité {{name}}", "es": "Actividad {{name}}", "pt": "{{name}} Atividade", "de": "Aktivität {{name}}" };
var l10n ={"en":"{{name}} Activity","fr":"Activité {{name}}","es":"Actividad {{name}}","pt":"{{name}} Atividade","de":"Aktivität {{name}}"};
var activityName = "";
for (var i = 0; i < environment.user.activities.length; i++) {
for (var i = 0 ; i < environment.user.activities.length ; i++) {
if (environment.user.activities[i].id == environment.bundleId) {
activityName = environment.user.activities[i].name;
break;
}
}
document.title = (l10n[environment.user.language] || l10n["en"]).replace("{{name}}", activityName) + " - Sugarizer";
document.title = (l10n[environment.user.language]||l10n["en"]).replace("{{name}}", activityName)+" - Sugarizer";
if (!environment.objectId) {
datastoreObject.setMetadata({
"title": (l10n[environment.user.language] || l10n["en"]).replace("{{name}}", environment.activityName),
"title": (l10n[environment.user.language]||l10n["en"]).replace("{{name}}", environment.activityName),
"title_set_by_user": "0",
"activity": environment.bundleId,
"activity_id": environment.activityId
});
}
if (env.isSugarizer()) {
presence.joinNetwork(function (error, presence) {
if (environment.sharedId) {
presence.joinSharedActivity(environment.sharedId, function () {
var group_color = presence.getSharedInfo().colorvalue;
icon.colorize(activityButton, group_color);
datastoreObject.setMetadata({ "buddy_color": group_color });
datastoreObject.save(function () { });
});
}
if (presenceCallback) {
presenceCallback(error, presence);
} else {
presenceResponse = { error: error, presence: presence };
}
});
}
if (env.isSugarizer()) {
presence.joinNetwork(function(error, presence) {
if (environment.sharedId) {
presence.joinSharedActivity(environment.sharedId, function() {
var group_color = presence.getSharedInfo().colorvalue;
icon.colorize(activityButton, group_color);
datastoreObject.setMetadata({"buddy_color":group_color});
datastoreObject.save(function() {});
});
}
if (presenceCallback) {
presenceCallback(error, presence);
} else {
presenceResponse = {error: error, presence: presence};
}
});
}
datastoreObject.save(function () {
datastoreObject.getMetadata(function (error, metadata) {
activityPalette.setTitleDescription(metadata);
});
});
if (environment.standAlone) {
document.getElementById("stop-button").style.visibility = "hidden";
};
if (environment.standAlone) {
document.getElementById("stop-button").style.visibility = "hidden";
};
});
};

activity.getDatastoreObject = function () {
return datastoreObject;
};

activity.getPresenceObject = function (connectionCallback) {
if (presenceResponse == null) {
presenceCallback = connectionCallback;
} else {
connectionCallback(presenceResponse.error, presenceResponse.presence);
presenceResponse = null;
}
return presence;
};
activity.getPresenceObject = function(connectionCallback) {
if (presenceResponse == null) {
presenceCallback = connectionCallback;
} else {
connectionCallback(presenceResponse.error, presenceResponse.presence);
presenceResponse = null;
}
return presence;
};

activity.getXOColor = function (callback) {
function onResponseReceived(error, result) {
Expand Down Expand Up @@ -185,7 +183,7 @@ define([
}
}

activity.traceStats("activity", "stop", window.top.sugar.environment.objectId, null);
activity.traceStats("activity","stop",window.top.sugar.environment.objectId,null);
bus.sendMessage("activity.close", [], onResponseReceived);
};

Expand All @@ -201,14 +199,14 @@ define([
stat.user_id = user.networkId;
stat.user_agent = navigator.userAgent;
stat.timestamp = new Date().getTime();
stat.client_type = (document.location.protocol.substr(0, 4) == "http" ? "Web App" : "App");
stat.client_type = (document.location.protocol.substr(0,4) == "http" ? "Web App" : "App");
stat.event_source = window.top.sugar.environment.bundleId;
stat.event_object = object;
stat.event_action = action;
stat.event_label = label;
stat.event_value = value;
statslist.push(stat);
datastore.localStorage.setValue('sugar_stats', statslist);
datastore.localStorage.setValue('sugar_stats', statslist);
};

activity.showObjectChooser = function (callback) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ define(["sugar-web/activity/shortcut",
"sugar-web/datastore",
"sugar-web/presence",
"sugar-web/graphics/icon",
"sugar-web/graphics/activitypalette"], function (shortcut, bus, env, datastore, presence, icon, activitypalette) {
"sugar-web/graphics/activitypalette"], function (
shortcut, bus, env, datastore, presence, icon, activitypalette) {

'use strict';

Expand All @@ -20,7 +21,6 @@ define(["sugar-web/activity/shortcut",
activity.setup = function () {
bus.listen();


function sendPauseEvent() {
var pauseEvent = document.createEvent("CustomEvent");
pauseEvent.initCustomEvent('activityPause', false, false, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ define(["sugar-web/activity/shortcut",
activity.setup = function () {
bus.listen();


function sendPauseEvent() {
var pauseEvent = document.createEvent("CustomEvent");
pauseEvent.initCustomEvent('activityPause', false, false, {
Expand Down
Loading

0 comments on commit 70facc1

Please sign in to comment.