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了,接下来会做详细的介绍。

  • 相关阅读:
    原型链加强练习
    Javascript中的原型链,__proto__和prototype等问题总结
    HTTPS 到底加密了什么?
    PrismCDN 网络的架构解析,以及低延迟、低成本的奥秘
    取代 FlashP2P,H5P2P 将成为 WebP2P 主流
    低延时的P2P HLS直播技术实践
    深挖“窄带高清”的实现原理
    【省带宽、压成本专题】爱奇艺第一季度又烧了11个亿元,什么时候是个头?
    【省带宽、压成本专题】深入解析 H.265 编码模式,带你了解 Apple 全面推进 H.265 的原因
    让互联网更快,Server Push 特性及开启方式详解
  • 原文地址:https://www.cnblogs.com/celery94/p/1348628.html
Copyright © 2011-2022 走看看