Repository: incubator-unomi Updated Branches: refs/heads/master cae989b3b -> c360cbcf2
UNOMI-213 Move twitter sample HTML out of root context and build a proper HTML welcome page in the root context Signed-off-by: Serge Huber <shu...@apache.org> Project: http://git-wip-us.apache.org/repos/asf/incubator-unomi/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-unomi/commit/c360cbcf Tree: http://git-wip-us.apache.org/repos/asf/incubator-unomi/tree/c360cbcf Diff: http://git-wip-us.apache.org/repos/asf/incubator-unomi/diff/c360cbcf Branch: refs/heads/master Commit: c360cbcf2e60518ccd0be58e5e304fbcc4bf0ac1 Parents: cae989b Author: Serge Huber <shu...@apache.org> Authored: Mon Nov 26 14:28:10 2018 +0100 Committer: Serge Huber <shu...@apache.org> Committed: Mon Nov 26 14:28:10 2018 +0100 ---------------------------------------------------------------------- samples/tweet-button-plugin/pom.xml | 3 +- .../src/main/webapp/index.html | 181 +++++++++++++++++++ wab/src/main/webapp/index.html | 173 ++---------------- 3 files changed, 200 insertions(+), 157 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/c360cbcf/samples/tweet-button-plugin/pom.xml ---------------------------------------------------------------------- diff --git a/samples/tweet-button-plugin/pom.xml b/samples/tweet-button-plugin/pom.xml index 039a196..56bfbfa 100644 --- a/samples/tweet-button-plugin/pom.xml +++ b/samples/tweet-button-plugin/pom.xml @@ -46,7 +46,8 @@ <extensions>true</extensions> <configuration> <instructions> - + <_wab>src/main/webapp</_wab> + <Web-ContextPath>/twitter</Web-ContextPath> </instructions> </configuration> </plugin> http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/c360cbcf/samples/tweet-button-plugin/src/main/webapp/index.html ---------------------------------------------------------------------- diff --git a/samples/tweet-button-plugin/src/main/webapp/index.html b/samples/tweet-button-plugin/src/main/webapp/index.html new file mode 100644 index 0000000..791d4dd --- /dev/null +++ b/samples/tweet-button-plugin/src/main/webapp/index.html @@ -0,0 +1,181 @@ +<!-- + ~ Licensed to the Apache Software Foundation (ASF) under one or more + ~ contributor license agreements. See the NOTICE file distributed with + ~ this work for additional information regarding copyright ownership. + ~ The ASF licenses this file to You under the Apache License, Version 2.0 + ~ (the "License"); you may not use this file except in compliance with + ~ the License. You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software + ~ distributed under the License is distributed on an "AS IS" BASIS, + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ~ See the License for the specific language governing permissions and + ~ limitations under the License. + --> +<!DOCTYPE html> +<html lang="en"> +<head> + <meta charset="UTF-8"> + <title>Apache Unomi Tweet button integration example</title> + <script type="application/javascript"> + window.twttr = (function (d, s, id) { + var js, fjs = d.getElementsByTagName(s)[0], + t = window.twttr || {}; + if (d.getElementById(id)) return; + js = d.createElement(s); + js.id = id; + js.src = "https://platform.twitter.com/widgets.js"; + fjs.parentNode.insertBefore(js, fjs); + + t._e = []; + t.ready = function (f) { + t._e.push(f); + }; + + return t; + }(document, "script", "twitter-wjs")); + + // Load context from Unomi asynchronously + (function (document, elementToCreate, id) { + var js, fjs = document.getElementsByTagName(elementToCreate)[0]; + if (document.getElementById(id)) return; + js = document.createElement(elementToCreate); + js.id = id; + js.src = "http://localhost:8181/context.js"; + fjs.parentNode.insertBefore(js, fjs); + }(document, 'script', 'context')); + + // Wait for the asynchronous resources to load + twttr.ready(function (twttr) { + // Now bind our custom intent events + twttr.events.bind('tweet', function (event) { + + var defaultErrorCallback = function () { + alert('There was an error making the request.'); + }; + + function generateUUID() { + var d = new Date().getTime(); + if (window.performance && typeof window.performance.now === "function") { + d += performance.now(); //use high-precision timer if available + } + var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { + var r = (d + Math.random() * 16) % 16 | 0; + d = Math.floor(d / 16); + return (c == 'x' ? r : (r & 0x3 | 0x8)).toString(16); + }); + return uuid; + } + + function contextRequest(successCallback, errorCallback, payload) { + var data = JSON.stringify(payload); + // if we don't already have a session id, generate one + var sessionId; + try { + sessionId = cxs.sessionId; + } catch (e) { + sessionId = generateUUID(); + } + + var url = 'http://localhost:8181/context.json?sessionId=' + sessionId; + var xhr = new XMLHttpRequest(); + var isGet = data.length < 100; + if (isGet) { + xhr.withCredentials = true; + xhr.open("GET", url + "&payload=" + encodeURIComponent(data), true); + } else if ("withCredentials" in xhr) { + xhr.open("POST", url, true); + xhr.withCredentials = true; + } else if (typeof XDomainRequest != "undefined") { + xhr = new XDomainRequest(); + xhr.open("POST", url); + } + xhr.onreadystatechange = function () { + if (xhr.readyState != 4) { + return; + } + if (xhr.status == 200) { + var response = xhr.responseText ? JSON.parse(xhr.responseText) : undefined; + if (response) { + cxs.sessionId = response.sessionId; + successCallback(response); + } + } else { + console.log("contextserver: " + xhr.status + " ERROR: " + xhr.statusText); + if (errorCallback) { + errorCallback(xhr); + } + } + }; + xhr.setRequestHeader("Content-Type", "text/plain;charset=UTF-8"); // Use text/plain to avoid CORS preflight + if (isGet) { + xhr.send(); + } else { + xhr.send(data); + } + } + + var scope = 'unomi-tweet-button-sample'; + var itemId = btoa(window.location.href); + var source = { + itemType: 'page', + scope: scope, + itemId: itemId, + properties: { + url: window.location.href + } + }; + var contextPayload = { + source: source, + events: [ + { + eventType: 'tweetEvent', + scope: scope, + source: source + } + ], + requiredProfileProperties: [ + 'tweetNb', + 'tweetedFrom' + ] + }; + + contextRequest(function (response) { + var element = document.querySelector('#tweetNB'); + element.setAttribute("value", response.profileProperties.tweetNb); + var list = document.querySelector("#tweetedFrom"); + list.innerHTML = ''; + var tweetedFrom = response.profileProperties.tweetedFrom; + for (var index in tweetedFrom) { + var entry = document.createElement('li'); + entry.appendChild(document.createTextNode(tweetedFrom[index])); + list.appendChild(entry); + } + element = document.querySelector("#response"); + element.appendChild(document.createTextNode(JSON.stringify(response))); + }, defaultErrorCallback, contextPayload); + }); + }); + </script> +</head> +<body> +<h1>Apache Unomi Tweet button integration example</h1> +<a href="https://twitter.com/share" class="twitter-share-button" data-via="jahia" data-related="jahia" data-hashtags="jahia">Tweet</a> +<ul> + <li> + <label for="tweetNB">Number of tweets:</label> + <input id="tweetNB" readonly value="0"> + </li> + <li> + <label for="tweetedFrom">Tweeted from URLs:</label> + <ul id="tweetedFrom"></ul> + </li> + <li> + <label for="response">Raw response:</label> + <pre id="response"></pre> + </li> +</ul> +</body> +</html> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/c360cbcf/wab/src/main/webapp/index.html ---------------------------------------------------------------------- diff --git a/wab/src/main/webapp/index.html b/wab/src/main/webapp/index.html index 16d9369..b461cc2 100644 --- a/wab/src/main/webapp/index.html +++ b/wab/src/main/webapp/index.html @@ -18,163 +18,24 @@ <html lang="en"> <head> <meta charset="UTF-8"> - <title>Unomi Tweet button integration example</title> - <script type="application/javascript"> - window.twttr = (function (d, s, id) { - var js, fjs = d.getElementsByTagName(s)[0], - t = window.twttr || {}; - if (d.getElementById(id)) return; - js = d.createElement(s); - js.id = id; - js.src = "https://platform.twitter.com/widgets.js"; - fjs.parentNode.insertBefore(js, fjs); - - t._e = []; - t.ready = function (f) { - t._e.push(f); - }; - - return t; - }(document, "script", "twitter-wjs")); - - // Load context from Unomi asynchronously - (function (document, elementToCreate, id) { - var js, fjs = document.getElementsByTagName(elementToCreate)[0]; - if (document.getElementById(id)) return; - js = document.createElement(elementToCreate); - js.id = id; - js.src = "http://localhost:8181/context.js"; - fjs.parentNode.insertBefore(js, fjs); - }(document, 'script', 'context')); - - // Wait for the asynchronous resources to load - twttr.ready(function (twttr) { - // Now bind our custom intent events - twttr.events.bind('tweet', function (event) { - - var defaultErrorCallback = function () { - alert('There was an error making the request.'); - }; - - function generateUUID() { - var d = new Date().getTime(); - if (window.performance && typeof window.performance.now === "function") { - d += performance.now(); //use high-precision timer if available - } - var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { - var r = (d + Math.random() * 16) % 16 | 0; - d = Math.floor(d / 16); - return (c == 'x' ? r : (r & 0x3 | 0x8)).toString(16); - }); - return uuid; - } - - function contextRequest(successCallback, errorCallback, payload) { - var data = JSON.stringify(payload); - // if we don't already have a session id, generate one - var sessionId; - try { - sessionId = cxs.sessionId; - } catch (e) { - sessionId = generateUUID(); - } - - var url = 'http://localhost:8181/context.json?sessionId=' + sessionId; - var xhr = new XMLHttpRequest(); - var isGet = data.length < 100; - if (isGet) { - xhr.withCredentials = true; - xhr.open("GET", url + "&payload=" + encodeURIComponent(data), true); - } else if ("withCredentials" in xhr) { - xhr.open("POST", url, true); - xhr.withCredentials = true; - } else if (typeof XDomainRequest != "undefined") { - xhr = new XDomainRequest(); - xhr.open("POST", url); - } - xhr.onreadystatechange = function () { - if (xhr.readyState != 4) { - return; - } - if (xhr.status == 200) { - var response = xhr.responseText ? JSON.parse(xhr.responseText) : undefined; - if (response) { - cxs.sessionId = response.sessionId; - successCallback(response); - } - } else { - console.log("contextserver: " + xhr.status + " ERROR: " + xhr.statusText); - if (errorCallback) { - errorCallback(xhr); - } - } - }; - xhr.setRequestHeader("Content-Type", "text/plain;charset=UTF-8"); // Use text/plain to avoid CORS preflight - if (isGet) { - xhr.send(); - } else { - xhr.send(data); - } - } - - var scope = 'unomi-tweet-button-sample'; - var itemId = btoa(window.location.href); - var source = { - itemType: 'page', - scope: scope, - itemId: itemId, - properties: { - url: window.location.href - } - }; - var contextPayload = { - source: source, - events: [ - { - eventType: 'tweetEvent', - scope: scope, - source: source - } - ], - requiredProfileProperties: [ - 'tweetNb', - 'tweetedFrom' - ] - }; - - contextRequest(function (response) { - var element = document.querySelector('#tweetNB'); - element.setAttribute("value", response.profileProperties.tweetNb); - var list = document.querySelector("#tweetedFrom"); - list.innerHTML = ''; - var tweetedFrom = response.profileProperties.tweetedFrom; - for (var index in tweetedFrom) { - var entry = document.createElement('li'); - entry.appendChild(document.createTextNode(tweetedFrom[index])); - list.appendChild(entry); - } - element = document.querySelector("#response"); - element.appendChild(document.createTextNode(JSON.stringify(response))); - }, defaultErrorCallback, contextPayload); - }); - }); - </script> + <title>Apache Unomi Welcome Page</title> </head> <body> -<a href="https://twitter.com/share" class="twitter-share-button" data-via="jahia" data-related="jahia" data-hashtags="jahia">Tweet</a> -<ul> - <li> - <label for="tweetNB">Number of tweets:</label> - <input id="tweetNB" readonly value="0"> - </li> - <li> - <label for="tweetedFrom">Tweeted from URLs:</label> - <ul id="tweetedFrom"></ul> - </li> - <li> - <label for="response">Raw response:</label> - <pre id="response"></pre> - </li> -</ul> + <h1>Welcome to Apache Unomi</h1> + <p>Congratulations, you have successfully installed Apache Unomi !</p> + <h2>Where to go from here</h2> + <ul> + <li>Checkout some cool <a href="http://unomi.apache.org/resources.html" target="_blank">videos & tutorials</a></li> + <li>Read <a href="http://unomi.apache.org/manual/latest/index.html" target="_blank">Apache Unomi's manual</a></li> + <li>Try out some <a href="http://unomi.apache.org/manual/latest/index.html#_integration_samples" target="_blank">samples</a></li> + <li>Join <a href="http://unomi.apache.org/community.html" target="_blank">Apache Unomi's mailing lists</a></li> + <li>Star the project on Github <!-- Place this tag where you want the button to render. --> + <a class="github-button" href="https://github.com/apache/incubator-unomi" data-icon="octicon-star" data-show-count="true" aria-label="Star apache/incubator-unomi on GitHub">Star</a> + </li> + <li>Fork the <a href="https://github.com/apache/incubator-unomi" target="_blank">code</a> and submit pull requests (github repository)</li> + </ul> + + <!-- Place this tag in your head or just before your close body tag. --> + <script async defer src="https://buttons.github.io/buttons.js"></script> </body> </html> \ No newline at end of file