Author: lindner
Date: Tue May 18 16:57:44 2010
New Revision: 945751
URL: http://svn.apache.org/viewvc?rev=945751&view=rev
Log:
rev connect features
Added:
shindig/trunk/features/src/main/javascript/features/shindig.connect-1.0/
shindig/trunk/features/src/main/javascript/features/shindig.connect-1.0/connect.js
shindig/trunk/features/src/main/javascript/features/shindig.connect-1.0/feature.xml
- copied, changed from r945750,
shindig/trunk/features/src/main/javascript/features/shindig.connect/feature.xml
Removed:
shindig/trunk/features/src/main/javascript/features/shindig.connect/connect.js
shindig/trunk/features/src/main/javascript/features/shindig.connect/feature.xml
Modified:
shindig/trunk/config/container.js
shindig/trunk/content/connect/page.html
shindig/trunk/features/src/main/javascript/features/features.txt
Modified: shindig/trunk/config/container.js
URL:
http://svn.apache.org/viewvc/shindig/trunk/config/container.js?rev=945751&r1=945750&r2=945751&view=diff
==============================================================================
--- shindig/trunk/config/container.js (original)
+++ shindig/trunk/config/container.js Tue May 18 16:57:44 2010
@@ -103,6 +103,10 @@
// Only configuration for required features will be used.
// See individual feature.xml files for configuration details.
"gadgets.features" : {
+ "shindig.connect-1.0" : {
+ "metadataUrl" : "/gadgets/metadata"
+ },
+
"core.io" : {
// Note: /proxy is an open proxy. Be careful how you expose this!
// Note: Here // is replaced with the current protocol http/https
Modified: shindig/trunk/content/connect/page.html
URL:
http://svn.apache.org/viewvc/shindig/trunk/content/connect/page.html?rev=945751&r1=945750&r2=945751&view=diff
==============================================================================
--- shindig/trunk/content/connect/page.html (original)
+++ shindig/trunk/content/connect/page.html Tue May 18 16:57:44 2010
@@ -70,7 +70,7 @@
font-size:13px;
}
</style>
-<script
src="/gadgets/js/shindig-connect.js?c=1&container=default&nocache=1&debug=1"></script>
+<script
src="/gadgets/js/shindig.connect-1.0.js?c=1&container=default&nocache=1&debug=1"></script>
</head>
<body>
@@ -80,12 +80,15 @@ 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>');
+ document.write('<os:gadget
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>
+<os:gadget 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>
+<li:login></li:login>
+<li:share></li:share>
+<!-- <os:gadget url="http://localhost/~plindner/login.xml"></os:gadget>
+<os:gadget url="http://localhost/~plindner/share.xml"></os:gadget>
+-->
</body>
</html>
Modified: shindig/trunk/features/src/main/javascript/features/features.txt
URL:
http://svn.apache.org/viewvc/shindig/trunk/features/src/main/javascript/features/features.txt?rev=945751&r1=945750&r2=945751&view=diff
==============================================================================
--- shindig/trunk/features/src/main/javascript/features/features.txt (original)
+++ shindig/trunk/features/src/main/javascript/features/features.txt Tue May 18
16:57:44 2010
@@ -59,7 +59,7 @@ features/rpc/feature.xml
features/security-token/feature.xml
features/setprefs/feature.xml
features/settitle/feature.xml
-features/shindig.connect/feature.xml
+features/shindig.connect-1.0/feature.xml
features/shindig.container/feature.xml
features/skins/feature.xml
features/swfobject/feature.xml
Added:
shindig/trunk/features/src/main/javascript/features/shindig.connect-1.0/connect.js
URL:
http://svn.apache.org/viewvc/shindig/trunk/features/src/main/javascript/features/shindig.connect-1.0/connect.js?rev=945751&view=auto
==============================================================================
---
shindig/trunk/features/src/main/javascript/features/shindig.connect-1.0/connect.js
(added)
+++
shindig/trunk/features/src/main/javascript/features/shindig.connect-1.0/connect.js
Tue May 18 16:57:44 2010
@@ -0,0 +1,263 @@
+shindig.connect = function() {
+ var config = {};
+ var FrameIdToGadget = {};
+ var moduleIdCounter = 1;
+ var Gadgets = {};
+
+ // TODO pull this from container config, namespace variable...
+ var LAYOUT = {
+ loading: "Loading...",
+ chrome: {
+ "default": {
+ template: "<h2>%title%</h2>%iframe%",
+ width: 300,
+ height: 300
+ },
+ "default.chromeless": {
+ template: "%iframe%",
+ width: 200,
+ height: 80
+ },
+ "canvas": {
+ template: '<h2><a href="#" id="shindig-connect-canvas-close">X</a>
%title%</h2>%iframe%',
+ width: 600,
+ height: 400
+ }
+ }
+ };
+
+ /**
+ *
+ */
+
+ function init(configuration) {
+ config = configuration["shindig.connect"] || {};
+ }
+
+ var requiredConfig = {
+ metadataUrl: gadgets.config.NonEmptyStringValidator
+ };
+ gadgets.config.register("shindig.connect-1.0", requiredConfig, init);
+
+ /**
+ *
+ */
+
+ function parseTags(pageContext, opt_cb) {
+ var request = {};
+ var gadgetlist = [];
+
+ // TODO eliminiate dupe code
+ jQuery("li\\:login", pageContext).each(function() {
+ var tag = jQuery(this);
+ var mid = moduleIdCounter++;
+ tag.attr("id", "gadget_id_" + mid);
+ tag.html(LAYOUT['loading']);
+ var g = {url: "http://localhost/~plindner/login.xml", moduleId: mid};
+ gadgetlist.push(g);
+ Gadgets[mid] = g;
+ FrameIdToGadget['remote_iframe_' + mid] = g;
+ });
+
+ jQuery("li\\:share", pageContext).each(function() {
+ var tag = jQuery(this);
+ var mid = moduleIdCounter++;
+ tag.attr("id", "gadget_id_" + mid);
+ tag.html(LAYOUT['loading']);
+ var g = {url: "http://localhost/~plindner/share.xml", moduleId: mid};
+ gadgetlist.push(g);
+ Gadgets[mid] = g;
+ FrameIdToGadget['remote_iframe_' + mid] = g;
+ });
+
+
+ jQuery("os\\:gadget", pageContext).each(function() {
+ var tag = jQuery(this);
+ var mid = moduleIdCounter++;
+ tag.attr("id", "gadget_id_" + mid);
+ tag.html(LAYOUT['loading']);
+ var g = {url: tag.attr('url'), moduleId: mid};
+ gadgetlist.push(g);
+ Gadgets[mid] = 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 should get URL from container injected value instead of from
os:config / default
+ var metadataUrl = config.metadataUrl || "/gadgets/metadata";
+
+ jQuery.getJSON(metadataUrl + "?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;
+
+ // calculate the libs parameter
+ 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 override all that above...
+ 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) {
+ // TODO change to error class, use error template
+ newGadget.className = "shindig-connect-gadget";
+ 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";
+
+ // TODO chop views like canvas.XXX to just canvas
+ var layout = LAYOUT.chrome[viewname + '.' + style] ||
LAYOUT.chrome[viewname] || {};
+ console.log(layout);
+
+ newGadget.className = "shindig-connect-" + style;
+ var remoteIframe = "remote_iframe_" + gadget.moduleId;
+ var iframeHeight = view.preferredHeight || gadget.height ||
layout.height;
+ var iframeWidth = view.preferredWidth || gadget.width ||
layout.width;
+ var html = layout.template || '%iframe%';
+
+ html = html.replace('%title%', '<span id="gadget_id_' +
gadget.moduleId + '_title">' + gadget.title + '</span>');
+ html = html.replace('%iframe%',
+ ['<iframe src="', gadget.iframeUrl,
+ '&libs=', libs ,
+ '&parent=', encodeURIComponent(document.location.protocol + '//' +
document.location.host),
+ '#rpcToken=', rpcToken, '"',
+ ' id="', remoteIframe, '"',
+ ' name="', remoteIframe, '"',
+ ' style="height: ', iframeHeight, 'px"',
+ ' scrolling="', (gadget.scrolling ? 'yes' : 'no'), '"',
+ ' width="', iframeWidth, '"',
+ '></iframe>'
+ ].join(""));
+ newGadget.innerHTML = html;
+ 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 add refetch param
+ gadgets.rpc.register('reload_page', function(refetch) {
+ window.location.reload( false );
+ });
+
+ 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];
+
+ var canvas = jQuery('#shindig-connect-canvas');
+
+ var moduleId = moduleIdCounter++;
+ canvas.html('<os:gadget 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");
+ });
+ });
+ });
+}();
Copied:
shindig/trunk/features/src/main/javascript/features/shindig.connect-1.0/feature.xml
(from r945750,
shindig/trunk/features/src/main/javascript/features/shindig.connect/feature.xml)
URL:
http://svn.apache.org/viewvc/shindig/trunk/features/src/main/javascript/features/shindig.connect-1.0/feature.xml?p2=shindig/trunk/features/src/main/javascript/features/shindig.connect-1.0/feature.xml&p1=shindig/trunk/features/src/main/javascript/features/shindig.connect/feature.xml&r1=945750&r2=945751&rev=945751&view=diff
==============================================================================
---
shindig/trunk/features/src/main/javascript/features/shindig.connect/feature.xml
(original)
+++
shindig/trunk/features/src/main/javascript/features/shindig.connect-1.0/feature.xml
Tue May 18 16:57:44 2010
@@ -17,7 +17,7 @@ KIND, either express or implied. See the
specific language governing permissions and limitations under the License.
-->
<feature>
- <name>shindig-connect</name>
+ <name>shindig.connect-1.0</name>
<dependency>globals</dependency>
<dependency>rpc</dependency>
<dependency>osapi</dependency>