Completed
Push — master ( 8f13d8...7401de )
by Olivier
09:09
created

$(document).ready   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 5
rs 9.4285

1 Function

Rating   Name   Duplication   Size   Complexity  
A 0 3 1
1
/* global OC, $, _, Gallery, SlideShow */
2
$(document).ready(function () {
3
	"use strict";
4
	$('#controls').insertBefore($('#content-wrapper'));
5
	Gallery.utility = new Gallery.Utility();
6
	Gallery.view = new Gallery.View();
7
	Gallery.token = Gallery.utility.getPublicToken();
8
	Gallery.ieVersion = Gallery.utility.getIeVersion();
9
	Gallery.filesClient = new OC.Files.Client({
10
		host: Gallery.utility.getWebdavHost(),
11
		port: OC.getPort(),
12
		root: Gallery.utility.getWebdavRoot(),
13
		useHTTPS: OC.getProtocol() === 'https'
14
	});
15
16
	// The first thing to do is to detect if we're on IE
17
	if (Gallery.ieVersion === 'unsupportedIe') {
18
		Gallery.utility.showIeWarning(Gallery.ieVersion);
19
		Gallery.view.showEmptyFolder('', null);
20
	} else {
21
		if (Gallery.ieVersion === 'oldIe') {
22
			Gallery.utility.showIeWarning(Gallery.ieVersion);
23
		}
24
25
		// Get the config, the files and initialise the slideshow
26
		Gallery.view.showLoading();
27
		$.getJSON(Gallery.utility.buildGalleryUrl('config', '', {}))
28
			.then(function (config) {
29
				Gallery.config = new Gallery.Config(config);
30
				var currentLocation = window.location.href.split('#')[1] || '';
31
				Gallery.activeSlideShow = new SlideShow();
32
				$.when(
33
					Gallery.activeSlideShow.init(
34
						false,
35
						null,
36
						Gallery.config.galleryFeatures
37
					))
38
					.then(function () {
39
						Gallery.getFiles(currentLocation).then(function () {
40
							window.onhashchange();
41
						});
42
					});
43
			});
44
45
		$(document).click(function () {
46
			$('.album-info-container').slideUp();
47
		});
48
49
		// This block loads new rows
50
		$('html, #content-wrapper').scroll(function () {
51
			Gallery.view.loadVisibleRows(Gallery.albumMap[Gallery.currentAlbum]);
52
		});
53
54
55
		var windowWidth = $(window).width();
56
		var windowHeight = $(window).height();
57
		$(window).resize(_.throttle(function () {
58
			var infoContentContainer = $('.album-info-container');
59
			// This section redraws the photowall and limits the width of dropdowns
60
			if (windowWidth !== $(window).width()) {
61
				if ($('#emptycontent').is(':hidden')) {
62
					Gallery.view.viewAlbum(Gallery.currentAlbum);
63
					infoContentContainer.css('max-width', $(window).width());
64
				}
65
				if (Gallery.currentAlbum) {
66
					Gallery.view.breadcrumb.setMaxWidth($(window).width() - Gallery.buttonsWidth);
67
				}
68
69
				windowWidth = $(window).width();
70
			}
71
			// This makes sure dropdowns will not be hidden after a window resize
72
			if (windowHeight !== $(window).height()) {
73
				infoContentContainer.css('max-height',
74
					$(window).height() - Gallery.browserToolbarHeight);
75
76
				windowHeight = $(window).height();
77
			}
78
		}, 250)); // A shorter delay avoids redrawing the view in the middle of a previous request,
79
				  // but it may kill baby CPUs
80
	}
81
});
82
83
/**
84
 * Responsible to refresh the view when we detect a change of location via the browser URL
85
 */
86
window.onhashchange = function () {
87
	"use strict";
88
	Gallery.view.dimControls();
89
	var currentLocation = window.location.href.split('#')[1] || '';
90
	// The hash location is ALWAYS encoded, despite what the browser shows
91
	var path = decodeURIComponent(currentLocation);
92
93
	// This section tries to determine if the hash location points to a file or a folder
94
	var albumPath = OC.dirname(path);
95
	if (Gallery.albumMap[path]) {
96
		albumPath = path;
97
	} else if (!Gallery.albumMap[albumPath]) {
98
		albumPath = '';
99
	}
100
	// We need to get new files if we've assessed that we've changed folder
101
	if (Gallery.currentAlbum !== null && Gallery.currentAlbum !== albumPath) {
102
		Gallery.getFiles(currentLocation).done(function () {
103
			Gallery.refresh(path, albumPath);
104
		});
105
	} else {
106
		// When the gallery is first loaded, the files have already been fetched
107
		Gallery.refresh(path, albumPath);
108
	}
109
};
110