SHINDIG-1056 by lipeng, BasicRemoteContentTest doesn't depend on static private key...
[shindig.git] / javascript / container / sample-pubsub.html
blob55e7ebe2643a5652ae557c845d2896685c4a62db
1 <!--
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 -->
19 <!DOCTYPE html>
20 <html>
21 <head>
22 <title>Sample: PubSub</title>
23 <!-- default container look and feel -->
24 <link rel="stylesheet" href="gadgets.css">
25 <script type="text/javascript" src="http://localhost:8080/gadgets/js/pubsub.js?c=1&debug=1"></script>
26 <script type="text/javascript" src="util.js"></script>
27 <script type="text/javascript" src="gadgets.js"></script>
28 <script type="text/javascript">
29 var my = {};
31 my.gadgetSpecUrls = [
32 'http://localhost:8080/gadgets/files/container/sample-pubsub-publisher.xml',
33 'http://localhost:8080/gadgets/files/container/sample-pubsub-subscriber.xml',
34 'http://localhost:8080/gadgets/files/container/sample-pubsub-subscriber.xml'
37 my.LayoutManager = function() {
38 gadgets.LayoutManager.call(this);
41 my.LayoutManager.inherits(gadgets.LayoutManager);
43 my.LayoutManager.prototype.getGadgetChrome = function(gadget) {
44 var chromeId = 'gadget-chrome-' + gadget.id;
45 return chromeId ? document.getElementById(chromeId) : null;
48 my.init = function() {
49 gadgets.pubsubrouter.init(function(id) {
50 return my.gadgetSpecUrls[parseInt(id[id.length - 1])];
51 }, {
52 onSubscribe: function(sender, channel) {
53 log(sender + " subscribes to channel '" + channel + "'");
54 // return true to reject the request.
56 onUnsubscribe: function(sender, channel) {
57 log(sender + " unsubscribes from channel '" + channel + "'");
58 // return true to reject the request.
60 onPublish: function(sender, channel, message) {
61 log(sender + " publishes '" + message + "' to channel '" + channel + "'");
62 // return true to reject the request.
64 });
65 gadgets.container.layoutManager = new my.LayoutManager();
68 my.renderGadgets = function() {
69 for (var i = 0; i < my.gadgetSpecUrls.length; ++i) {
70 var gadget = gadgets.container.createGadget(
71 {specUrl: my.gadgetSpecUrls[i], title: (i ? "Subscriber" : "Publisher")});
72 gadgets.container.addGadget(gadget);
73 gadgets.container.renderGadget(gadget);
77 function log(message) {
78 document.getElementById("output").innerHTML += gadgets.util.escapeString(message) + "<br/>";
80 </script>
81 </head>
82 <body onLoad="my.init();my.renderGadgets();">
83 <h2>Sample: PubSub</h2>
84 <div id="gadget-chrome-0" class="gadgets-gadget-chrome"></div>
85 <div id="gadget-chrome-1" class="gadgets-gadget-chrome"></div>
86 <div id="gadget-chrome-2" class="gadgets-gadget-chrome"></div>
87 <div id="output" style="clear: left;">
88 </div>
89 </body>
90 </html>