diff --git a/apps/gallery/lib/tiles.php b/apps/gallery/lib/tiles.php index e43c99bb76..48b54f0cf0 100644 --- a/apps/gallery/lib/tiles.php +++ b/apps/gallery/lib/tiles.php @@ -63,7 +63,7 @@ class TilesLine { $img_w = $this->tiles_array[$i]->getWidth(); $extra = ''; if ($img_w != IMAGE_WIDTH) $extra = ' style="width:'.$img_w.'px"'; - $r .= ''; + $r .= ''; } $r .= ''; @@ -122,7 +122,7 @@ class TileStack extends TileBase { $this->tiles_array = array(); $this->stack_name = $stack_name; for ($i = 0; $i < count($path_array) && $i < self::STACK_REPRESENTATIVES; $i++) { - $tile = new TileSingle($path_array[$i]); + $tile = new TileSingle($path_array[$i]); array_push($this->tiles_array, $tile); } } @@ -134,32 +134,47 @@ class TileStack extends TileBase { public function getWidth() { $max = 0; - for ($i = 0; $i < count($this->tiles_array); $i++) { - $max = max($max, $this->tiles_array[$i]->getWidth()); + if(count($this->tiles_array) == 0) { + $max = IMAGE_WIDTH; + } else { + for ($i = 0; $i < count($this->tiles_array); $i++) { + $max = max($max, $this->tiles_array[$i]->getWidth()); + } } return min(IMAGE_WIDTH, $max); } public function get() { $r = ''; - for ($i = 0; $i < count($this->tiles_array); $i++) { - $top = rand(-5, 5); - $left = rand(-5, 5); - $img_w = $this->tiles_array[$i]->getWidth(); - $extra = ''; - if ($img_w < IMAGE_WIDTH) { - $extra = 'width:'.$img_w.'px;'; + if(count($this->tiles_array) == 0) { + // aint no pictures in this folder... + $r.=''; + } else { + for ($i = 0; $i < count($this->tiles_array); $i++) { + $top = rand(-5, 5); + $left = rand(-5, 5); + $img_w = $this->tiles_array[$i]->getWidth(); + $extra = ''; + if ($img_w < IMAGE_WIDTH) { + $extra = 'width:'.$img_w.'px;'; + } + $r .= ''; } - $r .= ''; } return $r; } public function getOnHoverAction() { + if(count($this->tiles_array) == 0) { + return 'javascript:explode_empty(this);return false;'; + } return 'javascript:explode(this);return false;'; } public function getOnOutAction() { + if(count($this->tiles_array) == 0) { + return 'javascript:deplode_empty(this);return false;'; + } return 'javascript:deplode(this);return false;'; } diff --git a/apps/gallery/templates/index.php b/apps/gallery/templates/index.php index f992604549..930f80238b 100644 --- a/apps/gallery/templates/index.php +++ b/apps/gallery/templates/index.php @@ -16,6 +16,14 @@ div.visible { opacity: 0.8;} var root = ""; +function explode_empty(element) { + $('div', element).each(function(index, elem) { + if ($(elem).hasClass('title')) { + $(elem).addClass('visible'); + } + }); +} + function explode(element) { $('div', element).each(function(index, elem) { if ($(elem).hasClass('title')) { @@ -28,6 +36,14 @@ function explode(element) { }); } +function deplode_empty(element) { + $('div', element).each(function(index, elem) { + if ($(elem).hasClass('title')) { + $(elem).removeClass('visible'); + } + }); +} + function deplode(element) { $('div', element).each(function(index, elem) { if ($(elem).hasClass('title')) { @@ -79,41 +95,40 @@ $root = empty($_GET['root'])?'/':$_GET['root']; $images = \OC_FileCache::searchByMime('image', null, '/'.\OCP\USER::getUser().'/files'.$root); sort($images); -$arr = array(); $tl = new \OC\Pictures\TilesLine(); $ts = new \OC\Pictures\TileStack(array(), ''); $previous_element = @$images[0]; + +$root_images = array(); +$second_level_images = array(); + for($i = 0; $i < count($images); $i++) { $prev_dir_arr = explode('/', $previous_element); $dir_arr = explode('/', $images[$i]); - if (count($dir_arr)==1) { - $tl->addTile(new \OC\Pictures\TileSingle($root.$images[$i])); - continue; + if(count($dir_arr) == 1) { // getting the images in this directory + $root_images[] = $root.$images[$i]; + } else { + if (count($dir_arr) == 2) { // These are the pics in that subdir + $second_level_images[] = $root.$images[$i]; + } + if(strcmp($prev_dir_arr[0], $dir_arr[0]) != 0) { + $tl->addTile(new \OC\Pictures\TileStack($second_level_images, $prev_dir_arr[0])); + $second_level_images = array(); + } + // have us a little something to compare against + $previous_element = $images[$i]; } - if (strcmp($prev_dir_arr[0], $dir_arr[0])!=0) { - $tl->addTile(new \OC\Pictures\TileStack($arr, $prev_dir_arr[0])); - $arr = array(); - } - $arr[] = $root.$images[$i]; - $previous_element = $images[$i]; } -$dir_arr = explode('/', $previous_element); - -if (count($images)>1) { - if (count($dir_arr)==0) { - $tl->addTile(new \OC\Pictures\TileSingle($previous_element)); - } else if (count($dir_arr) && $ts->getCount() == 0){ - $ts = new \OC\Pictures\TileStack(array($root.$previous_element), $dir_arr[0]); - } else { - $arr[] = $previous_element; - $ts->addTile($arr); - } +// if last element in the directory was a directory we don't want to miss it :) +if(count($second_level_images)>0) { + $tl->addTile(new \OC\Pictures\TileStack($second_level_images, $prev_dir_arr[0])); } -if ($ts->getCount() != 0) { - $tl->addTile($ts); +// and finally our images actually stored in the root folder +for($i = 0; $iaddTile(new \OC\Pictures\TileSingle($root_images[$i])); } echo $tl->get();