summaryrefslogtreecommitdiff
path: root/resources/dynmenu.js
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2016-04-20 16:29:07 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2016-04-20 16:29:07 (GMT)
commit92892f13357188a5b4c81b5f2c35a3a740924d67 (patch)
tree26e5bb275c2171802f3bf477eb2a1aa0f20ec4df /resources/dynmenu.js
First commit.
Diffstat (limited to 'resources/dynmenu.js')
-rw-r--r--resources/dynmenu.js91
1 files changed, 91 insertions, 0 deletions
diff --git a/resources/dynmenu.js b/resources/dynmenu.js
new file mode 100644
index 0000000..a10296b
--- /dev/null
+++ b/resources/dynmenu.js
@@ -0,0 +1,91 @@
+
+var last_popped = null;
+var popped_in_use = false;
+
+var last_timeout = null;
+
+function prepareLastPopped(evt) {
+
+ last_popped.onmouseleave = removeLastPopped;
+
+ popped_in_use = true;
+
+}
+
+function removeLastPopped(evt) {
+
+ if (last_popped != null) {
+
+ last_popped.parentNode.removeChild(last_popped);
+ last_popped = null;
+
+ }
+
+}
+
+function forcePoppedHiding(evt) {
+
+ function cancelPopping() {
+
+ last_timeout = null;
+
+ if (!popped_in_use) {
+
+ removeLastPopped(null);
+
+ }
+
+ }
+
+ last_timeout = setTimeout(cancelPopping, 500);
+
+}
+
+function showMenu(target, inner) {
+
+ function waitForEvent(evt) {
+
+ if (last_timeout != null) {
+
+ clearTimeout(last_timeout);
+ last_timeout = null;
+
+ }
+
+ removeLastPopped(null);
+
+ if (inner == null)
+ return;
+
+ var menubar = document.createElement('div');
+
+ menubar.id = 'myMenu';
+ menubar.className = 'menu_arrow_box'
+ menubar.innerHTML = inner ;
+ document.body.insertBefore(menubar, document.body.childNodes[0]);
+
+ var rect = target.getBoundingClientRect();
+ var menu_rect = menubar.getBoundingClientRect();
+
+ menubar.style.left = (rect.left - (menu_rect.width - rect.width) / 2) + "px";
+ menubar.style.top = (rect.bottom + 20) + "px";
+
+ last_popped = menubar;
+ popped_in_use = false;
+
+ menubar.onmouseenter = prepareLastPopped;
+ target.onmouseleave = forcePoppedHiding;
+
+ }
+
+ return waitForEvent;
+
+}
+
+function addMenuToID(id, inner) {
+
+ var target = document.getElementById(id);
+
+ target.onmouseenter = showMenu(target, inner);
+
+}