Git Product home page Git Product logo

angular-resizable's Introduction

angular-resizable

A directive for creating resizable containers.

Why?

All other resizable directive concepts I came across include layout logic in the directive. I wanted a directive that only handled the resize logic. This way, the layout logic is quarantined to the CSS.

Usage

  1. npm install angular-resizable or bower install angular-resizable or clone/download this repo
  2. Include angular-resizable.min.js in your project.
  3. Include angular-resizable.min.css in your project as well (this provides default styling for the resize handles).
  4. Then include the module in your app: angular.module('app', ['angularResizable'])
  5. Use it: <section resizable r-directions="['bottom', 'right']" r-flex="true">

Include any sides you want to be resizable in an array inside r-directions. Accepts 'top','right','bottom', and 'left'. You can style the handles however you want. Just override the styles in the css in your own stylesheet.

Options

Attributes Default Accepts Description
rDirections ['right'] ['top', 'right', 'bottom', 'left',] Determines which sides of the element are resizable.
rFlex false boolean Set as true if you are using flexbox. See this codepen.
rCenteredX false boolean If set as true, the velocity of horizontal resizing will be doubled.
rCenteredY false boolean If set as true, the velocity of vertical resizing will be doubled.
rWidth false integer or $scope variable If set, the resizable element will be rendered with a predefined width relative to this value in pixels and a watcher will be set on the 'rWidth' attribute. See this codepen.
rHeight false integer or $scope variable If set, the resizable element will be rendered with a predefined height relative to this value in pixels and a watcher will be set on the 'rHeight' attribute. See this codepen.
rGrabber <span></span> string Defines custom inner html for the grabber.
rNoThrottle false boolean Disables angular-resizable.resizing throttling (see events section below).

Events

For an example using the events, see this codepen.

angular-resizable.resizeStart

This event is emitted at the beginning of a resize with the following info object:

  • info.width : The width of the directive at time of resize start. Will be false if resizing vertically
  • info.height : The height of the directive at time of resize start. Will be false if resizing horizontally
  • info.id : The id of the directive. Will be false if there is no id set.
  • info.evt : original mouse event object

angular-resizable.resizing

Called repeatedly while the mouse is being moved. By default, only calls once every 100ms to keep CPU usage low. For smooth resizing, use the rNoThrottle attribute. This event is emitted during the resizing of the element with the following object as an argument:

  • info.width : The width of the directive at time of resize end. Will be false if resizing vertically
  • info.height : The height of the directive at time of resize end. Will be false if resizing horizontally
  • info.id : The id of the directive. Will be false if there is no id set.
  • info.evt : original mouse event object

angular-resizable.resizeEnd

This event is emitted at the end of a resize with the following object as an argument:

  • info.width : The width of the directive at time of resize end. Will be false if resizing vertically
  • info.height : The height of the directive at time of resize end. Will be false if resizing horizontally
  • info.id : The id of the directive. Will be false if there is no id set.
  • info.evt : original mouse event object

version notes

1.2.0

  • Add angular-resizable.resizing event (see pull request #7)
  • Add attribute for providing custom inner html to the grabber element (see pull request #7)

License

MIT

angular-resizable's People

Contributors

ahdriel avatar elob avatar jedfoster avatar lemonl2 avatar nur-psoehnlein avatar omichelsen avatar philippsoehnlein avatar reklino avatar rhcad 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

angular-resizable's Issues

Is it compatible with Angular Material?

I'm trying to use this library with Angular Material but I can't get it work.
Look at this example:
I have a row with 2 md-content, one with flex at 20% and one with flex at 80%. My objective is to enlarge (resize) the first md-content if needed.

<div layout="row">
    <md-content flex="20">
    </md-content>
    <md-content flex="80">
    </md-content>
</div>

so I tried this (and also the opposite)

<div layout="row">
    <md-content flex="20" resizable r-directions="['right']" r-flex="true">
    </md-content>
    <md-content flex="80">
    </md-content>
</div>

How can I get it to work?

Save and restore state

angular-resizable is great! How would you go about saving and restoring the width/height of each resized section?

Please rename direcive

The resizable directive is colliding with another directive in a data-table module i am using. I have already requested them to rename it as per the best naming convention followed as discussed in this thread Directive Name Collision Issues and Best Practices #536
As it's much easier for you to do the renaming, will save me the effort of maintaining a separate fork :)
Also great plugin.

Usable with Angular Material

I just edited the source locally so this directive works with Angular Material's Textarea. Perhaps this could be of use or provide some hints. Perhaps not, but here it is anyway.

In order to use this with Angular Material's Textarea, the resizable attributes must be set to the <md-input-container> element:

<md-input-container class="md-block" resizable r-directions="['bottom']">
  <label>Biography</label>
  <textarea ng-model="user.biography" columns="1" md-maxlength="150" rows="5"></textarea>
</md-input-container>

If the attributes are set to the textarea element instead, the resize hint/icon won't appear, therefore the user won't be able to resize the textarea.

So I had to change the element that the resize is done against by simply detecting the tag name of the element:

link: function(scope, element, attr) {
    var draggingElement;

    if (element[0].tagName == 'MD-INPUT-CONTAINER') {
      draggingElement = element[0].getElementsByTagName('textarea')[0];
    } else {
      draggingElement = element[0];
    }

And finally I changed element[0] for draggingElement in both updateInfo and dragging functions. That was all.

It didn't work with with the r-flex option.

There's a small detail though: when the resizing starts, the height will jump certain amount of pixels, so it's not completely smooth at first.

unbind handle

Hello!

I am actually facing a problem.
Currently developping an app with resizable columns (so far it works), I plan to put a "condense" button which will wrap the column making it small. I tried many ways to remove the handle and so far no luck. If the handle is not removed, when I press the button, the handle does not adapt to the new content, so the handle does not move and there is a lot of space betweet that condensed column and the handle.

I hope I wasn't too confusing, anyone has an idea? Or is it actually something that isn't implemented?

Update npm

Hi. The latest releases on npmjs.org and here on Github, is not in sync with the latest repo changes, I.e, the rNoThrottle feature is missing from the releases both places.

Disable resize

I'd like an option to disable the resize functionality. I.e. what I'm looking for is an element that is resizable when a condition is true and not when it's false (so I can use an "Edit mode" button, and my div can only be resized when editmode == true)

Percentage Based Width?

Nice directive! Apologies if this is easy, still pretty new to Angular!

I wondered if its possible to return the width in percentage form?

Minor issues

Thanks for the great directive. I've played with your library somewhat and found a few issues that I've fixed. However, unfortunately my corporate firewall doesn't allow me to submit a PR, so I will highlight them here:

  1. 'rg-top' has an incorrect 'left' value. 'left' should change from 50% to 0.

  2. Dragging can cause the selection of elements in the panel. This can be disabled by adding the following to the bottom of dragStart:

            if(e.stopPropagation) e.stopPropagation();
            if(e.preventDefault) e.preventDefault();
            e.cancelBubble=true;
            e.returnValue=false;
    
  3. If you have height or width animations on the resizable div, it won't work smoothly. To fix this, add a no-transition class to the css:

    .resizable.no-transition {
    transition: none !important;
    }
    

    Then toggle it on in dragStart, and toggle it off in mouseup using the element.add/removeClass();

Internet Explorer: top direction selected, section expanding bottom side

Hi, I have defined my resizable sectionthis way:

Here there are the involved classes:

.lowthird{
min-height: 225px;
background: #0f1423; /* For browsers that do not support gradients /
background: -webkit-linear-gradient(#0f1423, #364c63); /
For Safari 5.1 to 6.0 /
background: -o-linear-gradient(#0f1423, #364c63); /
For Opera 11.1 to 12.0 /
background: -moz-linear-gradient(#0f1423, #364c63); /
For Firefox 3.6 to 15 /
background: linear-gradient(#0f1423, #364c63); /
Standard syntax */
z-index: 999;
left: 0;
right: 0;
bottom: 0;
flex: 1;
display: flex;
flex-flow: row nowrap;
margin-top: 6px;
}

@media screen and (-ms-high-contrast: active), (-ms-high-contrast: none) {
.lowthird{
bottom: 0;
}
}

.top-border{
border-top-style: solid;
border-top-width: 1px;
border-top-color: #edeeed;
}

In other browsers it works perfectly, but in IE it starts expanding on the bottom side

Lot of open PRs

@Reklino I was wondering if you want another dev to continue updating the gem, I can help with that, let me know and I can create a fork and start merging those PRs and adding new features

Add minimum width/height options

I tried to implement this with the following. I'm not familiar with flexbox so I ignored that, but something along these lines would be great.

            scope: {
                rDirections: "=",
                rCenteredX: "=",
                rCenteredY: "=",
                rWidth: "=",
                rHeight: "=",
                rFlex: "=",
                rGrabber: "@",
                rMinWidth: "=",
                rMinHeight: "="
            }
....

switch(dragDir) {
                        case 'top':
                            var newHeight = h + (offset * vy);
                            if(scope.rFlex) { element[0].style.flexBasis = newHeight + 'px'; }
                            else {            if(!scope.rMinHeight || ( newHeight > scope.rMinHeight)) { element[0].style.height = newHeight + 'px'; } }
                            break;
                        case 'right':
                            var newWidth = w - (offset * vx);
                            if(scope.rFlex) { element[0].style.flexBasis = newWidth + 'px'; }
                            else {            if(!scope.rMinWidth || ( newWidth > scope.rMinWidth)) { element[0].style.width = newWidth + 'px'; } }
                            break;
                        case 'bottom':
                            var newHeight = h - (offset * vy);
                            if(scope.rFlex) { element[0].style.flexBasis = h - (offset * vy) + 'px'; }
                            else {            if(!scope.rMinHeight || ( newHeight > scope.rMinHeight)) { element[0].style.height = h - (offset * vy) + 'px'; } }
                            break;
                        case 'left':
                            var newWidth = w + (offset * vx);
                            if(scope.rFlex) { element[0].style.flexBasis = newWidth + 'px'; }
                            else {            if(!scope.rMinWidth || ( newWidth > scope.rMinWidth)) { element[0].style.width = newWidth + 'px';} }
                            break;
                    }

Constrain Proportions options

Is there a way to constrain proportions to a specified width and height? I'm looking to define an initial width/height but they can resize it constrained.

Am i overlooking an option? If not maybe i can add it.

Usage with ngRepeat

Hi I'm curious if you have a suggestion for using your directive with ngRepeat. Specifically I want drag handles to the right of each box, except for the last one, but I see no way of disabling the directive on the last element?

Width/height should be obtained at dragStart

Hi, me again!

I've got some resizable panels whose height can change prior to them being resized. This results in the w/h values being incorrect because they're not updated until the mouseup event is captured. Is there any reason why these aren't set in dragStart? This also negates the need for them to be set on mouseup.

Drag-area appears under scrollbar when overflow auto is used

I just want to say this is a really great project and I've been finding it very helpful. I'm just having a problem with my scrollable content. I'm using a flex row layout with two div's side by side. Both are scrollable with overflow: auto in their styling.
This issue arises when I add the resizable direcitve to the left div and setting the drag direction to right. The appended rg-right div appears under the scrollable area and the user first has to scroll to it to use it. When the content is resized the width of the enitire div stays longer than the scrollable area and the scrollbar stays.
When I tried to add the directive to the right content I could not see the drag-bar at all.
Do you perhaps have a solution for this?

Angular Dependency in bower.json

Hi,

the bower.json states that angular-resizable works with Angular 1.3, which leads to a resolution request by bower when you do a bower install in a project which uses Angular 1.4.
Because I doubt that there are real compatibility problems with Angular != 1.3 (and Angular < 2) I would recommend to set the version statement in bower.json to 1.*.

rGrabber doesn't compile HTML

I would like the ability to use a full template in rGrabber so that I can do things like add ngClick functionality to elements within the grabber.

Issue with size adjustment after resizeEnd event

Hello everyone,

I have a problem that is demonstrated in the following example:
http://codepen.io/x3p8z/pen/BKXBPx

In this example, only line 21 in the JS file is changed from the original demo to:
$scope.dynamicSize.height = 50;

The expected behavior is that after every vertical resize, the size is reset to 50 px. This works the first time, but not for the following resize operations. While the value in the bottom left box is shown correctly as 50 all the time, the box has a different dimension.

I appreciate any inputs and hints how to achieve the desired behavior!

Issue with sizes when you have inline relative size

When you have a relative size in an inline CSS attribute, for example

<div resizable r-directions="['left']" style="width: 70%">
  …
</div>

the resize events do not convert the size into the proper absolute size.

Mouseup not raised if mouse is over an iframe

I've spent an hour or so trying to figure out why the resizer was sticking on some occasions. If you click the resizer, and quickly move it while letting go of the mouse over an iframe, the mouseup event never gets called. That means if you want to release the resizer, you have to click again.

I've tried a quick few hacks to fix this, and I can't see how to do it easily if you're using a cross-origin iframe. The only thing I can think of, is to add an element to cover the entire screen while dragging, to make sure the events are raised on the current document.

Any ideas? If not, I'll try and make the modifications and submit the code here.

General question

Hi,
We are trying to implement the flexible dashboard for our requirement. we are using the packery to have the backfill of the cards when a card is removed or for reshuffling the cards on the dashboard.

We are trying to implement the resize functionality as how in this directive is used, on the top of packery.

We are using the below packery angular directive from git hub, this directive wraps the packery functionality, but not exposing the resize functionality for a card (Widget)

https://github.com/Dilatorily/packery-angular
http://dilatorily.github.io/packery-angular/#/api/packery-angular

Can you please shed some light on this, any suggestions on how to accomplish this on the top of packery using angular.

Thanks in advance.

Resize a browser window

What about to call this function:
$scope.$on("angular-resizable.resizeEnd", function (event, args)

when I resize not a resizable container, but a browser window?

Bind resize to grid

Hi, in the project I am working on I need to bind resizing to a grid, resizing the element only by discrete steps.
I introduced few minor changes into your source code (mainly a new scope param "rGrid", which accepts an x,y grid size array).

If you agree, I would like to submit you the code for a review, maybe through a pull request or putting the code somewhere online.

I also noticed a slight difference in the value of "width" returned by

w = parseInt(style.getPropertyValue("width"));

inside

var dragStart = function(e, direction) {}

I then decided to retrieve it by using:

var elRect = element[0].getBoundingClientRect();
 w = parseInt(elRect.width);

What do you think?

Thx!

Dynamic directions values

I've got angular-resizable working very well on my app, thank you! Now I'm trying to wire it up to user preferences; e.g. a user can change the orientation of resizable panels on the page.

Using this, r-directions="[(preferences.orientation === 'vertical' ? 'bottom' : 'right')]", I am able to set the orientation correctly on the initial page load (preferences is an object stored in localStorage), but I don't see a way to make angular-resizable respond to changes to that scope property after the initial load. Is there a way to make angular-resizable re-render itself?

Thanks!

Safari and flexbox doesn't work

Since Safari <=8 still uses the vendor prefix webkitFlexBasis, resizing doesn't work.

Solution would be to do feature detection and choose the correct property.

Angular-Resizable not working on ie 10,9 and 8

I have used the angular-resizable in our webapp which is working fine on IE10+ browsers but when i try to run the app on IE10, 9 and 8 , the splitter stops working. So just want to get confirmation that the angular-resizable is compatible with those versions of internet explorer or not.

And what will be the possible ways to make it working on lower versions of IE. Thanks in advance.

Scope model inside resize events?

I would like to know if possible to retrieve scope model inside resizeStart/resizeEnd events.
For instance: I am using angular-resizable inside a ng-repeat, and I would like to operate on the underlying model on resizeEnd.
Is it possible to add custom params to resize events?
Obviously, we always have the option of something like: angular.element(e.target).scope()...
Or maybe it's simpler just to wrap the resizable object into a directive linked to the model (which is maybe the best solution).

Thank you very much!

events are only being $emitted, should they also be $broadcasted

I was trying to resize a table inside of a resizable container by trying to hook into the 'resizeEnd' event.

My solution was to catch the event at the top controller and then $broadcast an event.

Would it be better if this component also broadcasted these events instead of having them to echo back?

Touch support for Webkit ?

Hello,

There seems to be an issue with - at least - Chrome when trying to resize an panel, is there anyone else who ran into the same problem ?

Thank you !

M

EDIT : Bower version has no touch support. Sorry.

Module is named 'app'

Sorry, me again! Just tried to pull the NPM package, and it appears the directive is registered to a module called 'app'. This means the usage instructions don't work :/

I've renamed 'app' to 'angularResizable' and then referenced that in my app module.

Please support touch screen from mobile devices

Can you please support touch from mobile devices?
basically need to add the touchstart, touchend and touchmove when registering to events and removing registration, you can use the following event strings instead of the existing:

touchstart mousedown
touchmove mousemove
touchend mouseup

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.