123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292 |
- //页面加载完就执行
- $(function(){
- //自动根据url把当前菜单激活
- var current_page_id = $("#current_page_id").val();
- //如果中没有指定page_id,则判断有没有父目录为0的页面,默认打开第一个
- if(!current_page_id) {
- current_page_id = $(".doc-left li").children("a").attr("data-page-id");
- };
- if(current_page_id !=null && current_page_id.toString().length>0)
- {
- $(".doc-left li").each(function(){
- page_id = $(this).children("a").attr("data-page-id");
- //如果链接中包含当前url的信息,两者相匹配
- if (page_id !=null && page_id.toString().length>0 && page_id == current_page_id) {
- //激活菜单
- $(this).addClass("active");
- //如果该菜单是子菜单,则还需要把父菜单打开才行
- if ($(this).parent('.child-ul')) {
- $(this).parent('.child-ul').show();
- $(this).parent('.child-ul').parent('li').children("a").children('i').attr("class","icon-chevron-down");
- };
- if (page_id != '' && page_id !='#') {
- change_page(page_id)
- };
- };
- })
- }
- //根据屏幕宽度进行响应(应对移动设备的访问)
- if( isMobile() || $(window).width() < 1000){
- AdaptToMobile();
- }
- $(window).resize(function(){
- if( isMobile()){
- AdaptToMobile();
- }
- else if($(window).width() < 1000){
- AdaptToMobile();
- }else{
- window.location.reload();
- }
- });
- //增加返回顶部按钮
- $.goup({
- trigger: 100,
- bottomOffset: 150,
- locationOffset: 100,
- title: lang["back_to_top"] ,
- titleAsText: true,
- containerColor:"#08c",
- });
- //js获取url参数
- function GetQueryString(name)
- {
- var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
- var r = window.location.search.substr(1).match(reg);
- if(r!=null)return unescape(r[2]); return null;
- }
- function AdaptToMobile(){
- $(".doc-left").removeClass("span3");
- $(".doc-left").css("width",'100%');
- $(".doc-left").css("height",'initial');
- $(".doc-left").css("min-height",'0px');
- $(".doc-right").removeClass("span12");
- $(".doc-head .right").hide();
- $(".page-edit-link").html('');
- $(".doc-left-newbar").html('');
- //$(".iframe_content").css("padding-left","30px");
- $(".iframe_content").css("width",'');
- $(".doc-left .nav-list li a i ").css("margin-left" , '10px');
- $(".search-input-append").css("width","100%");
- $(".search-query-input").css("width","70%");
- }
- function mScroll(id){
- $("html,body").stop(true);
- $("html,body").animate(
- {scrollTop: $("#"+id).offset().top},
- 2000);
- }
- //点击左侧菜单事件
- $(".doc-left li").click(function(){
- //先把所有菜单的激活状态取消
- $(".doc-left li").each(function(){
- $(this).removeClass("active");
- });
- //先判断是否存在子菜单
- if ($(this).children('.child-ul').length != 0) {
- //如果子菜单是隐藏的,则显示之;如果是显示状态的,则隐藏
- if ($(this).children('.child-ul').css("display") == "none") {
- $(this).children('.child-ul').show();
- $(this).children("a").children('i').attr("class","icon-chevron-down");
- }else{
- $(this).children('.child-ul').hide();
- $(this).children("a").children('i').attr("class","icon-chevron-right");
- }
- };
- //激活菜单
- $(this).addClass("active");
- //获取对应的page_id
- page_id = $(this).children("a").attr("data-page-id");
- page_title = $(this).children("a")[0].innerText;
- if (page_id != '' && page_id != null && page_id !='#') {
- if (page_title != '' && page_title != null) {
- document.title = page_title + " - ShowDoc";
- }
- change_page(page_id);
- //如果是移动设备的话,则滚动页面
- if( isMobile()){
- mScroll("page-content");
- }
- };
- return false;//禁止原有的href链接
- });
- //切换页面;
- function change_page(page_id){
- if(!page_id)return;
- var item_id = $("#item_id").val();
- var item_domain = $("#item_domain").val();
- var base_url = $("#base_url").val();
- var iframe_url = base_url+"/home/page/index/page_id/"+page_id;
- $(".page-edit-link").show();
- //$("#page-content").attr("src" , iframe_url);
- $("#edit-link").attr("href" , base_url+"/home/page/edit/page_id/"+page_id);
- $("#copy-link").attr("href" , base_url+"/home/page/edit/item_id/"+item_id+"/copy_page_id/"+page_id);
- $("#delete-link").attr("href" , base_url+"/home/page/delete/page_id/"+page_id);
-
- var domain = item_domain ? item_domain : item_id ;
- var cur_page_url = window.location.protocol +"//"+window.location.host+base_url+"/"+domain;
- if(base_url.length == 0){
- cur_page_url += "?page_id="+page_id;
- }else{
- cur_page_url += "&page_id="+page_id;
- }
- $("#share-page-link").html(cur_page_url);
- history.replaceState(null, null, cur_page_url);
- var single_page_url = window.location.protocol +"//"+window.location.host+base_url+"/page/"+page_id;
- $("#share-single-link").html(single_page_url);
- $("#qr-page-link").attr("src","?s=home/common/qrcode&size=3&url="+cur_page_url);
- $("#qr-single-link").attr("src","?s=home/common/qrcode&size=3&url="+single_page_url);
- 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>';
- $(".iframe_content").html(html);
- iFrameHeight();
-
- }
- //分享项目
- $("#share").click(function(){
- $("#share-modal").modal();
- //延迟绑定分享事件
- setTimeout(function(){
- $('#copy-item-link').zclip(
- {
- path: DocConfig.pubile +'/jquery.zclip/ZeroClipboard.swf',
- copy:function()
- {
- return $('#share-item-link').html();
- },
- afterCopy: function() {
- show_top_msg("已经成功复制到剪切板",2000);
- }
- });
- },500);
- return false;
- });
- //分享页面
- $("#share-page").click(function(){
- $("#share-page-modal").modal();
- //延迟绑定分享事件
- setTimeout(function(){
- $('#copy-page-link').zclip(
- {
- path: DocConfig.pubile +'/jquery.zclip/ZeroClipboard.swf',
- copy:function()
- {
- return $('#share-page-link').html();
- },
- afterCopy: function() {
- show_top_msg("已经成功复制到剪切板",2000);
- }
- });
- $('#copy-single-link').zclip(
- {
- path:DocConfig.pubile +'/jquery.zclip/ZeroClipboard.swf',
- copy:function()
- {
- return $('#share-single-link').html();
- },
- afterCopy: function() {
- show_top_msg("已经成功复制到剪切板",2000);
- }
- });
- },500);
- return false;
- });
- function iFrameHeight() {
- var ifr = document.getElementById('page-content');
- ifr.onload = function() {
- var iDoc = ifr.contentDocument || ifr.document;
- var height = calcPageHeight(iDoc);
- ifr.style.height = height + 'px';
-
- if(!isMobile() && $(window).width() > 1000){
- //调节左侧栏背景的最小高度
- if(height > document.body.clientHeight){
- $(".doc-left").css("min-height",(height+60) + 'px');
- }else{
- $(".doc-left").css("min-height",'100%');
- }
- }
-
- }
- }
- // 计算页面的实际高度,iframe自适应会用到
- function calcPageHeight(doc) {
- var cHeight = Math.max(doc.body.clientHeight, doc.documentElement.clientHeight)
- var sHeight = Math.max(doc.body.scrollHeight, doc.documentElement.scrollHeight)
- var height = Math.max(cHeight, sHeight)
- return height
- }
- var keyMap = {
- // 编辑
- "Ctrl+E": function() {
- location.href = $("#edit-link").attr('href');
- },
- // 删除
- "Ctrl+D": function() {
- if (confirm(lang["confirm_to_delete"]))
- location.href = $("#delete-link").attr('href');
- },
- // 新建页面
- "Ctrl+F1": function() {
- location.href = $("#new-like").attr('href');
- },
- // 新建目录
- "Ctrl+F2": function() {
- location.href = $("#dir-like").attr('href');
- }
- };
- if (!isMobile()) initKeys();
- function initKeys() {
- var $doc = $(document);
- $.each(keyMap, function(key, fn) {
- $doc.on('keydown', null, key, function(e) {
- e.preventDefault();
- fn();
- return false;
- });
- });
- }
- })
|