Browse Source

Add docs locale.

zhixin 11 years ago
parent
commit
e193e23459
3 changed files with 73 additions and 46 deletions
  1. 15 3
      docs/common.js
  2. 57 42
      docs/docs.js
  3. 1 1
      docs/documentation.html

+ 15 - 3
docs/common.js

@@ -1,6 +1,16 @@
 $(function() {
     'use strict';
 
+    window.getLocale = function () {
+        if (!localStorage) {
+            return 'en';
+        }
+        if (location.search === '?locale=zh') {
+            localStorage.locale = 'zh';
+        }
+        return localStorage.locale;
+    };
+
     function main() {
         $(window).scroll(showGotoTop);
         $(window).resize(showGotoTop);
@@ -9,9 +19,11 @@ $(function() {
             document.documentElement.scrollTop = 0;
             return false;
         });
-        $('[data-zh]').each(function () {
-            $(this).html($(this).data('zh'));
-        });
+        if (getLocale() === 'zh') {
+            $('[data-zh]').each(function () {
+                $(this).html($(this).data('zh'));
+            });
+        }
         initScrollspy();
         showGotoTop();
         showBaiduShare();

+ 57 - 42
docs/docs.js

@@ -10,29 +10,64 @@ $(function () {
 
         $('#table, #column, #event, #method, #localization').bootstrapTable('destroy');
 
+        var tableColumns = [
+            {field: 'name', title: 'Name', sortable: true},
+            {field: 'name', title: '名称', sortable: true, visible: false},
+            {field: 'attribute', title: 'Attribute'},
+            {field: 'attribute', title: '属性', visible: false},
+            {field: 'type', title: 'Type'},
+            {field: 'type', title: '类型', visible: false},
+            {field: 'description', title: 'Description', align: 'left'},
+            {field: 'description_zh', title: '描述', align: 'left', visible: false},
+            {field: 'default', title: 'Default', align: 'left'},
+            {field: 'default', title: '默认', align: 'left', visible: false},
+            {field: 'example', title: '', valign: 'middle', formatter: function (value) {
+                if (!value) {
+                    return '-';
+                }
+                return [
+                    '<a title="Example" href="examples.html#' + value + '">',
+                    '<i class="glyphicon glyphicon-eye-open"></i>',
+                    '</a>'].join('');
+            }}
+        ];
+
+        var columnColumns = [
+            {field: 'name', title: 'Name', width: 60, sortable: true},
+            {field: 'name', title: '名称', width: 60, sortable: true, visible: false},
+            {field: 'attribute', title: 'Attribute'},
+            {field: 'attribute', title: '属性', visible: false},
+            {field: 'type', title: 'Type', width: 60},
+            {field: 'type', title: '类型', width: 60, visible: false},
+            {field: 'description', title: 'Description', align: 'left', width: 400},
+            {field: 'description_zh', title: '描述', align: 'left', width: 400, visible: false},
+            {field: 'default', title: 'Default', align: 'left', width: 180},
+            {field: 'default', title: '默认', align: 'left', width: 180, visible: false},
+            {field: 'example', title: '', formatter: function (value) {
+                if (!value) {
+                    return '-';
+                }
+                return [
+                    '<a title="Example" href="examples.html#' + value + '">',
+                    '<i class="glyphicon glyphicon-eye-open"></i>',
+                    '</a>'].join('');
+            }}
+        ];
+
+        if (getLocale() === 'zh') {
+            $.each([tableColumns, columnColumns], function (i, columns) {
+                $.each(columns, function (j, row) {
+                    if (row.field === 'example') {
+                        return;
+                    }
+                    row.visible = typeof row.visible !== 'undefined';
+                });
+            });
+        }
+
         $('#table').bootstrapTable({
             cardView: cardView,
-            columns: [
-                {field: 'name', title: 'Name', sortable: true},
-                {field: 'name', title: '名称', sortable: true, visible: false},
-                {field: 'attribute', title: 'Attribute'},
-                {field: 'attribute', title: '属性', visible: false},
-                {field: 'type', title: 'Type'},
-                {field: 'type', title: '类型', visible: false},
-                {field: 'description', title: 'Description', align: 'left'},
-                {field: 'description_zh', title: '描述', align: 'left', visible: false},
-                {field: 'default', title: 'Default', align: 'left'},
-                {field: 'default', title: '默认', align: 'left', visible: false},
-                {field: 'example', title: '', valign: 'middle', formatter: function (value) {
-                    if (!value) {
-                        return '-';
-                    }
-                    return [
-                        '<a title="Example" href="examples.html#' + value + '">',
-                        '<i class="glyphicon glyphicon-eye-open"></i>',
-                        '</a>'].join('');
-                }}
-            ],
+            columns: tableColumns,
             data: [
                 {
                     name: '-',
@@ -353,27 +388,7 @@ $(function () {
         });
         $('#column').bootstrapTable({
             cardView: cardView,
-            columns: [
-                {field: 'name', title: 'Name', width: 60, sortable: true},
-                {field: 'name', title: '名称', width: 60, sortable: true, visible: false},
-                {field: 'attribute', title: 'Attribute'},
-                {field: 'attribute', title: '属性', visible: false},
-                {field: 'type', title: 'Type', width: 60},
-                {field: 'type', title: '类型', width: 60, visible: false},
-                {field: 'description', title: 'Description', align: 'left', width: 400},
-                {field: 'description_zh', title: '描述', align: 'left', width: 400, visible: false},
-                {field: 'default', title: 'Default', align: 'left', width: 180},
-                {field: 'default', title: '默认', align: 'left', width: 180, visible: false},
-                {field: 'example', title: '', formatter: function (value) {
-                    if (!value) {
-                        return '-';
-                    }
-                    return [
-                        '<a title="Example" href="examples.html#' + value + '">',
-                        '<i class="glyphicon glyphicon-eye-open"></i>',
-                        '</a>'].join('');
-                }}
-            ],
+            columns: columnColumns,
             data: [
                 {
                     name: 'radio',

+ 1 - 1
docs/documentation.html

@@ -161,8 +161,8 @@
 <script src="assets/bulletin/jquery.bulletin.js"></script>
 <script src="bootstrap-table-config.js"></script>
 <script src="../src/bootstrap-table.js"></script>
-<script src="docs.js"></script>
 <script src="common.js"></script>
+<script src="docs.js"></script>
 <script src="//wenzhixin.net.cn/js/analytics.js"></script>
 <!-- Baidu share -->
 <script id="bdshare_js" data="type=slide&amp;img=6&amp;pos=right&amp;uid=6692400"></script>