http://www.sufeinet.com/plugin.php?id=keke_group

苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

分布式系统框架(V2.0) 轻松承载百亿数据,千万流量!讨论专区 - 源码下载 - 官方教程

HttpHelper爬虫框架(V2.7-含.netcore) HttpHelper官方出品,爬虫框架讨论区 - 源码下载 - 在线测试和代码生成

HttpHelper爬虫类(V2.0) 开源的爬虫类,支持多种模式和属性 源码 - 代码生成器 - 讨论区 - 教程- 例子

查看: 5457|回复: 4

[vue.js] 一个坑逼的选项卡JS,主要是与Vue冲突

[复制链接]
发表于 2019-1-22 18:07:52 | 显示全部楼层 |阅读模式
[JavaScript] 纯文本查看 复制代码
(function () {
    var $sidebar = $('#sidebar'),
        $container = $('#container'),
        $pages = $('#pages'),
        $pageContent = $('#page-content'),
        w = $pageContent.width(),
        h = $(window).height() - parseInt($container.css('marginTop'));

    var Layout = {
        cache: ['home'],
        urlCache: ['home'],
        template: '<li>{text}<i class="icon small" data-page-off title="关闭"></i></li>',
        activeIndex: 0,
        togglePage: function (index) {
            index = $.isNumeric(index) ? index : $pages.find('li').filter(function () {
                return this.firstChild.nodeValue === index;
            }).index();

            $pageContent.children().hide().eq(index).show();
            $pages.children().removeClass('active').find('i').css('color', '#999');
            $pages.children().eq(index).addClass('active').find('i').css('color', '#f5694b');
            this.activeIndex = index;

            if (index === 0) {
                $('html, body').css('overflow-y', 'auto');
            } else {
                $('html, body').css('overflow', 'hidden');
            }

            $pages.css('width', function () {

                var w = 30;

                $(this).find('li').each(function (index, el) {
                    w += $(el).outerWidth();
                });

                return w + 'px';
            });

            return index;
        },
        addPage: function (text, url) {

            var index = this.hasUrl(url);

            if (index === -1) {
                var $fm = $('<iframe width="' + w + '" height="' + h + '" frameborder="0" src="' + url + '"></iframe>');
                $pageContent.append($fm);
                $fm.show().siblings().hide();

                var win = $fm[0].contentWindow;
                this.cache.push(win);
                this.urlCache.push(url);

                var $title = $(this.template.replace('{text}', text));
                $pages.append($title);
                index = $title.index();
            }

            return this.togglePage(index);
        },
        removePage: function (index) {
            if (index === 0) {
                return;
            }
            var $page = $pages.children().eq(index);
            $sidebar.find('.sidebar-list a').filter(function () {
                return this.innerHTML === $page[0].firstChild.nodeValue;
            }).removeAttr('pageIndex');
            $page.remove();
            $pageContent.children().eq(index).remove();

            this.cache.splice(index, 1);
            this.urlCache.splice(index, 1);
            this.togglePage(index - 1);
        },
        closeAll: function () {
            $pages.children(':gt(0)').remove();
            $pageContent.children(':gt(0)').remove();
            $sidebar.find('.sidebar-list a').removeAttr('pageIndex');
            $pages.children(':first').addClass('active');
            $pageContent.children(':first').show();

            this.cache = ['home'];
            this.urlCache = ['home'];
        },
        getWindow: function (index) {
            return this.cache[index || this.activeIndex];
        },
        load: function (index, url) {
            this.getWindow(index).location = url;
        },
        reload: function (index) {
            this.getWindow(index).location.reload();
        },
        hasUrl: function (url) {
            return $.inArray(url, this.urlCache);
        },
        pagesMove: function (len) {
            var w = parseInt($pages.css('width'));
            var mw = parseInt($pages.css('min-width'));

            if (w > mw) {

                $pages.css('left', function () {
                    var left = parseInt($(this).css('left'));
                    return (len > 0 ? Math.max(left - len, mw - w) : Math.min(left - len, 0)) + 'px';
                });
            }
        }
    };

    $sidebar.on('click', '.sidebar-handle', function () {
        var $arrow = $(this).find('.arrow');
        w = $('body').width();
        if ($arrow.hasClass('r')) {
            $sidebar.css('left', '-180px');
            $container.css({
                'margin-left': 0
            });
            $pages.css('margin-left', 0);

        } else {
            $sidebar.css('left', 0);
            $container.css('margin-left', '181px');
            $pages.css('margin-left', '181px');
            w = w - 181;
        }
        $arrow.toggleClass('r l');

        $('iframe').width(w);

    }).on('click', '.sidebar-list a', function () {
        var url = this.getAttribute('href'),
            pageIndex = $(this).attr('pageIndex');

        if ( Layout.hasUrl(url) === -1) {
            var index = Layout.addPage(this.innerHTML, url);
            $(this).attr('pageIndex', index);
        } else {
            Layout.togglePage(pageIndex || this.innerHTML);
            Layout.reload(); //重新刷新当前页
        }

        return false;
    });

    $pages.on('click', '[data-page-off]', function () {
        Layout.removePage($(this).parent().index());
        return false;
    }).on('click', 'li', function () {
        Layout.togglePage($(this).index());
        return false;
    }).on('dblclick', 'li', function () {
        Layout.removePage($(this).index());
        return false;
    });


    $(document).on('click', '#closeAll', function () {
        Layout.closeAll();
    }).on('click', '#reloadPage', function () {
        Layout.reload();
    }).on('click', '[data-to-left]', function () {
        Layout.pagesMove(100);

    }).on('click', '[data-to-right]', function (event) {
        Layout.pagesMove(-100);
    });

    $(window).load(function () {
        $pages.css('min-width', (w - 70) + 'px');
    })

    $(window).resize(function () {
        w = $container.width();
        h = $(this).height() - parseInt($container.css('marginTop'));
        $pages.css('min-width', (w - 70) + 'px');
        $('iframe').width(w).height(h);
    });

    window.Layout = Layout;


} ());






1. 开通SVIP会员,免费下载本站所有源码,不限次数据,不限时间
2. 加官方QQ群,加官方微信群获取更多资源和帮助
3. 找站长苏飞做网站、商城、CRM、小程序、App、爬虫相关、项目外包等点这里
发表于 2019-1-22 20:40:28 | 显示全部楼层
真是难得给力的帖子啊。
发表于 2019-1-23 09:58:41 | 显示全部楼层
强烈支持楼主ing……
发表于 2019-1-23 17:31:37 | 显示全部楼层
我只是路过打酱油的。
发表于 2019-1-24 09:40:23 | 显示全部楼层
强烈支持楼主ing……
您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

QQ|手机版|小黑屋|手机版|联系我们|关于我们|广告合作|苏飞论坛 ( 豫ICP备18043678号-2)

GMT+8, 2024-4-25 19:08

© 2014-2021

快速回复 返回顶部 返回列表