-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SUP-2155, Dashboard: Subtracks should not limit to 5 in the carousel
-- Created new directive for responsive carousel -- Created new directive for fixing scope issue(angular/angular.js#7874 (comment)) with ng-transclude
- Loading branch information
vikasrohit
committed
Oct 17, 2015
1 parent
f3dcd4e
commit 1ca404b
Showing
8 changed files
with
206 additions
and
87 deletions.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
app/directives/responsive-carousel/responsive-carousel.directive.jade
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.tc-carousel | ||
ul(rn-carousel, rn-carousel-controls, slide-count="{{slideCounts[carouselIndex]}}") | ||
li(ng-repeat="slides in slidesCollection") | ||
.slide(ng-repeat="item in slides") | ||
tc-transclude |
75 changes: 75 additions & 0 deletions
75
app/directives/responsive-carousel/responsive-carousel.directive.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
(function() { | ||
'use strict'; | ||
angular.module('tcUIComponents').directive('responsiveCarousel', function() { | ||
return { | ||
restrict: 'E', | ||
transclude: true, | ||
replace: true, | ||
templateUrl: 'directives/responsive-carousel/responsive-carousel.directive.html', | ||
scope: { | ||
data: '=' | ||
}, | ||
controller: ['$log', '$scope', '$element', '$window', | ||
function($log, $scope, $element, $window) { | ||
$scope.slideCounts = {}; | ||
|
||
activate(); | ||
|
||
function activate() { | ||
init(); | ||
|
||
var window = angular.element($window); | ||
window.on('resize', function() { | ||
init(); | ||
// don't forget manually trigger $digest() | ||
$scope.$digest(); | ||
}); | ||
} | ||
|
||
function init() { | ||
var width = $window.innerWidth; | ||
console.log(width); | ||
if(width > 1070) { | ||
// desktop | ||
buildCarouselSlide(6); | ||
} else if(width > 900) { | ||
// desktop | ||
buildCarouselSlide(5); | ||
} else if(width <= 900 && width > 768) { | ||
// tablet | ||
buildCarouselSlide(4); | ||
} else { | ||
// phone | ||
buildCarouselSlide(2); | ||
} | ||
} | ||
|
||
|
||
function buildCarouselSlide(numItemsPerSlide) { | ||
var slidesCollection = []; | ||
var slide = []; | ||
// Might be able to change number of subtracks per slide based | ||
// on screen size if the width of each subtrack is consistent: | ||
// http://stackoverflow.com/questions/26252038/multi-item-responsive-carousel | ||
numItemsPerSlide = numItemsPerSlide || 5; | ||
|
||
for(var i = 0; i < $scope.data.length; i++) { | ||
if (slide.length === numItemsPerSlide) { | ||
// When slide is full, push it to collection and make a new slide [] | ||
slidesCollection.push(slide); | ||
// updates the slide count object | ||
$scope.slideCounts[slidesCollection.length - 1] = slide.length; | ||
slide = []; | ||
} | ||
slide.push($scope.data[i]); | ||
} | ||
slidesCollection.push(slide); | ||
// updates the slide count object | ||
$scope.slideCounts[slidesCollection.length - 1] = slide.length; | ||
$scope.slidesCollection = slidesCollection; | ||
} | ||
|
||
}] | ||
}; | ||
}); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
(function() { | ||
'use strict'; | ||
angular.module('tcUIComponents').directive('tcTransclude', function() { | ||
return { | ||
link: function($scope, $element, $attrs, controller, $transclude) { | ||
if (!$transclude) { | ||
throw minErr('ngTransclude')('orphan', | ||
'Illegal use of ngTransclude directive in the template! ' + | ||
'No parent directive that requires a transclusion found. ' + | ||
'Element: {0}', | ||
startingTag($element)); | ||
} | ||
var innerScope = $scope.$new(); | ||
$transclude(innerScope, function(clone) { | ||
$element.empty(); | ||
$element.append(clone); | ||
$element.on('$destroy', function() { | ||
innerScope.$destroy(); | ||
}); | ||
}); | ||
} | ||
}; | ||
}); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
@import 'topcoder-includes'; | ||
@import '../partials/combined'; | ||
|
||
.tc-carousel { | ||
|
||
ul { | ||
display: block; | ||
height: 148px; | ||
margin: 0 auto; | ||
@media only screen and (max-width: 767px) { | ||
display: none; | ||
} | ||
&[slide-count="1"] { | ||
width: 170px; | ||
} | ||
&[slide-count="2"] { | ||
width: 340px; | ||
} | ||
&[slide-count="3"] { | ||
width: 510px; | ||
} | ||
&[slide-count="4"] { | ||
width: 680px; | ||
} | ||
&[slide-count="5"] { | ||
width: 850px; | ||
} | ||
&[slide-count="6"] { | ||
width: 1020px; | ||
} | ||
&[slide-count="7"] { | ||
width: 1190px; | ||
} | ||
|
||
li { | ||
div:last-child { | ||
margin-right: 0; | ||
} | ||
} | ||
} | ||
|
||
.rn-carousel-controls { | ||
position: relative; | ||
@media only screen and (max-width: 767px) { | ||
display: none; | ||
} | ||
|
||
.rn-carousel-control { | ||
height: 148px; | ||
width: 80px; | ||
line-height: 148px; | ||
top: -148px; | ||
background-color: $gray-lightest; | ||
color: $accent-gray; | ||
text-align: center; | ||
} | ||
|
||
.rn-carousel-control-prev { | ||
left: 0; | ||
} | ||
|
||
.rn-carousel-control-next { | ||
right: 0; | ||
} | ||
|
||
} | ||
|
||
.slide { | ||
display: inline-block; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters