main.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <?php
  2. use yii\bootstrap\Nav;
  3. use yii\bootstrap\NavBar;
  4. use yii\helpers\Html;
  5. use yii\helpers\StringHelper;
  6. /* @var $this yii\web\View */
  7. \yii\apidoc\templates\bootstrap\assets\AssetBundle::register($this);
  8. // Navbar hides initial content when jumping to in-page anchor
  9. // https://github.com/twbs/bootstrap/issues/1768
  10. $this->registerJs(<<<JS
  11. var shiftWindow = function () { scrollBy(0, -50) };
  12. if (location.hash) setTimeout(shiftWindow, 1);
  13. window.addEventListener("hashchange", shiftWindow);
  14. JS
  15. ,
  16. \yii\web\View::POS_READY
  17. );
  18. $this->beginPage();
  19. ?>
  20. <!DOCTYPE html>
  21. <html lang="<?= Yii::$app->language ?>">
  22. <head>
  23. <meta charset="<?= Yii::$app->charset ?>"/>
  24. <meta name="viewport" content="width=device-width, initial-scale=1">
  25. <meta name="language" content="en" />
  26. <?= Html::csrfMetaTags() ?>
  27. <?php $this->head() ?>
  28. <title><?php if (isset($type)) {
  29. echo Html::encode(StringHelper::basename($type->name) . ", {$type->name} - {$this->context->pageTitle}");
  30. } elseif (isset($guideHeadline)) {
  31. echo Html::encode("$guideHeadline - {$this->context->pageTitle}");
  32. } else {
  33. echo Html::encode($this->context->pageTitle);
  34. }
  35. ?></title>
  36. </head>
  37. <body>
  38. <?php $this->beginBody() ?>
  39. <div class="wrap">
  40. <?php
  41. NavBar::begin([
  42. 'brandLabel' => $this->context->pageTitle,
  43. 'brandUrl' => ($this->context->apiUrl === null && $this->context->guideUrl !== null) ? './guide-index.html' : './index.html',
  44. 'options' => [
  45. 'class' => 'navbar-inverse navbar-fixed-top',
  46. ],
  47. 'renderInnerContainer' => false,
  48. 'view' => $this,
  49. ]);
  50. $nav = [];
  51. if ($this->context->apiUrl !== null) {
  52. $nav[] = ['label' => 'Class reference', 'url' => rtrim($this->context->apiUrl, '/') . '/index.html'];
  53. if (!empty($this->context->extensions)) {
  54. $extItems = [];
  55. foreach ($this->context->extensions as $ext) {
  56. $extItems[] = [
  57. 'label' => $ext,
  58. 'url' => "./ext-{$ext}-index.html",
  59. ];
  60. }
  61. $nav[] = ['label' => 'Extensions', 'items' => $extItems];
  62. }
  63. }
  64. if ($this->context->guideUrl !== null) {
  65. $nav[] = ['label' => 'Guide', 'url' => rtrim($this->context->guideUrl, '/') . '/' . $this->context->guidePrefix . 'README.html'];
  66. }
  67. echo Nav::widget([
  68. 'options' => ['class' => 'navbar-nav'],
  69. 'items' => $nav,
  70. 'view' => $this,
  71. 'params' => [],
  72. ]);
  73. ?>
  74. <div class="navbar-form navbar-left" role="search">
  75. <div class="form-group">
  76. <input id="searchbox" type="text" class="form-control" placeholder="Search">
  77. </div>
  78. </div>
  79. <?php
  80. \yii\apidoc\templates\bootstrap\assets\JsSearchAsset::register($this);
  81. // defer loading of the search index: https://developers.google.com/speed/docs/best-practices/payload?csw=1#DeferLoadingJS
  82. $this->registerJs(<<<JS
  83. var element = document.createElement("script");
  84. element.src = "./jssearch.index.js";
  85. document.body.appendChild(element);
  86. JS
  87. );
  88. $this->registerJs(<<<JS
  89. var searchBox = $('#searchbox');
  90. // search when typing in search field
  91. searchBox.on("keyup", function(event) {
  92. var query = $(this).val();
  93. if (query == '' || event.which == 27) {
  94. $('#search-resultbox').hide();
  95. return;
  96. } else if (event.which == 13) {
  97. var selectedLink = $('#search-resultbox a.selected');
  98. if (selectedLink.length != 0) {
  99. document.location = selectedLink.attr('href');
  100. return;
  101. }
  102. } else if (event.which == 38 || event.which == 40) {
  103. $('#search-resultbox').show();
  104. var selected = $('#search-resultbox a.selected');
  105. if (selected.length == 0) {
  106. $('#search-results').find('a').first().addClass('selected');
  107. } else {
  108. var next;
  109. if (event.which == 40) {
  110. next = selected.parent().next().find('a').first();
  111. } else {
  112. next = selected.parent().prev().find('a').first();
  113. }
  114. if (next.length != 0) {
  115. var resultbox = $('#search-results');
  116. var position = next.position();
  117. // TODO scrolling is buggy and jumps around
  118. // resultbox.scrollTop(Math.floor(position.top));
  119. // console.log(position.top);
  120. selected.removeClass('selected');
  121. next.addClass('selected');
  122. }
  123. }
  124. return;
  125. }
  126. $('#search-resultbox').show();
  127. $('#search-results').html('<li><span class="no-results">No results</span></li>');
  128. var result = jssearch.search(query);
  129. if (result.length > 0) {
  130. var i = 0;
  131. var resHtml = '';
  132. for (var key in result) {
  133. if (i++ > 20) {
  134. break;
  135. }
  136. resHtml = resHtml +
  137. '<li><a href="' + result[key].file.u.substr(3) +'"><span class="title">' + result[key].file.t + '</span>' +
  138. '<span class="description">' + result[key].file.d + '</span></a></li>';
  139. }
  140. $('#search-results').html(resHtml);
  141. }
  142. });
  143. // hide the search results on ESC
  144. $(document).on("keyup", function(event) { if (event.which == 27) { $('#search-resultbox').hide(); } });
  145. // hide search results on click to document
  146. $(document).bind('click', function (e) { $('#search-resultbox').hide(); });
  147. // except the following:
  148. searchBox.bind('click', function(e) { e.stopPropagation(); });
  149. $('#search-resultbox').bind('click', function(e) { e.stopPropagation(); });
  150. JS
  151. );
  152. NavBar::end();
  153. ?>
  154. <div id="search-resultbox" style="display: none;" class="modal-content">
  155. <ul id="search-results">
  156. </ul>
  157. </div>
  158. <?= $content ?>
  159. </div>
  160. <footer class="footer">
  161. <?php /* <p class="pull-left">&copy; My Company <?= date('Y') ?></p> */ ?>
  162. <p class="pull-right"><small>Page generated on <?= date('r') ?></small></p>
  163. <?= Yii::powered() ?>
  164. </footer>
  165. <?php $this->endBody() ?>
  166. </body>
  167. </html>
  168. <?php $this->endPage() ?>