aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Blott2014-11-23 13:42:03 +0000
committerStephen Blott2014-11-23 13:42:03 +0000
commit91b123a40e1d5eb54e771461e271f94051618c62 (patch)
tree075629ef6e0ce0f0ed1647d74e48bcc9f1e40df5
parent3863e724241408338c9c69af72117584c1258d34 (diff)
downloadvimium-91b123a40e1d5eb54e771461e271f94051618c62.tar.bz2
Frames; tidy up.
-rw-r--r--background_scripts/main.coffee25
-rw-r--r--lib/utils.coffee12
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