Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…garizer into pr/1381
  • Loading branch information
Lionel Laské committed Oct 17, 2023
2 parents ec7231a + 1a14558 commit 6b9307b
Show file tree
Hide file tree
Showing 14 changed files with 407 additions and 269 deletions.
2 changes: 1 addition & 1 deletion activities/MindMath.activity/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<link rel="stylesheet" href="css/introjs.css">
<link rel="stylesheet" href="css/libnotify.css">
<script>if (typeof module === 'object') { window.module = module; module = undefined; }</script>
<script src="https://unpkg.com/vue@3"></script>
<script src="lib/vue.global.prod.js"></script>
<script src="lib/intro.js"></script>
<script src="lib/require.js"></script>
<script type="text/javascript" src="../../cordova.js"></script>
Expand Down
2 changes: 0 additions & 2 deletions activities/MindMath.activity/js/activity.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,6 @@ const app = Vue.createApp({
if (vm.slots[vm.qNo].length != 0) {
currentRes = vm.slots[vm.qNo][vm.slots[vm.qNo].length - 1].res;
if (vm.compulsoryOpsRem.length === 0 && currentRes === vm.questions[vm.qNo].targetNum) {
//notifying user
vm.sugarPopup.log("You Got the Target Number")
return true;
} else {
return false;
Expand Down
37 changes: 20 additions & 17 deletions activities/MindMath.activity/js/components/SugarActivity.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
const SugarActivity= {
name: 'SugarActivity',
const SugarActivity = {
name: "SugarActivity",
render() {},
data: function() {
data: function () {
return {
activity: null,
environment: null
}
environment: null,
};
},
mounted: function() {
created: function () {
var vm = this;
requirejs(["sugar-web/activity/activity", "sugar-web/env"], function (activity, env) {
vm.activity = activity;
env.getEnvironment(function (err, environment) {
vm.environment = environment;
activity.setup();
vm.$emit('initialized');
});
});
requirejs(
["sugar-web/activity/activity", "sugar-web/env"],
function (activity, env) {
vm.activity = activity;
env.getEnvironment(function (err, environment) {
vm.environment = environment;
activity.setup();
vm.$emit("initialized");
});
},
);
},
methods: {
getActivity: function () {
Expand All @@ -25,6 +28,6 @@ const SugarActivity= {

getEnvironment: function () {
return this.environment;
}
}
}
},
},
};
113 changes: 65 additions & 48 deletions activities/MindMath.activity/js/components/SugarDevice.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,42 @@
const SugarDevice= {
const SugarDevice = {
/*html*/
template: `<div style="display: none">{{ watchId }}</div>`,
data: function () {
return {
readyToWatch: false,
frequency: null
}
frequency: null,
};
},
created: function () {
var cordovaScript = document.createElement('script');
cordovaScript.setAttribute('type', 'text/javascript');
cordovaScript.setAttribute('src', '../../cordova.js');
var cordovaScript = document.createElement("script");
cordovaScript.setAttribute("type", "text/javascript");
cordovaScript.setAttribute("src", "../../cordova.js");
document.head.appendChild(cordovaScript);
},
mounted: function () {
var vm = this;
//Accelerometer
if (this.isMobile()) {
document.addEventListener('deviceready', function () {
vm.readyToWatch = true;
}, false);
document.addEventListener(
"deviceready",
function () {
vm.readyToWatch = true;
},
false,
);
}

},
computed: {
watchId: function () {
if (this.readyToWatch && this.frequency) {
return navigator.accelerometer.watchAcceleration(this.accelerationCallback, null, { frequency: this.frequency });
return navigator.accelerometer.watchAcceleration(
this.accelerationCallback,
null,
{ frequency: this.frequency },
);
}
return null;
}
},
},
methods: {
isMobile() {
Expand All @@ -47,8 +54,8 @@ const SugarDevice= {
return false;
},
isApp() {
return document.location.protocol.substr(0,4) != "http";
},
return document.location.protocol.substr(0, 4) != "http";
},
isWebApp() {
if (!this.isMobile() && !this.isElectron() && !this.isApp()) {
return true;
Expand All @@ -58,33 +65,39 @@ const SugarDevice= {
getOS() {
var userAgent = navigator.userAgent;
var clientStrings = [
{ s: 'Windows 10', r: /(Windows 10.0|Windows NT 10.0)/ },
{ s: 'Windows 8.1', r: /(Windows 8.1|Windows NT 6.3)/ },
{ s: 'Windows 8', r: /(Windows 8|Windows NT 6.2)/ },
{ s: 'Windows 7', r: /(Windows 7|Windows NT 6.1)/ },
{ s: 'Windows Vista', r: /Windows NT 6.0/ },
{ s: 'Windows Server 2003', r: /Windows NT 5.2/ },
{ s: 'Windows XP', r: /(Windows NT 5.1|Windows XP)/ },
{ s: 'Windows 2000', r: /(Windows NT 5.0|Windows 2000)/ },
{ s: 'Windows ME', r: /(Win 9x 4.90|Windows ME)/ },
{ s: 'Windows 98', r: /(Windows 98|Win98)/ },
{ s: 'Windows 95', r: /(Windows 95|Win95|Windows_95)/ },
{ s: 'Windows NT 4.0', r: /(Windows NT 4.0|WinNT4.0|WinNT|Windows NT)/ },
{ s: 'Windows CE', r: /Windows CE/ },
{ s: 'Windows 3.11', r: /Win16/ },
{ s: 'Android', r: /Android/ },
{ s: 'Open BSD', r: /OpenBSD/ },
{ s: 'Sun OS', r: /SunOS/ },
{ s: 'Chrome OS', r: /CrOS/ },
{ s: 'Linux', r: /(Linux|X11(?!.*CrOS))/ },
{ s: 'iOS', r: /(iPhone|iPad|iPod)/ },
{ s: 'Mac OS X', r: /Mac OS X/ },
{ s: 'Mac OS', r: /(MacPPC|MacIntel|Mac_PowerPC|Macintosh)/ },
{ s: 'QNX', r: /QNX/ },
{ s: 'UNIX', r: /UNIX/ },
{ s: 'BeOS', r: /BeOS/ },
{ s: 'OS/2', r: /OS\/2/ },
{ s: 'Search Bot', r: /(nuhk|Googlebot|Yammybot|Openbot|Slurp|MSNBot|Ask Jeeves\/Teoma|ia_archiver)/ }
{ s: "Windows 10", r: /(Windows 10.0|Windows NT 10.0)/ },
{ s: "Windows 8.1", r: /(Windows 8.1|Windows NT 6.3)/ },
{ s: "Windows 8", r: /(Windows 8|Windows NT 6.2)/ },
{ s: "Windows 7", r: /(Windows 7|Windows NT 6.1)/ },
{ s: "Windows Vista", r: /Windows NT 6.0/ },
{ s: "Windows Server 2003", r: /Windows NT 5.2/ },
{ s: "Windows XP", r: /(Windows NT 5.1|Windows XP)/ },
{ s: "Windows 2000", r: /(Windows NT 5.0|Windows 2000)/ },
{ s: "Windows ME", r: /(Win 9x 4.90|Windows ME)/ },
{ s: "Windows 98", r: /(Windows 98|Win98)/ },
{ s: "Windows 95", r: /(Windows 95|Win95|Windows_95)/ },
{
s: "Windows NT 4.0",
r: /(Windows NT 4.0|WinNT4.0|WinNT|Windows NT)/,
},
{ s: "Windows CE", r: /Windows CE/ },
{ s: "Windows 3.11", r: /Win16/ },
{ s: "Android", r: /Android/ },
{ s: "Open BSD", r: /OpenBSD/ },
{ s: "Sun OS", r: /SunOS/ },
{ s: "Chrome OS", r: /CrOS/ },
{ s: "Linux", r: /(Linux|X11(?!.*CrOS))/ },
{ s: "iOS", r: /(iPhone|iPad|iPod)/ },
{ s: "Mac OS X", r: /Mac OS X/ },
{ s: "Mac OS", r: /(MacPPC|MacIntel|Mac_PowerPC|Macintosh)/ },
{ s: "QNX", r: /QNX/ },
{ s: "UNIX", r: /UNIX/ },
{ s: "BeOS", r: /BeOS/ },
{ s: "OS/2", r: /OS\/2/ },
{
s: "Search Bot",
r: /(nuhk|Googlebot|Yammybot|Openbot|Slurp|MSNBot|Ask Jeeves\/Teoma|ia_archiver)/,
},
];
for (var cs of clientStrings) {
if (cs.r.test(userAgent)) {
Expand All @@ -97,7 +110,7 @@ const SugarDevice= {
var vm = this;
var accelerometer = new Accelerometer({ frequency: frequency });
if (accelerometer) {
accelerometer.addEventListener('reading', function () {
accelerometer.addEventListener("reading", function () {
vm.accelerationCallback(accelerometer);
});
accelerometer.start();
Expand All @@ -107,7 +120,7 @@ const SugarDevice= {
},

accelerationCallback: function (acceleration) {
this.$emit('acceleration-callback', acceleration);
this.$emit("acceleration-callback", acceleration);
},

getLocation: function () {
Expand All @@ -117,18 +130,22 @@ const SugarDevice= {
} else {
resolve(null, { code: 1 });
}
})
});
},

vibrate: function (value) {
navigator.vibrate = navigator.vibrate || navigator.webkitVibrate || navigator.mozVibrate || navigator.msVibrate;
navigator.vibrate =
navigator.vibrate ||
navigator.webkitVibrate ||
navigator.mozVibrate ||
navigator.msVibrate;

if (navigator.vibrate) {
navigator.vibrate(value);
}
}
},
},
beforeDestroy: function () {
navigator.accelerometer.clearWatch(this.watchId);
}
};
},
};
35 changes: 20 additions & 15 deletions activities/MindMath.activity/js/components/SugarIcon.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const SugarIcon= {
const SugarIcon = {
render() {},
data: function () {
return {
icon: null
}
icon: null,
};
},
mounted() {
created() {
var vm = this;
requirejs(["sugar-web/graphics/icon"], function (icon) {
vm.icon = icon;
Expand All @@ -19,8 +19,14 @@ const SugarIcon= {
generateIconWithColors: function (path, colors) {
return new Promise((resolve, reject) => {
requirejs([`text!${path}`], function (icon) {
icon = icon.replace(/(stroke)_color\s\"#?\w*\"/, `stroke_color "${colors.stroke}"`);
icon = icon.replace(/(fill)_color\s\"#?\w*\"/, `fill_color "${colors.fill}"`);
icon = icon.replace(
/(stroke)_color\s\"#?\w*\"/,
`stroke_color "${colors.stroke}"`,
);
icon = icon.replace(
/(fill)_color\s\"#?\w*\"/,
`fill_color "${colors.fill}"`,
);
resolve("data:image/svg+xml;base64," + btoa(icon));
});
});
Expand All @@ -30,23 +36,22 @@ const SugarIcon= {
let vm = this;
return new Promise((resolve, reject) => {
var path = getBackgroundURL(element);
vm.generateIconWithColors(path, colors)
.then(src => {
element.style.backgroundImage = `url(${src})`;
resolve();
});
vm.generateIconWithColors(path, colors).then((src) => {
element.style.backgroundImage = `url(${src})`;
resolve();
});
});
}
}
},
},
};

let getBackgroundURL = function (el) {
var style = el.currentStyle || window.getComputedStyle(el, '');
var style = el.currentStyle || window.getComputedStyle(el, "");
// Remove prefix 'url(' and suffix ')' before return
var res = style.backgroundImage.slice(4, -1);
var last = res.length - 1;
if (res[0] == '"' && res[last] == '"') {
res = res.slice(1, last);
}
return res;
}
};
Loading

0 comments on commit 6b9307b

Please sign in to comment.