Thank you for your inquiry. DVSR_Sarma Krovi is no longer with the firm. For immediate assistance, please contact Reception at +91-40-6639-0000.
Sincerely, The D. E. Shaw Group -- 8< --- CUT HERE -------------------------- CUT HERE --- >8 -- From: rbaxte...@apache.org To: comm...@shindig.apache.org cc: Subject: svn commit: r1204704 - in /shindig/trunk: content/samplecontainer/examples/commoncontainer/ extras/src/main/javascript/features-extras/org.openajax.hub-2.0.5/ features/src/main/javascript/features/actions/ features/src/main/javascript/features/containe... Author: rbaxter85 Date: Mon Nov 21 21:06:26 2011 New Revision: 1204704 URL: http://svn.apache.org/viewvc?rev=1204704&view=rev Log: SHINDIG-1653 Add additional lifecycle handlers. Modified: shindig/trunk/content/samplecontainer/examples/commoncontainer/assembler.js shindig/trunk/content/samplecontainer/examples/commoncontainer/viewController.js shindig/trunk/extras/src/main/javascript/features-extras/org.openajax.hub-2.0.5/iframe.js shindig/trunk/features/src/main/javascript/features/actions/actions_container.js shindig/trunk/features/src/main/javascript/features/container.gadget/gadget_holder.js shindig/trunk/features/src/main/javascript/features/container.gadget/gadget_site.js shindig/trunk/features/src/main/javascript/features/container.util/constant.js shindig/trunk/features/src/main/javascript/features/container/container.js shindig/trunk/features/src/main/javascript/features/opensearch/opensearch.js shindig/trunk/features/src/main/javascript/features/shared-script-frame/shared-script-frame-container.js shindig/trunk/features/src/test/javascript/features/container/gadget_holder_test.js Modified: shindig/trunk/content/samplecontainer/examples/commoncontainer/assembler.js URL: http://svn.apache.org/viewvc/shindig/trunk/content/samplecontainer/examples/commoncontainer/assembler.js?rev=1204704&r1=1204703&r2=1204704&view=diff ============================================================================== --- shindig/trunk/content/samplecontainer/examples/commoncontainer/assembler.js (original) +++ shindig/trunk/content/samplecontainer/examples/commoncontainer/assembler.js Mon Nov 21 21:06:26 2011 @@ -59,6 +59,7 @@ CommonContainer.init = function() { }); CommonContainer.rpcRegister('set_title', setTitleHandler); + CommonContainer.addGadgetLifecycleCallback('com.example.commoncontainer', lifecycle()); try { @@ -116,3 +117,45 @@ function log(message) { document.getElementById('output').innerHTML = gadgets.util.escapeString(message) + '<br/>' + document.getElementById('output').innerHTML; } +var lifecycle = function() { + var preloadStart; + var navigateStart; + var closeStart; + var unloadStart; + var renderStart; + var listeners = {}; + listeners[osapi.container.CallbackType.ON_BEFORE_PRELOAD] = function(gadgetUrls) { + preloadStart = osapi.container.util.getCurrentTimeMs(); + }; + listeners[osapi.container.CallbackType.ON_PRELOADED] = function(response) { + var urls = []; + for(url in response) { + urls[urls.length] = url; + } + var dif = osapi.container.util.getCurrentTimeMs() - preloadStart; + log('It took ' + dif + 'ms to preload the URL(s) ' + urls + '.'); + }; + listeners[osapi.container.CallbackType.ON_BEFORE_NAVIGATE] = function(gadgetUrl) { + navigateStart = osapi.container.util.getCurrentTimeMs(); + }; + listeners[osapi.container.CallbackType.ON_NAVIGATED] = function(site) { + log('It took ' + (osapi.container.util.getCurrentTimeMs() - navigateStart) + ' ms' + + ' for the site ' + site.getId() + ' to navigate.'); + }; + listeners[osapi.container.CallbackType.ON_BEFORE_CLOSE] = function(site) { + closeStart = osapi.container.util.getCurrentTimeMs(); + }; + listeners[osapi.container.CallbackType.ON_CLOSED] = function(site) { + log('It took ' + (osapi.container.util.getCurrentTimeMs() - closeStart) + + ' ms to close the gadget in the site with id ' + site.getId()); + }; + listeners[osapi.container.CallbackType.ON_BEFORE_RENDER] = function(gadgetUrl) { + renderStart = osapi.container.util.getCurrentTimeMs(); + }; + listeners[osapi.container.CallbackType.ON_RENDER] = function(gadgetUrl) { + log('It took ' + (osapi.container.util.getCurrentTimeMs() - renderStart) + + ' ms to render the gadget at the URL ' + gadgetUrl); + }; + return listeners; +} + Modified: shindig/trunk/content/samplecontainer/examples/commoncontainer/viewController.js URL: http://svn.apache.org/viewvc/shindig/trunk/content/samplecontainer/examples/commoncontainer/viewController.js?rev=1204704&r1=1204703&r2=1204704&view=diff ============================================================================== --- shindig/trunk/content/samplecontainer/examples/commoncontainer/viewController.js (original) +++ shindig/trunk/content/samplecontainer/examples/commoncontainer/viewController.js Mon Nov 21 21:06:26 2011 @@ -75,18 +75,21 @@ $(function() { //handle gadget collapse, expand, and remove gadget actions handleNavigateAction = function(portlet,gadgetSite,gadgetURL,actionId) { - //remove button was click, remove the portlet/gadget - if (actionId === 'remove') { - if (confirm('This gadget will be removed, ok?')) { - portlet.remove(); - delete siteToTitleMap[gadgetSite.getId()]; - } - }else if (actionId === 'expand') { - //navigate to currentView prior to colapse gadget - CommonContainer.navigateView(gadgetSite, gadgetURL, currentView); - }else if (actionId === 'collapse') { - CommonContainer.colapseGadget(gadgetSite); - } + //remove button was click, remove the portlet/gadget + if(typeof gadgetSite !== 'undefined'){ + if (actionId === 'remove') { + if (confirm('This gadget will be removed, ok?')) { + CommonContainer.closeGadget(gadgetSite); + portlet.remove(); + delete siteToTitleMap[gadgetSite.getId()]; + } + }else if (actionId === 'expand') { + //navigate to currentView prior to colapse gadget + CommonContainer.navigateView(gadgetSite, gadgetURL, currentView); + }else if (actionId === 'collapse') { + CommonContainer.colapseGadget(gadgetSite); + } + } }; //RPC handler for the set-title feature Modified: shindig/trunk/extras/src/main/javascript/features-extras/org.openajax.hub-2.0.5/iframe.js URL: http://svn.apache.org/viewvc/shindig/trunk/extras/src/main/javascript/features-extras/org.openajax.hub-2.0.5/iframe.js?rev=1204704&r1=1204703&r2=1204704&view=diff ============================================================================== --- shindig/trunk/extras/src/main/javascript/features-extras/org.openajax.hub-2.0.5/iframe.js (original) +++ shindig/trunk/extras/src/main/javascript/features-extras/org.openajax.hub-2.0.5/iframe.js Mon Nov 21 21:06:26 2011 @@ -388,10 +388,20 @@ OpenAjax.hub.IframeContainer = function( if ( internalID !== clientID ) { idText = "&oahId=" + internalID.substring( internalID.lastIndexOf('_') + 1 ); } - document.getElementById( internalID ).src = params.IframeContainer.uri + + + var iframe = document.getElementById( internalID ); + if(iframe.attachEvent) { + //Works for IE + iframe.attachEvent('onload', function(){ + window[params.IframeContainer.onGadgetLoad](); + }); + } else { + iframe.onload = function(){window[params.IframeContainer.onGadgetLoad]();}; + } + iframe.src = params.IframeContainer.uri + "#rpctoken=" + securityToken + tunnelText + idText; } - + // If the relay iframe used by RPC has not been loaded yet, then we won't have unload protection // at this point. Since we can't detect when the relay iframe has loaded, we use a two stage // connection process. First, the child sends a connection msg and the container sends an ack. Modified: shindig/trunk/features/src/main/javascript/features/actions/actions_container.js URL: http://svn.apache.org/viewvc/shindig/trunk/features/src/main/javascript/features/actions/actions_container.js?rev=1204704&r1=1204703&r2=1204704&view=diff ============================================================================== --- shindig/trunk/features/src/main/javascript/features/actions/actions_container.js (original) +++ shindig/trunk/features/src/main/javascript/features/actions/actions_container.js Mon Nov 21 21:06:26 2011 @@ -553,7 +553,7 @@ preloadCallback; actionsLifecycleCallback[osapi.container.CallbackType.ON_NAVIGATED] = navigatedCallback; - actionsLifecycleCallback[osapi.container.CallbackType.ON_CLOSED] = + actionsLifecycleCallback[osapi.container.CallbackType.ON_BEFORE_CLOSE] = closedCallback; actionsLifecycleCallback[osapi.container.CallbackType.ON_UNLOADED] = unloadedCallback; Modified: shindig/trunk/features/src/main/javascript/features/container.gadget/gadget_holder.js URL: http://svn.apache.org/viewvc/shindig/trunk/features/src/main/javascript/features/container.gadget/gadget_holder.js?rev=1204704&r1=1204703&r2=1204704&view=diff ============================================================================== --- shindig/trunk/features/src/main/javascript/features/container.gadget/gadget_holder.js (original) +++ shindig/trunk/features/src/main/javascript/features/container.gadget/gadget_holder.js Mon Nov 21 21:06:26 2011 @@ -25,9 +25,10 @@ /** * @param {number} siteId The id of site containing this holder. * @param {Element} el The element to render gadgets in. + * @param {string} onGadgetLoad The name of the on load function * @constructor */ -osapi.container.GadgetHolder = function(siteId, el) { +osapi.container.GadgetHolder = function(siteId, el, onGadgetLoad) { /** * Unique numeric gadget ID. * @type {number} @@ -79,6 +80,13 @@ osapi.container.GadgetHolder = function( */ this.securityToken_ = null; + /** + * On load function for gadget iFrames. + * @type {string} + * @private + */ + this.onGadgetLoad_ = onGadgetLoad; + this.onConstructed(); }; @@ -259,7 +267,8 @@ osapi.container.GadgetHolder.prototype.d //tunnelURI: shindig.uri('/test1/gadgets/' + '../container/rpc_relay.html') // .resolve(shindig.uri(window.location.href)), tunnelURI: shindig.uri(this.relayPath_).resolve(shindig.uri(window.location.href)), - iframeAttrs: iframeParams + iframeAttrs: iframeParams, + onGadgetLoad: this.onGadgetLoad_ } } ); @@ -304,7 +313,7 @@ osapi.container.GadgetHolder.prototype.g 'height': this.renderParams_[osapi.container.RenderParam.HEIGHT], 'width': this.renderParams_[osapi.container.RenderParam.WIDTH] }; - + this.addOnLoad_(iframeParams); return osapi.container.util.createIframeHtml(iframeParams); }; @@ -372,6 +381,17 @@ osapi.container.GadgetHolder.prototype.u } }; +/** + * Adds an onload attribute if a callback is available. + * @param {Object} iframeParams The iFrames parameters. + * @private + */ +osapi.container.GadgetHolder.prototype.addOnLoad_ = function(iframeParams) { + iframeParams['onload'] = 'window.' + this.onGadgetLoad_ + + "('" + this.getUrl() + "');"; + +}; + function init(config) { if (config['container']) { var rpath = config['container']['relayPath']; Modified: shindig/trunk/features/src/main/javascript/features/container.gadget/gadget_site.js URL: http://svn.apache.org/viewvc/shindig/trunk/features/src/main/javascript/features/container.gadget/gadget_site.js?rev=1204704&r1=1204703&r2=1204704&view=diff ============================================================================== --- shindig/trunk/features/src/main/javascript/features/container.gadget/gadget_site.js (original) +++ shindig/trunk/features/src/main/javascript/features/container.gadget/gadget_site.js Mon Nov 21 21:06:26 2011 @@ -64,6 +64,12 @@ osapi.container.GadgetSite = function(ar this.loadingGadgetEl_ = args['bufferEl']; /** + * @type {string} + * @private + */ + this.gadgetOnLoad_ = args['gadgetOnLoad'] + + /** * Unique ID of this site. Uses the ID of the gadgetEl, if set, or an auto-generated number. * @type {string} * @private @@ -210,7 +216,8 @@ osapi.container.GadgetSite.prototype.nav var message = ['Failed to navigate for gadget ', gadgetUrl, '.'].join(''); osapi.container.util.warn(message); } else { - self.container_.applyLifecycleCallbacks_(osapi.container.CallbackType.ON_RENDER, gadgetInfo); + self.container_.applyLifecycleCallbacks_(osapi.container.CallbackType.ON_BEFORE_RENDER, + gadgetInfo); self.render(gadgetInfo, viewParams, renderParams); } @@ -311,7 +318,8 @@ osapi.container.GadgetSite.prototype.ren // Load into the double-buffer if there is one. var el = this.loadingGadgetEl_ || this.currentGadgetEl_; - this.loadingGadgetHolder_ = new osapi.container.GadgetHolder(this.id_, el); + this.loadingGadgetHolder_ = new osapi.container.GadgetHolder(this.id_, el, + this.gadgetOnLoad_); var localRenderParams = {}; for (var key in renderParams) { Modified: shindig/trunk/features/src/main/javascript/features/container.util/constant.js URL: http://svn.apache.org/viewvc/shindig/trunk/features/src/main/javascript/features/container.util/constant.js?rev=1204704&r1=1204703&r2=1204704&view=diff ============================================================================== --- shindig/trunk/features/src/main/javascript/features/container.util/constant.js (original) +++ shindig/trunk/features/src/main/javascript/features/container.util/constant.js Mon Nov 21 21:06:26 2011 @@ -146,9 +146,36 @@ osapi.container.ViewParam = { * @enum {string} */ osapi.container.CallbackType = { + /** Called before a gadget(s) is preloaded. */ + ON_BEFORE_PRELOAD: 'onBeforePreload', + + /** Called after a gadget(s) has finished preloading. */ ON_PRELOADED: 'onPreloaded', + + /** Called before navigate is called. */ + ON_BEFORE_NAVIGATE: 'onBeforeNavigate', + + /** Called after navigation has completed. */ ON_NAVIGATED: 'onNavigated', + + /** Called before a gadget is closed. */ + ON_BEFORE_CLOSE: 'onBeforeClose', + + /** Called after a gadget has been closed. */ ON_CLOSED: 'onClosed', + + /** Called before a gadget has been unloaded. */ + ON_BEFORE_UNLOAD: 'onBeforeUnload', + + /** Called after a gadget has been unloaded. */ ON_UNLOADED: 'onUnloaded', - ON_RENDER: 'onRender' + + /** Called before render is called. */ + ON_BEFORE_RENDER: 'onBeforeRender', + + /** Called after a gadget has rendered. */ + ON_RENDER: 'onRender', + + /** Name of the global function all gadgets will call when they are loaded. */ + GADGET_ON_LOAD: '__gadgetOnLoad' }; Modified: shindig/trunk/features/src/main/javascript/features/container/container.js URL: http://svn.apache.org/viewvc/shindig/trunk/features/src/main/javascript/features/container/container.js?rev=1204704&r1=1204703&r2=1204704&view=diff ============================================================================== --- shindig/trunk/features/src/main/javascript/features/container/container.js (original) +++ shindig/trunk/features/src/main/javascript/features/container/container.js Mon Nov 21 21:06:26 2011 @@ -143,6 +143,11 @@ osapi.container.Container = function(opt */ this.tokenRefreshTimer_ = null; + var self = this; + window[osapi.container.CallbackType.GADGET_ON_LOAD] = function(gadgetUrl){ + self.applyLifecycleCallbacks_(osapi.container.CallbackType.ON_RENDER, gadgetUrl); + }; + this.initializeMixins_(); this.setupRpcArbitrator_(config); @@ -169,7 +174,8 @@ osapi.container.Container.prototype.newG 'service' : this.service_, 'navigateCallback' : this.navigateCallback_, 'gadgetEl' : gadgetEl, - 'bufferEl' : bufferEl + 'bufferEl' : bufferEl, + 'gadgetOnLoad' : osapi.container.CallbackType.GADGET_ON_LOAD }); this.sites_[site.getId()] = site; return site; @@ -212,7 +218,8 @@ osapi.container.Container.prototype.navi selfSite = site, finishNavigate = function(preferences) { renderParams[RenderParam.USER_PREFS] = preferences; - + self.applyLifecycleCallbacks_(osapi.container.CallbackType.ON_BEFORE_NAVIGATE, + gadgetUrl); // TODO: Lifecycle, add ability for current gadget to cancel nav. site.navigateTo(gadgetUrl, viewParams, renderParams, function(gadgetInfo) { // TODO: Navigate to error screen on primary gadget load failure @@ -247,8 +254,9 @@ osapi.container.Container.prototype.navi */ osapi.container.Container.prototype.closeGadget = function(site) { var id = site.getId(); - this.applyLifecycleCallbacks_(osapi.container.CallbackType.ON_CLOSED, site); + this.applyLifecycleCallbacks_(osapi.container.CallbackType.ON_BEFORE_CLOSE, site); site.close(); + this.applyLifecycleCallbacks_(osapi.container.CallbackType.ON_CLOSED, site); delete this.sites_[id]; this.unscheduleRefreshTokens_(); }; @@ -305,6 +313,7 @@ osapi.container.Container.prototype.prel var self = this; this.refreshService_(); + this.applyLifecycleCallbacks_(osapi.container.CallbackType.ON_BEFORE_PRELOAD, gadgetUrls); this.service_.getGadgetMetadata(request, function(response) { self.addPreloadGadgets_(response); self.applyLifecycleCallbacks_(osapi.container.CallbackType.ON_PRELOADED, @@ -330,6 +339,8 @@ osapi.container.Container.prototype.unlo osapi.container.Container.prototype.unloadGadgets = function(gadgetUrls) { for (var i = 0; i < gadgetUrls.length; i++) { var url = gadgetUrls[i]; + this.applyLifecycleCallbacks_(osapi.container.CallbackType.ON_BEFORE_UNLOAD, + url); delete this.preloadedGadgetUrls_[url]; this.applyLifecycleCallbacks_(osapi.container.CallbackType.ON_UNLOADED, url); Modified: shindig/trunk/features/src/main/javascript/features/opensearch/opensearch.js URL: http://svn.apache.org/viewvc/shindig/trunk/features/src/main/javascript/features/opensearch/opensearch.js?rev=1204704&r1=1204703&r2=1204704&view=diff ============================================================================== --- shindig/trunk/features/src/main/javascript/features/opensearch/opensearch.js (original) +++ shindig/trunk/features/src/main/javascript/features/opensearch/opensearch.js Mon Nov 21 21:06:26 2011 @@ -231,7 +231,7 @@ var containerCallback = new Object(); containerCallback[osapi.container.CallbackType.ON_PRELOADED] = preloaded; - containerCallback[osapi.container.CallbackType.ON_CLOSED] = + containerCallback[osapi.container.CallbackType.ON_BEFORE_CLOSE] = closed; containerCallback[osapi.container.CallbackType.ON_NAVIGATED] = navigated; Modified: shindig/trunk/features/src/main/javascript/features/shared-script-frame/shared-script-frame-container.js URL: http://svn.apache.org/viewvc/shindig/trunk/features/src/main/javascript/features/shared-script-frame/shared-script-frame-container.js?rev=1204704&r1=1204703&r2=1204704&view=diff ============================================================================== --- shindig/trunk/features/src/main/javascript/features/shared-script-frame/shared-script-frame-container.js (original) +++ shindig/trunk/features/src/main/javascript/features/shared-script-frame/shared-script-frame-container.js Mon Nov 21 21:06:26 2011 @@ -122,12 +122,12 @@ osapi.container.Container.addMixin('Shar var lifeCycleHandlers = {}; /** - * Respond to the ON_RENDER event by creating a script frame for the + * Respond to the ON_BEFORE_RENDER event by creating a script frame for the * loading gadget, but only if we need one. * * @param {!Object} metadata The gadget metadata */ - lifeCycleHandlers[osapi.container.CallbackType.ON_RENDER] = function(metadata) { + lifeCycleHandlers[osapi.container.CallbackType.ON_BEFORE_RENDER] = function(metadata) { var url = metadata.url; try { var feature = metadata.modulePrefs.features['shared-script-frame']; Modified: shindig/trunk/features/src/test/javascript/features/container/gadget_holder_test.js URL: http://svn.apache.org/viewvc/shindig/trunk/features/src/test/javascript/features/container/gadget_holder_test.js?rev=1204704&r1=1204703&r2=1204704&view=diff ============================================================================== --- shindig/trunk/features/src/test/javascript/features/container/gadget_holder_test.js (original) +++ shindig/trunk/features/src/test/javascript/features/container/gadget_holder_test.js Mon Nov 21 21:06:26 2011 @@ -52,16 +52,18 @@ GadgetHolderTest.prototype.testNew = fun GadgetHolderTest.prototype.testRenderWithoutRenderParams = function() { var element = {}; var gadgetInfo = { - 'iframeUrl' : 'http://shindig/gadgets/ifr?url=gadget.xml' + 'iframeUrl' : 'http://shindig/gadgets/ifr?url=gadget.xml', + 'url' : 'gadget.xml' }; this.setupGadgetsRpcSetupReceiver(); - var holder = new osapi.container.GadgetHolder(123, element); + var holder = new osapi.container.GadgetHolder(123, element, '__gadgetOnLoad'); holder.render(gadgetInfo, {}, {}); this.assertEquals('<iframe' + ' marginwidth="0"' + ' hspace="0"' + ' frameborder="0"' + ' scrolling="no"' + + ' onload="window.__gadgetOnLoad(\'gadget.xml\');"' + ' marginheight="0"' + ' vspace="0"' + ' id="__gadget_123"' + @@ -75,7 +77,8 @@ GadgetHolderTest.prototype.testRenderWit GadgetHolderTest.prototype.testRenderWithRenderRequests = function() { var element = {}; var gadgetInfo = { - 'iframeUrl' : 'http://shindig/gadgets/ifr?url=gadget.xml' + 'iframeUrl' : 'http://shindig/gadgets/ifr?url=gadget.xml', + 'url' : 'gadget.xml' }; var renderParams = { 'cajole' : true, @@ -87,7 +90,7 @@ GadgetHolderTest.prototype.testRenderWit 'width' : 222 }; this.setupGadgetsRpcSetupReceiver(); - var holder = new osapi.container.GadgetHolder(123, element); + var holder = new osapi.container.GadgetHolder(123, element, '__gadgetOnLoad'); holder.render(gadgetInfo, {}, renderParams); this.assertEquals('<iframe' + ' marginwidth="0"' + @@ -95,6 +98,7 @@ GadgetHolderTest.prototype.testRenderWit ' height="111"' + ' frameborder="0"' + ' scrolling="no"' + + ' onload="window.__gadgetOnLoad(\'gadget.xml\');"' + ' class="xyz"' + ' marginheight="0"' + ' vspace="0"' +