Author: lindner
Date: Tue May 18 17:16:32 2010
New Revision: 945770
URL: http://svn.apache.org/viewvc?rev=945770&view=rev
Log:
Revert "more connect"
This reverts commit 0eadde25697c650e1d4bd5df119721df36e7e19c.
Added:
shindig/trunk/content/container/sample-connect.html
Removed:
shindig/trunk/content/connect/canvas.html
shindig/trunk/content/connect/page.html
Modified:
shindig/trunk/features/src/main/javascript/features/shindig.connect/connect.js
Added: shindig/trunk/content/container/sample-connect.html
URL:
http://svn.apache.org/viewvc/shindig/trunk/content/container/sample-connect.html?rev=945770&view=auto
==============================================================================
--- shindig/trunk/content/container/sample-connect.html (added)
+++ shindig/trunk/content/container/sample-connect.html Tue May 18 17:16:32 2010
@@ -0,0 +1,121 @@
+<!--
+ * 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.
+-->
+<html>
+<head>
+<title>Metadata Demo</title>
+<style>
+ .gadget {
+ border: solid 1px #000;
+ margin: 10px;
+ float: left;
+ text-align: center;
+ }
+ .gadget h2 {
+ background: #ccf;
+ border-bottom: solid 1px #000;
+ margin: 0;
+ padding: 5px;
+ }
+ .gadget iframe {
+ margin: 5px;
+ border: none;
+ height: 300px;
+ width: 300px;
+ }
+</style>
+<script src="/gadgets/js/shindig-connect.js?c=1&container=default"></script>
+</head>
+<body>
+Hello <os:viewer/>
+<os:config country="de"/>
+<os:gadget moduleId="1"
url="http://www.google.com/ig/modules/horoscope.xml"></os:gadget>
+<os:gadget moduleId="2"
url="http://www.labpixies.com/campaigns/todo/todo.xml"></os:gadget>
+
+<script type="text/javascript">
+ function renderGadgets(obj) {
+ var gadgetList = obj.gadgets;
+ var features = {};
+ for (var i = 0, gadget; gadget = gadgetList[i]; ++i) {
+ var feats = gadget.features || [];
+ for (var j = 0, feature; feature = feats[j]; ++j) {
+ features[feature] = true;
+ }
+ }
+ var libs = [];
+ for (var lib in features) {libs.push(lib);}
+ libs.sort();
+ libs = libs.join(":");
+
+ // TODO race condition exists here..
+ libs = "core:rpc";
+
+ for (var i = 0, gadget; gadget = gadgetList[i]; ++i) {
+ var newGadget = document.createElement("div");
+ newGadget.className = "gadget";
+
+ if (gadget.errors && gadget.errors.length > 0) {
+ newGadget.innerHTML = ["Unable to process gadget: ", gadget.url, ".
Errors: <pre>", gadget.errors.join("\n"), "</pre>"].join("");
+ document.body.appendChild(newGadget);
+ } else {
+ newGadget.innerHTML = ['<h2>', gadget.title, '</h2>',
+ '<iframe src="', gadget.iframeUrl, '&debug=1&libs=', libs
,'#parent=http://localhost:8080/&rpcToken=1111" id="remote_iframe_',
gadget.moduleId, '" name="remote_iframe_', gadget.moduleId, '" style="height:
', gadget.height, 'px"></iframe>'
+ ].join("");
+ $("#gadget_id_" + gadget.moduleId).html(newGadget);
+ gadgets.rpc.setupReceiver("remote_iframe_" + gadget.moduleId);
+ }
+ }
+ }
+
+ var request = {};
+ var gadgetlist = [];
+ $("os\\:gadget").each(function() {
+ var tag = $(this);
+ var mid = tag.attr('moduleId');
+ tag.attr("id", "gadget_id_" + mid);
+ tag.html("Loading...");
+ gadgetlist.push({url: tag.attr('url'), moduleId: mid});
+ });
+ // defaults
+ var context = {
+ country: "US",
+ language: "en",
+ view: "default",
+ container: "default",
+ debug: true
+ };
+
+ var os_config = $("os\\:config");
+ if (os_config) {
+ context.country = os_config.attr('country') || context.country;
+ context.language = os_config.attr('language') || context.language;
+ }
+ var request = {
+ context: context,
+ gadgets: gadgetlist
+ };
+
+ var req = gadgets.json.stringify(request);
+
+ var script = document.createElement('script');
+ script.setAttribute('src', "/gadgets/metadata?callback=renderGadgets&req=" +
req);
+ document.getElementsByTagName('head')[0].appendChild(script);
+
+</script>
+</body>
+</html>
Modified:
shindig/trunk/features/src/main/javascript/features/shindig.connect/connect.js
URL:
http://svn.apache.org/viewvc/shindig/trunk/features/src/main/javascript/features/shindig.connect/connect.js?rev=945770&r1=945769&r2=945770&view=diff
==============================================================================
---
shindig/trunk/features/src/main/javascript/features/shindig.connect/connect.js
(original)
+++
shindig/trunk/features/src/main/javascript/features/shindig.connect/connect.js
Tue May 18 17:16:32 2010
@@ -1,205 +1,7 @@
-shindig.connect = function() {
- var config = {};
- var FrameIdToGadget = {};
-
- // TODO pull this from container config, namespace variable...
- var TEMPLATES = {
- loading: "Loading...",
- };
-
- /**
- *
- */
-
- function init(configuration) {
- config = configuration["shindig.connect"] || {};
- }
-
-// var requiredConfig = {
-// metdataUrl: gadgets.config.NonEmptyStringValidator
-// };
-// gadgets.config.register("shindig.connect", requiredConfig, init);
-
- /**
- *
- */
-
- function parseTags(pageContext, opt_cb) {
- var request = {};
- var gadgetlist = [];
-
- jQuery("os\\:gadget", pageContext).each(function() {
- var tag = jQuery(this);
- var mid = tag.attr('moduleId');
- tag.attr("id", "gadget_id_" + mid);
- tag.html(TEMPLATES['loading']);
- var g = {url: tag.attr('url'), moduleId: mid};
- gadgetlist.push(g);
- FrameIdToGadget['remote_iframe_' + mid] = g;
- });
-
- // defaults
- var context = {
- country: "ALL",
- language: "ALL",
- view: "default",
- container: "default",
- };
-
- // ignore page context, we need the global config
- jQuery("os\\:config").each(function() {
- var tag = jQuery(this);
-
- // Strings
- var attrs = ['country', 'language', 'view'];
- for (var apos =0; apos < attrs.length; apos++ ) {
- var attr = attrs[apos];
- context[attr] = tag.attr(attr) || context[attr];
- }
-
- // Bools
- context.debug = (tag.attr('debug') === 'true');
- context.ignoreCache = (tag.attr('nocache') === 'true');
- });
-
- var req = gadgets.json.stringify({ context: context, gadgets: gadgetlist});
-
- // TODO get URL from context..
- jQuery.getJSON("/gadgets/metadata?req=" + req + "&callback=?",
- function(data) {
- renderGadgets(data, pageContext, context, opt_cb);
- });
- }
-
- /**
- *
- */
- function renderGadgets(obj, pageContext, context, opt_cb) {
- if (obj.viewer) {
- // Substitute vars..
- jQuery("os\\:Name", pageContext).each(function() {
- var tag = jQuery(this);
- var person = tag.attr('person');
- tag.html(obj.viewer.name.unstructured);
- });
- }
-
- var gadgetList = obj.gadgets;
- var features = {};
- for (var i = 0, gadget; gadget = gadgetList[i]; ++i) {
- var feats = gadget.features || [];
- for (var j = 0, feature; feature = feats[j]; ++j) {
- features[feature] = true;
- }
- }
- var libs = [];
- for (var lib in features) {libs.push(lib);}
- libs.sort();
- libs = libs.join(":");
-
- // TODO race condition exists here..
- libs = "core:rpc";
-
- for (var i = 0, gadget; gadget = gadgetList[i]; ++i) {
- var rpcToken = (0x7FFFFFFF * Math.random()) | 0;
-
- var newGadget = document.createElement("div");
-
- if (gadget.errors && gadget.errors.length > 0) {
- newGadget.className = "shindig-connect-gadget"; // TODO change to
error class
- newGadget.innerHTML = ["Unable to process gadget: ", gadget.url, ".
Errors: <pre>", gadget.errors.join("\n"), "</pre>"].join("");
- jQuery("#gadget_id_" + gadget.moduleId).html(newGadget);
- } else {
- var viewname = context.view || 'default';
- var view = (gadget.views) ? gadget.views[viewname] : undefined;
- var style = (view && view.attributes && view.attributes.style) ||
"gadget";
-
- newGadget.className = "shindig-connect-" + style;
- var remoteIframe = "remote_iframe_" + gadget.moduleId;
-
- // should be a template...
- newGadget.innerHTML = ['<a
id="shindig-connect-canvas-close">X</a><h2>', gadget.title, '</h2>',
- '<iframe src="', gadget.iframeUrl,
- '&libs=', libs ,
- '&st=', gadget.st,
- '#',
- 'parent=', 'http://', document.location.host,
- '&rpcToken=', rpcToken, '"',
- ' id="', remoteIframe, '"',
- ' name="', remoteIframe, '"',
- ' style="height: ', (view.preferredHeight || gadget.height || 300),
'px"',
- ' scrolling="', (gadget.scrolling ? 'yes' : 'no'), '"',
- ' width="', (view.preferredWidth || gadget.width || 300), '"',
- '></iframe>'
- ].join("");
- jQuery("#gadget_id_" + gadget.moduleId).html(newGadget);
- gadgets.rpc.setupReceiver(remoteIframe);
- }
- }
- if (opt_cb) opt_cb();
- }
-
- jQuery(document).ready( function() {
- parseTags(this);
- // Add boilerplate things
- jQuery('body').append('<div id="shindig-connect-canvas"></div><div
id="shindig-connect-canvas-background"></div>');
- // Add zuul gadget if not there already..
- });
-
- // TODO
- // need customized url template for canvas view.
gadgets.rpc.register('resize_iframe', function(height) {
- // TODO deal with canvas page.
var element = document.getElementById(this.f);
if (element) {
element.style.height = height + 'px';
}
});
-
-gadgets.rpc.register('requestNavigateTo', function(view, opt_params) {
- var id = this.f;
- var g = FrameIdToGadget[id];
-
- // TODO canvas here
- var canvas = jQuery('#shindig-connect-canvas');
-
- var moduleId = g.moduleId + 1000;
- canvas.html('<os:gadget moduleId="' + moduleId + '" url="' + g.url +
'"></os:gadget><os:config view="canvas"></os:config>');
-
- var windowWidth = document.documentElement.clientWidth;
- var windowHeight = document.documentElement.clientHeight;
-
- // Canvas at 80% of current size
- var height= Math.floor(windowHeight * .8);
- var width= Math.floor(windowWidth * .8);
-
- // allow local override
- if (opt_params) {
- height = opt_params.height || height;
- width = opt_params.width || width;
- }
-
- // Set div size, and make modal, add close box?
- parseTags(canvas, function() {
- var background = jQuery("#shindig-connect-canvas-background");
-
- var popupHeight = canvas.height();
- var popupWidth = canvas.width();
-
- canvas.css({
- "position": "absolute",
- "top": windowHeight/2-popupHeight/2,
- "left": windowWidth/2-popupWidth/2
- });
- background.css({"opacity": "0.7", height: windowHeight});
- background.fadeIn("slow");
- canvas.fadeIn("slow");
- jQuery('shindig-connect-canvas-close').click(function() {
- $(background).fadeOut("slow");
- $(canvas).fadeOut("slow");
- });
-
- });
- });
-}();