-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
56 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,41 @@ | ||
(ns flyer.storage | ||
"includes functions for storing window information" | ||
"includes functions for storing window information. This window | ||
information is stored in the parent window under the | ||
`window-list-key`." | ||
(:require [flyer.utils :as utils])) | ||
|
||
(declare get-window-refs) | ||
|
||
|
||
(def storage (utils/get-main-parent)) | ||
|
||
|
||
(def window-list-key "flyer_WindowReferences") | ||
|
||
|
||
(defn init-window-refs | ||
"Initializes our window references" | ||
[] | ||
(when (nil? (get-window-refs)) | ||
(aset storage window-list-key (set nil)))) | ||
|
||
|
||
(defn get-window-refs | ||
"Returns the window references, or an empty set" | ||
[] | ||
(or | ||
(aget storage window-list-key) | ||
nil)) | ||
|
||
|
||
(defn insert-window-ref! [window] | ||
(init-window-refs) | ||
(aset storage window-list-key | ||
(conj (get-window-refs) window))) | ||
|
||
|
||
(defn remove-window-ref! [window] | ||
(init-window-refs) | ||
(aset storage window-list-key | ||
(disj (get-window-refs) window))) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,31 @@ | ||
(ns flyer.utils) | ||
|
||
|
||
(defn is-frame? | ||
"Determines whether the current window is a frame within a set of | ||
frames currently showing." | ||
frames currently showing." | ||
[window] | ||
(let [parent-window (.-parent window) | ||
current-location (.-location window) | ||
parent-location (.-location parent-window)] | ||
(not= current-location parent-location))) | ||
|
||
|
||
(defn is-external-window? | ||
"Determines whether the current window was opened externally" | ||
[window] | ||
(not (nil? (.-opener window)))) | ||
|
||
|
||
(defn get-main-parent | ||
"Finds the main parent by traversing down till it has been | ||
determined that it is the parent" | ||
determined that it is the parent" | ||
([window] | ||
(cond | ||
(is-external-window? window) (get-main-parent (.-opener window)) | ||
(is-frame? window) (get-main-parent (.-parent window)) | ||
:else window)) | ||
(loop [window window] | ||
(if (is-external-window? window) | ||
(recur (.-opener window)) | ||
|
||
(if (is-frame? window) | ||
(recur (.-parent window)) | ||
window)))) | ||
([] (get-main-parent js/window))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters