From c6527aa81363fd1a5a277a16cbb28aecc0fb2fb7 Mon Sep 17 00:00:00 2001 From: Alexander Goedde Date: Mon, 14 Apr 2014 18:24:39 +0200 Subject: [PATCH] small fixes --- doc/_static/communitywidget.css | 11 ++-- doc/_static/communitywidget.js | 105 +++++++++++++++++++++++++------- doc/_templates/layout.html | 6 +- doc/index.rst | 4 +- doc/wampprogramming.rst | 1 + 5 files changed, 96 insertions(+), 31 deletions(-) diff --git a/doc/_static/communitywidget.css b/doc/_static/communitywidget.css index 7c5aff61..6546ef33 100644 --- a/doc/_static/communitywidget.css +++ b/doc/_static/communitywidget.css @@ -1,11 +1,12 @@ #communityWidget { position: fixed; top: 81px; - right: 0px; + right: -2px; background-color: #fff; z-index: 1000; - border-radius: 6px 0 0 6px; - box-shadow: 0 0 12px 2px rgba(0, 0, 0, 0.4); + border-radius: 3px 0 0 3px; + border: solid 1px #fff; + box-shadow: 0 0 5px 2px rgba(0, 0, 0, 0.3); } #communityWidget.nonDisplay { @@ -18,9 +19,9 @@ #communityWidget.min { width: 143px; - height: 40px; + height: 36px; } #communityWidget.max { width: 170px; - height: 279px; + height: 254px; } diff --git a/doc/_static/communitywidget.js b/doc/_static/communitywidget.js index 712f1161..2b124851 100644 --- a/doc/_static/communitywidget.js +++ b/doc/_static/communitywidget.js @@ -1,21 +1,14 @@ var showWidget = true; if (showWidget) { - // console.log("loaded"); - var widget = document.getElementById("communityWidget"), - parentUrl = window.location.host; + + var widget = document.getElementById("communityWidget"); + var parentUrl = window.location.host; widget.classList.add("min"); widget.classList.remove("nonDisplay"); - - // widget.addEventListener("load", sendUrlToWidget); - // function sendUrlToWidget() { - // widget.contentWindow.postMessage(parentUrl, "*"); // "*" - can be sent irrespective of the origin of the calling page - // } - function onIFrameMessage(evt) { - console.log("widget received event", evt.data); var targetSize = evt.data; @@ -28,14 +21,10 @@ if (showWidget) { widget.classList.remove("min"); widget.classList.add("max"); - } } - // window.addEventListener("message", function(evt) { console.log("message received", evt.data);}); window.addEventListener("message", onIFrameMessage); - - } @@ -58,23 +47,93 @@ window.addEventListener("focus", onInterActionDetected); window.addEventListener("blur", onInterActionDetected); var messageTarget = document.getElementById("communityWidget").contentWindow; + function onInterActionDetected(evt) { - // console.log("interaction detected", evt.type); - var actionType = evt.type, - source = window.location.href; + var actionType = evt.type; + var source = window.location.href; messageTarget.postMessage([actionType, source], "*"); } // change widget position on scrolling var widgetOffsetY = widget.getClientRects()[0].top; -window.addEventListener("scroll", function() { - var widget = document.getElementById("communityWidget"), - windowOffsetY = window.pageYOffset, - curWoY = widget.getClientRects()[0].top, - newOffSet; - console.log("orig, cur, window", widgetOffsetY, curWoY, windowOffsetY); +window.addEventListener("scroll", function() { + var widget = document.getElementById("communityWidget"); + var windowOffsetY = window.pageYOffset; + var curWoY = widget.getClientRects()[0].top; + var newOffSet; + + curWoY = widgetOffsetY - windowOffsetY; + curWoY < 0 ? curWoY = 0 : curWoY = curWoY; + + widget.style.top = curWoY + "px"; +}) +var showWidget = true; + +if (showWidget) { + + var widget = document.getElementById("communityWidget"); + var parentUrl = window.location.host; + + widget.classList.add("min"); + widget.classList.remove("nonDisplay"); + + function onIFrameMessage(evt) { + + var targetSize = evt.data; + + if (targetSize === "min") { + + widget.classList.remove("max"); + widget.classList.add("min"); + + } else if (targetSize === "max") { + + widget.classList.remove("min"); + widget.classList.add("max"); + } + } + + window.addEventListener("message", onIFrameMessage); +} + + +// detect user interacting with the page / tab +// message this to the community widget iframe + +document.addEventListener("click", onInterActionDetected); +document.addEventListener("keydown", onInterActionDetected); +document.addEventListener("mousemove", onInterActionDetected); +document.addEventListener("mousedown", onInterActionDetected); +document.addEventListener("mouseup", onInterActionDetected); +document.addEventListener("wheel", onInterActionDetected); + +// for touch devices +document.addEventListener("touchstart", onInterActionDetected); +document.addEventListener("touchend", onInterActionDetected); +document.addEventListener("touchmove", onInterActionDetected); + +window.addEventListener("focus", onInterActionDetected); +window.addEventListener("blur", onInterActionDetected); + +var messageTarget = document.getElementById("communityWidget").contentWindow; + +function onInterActionDetected(evt) { + var actionType = evt.type; + var source = window.location.href; + messageTarget.postMessage([actionType, source], "*"); +} + + +// change widget position on scrolling +var widgetOffsetY = widget.getClientRects()[0].top; + +window.addEventListener("scroll", function() { + var widget = document.getElementById("communityWidget"); + var windowOffsetY = window.pageYOffset; + var curWoY = widget.getClientRects()[0].top; + var newOffSet; curWoY = widgetOffsetY - windowOffsetY; curWoY < 0 ? curWoY = 0 : curWoY = curWoY; diff --git a/doc/_templates/layout.html b/doc/_templates/layout.html index 675524e1..1ab2c4b8 100644 --- a/doc/_templates/layout.html +++ b/doc/_templates/layout.html @@ -13,7 +13,7 @@ ga('send', 'pageview'); - + {% endblock %} @@ -22,7 +22,11 @@ + + + + diff --git a/doc/index.rst b/doc/index.rst index d97e59b0..6a682ff3 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -119,8 +119,8 @@ A sample WAMP application component implementing all client roles: Complete example code: - * **server**, which provides a remote procedure enpoint and publishes to a topic - `Twisted `_ - `asyncio `_ - * **client**, which calls the procedure and subscribes to the topic - `Twisted `_ - `asyncio `_ + * **server**, which provides a remote procedure enpoint and publishes to a topic - `Twisted `__ - `asyncio `__ + * **client**, which calls the procedure and subscribes to the topic - `Twisted `__ - `asyncio `__ There are many more examples showing options and advanced features, listed on the :doc:`example overview page `. diff --git a/doc/wampprogramming.rst b/doc/wampprogramming.rst index 57abdfb9..3a792bfd 100644 --- a/doc/wampprogramming.rst +++ b/doc/wampprogramming.rst @@ -149,6 +149,7 @@ For example, here is how you call a remote procedure that takes no arguments and now = yield session.call("com.timeservice.now") print(now) + This is using `yield`, which assumes the context in that you run this code is a *co-routine* (something decorated with `defer.inlineDeferred` in Twisted or `asyncio.coroutine` in asyncio). The same call using plain Twisted Deferreds would look like: