123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420 |
- var $taskContentInner = null;
- var $mainIframe = null;
- var tabwidth = 118;
- var $loading = null;
- var $navWraper = $("#nav-wrapper");
- var $content;
- var topMenuWidth = [];
- var headerHeight = 80;
- var openMenuHeight = 43;
- $(function () {
- // 各模块高度计算
- $mainIframe = $("#mainiframe");
- $content = $("#content");
- $loading = $("#loading");
- $content.height($(window).height() - headerHeight);
- $navWraper.height($(window).height() - headerHeight);
- $('.nav-list').css({"max-height": $(window).height() - headerHeight - 70, overflowY: 'auto'});
- $(window).resize(function () {
- $navWraper.height($(window).height() - headerHeight);
- var h = 0;
- if ($('.admin-tab:visible').length) {
- h = openMenuHeight;
- }
- $content.height($(window).height() - headerHeight - h);
- $('.nav-list').css({"max-height": $(window).height() - headerHeight - 70, overflowY: 'auto'});
- });
- // iframe 加载状态改变
- $("#content iframe").load(function () {
- $loading.hide();
- });
- // 多页面标签控制
- $taskContentInner = $(".admin-tab_inner");
- /*$(".admin-tab_inner").on("click", "li", function () {
- openapp($(this).attr("app-url"), $(this).attr("app-id"), $(this).attr("app-name"));
- return false;
- });
- $(".admin-tab_inner").on("dblclick", "li", function () {
- closeapp($(this));
- return false;
- });
- $(".admin-tab_inner").on("click", ".admin-tab_close", function () {
- closeapp($(this).parents('li'));
- return false;
- });
- $(".admin-tab_next").click(function () {
- var marginLeft = $taskContentInner.css("margin-left");
- marginLeft = marginLeft.replace("px", "");
- var contentInner = $(".admin-tab_inner").width();
- var contentWidth = $(".admin-tab").width();
- if (contentInner < contentWidth) {
- return false;
- }
- var lessWidth = contentWidth - contentInner;
- marginLeft = marginLeft - tabwidth <= lessWidth ? lessWidth : marginLeft - tabwidth;
- $taskContentInner.stop();
- $taskContentInner.animate({"margin-left": marginLeft + "px"}, 300, 'swing');
- });
- $(".admin-tab_prev").click(function () {
- var marginLeft = $taskContentInner.css("margin-left");
- marginLeft = parseInt(marginLeft.replace("px", ""));
- marginLeft = marginLeft + tabwidth > 0 ? 0 : marginLeft + tabwidth;
- // $taskContentInner.css("margin-left", marginLeft + "px");
- $taskContentInner.stop();
- $taskContentInner.animate({"margin-left": marginLeft + "px"}, 300, 'swing');
- });
- $('.admin-tab_inner>li:eq(1)').dblclick();
- // 空间计算
- $('.navbar-topnav li').each(function (index, item) {
- topMenuWidth[index] = $(this).width();
- });
- handleTopSpace();
- // 绑定事件
- $(window).resize(function () {
- handleTopSpace();
- });*/
- // 当前页面刷新
- $("#refresh-wrapper").click(function () {
- var $currentIframe = $("#content iframe:visible");
- $loading.show();
- //$currentIframe.attr("src",$currentIframe.attr("src"));
- $currentIframe[0].contentWindow.location.reload();
- return false;
- });
- // 首页隐藏左侧子菜单
- $('#sidebar').hide();
- // 初始切换到第一个一级目录
- /* switchMenu($('.navbar-topnav > li:eq(0)').attr('id'));*/
- //向左收缩事件
- // $('.navbar-toggle').click(function () {
- $('.sidebar_back').click(function () {
- if ($('#sidebar').hasClass('menu-min')) {
- $('.navbar-brand').animate({width: 200}, 0);
- $('#sidebar').animate({width: 200}, 0, function () {
- // $('#sidebar').removeClass('menu-min').find('.submenu .submenu').show();
- $('#sidebar').removeClass('menu-min');
- $('.sidebar_back').removeClass('menu-min');
- });
- } else {
- $('.navbar-brand').animate({width: 90}, 0);
- $('#sidebar').animate({width: 90}, 0, function () {
- // $('#sidebar').addClass('menu-min').find('.submenu .submenu').hide();
- $('#sidebar').addClass('menu-min');
- $('.sidebar_back').addClass('menu-min');
- });
- }
- });
- $('#sidebar').on('mouseenter', '.submenu li', function () {
- if ($(this).parents('.menu-min').length) {
- // $(this).find('.submenu').show();
- }
- });
- $('#sidebar').on('mouseleave', '.submenu li', function () {
- if ($(this).parents('.menu-min').length) {
- $(this).find('.submenu').hide();
- }
- });
- // 二级菜单点击事件
- $('.nav-list').on('click', '.outter>li', function () {
- if ($(this).attr('propagation') === 'stop') {
- $(this).removeAttr('propagation');
- return false;
- };
- $(this).find('ul').slideToggle(300, function () {
- $(this).toggleClass('open').find('>ul').removeAttr('style');
- }.bind(this));
- if (!$(this).hasClass('active')) {
- var $openLi = $(this).siblings('li.open:not(.active)');
- $openLi.find('ul').slideToggle(300, function () {
- $openLi.toggleClass('open').find('>ul').removeAttr('style');
- }.bind(this));
- }
- });
- // 位置栏切换事件
- $('.info_list').on('click', '.info_cnt', function () {
- var $id = $(this).attr('data-id');
- var $menu1st = $('li[data-menuid="' + $id + '"]');
- var $menu2nd = $('li[data-appid="' + $id + '"]');
- if ($(this).index() == 0) {
- $('[propagation="stop"]').removeAttr('propagation');
- $menu1st.find('>.submenu>li.active').attr('propagation', 'stop');
- switchMenu($id);
- } else if ($(this).index() == 1) {
- $('[propagation="stop"]').removeAttr('propagation');
- $menu2nd.attr('propagation', 'stop').find('.submenu>li:eq(0)>a').click();
- }
- });
- });
- function closeapp($this) {
- if (!$this.is(".noclose")) {
- if ($this.is('.active')) {
- $this.prev().click();
- }
- $this.remove();
- var appId = $this.attr("app-id");
- $("#appiframe-" + appId).remove();
- $('.nav-list li[data-appid="' + appId + '"]').removeClass('active');
- $(".admin-tab_prev").click();
- }
- }
- var task_item_tpl = '<li class="admin-tab_item">' +
- ' <a class="admin-tab_text">' +
- ' <i class="admin-tab_txt"></i>' +
- ' <i class="admin-tab_close fa fa-remove"></i>' +
- ' </a>' +
- '</li>';
- var appiframe_tpl = '<iframe style="width: 100%; height: 100%;" frameborder="0" class="appiframe"></iframe>';
- function openapp(url, appId, appname, refresh) {
- // 阻止冒泡
- var event = window.event || arguments.callee.caller.arguments[0];
- if (event) {
- event.stopPropagation();
- }
- // 调整 iframe 高度
- $content.height($(window).height() - headerHeight - openMenuHeight);
- // 通过 appId 寻找对应的三级菜单
- var $menu3rd = $('.nav-list').find('li[data-appid="' + appId + '"]');
- var $menu2nd = $menu3rd.parents('li:eq(0)');
- $('[propagation="stop"]').removeAttr('propagation');
- $menu2nd.attr('propagation', 'stop');
- if ($menu3rd.length === 0) {
- $menu3rd = $('.nav-list').find('.submenu .submenu .menu-text:contains(' + appname + ')').parent();
- $menu2nd = $menu3rd.parents('li:eq(1)');
- var menuid = $menu3rd.parents('li[data-menuid]').attr('data-menuid');
- switchMenu(menuid, false);
- $('[propagation="stop"]').removeAttr('propagation');
- $menu2nd.attr('propagation', 'stop');
- setTimeout(function () {
- $menu3rd.click();
- }, 0);
- }
- if (!$menu2nd.hasClass('active')) {
- $menu2nd.addClass('active open').siblings().removeClass('open');
- }
- //位置栏内容
- var menus = [];
- menus[0] = $('.navbar-topnav li.active .menu-text');
- menus[1] = $menu3rd.parents('li:eq(0)').find('> a > .menu-text');
- menus[2] = $menu3rd.find('> a > .menu-text', this);
- var remark = menus[2].attr('remark');
- $('.info_list').html('');
- $('.game-intro b').text(menus[2].text());
- $('.game-intro p').text(remark);
- for (var i = 0; i < menus.length; i++) {
- var parentNode = menus[i].parents('li:eq(0)');
- $('.info_list').append('<span class="info_cnt" data-id="' + (parentNode.attr('id') || parentNode.attr('data-appid')) + '">'+menus[i].text()+'</span>');
- }
- var $app = $(".admin-tab_inner li[app-id='" + appId + "']");
- $(".admin-tab_inner .active").removeClass("active");
- $('.nav-list .active').removeClass('active');
- $('.nav-list li[data-appid="' + appId + '"]').addClass('active').parents('li:eq(0)').addClass('active');
- $('#contextmenu').hide();
- if ($app.length == 0) {
- var task = $(task_item_tpl).attr({"app-id": appId, "app-url": url, "app-name": appname}).addClass("active");
- // var icon = $('[data-appid="' + appId + '"]').find('.fa').clone();
- // task.find('.admin-tab_text').prepend(icon);
- task.find(".admin-tab_txt").html(appname).attr("title", appname);
- $taskContentInner.append(task);
- $(".appiframe").hide();
- $loading.show();
- $appiframe = $(appiframe_tpl).attr("src", url).attr("id", "appiframe-" + appId);
- $appiframe.appendTo("#content");
- $appiframe.load(function () {
- var srcLoaded = $appiframe.get(0).contentWindow.location.href;
- if (srcLoaded.indexOf('admin/public/login') >= 0) {
- window.location.reload(true);
- }
- $loading.hide();
- });
- task.contextmenu(function (event) {
- event.preventDefault();
- var $contextmenu = $('#contextmenu');
- if ($contextmenu.length > 0) {
- $('#contextmenu').attr('curId', appId).css({'display': 'block', 'left': event.pageX, 'top': event.pageY});
- return false;
- }
- $('body').append('<div id="contextmenu" class="contextmenu"></div>');
- $('#contextmenu').attr('curId', appId).css({'left': event.pageX, 'top': event.pageY}).append('<a id="closeCurrent" href="javascript:;">关闭当前</a><a id="closeOther" href="javascript:;">关闭其他</a><a id="closeAll" href="javascript:;">关闭全部</a>');
- // 关闭当前
- $('#closeCurrent').click(function () {
- $('.admin-tab_inner li[app-id="' + $('#contextmenu').attr('curId') + '"]').dblclick();
- });
- // 关闭其他
- $('#closeOther').click(function () {
- $('.admin-tab_inner li').not(function (index) {
- return $(this).is('.noclose') || $(this).attr('app-id') === $('#contextmenu').attr('curId');
- }).dblclick();
- });
- // 关闭全部
- $('#closeAll').click(function () {
- $('.admin-tab_inner li:not(".noclose")').dblclick();
- });
- $(document).click(function () {
- $('#contextmenu').hide();
- });
- });
- } else {
- $app.addClass("active");
- $(".appiframe").hide();
- var $iframe = $("#appiframe-" + appId);
- var src = $iframe.get(0).contentWindow.location.href;
- src = src.substr(src.indexOf("://") + 3);
- if (refresh === true) {//刷新
- $loading.show();
- $iframe.attr("src", url);
- $iframe.load(function () {
- var srcLoaded = $iframe.get(0).contentWindow.location.href;
- if (srcLoaded.indexOf('admin/public/login') >= 0) {
- window.location.reload(true);
- }
- $loading.hide();
- });
- }
- $iframe.show();
- }
- var taskContentInner = $(".admin-tab_inner").width();
- var contentWidth = $(".admin-tab").width();
- if (taskContentInner <= contentWidth) { //如果没有开始滚动就不用进行下去了
- return;
- }
- var currentTabIndex = $(".admin-tab_inner li[app-id='" + appId + "']").index();
- var itemOffset = 0;
- var currentTabWidth = $(".admin-tab_inner li[app-id='" + appId + "']").width();
- $(".admin-tab_inner li:lt(" + currentTabIndex + ')').each(function () {
- itemOffset = itemOffset + $(this).width();
- });
- var cssMarginLeft = $taskContentInner.css("margin-left");
- cssMarginLeft = parseInt(cssMarginLeft.replace("px", ""));
- var marginLeft = currentTabWidth + itemOffset - contentWidth + cssMarginLeft;
- if (marginLeft > 0) {
- marginLeft = -(currentTabWidth + itemOffset - contentWidth);
- $taskContentInner.animate({"margin-left": marginLeft + "px"}, 300, 'swing');
- return;
- }
- if (itemOffset + cssMarginLeft < 0) {
- marginLeft = -itemOffset
- $taskContentInner.animate({"margin-left": marginLeft + "px"}, 300, 'swing');
- return;
- }
- }
- /**
- * 一级菜单切换
- */
- function switchMenu (id, subOpen) {
- subOpen = subOpen === undefined ? true : subOpen;
- // 一级菜单
- $('#'+id).addClass('active').siblings().removeClass('active');
- // 二级菜单
- var $subMenu = $('.nav-list li[data-menuid="' + id + '"]');
- $subMenu.show().siblings().hide().find('.open').removeClass('open');
- // $('.toggle-topnav li').removeClass('active');
- // $('#'+id+'-2').addClass('active');
- // 三级菜单
- if (subOpen) {
- $subMenu.find('>.submenu .submenu>li:eq(0)>a').click().parent().addClass('active');
- }
- /*if(!$('.nav-list li[data-menuid="' + id + '"]'+">.submenu .submenu").length){
- // $('.nav-list li[data-menuid="' + id + '"]'+">.submenu li:eq(0)>a").click();
- }*/
- // 左侧栏显示
- $('#sidebar').show();
- // 多页面标签 && 面包屑
- $('.admin-tab').show();
- }
- function openFrame (ppid, id, url) {
- var $parent = $('[id^="' + ppid + '"')
- $parent.find('> a').click()
- var _t = window.setInterval(function () {
- var $self = $('[data-appid^="' + id + '"')
- if ($self.length) {
- window.clearInterval(_t)
- $self.find('> a').click()
- }
- }, 60)
- }
- /**
- * 一级菜单空间控制
- */
- function handleTopSpace () {
- var topToggle = '<li class="topnav-toggle dropdown"><a href="javascript:;" class="dropdown-toggle" data-toggle="dropdown"><span class="icon-point"></span><span class="icon-point"></span><span class="icon-point"></span></a><ul class="toggle-topnav dropdown-menu pull-right"></ul></li>';
- if (!$('.topnav-toggle').length) {
- // 在一级菜单最后追加显示被隐藏菜单的入口
- $('.navbar-topnav').append(topToggle);
- }
- /*
- for (var i = 0, j = 0; i < topMenuWidth.length; i++) {
- j += topMenuWidth[i];
- var item = $('.navbar-topnav li').eq(i);
- if (winWidth - 500 > j) {
- if (item.is(':hidden')) {
- $('.toggle-topnav li[index="' + i + '"]').remove();
- item.show();
- }
- } else {
- if (item.is(':visible')) {
- $('.toggle-topnav').prepend(item.clone(true).show().attr({'index': i, 'id': item.attr('id') + '-2'}));
- item.hide();
- }
- }
- }
- */
- if (!$('.toggle-topnav li').length) {
- $('.topnav-toggle').remove();
- }
- }
- $('.tips').hover(function() {
- var offset = $(this).offset();
- $('.game-intro').show().css({
- left: offset.left + 20,
- top: offset.top
- });
- },function(){
- $('.game-intro').hide();
- });
|