Gadgets.views (v0.9)
From VZ Developer Wiki
(Redirected from Gadgets.views (v0.8))
This documentation is not completed yet and will be extended by more examples in future.
gadgets.views
Provides operations for dealing with views. See also: gadgets.views.View
Methods
gadgets.views.bind
<static> String gadgets.views.bind(urlTemplate, environment)
- Parameters
Name Type Description urlTemplate String A url template for a container view environment Array A set of named variables of type string (for example, [OWNER, PATH, PARAMS, NAME]).
- Returns
Type Description String A URL string
- Description
Binds a URL template with variables in the passed environment to produce a URL string.
See also: View.getUrlTemplate()
gadgets.views.getCurrentView
<static> gadgets.views.View gadgets.views.getCurrentView()
- Returns
Type Description gadgets.views.View The current view
- Description
Returns the current view.
gadgets.views.getParams
<static> Map.<String|String> gadgets.views.getParams()
- Returns
Type Description Map.<String|String> The parameter map
- Description
Returns the parameters passed into this gadget for this view. Does not include all URL parameters, only the ones passed into gadgets.views.requestNavigateTo.
gadgets.views.getSupportedViews
<static> Map<gadgets.views.ViewType | String|gadgets.views.View> gadgets.views.getSupportedViews()
- Returns
Type Description Map<gadgets.views.ViewType | String|gadgets.views.View> All supported views, keyed by their name attribute.
- Description
Returns a map of all the supported views. Keys each gadgets.view.View by its name. This function only returns the primary views and does not return any secondary views. Example: if the markup indicates a set of views named Canvas.About, Profile.About, Home.About, Canvas.Help the returned views will only be Canvas, Profile, Home.
<static> gadgets.views.requestNavigateTo(view, opt_params, opt_ownerId)
- Parameters
Name Type Description view String | gadgets.views.View {string} view If set to a string, the name of the view to navigate to. If set to a View, the View object to navigate to. Passing a View has been deprecated. opt_params Map.<String|String> {string} opt_params If the value is an object, it represents parameters to pass to the gadget after it has been navigated to on the surface. If the view navigated to contains an href and opt_params is a string, the value in opt_params is treated as a relative path that must be resolved relative to the href of the referenced view according to RFC 3986. If opt_params is a string all query parameters including query parameters encoded in a fragment are available in the receiving view using gadgets.views.getParams() opt_ownerId String The ID of the owner of the page to navigate to; defaults to the current owner opt_view_params Map.<String|String> Optional object with view params (width and height) for the designated view. Is only used when navigating to the popup view to adjust initial width and height of the popup window. Note that the initial height of the gadget will still be 400px, so you may call the adjustHeight method. (Example: {width: 800, height: 700}) - Description
Attempts to navigate to this gadget in a different view. If the container supports parameter passing it will pass the optional parameters along to the gadget in the new view. This also allows for navigation to named views on the current surface. Views are composed of names that are [Surface](.[Secondary])?. The canonical Surface names are Canvas, Profile, Home. The Secondary names are user defined. When navigating from [Surface].valueX to [Surface].valueY, the container can stay on the same Surface but will show the appropriate <Content> sections whose View is [Surface].valueY. When navigating from SurfaceA.[Secondary] to SurfaceB.[Secondary], the container will switch to the SurfaceB surface and show the appropriate <Content> sections whose View is SurfaceB.[Secondary].In no cases must the .[Secondary] item ever be declared.gadgets.views.View
Base interface for all view objects.
gadgets.views.ViewType
Used by gadgets.views.Views.
gadgets.views.ViewType.GROUP
- A view where the gadget is displayed in a small area usually on an overview page of a VZ platform group. Typically the viewer is not the same as the owner. This field may be used interchangeably with the string 'GROUP'.
gadgets.views.ViewType.GROUPINSTALLATION
gadgets.views.ViewType.GROUPCANVAS
gadgets.views.ViewType.GROUPCANVASINSTALLATION
gadgets.views.ViewType.PROFILE
- A view where the gadget is displayed in a small area usually on a page with other gadgets. The viewer is not always the same as the owner. This field may be used interchangeably with the string 'PROFILE'.
gadgets.views.ViewType.CANVAS
- A view where the gadget is displayed in a very large mode. It is typically the main content on the page. The viewer is not always the same as the owner. This field may be used interchangeably with the string 'CANVAS'.
gadgets.views.ViewType.POPUP
- A view where the gadget is displayed in a very large mode in a popup. It is the main content on the page. The viewer is not always the same as the owner. This field may be used interchangeably with the string 'POPUP'.
gadgets.views.ViewType.POPUPINSTALLATION
gadgets.views.ViewType.PREVIEW
- A demo view of the gadget. In this view the owner and viewer are not known. This field may be used interchangeably with the string 'PREVIEW'.
gadgets.views.ViewType.INTEGRATION
- In this view the gadget is integrated fullsize into the container page without any additional meta elements like title bar, install button etc. This field may be used interchangeably with the string 'INTEGRATION'.
gadgets.views.ViewType.INTEGRATIONINSTALLATION
gadgets.views.ViewType.NOBLEPROFILE
- A view where the gadget is displayed in a small area on a noble profile page with other gadgets. The viewer is typically not always same as the owner. This field may be used interchangeably with the string 'NOBLEPROFILE'.
gadgets.views.ViewType.NOBLEPROFILECANVAS
gadgets.views.ViewType.EMBED
gadgets.views.ViewType.EMBEDPROVIDER
Future supported view types
gadgets.views.ViewType.HOME
- A view where the gadget is displayed in a small area on the startpage of a user (maybe with other gadgets). The viewer is always the same as the owner. This field may be used interchangeably with the string 'HOME'.
Examples
See Gadgets_Views_Tech for a technical overview of the different views available.
Switching between views:
<?xml version="1.0" encoding="UTF-8"?> <Module> <ModulePrefs title="View test" > <Require feature="opensocial-0.8" /> <Require feature="views" /> </ModulePrefs> <Content type="html" view="profile,group"> <![CDATA[ <a href="javascript:gadgets.views.requestNavigateTo('canvas');">go to canvas view</a> ]]> </Content> <Content type="html" view="canvas"> <![CDATA[ <a href="javascript:gadgets.views.requestNavigateTo('profile');">go to profile view</a> ]]> </Content> </Module>
Navigating to popup view:
gadgets.views.requestNavigateTo('popup', null, null, {width: 800, height: 700});
Adding and retrieving Parameters:
var params = {'param1': 'value1', 'param2': 'value2'}; gadgets.views.requestNavigateTo('canvas', params);
var params = gadgets.views.getParams();
This tutorial will give you more examples or information on these features:
Lesson 03: Views and Navigation
OpenSocial (v0.9) gadgets.views
