Skip to content

Commit

Permalink
Merge pull request #44 from jca258/master
Browse files Browse the repository at this point in the history
Call event handlers when needed
  • Loading branch information
lordfriend committed Mar 5, 2015
2 parents e422ae5 + fbc705c commit 35958dd
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 3 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nya-bootstrap-select",
"version": "2.0.9",
"version": "2.0.10",
"main": [
"dist/js/nya-bs-select.js",
"dist/css/nya-bs-select.css"
Expand Down
17 changes: 17 additions & 0 deletions dist/js/nya-bs-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -664,10 +664,19 @@ nyaBsSelect.directive('nyaBsSelect', ['$parse', '$document', '$timeout', 'nyaBsC
// if click the outside of dropdown menu, close the dropdown menu
$document.on('click', function(event) {
if(filterTarget(event.target, $element.parent()[0], $element[0]) === null) {
if($element.hasClass('open')) {
$element.triggerHandler('blur');
}
$element.removeClass('open');
}
});


dropdownToggle.on('blur', function() {
if(!$element.hasClass('open')) {
$element.triggerHandler('blur');
}
});
dropdownToggle.on('click', function() {
var nyaBsOptionNode;
$element.toggleClass('open');
Expand Down Expand Up @@ -853,6 +862,9 @@ nyaBsSelect.directive('nyaBsSelect', ['$parse', '$document', '$timeout', 'nyaBsC
if(keyCode === 27) {
// escape pressed
dropdownToggle[0].focus();
if($element.hasClass('open')) {
$element.triggerHandler('blur');
}
$element.removeClass('open');
event.stopPropagation();

Expand Down Expand Up @@ -1067,6 +1079,9 @@ nyaBsSelect.directive('nyaBsSelect', ['$parse', '$document', '$timeout', 'nyaBsC

if(!isMultiple) {
// in single selection mode. close the dropdown menu
if($element.hasClass('open')) {
$element.triggerHandler('blur');
}
$element.removeClass('open');
}
updateButtonContent();
Expand Down Expand Up @@ -1108,6 +1123,8 @@ nyaBsSelect.directive('nyaBsSelect', ['$parse', '$document', '$timeout', 'nyaBsC

function updateButtonContent() {
var modelValue = ngCtrl.$modelValue;
$element.triggerHandler('change');

var filterOption = dropdownToggle.children().eq(0);
if(typeof modelValue === 'undefined') {
/**
Expand Down
2 changes: 1 addition & 1 deletion dist/js/nya-bs-select.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nya-bootstrap-select",
"version": "2.0.9",
"version": "2.0.10",
"description": "An angular directive wraps bootstrap-select",
"repository": {
"type": "git",
Expand Down
17 changes: 17 additions & 0 deletions src/nya-bs-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,19 @@ nyaBsSelect.directive('nyaBsSelect', ['$parse', '$document', '$timeout', 'nyaBsC
// if click the outside of dropdown menu, close the dropdown menu
$document.on('click', function(event) {
if(filterTarget(event.target, $element.parent()[0], $element[0]) === null) {
if($element.hasClass('open')) {
$element.triggerHandler('blur');
}
$element.removeClass('open');
}
});
console.log(dropdownToggle[0]==$element.find('button').eq(0)[0]);

dropdownToggle.on('blur', function() {
if(!$element.hasClass('open')) {
$element.triggerHandler('blur');
}
});
dropdownToggle.on('click', function() {
var nyaBsOptionNode;
$element.toggleClass('open');
Expand Down Expand Up @@ -450,6 +459,9 @@ nyaBsSelect.directive('nyaBsSelect', ['$parse', '$document', '$timeout', 'nyaBsC
if(keyCode === 27) {
// escape pressed
dropdownToggle[0].focus();
if($element.hasClass('open')) {
$element.triggerHandler('blur');
}
$element.removeClass('open');
event.stopPropagation();

Expand Down Expand Up @@ -664,6 +676,9 @@ nyaBsSelect.directive('nyaBsSelect', ['$parse', '$document', '$timeout', 'nyaBsC

if(!isMultiple) {
// in single selection mode. close the dropdown menu
if($element.hasClass('open')) {
$element.triggerHandler('blur');
}
$element.removeClass('open');
}
updateButtonContent();
Expand Down Expand Up @@ -705,6 +720,8 @@ nyaBsSelect.directive('nyaBsSelect', ['$parse', '$document', '$timeout', 'nyaBsC

function updateButtonContent() {
var modelValue = ngCtrl.$modelValue;
$element.triggerHandler('change');

var filterOption = dropdownToggle.children().eq(0);
if(typeof modelValue === 'undefined') {
/**
Expand Down

0 comments on commit 35958dd

Please sign in to comment.