Small code adjustments #232

pull/238/head
Tobias Reich 10 years ago
parent a0d11ca6b2
commit 582a8a3f93

@ -1,9 +0,0 @@
Experimental fork of Lychee, a photo management system, that features a number of improvements, including:
* Faster photo browsing thanks to caching.
* Default sort order of albums is changed from new to old.
* Preserves scroll position when changing from albums to album and vice versa
* Better Unicode support for values read from the database
See http://github.com/electerious/Lychee for more details on Lychee

@ -116,8 +116,9 @@ album = {
if (data!==false&&isNumber(data)) {
albums.refresh();
lychee.goto(data);
} else {
lychee.error(null, params, data);
}
else lychee.error(null, params, data);
});
@ -149,7 +150,7 @@ album = {
albumIDs.forEach(function(id) {
albums.json.num--;
view.albums.content.delete(id);
delete albums.json.content[id]
delete albums.json.content[id];
});
} else lychee.goto("");
@ -298,7 +299,7 @@ album = {
password = "",
listed = false,
downloadable = false;
albums.refresh();
if (!visible.message()&&album.json.public==0) {
@ -311,7 +312,7 @@ album = {
else $(".message .choice input.text").hide();
});
return true;
}

@ -17,13 +17,13 @@ albums = {
lychee.animate(".album:nth-child(-n+50), .photo:nth-child(-n+50)", "contentZoomOut");
lychee.animate(".divider", "fadeOut");
startTime = new Date().getTime();
if(albums.json == null) {
if(albums.json===null) {
lychee.api("getAlbums", function(data) {
/* Smart Albums */
data.unsortedAlbum = {
id: 0,
@ -34,7 +34,7 @@ albums = {
thumb1: data.unsortedThumb1,
thumb2: data.unsortedThumb2
};
data.starredAlbum = {
id: "f",
title: "Starred",
@ -44,7 +44,7 @@ albums = {
thumb1: data.starredThumb1,
thumb2: data.starredThumb2
};
data.publicAlbum = {
id: "s",
title: "Public",
@ -54,7 +54,7 @@ albums = {
thumb1: data.publicThumb1,
thumb2: data.publicThumb2
};
data.recentAlbum = {
id: "r",
title: "Recent",
@ -64,26 +64,30 @@ albums = {
thumb1: data.recentThumb1,
thumb2: data.recentThumb2
};
albums.json = data;
durationTime = (new Date().getTime() - startTime);
if (durationTime>300) waitTime = 0; else waitTime = 300 - durationTime;
if (!visible.albums()&&!visible.photo()&&!visible.album()) waitTime = 0;
if (visible.album()&&lychee.content.html()==="") waitTime = 0;
setTimeout(function() {
view.header.mode("albums");
view.albums.init();
lychee.animate(".album:nth-child(-n+50), .photo:nth-child(-n+50)", "contentZoomIn");
}, waitTime);
});
} else {
view.albums.init();
lychee.animate(".album:nth-child(-n+50), .photo:nth-child(-n+50)", "contentZoomIn");
}, waitTime);
});
} else {
setTimeout(function() {
view.header.mode("albums");
view.albums.init();
lychee.animate(".album:nth-child(-n+50), .photo:nth-child(-n+50)", "contentZoomIn");
}
}, 300);
}
},
parse: function(album) {
@ -99,9 +103,11 @@ albums = {
}
},
refresh: function() {
albums.json = null;
}
};

@ -34,7 +34,7 @@ build = {
title = albumJSON.title,
typeThumb = "";
if (title != null && title.length>18) {
if (title!==null&&title.length>18) {
title = albumJSON.title.substr(0, 18) + "...";
longTitle = albumJSON.title;
}
@ -76,7 +76,7 @@ build = {
longTitle = "",
title = photoJSON.title;
if (title != null && title.length>18) {
if (title!==null&&title.length>18) {
title = photoJSON.title.substr(0, 18) + "...";
longTitle = photoJSON.title;
}

@ -181,7 +181,6 @@ var lychee = {
if (albumID&&photoID) {
// Trash data
//albums.json = null;
photo.json = null;
// Show Photo
@ -195,7 +194,6 @@ var lychee = {
} else if (albumID) {
// Trash data
//albums.json = null;
photo.json = null;
// Show Album
@ -206,7 +204,6 @@ var lychee = {
} else {
// Trash data
//albums.json = null;
album.json = null;
photo.json = null;
search.code = "";

@ -5,10 +5,10 @@
* @copyright 2014 by Tobias Reich
*/
cache = null;
photo = {
json: null,
cache: null,
getID: function() {
@ -49,19 +49,26 @@ photo = {
});
},
//preload the next photo for better response time
preloadNext: function(photoID) {
if(album.json &&
album.json.content &&
var nextPhoto,
url;
if (album.json &&
album.json.content &&
album.json.content[photoID] &&
album.json.content[photoID].nextPhoto!="") {
var nextPhoto = album.json.content[photoID].nextPhoto;
var url = album.json.content[nextPhoto].url;
cache = new Image();
cache.src = url;
nextPhoto = album.json.content[photoID].nextPhoto;
url = album.json.content[nextPhoto].url;
photo.cache = new Image();
photo.cache.src = url;
}
},
parse: function() {
@ -331,7 +338,7 @@ photo = {
if (data!==true) lychee.error(null, params, data);
});
albums.refresh();
},
@ -339,15 +346,13 @@ photo = {
setPublic: function(photoID, e) {
var params;
if (photo.json.public==2) {
modal.show("Public Album", "This photo is located in a public album. To make this photo private or public, edit the visibility of the associated album.", [["Show Album", function() { lychee.goto(photo.json.original_album) }], ["Close", function() {}]]);
return false;
}
albums.refresh();
if (visible.photo()) {
@ -367,6 +372,8 @@ photo = {
});
albums.refresh();
},
setDescription: function(photoID) {

@ -10,7 +10,7 @@ view = {
header: {
show: function() {
var newMargin = -1*($("#imageview #image").height()/2)+20;
clearTimeout($(window).data("timeout"));
@ -121,32 +121,33 @@ view = {
},
content: {
scroll_pos: 0,
scrollPosition: 0,
init: function() {
var smartData = "",
albumsData = "";
/* Smart Albums */
/* Smart Albums */
albums.parse(albums.json.unsortedAlbum);
albums.parse(albums.json.publicAlbum);
albums.parse(albums.json.starredAlbum);
albums.parse(albums.json.recentAlbum);
if (!lychee.publicMode) smartData = build.divider("Smart Albums") + build.album(albums.json.unsortedAlbum) + build.album(albums.json.starredAlbum) + build.album(albums.json.publicAlbum) + build.album(albums.json.recentAlbum);
/* Albums */
/* Albums */
if (albums.json.content) {
$.each(albums.json.content, function() {
albums.parse(this);
//display albums in reverse order
albumsData = build.album(this) + albumsData;
});
if (!lychee.publicMode) albumsData = build.divider("Albums") + albumsData;
if (!lychee.publicMode) albumsData = build.divider("Albums") + albumsData;
}
if (smartData===""&&albumsData==="") {
@ -157,10 +158,10 @@ view = {
}
$("img[data-type!='nonretina']").retina();
//restore scroll
if (view.albums.content.scroll_pos != null) {
$("html, body").scrollTop(view.albums.content.scroll_pos);
/* Restore scroll position */
if (view.albums.content.scrollPosition!==null) {
$("html, body").scrollTop(view.albums.content.scrollPosition);
}
},
@ -172,7 +173,7 @@ view = {
title = albums.json.content[albumID].title;
if (albums.json.content[albumID].password) prefix = "<span class='icon-lock'></span> ";
if (title != null && title.length>18) {
if (title!==null&&title.length>18) {
longTitle = title;
title = title.substr(0, 18) + "...";
}
@ -259,10 +260,11 @@ view = {
lychee.content.html(photosData);
$("img[data-type!='svg']").retina();
view.albums.content.scroll_pos = $(document).scrollTop();
//scroll to top
/* Save and reset scroll position */
view.albums.content.scrollPosition = $(document).scrollTop();
$("html, body").scrollTop(0);
},
title: function(photoID) {
@ -270,7 +272,7 @@ view = {
var longTitle = "",
title = album.json.content[photoID].title;
if (title != null && title.length>18) {
if (title!==null&&title.length>18) {
longTitle = title;
title = title.substr(0, 18) + "...";
}
@ -468,7 +470,7 @@ view = {
photo: function() {
lychee.imageview.html(build.imageview(photo.json, photo.isSmall(), visible.controls()));
if ((album.json&&album.json.content&&album.json.content[photo.getID()]&&album.json.content[photo.getID()].nextPhoto==="")||lychee.viewMode) $("a#next").hide();
if ((album.json&&album.json.content&&album.json.content[photo.getID()]&&album.json.content[photo.getID()].previousPhoto==="")||lychee.viewMode) $("a#previous").hide();

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -31,21 +31,12 @@ gulp.task('view', function () {
.pipe(gulp.dest('../assets/min/'));
});
/*
gulp.task('js', function () {
gulp.src(paths.js)
.pipe(plugins.concat('main.js', {newLine: "\n"}))
.pipe(plugins.uglify())
.pipe(gulp.dest('../assets/min/'));
});
*/
gulp.task('js', function () {
gulp.src(paths.js)
.pipe(plugins.concat('main.js', {newLine: "\n"}))
.pipe(plugins.uglify())
.pipe(gulp.dest('../assets/min/'));
});

@ -11,7 +11,7 @@
"devDependencies": {
"gulp": "^3.8.8",
"gulp-autoprefixer": "1.0.0",
"gulp-concat": "^2.4.0",
"gulp-concat": "^2.4.1",
"gulp-load-plugins": "^0.6.0",
"gulp-minify-css": "^0.3.8",
"gulp-sass": "^0.7.3",

@ -9,7 +9,6 @@
if (!defined('LYCHEE')) exit('Error: Direct access is not allowed!');
if (!defined('LYCHEE_ACCESS_ADMIN')) exit('Error: You are not allowed to access this area!');
class Admin extends Access {
public function check($fn) {
@ -74,6 +73,7 @@ class Admin extends Access {
$album = new Album($this->database, $this->plugins, $this->settings, null);
echo json_encode($album->getAll(false));
}
private function getAlbum() {

@ -8,17 +8,6 @@
if (!defined('LYCHEE')) exit('Error: Direct access is not allowed!');
function debug_to_console( $data ) {
if ( is_array( $data ) )
$output = "<script>console.log( 'Debug Objects: " . implode( ',', $data) . "' );</script>";
else
$output = "<script>console.log( 'Debug Objects: " . $data . "' );</script>";
echo $output;
}
class Album extends Module {
private $database = null;
@ -94,10 +83,9 @@ class Album extends Module {
default: $query = Database::prepare($this->database, "SELECT * FROM ? WHERE id = '?' LIMIT 1", array(LYCHEE_TABLE_ALBUMS, $this->albumIDs));
$albums = $this->database->query($query);
$return = $albums->fetch_assoc();
$return['sysdate'] = date('d M. Y', $return['sysstamp']);
$return['password'] = ($return['password']=='' ? false : true);
$query = Database::prepare($this->database, "SELECT id, title, tags, public, star, album, thumbUrl, takestamp, url FROM ? WHERE album = '?' " . $this->settings['sorting'], array(LYCHEE_TABLE_PHOTOS, $this->albumIDs));
$return['sysdate'] = date('d M. Y', $return['sysstamp']);
$return['password'] = ($return['password']=='' ? false : true);
$query = Database::prepare($this->database, "SELECT id, title, tags, public, star, album, thumbUrl, takestamp, url FROM ? WHERE album = '?' " . $this->settings['sorting'], array(LYCHEE_TABLE_PHOTOS, $this->albumIDs));
break;
}
@ -112,7 +100,7 @@ class Album extends Module {
$photo['previousPhoto'] = $previousPhotoID;
$photo['nextPhoto'] = '';
$photo['thumbUrl'] = LYCHEE_URL_UPLOADS_THUMB . $photo['thumbUrl'];
# Parse url
$photo['url'] = LYCHEE_URL_UPLOADS_BIG . $photo['url'];
@ -214,7 +202,7 @@ class Album extends Module {
# Call plugins
$this->plugins(__METHOD__, 1, func_get_args());
return $return;
}
@ -407,7 +395,7 @@ class Album extends Module {
# Parse
if (strlen($title)>50) $title = substr($title, 0, 50);
# Execute query
$query = Database::prepare($this->database, "UPDATE ? SET title = '?' WHERE id IN (?)", array(LYCHEE_TABLE_ALBUMS, $title, $this->albumIDs));
$result = $this->database->query($query);

Loading…
Cancel
Save