Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

Commit

Permalink
feat(typeahead): add typeahead-append-to-body option
Browse files Browse the repository at this point in the history
  • Loading branch information
nurikk authored and pkozlowski-opensource committed Dec 20, 2013
1 parent 1fbcb5d commit dd8eac2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
12 changes: 12 additions & 0 deletions src/typeahead/test/typeahead.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,18 @@ describe('typeahead tests', function () {
expect(inputEl.val()).toEqual('AL');
expect($scope.result).toEqual($scope.states[0]);
});


});

describe('append to body', function () {

it('append typeahead results to body', function () {
var element = prepareInputEl("<div><input ng-model='result' typeahead='item for item in source | filter:$viewValue' typeahead-append-to-body='true'></div>");
changeInputValueTo(element, 'ba');
expect($document.find('body')).toBeOpenWithActive(2, 0);

});
});

});
11 changes: 9 additions & 2 deletions src/typeahead/typeahead.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position', 'ui.bootstrap

var inputFormatter = attrs.typeaheadInputFormatter ? $parse(attrs.typeaheadInputFormatter) : undefined;

var appendToBody = attrs.typeaheadAppendToBody ? $parse(attrs.typeaheadAppendToBody) : false;

//INTERNAL VARIABLES

//model setter executed upon match selection
Expand Down Expand Up @@ -120,7 +122,7 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position', 'ui.bootstrap
//position pop-up with matches - we need to re-calculate its position each time we are opening a window
//with matches as a pop-up might be absolute-positioned and position of an input might have changed on a page
//due to other elements being rendered
scope.position = $position.position(element);
scope.position = appendToBody ? $position.offset(element) : $position.position(element);
scope.position.top = scope.position.top + element.prop('offsetHeight');

} else {
Expand Down Expand Up @@ -275,7 +277,12 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position', 'ui.bootstrap
$document.unbind('click', dismissClickHandler);
});

element.after($compile(popUpEl)(scope));
var $popup = $compile(popUpEl)(scope);
if ( appendToBody ) {
$document.find('body').append($popup);
} else {
element.after($popup);
}
}
};

Expand Down

0 comments on commit dd8eac2

Please sign in to comment.