On Feb 7, 2008 5:47 PM, Paul Lindner <[EMAIL PROTECTED]> wrote:

> Hi,
>
> I notice that the packaged gadgets.js file doesn't have support for
> passing the view, nocache, country or language parameters on the
> iframe URL.
>
> I also added a convenience method to the StaticLayoutManager to append
> classes to the list, plus added a way to specify data you want to pass
> via the hash.
>
>
>
> Index: javascript/container/gadgets.js
> ===================================================================
> --- javascript/container/gadgets.js     (revision 619718)
> +++ javascript/container/gadgets.js     (working copy)
> @@ -275,7 +275,7 @@
>  };
>
>  /**
> - * Gets the HTML element that is the chrome of a gadget into which the
> cotnent
> + * Gets the HTML element that is the chrome of a gadget into which the
> content
>  * of the gadget can be rendered.
>  * @param {Object} gadget Gadget instance
>  * @return {Object} HTML element that is the chrome for the given gadget
> @@ -306,6 +306,18 @@
>   this.gadgetChromeIds_ = gadgetChromeIds;
>  };
>
> +/**
> + * Add a chromeid to the list of applications
> + */
> +gadgets.StaticLayoutManager.prototype.addGadgetChromeId =
> +    function(gadgetChromeId) {
> +    if (!this.gadgetChromeIds_) {
> +        this.gadgetChromeIds_ = new Array(gadgetChromeId);


Use an array literal here instead. This isn't just a style issue -- if
gadgetChromeId is a number you'll actually get an empty array of
gadgetChromeId elements instead of what you expect.


>
> +    } else {
> +       this.gadgetChromeIds_.push(gadgetChromeId);
> +    }
> +};
> +
>  gadgets.StaticLayoutManager.prototype.getGadgetChrome = function(gadget)
> {
>   var chromeId = this.gadgetChromeIds_[gadget.id];
>   return chromeId ? document.getElementById(chromeId) : null;
> @@ -347,7 +359,7 @@
>  // Gadget
>
>  /**
> - * Creates a new instance of gadget.  Optoinal parameters are set as
> instance
> + * Creates a new instance of gadget.  Optional parameters are set as
> instance
>  * variables.
>  * @constructor
>  * @param {Object} params Parameters to set on gadget.  Common parameters:
> @@ -355,10 +367,10 @@
>  *    "private": Whether gadget spec is accessible only privately, which
> means
>  *        browser can load it but not gadget server
>  *    "spec": Gadget Specification in XML
> + *    "hashData": data to be passed on the # of the iframe URL


hashData is fairly complex now (st and  view-params are both passed here).
It would probably be a good idea to set these fields separately.


>  */
>  gadgets.Gadget = function(params) {
>   this.userPrefs_ = {};
> -
>   if (params) {
>     for (var name in params) {


I can't tell if this is yours or not; there should be a hasOwnProperty test
here.


>       this[name] = params[name];
> @@ -481,10 +493,12 @@
>
>  gadgets.IfrGadget.prototype.getMainContent = function(continuation) {
>   var iframeId = this.getIframeId();
> +  var heightAttribute = (this.Height) ? ' h="' + this.Height + '" ' : '';
> +
>   continuation('<div class="' + this.cssClassGadgetContent + '"><iframe
> id="' +
>       iframeId + '" name="' + iframeId + '" class="' + this.cssClassGadget+
> -      '" src="' + this.getIframeUrl() +
> -      '" frameborder="0" scrolling="no"></iframe></div>');
> +      '" src="' + this.getIframeUrl() + heightAttribute +
> +      '" width="100%"  frameborder="0" scrolling="no"></iframe></div>');
>  };
>
>  gadgets.IfrGadget.prototype.getIframeId = function() {
> @@ -497,9 +511,12 @@
>
>  gadgets.IfrGadget.prototype.getIframeUrl = function() {
>   return this.serverBase_ + 'ifr?url=' +
> -      encodeURIComponent(this.specUrl) + '&synd=' + this.SYND + '&mid=' +
> +      encodeURIComponent(this.specUrl) + '&nocache=' +
> gadgets.container.nocache_ + '&synd=' + this.SYND + '&mid=' +
>       this.id + '&parent=' + encodeURIComponent(
> gadgets.container.parentUrl_) +
> -      '&ogc=' + document.location.host + this.getUserPrefsParams();
> +      '&ogc=' + document.location.host + this.getUserPrefsParams() +
> +      '&country=' + gadgets.container.country_ + '&lang=' +
> gadgets.container.language_ +
> +      '&view=' + gadgets.container.view_ +
> +      '#' + this.hashData;
>  };
>
>  gadgets.IfrGadget.prototype.getUserPrefsParams = function() {
> @@ -536,7 +553,7 @@
>
>     var script = document.createElement('script');
>     script.src = 'http://gmodules.com/ig/gadgetsettings?url=' +
> this.specUrl +
> -        '&mid=' + this.id + '&output=js' + this.getUserPrefsParams();
> +        '&mid=' + this.id + '&output=js' + this.getUserPrefsParams() +
> '#' + this.hashData;
>     document.body.appendChild(script);
>   }
>  };
> @@ -600,6 +617,10 @@
>  gadgets.Container = function() {
>   this.gadgets_ = {};
>   this.parentUrl_ = '';
> +  this.country_  = 'US';
> +  this.language_  = 'en';
> +  this.view_ = '';
> +  this.nocache_ = 1;
>  };
>
>  gadgets.Container.inherits(gadgets.Extensible);
> @@ -626,6 +647,22 @@
>   this.parentUrl_ = url;
>  };
>
> +gadgets.Container.prototype.setCountry = function(country) {
> +  this.country_ = country;
> +};
> +
> +gadgets.Container.prototype.setNoCache = function(nocache) {
> +  this.nocache_ = nocache;
> +}
> +
> +gadgets.Container.prototype.setLanguage = function(language) {
> +  this.language_ = language;
> +};
> +
> +gadgets.Container.prototype.setView = function(view) {
> +    this.view_ = view;
> +};
> +
>  gadgets.Container.prototype.getGadgetKey_ = function(instanceId) {
>   return 'gadget_' + instanceId;
>  };
>
> --
> Paul Lindner
> hi5 Architect
> [EMAIL PROTECTED]
>

Reply via email to