Browse Source

Integrate splitter for main view

Vijayakrishnan Krishnan 5 năm trước cách đây
mục cha
commit
30e0542ced

+ 21 - 0
public/v-splitter-px/v-splitter.css

@@ -0,0 +1,21 @@
+.v-split {
+    position: absolute;
+    /*height: 100%;*/
+    width: 6px;
+    background: gray;
+    opacity: 0.3;
+    box-sizing: border-box;
+    cursor: ew-resize;
+    z-index: 2;
+    margin-left: 3px;
+    border-radius: 3px;
+    margin-top: 2px;
+    height: calc(100% - 4px);
+}
+.v-moving .v-split-active, .v-split:hover {
+    opacity: 0.5;
+}
+
+.v-moving .v-split-panel {
+    pointer-events: none;
+}

+ 59 - 0
public/v-splitter-px/v-splitter.js

@@ -0,0 +1,59 @@
+function initVSplitter(_name, _left, _right, _alignTo = null) {
+
+    var minSplitWidth = 300;
+
+    if($('.v-split[data-name="' + _name + '"]').length) return;
+
+    if(localStorage['v-split-rounded-' + _name]) {
+        var tempFinalLeft = Math.round(parseFloat(localStorage['v-split-rounded-' + _name]));
+        _left.css({flex: '0 0 ' + tempFinalLeft + '%'});
+        _right.css({flex: '0 0 ' + (100 - tempFinalLeft) + '%'});
+    }
+
+    var origLeft = -1, finalLeft = -1, origX = -1, vMoving = false, totalWidth = _left.parent().width();
+    _left.parent().css({position: 'relative'});
+    _left.addClass('v-split-panel').css({maxWidth: 'unset', minWidth: 'unset'});
+    _right.addClass('v-split-panel').css({maxWidth: 'unset', minWidth: 'unset'});
+    const vSplit = $('<div/>').addClass('v-split').attr('data-name', _name).insertAfter(_left);
+
+    function _setSplitterHeight() {
+        if(!_alignTo) return;
+        vSplit.css({marginTop: (_alignTo.position().top + 'px'), height: (_alignTo.outerHeight())});
+    }
+    _setSplitterHeight();
+
+    vSplit.css({left: (_left.outerWidth() * 100 / totalWidth) + '%'})
+        .off('mousedown.' + _name).on('mousedown.' + _name, function(_e) {
+            totalWidth = _left.parent().width();
+            origLeft = vSplit.position().left;
+            origX = _e.screenX;
+            vMoving = true;
+            $('body').addClass('v-moving');
+            $(this).addClass('v-split-active');
+            return false;
+        });
+
+    $(document)
+        .off('mousemove.' + _name).on('mousemove.' + _name, function(_e) {
+            if(!vMoving) return;
+            var tempFinalLeft = origLeft + (_e.screenX - origX);
+            if(tempFinalLeft < minSplitWidth || tempFinalLeft > (totalWidth - minSplitWidth)) return;
+            finalLeft = tempFinalLeft;
+            vSplit.css({left: ((tempFinalLeft * 100) / totalWidth) + '%'});
+        })
+        .off('mouseup.' + _name).on('mouseup.' + _name, function(_e) {
+            if(!vMoving) return;
+            vMoving = false;
+            $('body').removeClass('v-moving');
+            var tempFinalLeft = ((_left.outerWidth() + (finalLeft - origLeft)) * 100 / totalWidth);
+            tempFinalLeft = Math.round(tempFinalLeft);
+            _left.css({flex: '0 0 ' + tempFinalLeft + '%'});
+            vSplit.css({left: (_left.outerWidth() * 100 / totalWidth) + '%'})
+            _right.css({flex: '0 0 ' + (100 - tempFinalLeft) + '%'});
+            $('.v-split-active').removeClass('v-split-active');
+            localStorage['v-split-rounded-' + _name] = tempFinalLeft;
+        });
+
+    $(window).off('resize.' + _name).on('resize.' + _name, function(_e) { _setSplitterHeight(); });
+    $(window).off('scroll.' + _name).on('scroll.' + _name, function(_e) { _setSplitterHeight(); });
+}

+ 8 - 3
resources/views/mc.blade.php

@@ -5,18 +5,23 @@
     <meta name="viewport"
           content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
     <meta http-equiv="X-UA-Compatible" content="ie=edge">
-    <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
     <link rel="stylesheet" href="/css/bootstrap.min.css">
     <title>Meeting Center</title>
 </head>
 <body class="d-flex align-items-stretch h-100">
     <div class="row w-100">
-        <div class="col-9 pr-0">
+        <div class="col-9 pr-0 app-left-panel">
             <iframe src="{{ $page }}" frameborder="0" class="h-100 w-100"></iframe>
         </div>
-        <div class="col-3 border-left">
+        <div class="col-3 border-left app-right-panel">
             Meeting stuff goes here
         </div>
     </div>
+    <script src="/AdminLTE-3.0.5/plugins/jquery/jquery.min.js"></script>
+    <link rel="stylesheet" href="/v-splitter-px/v-splitter.css">
+    <script src="/v-splitter-px/v-splitter.js"></script>
+    <script>
+        initVSplitter('stag-mc-main', $('.app-left-panel'), $('.app-right-panel'));
+    </script>
 </body>
 </html>