You could download the full source code here
// Class for a Sugar icon
enyo.kind({
name: "Sugar.Icon",
kind: enyo.Control,
published: {
icon: null,
x: -1,
y: -1
},
classes: "web-activity",
components: [
{ name: "icon", classes: "web-activity-icon"}
],
// Constructor
create: function() {
this.inherited(arguments);
this.iconChanged();
this.xChanged();
this.yChanged();
},
// Property changed
xChanged: function() {
if (this.x != -1) {
this.applyStyle("margin-left", this.x+"px");
}
},
yChanged: function() {
if (this.y != -1) {
this.applyStyle("margin-top", this.y+"px");
}
},
iconChanged: function() {
if (this.icon != null)
this.$.icon.applyStyle("background-image", "url(" + this.icon.directory+"/"+this.icon.icon + ")");
else
this.$.icon.applyStyle("background-image", null);
}
});
// Main app class
enyo.kind({
name: "TestApp",
kind: enyo.Control,
components: [
{name: "desktop", showing: true, components: [
{name: "journal", kind: "Sugar.Icon", icon: {directory:"images", icon:"activity-journal.svg"}}
]},
],
// Constructor
create: function() {
this.inherited(arguments);
this.timer = null;
//this.displayIcon(); // Uncomment this line and comment the following one and it works perfectly
this.timer = window.setInterval(enyo.bind(this, "displayIcon"), 1000);
},
// Display icon
displayIcon: function() {
if (this.timer != null) window.clearInterval(this.timer);
console.log("Move icon...");
// Nothing happen here if it come from the timer callback
this.$.journal.setX(200);
this.$.journal.setY(100);
console.log("Done");
}
});
It looks like you're new here. If you want to get involved, click one of these buttons!