From e51c4aa847939079f79eb40f08c3b81cac32ac74 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Sat, 21 Jan 2012 11:30:16 +0000 Subject: [PATCH] call gc before focus/blur to remove elements from focus stack that are no longer around --- source/Ox.UI/js/Core/Ox.Focus.js | 4 +++- source/Ox.UI/js/Core/Ox.GarbageCollection.js | 9 ++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/source/Ox.UI/js/Core/Ox.Focus.js b/source/Ox.UI/js/Core/Ox.Focus.js index f23b7a9a..fde85e6c 100644 --- a/source/Ox.UI/js/Core/Ox.Focus.js +++ b/source/Ox.UI/js/Core/Ox.Focus.js @@ -19,6 +19,7 @@ Ox.Focus = (function() { (id) -> blur element by id @*/ blur: function(id) { + Ox.GarbageCollection(); var index = stack.indexOf(id); if (index > -1 && index == stack.length - 1) { stack.length == 1 @@ -40,6 +41,7 @@ Ox.Focus = (function() { (id) -> focus element by id @*/ focus: function(id) { + Ox.GarbageCollection(); var index = stack.indexOf(id); if (index == -1 || index < stack.length - 1) { index > -1 && stack.splice(index, 1); @@ -47,7 +49,7 @@ Ox.Focus = (function() { if (stack.length > 1) { Ox.UI.elements[stack[stack.length - 2]] .removeClass('OxFocus') - .triggerEvent('losefocus') + .triggerEvent('losefocus'); } Ox.UI.elements[id] .addClass('OxFocus') diff --git a/source/Ox.UI/js/Core/Ox.GarbageCollection.js b/source/Ox.UI/js/Core/Ox.GarbageCollection.js index a17f57a6..a6de9772 100644 --- a/source/Ox.UI/js/Core/Ox.GarbageCollection.js +++ b/source/Ox.UI/js/Core/Ox.GarbageCollection.js @@ -3,10 +3,11 @@ Ox.GarbageCollection = (function() { var that = function() { - collect(); - }; + collect(); + }, + timeout; - setInterval(collect, 60000); + collect(); function collect() { var len = Ox.len(Ox.UI.elements); @@ -19,6 +20,8 @@ Ox.GarbageCollection = (function() { delete Ox.UI.elements[id]; } }); + timeout && clearTimeout(timeout); + timeout = setTimeout(collect, 60000); Ox.Log('GC', len, '-->', Ox.len(Ox.UI.elements)); }