Seajs demo
2014-03-11 00:25
405 查看
index.html
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <script src="seajs/sea.js"></script> </head> <body> <ul class="pills"> <li class="home-pill"><a>Home</a></li> <li class="about-pill"><a>About</a></li> <li class="contact-pill"><a>Contact</a></li> </ul> <div id="home-page" class="pages">Hi I'm the home page!</div> <div id="about-page" class="pages">Hi I'm the about page!</div> <div id="contact-page" class="pages">Hi I'm the contact page!</div> <script> seajs.config({ base: '../example-2', alias: { 'jquery': 'lib/jquery-latest.js', 'underscore': 'lib/underscore.js', 'backbone': 'lib/backbone.js', 'AppRoute': 'router/AppRoute.js', 'AppView': 'view/AppView.js' } }); seajs.use(['AppRoute', 'AppView'], function (AppRoute, AppView) { new AppView(); }); </script> </body> </html>
define(['jquery', 'underscore', 'backbone'], function (require, exports, module) { var ApplicationRoute = Backbone.Router.extend({ routes: { "": "home", "home": "home", "about": "about", "contact": "contact" }, deselectPills: function(){ $('ul.pills li').removeClass('active'); }, selectPill: function(pill){ this.deselectPills(); $(pill).addClass('active'); }, hidePages: function(){ $('div.pages').hide(); }, showPage: function(page){ this.hidePages(); $(page).show(); }, home: function() { this.showPage('div#home-page'); this.selectPill('li.home-pill'); }, about: function() { this.showPage('div#about-page'); this.selectPill('li.about-pill'); }, contact: function() { this.showPage('div#contact-page'); this.selectPill('li.contact-pill'); } }); module.exports = ApplicationRoute; });
define('AppView', ['jquery', 'underscore', 'backbone', 'AppRoute'], function (require, exports, module) { var ApplicationRoute = require('AppRoute'); var AppView = Backbone.View.extend({ el: $('body'), events: { 'click ul.pills li.home-pill a': 'displayHome', 'click ul.pills li.about-pill a': 'displayAbout', 'click ul.pills li.contact-pill a': 'displayContact' }, initialize: function(){ this.router = new ApplicationRoute(); Backbone.history.start(); }, displayHome: function(){ this.router.navigate("home", true); }, displayAbout: function(){ this.router.navigate("about", true); }, displayContact: function(){ this.router.navigate("contact", true); } }); module.exports = AppView; })
相关文章推荐
- 上传漏洞科普[2]-js验证
- 如何用javascript获取文本框,下拉框,单选框的对应值或者将值赋给它们?
- ie浏览器使用js导出网页到excel并打印
- js 针对html DOM元素操作等经验累积
- JS图片无缝、平滑滚动代码
- js解析json读取List中的实体对象示例
- Javascript加载速度慢的解决方案
- JavaScript中奇葩的假值示例应用
- javascript parseUrl函数(来自国外的获取网址url参数)
- JSP的三大指令 七大动作 九大对象
- javascript 注意点收集一
- js中判断两个变量是否相等的问题
- JSP 返回上一页的几种方法 【转自睡不醒的猫的博客】
- js 解析json 读取List中的实体对象
- 2.js基础
- js模版引擎handlebars.js实用教程——each嵌套
- js模版引擎handlebars.js实用教程——循环中使用索引
- JSON教程之简介
- YUI Compressor 在线压缩 JavaScript/CSS
- 【js学习笔记-096】----拖放事件