From 91b123a40e1d5eb54e771461e271f94051618c62 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sun, 23 Nov 2014 13:42:03 +0000 Subject: Frames; tidy up. --- background_scripts/main.coffee | 25 +++++++++++-------------- lib/utils.coffee | 12 ++++++------ 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index aac63213..cda4f118 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -598,27 +598,24 @@ openOptionsPageInNewTab = -> registerFrame = (request, sender) -> frames = frameIdsForTab[sender.tab.id] ?= [] - return if request.is_frameset # Don't store frameset containers; focusing them is no use. - if request.is_top - frames.unshift request.frameId - else - frames.push request.frameId + unless request.is_frameset # Don't store frameset containers; focusing them is no use. + if request.is_top then frames.unshift request.frameId else frames.push request.frameId unregisterFrame = (request, sender) -> - frames = frameIdsForTab[sender.tab.id] - return unless frames? + tabId = sender.tab.id + return unless frameIdsForTab[tabId]? if request.is_top # The whole tab is closing, so we can drop the frames list. updateOpenTabs sender.tab - else if not request.if_frameset - index = frames.indexOf request.frameId - return if index == -1 - frames.splice index, 1 - nextFrame 0 if index == 0 + else + removingCurrent = frameIdsForTab[tabId].length and frameIdsForTab[tabId][0] == request.frameId + frameIdsForTab[tabId] = (id for id in frameIdsForTab[tabId] when id != request.frameId) + BackGroundCommands.nextFrame 0 if removingCurrent handleFrameFocused = (request, sender) -> - index = frameIdsForTab[sender.tab.id].indexOf request.frameId - frameIdsForTab[sender.tab.id] = frames.rotate index + tabId = sender.tab.id + frameIdsForTab[tabId] = + [request.frameId, (id for id in frameIdsForTab[tabId] when id != request.frameId)...] # Port handler mapping portHandlers = diff --git a/lib/utils.coffee b/lib/utils.coffee index 428112c8..c8a02328 100644 --- a/lib/utils.coffee +++ b/lib/utils.coffee @@ -145,15 +145,15 @@ Function::curry = -> Array.copy = (array) -> Array.prototype.slice.call(array, 0) -String::startsWith = (str) -> @indexOf(str) == 0 - Array::rotate = (count) -> - return this if @length == 0 - count = count % @length - count = count + @length if count < 0 - Array::push.apply(this, @splice(0, count)) + if @length + count = count % @length + count += @length while count < 0 + Array::push.apply(this, @splice(0, count)) this +String::startsWith = (str) -> @indexOf(str) == 0 + globalRoot = window ? global globalRoot.extend = (hash1, hash2) -> for key of hash2 -- cgit v1.2.3