commit ce2e0d91e7ad83cd25dc9f633cdb8c6ab47af00b
parent f0417a2f05eac2214fde5934072315e9fca500ce
Author: Felicitus <felicitus@felicitus.org>
Date: Thu, 22 Nov 2012 06:14:50 +0100
Optimized the system notice button's fading so that it doesn't eat CPU cycles when not visible. Partial fix for #262 and #241
Diffstat:
2 files changed, 64 insertions(+), 27 deletions(-)
diff --git a/src/frontend/js/Components/Widgets/FadingButton.js b/src/frontend/js/Components/Widgets/FadingButton.js
@@ -1,24 +1,44 @@
Ext.define('PartKeepr.FadingButton', {
extend: 'Ext.Button',
+
+ /**
+ * Holds the fadeButtonTask
+ * @var object
+ */
+ fadeButtonTask: null,
+
+ /**
+ * Holds the selector for the button's icon
+ * @var string
+ */
+ selector: ".x-btn-icon",
+
+ /**
+ * Initializes the component and adds the fadeButtonTask.
+ */
initComponent: function () {
this.callParent();
-
+
+ this.fadeButtonTask = {
+ run: this.fadeButton,
+ interval: 10000, // No constant fading, because fading eats quite some CPU
+ scope: this
+ };
+
},
- startFading: function () {
- var iconEl = this.getEl().down(".x-btn-inner");
-
+ /**
+ * Adds an animation to the button's icon. This is only done once and needs to be refreshed (done automatically
+ * by startFading).
+ *
+ * @param none
+ * @return nothing
+ */
+ fadeButton: function () {
+ var iconEl = this.getEl().down(this.selector);
+
iconEl.animate({
- duration: 1000,
- iterations: 1, // Should be enough for any session,
- listeners: {
- afteranimate: function () {
- if (this.fadeRunning) {
- // Not sure why defer is needed, but without it, it won't work.
- Ext.defer(this.startFading, 100, this);
- }
- },
- scope: this
- },
+ duration: 1000, // One second
+ iterations: 1,
keyframes: {
50: {
opacity: 0
@@ -27,18 +47,21 @@ Ext.define('PartKeepr.FadingButton', {
opacity: 1
}
}});
- this.fadeRunning = true;
},
+ /**
+ * Starts button fading by adding the task from the task manager
+ * @param none
+ * @return nothing
+ */
+ startFading: function () {
+ Ext.TaskManager.start(this.fadeButtonTask);
+ },
+ /**
+ * Stops button fading by removing the task from the task manager
+ * @param none
+ * @return nothing
+ */
stopFading: function () {
- this.fadeRunning = false;
- },
- isFading: function () {
- var iconEl = this.getEl().down(".x-btn-inner");
-
- if (iconEl.getActiveAnimation() === false) {
- return false;
- }
-
- return true;
+ Ext.TaskManager.stop(this.fadeButtonTask);
}
});
\ No newline at end of file
diff --git a/src/frontend/js/Components/Widgets/SystemNoticeButton.js b/src/frontend/js/Components/Widgets/SystemNoticeButton.js
@@ -2,12 +2,26 @@ Ext.define('PartKeepr.SystemNoticeButton', {
extend: 'PartKeepr.FadingButton',
icon: 'resources/fugue-icons/icons/service-bell.png',
tooltip: i18n("Unacknowledged System Notices"),
+
+ /**
+ * Initializes the component. Adds the start/stop and click fading handlers.
+ *
+ * @param none
+ * @return nothing
+ */
initComponent: function () {
this.callParent();
- this.on("render", this.startFading, this);
+ this.on("show", this.startFading, this);
+ this.on("hide", this.stopFading, this);
this.on("click", this.onClick, this);
},
+ /**
+ * Open the system notices when clicked.
+ *
+ * @param none
+ * @return nothing
+ */
onClick: function () {
PartKeepr.getApplication().menuBar.showSystemNotices();
}