Code Monkey home page Code Monkey logo

angularjs-scroll-glue's Introduction

angular-scroll-glue Build Status

An AngularJs directive that automatically scrolls to the bottom of an element on changes in its scope.

Install

Bower

$ bower install angular-scroll-glue --save

npm

$ npm i angularjs-scroll-glue

Usage

// Add `luegg.directives` to your module's dependencies.
angular.module('yourModule', [
	...,
	'luegg.directives'
]);
<div scroll-glue>
	<!-- Content here will be "scroll-glued". -->
</div>

<div scroll-glue="glued">
	<!-- Content here will be "scroll-glued" if the passed expression is truthy. -->
</div>

<div scroll-glue force-glue>
	<!-- Content here will be "scroll-glued" even if user manually scroll top. -->
</div>

<div class="parent" scroll-glue>
    <div class="child1" scroll-glue-anchor></div>
    <div class="child2" scroll-glue-anchor></div>
	<!-- Parent here will be "scroll-glued" according to the child1 and child2 size change event -->
</div>

More information can be found in the live demo.

Live demo

Demo Plunk

Contribute

Despite this is a ultra specialized library, there will always be a fix to be made or a new feature to be added and I'm glad for any contributions. But please make sure to check the following before committing a pull request:

  1. Make sure the unit tests pass. Just run npm test and check if all is green.
  2. Try to add new tests that cover your changes.
  3. Make sure you do not introduce changes that break backward compatibility unless there is a really good reason to.

License (MIT)

Copyright (C) 2013 Luegg

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

angularjs-scroll-glue's People

Contributors

chrismbarr avatar dani3l avatar hackfan avatar jimtotheb avatar kamalkhan avatar liollury avatar luegg avatar oliversalzburg avatar williamboman 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

angularjs-scroll-glue's Issues

Why watch function calling multiple times???

Hi,
I just use your angular directive code for scroll bottom in chat box but i realized watch function calling number of times.
According to angular documentation it should be call only two times. so could you tell me why it is calling multiple times?

Scroll Glue with Jade

Hello,

I'm having a hard time getting the library to work. I've got the dependency injecting on the highest level/module like such:

angular.module('secureMessagingApp', [ ... 'luegg.directives' ]) ...

, so therefore, every I assume that every nested module and nested DOM element with "scroll-glue" should work.

And in my Jade file I've defined it as such:

#chat.container-fluid(xeditable-focus='',ng-controller='ChatCtrl') .row(scroll-glue="glued") .col-lg-12.padding-top-10

, which evaluates to:

`

...`

I've got a scope variable "glued = true"

The page loads with the script at the bottom as this:
<script src="bower_components/angular-scroll-glue/src/scrollglue.js"></script>

I've run the installation as outlined. Not sure if the injection has to be done on the 'ChatCtrl' controller, or if it is acceptable to do it on the highest level as it currently is.

I can't get any indication the module is actually working. Any help would be much appreciated! Thanks!

Maintaining this module

I would be interested in taking over maintenance of this module. Please get in touch with me if you're interested.

Issue with Scope setting

Firstly, I've just started with Angular so this may be a basic question. But your directive looks like just what I need. I have been playing with this for few hours and I'm stumped so would really appreciate some help.

I have a simple chat app (basically the pusher angular mini version which is at pubnub/angular-js). I haven't altered anything except formatting with bootstrap. Everything but the scroll-glue is working fine. I am trying to scroll to the bottom of the message div with every new message but no dice. Not sure if I'm applying the glue to the correct scope. There is no scope for just "messages" so I applied the glue to scope that contains the messages as that should trigger the glue (or at least I thought it would). I did try it all the scopes and still no dice. Thus my "stumpedness".

The model/scope output in the debugger looks like below:

{ 
userId: User 878
channel: ChatX Channel
messages: 
[ Welcome to ChatX Channel, [User 39] Woot, [User 4] fleh, [User 4] dammit, [User 878] test, [User 878] what? ]
publish: null
glued: true
users: 
[ User 4, User 878 ]
newMessage: 
 } 

. As there no defined scope for the messages alone I set the option in the only scope available that would trigger the directive (in the register function at the bottom):

angular.module('PubNubAngularApp', ["pubnub.angular.service"])
.controller('ChatCtrl', function($rootScope, $scope, $location, PubNub) {
  // make up a user id (you probably already have this)
  $scope.userId   = "User " + Math.round(Math.random() * 1000);
  // make up a channel name
  $scope.channel  = 'ChatX Channel';
  // pre-populate any existing messages (just an AngularJS scope object)
  $scope.messages = ['Welcome to ' + $scope.channel];

  if (!$rootScope.initialized) {
    // Initialize the PubNub service
    PubNub.init({
      subscribe_key: 'demo',
      publish_key: 'demo',
      uuid:$scope.userId
    });
    $rootScope.initialized = true;
  }

  // Subscribe to the Channel
  PubNub.ngSubscribe({ channel: $scope.channel });

  // Create a publish() function in the scope
  $scope.publish = function() {
    PubNub.ngPublish({
      channel: $scope.channel,
      message: "[" + $scope.userId + "] " + $scope.newMessage
    });
    $scope.newMessage = '';
  };

  // Register for message events
  $rootScope.$on(PubNub.ngMsgEv($scope.channel), function(ngEvent, payload) {
    $scope.$apply(function() {
     $scope.glued = true;
      $scope.messages.push(payload.message);
    });
  });

Lastly I'm attaching to the div that contains the repeating messages like below. Im not using two-way binding as I dodn't think I needed it. Maybe I'm wrong here:

...
                    <div id="chat_widget_messages_container">
                        <div id="chat_widget_messages" scroll-glue >
                            <ul>
                                <li ng-repeat="message in messages">{{message}}</li>
                            </ul>
                        </div>
                    </div>
...

And lastly, the style (with overflow-y set) on the scrolling container looks like this:

#chat_widget_messages {
        overflow-x: hidden;
        overflow-y: scroll;
        position: absolute;
        max-height: 300px;
        bottom: 0;
}

Any help would be awesome. Thanks.

Animation

When I use a max-height css animation on a ng-repeat, the scroll-glue only scrolls to the height at the the first point in the animation.

It would be nice if this directive could listen for the animation ending, then fire. Or perhaps fire at beginning and end.

NPM Parity

Currently, v2.0.6 is available via bower, but npm only has 2.0.4 as the most recent version. I noticed that the maintainer for the npm package is not you. Was it deliberate or did that guy just register his package before you could?

In any case, keeping both package manager versions of your module would be ideal. If there's any way you can make that happen, you would be my hero! ๐Ÿ˜„

Unknown provider scrollGlueDirective

I face a problem when integrating scroll-glue in my project.

I got this error :

Error: [$injector:unpr] Unknown provider: aProvider <- a <- scrollGlueDirective
http://errors.angularjs.org/1.2.26/$injector/unpr?p0=aProvider%20%3C-%20a%20%3C-%20scrollGlueDirective

I've included 'luegg.directives' in my dependencies.
It's weird because there is no mention of scrollGlueDirective apart in the above error message.

Any help will be appreciated ! Thanks

Tagging

Could you create the initial tag (ex. 0.0.1) for this repo and add new tags for future releases? It would be very helpful for installing with bower.

Great directive BTW ๐Ÿ‘

Does not scroll to bottom of images loaded with ng-src on iOS

It looks like on Safari for iOS it's not handling images properly. When a new image appears in a container that's glued to the bottom it only scrolls down a little bit, rather than scrolling down far enough to be able to see the entire image. It doesn't seem to happen on android.

Here's a stripped down version of the code where I'm seeing the problem.

<div scroll-glue="true">
    <div ng-repeat="message in messages" class="message">
        <div>
            <div ng-if="message.type == 'image'" ng-cloak><img ng-src="{{ message.content }}"></div>
        </div>
    </div>
</div>

I also found an issue elsewhere that might be related: matthewwilson/ping#4

New release

Latest version on NPM 2.0.7 doesn't have support for Browserify / UMD as master has - could you make a new release?

Zooming breaks shouldActivateAutoScroll

When I zoom in the browser (Ctrl++), elements that previously worked fine with scroll-glue, will stop scrolling down, because the condition in shouldActivateAutoScroll is no longer met.

Is there a way to scroll to bottom after scrolling up manually

Scenario:

1.) Div is set to "scroll-glue"
2.) Add multiple items to list and stays scrolled to bottom
3.) Manually scroll up to top
4.) Add another item

After the item at step 4 is added should the div be scrolled back down to bottom?
Currently is stays at the top.

Avoid digest on scroll?

Would it be possible to avoid digesting on scroll? My app can't handle digesting 100s of times a second.

angular is not defined

Hi! I am coding a chat application using angular/ionic, although I am still pretty new. I cloned the file you have provided inside my "node_modules" folder using npm command you mentioned. However, when trying to import it in "app.module.ts" file, I get an "ReferenceError: angular is not defined". What can I do to solve this?

re-enable scroll glue

If a user scrolls, say, a horizontal block to the middle, scroll glue is suspended (i.e. turned off). How can I programmatically, if I add new horizontal content to the block, re-enable scroll glue?

scroll goes too soon

Hello here. I'm trying to use this directive for my case, and it seems it doesn't work properly.

I have scrollable div, with AJAX messages there. So, I expect, that after message is added, container will scroll down for it. But, it doesn't work.

My inverstigations:

$window.addEventListener('resize', scrollIfGlued, false); doesn't call the callback. Callback is called from scope.$watch(scrollIfGlued); immediately after AJAX query done (it's noticeable from stacktrace), and scroll function is called too early, when el.scrollHeight isn't enought high.

The solution is

scope.$watch(function() {                                   
  $timeout(scrollIfGlued, 0, false);                                  
}); 

I'd commit pull request, but test fails for me, and I can't repair them.

I understand, it sounds like edge case, but it will make directive more robust

[scroll-glue] css name

I do have to use this name, [scroll-glue] or I can change to everything I want?

<style type="text/css">
  [scroll-glue]{
    height: 100px;
    overflow-y: scroll;
    border: 1px solid red;
  }
</style>

npm / git different package

Hi,
the npm latest version seems not to be the same as the git master version.
For example, we cannot find the 'force-glue' parameter on the npm version.
Whereas both are 2.1.0 version

Bower package naming.

Hey I love your directive, just found it through google.

A couple of notes, your bower.json says package name is "angularjs-scroll-glue".
And in the bower database it's "angularjs-scroll-glue-Luegg".

For naming policys sake, could you rename into "angular-scroll-glue".
Angularjs libraries tend to use "angular" prefix.

Also by changing the name you could reclaim your version as the REAL package, I see that a old fork has reclaimed your name. Which is just silly, as you keep your package up-to-date, wishbear aka prettynatty could remove his.

โžœ  chat git:(master) โœ— bower search scroll-glue
  Search results:

angularjs-scroll-glue git://github.com/wishbear/angularjs-scroll-glue.git
angularjs-scroll-glue-Luegg git://github.com/Luegg/angularjs-scroll-glue.git

Kind regards Aciid ~

improve module name

This is just a tiny suggestion. (I recently found out about this directive on Stack Overflow.)

I note that you are using a module name of luegg.directives, which might be appropriate if this is a whole library of Luegg's directive. But as this is just a tiny, single function module (a good thing!), maybe a model name of something like scroll-glue might be more appropriate? There are many possible variations.

Thanks for the nice work!

Issues applying to an element that already makes use of ngModel

I'm getting some issues trying to use scrollGlue on an element that already makes use of ngModel.

scrollGlue changes my model to true or false, overriding my application data.

Is the real ngModel instance really necessary for this plugin? Always using the fake one solves my issue.

How to do ES6 import?

I am trying to import this module in the following way:

  1. Added to package.json
  2. In app.js I added import luegg from 'angularjs-scroll-glue'
  3. And then
export let app = angular.module('mymodule', [
   ...some other modules...
    luegg.directives,
]);

But console throws: Error: [$injector:modulerr] Failed to instantiate module mymodule due to:
[$injector:modulerr] Failed to instantiate module undefined due to:
[ng:areq] Argument 'module' is not a function, got undefined

It seems that it actually wants to load it but fails. Am I doing something wrong and is there any way I can make this work?

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.