show.js 8.6 KB

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