Author: lindner
Date: Tue May 18 16:57:29 2010
New Revision: 945748

URL: http://svn.apache.org/viewvc?rev=945748&view=rev
Log:
more connect

Added:
    shindig/trunk/content/connect/
    shindig/trunk/content/connect/canvas.html
    shindig/trunk/content/connect/page.html
Removed:
    shindig/trunk/content/container/sample-connect.html
Modified:
    
shindig/trunk/features/src/main/javascript/features/shindig.connect/connect.js

Added: shindig/trunk/content/connect/canvas.html
URL: 
http://svn.apache.org/viewvc/shindig/trunk/content/connect/canvas.html?rev=945748&view=auto
==============================================================================
--- shindig/trunk/content/connect/canvas.html (added)
+++ shindig/trunk/content/connect/canvas.html Tue May 18 16:57:29 2010
@@ -0,0 +1,68 @@
+<!--
+ * 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>Connect Demo</title>
+<style>
+  .shindig-connect-gadget {
+    border: solid 1px #000;
+    margin: 10px;
+    float: left;
+    text-align: center;
+  }
+  .shindig-connect-gadget h2 {
+    background: #ccf;
+    border-bottom: solid 1px #000;
+    margin: 0;
+    padding: 5px;
+  }
+  .shindig-connect-gadget iframe {
+    margin: 5px;
+    border: none;
+    height: 300px;
+  }
+
+  .shindig-connect-chromeless iframe {
+    margin: 1px;
+    border: none;
+  }
+
+  .shindig-connect-chromeless h2 {
+    display: none;
+  }
+</style>
+<script 
src="/gadgets/js/shindig-connect.js?c=1&container=default&nocache=1&debug=1"></script>
+</head>
+
+<body>
+<os:config country="de" debug="true" nocache="true" view="canvas"></os:config>
+<br/>
+<script>
+  var p = gadgets.util.getUrlParameters();
+  console.log(p);
+  if (p && p.url) {
+    document.write('<os:gadget moduleId="1" url="' + p.url + 
'"></os:gadget>'); 
+  } else {
+    jQuery('errors').html("No url parameter specified");
+  }
+</script>
+<div id="errors"></div>
+<br/>
+</body>
+</html>

Added: shindig/trunk/content/connect/page.html
URL: 
http://svn.apache.org/viewvc/shindig/trunk/content/connect/page.html?rev=945748&view=auto
==============================================================================
--- shindig/trunk/content/connect/page.html (added)
+++ shindig/trunk/content/connect/page.html Tue May 18 16:57:29 2010
@@ -0,0 +1,91 @@
+<!--
+ * 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>Connect Demo</title>
+<style>
+  .shindig-connect-gadget {
+    border: solid 1px #000;
+    margin: 10px;
+    float: left;
+    text-align: center;
+  }
+  .shindig-connect-gadget h2 {
+    background: #ccf;
+    border-bottom: solid 1px #000;
+    margin: 0;
+    padding: 5px;
+  }
+  .shindig-connect-gadget iframe {
+    margin: 5px;
+    border: none;
+    height: 300px;
+  }
+
+  .shindig-connect-chromeless iframe {
+    margin: 1px;
+    border: none;
+  }
+
+  .shindig-connect-chromeless h2 {
+    display: none;
+  }
+  #shindig-connect-canvas-background {  
+    display:none;  
+    position:fixed;  
+    _position:absolute; /* hack for internet explorer 6*/  
+    height:100%;  
+    width:100%;  
+    top:0;  
+    left:0;  
+    background:#000000;  
+    border:1px solid #cecece;  
+    z-index:1;  
+}  
+
+ #shindig-connect-canvas {
+   display:none;  
+   position:fixed;  
+   _position:absolute; /* hack for internet explorer 6*/  
+   background:#FFFFFF;  
+   border:2px solid #cecece;  
+   z-index:2;  
+   padding:4px;  
+   font-size:13px;  
+ }
+</style>
+<script 
src="/gadgets/js/shindig-connect.js?c=1&container=default&nocache=1&debug=1"></script>
+</head>
+
+<body>
+<os:config country="de" debug="true" nocache="true"></os:config>
+
+Hello <os:Name></os:Name>
+<br/>
+<script>
+  // You can dynamically add things like this..
+  document.write('<os:gadget moduleId="1" 
url="http://www.google.com/ig/modules/horoscope.xml";>Temporary, will be 
replaced</os:gadget>'); 
+</script>
+<br/>
+<os:gadget moduleId="2" 
url="http://www.labpixies.com/campaigns/todo/todo.xml";></os:gadget>
+<br/>
+<os:gadget moduleId="3" url="http://localhost/~plindner/login.xml";></os:gadget>
+<os:gadget moduleId="4" url="http://localhost/~plindner/share.xml";></os:gadget>
+</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=945748&r1=945747&r2=945748&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 16:57:29 2010
@@ -1,7 +1,205 @@
+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");  
+              });
+
+        });
+    });
+}();


Reply via email to