2016-01-21 17:23:03 +03:00
|
|
|
|
/* global oc_isadmin */
|
|
|
|
|
|
2013-02-07 11:11:18 +04:00
|
|
|
|
var oc_debug;
|
|
|
|
|
var oc_webroot;
|
2013-06-26 13:23:21 +04:00
|
|
|
|
|
|
|
|
|
var oc_current_user = document.getElementsByTagName('head')[0].getAttribute('data-user');
|
|
|
|
|
var oc_requesttoken = document.getElementsByTagName('head')[0].getAttribute('data-requesttoken');
|
|
|
|
|
|
2014-02-04 16:56:10 +04:00
|
|
|
|
window.oc_config = window.oc_config || {};
|
|
|
|
|
|
2013-02-08 21:44:52 +04:00
|
|
|
|
if (typeof oc_webroot === "undefined") {
|
2013-12-13 15:54:08 +04:00
|
|
|
|
oc_webroot = location.pathname;
|
|
|
|
|
var pos = oc_webroot.indexOf('/index.php/');
|
|
|
|
|
if (pos !== -1) {
|
|
|
|
|
oc_webroot = oc_webroot.substr(0, pos);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
oc_webroot = oc_webroot.substr(0, oc_webroot.lastIndexOf('/'));
|
|
|
|
|
}
|
2013-02-08 21:44:52 +04:00
|
|
|
|
}
|
2012-11-15 22:43:10 +04:00
|
|
|
|
|
2018-10-24 17:24:16 +03:00
|
|
|
|
/** @namespace OCP */
|
2019-01-28 13:24:08 +03:00
|
|
|
|
var OCP = Object.assign({}, window.OCP);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @namespace OC
|
|
|
|
|
*/
|
|
|
|
|
Object.assign(window.OC, {
|
2017-11-02 16:55:58 +03:00
|
|
|
|
PERMISSION_NONE:0,
|
2012-08-31 02:59:10 +04:00
|
|
|
|
PERMISSION_CREATE:4,
|
|
|
|
|
PERMISSION_READ:1,
|
|
|
|
|
PERMISSION_UPDATE:2,
|
|
|
|
|
PERMISSION_DELETE:8,
|
|
|
|
|
PERMISSION_SHARE:16,
|
2013-08-14 00:58:27 +04:00
|
|
|
|
PERMISSION_ALL:31,
|
2014-11-18 20:53:45 +03:00
|
|
|
|
TAG_FAVORITE: '_$!<Favorite>!$_',
|
2014-05-26 20:43:26 +04:00
|
|
|
|
/* jshint camelcase: false */
|
2015-07-13 16:26:01 +03:00
|
|
|
|
/**
|
2016-11-24 18:05:05 +03:00
|
|
|
|
* Relative path to Nextcloud root.
|
|
|
|
|
* For example: "/nextcloud"
|
2015-07-13 16:26:01 +03:00
|
|
|
|
*
|
|
|
|
|
* @type string
|
|
|
|
|
*
|
|
|
|
|
* @deprecated since 8.2, use OC.getRootPath() instead
|
|
|
|
|
* @see OC#getRootPath
|
|
|
|
|
*/
|
2011-07-26 00:30:55 +04:00
|
|
|
|
webroot:oc_webroot,
|
2015-07-13 16:26:01 +03:00
|
|
|
|
|
2017-12-01 12:36:13 +03:00
|
|
|
|
/**
|
|
|
|
|
* Capabilities
|
|
|
|
|
*
|
|
|
|
|
* @type array
|
|
|
|
|
*/
|
|
|
|
|
_capabilities: window.oc_capabilities || null,
|
|
|
|
|
|
2013-01-07 23:15:51 +04:00
|
|
|
|
appswebroots:(typeof oc_appswebroots !== 'undefined') ? oc_appswebroots:false,
|
2016-02-01 17:11:42 +03:00
|
|
|
|
/**
|
|
|
|
|
* Currently logged in user or null if none
|
|
|
|
|
*
|
|
|
|
|
* @type String
|
|
|
|
|
* @deprecated use {@link OC.getCurrentUser} instead
|
|
|
|
|
*/
|
2011-08-11 18:53:00 +04:00
|
|
|
|
currentUser:(typeof oc_current_user!=='undefined')?oc_current_user:false,
|
2014-05-30 21:02:19 +04:00
|
|
|
|
config: window.oc_config,
|
|
|
|
|
appConfig: window.oc_appconfig || {},
|
|
|
|
|
theme: window.oc_defaults || {},
|
2015-01-13 18:42:04 +03:00
|
|
|
|
coreApps:['', 'admin','log','core/search','settings','core','3rdparty'],
|
2015-08-26 18:08:25 +03:00
|
|
|
|
requestToken: oc_requesttoken,
|
2015-03-26 13:59:30 +03:00
|
|
|
|
menuSpeed: 50,
|
2014-05-19 17:44:19 +04:00
|
|
|
|
|
2011-08-07 01:18:49 +04:00
|
|
|
|
/**
|
2014-04-21 15:46:33 +04:00
|
|
|
|
* Get an absolute url to a file in an app
|
|
|
|
|
* @param {string} app the id of the app the file belongs to
|
|
|
|
|
* @param {string} file the file path relative to the app folder
|
|
|
|
|
* @return {string} Absolute URL to a file
|
2011-08-07 01:18:49 +04:00
|
|
|
|
*/
|
2011-07-26 00:30:55 +04:00
|
|
|
|
linkTo:function(app,file){
|
|
|
|
|
return OC.filePath(app,'',file);
|
|
|
|
|
},
|
2014-10-07 14:02:58 +04:00
|
|
|
|
|
2013-01-25 19:00:26 +04:00
|
|
|
|
/**
|
2014-04-21 15:46:33 +04:00
|
|
|
|
* Creates a relative url for remote use
|
|
|
|
|
* @param {string} service id
|
|
|
|
|
* @return {string} the url
|
2013-01-25 19:00:26 +04:00
|
|
|
|
*/
|
|
|
|
|
linkToRemoteBase:function(service) {
|
2018-10-09 08:44:26 +03:00
|
|
|
|
return OC.getRootPath() + '/remote.php/' + service;
|
2013-01-25 19:00:26 +04:00
|
|
|
|
},
|
2014-03-03 01:30:24 +04:00
|
|
|
|
|
2014-04-21 15:46:33 +04:00
|
|
|
|
/**
|
|
|
|
|
* @brief Creates an absolute url for remote use
|
|
|
|
|
* @param {string} service id
|
|
|
|
|
* @return {string} the url
|
|
|
|
|
*/
|
|
|
|
|
linkToRemote:function(service) {
|
|
|
|
|
return window.location.protocol + '//' + window.location.host + OC.linkToRemoteBase(service);
|
|
|
|
|
},
|
2014-04-30 19:42:35 +04:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets the base path for the given OCS API service.
|
|
|
|
|
* @param {string} service name
|
2015-11-16 16:21:45 +03:00
|
|
|
|
* @param {int} version OCS API version
|
2014-04-30 19:42:35 +04:00
|
|
|
|
* @return {string} OCS API base path
|
|
|
|
|
*/
|
2015-11-16 16:21:45 +03:00
|
|
|
|
linkToOCS: function(service, version) {
|
|
|
|
|
version = (version !== 2) ? 1 : 2;
|
2018-10-09 08:44:26 +03:00
|
|
|
|
return window.location.protocol + '//' + window.location.host + OC.getRootPath() + '/ocs/v' + version + '.php/' + service + '/';
|
2014-04-30 19:42:35 +04:00
|
|
|
|
},
|
|
|
|
|
|
2014-03-03 02:15:37 +04:00
|
|
|
|
/**
|
|
|
|
|
* Generates the absolute url for the given relative url, which can contain parameters.
|
2015-02-16 22:07:45 +03:00
|
|
|
|
* Parameters will be URL encoded automatically.
|
2014-04-21 16:42:50 +04:00
|
|
|
|
* @param {string} url
|
2015-02-11 16:01:22 +03:00
|
|
|
|
* @param [params] params
|
2015-02-16 22:07:45 +03:00
|
|
|
|
* @param [options] options
|
|
|
|
|
* @param {bool} [options.escape=true] enable/disable auto escape of placeholders (by default enabled)
|
2014-04-21 15:46:33 +04:00
|
|
|
|
* @return {string} Absolute URL for the given relative URL
|
2014-03-03 02:15:37 +04:00
|
|
|
|
*/
|
2015-02-16 22:07:45 +03:00
|
|
|
|
generateUrl: function(url, params, options) {
|
|
|
|
|
var defaultOptions = {
|
|
|
|
|
escape: true
|
|
|
|
|
},
|
|
|
|
|
allOptions = options || {};
|
|
|
|
|
_.defaults(allOptions, defaultOptions);
|
|
|
|
|
|
2014-03-03 01:30:24 +04:00
|
|
|
|
var _build = function (text, vars) {
|
2017-05-01 07:09:29 +03:00
|
|
|
|
vars = vars || [];
|
2014-03-03 01:30:24 +04:00
|
|
|
|
return text.replace(/{([^{}]*)}/g,
|
|
|
|
|
function (a, b) {
|
2015-02-16 22:07:45 +03:00
|
|
|
|
var r = (vars[b]);
|
|
|
|
|
if(allOptions.escape) {
|
|
|
|
|
return (typeof r === 'string' || typeof r === 'number') ? encodeURIComponent(r) : encodeURIComponent(a);
|
|
|
|
|
} else {
|
|
|
|
|
return (typeof r === 'string' || typeof r === 'number') ? r : a;
|
|
|
|
|
}
|
2014-03-03 01:30:24 +04:00
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
if (url.charAt(0) !== '/') {
|
|
|
|
|
url = '/' + url;
|
|
|
|
|
|
|
|
|
|
}
|
2015-02-11 03:10:03 +03:00
|
|
|
|
|
2019-05-02 09:28:24 +03:00
|
|
|
|
if(OC.config.modRewriteWorking == true) {
|
2018-10-09 08:44:26 +03:00
|
|
|
|
return OC.getRootPath() + _build(url, params);
|
2015-02-11 03:10:03 +03:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-09 08:44:26 +03:00
|
|
|
|
return OC.getRootPath() + '/index.php' + _build(url, params);
|
2014-03-03 01:30:24 +04:00
|
|
|
|
},
|
|
|
|
|
|
2013-01-25 19:00:26 +04:00
|
|
|
|
/**
|
2014-04-21 15:46:33 +04:00
|
|
|
|
* Get the absolute url for a file in an app
|
|
|
|
|
* @param {string} app the id of the app
|
|
|
|
|
* @param {string} type the type of the file to link to (e.g. css,img,ajax.template)
|
|
|
|
|
* @param {string} file the filename
|
|
|
|
|
* @return {string} Absolute URL for a file in an app
|
2011-08-07 01:18:49 +04:00
|
|
|
|
*/
|
2011-07-26 00:30:55 +04:00
|
|
|
|
filePath:function(app,type,file){
|
2012-09-23 05:16:52 +04:00
|
|
|
|
var isCore=OC.coreApps.indexOf(app)!==-1,
|
2018-10-09 08:44:26 +03:00
|
|
|
|
link=OC.getRootPath();
|
2014-07-21 15:03:14 +04:00
|
|
|
|
if(file.substring(file.length-3) === 'php' && !isCore){
|
2012-08-15 19:38:55 +04:00
|
|
|
|
link+='/index.php/apps/' + app;
|
2012-05-11 07:04:27 +04:00
|
|
|
|
if (file != 'index.php') {
|
2012-08-15 19:38:55 +04:00
|
|
|
|
link+='/';
|
2012-05-11 07:04:27 +04:00
|
|
|
|
if(type){
|
|
|
|
|
link+=encodeURI(type + '/');
|
|
|
|
|
}
|
|
|
|
|
link+= file;
|
2012-04-24 23:54:09 +04:00
|
|
|
|
}
|
2012-09-23 05:16:52 +04:00
|
|
|
|
}else if(file.substring(file.length-3) !== 'php' && !isCore){
|
2012-06-06 23:54:57 +04:00
|
|
|
|
link=OC.appswebroots[app];
|
2012-04-24 23:33:34 +04:00
|
|
|
|
if(type){
|
2012-06-22 14:24:10 +04:00
|
|
|
|
link+= '/'+type+'/';
|
2012-04-24 23:33:34 +04:00
|
|
|
|
}
|
2012-09-23 05:16:52 +04:00
|
|
|
|
if(link.substring(link.length-1) !== '/'){
|
2012-07-04 01:58:08 +04:00
|
|
|
|
link+='/';
|
2012-09-23 05:16:52 +04:00
|
|
|
|
}
|
2012-04-24 23:54:09 +04:00
|
|
|
|
link+=file;
|
2012-04-21 00:35:12 +04:00
|
|
|
|
}else{
|
2012-10-28 22:28:44 +04:00
|
|
|
|
if ((app == 'settings' || app == 'core' || app == 'search') && type == 'ajax') {
|
2012-09-29 20:08:54 +04:00
|
|
|
|
link+='/index.php/';
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
link+='/';
|
|
|
|
|
}
|
2012-04-21 00:35:12 +04:00
|
|
|
|
if(!isCore){
|
|
|
|
|
link+='apps/';
|
|
|
|
|
}
|
2012-09-23 05:16:52 +04:00
|
|
|
|
if (app !== '') {
|
2012-05-07 20:35:02 +04:00
|
|
|
|
app+='/';
|
|
|
|
|
link+=app;
|
|
|
|
|
}
|
2012-04-21 00:35:12 +04:00
|
|
|
|
if(type){
|
|
|
|
|
link+=type+'/';
|
|
|
|
|
}
|
2012-07-31 14:21:06 +04:00
|
|
|
|
link+=file;
|
2011-07-26 00:30:55 +04:00
|
|
|
|
}
|
|
|
|
|
return link;
|
|
|
|
|
},
|
2014-10-07 14:02:58 +04:00
|
|
|
|
|
2017-02-13 18:51:23 +03:00
|
|
|
|
/**
|
|
|
|
|
* Check if a user file is allowed to be handled.
|
|
|
|
|
* @param {string} file to check
|
|
|
|
|
*/
|
|
|
|
|
fileIsBlacklisted: function(file) {
|
2019-05-02 09:28:24 +03:00
|
|
|
|
return !!(file.match(OC.config.blacklist_files_regex));
|
2017-02-13 18:51:23 +03:00
|
|
|
|
},
|
|
|
|
|
|
2015-01-19 13:56:04 +03:00
|
|
|
|
/**
|
2016-11-24 18:05:05 +03:00
|
|
|
|
* Protocol that is used to access this Nextcloud instance
|
2015-01-19 13:56:04 +03:00
|
|
|
|
* @return {string} Used protocol
|
|
|
|
|
*/
|
|
|
|
|
getProtocol: function() {
|
|
|
|
|
return window.location.protocol.split(':')[0];
|
|
|
|
|
},
|
|
|
|
|
|
2015-07-13 16:26:01 +03:00
|
|
|
|
/**
|
2016-11-24 18:05:05 +03:00
|
|
|
|
* Returns the host used to access this Nextcloud instance
|
2016-02-03 13:28:07 +03:00
|
|
|
|
* Host is sometimes the same as the hostname but now always.
|
2015-07-13 16:26:01 +03:00
|
|
|
|
*
|
2016-02-03 13:28:07 +03:00
|
|
|
|
* Examples:
|
|
|
|
|
* http://example.com => example.com
|
2016-04-04 11:57:17 +03:00
|
|
|
|
* https://example.com => example.com
|
2016-02-03 13:28:07 +03:00
|
|
|
|
* http://example.com:8080 => example.com:8080
|
|
|
|
|
*
|
|
|
|
|
* @return {string} host
|
2015-07-13 16:26:01 +03:00
|
|
|
|
*
|
|
|
|
|
* @since 8.2
|
|
|
|
|
*/
|
|
|
|
|
getHost: function() {
|
|
|
|
|
return window.location.host;
|
|
|
|
|
},
|
|
|
|
|
|
2016-02-03 13:28:07 +03:00
|
|
|
|
/**
|
2016-11-24 18:05:05 +03:00
|
|
|
|
* Returns the hostname used to access this Nextcloud instance
|
2016-02-03 13:28:07 +03:00
|
|
|
|
* The hostname is always stripped of the port
|
|
|
|
|
*
|
|
|
|
|
* @return {string} hostname
|
|
|
|
|
* @since 9.0
|
|
|
|
|
*/
|
|
|
|
|
getHostName: function() {
|
|
|
|
|
return window.location.hostname;
|
|
|
|
|
},
|
|
|
|
|
|
2015-07-13 16:26:01 +03:00
|
|
|
|
/**
|
2016-11-24 18:05:05 +03:00
|
|
|
|
* Returns the port number used to access this Nextcloud instance
|
2015-07-13 16:26:01 +03:00
|
|
|
|
*
|
|
|
|
|
* @return {int} port number
|
|
|
|
|
*
|
|
|
|
|
* @since 8.2
|
|
|
|
|
*/
|
|
|
|
|
getPort: function() {
|
|
|
|
|
return window.location.port;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
2016-11-24 18:05:05 +03:00
|
|
|
|
* Returns the web root path where this Nextcloud instance
|
2015-07-13 16:26:01 +03:00
|
|
|
|
* is accessible, with a leading slash.
|
2016-11-24 18:05:05 +03:00
|
|
|
|
* For example "/nextcloud".
|
2015-07-13 16:26:01 +03:00
|
|
|
|
*
|
|
|
|
|
* @return {string} web root path
|
|
|
|
|
*
|
|
|
|
|
* @since 8.2
|
|
|
|
|
*/
|
|
|
|
|
getRootPath: function() {
|
|
|
|
|
return OC.webroot;
|
|
|
|
|
},
|
|
|
|
|
|
2017-12-01 12:36:13 +03:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the capabilities
|
|
|
|
|
*
|
|
|
|
|
* @return {array} capabilities
|
|
|
|
|
*
|
2018-02-15 13:06:51 +03:00
|
|
|
|
* @since 14.0
|
2017-12-01 12:36:13 +03:00
|
|
|
|
*/
|
|
|
|
|
getCapabilities: function() {
|
|
|
|
|
return OC._capabilities;
|
|
|
|
|
},
|
|
|
|
|
|
2016-02-01 17:11:42 +03:00
|
|
|
|
/**
|
|
|
|
|
* Returns the currently logged in user or null if there is no logged in
|
|
|
|
|
* user (public page mode)
|
|
|
|
|
*
|
|
|
|
|
* @return {OC.CurrentUser} user spec
|
|
|
|
|
* @since 9.0.0
|
|
|
|
|
*/
|
|
|
|
|
getCurrentUser: function() {
|
|
|
|
|
if (_.isUndefined(this._currentUserDisplayName)) {
|
|
|
|
|
this._currentUserDisplayName = document.getElementsByTagName('head')[0].getAttribute('data-user-displayname');
|
|
|
|
|
}
|
|
|
|
|
return {
|
|
|
|
|
uid: this.currentUser,
|
|
|
|
|
displayName: this._currentUserDisplayName
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
|
2011-08-07 01:18:49 +04:00
|
|
|
|
/**
|
|
|
|
|
* get the absolute path to an image file
|
2014-10-07 14:02:58 +04:00
|
|
|
|
* if no extension is given for the image, it will automatically decide
|
2014-04-21 15:46:33 +04:00
|
|
|
|
* between .png and .svg based on what the browser supports
|
|
|
|
|
* @param {string} app the app id to which the image belongs
|
|
|
|
|
* @param {string} file the name of the image file
|
|
|
|
|
* @return {string}
|
2012-07-31 14:21:06 +04:00
|
|
|
|
*/
|
2011-07-26 00:30:55 +04:00
|
|
|
|
imagePath:function(app,file){
|
2016-06-23 13:15:16 +03:00
|
|
|
|
if(file.indexOf('.')==-1){//if no extension is given, use svg
|
|
|
|
|
file+='.svg';
|
2011-07-28 06:28:04 +04:00
|
|
|
|
}
|
2011-07-26 00:30:55 +04:00
|
|
|
|
return OC.filePath(app,'img',file);
|
|
|
|
|
},
|
2014-10-07 14:02:58 +04:00
|
|
|
|
|
2014-11-18 20:53:45 +03:00
|
|
|
|
/**
|
|
|
|
|
* URI-Encodes a file path but keep the path slashes.
|
|
|
|
|
*
|
|
|
|
|
* @param path path
|
|
|
|
|
* @return encoded path
|
|
|
|
|
*/
|
|
|
|
|
encodePath: function(path) {
|
|
|
|
|
if (!path) {
|
|
|
|
|
return path;
|
|
|
|
|
}
|
|
|
|
|
var parts = path.split('/');
|
|
|
|
|
var result = [];
|
|
|
|
|
for (var i = 0; i < parts.length; i++) {
|
|
|
|
|
result.push(encodeURIComponent(parts[i]));
|
|
|
|
|
}
|
|
|
|
|
return result.join('/');
|
|
|
|
|
},
|
|
|
|
|
|
2011-08-07 01:18:49 +04:00
|
|
|
|
/**
|
2014-10-07 14:02:58 +04:00
|
|
|
|
* Load a script for the server and load it. If the script is already loaded,
|
2014-04-22 11:54:25 +04:00
|
|
|
|
* the event handler will be called directly
|
2014-04-21 15:46:33 +04:00
|
|
|
|
* @param {string} app the app id to which the script belongs
|
2014-04-21 16:42:50 +04:00
|
|
|
|
* @param {string} script the filename of the script
|
2014-04-22 11:54:25 +04:00
|
|
|
|
* @param ready event handler to be called when the script is loaded
|
2019-01-04 13:24:50 +03:00
|
|
|
|
* @deprecated 16.0.0 Use OCP.Loader.loadScript
|
2011-08-07 01:18:49 +04:00
|
|
|
|
*/
|
2011-07-26 00:30:55 +04:00
|
|
|
|
addScript:function(app,script,ready){
|
2012-09-23 05:16:52 +04:00
|
|
|
|
var deferred, path=OC.filePath(app,'js',script+'.js');
|
2017-03-26 15:11:58 +03:00
|
|
|
|
if(!OC.addScript.loaded[path]) {
|
2018-10-09 10:04:42 +03:00
|
|
|
|
deferred = $.Deferred();
|
|
|
|
|
$.getScript(path, function() {
|
|
|
|
|
deferred.resolve();
|
2017-03-26 20:45:36 +03:00
|
|
|
|
});
|
2017-03-26 15:11:58 +03:00
|
|
|
|
OC.addScript.loaded[path] = deferred;
|
|
|
|
|
} else {
|
|
|
|
|
if (ready) {
|
2011-07-30 23:18:54 +04:00
|
|
|
|
ready();
|
|
|
|
|
}
|
2011-07-26 00:30:55 +04:00
|
|
|
|
}
|
2012-08-29 03:57:35 +04:00
|
|
|
|
return OC.addScript.loaded[path];
|
2011-07-26 00:30:55 +04:00
|
|
|
|
},
|
2011-08-07 01:18:49 +04:00
|
|
|
|
/**
|
2014-04-21 15:46:33 +04:00
|
|
|
|
* Loads a CSS file
|
|
|
|
|
* @param {string} app the app id to which the css style belongs
|
2014-04-21 16:42:50 +04:00
|
|
|
|
* @param {string} style the filename of the css file
|
2019-01-04 13:24:50 +03:00
|
|
|
|
* @deprecated 16.0.0 Use OCP.Loader.loadStylesheet
|
2011-08-07 01:18:49 +04:00
|
|
|
|
*/
|
2011-07-26 00:30:55 +04:00
|
|
|
|
addStyle:function(app,style){
|
|
|
|
|
var path=OC.filePath(app,'css',style+'.css');
|
2012-09-23 05:16:52 +04:00
|
|
|
|
if(OC.addStyle.loaded.indexOf(path)===-1){
|
2011-09-26 23:18:56 +04:00
|
|
|
|
OC.addStyle.loaded.push(path);
|
2013-07-02 19:44:10 +04:00
|
|
|
|
if (document.createStyleSheet) {
|
|
|
|
|
document.createStyleSheet(path);
|
|
|
|
|
} else {
|
|
|
|
|
style=$('<link rel="stylesheet" type="text/css" href="'+path+'"/>');
|
|
|
|
|
$('head').append(style);
|
|
|
|
|
}
|
2011-07-30 20:05:20 +04:00
|
|
|
|
}
|
|
|
|
|
},
|
2014-10-07 14:02:58 +04:00
|
|
|
|
|
2014-11-18 14:13:44 +03:00
|
|
|
|
/**
|
|
|
|
|
* Loads translations for the given app asynchronously.
|
|
|
|
|
*
|
|
|
|
|
* @param {String} app app name
|
|
|
|
|
* @param {Function} callback callback to call after loading
|
|
|
|
|
* @return {Promise}
|
|
|
|
|
*/
|
|
|
|
|
addTranslations: function(app, callback) {
|
|
|
|
|
return OC.L10N.load(app, callback);
|
|
|
|
|
},
|
|
|
|
|
|
2014-04-21 15:46:33 +04:00
|
|
|
|
/**
|
2014-06-24 01:56:10 +04:00
|
|
|
|
* Returns the base name of the given path.
|
|
|
|
|
* For example for "/abc/somefile.txt" it will return "somefile.txt"
|
|
|
|
|
*
|
|
|
|
|
* @param {String} path
|
|
|
|
|
* @return {String} base name
|
2014-04-21 15:46:33 +04:00
|
|
|
|
*/
|
2012-09-09 01:56:37 +04:00
|
|
|
|
basename: function(path) {
|
|
|
|
|
return path.replace(/\\/g,'/').replace( /.*\//, '' );
|
|
|
|
|
},
|
2014-10-07 14:02:58 +04:00
|
|
|
|
|
2014-04-21 15:46:33 +04:00
|
|
|
|
/**
|
2014-06-24 01:56:10 +04:00
|
|
|
|
* Returns the dir name of the given path.
|
|
|
|
|
* For example for "/abc/somefile.txt" it will return "/abc"
|
|
|
|
|
*
|
|
|
|
|
* @param {String} path
|
|
|
|
|
* @return {String} dir name
|
2014-04-21 15:46:33 +04:00
|
|
|
|
*/
|
2012-09-09 01:56:37 +04:00
|
|
|
|
dirname: function(path) {
|
2012-09-23 05:16:52 +04:00
|
|
|
|
return path.replace(/\\/g,'/').replace(/\/[^\/]*$/, '');
|
2012-09-09 02:35:02 +04:00
|
|
|
|
},
|
2014-10-07 14:02:58 +04:00
|
|
|
|
|
2015-12-21 15:10:03 +03:00
|
|
|
|
/**
|
|
|
|
|
* Returns whether the given paths are the same, without
|
|
|
|
|
* leading, trailing or doubled slashes and also removing
|
|
|
|
|
* the dot sections.
|
|
|
|
|
*
|
|
|
|
|
* @param {String} path1 first path
|
|
|
|
|
* @param {String} path2 second path
|
|
|
|
|
* @return {bool} true if the paths are the same
|
|
|
|
|
*
|
|
|
|
|
* @since 9.0
|
|
|
|
|
*/
|
|
|
|
|
isSamePath: function(path1, path2) {
|
|
|
|
|
var filterDot = function(p) {
|
|
|
|
|
return p !== '.';
|
|
|
|
|
};
|
|
|
|
|
var pathSections1 = _.filter((path1 || '').split('/'), filterDot);
|
|
|
|
|
var pathSections2 = _.filter((path2 || '').split('/'), filterDot);
|
|
|
|
|
path1 = OC.joinPaths.apply(OC, pathSections1);
|
|
|
|
|
path2 = OC.joinPaths.apply(OC, pathSections2);
|
|
|
|
|
return path1 === path2;
|
|
|
|
|
},
|
|
|
|
|
|
2015-07-10 14:01:01 +03:00
|
|
|
|
/**
|
|
|
|
|
* Join path sections
|
|
|
|
|
*
|
|
|
|
|
* @param {...String} path sections
|
|
|
|
|
*
|
|
|
|
|
* @return {String} joined path, any leading or trailing slash
|
|
|
|
|
* will be kept
|
|
|
|
|
*
|
|
|
|
|
* @since 8.2
|
|
|
|
|
*/
|
|
|
|
|
joinPaths: function() {
|
|
|
|
|
if (arguments.length < 1) {
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
var path = '';
|
2015-07-13 11:57:52 +03:00
|
|
|
|
// convert to array
|
|
|
|
|
var args = Array.prototype.slice.call(arguments);
|
|
|
|
|
// discard empty arguments
|
|
|
|
|
args = _.filter(args, function(arg) {
|
|
|
|
|
return arg.length > 0;
|
|
|
|
|
});
|
|
|
|
|
if (args.length < 1) {
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var lastArg = args[args.length - 1];
|
|
|
|
|
var leadingSlash = args[0].charAt(0) === '/';
|
2015-07-10 14:01:01 +03:00
|
|
|
|
var trailingSlash = lastArg.charAt(lastArg.length - 1) === '/';
|
|
|
|
|
var sections = [];
|
|
|
|
|
var i;
|
2015-07-13 11:57:52 +03:00
|
|
|
|
for (i = 0; i < args.length; i++) {
|
|
|
|
|
sections = sections.concat(args[i].split('/'));
|
2015-07-10 14:01:01 +03:00
|
|
|
|
}
|
|
|
|
|
var first = !leadingSlash;
|
|
|
|
|
for (i = 0; i < sections.length; i++) {
|
|
|
|
|
if (sections[i] !== '') {
|
|
|
|
|
if (first) {
|
|
|
|
|
first = false;
|
|
|
|
|
} else {
|
|
|
|
|
path += '/';
|
|
|
|
|
}
|
|
|
|
|
path += sections[i];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (trailingSlash) {
|
|
|
|
|
// add it back
|
|
|
|
|
path += '/';
|
|
|
|
|
}
|
|
|
|
|
return path;
|
|
|
|
|
},
|
|
|
|
|
|
2013-08-17 15:07:18 +04:00
|
|
|
|
/**
|
|
|
|
|
* Parses a URL query string into a JS map
|
2014-04-21 15:46:33 +04:00
|
|
|
|
* @param {string} queryString query string in the format param1=1234¶m2=abcde¶m3=xyz
|
2014-06-24 01:56:10 +04:00
|
|
|
|
* @return {Object.<string, string>} map containing key/values matching the URL parameters
|
2013-08-17 15:07:18 +04:00
|
|
|
|
*/
|
|
|
|
|
parseQueryString:function(queryString){
|
|
|
|
|
var parts,
|
2014-01-28 19:16:09 +04:00
|
|
|
|
pos,
|
2013-08-17 15:07:18 +04:00
|
|
|
|
components,
|
|
|
|
|
result = {},
|
|
|
|
|
key,
|
|
|
|
|
value;
|
|
|
|
|
if (!queryString){
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2014-01-28 19:16:09 +04:00
|
|
|
|
pos = queryString.indexOf('?');
|
|
|
|
|
if (pos >= 0){
|
|
|
|
|
queryString = queryString.substr(pos + 1);
|
2013-08-17 15:07:18 +04:00
|
|
|
|
}
|
2014-01-28 19:16:09 +04:00
|
|
|
|
parts = queryString.replace(/\+/g, '%20').split('&');
|
2013-08-17 15:07:18 +04:00
|
|
|
|
for (var i = 0; i < parts.length; i++){
|
2014-01-28 19:16:09 +04:00
|
|
|
|
// split on first equal sign
|
2014-04-21 16:28:54 +04:00
|
|
|
|
var part = parts[i];
|
2014-01-28 19:16:09 +04:00
|
|
|
|
pos = part.indexOf('=');
|
|
|
|
|
if (pos >= 0) {
|
|
|
|
|
components = [
|
|
|
|
|
part.substr(0, pos),
|
|
|
|
|
part.substr(pos + 1)
|
2014-04-15 06:44:24 +04:00
|
|
|
|
];
|
2014-01-28 19:16:09 +04:00
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
// key only
|
|
|
|
|
components = [part];
|
|
|
|
|
}
|
2013-08-17 15:07:18 +04:00
|
|
|
|
if (!components.length){
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
key = decodeURIComponent(components[0]);
|
|
|
|
|
if (!key){
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2014-01-28 19:16:09 +04:00
|
|
|
|
// if equal sign was there, return string
|
|
|
|
|
if (components.length > 1) {
|
|
|
|
|
result[key] = decodeURIComponent(components[1]);
|
|
|
|
|
}
|
|
|
|
|
// no equal sign => null value
|
|
|
|
|
else {
|
|
|
|
|
result[key] = null;
|
|
|
|
|
}
|
2013-08-17 15:07:18 +04:00
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
},
|
2014-01-24 15:44:31 +04:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Builds a URL query from a JS map.
|
2014-06-24 01:56:10 +04:00
|
|
|
|
* @param {Object.<string, string>} params map containing key/values matching the URL parameters
|
2014-04-21 15:46:33 +04:00
|
|
|
|
* @return {string} String containing a URL query (without question) mark
|
2014-01-24 15:44:31 +04:00
|
|
|
|
*/
|
|
|
|
|
buildQueryString: function(params) {
|
|
|
|
|
if (!params) {
|
2014-04-15 06:44:24 +04:00
|
|
|
|
return '';
|
2014-01-24 15:44:31 +04:00
|
|
|
|
}
|
2014-04-15 06:44:24 +04:00
|
|
|
|
return $.map(params, function(value, key) {
|
|
|
|
|
var s = encodeURIComponent(key);
|
2014-01-24 15:44:31 +04:00
|
|
|
|
if (value !== null && typeof(value) !== 'undefined') {
|
|
|
|
|
s += '=' + encodeURIComponent(value);
|
|
|
|
|
}
|
2014-04-15 06:44:24 +04:00
|
|
|
|
return s;
|
|
|
|
|
}).join('&');
|
2014-01-24 15:44:31 +04:00
|
|
|
|
},
|
|
|
|
|
|
2012-07-31 18:03:08 +04:00
|
|
|
|
/**
|
|
|
|
|
* Opens a popup with the setting for an app.
|
2014-04-21 15:46:33 +04:00
|
|
|
|
* @param {string} appid The ID of the app e.g. 'calendar', 'contacts' or 'files'.
|
|
|
|
|
* @param {boolean|string} loadJS If true 'js/settings.js' is loaded. If it's a string
|
2012-07-31 18:03:08 +04:00
|
|
|
|
* it will attempt to load a script by that name in the 'js' directory.
|
2014-04-21 15:46:33 +04:00
|
|
|
|
* @param {boolean} [cache] If true the javascript file won't be forced refreshed. Defaults to true.
|
|
|
|
|
* @param {string} [scriptName] The name of the PHP file to load. Defaults to 'settings.php' in
|
2012-07-31 18:03:08 +04:00
|
|
|
|
* the root of the app directory hierarchy.
|
|
|
|
|
*/
|
2012-07-31 16:17:28 +04:00
|
|
|
|
appSettings:function(args) {
|
|
|
|
|
if(typeof args === 'undefined' || typeof args.appid === 'undefined') {
|
2012-07-31 18:03:08 +04:00
|
|
|
|
throw { name: 'MissingParameter', message: 'The parameter appid is missing' };
|
2012-07-31 16:17:28 +04:00
|
|
|
|
}
|
2012-07-31 18:03:08 +04:00
|
|
|
|
var props = {scriptName:'settings.php', cache:true};
|
|
|
|
|
$.extend(props, args);
|
2012-07-31 14:21:06 +04:00
|
|
|
|
var settings = $('#appsettings');
|
2014-04-15 06:44:24 +04:00
|
|
|
|
if(settings.length === 0) {
|
2012-07-31 18:03:08 +04:00
|
|
|
|
throw { name: 'MissingDOMElement', message: 'There has be be an element with id "appsettings" for the popup to show.' };
|
|
|
|
|
}
|
2012-08-12 20:42:54 +04:00
|
|
|
|
var popup = $('#appsettings_popup');
|
2014-04-15 06:44:24 +04:00
|
|
|
|
if(popup.length === 0) {
|
2012-08-12 20:42:54 +04:00
|
|
|
|
$('body').prepend('<div class="popup hidden" id="appsettings_popup"></div>');
|
2013-02-09 20:20:08 +04:00
|
|
|
|
popup = $('#appsettings_popup');
|
2012-08-12 20:42:54 +04:00
|
|
|
|
popup.addClass(settings.hasClass('topright') ? 'topright' : 'bottomleft');
|
|
|
|
|
}
|
|
|
|
|
if(popup.is(':visible')) {
|
|
|
|
|
popup.hide().remove();
|
2012-07-31 14:21:06 +04:00
|
|
|
|
} else {
|
2012-08-12 20:42:54 +04:00
|
|
|
|
var arrowclass = settings.hasClass('topright') ? 'up' : 'left';
|
|
|
|
|
var jqxhr = $.get(OC.filePath(props.appid, '', props.scriptName), function(data) {
|
|
|
|
|
popup.html(data).ready(function() {
|
2016-06-23 14:39:28 +03:00
|
|
|
|
popup.prepend('<span class="arrow '+arrowclass+'"></span><h2>'+t('core', 'Settings')+'</h2><a class="close"></a>').show();
|
2012-08-12 20:42:54 +04:00
|
|
|
|
popup.find('.close').bind('click', function() {
|
|
|
|
|
popup.remove();
|
2012-09-06 00:17:33 +04:00
|
|
|
|
});
|
2012-08-12 20:42:54 +04:00
|
|
|
|
if(typeof props.loadJS !== 'undefined') {
|
|
|
|
|
var scriptname;
|
|
|
|
|
if(props.loadJS === true) {
|
|
|
|
|
scriptname = 'settings.js';
|
|
|
|
|
} else if(typeof props.loadJS === 'string') {
|
|
|
|
|
scriptname = props.loadJS;
|
|
|
|
|
} else {
|
|
|
|
|
throw { name: 'InvalidParameter', message: 'The "loadJS" parameter must be either boolean or a string.' };
|
2012-07-31 18:03:08 +04:00
|
|
|
|
}
|
2012-08-12 20:42:54 +04:00
|
|
|
|
if(props.cache) {
|
|
|
|
|
$.ajaxSetup({cache: true});
|
|
|
|
|
}
|
|
|
|
|
$.getScript(OC.filePath(props.appid, 'js', scriptname))
|
|
|
|
|
.fail(function(jqxhr, settings, e) {
|
|
|
|
|
throw e;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}).show();
|
|
|
|
|
}, 'html');
|
2012-07-31 14:21:06 +04:00
|
|
|
|
}
|
2014-03-14 13:33:19 +04:00
|
|
|
|
},
|
|
|
|
|
|
2014-04-21 15:46:33 +04:00
|
|
|
|
/**
|
2014-04-22 11:54:25 +04:00
|
|
|
|
* For menu toggling
|
2014-04-21 15:46:33 +04:00
|
|
|
|
* @todo Write documentation
|
2017-01-24 09:47:14 +03:00
|
|
|
|
*
|
|
|
|
|
* @param {jQuery} $toggle
|
|
|
|
|
* @param {jQuery} $menuEl
|
|
|
|
|
* @param {function|undefined} toggle callback invoked everytime the menu is opened
|
2018-02-21 17:12:42 +03:00
|
|
|
|
* @param {boolean} headerMenu is this a top right header menu?
|
2017-01-24 09:47:14 +03:00
|
|
|
|
* @returns {undefined}
|
2014-04-21 15:46:33 +04:00
|
|
|
|
*/
|
2018-02-21 17:12:42 +03:00
|
|
|
|
registerMenu: function($toggle, $menuEl, toggle, headerMenu) {
|
2015-07-16 16:28:45 +03:00
|
|
|
|
var self = this;
|
2014-03-14 13:33:19 +04:00
|
|
|
|
$menuEl.addClass('menu');
|
2018-10-24 17:24:16 +03:00
|
|
|
|
|
2018-08-22 10:47:00 +03:00
|
|
|
|
// On link, the enter key trigger a click event
|
|
|
|
|
// Only use the click to avoid two fired events
|
|
|
|
|
$toggle.on($toggle.prop('tagName') === 'A'
|
|
|
|
|
? 'click.menu'
|
|
|
|
|
: 'click.menu keyup.menu', function(event) {
|
2015-04-09 15:46:26 +03:00
|
|
|
|
// prevent the link event (append anchor to URL)
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
2018-07-20 21:51:23 +03:00
|
|
|
|
// allow enter key as a trigger
|
2018-07-23 11:17:32 +03:00
|
|
|
|
if (event.key && event.key !== "Enter") {
|
2018-07-20 21:51:23 +03:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-14 13:33:19 +04:00
|
|
|
|
if ($menuEl.is(OC._currentMenu)) {
|
2015-07-16 16:28:45 +03:00
|
|
|
|
self.hideMenus();
|
2015-04-09 15:46:26 +03:00
|
|
|
|
return;
|
2014-03-14 13:33:19 +04:00
|
|
|
|
}
|
|
|
|
|
// another menu was open?
|
|
|
|
|
else if (OC._currentMenu) {
|
|
|
|
|
// close it
|
2015-07-16 16:28:45 +03:00
|
|
|
|
self.hideMenus();
|
2014-03-14 13:33:19 +04:00
|
|
|
|
}
|
2018-02-21 11:48:07 +03:00
|
|
|
|
|
2018-02-21 17:12:42 +03:00
|
|
|
|
if (headerMenu === true) {
|
2018-02-22 11:59:48 +03:00
|
|
|
|
$menuEl.parent().addClass('openedMenu');
|
2018-02-21 17:12:42 +03:00
|
|
|
|
}
|
2018-02-21 11:48:07 +03:00
|
|
|
|
|
2018-04-18 14:33:08 +03:00
|
|
|
|
// Set menu to expanded
|
|
|
|
|
$toggle.attr('aria-expanded', true);
|
|
|
|
|
|
2017-01-24 09:47:14 +03:00
|
|
|
|
$menuEl.slideToggle(OC.menuSpeed, toggle);
|
2014-03-14 13:33:19 +04:00
|
|
|
|
OC._currentMenu = $menuEl;
|
|
|
|
|
OC._currentMenuToggle = $toggle;
|
|
|
|
|
});
|
2014-03-18 16:09:25 +04:00
|
|
|
|
},
|
|
|
|
|
|
2014-04-21 15:46:33 +04:00
|
|
|
|
/**
|
|
|
|
|
* @todo Write documentation
|
|
|
|
|
*/
|
2014-03-18 16:09:25 +04:00
|
|
|
|
unregisterMenu: function($toggle, $menuEl) {
|
|
|
|
|
// close menu if opened
|
|
|
|
|
if ($menuEl.is(OC._currentMenu)) {
|
2015-07-16 16:28:45 +03:00
|
|
|
|
this.hideMenus();
|
2014-03-18 16:09:25 +04:00
|
|
|
|
}
|
|
|
|
|
$toggle.off('click.menu').removeClass('menutoggle');
|
|
|
|
|
$menuEl.removeClass('menu');
|
2014-03-18 19:02:13 +04:00
|
|
|
|
},
|
|
|
|
|
|
2015-07-16 16:28:45 +03:00
|
|
|
|
/**
|
|
|
|
|
* Hides any open menus
|
|
|
|
|
*
|
|
|
|
|
* @param {Function} complete callback when the hiding animation is done
|
|
|
|
|
*/
|
|
|
|
|
hideMenus: function(complete) {
|
|
|
|
|
if (OC._currentMenu) {
|
2015-08-11 12:35:46 +03:00
|
|
|
|
var lastMenu = OC._currentMenu;
|
2015-07-16 16:28:45 +03:00
|
|
|
|
OC._currentMenu.trigger(new $.Event('beforeHide'));
|
2015-08-11 12:35:46 +03:00
|
|
|
|
OC._currentMenu.slideUp(OC.menuSpeed, function() {
|
|
|
|
|
lastMenu.trigger(new $.Event('afterHide'));
|
|
|
|
|
if (complete) {
|
|
|
|
|
complete.apply(this, arguments);
|
|
|
|
|
}
|
|
|
|
|
});
|
2015-07-16 16:28:45 +03:00
|
|
|
|
}
|
2018-04-18 14:33:08 +03:00
|
|
|
|
|
|
|
|
|
// Set menu to closed
|
|
|
|
|
$('.menutoggle').attr('aria-expanded', false);
|
|
|
|
|
|
2018-02-21 11:48:07 +03:00
|
|
|
|
$('.openedMenu').removeClass('openedMenu');
|
2015-07-16 16:28:45 +03:00
|
|
|
|
OC._currentMenu = null;
|
|
|
|
|
OC._currentMenuToggle = null;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Shows a given element as menu
|
|
|
|
|
*
|
|
|
|
|
* @param {Object} [$toggle=null] menu toggle
|
|
|
|
|
* @param {Object} $menuEl menu element
|
|
|
|
|
* @param {Function} complete callback when the showing animation is done
|
|
|
|
|
*/
|
|
|
|
|
showMenu: function($toggle, $menuEl, complete) {
|
|
|
|
|
if ($menuEl.is(OC._currentMenu)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
this.hideMenus();
|
|
|
|
|
OC._currentMenu = $menuEl;
|
|
|
|
|
OC._currentMenuToggle = $toggle;
|
|
|
|
|
$menuEl.trigger(new $.Event('beforeShow'));
|
|
|
|
|
$menuEl.show();
|
|
|
|
|
$menuEl.trigger(new $.Event('afterShow'));
|
|
|
|
|
// no animation
|
2015-08-12 18:28:55 +03:00
|
|
|
|
if (_.isFunction(complete)) {
|
2015-07-16 16:28:45 +03:00
|
|
|
|
complete();
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2018-10-17 22:43:37 +03:00
|
|
|
|
/**
|
|
|
|
|
* Returns the user's locale as a BCP 47 compliant language tag
|
|
|
|
|
*
|
|
|
|
|
* @return {String} locale string
|
|
|
|
|
*/
|
|
|
|
|
getCanonicalLocale: function() {
|
|
|
|
|
var locale = this.getLocale();
|
|
|
|
|
return typeof locale === 'string' ? locale.replace(/_/g, '-') : locale;
|
|
|
|
|
},
|
|
|
|
|
|
2014-11-18 14:13:44 +03:00
|
|
|
|
/**
|
|
|
|
|
* Returns the user's locale
|
|
|
|
|
*
|
|
|
|
|
* @return {String} locale string
|
|
|
|
|
*/
|
|
|
|
|
getLocale: function() {
|
2017-11-12 12:38:33 +03:00
|
|
|
|
return $('html').data('locale');
|
2017-07-17 11:08:51 +03:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the user's language
|
|
|
|
|
*
|
|
|
|
|
* @returns {String} language string
|
|
|
|
|
*/
|
|
|
|
|
getLanguage: function () {
|
2014-11-18 14:13:44 +03:00
|
|
|
|
return $('html').prop('lang');
|
2016-01-21 17:23:03 +03:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns whether the current user is an administrator
|
|
|
|
|
*
|
|
|
|
|
* @return {bool} true if the user is an admin, false otherwise
|
|
|
|
|
* @since 9.0.0
|
|
|
|
|
*/
|
|
|
|
|
isUserAdmin: function() {
|
|
|
|
|
return oc_isadmin;
|
|
|
|
|
},
|
2015-12-10 20:08:40 +03:00
|
|
|
|
|
2016-09-20 00:49:42 +03:00
|
|
|
|
/**
|
|
|
|
|
* Warn users that the connection to the server was lost temporarily
|
|
|
|
|
*
|
|
|
|
|
* This function is throttled to prevent stacked notfications.
|
|
|
|
|
* After 7sec the first notification is gone, then we can show another one
|
|
|
|
|
* if necessary.
|
|
|
|
|
*/
|
|
|
|
|
_ajaxConnectionLostHandler: _.throttle(function() {
|
|
|
|
|
OC.Notification.showTemporary(t('core', 'Connection to server lost'));
|
|
|
|
|
}, 7 * 1000, {trailing: false}),
|
|
|
|
|
|
2015-12-10 20:08:40 +03:00
|
|
|
|
/**
|
|
|
|
|
* Process ajax error, redirects to main page
|
|
|
|
|
* if an error/auth error status was returned.
|
|
|
|
|
*/
|
|
|
|
|
_processAjaxError: function(xhr) {
|
2016-03-22 20:28:54 +03:00
|
|
|
|
var self = this;
|
2015-12-10 20:08:40 +03:00
|
|
|
|
// purposefully aborted request ?
|
2016-03-22 18:54:01 +03:00
|
|
|
|
// this._userIsNavigatingAway needed to distinguish ajax calls cancelled by navigating away
|
|
|
|
|
// from calls cancelled by failed cross-domain ajax due to SSO redirect
|
2016-03-22 20:28:54 +03:00
|
|
|
|
if (xhr.status === 0 && (xhr.statusText === 'abort' || xhr.statusText === 'timeout' || self._reloadCalled)) {
|
2015-12-10 20:08:40 +03:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-02 01:44:50 +03:00
|
|
|
|
if (_.contains([302, 303, 307, 401], xhr.status) && OC.currentUser) {
|
2016-03-22 20:28:54 +03:00
|
|
|
|
// sometimes "beforeunload" happens later, so need to defer the reload a bit
|
|
|
|
|
setTimeout(function() {
|
|
|
|
|
if (!self._userIsNavigatingAway && !self._reloadCalled) {
|
2017-02-04 08:47:09 +03:00
|
|
|
|
var timer = 0;
|
|
|
|
|
var seconds = 5;
|
|
|
|
|
var interval = setInterval( function() {
|
2017-02-08 09:55:31 +03:00
|
|
|
|
OC.Notification.showUpdate(n('core', 'Problem loading page, reloading in %n second', 'Problem loading page, reloading in %n seconds', seconds - timer));
|
2017-02-04 08:47:09 +03:00
|
|
|
|
if (timer >= seconds) {
|
2017-02-08 09:55:31 +03:00
|
|
|
|
clearInterval(interval);
|
2017-02-04 08:47:09 +03:00
|
|
|
|
OC.reload();
|
2017-02-08 09:55:31 +03:00
|
|
|
|
}
|
2017-02-04 08:47:09 +03:00
|
|
|
|
timer++;
|
|
|
|
|
}, 1000 // 1 second interval
|
|
|
|
|
);
|
|
|
|
|
|
2016-03-22 20:28:54 +03:00
|
|
|
|
// only call reload once
|
|
|
|
|
self._reloadCalled = true;
|
|
|
|
|
}
|
|
|
|
|
}, 100);
|
2016-09-20 00:49:42 +03:00
|
|
|
|
} else if(xhr.status === 0) {
|
|
|
|
|
// Connection lost (e.g. WiFi disconnected or server is down)
|
|
|
|
|
setTimeout(function() {
|
|
|
|
|
if (!self._userIsNavigatingAway && !self._reloadCalled) {
|
|
|
|
|
self._ajaxConnectionLostHandler();
|
|
|
|
|
}
|
|
|
|
|
}, 100);
|
2015-12-10 20:08:40 +03:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Registers XmlHttpRequest object for global error processing.
|
|
|
|
|
*
|
|
|
|
|
* This means that if this XHR object returns 401 or session timeout errors,
|
|
|
|
|
* the current page will automatically be reloaded.
|
|
|
|
|
*
|
|
|
|
|
* @param {XMLHttpRequest} xhr
|
|
|
|
|
*/
|
|
|
|
|
registerXHRForErrorProcessing: function(xhr) {
|
|
|
|
|
var loadCallback = function() {
|
|
|
|
|
if (xhr.readyState !== 4) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (xhr.status >= 200 && xhr.status < 300 || xhr.status === 304) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// fire jquery global ajax error handler
|
|
|
|
|
$(document).trigger(new $.Event('ajaxError'), xhr);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var errorCallback = function() {
|
|
|
|
|
// fire jquery global ajax error handler
|
|
|
|
|
$(document).trigger(new $.Event('ajaxError'), xhr);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (xhr.addEventListener) {
|
|
|
|
|
xhr.addEventListener('load', loadCallback);
|
|
|
|
|
xhr.addEventListener('error', errorCallback);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
2019-01-28 13:24:08 +03:00
|
|
|
|
});
|
2014-04-21 15:46:33 +04:00
|
|
|
|
|
2011-07-30 20:05:20 +04:00
|
|
|
|
OC.addStyle.loaded=[];
|
|
|
|
|
OC.addScript.loaded=[];
|
|
|
|
|
|
2014-02-04 16:56:10 +04:00
|
|
|
|
/**
|
|
|
|
|
* Initializes core
|
|
|
|
|
*/
|
|
|
|
|
function initCore() {
|
2015-09-14 15:08:16 +03:00
|
|
|
|
/**
|
|
|
|
|
* Disable automatic evaluation of responses for $.ajax() functions (and its
|
|
|
|
|
* higher-level alternatives like $.get() and $.post()).
|
|
|
|
|
*
|
|
|
|
|
* If a response to a $.ajax() request returns a content type of "application/javascript"
|
|
|
|
|
* JQuery would previously execute the response body. This is a pretty unexpected
|
|
|
|
|
* behaviour and can result in a bypass of our Content-Security-Policy as well as
|
|
|
|
|
* multiple unexpected XSS vectors.
|
|
|
|
|
*/
|
|
|
|
|
$.ajaxSetup({
|
|
|
|
|
contents: {
|
|
|
|
|
script: false
|
|
|
|
|
}
|
|
|
|
|
});
|
2014-02-04 16:56:10 +04:00
|
|
|
|
|
2017-03-17 01:03:02 +03:00
|
|
|
|
/**
|
|
|
|
|
* Disable execution of eval in jQuery. We do require an allowed eval CSP
|
|
|
|
|
* configuration at the moment for handlebars et al. But for jQuery there is
|
|
|
|
|
* not much of a reason to execute JavaScript directly via eval.
|
|
|
|
|
*
|
|
|
|
|
* This thus mitigates some unexpected XSS vectors.
|
|
|
|
|
*/
|
|
|
|
|
jQuery.globalEval = function(){};
|
|
|
|
|
|
2014-10-22 18:38:17 +04:00
|
|
|
|
/**
|
2014-11-18 14:13:44 +03:00
|
|
|
|
* Set users locale to moment.js as soon as possible
|
2014-10-22 18:38:17 +04:00
|
|
|
|
*/
|
2014-11-18 14:13:44 +03:00
|
|
|
|
moment.locale(OC.getLocale());
|
2014-10-22 18:38:17 +04:00
|
|
|
|
|
2016-04-19 12:55:40 +03:00
|
|
|
|
var userAgent = window.navigator.userAgent;
|
|
|
|
|
var msie = userAgent.indexOf('MSIE ');
|
|
|
|
|
var trident = userAgent.indexOf('Trident/');
|
|
|
|
|
var edge = userAgent.indexOf('Edge/');
|
|
|
|
|
|
|
|
|
|
if (msie > 0 || trident > 0) {
|
|
|
|
|
// (IE 10 or older) || IE 11
|
2015-11-10 16:05:05 +03:00
|
|
|
|
$('html').addClass('ie');
|
2016-04-19 12:55:40 +03:00
|
|
|
|
} else if (edge > 0) {
|
2015-11-10 16:05:05 +03:00
|
|
|
|
// for edge
|
|
|
|
|
$('html').addClass('edge');
|
|
|
|
|
}
|
2014-10-22 18:38:17 +04:00
|
|
|
|
|
2018-06-14 20:04:09 +03:00
|
|
|
|
// css variables fallback for IE
|
|
|
|
|
if (msie > 0 || trident > 0) {
|
2019-01-15 21:57:51 +03:00
|
|
|
|
cssVars({
|
|
|
|
|
watch: true
|
|
|
|
|
});
|
2018-06-14 20:04:09 +03:00
|
|
|
|
}
|
|
|
|
|
|
2016-03-23 12:53:40 +03:00
|
|
|
|
$(window).on('unload.main', function() {
|
2016-03-22 18:54:01 +03:00
|
|
|
|
OC._unloadCalled = true;
|
|
|
|
|
});
|
2016-03-23 12:53:40 +03:00
|
|
|
|
$(window).on('beforeunload.main', function() {
|
2016-03-22 18:54:01 +03:00
|
|
|
|
// super-trick thanks to http://stackoverflow.com/a/4651049
|
|
|
|
|
// in case another handler displays a confirmation dialog (ex: navigating away
|
|
|
|
|
// during an upload), there are two possible outcomes: user clicked "ok" or
|
|
|
|
|
// "cancel"
|
|
|
|
|
|
|
|
|
|
// first timeout handler is called after unload dialog is closed
|
|
|
|
|
setTimeout(function() {
|
|
|
|
|
OC._userIsNavigatingAway = true;
|
|
|
|
|
|
|
|
|
|
// second timeout event is only called if user cancelled (Chrome),
|
|
|
|
|
// but in other browsers it might still be triggered, so need to
|
|
|
|
|
// set a higher delay...
|
|
|
|
|
setTimeout(function() {
|
|
|
|
|
if (!OC._unloadCalled) {
|
|
|
|
|
OC._userIsNavigatingAway = false;
|
|
|
|
|
}
|
|
|
|
|
}, 10000);
|
|
|
|
|
},1);
|
|
|
|
|
});
|
2015-12-10 20:08:40 +03:00
|
|
|
|
$(document).on('ajaxError.main', function( event, request, settings ) {
|
|
|
|
|
if (settings && settings.allowAuthErrors) {
|
|
|
|
|
return;
|
2015-06-06 23:43:41 +03:00
|
|
|
|
}
|
2015-12-10 20:08:40 +03:00
|
|
|
|
OC._processAjaxError(request);
|
2015-06-06 23:43:41 +03:00
|
|
|
|
});
|
|
|
|
|
|
2014-02-04 16:56:10 +04:00
|
|
|
|
/**
|
2018-02-26 19:13:23 +03:00
|
|
|
|
* Calls the server periodically to ensure that session and CSRF
|
|
|
|
|
* token doesn't expire
|
2014-02-04 16:56:10 +04:00
|
|
|
|
*/
|
2018-02-26 19:13:23 +03:00
|
|
|
|
function initSessionHeartBeat() {
|
2014-02-04 16:56:10 +04:00
|
|
|
|
// interval in seconds
|
2018-10-11 11:53:25 +03:00
|
|
|
|
var interval = NaN;
|
2019-05-02 09:28:24 +03:00
|
|
|
|
if (OC.config.session_lifetime) {
|
|
|
|
|
interval = Math.floor(OC.config.session_lifetime / 2);
|
2014-02-04 16:56:10 +04:00
|
|
|
|
}
|
2018-10-11 11:53:25 +03:00
|
|
|
|
interval = isNaN(interval)? 900: interval;
|
|
|
|
|
|
2014-02-04 16:56:10 +04:00
|
|
|
|
// minimum one minute
|
2018-02-26 19:13:23 +03:00
|
|
|
|
interval = Math.max(60, interval);
|
|
|
|
|
// max interval in seconds set to 24 hours
|
|
|
|
|
interval = Math.min(24 * 3600, interval);
|
|
|
|
|
|
|
|
|
|
var url = OC.generateUrl('/csrftoken');
|
|
|
|
|
setInterval(function() {
|
|
|
|
|
$.ajax(url).then(function(resp) {
|
|
|
|
|
oc_requesttoken = resp.token;
|
|
|
|
|
OC.requestToken = resp.token;
|
|
|
|
|
}).fail(function(e) {
|
|
|
|
|
console.error('session heartbeat failed', e);
|
|
|
|
|
});
|
|
|
|
|
}, interval * 1000);
|
2014-02-04 16:56:10 +04:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-04 23:58:06 +04:00
|
|
|
|
// session heartbeat (defaults to enabled)
|
2019-05-02 09:28:24 +03:00
|
|
|
|
if (typeof(OC.config.session_keepalive) === 'undefined' ||
|
|
|
|
|
!!OC.config.session_keepalive) {
|
2014-02-04 16:56:10 +04:00
|
|
|
|
|
|
|
|
|
initSessionHeartBeat();
|
|
|
|
|
}
|
2011-10-04 20:54:07 +04:00
|
|
|
|
|
2018-02-21 17:12:42 +03:00
|
|
|
|
OC.registerMenu($('#expand'), $('#expanddiv'), false, true);
|
2011-08-14 16:55:43 +04:00
|
|
|
|
|
2014-03-14 13:33:19 +04:00
|
|
|
|
// toggle for menus
|
2018-07-20 21:51:23 +03:00
|
|
|
|
//$(document).on('mouseup.closemenus keyup', function(event) {
|
2014-03-14 13:33:19 +04:00
|
|
|
|
$(document).on('mouseup.closemenus', function(event) {
|
2018-07-20 21:51:23 +03:00
|
|
|
|
|
|
|
|
|
// allow enter as a trigger
|
2018-07-23 11:17:32 +03:00
|
|
|
|
// if (event.key && event.key !== "Enter") {
|
2018-07-20 21:51:23 +03:00
|
|
|
|
// return;
|
|
|
|
|
// }
|
|
|
|
|
|
2014-03-14 13:33:19 +04:00
|
|
|
|
var $el = $(event.target);
|
|
|
|
|
if ($el.closest('.menu').length || $el.closest('.menutoggle').length) {
|
|
|
|
|
// don't close when clicking on the menu directly or a menu toggle
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2015-07-16 16:28:45 +03:00
|
|
|
|
|
|
|
|
|
OC.hideMenus();
|
2014-03-14 13:33:19 +04:00
|
|
|
|
});
|
|
|
|
|
|
2014-03-18 16:09:25 +04:00
|
|
|
|
/**
|
|
|
|
|
* Set up the main menu toggle to react to media query changes.
|
|
|
|
|
* If the screen is small enough, the main menu becomes a toggle.
|
|
|
|
|
* If the screen is bigger, the main menu is not a toggle any more.
|
|
|
|
|
*/
|
|
|
|
|
function setupMainMenu() {
|
2017-03-02 01:21:38 +03:00
|
|
|
|
|
2017-03-03 04:09:49 +03:00
|
|
|
|
// init the more-apps menu
|
2018-08-22 10:47:00 +03:00
|
|
|
|
OC.registerMenu($('#more-apps > a'), $('#navigation'));
|
2017-03-03 04:09:49 +03:00
|
|
|
|
|
2014-05-16 18:04:36 +04:00
|
|
|
|
// toggle the navigation
|
2017-03-02 01:21:38 +03:00
|
|
|
|
var $toggle = $('#header .header-appname-container');
|
2014-03-18 18:52:06 +04:00
|
|
|
|
var $navigation = $('#navigation');
|
2017-04-25 18:31:04 +03:00
|
|
|
|
var $appmenu = $('#appmenu');
|
2014-03-18 16:09:25 +04:00
|
|
|
|
|
2014-05-17 20:03:00 +04:00
|
|
|
|
// init the menu
|
|
|
|
|
OC.registerMenu($toggle, $navigation);
|
|
|
|
|
$toggle.data('oldhref', $toggle.attr('href'));
|
|
|
|
|
$toggle.attr('href', '#');
|
|
|
|
|
$navigation.hide();
|
2014-06-04 15:18:05 +04:00
|
|
|
|
|
2018-12-03 10:35:31 +03:00
|
|
|
|
// show loading feedback on more apps list
|
2016-08-18 12:46:00 +03:00
|
|
|
|
$navigation.delegate('a', 'click', function(event) {
|
2014-06-04 15:18:05 +04:00
|
|
|
|
var $app = $(event.target);
|
|
|
|
|
if(!$app.is('a')) {
|
|
|
|
|
$app = $app.closest('a');
|
|
|
|
|
}
|
2016-08-19 11:47:02 +03:00
|
|
|
|
if(event.which === 1 && !event.ctrlKey && !event.metaKey) {
|
2018-12-03 10:35:31 +03:00
|
|
|
|
$app.find('svg').remove();
|
|
|
|
|
$app.find('div').remove(); // prevent odd double-clicks
|
|
|
|
|
// no need for theming, loader is already inverted on dark mode
|
|
|
|
|
// but we need it over the primary colour
|
|
|
|
|
$app.prepend($('<div/>').addClass('icon-loading-small'));
|
2016-04-14 12:53:20 +03:00
|
|
|
|
} else {
|
2016-08-18 12:46:00 +03:00
|
|
|
|
// Close navigation when opening app in
|
|
|
|
|
// a new tab
|
2017-05-01 06:42:53 +03:00
|
|
|
|
OC.hideMenus(function(){return false;});
|
2016-08-19 11:47:02 +03:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$navigation.delegate('a', 'mouseup', function(event) {
|
|
|
|
|
if(event.which === 2) {
|
|
|
|
|
// Close navigation when opening app in
|
|
|
|
|
// a new tab via middle click
|
2017-05-01 06:42:53 +03:00
|
|
|
|
OC.hideMenus(function(){return false;});
|
2014-07-07 12:39:48 +04:00
|
|
|
|
}
|
2014-06-04 15:18:05 +04:00
|
|
|
|
});
|
2017-04-25 18:31:04 +03:00
|
|
|
|
|
2018-12-03 10:35:31 +03:00
|
|
|
|
// show loading feedback on visible apps list
|
|
|
|
|
$appmenu.delegate('li:not(#more-apps) > a', 'click', function(event) {
|
2017-04-25 18:31:04 +03:00
|
|
|
|
var $app = $(event.target);
|
|
|
|
|
if(!$app.is('a')) {
|
|
|
|
|
$app = $app.closest('a');
|
|
|
|
|
}
|
2018-12-03 10:35:31 +03:00
|
|
|
|
if(event.which === 1 && !event.ctrlKey && !event.metaKey && $app.parent('#more-apps').length === 0) {
|
|
|
|
|
$app.find('svg').remove();
|
|
|
|
|
$app.find('div').remove(); // prevent odd double-clicks
|
|
|
|
|
$app.prepend($('<div/>').addClass(
|
|
|
|
|
OCA.Theming && OCA.Theming.inverted
|
|
|
|
|
? 'icon-loading-small'
|
|
|
|
|
: 'icon-loading-small-dark'
|
|
|
|
|
));
|
2017-04-25 18:31:04 +03:00
|
|
|
|
} else {
|
|
|
|
|
// Close navigation when opening app in
|
|
|
|
|
// a new tab
|
2017-05-01 06:42:53 +03:00
|
|
|
|
OC.hideMenus(function(){return false;});
|
2017-04-25 18:31:04 +03:00
|
|
|
|
}
|
|
|
|
|
});
|
2014-03-17 23:40:22 +04:00
|
|
|
|
}
|
2014-03-18 16:09:25 +04:00
|
|
|
|
|
2016-04-14 12:53:09 +03:00
|
|
|
|
function setupUserMenu() {
|
|
|
|
|
var $menu = $('#header #settings');
|
|
|
|
|
|
2016-08-19 11:47:02 +03:00
|
|
|
|
// show loading feedback
|
2016-08-18 12:46:00 +03:00
|
|
|
|
$menu.delegate('a', 'click', function(event) {
|
2016-04-14 12:53:09 +03:00
|
|
|
|
var $page = $(event.target);
|
|
|
|
|
if (!$page.is('a')) {
|
|
|
|
|
$page = $page.closest('a');
|
|
|
|
|
}
|
2016-08-19 11:47:02 +03:00
|
|
|
|
if(event.which === 1 && !event.ctrlKey && !event.metaKey) {
|
|
|
|
|
$page.find('img').remove();
|
|
|
|
|
$page.find('div').remove(); // prevent odd double-clicks
|
2018-02-21 11:48:07 +03:00
|
|
|
|
$page.prepend($('<div/>').addClass('icon-loading-small'));
|
2016-08-19 11:47:02 +03:00
|
|
|
|
} else {
|
|
|
|
|
// Close navigation when opening menu entry in
|
|
|
|
|
// a new tab
|
2017-05-01 06:42:53 +03:00
|
|
|
|
OC.hideMenus(function(){return false;});
|
2016-08-19 11:47:02 +03:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$menu.delegate('a', 'mouseup', function(event) {
|
|
|
|
|
if(event.which === 2) {
|
|
|
|
|
// Close navigation when opening app in
|
|
|
|
|
// a new tab via middle click
|
2017-05-01 06:42:53 +03:00
|
|
|
|
OC.hideMenus(function(){return false;});
|
2016-08-19 11:47:02 +03:00
|
|
|
|
}
|
2016-04-14 12:53:09 +03:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-24 09:47:14 +03:00
|
|
|
|
function setupContactsMenu() {
|
|
|
|
|
new OC.ContactsMenu({
|
|
|
|
|
el: $('#contactsmenu .menu'),
|
|
|
|
|
trigger: $('#contactsmenu .menutoggle')
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-17 20:03:00 +04:00
|
|
|
|
setupMainMenu();
|
2016-04-14 12:53:09 +03:00
|
|
|
|
setupUserMenu();
|
2017-01-24 09:47:14 +03:00
|
|
|
|
setupContactsMenu();
|
2014-06-05 15:19:56 +04:00
|
|
|
|
|
2015-03-26 18:25:29 +03:00
|
|
|
|
// move triangle of apps dropdown to align with app name triangle
|
2015-03-26 19:10:59 +03:00
|
|
|
|
// 2 is the additional offset between the triangles
|
2015-03-26 18:25:29 +03:00
|
|
|
|
if($('#navigation').length) {
|
2017-03-03 04:09:49 +03:00
|
|
|
|
$('#header #nextcloud + .menutoggle').on('click', function(){
|
|
|
|
|
$('#menu-css-helper').remove();
|
|
|
|
|
var caretPosition = $('.header-appname + .icon-caret').offset().left - 2;
|
2015-03-26 18:25:29 +03:00
|
|
|
|
if(caretPosition > 255) {
|
|
|
|
|
// if the app name is longer than the menu, just put the triangle in the middle
|
|
|
|
|
return;
|
|
|
|
|
} else {
|
2017-03-03 04:09:49 +03:00
|
|
|
|
$('head').append('<style id="menu-css-helper">#navigation:after { left: '+ caretPosition +'px; }</style>');
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
$('#header #appmenu .menutoggle').on('click', function() {
|
|
|
|
|
$('#appmenu').toggleClass('menu-open');
|
|
|
|
|
if($('#appmenu').is(':visible')) {
|
|
|
|
|
$('#menu-css-helper').remove();
|
2015-03-26 18:25:29 +03:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-28 16:04:56 +03:00
|
|
|
|
var resizeMenu = function() {
|
|
|
|
|
var appList = $('#appmenu li');
|
2018-08-27 19:03:42 +03:00
|
|
|
|
var rightHeaderWidth = $('.header-right').outerWidth();
|
|
|
|
|
var headerWidth = $('header').outerWidth();
|
2017-06-10 18:33:01 +03:00
|
|
|
|
var usePercentualAppMenuLimit = 0.33;
|
2017-06-14 12:08:45 +03:00
|
|
|
|
var minAppsDesktop = 8;
|
2018-08-27 19:03:42 +03:00
|
|
|
|
var availableWidth = headerWidth - $('#nextcloud').outerWidth() - (rightHeaderWidth > 210 ? rightHeaderWidth : 210)
|
2017-06-14 12:08:45 +03:00
|
|
|
|
var isMobile = $(window).width() < 768;
|
|
|
|
|
if (!isMobile) {
|
2018-08-27 19:03:42 +03:00
|
|
|
|
availableWidth = availableWidth * usePercentualAppMenuLimit;
|
2017-06-14 12:08:45 +03:00
|
|
|
|
}
|
2017-06-10 18:33:01 +03:00
|
|
|
|
var appCount = Math.floor((availableWidth / $(appList).width()));
|
2017-06-14 12:08:45 +03:00
|
|
|
|
if (isMobile && appCount > minAppsDesktop) {
|
|
|
|
|
appCount = minAppsDesktop;
|
|
|
|
|
}
|
|
|
|
|
if (!isMobile && appCount < minAppsDesktop) {
|
|
|
|
|
appCount = minAppsDesktop;
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-28 16:04:56 +03:00
|
|
|
|
// show at least 2 apps in the popover
|
|
|
|
|
if(appList.length-1-appCount >= 1) {
|
|
|
|
|
appCount--;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$('#more-apps a').removeClass('active');
|
|
|
|
|
var lastShownApp;
|
|
|
|
|
for (var k = 0; k < appList.length-1; k++) {
|
|
|
|
|
var name = $(appList[k]).data('id');
|
|
|
|
|
if(k < appCount) {
|
|
|
|
|
$(appList[k]).removeClass('hidden');
|
|
|
|
|
$('#apps li[data-id=' + name + ']').addClass('in-header');
|
|
|
|
|
lastShownApp = appList[k];
|
|
|
|
|
} else {
|
|
|
|
|
$(appList[k]).addClass('hidden');
|
|
|
|
|
$('#apps li[data-id=' + name + ']').removeClass('in-header');
|
|
|
|
|
// move active app to last position if it is active
|
|
|
|
|
if(appCount > 0 && $(appList[k]).children('a').hasClass('active')) {
|
|
|
|
|
$(lastShownApp).addClass('hidden');
|
|
|
|
|
$('#apps li[data-id=' + $(lastShownApp).data('id') + ']').removeClass('in-header');
|
|
|
|
|
$(appList[k]).removeClass('hidden');
|
|
|
|
|
$('#apps li[data-id=' + name + ']').addClass('in-header');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// show/hide more apps icon
|
|
|
|
|
if($('#apps li:not(.in-header)').length === 0) {
|
|
|
|
|
$('#more-apps').hide();
|
|
|
|
|
$('#navigation').hide();
|
|
|
|
|
} else {
|
|
|
|
|
$('#more-apps').show();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
$(window).resize(resizeMenu);
|
2018-08-27 19:03:42 +03:00
|
|
|
|
setTimeout(resizeMenu, 0);
|
2017-03-28 16:04:56 +03:00
|
|
|
|
|
2014-06-06 03:20:31 +04:00
|
|
|
|
// just add snapper for logged in users
|
2019-04-05 16:41:12 +03:00
|
|
|
|
// and if the app doesn't handle the nav slider itself
|
|
|
|
|
if($('#app-navigation').length && !$('html').hasClass('lte9')
|
|
|
|
|
&& !$('#app-content').hasClass('no-snapper')) {
|
2014-06-05 19:06:21 +04:00
|
|
|
|
|
2014-06-06 03:20:31 +04:00
|
|
|
|
// App sidebar on mobile
|
|
|
|
|
var snapper = new Snap({
|
|
|
|
|
element: document.getElementById('app-content'),
|
|
|
|
|
disable: 'right',
|
2018-07-23 21:14:19 +03:00
|
|
|
|
maxPosition: 300, // $navigation-width
|
2015-07-21 18:03:45 +03:00
|
|
|
|
minDragDistance: 100
|
2014-06-06 03:20:31 +04:00
|
|
|
|
});
|
2018-07-17 14:10:25 +03:00
|
|
|
|
|
|
|
|
|
$('#app-content').prepend('<div id="app-navigation-toggle" class="icon-menu" style="display:none;" tabindex="0"></div>');
|
|
|
|
|
|
|
|
|
|
var toggleSnapperOnButton = function(){
|
2014-06-06 03:20:31 +04:00
|
|
|
|
if(snapper.state().state == 'left'){
|
|
|
|
|
snapper.close();
|
|
|
|
|
} else {
|
|
|
|
|
snapper.open('left');
|
|
|
|
|
}
|
2018-07-17 14:10:25 +03:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$('#app-navigation-toggle').click(function(){
|
|
|
|
|
toggleSnapperOnButton();
|
2014-06-06 03:20:31 +04:00
|
|
|
|
});
|
2018-07-17 14:10:25 +03:00
|
|
|
|
|
|
|
|
|
$('#app-navigation-toggle').keypress(function(e) {
|
|
|
|
|
if(e.which == 13) {
|
|
|
|
|
toggleSnapperOnButton();
|
|
|
|
|
}
|
2014-06-06 03:20:31 +04:00
|
|
|
|
});
|
2018-07-17 14:10:25 +03:00
|
|
|
|
|
2014-06-06 03:20:31 +04:00
|
|
|
|
// close sidebar when switching navigation entry
|
|
|
|
|
var $appNavigation = $('#app-navigation');
|
2015-06-16 20:41:20 +03:00
|
|
|
|
$appNavigation.delegate('a, :button', 'click', function(event) {
|
2014-06-06 03:20:31 +04:00
|
|
|
|
var $target = $(event.target);
|
|
|
|
|
// don't hide navigation when changing settings or adding things
|
|
|
|
|
if($target.is('.app-navigation-noclose') ||
|
|
|
|
|
$target.closest('.app-navigation-noclose').length) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2016-07-31 12:57:03 +03:00
|
|
|
|
if($target.is('.app-navigation-entry-utils-menu-button') ||
|
|
|
|
|
$target.closest('.app-navigation-entry-utils-menu-button').length) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2014-06-06 03:20:31 +04:00
|
|
|
|
if($target.is('.add-new') ||
|
|
|
|
|
$target.closest('.add-new').length) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if($target.is('#app-settings') ||
|
|
|
|
|
$target.closest('#app-settings').length) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2014-06-05 15:19:56 +04:00
|
|
|
|
snapper.close();
|
2014-06-06 03:20:31 +04:00
|
|
|
|
});
|
|
|
|
|
|
2017-10-23 02:01:01 +03:00
|
|
|
|
var navigationBarSlideGestureEnabled = false;
|
|
|
|
|
var navigationBarSlideGestureAllowed = true;
|
|
|
|
|
var navigationBarSlideGestureEnablePending = false;
|
|
|
|
|
|
|
|
|
|
OC.allowNavigationBarSlideGesture = function() {
|
|
|
|
|
navigationBarSlideGestureAllowed = true;
|
|
|
|
|
|
|
|
|
|
if (navigationBarSlideGestureEnablePending) {
|
|
|
|
|
snapper.enable();
|
|
|
|
|
|
|
|
|
|
navigationBarSlideGestureEnabled = true;
|
|
|
|
|
navigationBarSlideGestureEnablePending = false;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
OC.disallowNavigationBarSlideGesture = function() {
|
|
|
|
|
navigationBarSlideGestureAllowed = false;
|
|
|
|
|
|
|
|
|
|
if (navigationBarSlideGestureEnabled) {
|
2017-12-14 20:12:12 +03:00
|
|
|
|
var endCurrentDrag = true;
|
|
|
|
|
snapper.disable(endCurrentDrag);
|
2017-10-23 02:01:01 +03:00
|
|
|
|
|
|
|
|
|
navigationBarSlideGestureEnabled = false;
|
|
|
|
|
navigationBarSlideGestureEnablePending = true;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2014-06-06 03:20:31 +04:00
|
|
|
|
var toggleSnapperOnSize = function() {
|
|
|
|
|
if($(window).width() > 768) {
|
|
|
|
|
snapper.close();
|
|
|
|
|
snapper.disable();
|
2017-10-23 02:01:01 +03:00
|
|
|
|
|
|
|
|
|
navigationBarSlideGestureEnabled = false;
|
|
|
|
|
navigationBarSlideGestureEnablePending = false;
|
|
|
|
|
} else if (navigationBarSlideGestureAllowed) {
|
2014-06-06 03:20:31 +04:00
|
|
|
|
snapper.enable();
|
2017-10-23 02:01:01 +03:00
|
|
|
|
|
|
|
|
|
navigationBarSlideGestureEnabled = true;
|
|
|
|
|
navigationBarSlideGestureEnablePending = false;
|
|
|
|
|
} else {
|
|
|
|
|
navigationBarSlideGestureEnablePending = true;
|
2014-06-06 03:20:31 +04:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2014-06-06 11:50:46 +04:00
|
|
|
|
$(window).resize(_.debounce(toggleSnapperOnSize, 250));
|
2014-06-06 03:20:31 +04:00
|
|
|
|
|
|
|
|
|
// initial call
|
|
|
|
|
toggleSnapperOnSize();
|
|
|
|
|
|
|
|
|
|
}
|
2016-08-31 18:33:00 +03:00
|
|
|
|
|
|
|
|
|
// Update live timestamps every 30 seconds
|
|
|
|
|
setInterval(function() {
|
|
|
|
|
$('.live-relative-timestamp').each(function() {
|
|
|
|
|
$(this).text(OC.Util.relativeModifiedDate(parseInt($(this).attr('data-timestamp'), 10)));
|
|
|
|
|
});
|
|
|
|
|
}, 30 * 1000);
|
2016-09-19 16:33:30 +03:00
|
|
|
|
|
|
|
|
|
OC.PasswordConfirmation.init();
|
2014-02-04 16:56:10 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$(document).ready(initCore);
|
2011-08-08 13:07:44 +04:00
|
|
|
|
|
2014-04-21 15:46:33 +04:00
|
|
|
|
/**
|
2014-05-09 00:06:30 +04:00
|
|
|
|
// fallback to hashchange when no history support
|
|
|
|
|
if (window.history.pushState) {
|
|
|
|
|
window.onpopstate = _.bind(OC.Util.History._onPopState, OC.Util.History);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$(window).on('hashchange', _.bind(OC.Util.History._onPopState, OC.Util.History));
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-29 23:52:42 +04:00
|
|
|
|
/**
|
2014-04-21 15:46:33 +04:00
|
|
|
|
* Get a variable by name
|
|
|
|
|
* @param {string} name
|
|
|
|
|
* @return {*}
|
2012-08-29 23:52:42 +04:00
|
|
|
|
*/
|
|
|
|
|
OC.get=function(name) {
|
|
|
|
|
var namespaces = name.split(".");
|
|
|
|
|
var tail = namespaces.pop();
|
|
|
|
|
var context=window;
|
2013-07-07 22:26:09 +04:00
|
|
|
|
|
2012-08-29 23:52:42 +04:00
|
|
|
|
for(var i = 0; i < namespaces.length; i++) {
|
|
|
|
|
context = context[namespaces[i]];
|
|
|
|
|
if(!context){
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return context[tail];
|
2012-09-23 05:16:52 +04:00
|
|
|
|
};
|
2012-08-29 23:52:42 +04:00
|
|
|
|
|
|
|
|
|
/**
|
2014-04-21 15:46:33 +04:00
|
|
|
|
* Set a variable by name
|
|
|
|
|
* @param {string} name
|
2014-04-21 16:42:50 +04:00
|
|
|
|
* @param {*} value
|
2012-08-29 23:52:42 +04:00
|
|
|
|
*/
|
|
|
|
|
OC.set=function(name, value) {
|
|
|
|
|
var namespaces = name.split(".");
|
|
|
|
|
var tail = namespaces.pop();
|
|
|
|
|
var context=window;
|
2013-07-07 22:26:09 +04:00
|
|
|
|
|
2012-08-29 23:52:42 +04:00
|
|
|
|
for(var i = 0; i < namespaces.length; i++) {
|
|
|
|
|
if(!context[namespaces[i]]){
|
|
|
|
|
context[namespaces[i]]={};
|
|
|
|
|
}
|
|
|
|
|
context = context[namespaces[i]];
|
|
|
|
|
}
|
|
|
|
|
context[tail]=value;
|
2012-09-23 05:16:52 +04:00
|
|
|
|
};
|