show.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. //页面加载完就执行
  2. $(function(){
  3. //自动根据url把当前菜单激活
  4. var current_page_id = $("#current_page_id").val();
  5. //如果中没有指定page_id,则判断有没有父目录为0的页面,默认打开第一个
  6. if(!current_page_id) {
  7. current_page_id = $(".doc-left li").children("a").attr("data-page-id");
  8. };
  9. if(current_page_id !=null && current_page_id.toString().length>0)
  10. {
  11. $(".doc-left li").each(function(){
  12. page_id = $(this).children("a").attr("data-page-id");
  13. //如果链接中包含当前url的信息,两者相匹配
  14. if (page_id !=null && page_id.toString().length>0 && page_id == current_page_id) {
  15. //激活菜单
  16. $(this).addClass("active");
  17. //如果该菜单是子菜单,则还需要把父菜单打开才行
  18. if ($(this).parent('.child-ul')) {
  19. $(this).parent('.child-ul').show();
  20. $(this).parent('.child-ul').parent('li').children("a").children('i').attr("class","icon-chevron-down");
  21. };
  22. if (page_id != '' && page_id !='#') {
  23. change_page(page_id)
  24. };
  25. };
  26. })
  27. }
  28. //根据屏幕宽度进行响应(应对移动设备的访问)
  29. if( isMobile()){
  30. AdaptToMobile();
  31. }
  32. $(window).resize(function(){
  33. if( isMobile()){
  34. AdaptToMobile();
  35. }
  36. else if($(window).width() < 600){
  37. AdaptToMobile();
  38. }else{
  39. window.location.reload();
  40. }
  41. });
  42. //增加返回顶部按钮
  43. $.goup({
  44. trigger: 100,
  45. bottomOffset: 150,
  46. locationOffset: 100,
  47. title: lang["back_to_top"] ,
  48. titleAsText: true,
  49. containerColor:"#08c",
  50. });
  51. //js获取url参数
  52. function GetQueryString(name)
  53. {
  54. var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
  55. var r = window.location.search.substr(1).match(reg);
  56. if(r!=null)return unescape(r[2]); return null;
  57. }
  58. function AdaptToMobile(){
  59. $(".doc-left").removeClass("span3");
  60. $(".doc-left").css("width",'100%');
  61. $(".doc-left").css("height",'initial');
  62. $(".doc-left").css("min-height",'0px');
  63. $(".doc-right").removeClass("span12");
  64. $(".doc-head .right").hide();
  65. $(".page-edit-link").html('');
  66. $(".doc-left-newbar").html('');
  67. $(".iframe_content").css("padding-left","30px");
  68. $(".doc-left .nav-list li a i ").css("margin-left" , '10px');
  69. $(".search-input-append").css("width","100%");
  70. $(".search-query-input").css("width","70%");
  71. }
  72. function mScroll(id){
  73. $("html,body").stop(true);
  74. $("html,body").animate(
  75. {scrollTop: $("#"+id).offset().top},
  76. 2000);
  77. }
  78. //点击左侧菜单事件
  79. $(".doc-left li").click(function(){
  80. //先把所有菜单的激活状态取消
  81. $(".doc-left li").each(function(){
  82. $(this).removeClass("active");
  83. });
  84. //先判断是否存在子菜单
  85. if ($(this).children('.child-ul').length != 0) {
  86. //如果子菜单是隐藏的,则显示之;如果是显示状态的,则隐藏
  87. if ($(this).children('.child-ul').css("display") == "none") {
  88. $(this).children('.child-ul').show();
  89. $(this).children("a").children('i').attr("class","icon-chevron-down");
  90. }else{
  91. $(this).children('.child-ul').hide();
  92. $(this).children("a").children('i').attr("class","icon-chevron-right");
  93. }
  94. };
  95. //获取对应的page_id
  96. page_id = $(this).children("a").attr("data-page-id");
  97. page_title = $(this).children("a")[0].innerText;
  98. if (page_id != '' && page_id != null && page_id !='#') {
  99. if (page_title != '' && page_title != null) {
  100. document.title = page_title + " - ShowDoc";
  101. }
  102. change_page(page_id);
  103. //如果是移动设备的话,则滚动页面
  104. if( isMobile()){
  105. mScroll("page-content");
  106. }
  107. };
  108. return false;//禁止原有的href链接
  109. });
  110. //切换页面;
  111. function change_page(page_id){
  112. if(!page_id)return;
  113. var item_id = $("#item_id").val();
  114. var item_domain = $("#item_domain").val();
  115. var base_url = $("#base_url").val();
  116. var iframe_url = base_url+"/home/page/index/page_id/"+page_id;
  117. $(".page-edit-link").show();
  118. //$("#page-content").attr("src" , iframe_url);
  119. $("#edit-link").attr("href" , base_url+"/home/page/edit/page_id/"+page_id);
  120. $("#copy-link").attr("href" , base_url+"/home/page/edit/item_id/"+item_id+"/copy_page_id/"+page_id);
  121. $("#delete-link").attr("href" , base_url+"/home/page/delete/page_id/"+page_id);
  122. var domain = item_domain ? item_domain : item_id ;
  123. var cur_page_url = window.location.protocol +"//"+window.location.host+base_url+"/"+domain+"&page_id="+page_id;
  124. $("#share-page-link").html(cur_page_url);
  125. history.replaceState(null, null, cur_page_url);
  126. var html = '<iframe id="page-content" width="100%" scrolling="yes" height="100%" frameborder="0" style=" overflow:visible; height:100%;" name="main" seamless ="seamless"src="'+iframe_url+'"></iframe>';
  127. $(".iframe_content").html(html);
  128. iFrameHeight();
  129. }
  130. //分享项目
  131. $("#share").click(function(){
  132. $("#share-modal").modal();
  133. return false;
  134. });
  135. //分享页面
  136. $("#share-page").click(function(){
  137. $("#share-page-modal").modal();
  138. return false;
  139. });
  140. function iFrameHeight() { 
  141. var ifr = document.getElementById('page-content');
  142. ifr.onload = function() {
  143. var iDoc = ifr.contentDocument || ifr.document;
  144. var height = calcPageHeight(iDoc);
  145. ifr.style.height = height + 'px';
  146. if(!isMobile()){
  147. //调节左侧栏背景的最小高度
  148. if(height > document.body.clientHeight){
  149. $(".doc-left").css("min-height",(height+60) + 'px');
  150. }else{
  151. $(".doc-left").css("min-height",'100%');
  152. }
  153. }
  154. }
  155.  }
  156. // 计算页面的实际高度,iframe自适应会用到
  157. function calcPageHeight(doc) {
  158. var cHeight = Math.max(doc.body.clientHeight, doc.documentElement.clientHeight)
  159. var sHeight = Math.max(doc.body.scrollHeight, doc.documentElement.scrollHeight)
  160. var height = Math.max(cHeight, sHeight)
  161. return height
  162. }
  163. var keyMap = {
  164. // 编辑
  165. "Ctrl+E": function() {
  166. location.href = $("#edit-link").attr('href');
  167. },
  168. // 删除
  169. "Ctrl+D": function() {
  170. if (confirm(lang["confirm_to_delete"]))
  171. location.href = $("#delete-link").attr('href');
  172. },
  173. // 新建页面
  174. "Ctrl+F1": function() {
  175. location.href = $("#new-like").attr('href');
  176. },
  177. // 新建目录
  178. "Ctrl+F2": function() {
  179. location.href = $("#dir-like").attr('href');
  180. }
  181. };
  182. if (!isMobile()) initKeys();
  183. function initKeys() {
  184. var $doc = $(document);
  185. $.each(keyMap, function(key, fn) {
  186. $doc.on('keydown', null, key, function(e) {
  187. e.preventDefault();
  188. fn();
  189. return false;
  190. });
  191. });
  192. }
  193. })