echartsHome.js 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. var version = '2.2.1';
  2. var sp = location.href.lastIndexOf('/');
  3. var ep = location.href.lastIndexOf('.html');
  4. var curPage = sp < ep ? location.href.slice(sp + 1, ep) : 'index';
  5. var enVersion = (location.hash && location.hash.indexOf('-en') != -1)
  6. || location.href.indexOf('-en') != -1;
  7. var activeClass = {};
  8. var loc = {};
  9. var forkWidth = 149;
  10. curPage = curPage.replace('-en', '');
  11. var isExample = false;
  12. switch (curPage) {
  13. case 'index' :
  14. activeClass[curPage] = 'active';
  15. loc[curPage] = '.';
  16. loc.feature = './doc';
  17. loc.example = './doc';
  18. loc.doc = './doc';
  19. loc.about = './doc';
  20. loc.changelog = './doc';
  21. loc.start = './doc';
  22. loc.img = './doc';
  23. break;
  24. case 'feature' :
  25. case 'example' :
  26. case 'doc' :
  27. case 'about' :
  28. case 'changelog' :
  29. case 'start' :
  30. activeClass[curPage] = 'active';
  31. loc.index = '..';
  32. break;
  33. default :
  34. isExample = true;
  35. forkWidth = 60;
  36. activeClass['example'] = 'active';
  37. var extSub = location.href.indexOf('extension') != -1 ? '../' : '';
  38. loc.index = extSub + '../..';
  39. loc.feature = extSub + '../../doc';
  40. loc.example = extSub + '../../doc';
  41. loc.doc = extSub + '../../doc';
  42. loc.about = extSub + '../../doc';
  43. loc.changelog = extSub + '../../doc';
  44. loc.start = extSub + '../../doc';
  45. loc.img = extSub + '../../doc';
  46. break;
  47. }
  48. $('#head')[0].innerHTML =
  49. '<div class="container">'
  50. + '<div class="navbar-header">'
  51. + '<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">'
  52. + '<span class="sr-only">Toggle navigation</span>'
  53. + '<span class="icon-bar"></span>'
  54. + '<span class="icon-bar"></span>'
  55. + '<span class="icon-bar"></span>'
  56. + '</button>'
  57. + '<a class="navbar-brand" href="http://echarts.baidu.com/index'
  58. + (enVersion ? '-en': '')
  59. + '.html">ECharts</a>'
  60. + '</div>'
  61. + '<a href="https://github.com/ecomfe/echarts" target="_blank">'
  62. + '<img id="fork-image" style="position:absolute;top:0;right:0;border:0;z-index:1000;width:' + forkWidth + 'px" src="'+ (loc.img || '.') + '/asset/img/fork.png" alt="Fork me on GitHub">'
  63. + '</a>'
  64. + '<div class="navbar-collapse collapse" id="nav-wrap">'
  65. + '<ul class="nav navbar-nav navbar-right" id="nav" style="max-width:100%;">'
  66. + (enVersion
  67. ? ('<li class="' + (activeClass.index || '') + '"><a href="' + (loc.index || '.') + '/index-en.html">Home</a></li>'
  68. + '<li class="' + (activeClass.feature || '') + '"><a href="' + (loc.feature || '.') + '/feature-en.html">Feature</a></li>'
  69. + '<li class="' + (activeClass.example || '') + '"><a href="' + (loc.example || '.') + '/example-en.html">Example</a></li>'
  70. + '<li class="' + (activeClass.doc || '') + '"><a href="' + (loc.doc || '.') + '/doc-en.html">API & Doc</a></li>'
  71. )
  72. : ('<li class="' + (activeClass.index || '') + '"><a href="' + (loc.index || '.') + '/index.html">首页</a></li>'
  73. + '<li class="' + (activeClass.feature || '') + '"><a href="' + (loc.feature || '.') + '/feature.html">特性</a></li>'
  74. + '<li class="' + (activeClass.example || '') + '"><a href="' + (loc.example || '.') + '/example.html">实例</a></li>'
  75. + '<li class="' + (activeClass.doc || '') + '"><a href="' + (loc.doc || '.') + '/doc.html">文档</a></li>'
  76. ))
  77. /*
  78. + '<li class="dropdown">'
  79. + '<a href="#" class="dropdown-toggle" data-toggle="dropdown">教学 <b class="caret"></b></a>'
  80. + '<ul class="dropdown-menu">'
  81. + '<li><a href="#">初学教程</a></li>'
  82. + '<li class="divider"></li>'
  83. + '<li class="dropdown-header">外部资源</li>'
  84. + '<li><a href="#"></a></li>'
  85. + '<li><a href="#"></a></li>'
  86. + '</ul>'
  87. + '</li>'
  88. */
  89. + '<li class="dropdown">'
  90. + '<a href="#" class="dropdown-toggle" data-toggle="dropdown">' + (enVersion ? 'Download' : '下载') + '<b class="caret"></b></a>'
  91. + '<ul class="dropdown-menu">'
  92. + '<li><a href="http://echarts.baidu.com/build/echarts-' + version + '.zip"> echarts-' + version + ' (from Baidu)</a></li>'
  93. + '<li><a href="https://github.com/ecomfe/echarts/archive/' + version + '.zip"> echarts-' + version + ' (from GitHub)</a></li>'
  94. + '<li><a href="http://echarts.baidu.com/build/echarts-m-1.0.0.zip"> echarts-m-1.0.0 (beta)</a></li>'
  95. + '<li><a href="http://echarts.baidu.com/x/build/echarts-x-0.1.0.zip"> echarts-x-0.1.0 </a></li>'
  96. + '<li class="divider"></li>'
  97. + (enVersion
  98. ? '<li><a href="http://ecomfe.github.io/echarts/doc/changelog-en.html">Changelog</a></li>'
  99. : '<li><a href="http://echarts.baidu.com/doc/changelog.html">Changelog</a></li>'
  100. )
  101. + '</ul>'
  102. + '</li>'
  103. //+ '<li><a href="http://echarts.baidu.com/build/echarts-' + version + '.rar">下载</a></li>'
  104. + (enVersion
  105. ? ('<li class="' + (activeClass.about || '') + '"><a href="' + (loc.about || '.') + '/about-en.html">About Us</a></li>')
  106. : ('<li class="' + (activeClass.about || '') + '"><a href="' + (loc.about || '.') + '/about.html">关于我们</a></li>')
  107. )
  108. + '<li><a href="javascript:void()" onclick="changeVersion()">' + (enVersion ? '中文' : 'English') + '</a></li>'
  109. + '</ul>'
  110. + '</div><!--/.nav-collapse -->'
  111. + '</div>';
  112. function back2Top() {
  113. $("body,html").animate({scrollTop:0},1000);
  114. return false;
  115. }
  116. function changeVersion() {
  117. if (!isExample) {
  118. window.location = curPage + (enVersion ? '' : '-en') + '.html'
  119. }
  120. else {
  121. window.location = curPage + '.html' + (enVersion ? '' : '#-en');
  122. if (enVersion) {
  123. window.location.hash = window.location.hash.replace('-en', '');
  124. }
  125. window.location.reload();
  126. }
  127. }
  128. $('#footer')[0].style.marginTop = '50px';
  129. $('#footer')[0].innerHTML =
  130. '<div class="container">'
  131. + '<div class="row" style="padding-bottom:20px;">'
  132. + '<div class="col-md-3">'
  133. + '<p>' + (enVersion ? 'Link' : 'ECharts团队出品') + '</p>'
  134. + '<ul>'
  135. + '<li><a href="http://tushuo.baidu.com/" target="_blank">Baidu 图说</a></li>'
  136. + '<li><a href="' + (enVersion ? "http://ecomfe.github.io/echarts-x" : 'http://echarts.baidu.com/x/doc') + '" target="_blank">ECharts-X</a></li>'
  137. + '<li><a href="http://ecomfe.github.io/zrender/index.html" target="_blank">ZRender</a></li>'
  138. + '<li><a href="https://github.com/pissang/qtek" target="_blank">QTEK</a></li>'
  139. + '</ul>'
  140. + '</div>'
  141. + '<div class="col-md-3">'
  142. + '<p>' + (enVersion ? 'More' : '更多') + '</p>'
  143. + '<ul>'
  144. + '<li><a href="https://github.com/ecomfe/echarts/blob/master/LICENSE.txt" target="_blank">License</a></li>'
  145. + '<li><a href="http://echarts.baidu.com/doc/changelog' + (enVersion ? '-en' : '') + '.html" target="_blank">Changelog</a></li>'
  146. + '<li><a href="http://efe.baidu.com" target="_blank">Baidu EFE</a></li>'
  147. + '<li><a href="http://www.oschina.net/p/echarts" target="_blank">' + (enVersion ? 'Open Source China' : '开源中国') + '</a></li>'
  148. + '</ul>'
  149. + '</div>'
  150. + '<div class="col-md-3">'
  151. + '<p>' + (enVersion ? 'Contact Us' : '联系我们') + '</p>'
  152. + '<ul>'
  153. + '<li><a href="mailto:echarts(a)baidu.com">echarts(a)baidu.com</a></li>'
  154. + '<li><a href="https://github.com/ecomfe/echarts" target="_blank"> Github</a></li>'
  155. + '<li><a href="http://weibo.com/echarts" target="_blank">Weibo</a></li>'
  156. + '</ul>'
  157. + '</div>'
  158. + '<div class="col-md-3 flogo">'
  159. + '<a href="javascript:void(0)" onclick="back2Top()" title="' + (enVersion ? 'Back to top' : '回到顶部') + '"><img src="'+ (loc.img || '.')+ '/asset/img/echarts-logo2.png" alt="ECharts"/></a>'
  160. + '</div>'
  161. + '</div>'
  162. + '<p class="pull-right"><a href="javascript:void(0)" onclick="back2Top()" >Back to top</a></p>'
  163. + '<p>&copy; 2015 <a href="http://www.baidu.com/" target="_blank">Baidu</a></p>'
  164. + '</div>';
  165. if (document.location.href.indexOf('local') == -1) {
  166. var _bdhmProtocol = (("https:" == document.location.protocol) ? " https://" : " http://");
  167. document.write(unescape("%3Cscript src='" + _bdhmProtocol + "hm.baidu.com/h.js%3Fb78830c9a5dad062d08b90b2bc0cf5da' type='text/javascript'%3E%3C/script%3E"));
  168. }
  169. function fixFork () {
  170. var navMarginRight = 0;
  171. var bodyWidth = document.body.offsetWidth;
  172. var contnetWidth = $('#nav-wrap')[0].offsetWidth;
  173. if (bodyWidth < 1440) {
  174. navMarginRight = 150 - (bodyWidth - contnetWidth) / 2;
  175. }
  176. $('#nav')[0].style.marginRight = navMarginRight + 'px';
  177. $('#fork-image')[0].style.width = (document.body.offsetWidth < 768 ? 1 : forkWidth) + 'px';
  178. };
  179. fixFork();
  180. $(window).on('resize', fixFork);