fixed sorting errors and missbehaviours - now sorting like file browser
This commit is contained in:
parent
e154806838
commit
e4278574a8
|
@ -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 .= '<div class="gallery_div" '.$extra.' onmouseover="'.$this->tiles_array[$i]->getOnHoverAction().'" onmouseout="'.$this->tiles_array[$i]->getOnOutAction().'" onclick="'.$this->tiles_array[$i]->getOnClickAction().'">'.$this->tiles_array[$i]->get().'</div>';
|
||||
$r .= '<div class="gallery_div" '.$extra.' onmouseover="'.$this->tiles_array[$i]->getOnHoverAction().'" onmouseout="'.$this->tiles_array[$i]->getOnOutAction().'" onclick="'.$this->tiles_array[$i]->getOnClickAction().'">'.$this->tiles_array[$i]->get().'</div>';
|
||||
}
|
||||
|
||||
$r .= '</div>';
|
||||
|
@ -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 = '<div class="title gallery_div">'.$this->stack_name.'</div>';
|
||||
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.='<div class="miniature_border gallery_div" style="border:2px solid; margin-right: 2px;"></div>';
|
||||
} 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 .= '<div class="miniature_border gallery_div" style="background-image:url(\''.$this->tiles_array[$i]->getMiniatureSrc().'\');margin-top:'.$top.'px; margin-left:'.$left.'px;'.$extra.'"></div>';
|
||||
}
|
||||
$r .= '<div class="miniature_border gallery_div" style="background-image:url(\''.$this->tiles_array[$i]->getMiniatureSrc().'\');margin-top:'.$top.'px; margin-left:'.$left.'px;'.$extra.'"></div>';
|
||||
}
|
||||
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;';
|
||||
}
|
||||
|
||||
|
|
|
@ -16,6 +16,14 @@ div.visible { opacity: 0.8;}
|
|||
|
||||
var root = "<?php echo htmlentities($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; $i<count($root_images); $i++) {
|
||||
$tl->addTile(new \OC\Pictures\TileSingle($root_images[$i]));
|
||||
}
|
||||
|
||||
echo $tl->get();
|
||||
|
|
Loading…
Reference in New Issue