diff options
author | Olivier Paroz <github@oparoz.com> | 2015-04-16 04:23:10 +0300 |
---|---|---|
committer | Olivier Paroz <github@oparoz.com> | 2015-04-16 04:23:10 +0300 |
commit | 764c47189a4017e4f1c83b3fc15fe2218eb2bbab (patch) | |
tree | 95afc746b74b9d999a2194b368ce19c976658882 /js | |
parent | 5a6128cd544d1065f271562b46d6212f33c6ee02 (diff) |
More JS class separations
Diffstat (limited to 'js')
-rw-r--r-- | js/app.js | 100 | ||||
-rw-r--r-- | js/gallery.js | 100 | ||||
-rw-r--r-- | js/galleryfileaction.js | 82 | ||||
-rw-r--r-- | js/slideshow.js | 84 |
4 files changed, 183 insertions, 183 deletions
diff --git a/js/app.js b/js/app.js new file mode 100644 index 00000000..34da7abb --- /dev/null +++ b/js/app.js @@ -0,0 +1,100 @@ +/* global OC, $, _, t, Gallery */ +$(document).ready(function () { + Gallery.hideSearch(); + + Gallery.ie11AndAbove = + navigator.userAgent.indexOf('Trident') != -1 && navigator.userAgent.indexOf('MSIE') == -1; + Gallery.ie10AndBelow = navigator.userAgent.indexOf('MSIE') != -1; + + if (Gallery.ie10AndBelow) { + Gallery.showOldIeWarning(); + Gallery.showEmpty(); + } else { + if (Gallery.ie11AndAbove) { + Gallery.showModernIeWarning(); + } + + // Needed to centre the spinner in some browsers + Gallery.resetContentHeight(); + Gallery.showLoading(); + + Gallery.view = new Gallery.View(); + Gallery.token = Gallery.view.getRequestToken(); + + $.getJSON(Gallery.buildGalleryUrl('mediatypes', '', {})) + .then(function (mediaTypes) { + //console.log('mediaTypes', mediaTypes); + Gallery.mediaTypes = mediaTypes; + }) + .then(function () { + Gallery.getFiles().then(function () { + window.onhashchange(); + }); + }); + + $('#openAsFileListButton').click(function () { + var subUrl = ''; + var params = {path: '/' + encodeURIComponent(Gallery.currentAlbum)}; + if (Gallery.token) { + params.token = Gallery.token; + subUrl = 's/{token}?path={path}'; + } else { + subUrl = 'apps/files?dir={path}'; + } + OC.redirect(OC.generateUrl(subUrl, params)); + }); + + $(document).click(function () { + $('.album-info-content').slideUp(); + }); + + $(window).scroll(function () { + Gallery.view.loadVisibleRows(Gallery.albumMap[Gallery.currentAlbum], + Gallery.currentAlbum); + }); + $('#content-wrapper').scroll(function () { + Gallery.view.loadVisibleRows(Gallery.albumMap[Gallery.currentAlbum], + Gallery.currentAlbum); + }); + + // A shorter delay avoids redrawing the view in the middle of a previous request, but it + // may kill baby CPUs + var windowWidth = $(window).width(); + var windowHeight = $(window).height(); + $(window).resize(_.throttle(function () { + if (windowWidth !== $(window).width()) { + Gallery.view.viewAlbum(Gallery.currentAlbum); + // 320 is the width required for the buttons + Gallery.view.breadcrumb.setMaxWidth(windowWidth - 320); + + windowWidth = $(window).width(); + } + if (windowHeight !== $(window).height()) { + Gallery.resetContentHeight(); + var infoContentElement = $('.album-info-content'); + // 150 is the space required for the browser toolbar on some mobile OS + infoContentElement.css('max-height', windowHeight - 150); + + windowHeight = $(window).height(); + } + }, 250)); + } +}); + +window.onhashchange = function () { + // The hash location is ALWAYS encoded + var path = decodeURIComponent(window.location.href.split('#')[1] || ''); + var albumPath = OC.dirname(path); + if (Gallery.albumMap[path]) { + albumPath = path; + } else if (!Gallery.albumMap[albumPath]) { + albumPath = ''; + } + if (Gallery.currentAlbum !== null && Gallery.currentAlbum !== albumPath) { + Gallery.getFiles().done(function () { + Gallery.refresh(path, albumPath); + }); + } else { + Gallery.refresh(path, albumPath); + } +};
\ No newline at end of file diff --git a/js/gallery.js b/js/gallery.js index e9ab9580..98dbdbe1 100644 --- a/js/gallery.js +++ b/js/gallery.js @@ -483,103 +483,3 @@ Gallery.slideShow = function (images, startImage, autoPlay) { }; Gallery.activeSlideShow = null; - -$(document).ready(function () { - Gallery.hideSearch(); - - Gallery.ie11AndAbove = - navigator.userAgent.indexOf('Trident') != -1 && navigator.userAgent.indexOf('MSIE') == -1; - Gallery.ie10AndBelow = navigator.userAgent.indexOf('MSIE') != -1; - - if (Gallery.ie10AndBelow) { - Gallery.showOldIeWarning(); - Gallery.showEmpty(); - } else { - if (Gallery.ie11AndAbove) { - Gallery.showModernIeWarning(); - } - - // Needed to centre the spinner in some browsers - Gallery.resetContentHeight(); - Gallery.showLoading(); - - Gallery.view = new Gallery.View(); - Gallery.token = Gallery.view.getRequestToken(); - - $.getJSON(Gallery.buildGalleryUrl('mediatypes', '', {})) - .then(function (mediaTypes) { - //console.log('mediaTypes', mediaTypes); - Gallery.mediaTypes = mediaTypes; - }) - .then(function () { - Gallery.getFiles().then(function () { - window.onhashchange(); - }); - }); - - $('#openAsFileListButton').click(function () { - var subUrl = ''; - var params = {path: '/' + encodeURIComponent(Gallery.currentAlbum)}; - if (Gallery.token) { - params.token = Gallery.token; - subUrl = 's/{token}?path={path}'; - } else { - subUrl = 'apps/files?dir={path}'; - } - OC.redirect(OC.generateUrl(subUrl, params)); - }); - - $(document).click(function () { - $('.album-info-content').slideUp(); - }); - - $(window).scroll(function () { - Gallery.view.loadVisibleRows(Gallery.albumMap[Gallery.currentAlbum], - Gallery.currentAlbum); - }); - $('#content-wrapper').scroll(function () { - Gallery.view.loadVisibleRows(Gallery.albumMap[Gallery.currentAlbum], - Gallery.currentAlbum); - }); - - // A shorter delay avoids redrawing the view in the middle of a previous request, but it - // may kill baby CPUs - var windowWidth = $(window).width(); - var windowHeight = $(window).height(); - $(window).resize(_.throttle(function () { - if (windowWidth !== $(window).width()) { - Gallery.view.viewAlbum(Gallery.currentAlbum); - // 320 is the width required for the buttons - Gallery.view.breadcrumb.setMaxWidth(windowWidth - 320); - - windowWidth = $(window).width(); - } - if (windowHeight !== $(window).height()) { - Gallery.resetContentHeight(); - var infoContentElement = $('.album-info-content'); - // 150 is the space required for the browser toolbar on some mobile OS - infoContentElement.css('max-height', windowHeight - 150); - - windowHeight = $(window).height(); - } - }, 250)); - } -}); - -window.onhashchange = function () { - // The hash location is ALWAYS encoded - var path = decodeURIComponent(window.location.href.split('#')[1] || ''); - var albumPath = OC.dirname(path); - if (Gallery.albumMap[path]) { - albumPath = path; - } else if (!Gallery.albumMap[albumPath]) { - albumPath = ''; - } - if (Gallery.currentAlbum !== null && Gallery.currentAlbum !== albumPath) { - Gallery.getFiles().done(function () { - Gallery.refresh(path, albumPath); - }); - } else { - Gallery.refresh(path, albumPath); - } -}; diff --git a/js/galleryfileaction.js b/js/galleryfileaction.js new file mode 100644 index 00000000..604ccf25 --- /dev/null +++ b/js/galleryfileaction.js @@ -0,0 +1,82 @@ +/* global jQuery, OC ,OCA, $, t, oc_requesttoken, SlideShow */ +$(document).ready(function () { + // This is still required in OC8 + var requestToken; + if ($('#filesApp').val() && $('#isPublic').val()) { + // That's the only way to get one with the broken template + requestToken = $('#publicUploadRequestToken').val(); + } else if ($('#gallery').data('requesttoken')) { + requestToken = $('#gallery').data('requesttoken'); + } else { + requestToken = oc_requesttoken; + } + $(document).on('ajaxSend', function (elm, xhr) { + xhr.setRequestHeader('requesttoken', requestToken); + }); + + var prepareFileActions = function (mime) { + return OCA.Files.fileActions.register(mime, 'View', OC.PERMISSION_READ, '', + function (filename, context) { + var imageUrl, downloadUrl; + var fileList = context.fileList; + var files = fileList.files; + var start = 0; + var images = []; + var dir = context.dir + '/'; + var width = Math.floor($(window).width() * window.devicePixelRatio); + var height = Math.floor($(window).height() * window.devicePixelRatio); + + for (var i = 0; i < files.length; i++) { + var file = files[i]; + // We only add images to the slideshow if we think we'll be able + // to generate previews for this media type + if (file.isPreviewAvailable || file.mimetype === 'image/svg+xml') { + var params = { + file: dir + file.name, + x: width, + y: height, + requesttoken: requestToken + }; + imageUrl = SlideShow.buildGalleryUrl('preview', '', params); + downloadUrl = SlideShow.buildGalleryUrl('download', '', params); + + images.push({ + name: file.name, + path: dir + file.name, + mimeType: file.mimetype, + url: imageUrl, + downloadUrl: downloadUrl + }); + } + } + for (i = 0; i < images.length; i++) { + //console.log("Images in the slideshow : ", images[i]); + if (images[i].name === filename) { + start = i; + } + } + var slideShow = new SlideShow($('#slideshow'), images); + slideShow.onStop = function () { + location.hash = ''; + }; + slideShow.init(); + slideShow.show(start); + }); + }; + + var url = SlideShow.buildGalleryUrl('mediatypes', '', {slideshow: 1}); + // We're asking for a list of supported media types. Media files are retrieved through the + // context + $.getJSON(url).then(function (mediaTypes) { + //console.log("enabledPreviewProviders: ", mediaTypes); + SlideShow.mediaTypes = mediaTypes; + + // We only want to create slideshows for supported media types + for (var i = 0, keys = Object.keys(mediaTypes); i < keys.length; i++) { + // Each click handler gets the same function and images array and + // is responsible to load the slideshow + prepareFileActions(keys[i]); + OCA.Files.fileActions.setDefault(keys[i], 'View'); + } + }); +});
\ No newline at end of file diff --git a/js/slideshow.js b/js/slideshow.js index 6a877408..b1f6edff 100644 --- a/js/slideshow.js +++ b/js/slideshow.js @@ -1,4 +1,4 @@ -/* global jQuery, OC ,OCA, $, t, oc_requesttoken */ +/* global jQuery, OC, $, t */ /** * * @param {jQuery} container @@ -343,86 +343,4 @@ $(document).ready(function () { }).fail(function () { OC.Notification.show(t('core', 'Error loading slideshow template')); }); - - if (OCA.Files && OCA.Files.fileActions) { - // This is still required in OC8 - var requestToken; - if ($('#filesApp').val() && $('#isPublic').val()) { - // That's the only way to get one with the broken template - requestToken = $('#publicUploadRequestToken').val(); - } else if ($('#gallery').data('requesttoken')) { - requestToken = $('#gallery').data('requesttoken'); - } else { - requestToken = oc_requesttoken; - } - $(document).on('ajaxSend', function (elm, xhr) { - xhr.setRequestHeader('requesttoken', requestToken); - }); - - var prepareFileActions = function (mime) { - return OCA.Files.fileActions.register(mime, 'View', OC.PERMISSION_READ, '', - function (filename, context) { - var imageUrl, downloadUrl; - var fileList = context.fileList; - var files = fileList.files; - var start = 0; - var images = []; - var dir = context.dir + '/'; - var width = Math.floor($(window).width() * window.devicePixelRatio); - var height = Math.floor($(window).height() * window.devicePixelRatio); - - for (var i = 0; i < files.length; i++) { - var file = files[i]; - // We only add images to the slideshow if we think we'll be able - // to generate previews for this media type - if (file.isPreviewAvailable || file.mimetype === 'image/svg+xml') { - var params = { - file: dir + file.name, - x: width, - y: height, - requesttoken: requestToken - }; - imageUrl = SlideShow.buildGalleryUrl('preview', '', params); - downloadUrl = SlideShow.buildGalleryUrl('download', '', params); - - images.push({ - name: file.name, - path: dir + file.name, - mimeType: file.mimetype, - url: imageUrl, - downloadUrl: downloadUrl - }); - } - } - for (i = 0; i < images.length; i++) { - //console.log("Images in the slideshow : ", images[i]); - if (images[i].name === filename) { - start = i; - } - } - var slideShow = new SlideShow($('#slideshow'), images); - slideShow.onStop = function () { - location.hash = ''; - }; - slideShow.init(); - slideShow.show(start); - }); - }; - - var url = SlideShow.buildGalleryUrl('mediatypes', '', {slideshow: 1}); - // We're asking for a list of supported media types. Media files are retrieved through the - // context - $.getJSON(url).then(function (mediaTypes) { - //console.log("enabledPreviewProviders: ", mediaTypes); - SlideShow.mediaTypes = mediaTypes; - - // We only want to create slideshows for supported media types - for (var i = 0, keys = Object.keys(mediaTypes); i < keys.length; i++) { - // Each click handler gets the same function and images array and - // is responsible to load the slideshow - prepareFileActions(keys[i]); - OCA.Files.fileActions.setDefault(keys[i], 'View'); - } - }); - } }); |