Skip to content

Commit

Permalink
Merge pull request #39 from pedroabreu/fix_row
Browse files Browse the repository at this point in the history
fix dynamic row size
  • Loading branch information
pedroabreu committed Feb 9, 2016
2 parents 3e550f3 + 8997fcf commit c835dc6
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 33 deletions.
32 changes: 16 additions & 16 deletions dist/ion-gallery.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@
};

function controller($scope) {
var _rowSize = parseInt($scope.ionGalleryRowSize)

var _drawGallery = function () {
$scope.ionGalleryRowSize = ionGalleryHelper.getRowSize(parseInt($scope.ionGalleryRowSize), $scope.ionGalleryItems.length);
$scope.ionGalleryRowSize = ionGalleryHelper.getRowSize(_rowSize || ionGalleryConfig.row_size, $scope.ionGalleryItems.length);
$scope.actionLabel = ionGalleryConfig.action_label;
$scope.items = ionGalleryHelper.buildGallery($scope.ionGalleryItems, $scope.ionGalleryRowSize);
$scope.responsiveGrid = parseInt((1 / $scope.ionGalleryRowSize) * 100);
Expand Down Expand Up @@ -97,7 +99,7 @@
else{
rowSize = size;
}

return rowSize;

};
Expand Down Expand Up @@ -163,17 +165,16 @@
};

element.bind("load" , function(e){
var _this = this;
if(element.parent()[0].offsetHeight > 0){
scaleImage(this,element.parent()[0].offsetHeight);
}
else{
var _this = this;
scope.$watch(function(){
return element.parent()[0].offsetHeight;
},function(newValue){
scaleImage(_this,newValue);
});
}

scope.$watch(function(){
return element.parent()[0].offsetHeight;
},function(newValue){
scaleImage(_this,newValue);
});
});
}
}
Expand All @@ -185,24 +186,23 @@
.module('ion-gallery')
.directive('ionRowHeight',ionRowHeight);

ionRowHeight.$inject = [];
ionRowHeight.$inject = ['ionGalleryConfig'];

function ionRowHeight(){
function ionRowHeight(ionGalleryConfig){

return {
restrict: 'A',
link : link
};

function link(scope, element, attrs) {

scope.$watch(
function(){
return element[0].offsetWidth;
return scope.ionGalleryRowSize;
},
function(newValue){
function(newValue,oldValue){
if(newValue > 0){
element.css('height',newValue * parseInt(scope.$parent.responsiveGrid)/100 + 'px');
element.css('height',element[0].offsetWidth * parseInt(scope.responsiveGrid)/100 + 'px');
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion dist/ion-gallery.min.js

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

4 changes: 3 additions & 1 deletion src/js/gallery.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
};

function controller($scope) {
var _rowSize = parseInt($scope.ionGalleryRowSize)

var _drawGallery = function () {
$scope.ionGalleryRowSize = ionGalleryHelper.getRowSize(parseInt($scope.ionGalleryRowSize), $scope.ionGalleryItems.length);
$scope.ionGalleryRowSize = ionGalleryHelper.getRowSize(_rowSize || ionGalleryConfig.row_size, $scope.ionGalleryItems.length);
$scope.actionLabel = ionGalleryConfig.action_label;
$scope.items = ionGalleryHelper.buildGallery($scope.ionGalleryItems, $scope.ionGalleryRowSize);
$scope.responsiveGrid = parseInt((1 / $scope.ionGalleryRowSize) * 100);
Expand Down
2 changes: 1 addition & 1 deletion src/js/galleryHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
else{
rowSize = size;
}

return rowSize;

};
Expand Down
15 changes: 7 additions & 8 deletions src/js/imageScale.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,16 @@
};

element.bind("load" , function(e){
var _this = this;
if(element.parent()[0].offsetHeight > 0){
scaleImage(this,element.parent()[0].offsetHeight);
}
else{
var _this = this;
scope.$watch(function(){
return element.parent()[0].offsetHeight;
},function(newValue){
scaleImage(_this,newValue);
});
}

scope.$watch(function(){
return element.parent()[0].offsetHeight;
},function(newValue){
scaleImage(_this,newValue);
});
});
}
}
Expand Down
11 changes: 5 additions & 6 deletions src/js/rowHeight.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,23 @@
.module('ion-gallery')
.directive('ionRowHeight',ionRowHeight);

ionRowHeight.$inject = [];
ionRowHeight.$inject = ['ionGalleryConfig'];

function ionRowHeight(){
function ionRowHeight(ionGalleryConfig){

return {
restrict: 'A',
link : link
};

function link(scope, element, attrs) {

scope.$watch(
function(){
return element[0].offsetWidth;
return scope.ionGalleryRowSize;
},
function(newValue){
function(newValue,oldValue){
if(newValue > 0){
element.css('height',newValue * parseInt(scope.$parent.responsiveGrid)/100 + 'px');
element.css('height',element[0].offsetWidth * parseInt(scope.responsiveGrid)/100 + 'px');
}
});
}
Expand Down

0 comments on commit c835dc6

Please sign in to comment.