在bootjack

时间:2015-05-18 08:49:55

标签: twitter-bootstrap dart bootjack

我正在使用twitter bootstrap的CSS来创建standard bootstrap navbar,然后调用Dropdown.use();,这使导航栏自动运行。

bootstrap navbar with bootjack dropdown

当我重新调整页面大小或在移动设备上查看时,导航栏会显示此菜单按钮,当您单击该按钮时,该按钮不会执行任何操作。

bootstrap navbar in mobile mode

如何使用dquery / bootjack连接此菜单按钮以显示此示例中显示的菜单:

bootstrap responsive navbar example

(PS,喜欢bootjack,感谢所有参与其中的人!!!)

澄清,我不想包含jquery和bootstrap js来使它工作,我的整个dart应用程序包括400多个文件(图像,html,dart,less等)低于400kB并添加这些js库将使应用程序的大小爆炸。我只是在寻找bootstrap用于使菜单按钮工作的机制,以便我可以在dart / dquery / bootjack中重写它,或者如果已经有一个可以执行它的bootjack机制,如何使用它。

根据要求更新一些代码:

pubspec.yaml:

....
environment:
  sdk: '>=1.0.0 <2.0.0'
dependencies:
  bootjack_datepicker: any
  less_dart: any
  bootjack: any
  browser: any
  http: any
transformers:
- $dart2js:
    commandLineOptions: [--enable-experimental-mirrors]
- less_dart:
    entry_point: web/styles/main.less
    build_mode: dart

的index.html:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    ....
    <link rel="stylesheet" href="styles/main.css">
</head>
<body>

<nav class="navbar navbar-inverse navbar-static-top" role="navigation">
    <div class="container-fluid">
        <!-- Brand and toggle get grouped for better mobile display -->

        <div class="navbar-header">
            <button type="button" class="navbar-toggle" data-toggle="collapse"
                    data-target="#bs-example-navbar-collapse-1">
                <span class="sr-only">Toggle navigation</span> <span
                    class="icon-bar"></span> <span class="icon-bar"></span> <span
                    class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="#">My Application</a>
        </div>
        <!-- Collect the nav links, forms, and other content for toggling -->
        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
            <ul class="nav navbar-nav">


                <li>
                    <a class="dropdown-toggle" data-toggle="dropdown">Item<span class="caret"></span></a>
                    <ul class="dropdown-menu" role="menu">
                        <li><a href="#itemss-list">Items</a></li>
                        <li><a href="#foo-bar">Foo Bar</a></li>
                        <li class="divider"></li>
                        <li>
                            <a href="#item-create">
                                <span class="glyphicon glyphicon-plus"></span>
                                Create Item
                            </a>
                        </li>
                    </ul>
                </li>
        ...

    <script type="application/dart" src="main.dart"></script>
    <script data-pub-inline src="packages/browser/dart.js"></script>
</body>
</html>

main.less:

@import 'web/styles/bootstrap/bootstrap.less';
@import 'web/styles/bootjack-calendar/calendar.less';

@media screen {

  body {
    background: #FEFEFE;
  }

  ...

}

main.dart:

import 'dart:html';
import 'pages/pages.dart';
import 'dart:convert' show JSON;
import 'package:dquery/dquery.dart';
import 'package:bootjack/bootjack.dart';
import 'package:bootjack_datepicker/bootjack_datepicker.dart';

...

void main() {

    ...

    // enable bootjack functionality
    Transition.use();
    Calendar.use();
    Dropdown.use();
    Modal.use();

    ...

}

1 个答案:

答案 0 :(得分:1)

在查看工作导航栏上的课程,同时切换它几次后,我意识到这很简单 - 在课程中添加/输出会使导航栏在移动视图中弹出/输出。

ButtonElement navbarToggle = querySelector("button.navbar-toggle");
navbarToggle.onClick.listen((e){
    DivElement menu = querySelector("div.navbar-collapse");
    if (menu.classes.contains("in")){
        menu.classes
            ..remove("in")
            ..add("out");
    } else if (menu.classes.contains("out")){
        menu.classes
            ..remove("out")
            ..add("in");
    }
});