Skip to content

Commit

Permalink
Merge branch 'pr/1513' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Lionel Laské committed Mar 10, 2024
2 parents 667e6dc + 9f31dab commit 2b4a943
Show file tree
Hide file tree
Showing 34 changed files with 850 additions and 1,678 deletions.
3 changes: 1 addition & 2 deletions activities/ActivityTemplate/VueJS/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@
<title>My Vue Activity</title>
<meta name="viewport"
content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, viewport-fit=cover" />
<link rel="prefetch" type="application/l10n" href="locale.ini" />
<link rel="stylesheet" media="not screen and (device-width: 1200px) and (device-height: 900px)"
href="lib/sugar-web/graphics/css/sugar-96dpi.css">
<link rel="stylesheet" media="screen and (device-width: 1200px) and (device-height: 900px)"
href="lib/sugar-web/graphics/css/sugar-200dpi.css">
<link rel="stylesheet" href="css/activity.css">
<script src="lib/vue.min.js"></script>
<script src="lib/vue.global.prod.js"></script>
<script src="lib/require.js"></script>
<script type="text/javascript" src="../../cordova.js"></script>
</head>
Expand Down
17 changes: 13 additions & 4 deletions activities/ActivityTemplate/VueJS/js/activity.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,17 @@ requirejs.config({
});

// Vue main app
var app = new Vue({
el: '#app',
data: {},
methods: {}
const app = Vue.createApp({
components: {
"sugar-activity": SugarActivity,
"sugar-toolbar": SugarToolbar,
"sugar-toolitem": SugarToolitem,
},

data: function () {
return {};
},
methods: {},
});

app.mount("#app");
38 changes: 21 additions & 17 deletions activities/ActivityTemplate/VueJS/js/components/SugarActivity.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
Vue.component('sugar-activity', {
name: 'SugarActivity',
data: function() {
const SugarActivity = {
name: "SugarActivity",
render() {},
data: function () {
return {
activity: null,
environment: null
}
environment: null,
};
},
mounted() {
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 @@ -24,6 +28,6 @@ Vue.component('sugar-activity', {

getEnvironment: function () {
return this.environment;
}
}
})
},
},
};
113 changes: 65 additions & 48 deletions activities/ActivityTemplate/VueJS/js/components/SugarDevice.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,42 @@
Vue.component('sugar-device', {
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 @@ Vue.component('sugar-device', {
return false;
},
isApp() {
return document.location.protocol.substr(0,4) != "http";
},
return document.location.protocol.substring(0, 4) != "http";
},
isWebApp() {
if (!this.isMobile() && !this.isElectron() && !this.isApp()) {
return true;
Expand All @@ -58,33 +65,39 @@ Vue.component('sugar-device', {
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 @@ Vue.component('sugar-device', {
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 @@ Vue.component('sugar-device', {
},

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

getLocation: function () {
Expand All @@ -117,18 +130,22 @@ Vue.component('sugar-device', {
} 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);
}
});
},
};
38 changes: 22 additions & 16 deletions activities/ActivityTemplate/VueJS/js/components/SugarIcon.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
Vue.component('sugar-icon', {
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 @@ -18,8 +19,14 @@ Vue.component('sugar-icon', {
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 @@ -29,23 +36,22 @@ Vue.component('sugar-icon', {
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 2b4a943

Please sign in to comment.