small fixes

This commit is contained in:
Alexander Goedde
2014-04-14 18:24:39 +02:00
parent 7b27509d18
commit c6527aa813
5 changed files with 96 additions and 31 deletions

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -13,7 +13,7 @@
ga('send', 'pageview');
</script>
<link rel="stylesheet" href="_static/communitywidget.css">
{% endblock %}
@@ -22,7 +22,11 @@
<!-- community widget iframe -->
<!-- <iframe id="communityWidget" src="http://127.0.0.1:8090/widget/index.html" frameborder="0"></iframe> -->
<link rel="stylesheet" href="_static/communitywidget.css">
<iframe id="communityWidget" src="http://192.168.1.147:8090/widget/index.html" frameborder="0"></iframe>
<!-- change url for production -->
<script src="_static/communitywidget.js"></script>

View File

@@ -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 <https://github.com/tavendo/AutobahnPython/blob/master/examples/twisted/wamp/beginner/server.py>`_ - `asyncio <https://github.com/tavendo/AutobahnPython/blob/master/examples/asyncio/wamp/beginner/server.py>`_
* **client**, which calls the procedure and subscribes to the topic - `Twisted <https://github.com/tavendo/AutobahnPython/blob/master/examples/twisted/wamp/beginner/client.py>`_ - `asyncio <https://github.com/tavendo/AutobahnPython/blob/master/examples/asyncio/wamp/beginner/client.py>`_
* **server**, which provides a remote procedure enpoint and publishes to a topic - `Twisted <https://github.com/tavendo/AutobahnPython/blob/master/examples/twisted/wamp/beginner/server.py>`__ - `asyncio <https://github.com/tavendo/AutobahnPython/blob/master/examples/asyncio/wamp/beginner/server.py>`__
* **client**, which calls the procedure and subscribes to the topic - `Twisted <https://github.com/tavendo/AutobahnPython/blob/master/examples/twisted/wamp/beginner/client.py>`__ - `asyncio <https://github.com/tavendo/AutobahnPython/blob/master/examples/asyncio/wamp/beginner/client.py>`__
There are many more examples showing options and advanced features, listed on the :doc:`example overview page <examples>`.

View File

@@ -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: