zoukankan      html  css  js  c++  java
  • Seajs demo

    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;
    })
  • 相关阅读:
    asp.net2.0 Theme and Skin
    Microsoft Exchange Server 2010 介绍
    Visual Studio 2010 Team System 动手实验室
    WCF中的消息契约
    Windows Workflow Foundation实验01——Windows Workflow Foundation 快速入门(练习二)
    C#中Brush、Color、String相互转换
    VS自动生成有参构造函数并自动依赖注入插件
    C#集合已修改:可能无法执行枚举操作
    Docker安装后启动不了,报“参考的对象类型不支持尝试的操作”
    windows下安装Docker超全图文教程
  • 原文地址:https://www.cnblogs.com/wangwenfei/p/seajs.html
Copyright © 2011-2022 走看看