index.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. $(function(){
  2. hljs.initHighlightingOnLoad();
  3. var EditormdView = editormd.markdownToHTML("page_md_content", {
  4. htmlDecode : "style,script,iframe", // you can filter tags decode
  5. emoji : true,
  6. taskList : true,
  7. tex : true, // 默认不解析
  8. flowChart : true, // 默认不解析
  9. sequenceDiagram : true, // 默认不解析
  10. });
  11. //为所有table标签添加bootstap支持的表格类
  12. $("table").addClass("table table-bordered table-hover");
  13. $.each($('table'), function() {
  14. $(this).prop('outerHTML', '<div style="width: 100%;overflow-x: auto;">'+$(this).prop('outerHTML')+'</div>');
  15. });
  16. //不是本项目的超链接都在新窗口打开
  17. $('a[href^="http"]').each(function() {
  18. $(this).attr('target', '_blank');
  19. $(this).click(function(){
  20. var target_url = $(this).attr("href") ;
  21. if (target_url.indexOf(window.top.location.host + window.top.location.pathname) > -1 ){
  22. window.top.location.href = target_url;
  23. return false;
  24. }
  25. });
  26. });
  27. if (!isMobile()) {
  28. $("th").css("min-width","77px");
  29. };
  30. $("table thead tr").css({"background-color":"#08c","color":"#fff"});
  31. $("table tr").each(function(){
  32. if($(this).find("td").eq(1).html()=="object" || $(this).find("td").eq(1).html()=="array[object]")
  33. {
  34. $(this).css({"background-color":"#99CC99","color":"#000"});
  35. }
  36. });
  37. //图片点击放大
  38. $("#page_md_content img").click(function(){
  39. var img_url = $(this).attr("src");
  40. //如果不在iframe里,则直接当前窗口打开
  41. if (self == top) {
  42. var json = {
  43. "title": "", //相册标题
  44. "id": 123, //相册id
  45. "start": 0, //初始显示的图片序号,默认0
  46. "data": [ //相册包含的图片,数组格式
  47. {
  48. "alt": "",
  49. "pid": 666, //图片id
  50. "src": img_url, //原图地址
  51. "thumb": img_url //缩略图地址
  52. }
  53. ]
  54. }
  55. layer.photos({
  56. photos: json
  57. ,anim: 5 //0-6的选择,指定弹出图片动画类型,默认随机(请注意,3.0之前的版本用shift参数)
  58. });
  59. }else{
  60. //如果在iframe里,则直接传url给父窗口
  61. var message ={"img_url":img_url,"meessage_type":"img_url"};
  62. top.postMessage(message, window.location.origin);
  63. }
  64. });
  65. })