练习
Prev Chapter 10. 代码组织 Next

练习

创建Portlet模块

在你的浏览器中打开/exercises/portlets.html文件,使用/exercises/js/portlets.js文件,你的任务是使用模块模式编写一个portlet创建函数,就像下列代码那样工作:

var myPortlet = Portlet({
    title : 'Curry',
    source : 'data/html/curry.html',
    initialState : 'open' // 或'closed'
});

myPortlet.$element.appendTo('body');

每个Portlet应该是一个DIV,带有一个标题、一个内容区域、一个打开/关闭按钮、一个删除portlet的按钮和一个刷新portlet的按钮。Portlet函数返回的portlet应该具有下列公有API:

myPortlet.open(); // 强制打开状态
myPortlet.close(); // 强制关闭状态
myPortlet.toggle(); // 切换开/关状态
myPortlet.refresh(); // 刷新内容
myPortlet.destroy(); // 从页面中移除一个portlet
myPortlet.setSource('data/html/onions.html'); // 改变数据源

Copyright Rebecca Murphey, released under the Creative Commons Attribution-Share Alike 3.0 United States license.


Prev Up Next
管理依赖 Home Chapter 11. Custom Events