zoukankan      html  css  js  c++  java
  • Opensocial使用OpenSocial开发IGoogle小工具:代码结构

    整体来说,小工具就是XML文件,外加一些其他的引用文件。比如说图片,javascript文件,或者是其他的XML文件等等。

    先不说复杂的代码,先看Hello World程序:

    <?xml version="1.0" encoding="UTF-8"?>
    <Module>
        <ModulePrefs title="List Friends Example">    <!--小工具标题-->
            <Require feature="opensocial-0.7"/>        <!--导入 OpenSocial Library-->
        </ModulePrefs>
        <Content type="html">    <!--内容形式为HTML,可能还有其他的形式-->
            <![CDATA[                 <!--包括小工具的详细内容:HTML,CSS,JavaScript,可以引用其他文件-->
                Hello, world!
            ]]>
        </Content>
    </Module>

    上面是最简单的代码,如果稍微复杂一点代码,使用和HTML差不多的方式来写:

    <?xml version="1.0" encoding="UTF-8" ?>
    <Module>
        <ModulePrefs title="List Friends Example">
            <Require feature="opensocial-0.7"/>
        </ModulePrefs>
        <Content type="html">

        <![CDATA[
        <!--引用外部的JavaScript的写法-->
        <script src="http://opensocial-resources.googlecode.com/svn/samples/tutorial/tags/api-0.7/gifts_1_friends.js"></script>

        <script type="text/javascript"> //JavaScript的写法

        /**
        * Request for friend information.
        */
        function getData() {
            var req = opensocial.newDataRequest();
            req.add(req.newFetchPersonRequest(opensocial.DataRequest.PersonId.VIEWER), 'viewer');
            req.add(req.newFetchPeopleRequest(opensocial.DataRequest.Group.VIEWER_FRIENDS), 'viewerFriends');
            req.send(onLoadFriends);
        };

        /**
        * Parses the response to the friend information request and generates
        * html to list the friends along with their display name.
        *
        * @param {Object} dataResponse Friend information that was requested.
        */
        function onLoadFriends(dataResponse) {
            var viewer = dataResponse.get('viewer').getData();
            var html = 'Friends of ' + viewer.getDisplayName();
            html += ':<br><ul>';
            var viewerFriends = dataResponse.get('viewerFriends').getData();
            viewerFriends.each(function(person) {
                html += '<li>' + person.getDisplayName() + '</li>';
            });
            html += '</ul>';
            document.getElementById('message').innerHTML = html;
        };

        gadgets.util.registerOnLoadHandler(getData);

        </script>
        <div id="message"> </div> <!--HTML的写法-->
        ]]>
        </Content>
    </Module>

    以上代码已经使用了OpenSocial的API了,接下来会做详细的介绍。

  • 相关阅读:
    apache 虚拟主机配置(根据不同的域名映射到不同网站)
    Tortoise SVN 使用笔记
    Apache 根据不同的端口 映射不同的站点
    jquery 获取当前元素的索引值
    修改ThinkPHP的验证码类
    NetBeans无法使用编码GBK安全地打开该文件
    在win2003下apache2.2无法加载php5apache2_4.dll
    我看软件工程
    PHP函数参数传递(相对于C++的值传递和引用传递)
    Notepad++ 使用正则表达式查找替换字符串
  • 原文地址:https://www.cnblogs.com/celery94/p/1348628.html
Copyright © 2011-2022 走看看