summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorRobin Appelman <icewind@owncloud.com>2012-03-07 18:58:10 +0100
committerRobin Appelman <icewind@owncloud.com>2012-03-07 18:58:10 +0100
commitcf5d63f0abc2b4537098962ad5051180861f965b (patch)
tree89623ed95607e46b8c998c228349dd5bcf1f9eba /apps
parentd8d293966852e28168c3ec42c79c2a271a8c8ade (diff)
downloadnextcloud-server-cf5d63f0abc2b4537098962ad5051180861f965b.tar.gz
nextcloud-server-cf5d63f0abc2b4537098962ad5051180861f965b.zip
some js cleanup for gallary
also tabs no spaces
Diffstat (limited to 'apps')
-rw-r--r--apps/gallery/ajax/galleryOp.php2
-rw-r--r--apps/gallery/js/album_cover.js309
-rw-r--r--apps/gallery/js/albums.js192
3 files changed, 252 insertions, 251 deletions
diff --git a/apps/gallery/ajax/galleryOp.php b/apps/gallery/ajax/galleryOp.php
index f33eb46041b..64f1b1697ba 100644
--- a/apps/gallery/ajax/galleryOp.php
+++ b/apps/gallery/ajax/galleryOp.php
@@ -104,7 +104,7 @@ function handleGetGallery($path) {
$album_name = $r['album_name'];
$size=OC_Gallery_Album::getAlbumSize($r['album_id']);
- $a[] = array('name' => utf8_encode($album_name), 'numOfItems' => min($size, 10));
+ $a[] = array('name' => utf8_encode($album_name), 'numOfItems' => min($size, 10),'path'=>$r['album_path']);
}
$result = OC_Gallery_Photo::find($album_details['album_id']);
diff --git a/apps/gallery/js/album_cover.js b/apps/gallery/js/album_cover.js
index 98f29072816..71de1adae11 100644
--- a/apps/gallery/js/album_cover.js
+++ b/apps/gallery/js/album_cover.js
@@ -1,184 +1,187 @@
var actual_cover;
-var paths = '';
+var paths = [];
var crumbCount = 0;
$(document).ready(returnToElement(0));
function returnToElement(num) {
- while (crumbCount != num) {
- $('#g-album-navigation .last').remove();
- $('#g-album-navigation .crumb :last').parent().addClass('last');
- crumbCount--;
- paths = paths.substring(0, paths.lastIndexOf('\/'));
- }
- $.getJSON('ajax/galleryOp.php', {operation: 'get_gallery', path: paths }, albumClickHandler);
+ while (crumbCount != num) {
+ $('#g-album-navigation .last').remove();
+ $('#g-album-navigation .crumb :last').parent().addClass('last');
+ crumbCount--;
+ paths.pop();
+ }
+ path=paths[paths.length-1];
+ $.getJSON(OC.filePath('gallery','ajax','galleryOp.php'), {operation: 'get_gallery', path: path }, albumClickHandler);
}
-function albumClick(e) {
- var title = decodeURIComponent(escape(e.data.title));
- paths += '/' + title;
- crumbCount++;
- $.getJSON('ajax/galleryOp.php', {operation: 'get_gallery', path: paths }, albumClickHandler);
- if ($('#g-album-navigation :last-child'))
- $('#g-album-navigation :last-child').removeClass('last');
- $('#g-album-navigation').append('<div class="crumb last real" style="background-image:url(\''+OC.webroot+'/core/img/breadcrumb.png\')"><a href=\"javascript:returnToElement('+crumbCount+');\">'+title+'</a></div>');
+function albumClick(title,path) {
+ paths.push(path);
+ crumbCount++;
+ $.getJSON(OC.filePath('gallery','ajax','galleryOp.php'), {operation: 'get_gallery', path: path }, albumClickHandler);
+ if ($('#g-album-navigation :last-child'))
+ $('#g-album-navigation :last-child').removeClass('last');
+ $('#g-album-navigation').append('<div class="crumb last real" style="background-image:url(\''+OC.imagePath('core','breadcrumb')+'\')"><a href=\"javascript:returnToElement('+crumbCount+');\">'+title+'</a></div>');
}
function albumClickHandler(r) {
- Albums.photos = [];
- Albums.albums = [];
- if (r.status == 'success') {
- for (var i in r.albums) {
- var a = r.albums[i];
- Albums.add(a.name, a.numOfItems);
- }
- for (var i in r.photos) {
- Albums.photos.push(r.photos[i]);
- }
- var targetDiv = document.getElementById('gallery_list');
- if (targetDiv) {
- $(targetDiv).html('');
- Albums.display(targetDiv);
- //$('#gallery_list').sortable({revert:true});
- $('.album').each(function(i, el) {
- $(el).click({title:$(el).attr('title')}, albumClick);
- //$(el).draggable({connectToSortable: '#gallery_list', handle: '.dummy'});
- });
- } else {
- OC.dialogs.alert(t('gallery', 'Error: no such layer `gallery_list`'), t('gallery', 'Internal error'));
- }
- } else {
- OC.dialogs.alert(t('gallery', 'Error: ') + r.message, t('gallery', 'Internal error'));
- }
+ Albums.photos = [];
+ Albums.albums = [];
+ if (r.status == 'success') {
+ for (var i in r.albums) {
+ var a = r.albums[i];
+ Albums.add(a.name, a.numOfItems,a.path);
+ }
+ for (var i in r.photos) {
+ Albums.photos.push(r.photos[i]);
+ }
+ var targetDiv = document.getElementById('gallery_list');
+ if (targetDiv) {
+ $(targetDiv).html('');
+ Albums.display(targetDiv);
+ //$('#gallery_list').sortable({revert:true});
+ $('.album').each(function(i, el) {
+ $(el).click(albumClick.bind(null,$(el).attr('title'),$(el).data('path')));
+ //$(el).draggable({connectToSortable: '#gallery_list', handle: '.dummy'});
+ });
+ } else {
+ OC.dialogs.alert(t('gallery', 'Error: no such layer `gallery_list`'), t('gallery', 'Internal error'));
+ }
+ } else {
+ OC.dialogs.alert(t('gallery', 'Error: ') + r.message, t('gallery', 'Internal error'));
+ }
}
function createNewAlbum() {
- var name = prompt("album name", "");
- if (name != null && name != "") {
- $.getJSON("ajax/createAlbum.php", {album_name: name}, function(r) {
- if (r.status == "success") {
- var v = '<div class="gallery_box"><a href="?view='+r.name+'"><img class="gallery_album_cover"/></a><h1>'+r.name+'</h1></div>';
- $('div#gallery_list').append(v);
- }
- });
- }
+ var name = prompt("album name", "");
+ if (name != null && name != "") {
+ $.getJSON(OC.filePath('gallery','ajax','createAlbum.php'), {album_name: name}, function(r) {
+ if (r.status == "success") {
+ var v = '<div class="gallery_box"><a href="?view='+r.name+'"><img class="gallery_album_cover"/></a><h1>'+r.name+'</h1></div>';
+ $('div#gallery_list').append(v);
+ }
+ });
+ }
}
var albumCounter = 0;
var totalAlbums = 0;
function scanForAlbums(cleanup) {
- cleanup = cleanup?true:false;
- var albumCounter = 0;
- var totalAlbums = 0;
- $('#g-scan-button').attr('disabled', 'true');
- $.getJSON('ajax/galleryOp.php?operation=filescan', {cleanup: cleanup}, function(r) {
+ cleanup = cleanup?true:false;
+ var albumCounter = 0;
+ var totalAlbums = 0;
+ $('#g-scan-button').attr('disabled', 'true');
+ $.getJSON(OC.filePath('gallery','ajax','galleryOp.php'), {cleanup: cleanup,operation:'filescan'}, function(r) {
- if (r.status == 'success') {
- totalAlbums = r.paths.length;
- if (totalAlbums == 0) {
- $('#notification').text(t('gallery', "No photos found")).fadeIn().slideDown().delay(3000).fadeOut().slideUp();
- return;
- }
- $('#scanprogressbar').progressbar({ value: (albumCounter/totalAlbums)*100 }).fadeIn();
- for(var a in r.paths) {
- $.getJSON('ajax/galleryOp.php',{operation:'partial_create','path':r.paths[a]}, function(r) {
+ if (r.status == 'success') {
+ totalAlbums = r.paths.length;
+ if (totalAlbums == 0) {
+ $('#notification').text(t('gallery', "No photos found")).fadeIn().slideDown().delay(3000).fadeOut().slideUp();
+ return;
+ }
+ $('#scanprogressbar').progressbar({ value: (albumCounter/totalAlbums)*100 }).fadeIn();
+ for(var a in r.paths) {
+ $.getJSON(OC.filePath('gallery','ajax','galleryOp.php'),{operation:'partial_create','path':r.paths[a]}, function(r) {
- albumCounter++;
- $('#scanprogressbar').progressbar({ value: (albumCounter/totalAlbums)*100 });
- if (albumCounter == totalAlbums) {
- $('#scanprogressbar').fadeOut();
- var targetDiv = document.getElementById('gallery_list');
- if (targetDiv) {
- targetDiv.innerHTML = '';
- Albums.photos = [];
- Albums.albums = [];
- returnToElement(0);
- } else {
- alert('Error occured: no such layer `gallery_list`');
- }
- $('#g-scan-button').attr('disabled', null);
- }
- });
- }
- } else {
- alert('Error occured: ' + r.message);
- }
- });
+ albumCounter++;
+ $('#scanprogressbar').progressbar({ value: (albumCounter/totalAlbums)*100 });
+ if (albumCounter == totalAlbums) {
+ $('#scanprogressbar').fadeOut();
+ var targetDiv = document.getElementById('gallery_list');
+ if (targetDiv) {
+ targetDiv.innerHTML = '';
+ Albums.photos = [];
+ Albums.albums = [];
+ returnToElement(0);
+ } else {
+ alert('Error occured: no such layer `gallery_list`');
+ }
+ $('#g-scan-button').attr('disabled', null);
+ }
+ });
+ }
+ } else {
+ alert('Error occured: ' + r.message);
+ }
+ });
}
function galleryRemove(albumName) {
- OC.dialogs.confirm(t('gallery', 'Do you want to remove album ') + decodeURIComponent(escape(albumName)),
- t('gallery', 'Remove confirmation'),
- function(decision) {
- if (decision) {
- $.getJSON("ajax/galleryOp.php", {operation: "remove", name: decodeURIComponent(escape(albumName))}, function(r) {
- if (r.status == "success") {
- $(".gallery_box").filterAttr('data-album',albumName).remove();
- Albums.remove(albumName);
- } else {
- OC.dialogs.alert(r.cause, "Error");
- }
- });
- }
- });
+ OC.dialogs.confirm(t('gallery', 'Do you want to remove album ') + decodeURIComponent(escape(albumName)),
+ t('gallery', 'Remove confirmation'),
+ function(decision) {
+ if (decision) {
+ $.getJSON(OC.filePath('gallery','ajax','galleryOp.php'), {operation: "remove", name: decodeURIComponent(escape(albumName))}, function(r) {
+ if (r.status == "success") {
+ $(".gallery_box").filterAttr('data-album',albumName).remove();
+ Albums.remove(albumName);
+ } else {
+ OC.dialogs.alert(r.cause, "Error");
+ }
+ });
+ }
+ }
+ );
}
function galleryRename(name) {
- OC.dialogs.prompt(t('gallery', 'New album name'),
- t('gallery', 'Change name'),
- name,
- function(newname) {
- if (newname == name || newname == '') return;
- if (Albums.find(newname)) {
- OC.dialogs.alert('Album ' + newname + ' exists', 'Alert');
- return;
- }
- $.getJSON('ajax/galleryOp.php', {operation: 'rename', oldname: name, newname: newname}, function(r) {
- if (r.status == 'success') {
- Albums.rename($(".gallery_box").filterAttr('data-album',name), newname);
- } else {
- OC.dialogs.alert('Error: ' + r.cause, 'Error');
- }
- });
- });
+ OC.dialogs.prompt(t('gallery', 'New album name'),
+ t('gallery', 'Change name'),
+ name,
+ function(newname) {
+ if (newname == name || newname == '') return;
+ if (Albums.find(newname)) {
+ OC.dialogs.alert('Album ' + newname + ' exists', 'Alert');
+ return;
+ }
+ $.getJSON(OC.filePath('gallery','ajax','galleryOp.php'), {operation: 'rename', oldname: name, newname: newname}, function(r) {
+ if (r.status == 'success') {
+ Albums.rename($(".gallery_box").filterAttr('data-album',name), newname);
+ } else {
+ OC.dialogs.alert('Error: ' + r.cause, 'Error');
+ }
+ });
+ }
+ );
}
function settings() {
- $( '#g-dialog-settings' ).dialog({
- height: 180,
- width: 350,
- modal: false,
- buttons: [{
- text: t('gallery', 'Apply'),
- click: function() {
- var scanning_root = $('#g-scanning-root').val();
- var disp_order = $('#g-display-order option:selected').val();
- if (scanning_root == '') {
- alert('Scanning root cannot be empty');
- return;
- }
- $.getJSON('ajax/galleryOp.php', {operation: 'store_settings', root: scanning_root, order: disp_order}, function(r) {
- if (r.status == 'success') {
- if (r.rescan == 'yes') {
- $('#g-dialog-settings').dialog('close');
- Albums.clear(document.getElementById('gallery_list'));
- scanForAlbums(true);
- return;
- }
- } else {
- alert('Error: ' + r.cause);
- return;
- }
- $('#g-dialog-settings').dialog('close');
- });
- }
- },
- {
- text: t('gallery', 'Cancel'),
- click: function() {
- $(this).dialog('close');
- }
- }
- ],
- });
+ $( '#g-dialog-settings' ).dialog({
+ height: 180,
+ width: 350,
+ modal: false,
+ buttons: [
+ {
+ text: t('gallery', 'Apply'),
+ click: function() {
+ var scanning_root = $('#g-scanning-root').val();
+ var disp_order = $('#g-display-order option:selected').val();
+ if (scanning_root == '') {
+ alert('Scanning root cannot be empty');
+ return;
+ }
+ $.getJSON(OC.filePath('gallery','ajax','galleryOp.php'), {operation: 'store_settings', root: scanning_root, order: disp_order}, function(r) {
+ if (r.status == 'success') {
+ if (r.rescan == 'yes') {
+ $('#g-dialog-settings').dialog('close');
+ Albums.clear(document.getElementById('gallery_list'));
+ scanForAlbums(true);
+ return;
+ }
+ } else {
+ alert('Error: ' + r.cause);
+ return;
+ }
+ $('#g-dialog-settings').dialog('close');
+ });
+ }
+ },
+ {
+ text: t('gallery', 'Cancel'),
+ click: function() {
+ $(this).dialog('close');
+ }
+ }
+ ],
+ });
}
diff --git a/apps/gallery/js/albums.js b/apps/gallery/js/albums.js
index 3882deb5146..afdfbd3cc83 100644
--- a/apps/gallery/js/albums.js
+++ b/apps/gallery/js/albums.js
@@ -1,100 +1,98 @@
Albums={
- // album item in this array should look as follow
- // {name: string,
- // numOfCovers: int}
- //
- // previews array should be an array of base64 decoded images
- // to display to user as preview picture when scrolling throught
- // the album cover
- albums:new Array(),
- photos:new Array(),
- // add simply adds new album to internal structure
- // however albums names must be unique so other
- // album with the same name wont be insered,
- // and false will be returned
- // true on success
- add: function(album_name, num) {
- if (Albums.albums[album_name] != undefined) return false;
- Albums.albums[album_name] = {name: album_name, numOfCovers: num};
- return true;
- },
- // remove element with given name
- // returns remove element or undefined if no such element was present
- remove: function(name) {
- var i = -1, tmp = 0;
- for (var a in Albums.albums) {
- if (a.name == name) {
- i = tmp;
- break;
- }
- tmp++;
- }
- if (i != -1) {
- return Albums.albums.splice(i,1);
- }
- return undefined;
- },
- // return element which match given name
- // of undefined if such element do not exist
- find: function(name) {
- return Albums.albums[name];
- },
- // displays gallery in linear representation
- // on given element, and apply default styles for gallery
- display: function(element) {
- var displayTemplate = '<div class="gallery_box album"><div class="dummy"></div><a class="view"><div class="gallery_album_cover"></div></a><h1></h1><div class="gallery_album_decoration"><a><img src="img/share.png" title="Share"></a><a class="rename"><img src="img/rename.png" title="Rename"></a><a class="remove"><img src="img/delete.png" title="Delete"></a></div></div>';
- for (var i in Albums.albums) {
- var a = Albums.albums[i];
- var local=$(displayTemplate);
- local.attr('title', a.name);
- local.attr('data-album',a.name);
- $(".gallery_album_decoration a.rename", local).bind('click', {name: a.name},function(event){
- event.preventDefault();
- event.stopPropagation();
- galleryRename(event.data.name);
- });
- $(".gallery_album_decoration a.remove", local).bind('click', {name: a.name},function(event){
- event.preventDefault();
- event.stopPropagation();
- galleryRemove(event.data.name);
- });
- // $("a.view", local).attr('href','?view='+decodeURIComponent(escape(a.name)));
- $('h1',local).text(decodeURIComponent(escape(a.name)));
- $(".gallery_album_cover", local).attr('title',decodeURIComponent(escape(a.name)));
- $(".gallery_album_cover", local).css('background-repeat', 'no-repeat');
- $(".gallery_album_cover", local).css('background-position', '0');
- $(".gallery_album_cover", local).css('background-image','url("ajax/galleryOp.php?operation=get_covers&albumname='+escape(a.name)+'")');
- $(".gallery_album_cover", local).mousemove(function(e) {
-
- var albumMetadata = Albums.find(this.title);
- if (albumMetadata == undefined) {
- return;
- }
- var x = Math.floor((e.layerX - this.offsetLeft)/(this.offsetWidth/albumMetadata.numOfCovers));
- x *= this.offsetWidth;
- if (x < 0) x=0;
- $(this).css('background-position', -x+'px 0');
- });
- $(element).append(local);
- }
- var photoDisplayTemplate = '<div class="gallery_box"><div class="dummy"></div><div><a rel="images" href="'+OC.webroot+'/files/download.php?file=URLPATH"><img src="ajax/thumbnail.php?img=IMGPATH"></a></div></div>';
- for (var i in Albums.photos) {
- $(element).append(photoDisplayTemplate.replace("IMGPATH", escape(Albums.photos[i])).replace("URLPATH", escape(Albums.photos[i])));
- }
- $("a[rel=images]").fancybox({
- 'titlePosition': 'inside'
- });
- },
- rename: function(element, new_name) {
- if (new_name) {
- $(element).attr("data-album", new_name);
- $("a.view", element).attr("href", "?view="+new_name);
- $("h1", element).text(new_name);
+ // album item in this array should look as follow
+ // {name: string,
+ // numOfCovers: int}
+ //
+ // previews array should be an array of base64 decoded images
+ // to display to user as preview picture when scrolling throught
+ // the album cover
+ albums:new Array(),
+ photos:new Array(),
+ // add simply adds new album to internal structure
+ // however albums names must be unique so other
+ // album with the same name wont be insered,
+ // and false will be returned
+ // true on success
+ add: function(album_name, num,path) {
+ if (Albums.albums[album_name] != undefined) return false;
+ Albums.albums[album_name] = {name: album_name, numOfCovers: num, path:path};
+ return true;
+ },
+ // remove element with given name
+ // returns remove element or undefined if no such element was present
+ remove: function(name) {
+ var i = -1, tmp = 0;
+ for (var a in Albums.albums) {
+ if (a.name == name) {
+ i = tmp;
+ break;
+ }
+ tmp++;
+ }
+ if (i != -1) {
+ return Albums.albums.splice(i,1);
+ }
+ return undefined;
+ },
+ // return element which match given name
+ // of undefined if such element do not exist
+ find: function(name) {
+ return Albums.albums[name];
+ },
+ // displays gallery in linear representation
+ // on given element, and apply default styles for gallery
+ display: function(element) {
+ var displayTemplate = '<div class="gallery_box album"><div class="dummy"></div><a class="view"><div class="gallery_album_cover"></div></a><h1></h1><div class="gallery_album_decoration"><a><img src="img/share.png" title="Share"></a><a class="rename"><img src="img/rename.png" title="Rename"></a><a class="remove"><img src="img/delete.png" title="Delete"></a></div></div>';
+ for (var i in Albums.albums) {
+ var a = Albums.albums[i];
+ var local=$(displayTemplate);
+ local.attr('title', a.name);
+ local.attr('data-path', a.path);
+ local.attr('data-album',a.name);
+ $(".gallery_album_decoration a.rename", local).bind('click', {name: a.name},function(name,event){
+ event.preventDefault();
+ event.stopPropagation();
+ galleryRename(name);
+ }.bind(null,a.name));
+ $(".gallery_album_decoration a.remove", local).bind('click', {name: a.name},function(name,event){
+ event.preventDefault();
+ event.stopPropagation();
+ galleryRemove(name);
+ }.bind(null,a.name));
+ $('h1',local).text(decodeURIComponent(escape(a.name)));
+ $(".gallery_album_cover", local).attr('title',decodeURIComponent(escape(a.name)));
+ $(".gallery_album_cover", local).css('background-repeat', 'no-repeat');
+ $(".gallery_album_cover", local).css('background-position', '0');
+ $(".gallery_album_cover", local).css('background-image','url("'+OC.filePath('gallery','ajax','galleryOp.php')+'?operation=get_covers&albumname='+escape(a.name)+'")');
+ $(".gallery_album_cover", local).mousemove(function(e) {
+ var albumMetadata = Albums.find(this.title);
+ if (albumMetadata == undefined) {
+ return;
+ }
+ var x = Math.floor((e.layerX - this.offsetLeft)/(this.offsetWidth/albumMetadata.numOfCovers));
+ x *= this.offsetWidth;
+ if (x < 0) x=0;
+ $(this).css('background-position', -x+'px 0');
+ });
+ $(element).append(local);
+ }
+ var photoDisplayTemplate = '<div class="gallery_box"><div class="dummy"></div><div><a rel="images" href="'+OC.linkTo('files','download.php')+'?file=URLPATH"><img src="'+OC.filePath('gallery','ajax','thumbnail.php')+'?img=IMGPATH"></a></div></div>';
+ for (var i in Albums.photos) {
+ $(element).append(photoDisplayTemplate.replace("IMGPATH", escape(Albums.photos[i])).replace("URLPATH", escape(Albums.photos[i])));
+ }
+ $("a[rel=images]").fancybox({
+ 'titlePosition': 'inside'
+ });
+ },
+ rename: function(element, new_name) {
+ if (new_name) {
+ $(element).attr("data-album", new_name);
+ $("a.view", element).attr("href", "?view="+new_name);
+ $("h1", element).text(new_name);
+ }
+ },
+ clear: function(element) {
+ Albums.albums = new Array();
+ element.innerHTML = '';
}
- },
- clear: function(element) {
- Albums.albums = new Array();
- element.innerHTML = '';
- }
-
}