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

Commit

Permalink
fix(carousel): change to avoid references to debug info
Browse files Browse the repository at this point in the history
- Change usage of `.scope()` and `.isolateScope()` to grab metadata from elements

Closes #3795
Fixes #3794
  • Loading branch information
wesleycho committed Jun 12, 2015
1 parent a5a2514 commit ca07ad7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
20 changes: 15 additions & 5 deletions src/carousel/carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
*
*/
angular.module('ui.bootstrap.carousel', [])
.controller('CarouselController', ['$scope', '$interval', '$animate', function ($scope, $interval, $animate) {
.controller('CarouselController', ['$scope', '$element', '$interval', '$animate', function ($scope, $element, $interval, $animate) {
var self = this,
slides = self.slides = $scope.slides = [],
NO_TRANSITION = 'uib-noTransition',
SLIDE_DIRECTION = 'uib-slideDirection',
currentIndex = -1,
currentInterval, isPlaying;
self.currentSlide = null;
Expand All @@ -36,6 +38,7 @@ angular.module('ui.bootstrap.carousel', [])
angular.extend(self.currentSlide || {}, {direction: direction, active: false});
if ($animate.enabled() && !$scope.noTransition && !$scope.$currentTransition &&
slide.$element) {
slide.$element.data(SLIDE_DIRECTION, slide.direction);
$scope.$currentTransition = true;
slide.$element.one('$animate:close', function closeFn() {
$scope.$currentTransition = null;
Expand Down Expand Up @@ -167,6 +170,10 @@ angular.module('ui.bootstrap.carousel', [])
}
};

$scope.$watch('noTransition', function(noTransition) {
$element.data(NO_TRANSITION, noTransition);
});

}])

/**
Expand Down Expand Up @@ -295,13 +302,16 @@ function CarouselDemoCtrl($scope) {
.animation('.item', [
'$animate',
function ($animate) {
var NO_TRANSITION = 'uib-noTransition',
SLIDE_DIRECTION = 'uib-slideDirection';

return {
beforeAddClass: function (element, className, done) {
// Due to transclusion, noTransition property is on parent's scope
if (className == 'active' && element.parent() &&
!element.parent().scope().noTransition) {
!element.parent().data(NO_TRANSITION)) {
var stopped = false;
var direction = element.isolateScope().direction;
var direction = element.data(SLIDE_DIRECTION);
var directionClass = direction == 'next' ? 'left' : 'right';
element.addClass(direction);
$animate.addClass(element, directionClass).then(function () {
Expand All @@ -320,9 +330,9 @@ function ($animate) {
beforeRemoveClass: function (element, className, done) {
// Due to transclusion, noTransition property is on parent's scope
if (className == 'active' && element.parent() &&
!element.parent().scope().noTransition) {
!element.parent().data(NO_TRANSITION)) {
var stopped = false;
var direction = element.isolateScope().direction;
var direction = element.data(SLIDE_DIRECTION);
var directionClass = direction == 'next' ? 'left' : 'right';
$animate.addClass(element, directionClass).then(function () {
if (!stopped) {
Expand Down
2 changes: 1 addition & 1 deletion src/carousel/test/carousel.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ describe('carousel', function() {

beforeEach(function() {
scope = $rootScope.$new();
ctrl = $controller('CarouselController', {$scope: scope, $element: null});
ctrl = $controller('CarouselController', {$scope: scope, $element: angular.element('<div></div>')});
for(var i = 0;i < slides.length;i++){
ctrl.addSlide(slides[i]);
}
Expand Down

0 comments on commit ca07ad7

Please sign in to comment.