[Kimchi-devel] [PATCH] [UI] Window Widget Enhancement - Allow onClose Listener
Hongliang Wang
hlwang at linux.vnet.ibm.com
Mon Mar 10 04:59:04 UTC 2014
Sometimes we want to trigger some action when window is being closed.
For example, we register some listeners in one window, and we want to
unregister them after this window is closed, in this case we can take
advantage of this feature.
Signed-off-by: Hongliang Wang <hlwang at linux.vnet.ibm.com>
---
ui/js/src/kimchi.window.js | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/ui/js/src/kimchi.window.js b/ui/js/src/kimchi.window.js
index b32ab60..c2af63e 100644
--- a/ui/js/src/kimchi.window.js
+++ b/ui/js/src/kimchi.window.js
@@ -17,6 +17,7 @@
*/
kimchi.window = (function() {
var _windows = [];
+ var _listeners = {};
var open = function(settings) {
var settings = jQuery.type(settings) === 'object' ? settings : {
url: settings
@@ -29,6 +30,7 @@ kimchi.window = (function() {
}
_windows.push(windowID);
+ _listeners[windowID] = settings['close'];
var windowNode = $('<div></div>', {
id: windowID,
'class': settings['class'] ? settings['class'] + ' bgmask' : 'bgmask'
@@ -37,9 +39,6 @@ kimchi.window = (function() {
$(windowNode).css(settings['style'] || '');
$(windowNode).appendTo('body').on('click', '.window .close', function() {
- if (settings.close) {
- settings.close();
- }
kimchi.window.close();
});
@@ -52,7 +51,14 @@ kimchi.window = (function() {
};
var close = function() {
- $('#' + _windows.pop()).fadeOut(100, function() {
+ var windowID = _windows.pop();
+ if(_listeners[windowID]) {
+ _listeners[windowID]();
+ _listeners[windowID] = null;
+ }
+ delete _listeners[windowID];
+
+ $('#' + windowID).fadeOut(100, function() {
$(this).remove();
});
};
--
1.8.1.4
More information about the Kimchi-devel
mailing list