Skip to content

Commit 8b7e137

Browse files
committed
fix(Multiple Select): Dont scroll to top when select multiple items
Thanks @frnan for the solution Closes #59
1 parent e40387f commit 8b7e137

File tree

7 files changed

+84
-49
lines changed

7 files changed

+84
-49
lines changed

dist/angular-chosen.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* angular-chosen-localytics - Angular Chosen directive is an AngularJS Directive that brings the Chosen jQuery in a Angular way
3-
* @version v1.4.2
3+
* @version v1.4.3
44
* @link http://github.com/leocaseiro/angular-chosen
55
* @license MIT
66
*/
@@ -67,8 +67,12 @@
6767
chosen = null;
6868
empty = false;
6969
initOrUpdate = function() {
70-
var defaultText;
70+
var defaultText, dropListDom;
7171
if (chosen) {
72+
dropListDom = $(element.parent()).find("div.chosen-drop");
73+
if (dropListDom && dropListDom.length > 0 && dropListDom.css("left").indexOf("0") >= 0) {
74+
return;
75+
}
7276
return element.trigger('chosen:updated');
7377
} else {
7478
$timeout(function() {

dist/angular-chosen.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/index.coffee

Lines changed: 0 additions & 42 deletions
This file was deleted.

example/index.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,12 @@ <h2>#179 - inherit-select-class inside ng-if:</h2>
132132
</select>
133133
</div>
134134

135+
<h2>#59 - Don't scroll to top when selecting multiple items with ctrl</h2>
136+
<div>
137+
<select multiple chosen ng-model="state" ng-options="s for s in states" style="width:200px;">
138+
<option value=""></option>
139+
</select>
140+
</div>
135141

136142
</body>
137143

example/index.js

Lines changed: 62 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "angular-chosen-localytics",
33
"filename": "chosen.js",
44
"main": "dist/angular-chosen.js",
5-
"version": "1.4.2",
5+
"version": "1.4.3",
66
"description": "Angular Chosen directive is an AngularJS Directive that brings the Chosen jQuery in a Angular way",
77
"homepage": "http://github.com/leocaseiro/angular-chosen",
88
"repository": {
@@ -40,7 +40,8 @@
4040
"slobo",
4141
"lpsBetty",
4242
"nike-17",
43-
"vstene"
43+
"vstene",
44+
"frnan"
4445
],
4546
"dependencies": {
4647
"angular": "^1.5.7",

src/chosen.coffee

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,11 @@ angular.module('localytics.directives').directive 'chosen', ['$timeout', ($timeo
7676

7777
initOrUpdate = ->
7878
if chosen
79-
element.trigger('chosen:updated')
79+
# Fix #56 Don't scroll to top when selecting multiple items with ctrl
80+
dropListDom = $(element.parent()).find("div.chosen-drop") #uses jQuery instead of Angular.
81+
if dropListDom && dropListDom.length > 0 && dropListDom.css("left").indexOf("0") >= 0
82+
return
83+
return element.trigger('chosen:updated')
8084
else
8185
$timeout ->
8286
chosen = element.chosen(options).data('chosen')

0 commit comments

Comments
 (0)