GithubHelp home page GithubHelp logo

jcubic / jquery.splitter Goto Github PK

View Code? Open in Web Editor NEW
241.0 19.0 96.0 119 KB

Plugin that split your content with draggable divider

License: GNU Lesser General Public License v3.0

CSS 7.91% JavaScript 73.73% HTML 18.36%

jquery.splitter's Introduction

jQuery Splitter

npm bower

jQuery Splitter is plugin that split your content with movable splitter between them.

Example

var splitter = $('#foo').height(200).split({
    orientation: 'vertical',
    limit: 10,
    position: '50%', // if there is no percentage it interpret it as pixels
    onDrag: function(event) {
        console.log(splitter.position());
    }
});
<div id="foo">
    <div id="leftPane">Foo</div>
    <div id="rightPane">Bar</div>
</div>

Limitations

You need to set the height of the container for splitter to work.

You can use this css:

.container {
  height: 100vh !important;
}

to force full height.

If you have wrappers inside left or right splitter and you create another splitter inside:

<div class="splitter"
  <div class="left">
    <div class="wrapper">
       <div class="top"></div>
       <div class="bottom"></div>
    </div>
  </div>
  <div class="right">
  </div>
</div>

wrapper is not directly inside left, so it will not get the full height (this is how CSS work), so in order to fix this case, you need to set the wrapper to proper height. Most likely you want:

.splitter .wrapper {
  height: 100%;
}

to fit full height of the left splitter.

Options

  • orientation - string 'horizontal' or 'vertical'.
  • limit - number or object {leftUpper: number, rightBottom: number} that indicate how many pixels where you can't move the splitter to the edge.
  • position - number or string with % indicate initial position of the splitter. (from version 0.28.0 you can use array of numbers or percents for multiple panels, array length need to have the same number as there are splitters so children.length - 1).
  • onDrag - event fired when draging the splitter, the event object is from mousemove
  • percent - boolean that indicate if spliter should use % instead of px (for use in print or when calling the window)

Methods

Instance returned by splitter is jQuery object with additional methods:

  • refresh()
  • option (name[, value]) - option setter/getter
  • position(number)|position([num1, num2, ...])|position() - position setter/getter (if you have 2 panels you can use single number to set the position for more panels you need to use array with panels - 1 same as number of splitters)
  • isActive - returns boolean
  • destroy() - remove splitter data

Demo

http://jquery.jcubic.pl/splitter.php

Patch Contributors

License

Copyright (C) 2010-2020 Jakub T. Jankiewicz <https://jcubic.pl/me>
Released under the terms of the GNU Lesser General Public License

jquery.splitter's People

Contributors

aeschylus avatar beskorsova avatar brulead avatar cxong avatar fbergeron avatar inelsonrocha avatar jcubic avatar lordjz avatar omphalos avatar plashenkov avatar roboncode avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jquery.splitter's Issues

[FR] Implement desplit.

Desplit means quitting the split mode, and having one of the panes occupy full area of the parent.

Something like this:
$(...).desplit();

When this is called, the staying pane completely fills the parent, while the splitter and the other pane disappears. Also, calling split() again toggles the split mode back on.

new wish : docking option (for minimize/resize)

Thanks for this wonderful plugin. best part we can have n number of panels, and it works smoothly.

just one more wish, can these panels have docking options (for minimize/resize) available.. this will really help in many scenarios

split().destroy bug with more than one splitter in place

First: I love your work. Unfortunately I found a bug (or I'm stupid :/ ).

Setting: I want to have a screen split by two splitters and I want to turn one splitter on and off by user request. So my plan was to use the $("xyz").split().destroy method and re-init the split on request.
However, after the "destroy" method is called, the split does not work anymore if re-done. And unfortunately I do not know why or how to fix that problem.

Attached there is a minimal working example where the latest jquery and jquery.splitter is included

splitter.zip

edit: problem on
Firefox 43.0
Chromium 47.0.2526.73
Chrome 47.0.2526.106 (for completes ;) )

double click event on splitter

hi,

thanks for great plugin. Is there any way, by which i can add 'double click' event on the splitter? I need it to minimize the panels

How to determine the splitter position when window size has changed

Hi,

I'm using the plugin as a horizontal splitter,the thing is that I'm trying to sets the splitter position at the middle at each time that the window size is been changed - meaning the upper and bottom parts will be 50% of the total height.

How can I determine and do it? It's sure not very that clear, thanks for any kind of help

Splitter does not trigger splitter.resize event

When I bind to the splitter.resize event, it does not trigger.

I believe the bug is on line 262 of jquery.splitter-0.15.0. Since the current_splitter already is the .splitter_panel, the following line doesn't trigger anything:

current_splitter.find('.splitter_panel').trigger('splitter.resize');

The line, therefore, should be:

current_splitter.trigger('splitter.resize');

This fixes the problem I was having when I tried to bind to the splitter.

P.S: I tried submitting a pull request, but I wasn't able to push my branch to this repo. I'm not sure if this is supposed to work—I've never tried submitting pull requests to repos I'm not a member of.

Adding and removing additional splitter breaks auto-resize

To reproduce:

  1. Create 2 splitters
  2. Remove one of them
  3. Re-size browser window

The result is the following error

Uncaught TypeError: Cannot read property 'refresh' of null on this line:
$.each(splitters, function(i, splitter) {
(=>) splitter.refresh();

The root cause is the way destroy() works: it sets the entry in 'splitters' array to 'null'. But $.each will iterate over nulls as well.

panel height

how i can set custom height and width for each panel

$('#mainDiv').height(600).split({orientation:'horizontal', limit:100});

in above code 600 is fix height for whole panel but i want to give one panel height of 200 and another 400.
any suggetion will be helpful.

To resize the splitter bar(s)

I am using this in a mobile application and need to adjust the bars so fingers can grab them. At there current size, hits hit or miss.
Is there a setting for this?

splitter.resize notifications received in parent even when not not affected by resizing a nested splitter

Refer to this demo which shows nested splitters: http://codepen.io/vsajip/pen/EPvYxb

When the horizontal divider is moved, both splitters get a splitter.resize notification - this is correct.

However, when the vertical divider is moved, which doesn't really affect the outer splitter, both splitters get a splitter.resize notification. This seems wrong, since the panes of the outer splitter haven't really been resized.

Change the package name from "jcubic/jquery.splitter" to "jquery.splitter" in bower.json

There was an error occurred while running bower install jquery.splitter to install the package:

$ bower install jquery.splitter
bower install jquery.splitter
bower cloning git://github.com/jcubic/jquery.splitter.git
bower cached git://github.com/jcubic/jquery.splitter.git
bower fetching jquery.splitter
bower checking out jquery.splitter#0.14.0
bower error Invalid name: "jcubic/jquery.splitter"

There were errors, here's a summary of them:
- jquery.splitter Invalid name: "jcubic/jquery.splitter"
An error was caught when reading the bower.json: Invalid name: "jcubic/jquery.splitter"

The slash character (/) is not allowed for defining a package name.
Could you change the package name from "jcubic/jquery.splitter" to "jquery.splitter" in bower.json? Thanks.

[enhancement] Add missing bower.json.

Hey, maintainer(s) of jcubic/jquery.splitter!

We at VersionEye are working hard to keep up the quality of the bower's registry.

We just finished our initial analysis of the quality of the Bower.io registry:

7530 - registered packages, 224 of them doesnt exists anymore;

We analysed 7306 existing packages and 1070 of them don't have bower.json on the master branch ( that's where a Bower client pulls a data ).

Sadly, your library jcubic/jquery.splitter is one of them.

Can you spare 15 minutes to help us to make Bower better?

Just add a new file bower.json and change attributes.

{
  "name": "jcubic/jquery.splitter",
  "version": "1.0.0",
  "main": "path/to/main.css",
  "description": "please add it",
  "license": "Eclipse",
  "ignore": [
    ".jshintrc",
    "**/*.txt"
  ],
  "dependencies": {
    "<dependency_name>": "<semantic_version>",
    "<dependency_name>": "<Local_folder>",
    "<dependency_name>": "<package>"
  },
  "devDependencies": {
    "<test-framework-name>": "<version>"
  }
}

Read more about bower.json on the official spefication and nodejs semver library has great examples of proper versioning.

NB! Please validate your bower.json with jsonlint before commiting your updates.

Thank you!

Timo,
twitter: @versioneye
email: [email protected]
VersionEye - no more legacy software!

Embedded splitters covering entire contents won't work

Hi, I've created a JSFiddle with a skeleton of the page I'm trying to do.
It has a horizontal splitter inside the right pane of a vertical splitter.

But the horizontal splitter just doesn't work - the dividing bar won't move and when the vertical pane is resized the horizontal splitter bounces back to a height of 0 and basically goes ballistic.

https://jsfiddle.net/o0tnchuy/7/

Is there an expectation of the html structure I'm missing?

I would really like to set the bottom horizontal pane to a set/fixed height, but it looks this library only uses the position property to set the top/left?

destroy splitter

Found a small bug, seems that in the destroy method 'splitters[i]' should be replaced with splitters[id]

demo not working

subj. demo page on jquery plugin page not working in current version of Firefox.

enforce limit on resize

Is there anyway you can make this enforce the limit on a resize? Currently you can resize and the limit is ignored.

Love the library. Thanks for making it. Love that is makes the mask div for hovering over objects and love the events for on drag and such.

Problem on Destroy Function

Hello!
Thank you for developing this component!

I believe there is a problem in the destroy function. Each time we remove a splitter from the screen with destroy(), we should also decrease the count variable. If we fail to do so, after destroying splitters and creating new ones, the component uses the wrong id on the new ones because the value of count is wrong.

Regards,
Toyo

Typo in demo.html

Just a little typo in the demo page
Demo attempts to load the splitter-0.5 script, but the repo now contains 0.6

jQuery .height() and .width() don't include padding and border

jQuery .height() and .width() are not equivalent to offsetHeight and offsetWidth since they don't include padding and border.

If we want to override the default splitter style with padding and border, the calculated height and width will be incorrect.

You can replace splitter.width() and splitter.height() with splitter.get(0).offsetWidth and splitter.get(0).offsetHeight, respectively, to overcome this issue.

onDrag event doesn't trigger

onDragStart and onDragEnd events trigger just fine, but onDrag event doesn't.
That is because in the binding:

.bind('mousemove.splitter', function(e) {
  ...
  if (current_splitter.orientation == 'vertical') {
    ...
      current_splitter.find('.splitter_panel').trigger('splitter.resize');
      return false;
    ...
  }
  if (current_splitter.orientation == 'horizontal') {
    ...
      current_splitter.trigger('splitter.resize');
      return false;
    ...
  }
  settings.onDrag(e);
}

"return false;" is always called and "settings.onDrag(e);" is never reached.

Need a method to give initial width or height

when doing

$('#content').split({orientation:'vertical', limit:100});

the spliter appears exactly in the middle making both child containers half size.
need a way to give a specific width to either container.
css does not work.

Adding overlay DIV while resizing

I noticed that you change $(body).css('cursor', ...) when user drags the splitter.
But what if I use special cursor for my document? I.e. I write in my CSS: body {cursor: default}. The splitter will override this CSS, this is not good.
I also noticed that you create DIV .splitterMask when user drags the splitter, and then remove it when he finishes dragging, but I did not found that it is used in other parts of your JS code or CSS rules.
I conjecture this must be something like overlay, and it is really what is necessary to make.
Please see this commit: 8723b3e
Here is an example: http://www.plashenkov.com/help/

Overlay allows to change a cursor the right way. It allows to prevent the :hover state of elements while dragging a splitter. And if one (or both) panel is an IFRAME, which does not allow to process a mousemove event, overlay solves this problem also.

3 column splitter

How to create a 3 column splitter with left pane starting at 300 width and max of 600. Similarly, the right pane starting at 300 width from right and max out at 600 from right. Middle pane to respond to either left or right splitter drag without overflowing in browser width?

3-col-splitter

3 column grid

Sorry JS is not really my specialty and I am trying to create an equal 3 column grid all vertical that can be re-sized, any ideas on how I would go about this?

Cheers,
Otis.

JQuery migration warning about "bind" method

While upgrading to the current version of JQuery (3.4.1), the migration tool threw this warning in jquery.splitter code (running version 0.27.1):

  | migrateWarn | jquery-migrate-3.0.1.js:76
  | bind | @ | jquery-migrate-3.0.1.js:499
  | $.fn.split | @ | jquery.splitter.min.js:5
  | initSplitter | @ | base.min.js:143 (our code)

Multiple Panels in one layer

Will it be possible to have multiple panels in one layer instead of having to nest panels?
My use case, I am displaying a file list as well as a file editor in one window (think Visual Studio panels), and I would like to be able to add and remove panels as I please to show the user multiple editor windows.
It doesn't make sense to have to nest the panels to do this, but rather have an array of panels. Is this planned for the future?

Drag & Drop across split

Hi, I tried to drag a draggable (jquery UI) across a split. Seem the object is confined to its split and I won't be able to drag it across the split line. Is there a setting on Splitter for me to drag and drop an object on a div across split line? Thanks.

"Invisible" splitter mode

Hello! Thank you for such good splitter!
I would like to suggest an improvement:
sometimes you do not want to have a bold splitter, you want just a slim 1px line. But it is inconvenient for users to hit this 1px splitter.
The solution is to make splitter "invisible" but presented over the boundary between two panels.
Please see this commit: b715d4f
Here is a working example: http://www.plashenkov.com/help/

One-line doco explaining basic usage would be nice

What's "limit" and do we need to create "div" elements for each splitter pane? (I would only know this if I'd used other splitter controls).

Just a few lines explaining these things would make this a lot better, I think.

I know the source code is there but that would be a copout.

How to add button in splitter for up and down

Hi ,
Is it possible to add button in splitter for up and down array? If i click up array then botton panel should show completely and upper panel should hide and vice-versa.
Please help

External 'splitter.resize' listener

How can I make the console.log was showed?

$('#v-handler').split({orientation: 'vertical'});

$('#v-handler').on('spliter.resize', function(){
  console.log("RESIZING")
})

Bad import !

I have download the plugin, but in demo.html, the file imported is jquery.splitter-0.12.0.js. So it doesn't work because the good file is jquery.splitter-0.14.0.js. Just need to change it :) .

Unable to render any splitter

Hi, I'm sorry but I cannot get this splitter to work at all.
There must be some assumption I am making about splitters that is not the case (I've used kendo splitter)

My web page, a HTML file attached - wrapped in .txt to allow it to be uploaded here.
it is self sufficient apart from the .css reference (there's no instruction that reminds you that a css inclusion is needed BTW)

Pretty similar to the demo.
All I want is the entire page, fully split vertically - into a left and right side.
Am I using the right plugin?

The code below is definitely running the plugin but not showing any splitters.
jquery-test.txt

Capture Resize Event

I'd like my UI to react whenever the splitter is moved. Could you add an event that I could latch on to when the splitter position is changed? Something like:

  $("#splitter")
    .split(
      {
        orientation: "vertical",
        limit: 200,
        position: (window.innerWidth - 200),
        resize: myResizeFuntion
      }
    );

And then myResizeFunction would be called each time the splitter position is changed?

Handling nested splitters.

When nesting multiple splitters with each other, I seem to have a problem in 0.13. The inner splitter doesn't resize as I'm resizing the outer splitter.

Currently, I'm handling it by catching the onDrag event of the outer splitter and triggering resize of the inner splitter manually in the callback, but I'm hoping there might be a better way. Here's a setup that reproduces this:

<div id="outerparent">
<div></div>
<div id="innerparent">
    <div></div>
    <div>
         <div id="child">
              <div></div>
              <div></div>
         </div>
    </div>
</div>
</div>
 $('#outerparent').split({
     orientation: 'vertical',
     limit: 200,
     position: '200px',
     onDrag: function () { $('#child').trigger('splitter.resize'); }
});

$('#innerparent').split({
   orientation: 'horizontal',
   limit: 100,
   position: '200px'
});

$('#child').split({
   orientation: 'vertical',
   limit: 200,
  position: '350px'
});

Removing the onDrag option causes the child splitter to no trigger resize as I'm resizing #outerparent.

Also, I'm pretty sure this wasn't an issue in the last (and ancient version) of the plugin I've been using - 0.8.0.

Dragging causes text to be selected in IE

I have a basic setup with a vertical splitter. If I drag the splitter, IE will select text in my panels. Is there a simple way to prevent this? I've just added an e.preventDefault to the mousedown event handler which fixes the problem. Any reason why that would be a bad idea?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.