show.js 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  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. if($(this).parent('.child-ul').parent().parent('.child-ul')){
  22. $(this).parent('.child-ul').parent().parent('.child-ul').show();
  23. $(this).parent('.child-ul').parent().parent('.child-ul').parent('li').children("a").children('i').attr("class","icon-chevron-down");
  24. }
  25. };
  26. if (page_id != '' && page_id !='#') {
  27. change_page(page_id)
  28. };
  29. };
  30. })
  31. }
  32. //根据屏幕宽度进行响应(应对移动设备的访问)
  33. if( isMobile() || $(window).width() < 1000){
  34. AdaptToMobile();
  35. }
  36. $(window).resize(function(){
  37. if( isMobile()){
  38. AdaptToMobile();
  39. }
  40. else if($(window).width() < 1000){
  41. AdaptToMobile();
  42. }else{
  43. window.location.reload();
  44. }
  45. });
  46. //增加返回顶部按钮
  47. $.goup({
  48. trigger: 100,
  49. bottomOffset: 150,
  50. locationOffset: 100,
  51. title: lang["back_to_top"] ,
  52. titleAsText: true,
  53. containerColor:"#08c",
  54. });
  55. //js获取url参数
  56. function GetQueryString(name)
  57. {
  58. var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
  59. var r = window.location.search.substr(1).match(reg);
  60. if(r!=null)return unescape(r[2]); return null;
  61. }
  62. function AdaptToMobile(){
  63. $(".doc-left").removeClass("span3");
  64. $(".doc-left").css("width",'100%');
  65. $(".doc-left").css("height",'initial');
  66. $(".doc-left").css("min-height",'0px');
  67. $(".doc-right").removeClass("span12");
  68. $(".doc-head .right").hide();
  69. $(".page-edit-link").html('');
  70. $(".doc-left-newbar").html('');
  71. //$(".iframe_content").css("padding-left","30px");
  72. $(".iframe_content").css("width",'');
  73. $(".doc-left .nav-list li a i ").css("margin-left" , '10px');
  74. $(".search-input-append").css("width","100%");
  75. $(".search-query-input").css("width","70%");
  76. }
  77. function mScroll(id){
  78. $("html,body").stop(true);
  79. $("html,body").animate(
  80. {scrollTop: $("#"+id).offset().top},
  81. 2000);
  82. }
  83. //点击左侧菜单事件
  84. $(".doc-left li").click(function(){
  85. //先把所有菜单的激活状态取消
  86. $(".doc-left li").each(function(){
  87. $(this).removeClass("active");
  88. });
  89. //先判断是否存在子菜单
  90. if ($(this).children('.child-ul').length != 0) {
  91. //如果子菜单是隐藏的,则显示之;如果是显示状态的,则隐藏
  92. if ($(this).children('.child-ul').css("display") == "none") {
  93. $(this).children('.child-ul').show();
  94. $(this).children("a").children('i').attr("class","icon-chevron-down");
  95. }else{
  96. $(this).children('.child-ul').hide();
  97. $(this).children("a").children('i').attr("class","icon-chevron-right");
  98. }
  99. };
  100. //激活菜单
  101. $(this).addClass("active");
  102. //获取对应的page_id
  103. page_id = $(this).children("a").attr("data-page-id");
  104. page_title = $(this).children("a")[0].innerText;
  105. if (page_id != '' && page_id != null && page_id !='#') {
  106. if (page_title != '' && page_title != null) {
  107. document.title = page_title + " - ShowDoc";
  108. }
  109. change_page(page_id);
  110. //如果是移动设备的话,则滚动页面
  111. if( isMobile()){
  112. mScroll("page-content");
  113. }
  114. };
  115. return false;//禁止原有的href链接
  116. });
  117. //切换页面;
  118. function change_page(page_id){
  119. if(!page_id)return;
  120. var item_id = $("#item_id").val();
  121. var item_domain = $("#item_domain").val();
  122. var base_url = $("#base_url").val();
  123. var iframe_url = base_url+"/home/page/index/page_id/"+page_id;
  124. $(".page-edit-link").show();
  125. //$("#page-content").attr("src" , iframe_url);
  126. $("#edit-link").attr("href" , base_url+"/home/page/edit/page_id/"+page_id);
  127. $("#copy-link").attr("href" , base_url+"/home/page/edit/item_id/"+item_id+"/copy_page_id/"+page_id);
  128. $("#delete-link").attr("href" , base_url+"/home/page/delete/page_id/"+page_id);
  129. var domain = item_domain ? item_domain : item_id ;
  130. var cur_page_url = window.location.protocol +"//"+window.location.host+base_url+"/"+domain;
  131. if(base_url.length == 0){
  132. cur_page_url += "?page_id="+page_id;
  133. }else{
  134. cur_page_url += "&page_id="+page_id;
  135. }
  136. $("#share-page-link").html(cur_page_url);
  137. history.replaceState(null, null, cur_page_url);
  138. var single_page_url = window.location.protocol +"//"+window.location.host+base_url+"/page/"+page_id;
  139. $("#share-single-link").html(single_page_url);
  140. $("#qr-page-link").attr("src","?s=home/common/qrcode&size=3&url="+cur_page_url);
  141. $("#qr-single-link").attr("src","?s=home/common/qrcode&size=3&url="+single_page_url);
  142. 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>';
  143. $(".iframe_content").html(html);
  144. iFrameHeight();
  145. }
  146. //分享项目
  147. $("#share").click(function(){
  148. $("#share-modal").modal();
  149. //延迟绑定分享事件
  150. setTimeout(function(){
  151. $('#copy-item-link').zclip(
  152. {
  153. path: DocConfig.pubile +'/jquery.zclip/ZeroClipboard.swf',
  154. copy:function()
  155. {
  156. return $('#share-item-link').html();
  157. },
  158. afterCopy: function() {
  159. show_top_msg("已经成功复制到剪切板",2000);
  160. }
  161. });
  162. },500);
  163. return false;
  164. });
  165. //分享页面
  166. $("#share-page").click(function(){
  167. $("#share-page-modal").modal();
  168. //延迟绑定分享事件
  169. setTimeout(function(){
  170. $('#copy-page-link').zclip(
  171. {
  172. path: DocConfig.pubile +'/jquery.zclip/ZeroClipboard.swf',
  173. copy:function()
  174. {
  175. return $('#share-page-link').html();
  176. },
  177. afterCopy: function() {
  178. show_top_msg("已经成功复制到剪切板",2000);
  179. }
  180. });
  181. $('#copy-single-link').zclip(
  182. {
  183. path:DocConfig.pubile +'/jquery.zclip/ZeroClipboard.swf',
  184. copy:function()
  185. {
  186. return $('#share-single-link').html();
  187. },
  188. afterCopy: function() {
  189. show_top_msg("已经成功复制到剪切板",2000);
  190. }
  191. });
  192. },500);
  193. return false;
  194. });
  195. function iFrameHeight() { 
  196. var ifr = document.getElementById('page-content');
  197. ifr.onload = function() {
  198. var iDoc = ifr.contentDocument || ifr.document;
  199. var height = calcPageHeight(iDoc);
  200. ifr.style.height = height + 'px';
  201. if(!isMobile() && $(window).width() > 1000){
  202. //调节左侧栏背景的最小高度
  203. if(height > document.body.clientHeight){
  204. $(".doc-left").css("min-height",(height+60) + 'px');
  205. }else{
  206. $(".doc-left").css("min-height",'100%');
  207. }
  208. }
  209. }
  210.  }
  211. // 计算页面的实际高度,iframe自适应会用到
  212. function calcPageHeight(doc) {
  213. var cHeight = Math.max(doc.body.clientHeight, doc.documentElement.clientHeight)
  214. var sHeight = Math.max(doc.body.scrollHeight, doc.documentElement.scrollHeight)
  215. var height = Math.max(cHeight, sHeight)
  216. return height
  217. }
  218. var keyMap = {
  219. // 编辑
  220. "Ctrl+E": function() {
  221. location.href = $("#edit-link").attr('href');
  222. },
  223. // 删除
  224. "Ctrl+D": function() {
  225. if (confirm(lang["confirm_to_delete"]))
  226. location.href = $("#delete-link").attr('href');
  227. },
  228. // 新建页面
  229. "Ctrl+F1": function() {
  230. location.href = $("#new-like").attr('href');
  231. },
  232. // 新建目录
  233. "Ctrl+F2": function() {
  234. location.href = $("#dir-like").attr('href');
  235. }
  236. };
  237. if (!isMobile()) initKeys();
  238. function initKeys() {
  239. var $doc = $(document);
  240. $.each(keyMap, function(key, fn) {
  241. $doc.on('keydown', null, key, function(e) {
  242. e.preventDefault();
  243. fn();
  244. return false;
  245. });
  246. });
  247. }
  248. })