Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

386 řádky
12 KiB

před 3 roky
  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. page_title = $(this).children("a")[0].innerText;
  27. document.title = page_title + " - ShowDoc";
  28. if (page_id != '' && page_id !='#') {
  29. change_page(page_id)
  30. };
  31. };
  32. })
  33. }
  34. //根据屏幕宽度进行响应(应对移动设备的访问)
  35. if( isMobile() || $(window).width() < 1000){
  36. AdaptToMobile();
  37. }
  38. $(window).resize(function(){
  39. if( isMobile()){
  40. AdaptToMobile();
  41. }
  42. else if($(window).width() < 1000){
  43. AdaptToMobile();
  44. }else{
  45. window.location.reload();
  46. }
  47. });
  48. //增加返回顶部按钮
  49. $.goup({
  50. trigger: 100,
  51. bottomOffset: 150,
  52. locationOffset: 100,
  53. title: lang["back_to_top"] ,
  54. titleAsText: true,
  55. containerColor:"#08c",
  56. });
  57. //js获取url参数
  58. function GetQueryString(name)
  59. {
  60. var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
  61. var r = window.location.search.substr(1).match(reg);
  62. if(r!=null)return unescape(r[2]); return null;
  63. }
  64. function AdaptToMobile(){
  65. $(".doc-left").removeClass("span3");
  66. $(".doc-left").css("width",'100%');
  67. $(".doc-left").css("height",'initial');
  68. $(".doc-left").css("min-height",'0px');
  69. $(".doc-left").css("position",'static');
  70. $(".doc-right").css("margin-top",'0px');
  71. $(".doc-right").css("margin-left",'0px');
  72. $(".doc-right").removeClass("span12");
  73. $(".doc-head .right").hide();
  74. $(".page-edit-link").html('');
  75. $(".doc-left-newbar").html('');
  76. //$(".iframe_content").css("padding-left","30px");
  77. $(".iframe_content").css("width",'');
  78. $(".doc-left .nav-list li a i ").css("margin-left" , '10px');
  79. $(".search-input-append").css("width","100%");
  80. $(".search-query-input").css("width","70%");
  81. }
  82. function mScroll(id){
  83. $("html,body").stop(true);
  84. $("html,body").animate(
  85. {scrollTop: $("#"+id).offset().top},
  86. 2000);
  87. }
  88. //点击左侧菜单事件
  89. $(".doc-left li").click(function(){
  90. //先把所有菜单的激活状态取消
  91. $(".doc-left li").each(function(){
  92. $(this).removeClass("active");
  93. });
  94. //先判断是否存在子菜单
  95. if ($(this).children('.child-ul').length != 0) {
  96. //如果子菜单是隐藏的,则显示之;如果是显示状态的,则隐藏
  97. if ($(this).children('.child-ul').css("display") == "none") {
  98. $(this).children('.child-ul').show();
  99. $(this).children("a").children('i').attr("class","icon-chevron-down");
  100. }else{
  101. $(this).children('.child-ul').hide();
  102. $(this).children("a").children('i').attr("class","icon-chevron-right");
  103. }
  104. };
  105. //激活菜单
  106. $(this).addClass("active");
  107. //获取对应的page_id
  108. page_id = $(this).children("a").attr("data-page-id");
  109. page_title = $(this).children("a")[0].innerText;
  110. if (page_id != '' && page_id != null && page_id !='#') {
  111. if (page_title != '' && page_title != null) {
  112. document.title = page_title + " - ShowDoc";
  113. }
  114. change_page(page_id);
  115. //如果是移动设备的话,则滚动页面
  116. if( isMobile()){
  117. mScroll("page-content");
  118. }
  119. };
  120. return false;//禁止原有的href链接
  121. });
  122. //切换页面;
  123. function change_page(page_id){
  124. if(!page_id)return;
  125. var item_id = $("#item_id").val();
  126. var item_domain = $("#item_domain").val();
  127. var base_url = $("#base_url").val();
  128. var iframe_url = base_url+"/home/page/index/page_id/"+page_id;
  129. $(".page-edit-link").show();
  130. //$("#page-content").attr("src" , iframe_url);
  131. $("#edit-link").attr("href" , base_url+"/home/page/edit/page_id/"+page_id);
  132. $("#copy-link").attr("href" , base_url+"/home/page/edit/item_id/"+item_id+"/copy_page_id/"+page_id);
  133. $("#delete-link").data("page_id",page_id);
  134. var domain = item_domain ? item_domain : item_id ;
  135. var cur_page_url = window.location.protocol +"//"+window.location.host+base_url+"/"+domain;
  136. if(base_url.length == 0){
  137. cur_page_url += "?page_id="+page_id;
  138. }else{
  139. cur_page_url += "&page_id="+page_id;
  140. }
  141. $("#share-page-link").html(cur_page_url);
  142. history.replaceState(null, null, cur_page_url);
  143. var single_page_url = window.location.protocol +"//"+window.location.host+base_url+"/page/"+page_id;
  144. $("#share-single-link").html(single_page_url);
  145. $("#qr-page-link").attr("src","?s=home/common/qrcode&size=3&url="+encodeURIComponent(cur_page_url));
  146. $("#qr-single-link").attr("src","?s=home/common/qrcode&size=3&url="+encodeURIComponent(single_page_url));
  147. $(".show_page_info").data("page_id",page_id);
  148. 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>';
  149. $(".iframe_content").html(html);
  150. iFrameHeight();
  151. }
  152. //分享项目
  153. $("#share").click(function(){
  154. $("#share-modal").modal();
  155. //延迟绑定分享事件
  156. setTimeout(function(){
  157. $('#copy-item-link').zclip(
  158. {
  159. path: DocConfig.pubile +'/jquery.zclip/ZeroClipboard.swf',
  160. copy:function()
  161. {
  162. return $('#share-item-link').html();
  163. },
  164. afterCopy: function() {
  165. show_top_msg("已经成功复制到剪切板",2000);
  166. }
  167. });
  168. },500);
  169. return false;
  170. });
  171. //分享页面
  172. $("#share-page").click(function(){
  173. $("#share-page-modal").modal();
  174. //延迟绑定分享事件
  175. setTimeout(function(){
  176. $('#copy-page-link').zclip(
  177. {
  178. path: DocConfig.pubile +'/jquery.zclip/ZeroClipboard.swf',
  179. copy:function()
  180. {
  181. return $('#share-page-link').html();
  182. },
  183. afterCopy: function() {
  184. show_top_msg("已经成功复制到剪切板",2000);
  185. }
  186. });
  187. $('#copy-single-link').zclip(
  188. {
  189. path:DocConfig.pubile +'/jquery.zclip/ZeroClipboard.swf',
  190. copy:function()
  191. {
  192. return $('#share-single-link').html();
  193. },
  194. afterCopy: function() {
  195. show_top_msg("已经成功复制到剪切板",2000);
  196. }
  197. });
  198. },500);
  199. return false;
  200. });
  201. function iFrameHeight() { 
  202. var ifr = document.getElementById('page-content');
  203. ifr.onload = function() {
  204. var iDoc = ifr.contentDocument || ifr.document;
  205. var height = calcPageHeight(iDoc);
  206. ifr.style.height = height + 'px';
  207. }
  208.  }
  209. // 计算页面的实际高度,iframe自适应会用到
  210. function calcPageHeight(doc) {
  211. var cHeight = Math.max(doc.body.clientHeight, doc.documentElement.clientHeight)
  212. var sHeight = Math.max(doc.body.scrollHeight, doc.documentElement.scrollHeight)
  213. var height = Math.max(cHeight, sHeight)
  214. return height
  215. }
  216. var keyMap = {
  217. // 编辑
  218. "Ctrl+E": function() {
  219. location.href = $("#edit-link").attr('href');
  220. },
  221. // 删除
  222. "Ctrl+D": function() {
  223. $("#delete-link").click();
  224. },
  225. // 新建页面
  226. "Ctrl+F1": function() {
  227. location.href = $("#new-like").attr('href');
  228. },
  229. // 新建目录
  230. "Ctrl+F2": function() {
  231. location.href = $("#dir-like").attr('href');
  232. }
  233. };
  234. if (!isMobile()) initKeys();
  235. function initKeys() {
  236. var $doc = $(document);
  237. $.each(keyMap, function(key, fn) {
  238. $doc.on('keydown', null, key, function(e) {
  239. e.preventDefault();
  240. fn();
  241. return false;
  242. });
  243. });
  244. }
  245. $(".show_page_info").click(function(){
  246. var page_id = $(this).data("page_id") ;
  247. $.post(
  248. DocConfig.server+"/api/page/info",
  249. {"page_id":page_id},
  250. function(data){
  251. var html = "<p>最后编辑时间:"+data.data.addtime+"</p><p>编辑人:"+data.data.author_username+"</p>";
  252. $.alert(html);
  253. },
  254. "json"
  255. );
  256. return false;
  257. });
  258. //删除页面
  259. $("#delete-link").click(function(){
  260. var page_id = $(this).data("page_id") ;
  261. $.confirm(lang["confirm_to_delete"],{},function(){
  262. $.post(
  263. DocConfig.server+"/api/page/delete",
  264. {"page_id":page_id},
  265. function(data){
  266. if (data.error_code == 0) {
  267. $.alert(lang["delete_success"],function(){
  268. window.location.reload();
  269. });
  270. }else{
  271. if (data.error_message) {
  272. $.alert(data.error_message);
  273. }else{
  274. $.alert(lang["delete_fail"]);
  275. }
  276. }
  277. },
  278. "json"
  279. );
  280. });
  281. return false;
  282. });
  283. $("#delete-link").click(function(){
  284. var page_id = $(this).data("page_id") ;
  285. $.confirm(lang["confirm_to_delete"],{},function(){
  286. $.post(
  287. DocConfig.server+"/api/page/delete",
  288. {"page_id":page_id},
  289. function(data){
  290. if (data.error_code == 0) {
  291. $.alert(lang["delete_success"],function(){
  292. window.location.reload();
  293. });
  294. }else{
  295. if (data.error_message) {
  296. $.alert(data.error_message);
  297. }else{
  298. $.alert(lang["delete_fail"]);
  299. }
  300. }
  301. },
  302. "json"
  303. );
  304. });
  305. return false;
  306. });
  307. window.addEventListener('message', function(e){
  308. if(e.origin != window.location.origin) return;
  309. if (e.data.meessage_type != 'img_url') {
  310. return ;
  311. }
  312. var img_url =e.data.img_url;
  313. var json = {
  314. "title": "", //相册标题
  315. "id": 123, //相册id
  316. "start": 0, //初始显示的图片序号,默认0
  317. "data": [ //相册包含的图片,数组格式
  318. {
  319. "alt": "",
  320. "pid": 666, //图片id
  321. "src": img_url, //原图地址
  322. "thumb": img_url //缩略图地址
  323. }
  324. ]
  325. }
  326. $.photos({
  327. photos: json
  328. ,anim: 5 //0-6的选择,指定弹出图片动画类型,默认随机(请注意,3.0之前的版本用shift参数)
  329. });
  330. }, false);
  331. })