Skip to content

Commit 571c375

Browse files
Merge pull request #3 from lght/dev
Adding a scroll-name to be able to have multiple scroll panes
2 parents 862bf73 + 6970d7e commit 571c375

File tree

4 files changed

+17
-10
lines changed

4 files changed

+17
-10
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ angular.module("app").controller("MyCtrl", function () {
3737
</html>
3838
```
3939

40-
**Don't forget to specify an id for your scroll pane, otherwise it won't be working**
40+
**Don't forget to specify an id (or an attribute 'scroll-name') for your scroll pane, otherwise it won't be working**
4141

4242
### Reinitialize the pane
4343

dist/angular-jscrollpane.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,23 @@
88
transclude: true,
99
template: '<div class="scroll-pane"><div ng-transclude></div></div>',
1010
link: function($scope, $elem, $attrs) {
11-
var config, fn;
11+
var config, fn, selector;
1212
config = {};
1313
if ($attrs.scrollConfig) {
1414
config = $scope.$eval($attrs.scrollConfig);
1515
}
16+
selector = "#" + $attrs.id;
17+
if ($attrs.scrollName) {
18+
selector = "[scroll-name='" + $attrs.scrollName + "']";
19+
}
1620
fn = function() {
17-
jQuery("#" + $attrs.id).jScrollPane(config);
18-
return $scope.pane = jQuery("#" + $attrs.id).data("jsp");
21+
jQuery(selector).jScrollPane(config);
22+
return $scope.pane = jQuery(selector).data("jsp");
1923
};
2024
if ($attrs.scrollTimeout) {
2125
$timeout(fn, $scope.$eval($attrs.scrollTimeout));
2226
} else {
23-
fn();
27+
$timeout(fn, 0);
2428
}
2529
return $scope.$on("reinit-pane", function(event, id) {
2630
if (id === $attrs.id && $scope.pane) {

dist/angular-jscrollpane.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/jscrollpane.coffee

+6-3
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,16 @@ angular
1010
config = {}
1111
if $attrs.scrollConfig
1212
config = $scope.$eval($attrs.scrollConfig)
13+
selector = "##{$attrs.id}"
14+
if $attrs.scrollName
15+
selector = "[scroll-name='#{$attrs.scrollName}']"
1316
fn = ->
14-
jQuery("##{$attrs.id}").jScrollPane(config)
15-
$scope.pane = jQuery("##{$attrs.id}").data("jsp")
17+
jQuery(selector).jScrollPane(config)
18+
$scope.pane = jQuery(selector).data("jsp")
1619
if $attrs.scrollTimeout
1720
$timeout(fn, $scope.$eval($attrs.scrollTimeout))
1821
else
19-
do fn
22+
$timeout(fn, 0)
2023
$scope.$on("reinit-pane", (event, id) ->
2124
if id is $attrs.id and $scope.pane
2225
console.log("Reinit pane #{id}")

0 commit comments

Comments
 (0)