Skip to content
This repository has been archived by the owner on Jan 4, 2021. It is now read-only.

Give fedmenu a configurable selector context. #12

Merged
merged 1 commit into from May 20, 2015

Conversation

ralphbean
Copy link
Contributor

This should allow docs.fp.o to call fedmenu from the table-of-contents
iframe with parent.document to do all the fedmenu work on the
parent.

This should allow docs.fp.o to call fedmenu from the table-of-contents
iframe with ``parent.document`` to do all the fedmenu work on the
parent.
@ralphbean
Copy link
Contributor Author

Here's the patch to docs.fp.o. It is @pypingou's original patch with only one new line to add the context argument.

From 23e9e1f56a48322fa229257305b092385d035fdd Mon Sep 17 00:00:00 2001
From: Pierre-Yves Chibon <pingou@pingoured.fr>
Date: Tue, 19 May 2015 15:45:13 -0400
Subject: [PATCH] Add fedmenu to docs.fp.o.

This is done by modifying ``toc.js`` to pull in the fedmenu resources
which in turn write the fedmenu elements to the DOM.  We run into
trouble though, because toc.js executes in the context of an iframe
child and fedmenu gets confused -- where should it write!?

This required a patch to fedmenu that allows it to accept a `context`
argument:  https://github.com/fedora-infra/fedmenu/pull/12

In this patch, we pass ``parent.document`` as the context, which gets
fedmenu to write to the correct location.

Signed-off-by: Ralph Bean <rbean@redhat.com>
---
 public_html/toc.js | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 57 insertions(+)

diff --git a/public_html/toc.js b/public_html/toc.js
index 501b27a..a57d564 100644
--- a/public_html/toc.js
+++ b/public_html/toc.js
@@ -337,3 +337,60 @@ function showMenu() {
    setCookie(name_menu, 'open', expDate, '/', false, false);
 }

+/* fedmenu integration */
+
+function install_fedmenu() {
+    var jquery_src = document.createElement('script');
+    jquery_src.type = 'text/javascript';
+    jquery_src.src = 'https://apps.fedoraproject.org/fedmenu/js/jquery-1.11.2.min.js';
+    var done = false;
+    jquery_src.onload = jquery_src.onreadystatechange = function() {
+        if (!done && (
+                !this.readyState ||
+                this.readyState == 'loaded' ||
+                this.readyState == 'complete'
+                )) {
+            done = true;
+            set_fedmenu();  // Do the callback
+            jquery_src.onload = jquery_src.onreadystatechange = null;
+            document.body.removeChild(jquery_src);
+        };
+    };
+    document.body.appendChild(jquery_src);
+}
+
+function set_fedmenu() {
+    var fedmenu_src = document.createElement('script');
+    fedmenu_src.type = 'text/javascript';
+    fedmenu_src.src = 'https://apps.fedoraproject.org/fedmenu/js/fedmenu.js';
+    var done = false;
+    fedmenu_src.onload = fedmenu_src.onreadystatechange = function() {
+        if (!done && (
+                !this.readyState ||
+                this.readyState == 'loaded' ||
+                this.readyState == 'complete'
+                )) {
+            done = true;
+            run_fedmenu();  // Do the callback
+            fedmenu_src.onload = fedmenu_src.onreadystatechange = null;
+            document.body.removeChild(fedmenu_src);
+        };
+    };
+    document.body.appendChild(fedmenu_src);
+}
+
+function run_fedmenu() {
+    var fedmenu_spt = document.createElement('script');
+    fedmenu_spt.type = 'text/javascript';
+    fedmenu_spt.text = 'fedmenu({'
+        + '"url": "https://apps.fedoraproject.org/js/data.js", '
+        + '"mimetype": "application/javascript", '
+        + '"position": "bottom-right", '
+        + '"context": parent.document'
+        + '});';
+    document.body.appendChild(fedmenu_spt);
+}
+
+window.addEventListener("load", function(){
+    install_fedmenu();
+});
-- 
2.4.1

@pypingou
Copy link
Member

Cooo, 👍 :)

@ralphbean
Copy link
Contributor Author

Thanks @pypingou!

ralphbean added a commit that referenced this pull request May 20, 2015
Give fedmenu a configurable selector context.
@ralphbean ralphbean merged commit 8e3dc2f into develop May 20, 2015
@ralphbean ralphbean deleted the feature/flexible-context branch May 20, 2015 15:13
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants