Skip to content

Commit

Permalink
fix(Multiple Select): Dont scroll to top when select multiple items
Browse files Browse the repository at this point in the history
Thanks @frnan for the solution

Closes #59
  • Loading branch information
leocaseiro committed Jul 26, 2016
1 parent e40387f commit 8b7e137
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 49 deletions.
8 changes: 6 additions & 2 deletions dist/angular-chosen.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* angular-chosen-localytics - Angular Chosen directive is an AngularJS Directive that brings the Chosen jQuery in a Angular way
* @version v1.4.2
* @version v1.4.3
* @link http://github.com/leocaseiro/angular-chosen
* @license MIT
*/
Expand Down Expand Up @@ -67,8 +67,12 @@
chosen = null;
empty = false;
initOrUpdate = function() {
var defaultText;
var defaultText, dropListDom;
if (chosen) {
dropListDom = $(element.parent()).find("div.chosen-drop");
if (dropListDom && dropListDom.length > 0 && dropListDom.css("left").indexOf("0") >= 0) {
return;
}
return element.trigger('chosen:updated');
} else {
$timeout(function() {
Expand Down
4 changes: 2 additions & 2 deletions dist/angular-chosen.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 0 additions & 42 deletions example/index.coffee

This file was deleted.

6 changes: 6 additions & 0 deletions example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ <h2>#179 - inherit-select-class inside ng-if:</h2>
</select>
</div>

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

</body>

Expand Down
62 changes: 62 additions & 0 deletions example/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "angular-chosen-localytics",
"filename": "chosen.js",
"main": "dist/angular-chosen.js",
"version": "1.4.2",
"version": "1.4.3",
"description": "Angular Chosen directive is an AngularJS Directive that brings the Chosen jQuery in a Angular way",
"homepage": "http://github.com/leocaseiro/angular-chosen",
"repository": {
Expand Down Expand Up @@ -40,7 +40,8 @@
"slobo",
"lpsBetty",
"nike-17",
"vstene"
"vstene",
"frnan"
],
"dependencies": {
"angular": "^1.5.7",
Expand Down
6 changes: 5 additions & 1 deletion src/chosen.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@ angular.module('localytics.directives').directive 'chosen', ['$timeout', ($timeo

initOrUpdate = ->
if chosen
element.trigger('chosen:updated')
# Fix #56 Don't scroll to top when selecting multiple items with ctrl
dropListDom = $(element.parent()).find("div.chosen-drop") #uses jQuery instead of Angular.
if dropListDom && dropListDom.length > 0 && dropListDom.css("left").indexOf("0") >= 0
return
return element.trigger('chosen:updated')
else
$timeout ->
chosen = element.chosen(options).data('chosen')
Expand Down

0 comments on commit 8b7e137

Please sign in to comment.