2012-11-15 22:43:10 +04:00
|
|
|
|
/**
|
|
|
|
|
* Disable console output unless DEBUG mode is enabled.
|
2013-07-07 22:26:09 +04:00
|
|
|
|
* Add
|
2014-03-01 05:46:27 +04:00
|
|
|
|
* define('DEBUG', true);
|
2012-11-15 22:43:10 +04:00
|
|
|
|
* To the end of config/config.php to enable debug mode.
|
2013-01-02 15:21:30 +04:00
|
|
|
|
* The undefined checks fix the broken ie8 console
|
2012-11-15 22:43:10 +04:00
|
|
|
|
*/
|
2014-06-24 01:56:10 +04:00
|
|
|
|
|
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
|
|
|
|
}
|
2014-03-01 05:46:27 +04:00
|
|
|
|
if (
|
|
|
|
|
oc_debug !== true || typeof console === "undefined" ||
|
|
|
|
|
typeof console.log === "undefined"
|
|
|
|
|
) {
|
2012-11-15 22:43:10 +04:00
|
|
|
|
if (!window.console) {
|
|
|
|
|
window.console = {};
|
|
|
|
|
}
|
2014-04-15 06:44:24 +04:00
|
|
|
|
var noOp = function() { };
|
2014-03-17 22:39:19 +04:00
|
|
|
|
var methods = ['log', 'debug', 'warn', 'info', 'error', 'assert', 'time', 'timeEnd'];
|
2012-11-15 22:43:10 +04:00
|
|
|
|
for (var i = 0; i < methods.length; i++) {
|
2014-04-15 06:44:24 +04:00
|
|
|
|
console[methods[i]] = noOp;
|
2012-11-15 22:43:10 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-07 22:26:09 +04:00
|
|
|
|
/**
|
2014-04-21 15:46:33 +04:00
|
|
|
|
* Sanitizes a HTML string by replacing all potential dangerous characters with HTML entities
|
2014-04-21 16:42:50 +04:00
|
|
|
|
* @param {string} s String to sanitize
|
2014-04-21 15:46:33 +04:00
|
|
|
|
* @return {string} Sanitized string
|
2012-10-12 16:01:47 +04:00
|
|
|
|
*/
|
|
|
|
|
function escapeHTML(s) {
|
2014-04-13 17:24:35 +04:00
|
|
|
|
return s.toString().split('&').join('&').split('<').join('<').split('>').join('>').split('"').join('"').split('\'').join(''');
|
2012-10-12 16:01:47 +04:00
|
|
|
|
}
|
|
|
|
|
|
2012-08-27 23:46:05 +04:00
|
|
|
|
/**
|
|
|
|
|
* Get the path to download a file
|
2014-04-21 15:46:33 +04:00
|
|
|
|
* @param {string} file The filename
|
|
|
|
|
* @param {string} dir The directory the file is in - e.g. $('#dir').val()
|
|
|
|
|
* @return {string} Path to download the file
|
2013-10-28 23:22:06 +04:00
|
|
|
|
* @deprecated use Files.getDownloadURL() instead
|
2012-08-27 23:46:05 +04:00
|
|
|
|
*/
|
|
|
|
|
function fileDownloadPath(dir, file) {
|
2012-10-27 17:10:21 +04:00
|
|
|
|
return OC.filePath('files', 'ajax', 'download.php')+'?files='+encodeURIComponent(file)+'&dir='+encodeURIComponent(dir);
|
2012-08-27 23:46:05 +04:00
|
|
|
|
}
|
|
|
|
|
|
2014-06-24 01:56:10 +04:00
|
|
|
|
/** @namespace */
|
2012-09-23 05:16:52 +04:00
|
|
|
|
var OC={
|
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
|
|
|
|
/**
|
|
|
|
|
* Relative path to ownCloud root.
|
|
|
|
|
* For example: "/owncloud"
|
|
|
|
|
*
|
|
|
|
|
* @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
|
|
|
|
|
2013-01-07 23:15:51 +04:00
|
|
|
|
appswebroots:(typeof oc_appswebroots !== 'undefined') ? oc_appswebroots:false,
|
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) {
|
|
|
|
|
return OC.webroot + '/remote.php/' + service;
|
|
|
|
|
},
|
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;
|
|
|
|
|
return window.location.protocol + '//' + window.location.host + OC.webroot + '/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) {
|
2014-08-26 17:40:56 +04:00
|
|
|
|
var 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
|
|
|
|
|
|
|
|
|
if(oc_config.modRewriteWorking == true) {
|
|
|
|
|
return OC.webroot + _build(url, params);
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-03 01:30:24 +04:00
|
|
|
|
return OC.webroot + '/index.php' + _build(url, params);
|
|
|
|
|
},
|
|
|
|
|
|
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,
|
|
|
|
|
link=OC.webroot;
|
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
|
|
|
|
|
2014-01-24 16:32:31 +04:00
|
|
|
|
/**
|
|
|
|
|
* Redirect to the target URL, can also be used for downloads.
|
2014-04-21 15:46:33 +04:00
|
|
|
|
* @param {string} targetURL URL to redirect to
|
2014-01-24 16:32:31 +04:00
|
|
|
|
*/
|
2014-04-21 16:42:50 +04:00
|
|
|
|
redirect: function(targetURL) {
|
|
|
|
|
window.location = targetURL;
|
2014-01-24 16:32:31 +04:00
|
|
|
|
},
|
2014-10-07 14:02:58 +04:00
|
|
|
|
|
2015-01-19 13:56:04 +03:00
|
|
|
|
/**
|
|
|
|
|
* Protocol that is used to access this ownCloud instance
|
|
|
|
|
* @return {string} Used protocol
|
|
|
|
|
*/
|
|
|
|
|
getProtocol: function() {
|
|
|
|
|
return window.location.protocol.split(':')[0];
|
|
|
|
|
},
|
|
|
|
|
|
2015-07-13 16:26:01 +03:00
|
|
|
|
/**
|
|
|
|
|
* Returns the host name used to access this ownCloud instance
|
|
|
|
|
*
|
|
|
|
|
* @return {string} host name
|
|
|
|
|
*
|
|
|
|
|
* @since 8.2
|
|
|
|
|
*/
|
|
|
|
|
getHost: function() {
|
|
|
|
|
return window.location.host;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the port number used to access this ownCloud instance
|
|
|
|
|
*
|
|
|
|
|
* @return {int} port number
|
|
|
|
|
*
|
|
|
|
|
* @since 8.2
|
|
|
|
|
*/
|
|
|
|
|
getPort: function() {
|
|
|
|
|
return window.location.port;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the web root path where this ownCloud instance
|
|
|
|
|
* is accessible, with a leading slash.
|
|
|
|
|
* For example "/owncloud".
|
|
|
|
|
*
|
|
|
|
|
* @return {string} web root path
|
|
|
|
|
*
|
|
|
|
|
* @since 8.2
|
|
|
|
|
*/
|
|
|
|
|
getRootPath: function() {
|
|
|
|
|
return OC.webroot;
|
|
|
|
|
},
|
|
|
|
|
|
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){
|
2012-04-15 15:32:45 +04:00
|
|
|
|
if(file.indexOf('.')==-1){//if no extension is given, use png or svg depending on browser support
|
2014-04-09 17:23:09 +04:00
|
|
|
|
file+=(OC.Util.hasSVGSupport())?'.svg':'.png';
|
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
|
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');
|
2012-08-29 03:57:35 +04:00
|
|
|
|
if(!OC.addScript.loaded[path]){
|
2011-07-30 20:05:20 +04:00
|
|
|
|
if(ready){
|
2012-09-23 05:16:52 +04:00
|
|
|
|
deferred=$.getScript(path,ready);
|
2011-07-30 20:05:20 +04:00
|
|
|
|
}else{
|
2012-09-23 05:16:52 +04:00
|
|
|
|
deferred=$.getScript(path);
|
2011-07-30 20:05:20 +04:00
|
|
|
|
}
|
2012-08-29 03:57:35 +04:00
|
|
|
|
OC.addScript.loaded[path]=deferred;
|
2011-07-30 23:18:54 +04:00
|
|
|
|
}else{
|
|
|
|
|
if(ready){
|
|
|
|
|
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
|
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-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;
|
|
|
|
|
},
|
|
|
|
|
|
2011-08-07 01:18:49 +04:00
|
|
|
|
/**
|
2014-04-21 15:46:33 +04:00
|
|
|
|
* Do a search query and display the results
|
|
|
|
|
* @param {string} query the search query
|
2011-08-07 01:18:49 +04:00
|
|
|
|
*/
|
2014-12-10 19:11:02 +03:00
|
|
|
|
search: function (query) {
|
2014-12-17 20:49:39 +03:00
|
|
|
|
OC.Search.search(query, null, 0, 30);
|
2014-12-10 19:11:02 +03:00
|
|
|
|
},
|
2014-06-24 01:56:10 +04:00
|
|
|
|
/**
|
|
|
|
|
* Dialog helper for jquery dialogs.
|
|
|
|
|
*
|
|
|
|
|
* @namespace OC.dialogs
|
|
|
|
|
*/
|
2012-04-02 21:39:24 +04:00
|
|
|
|
dialogs:OCdialogs,
|
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() {
|
|
|
|
|
popup.prepend('<span class="arrow '+arrowclass+'"></span><h2>'+t('core', 'Settings')+'</h2><a class="close svg"></a>').show();
|
|
|
|
|
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;
|
|
|
|
|
});
|
|
|
|
|
}
|
2014-04-09 17:23:09 +04:00
|
|
|
|
if(!OC.Util.hasSVGSupport()) {
|
2014-04-04 13:32:07 +04:00
|
|
|
|
OC.Util.replaceSVG();
|
2014-01-11 00:19:30 +04:00
|
|
|
|
}
|
2012-08-12 20:42:54 +04:00
|
|
|
|
}).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
|
|
|
|
|
*/
|
2014-03-14 13:33:19 +04:00
|
|
|
|
registerMenu: function($toggle, $menuEl) {
|
2015-07-16 16:28:45 +03:00
|
|
|
|
var self = this;
|
2014-03-14 13:33:19 +04:00
|
|
|
|
$menuEl.addClass('menu');
|
2014-03-18 16:09:25 +04:00
|
|
|
|
$toggle.on('click.menu', function(event) {
|
2015-04-09 15:46:26 +03:00
|
|
|
|
// prevent the link event (append anchor to URL)
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
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
|
|
|
|
}
|
2015-03-26 13:59:30 +03:00
|
|
|
|
$menuEl.slideToggle(OC.menuSpeed);
|
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
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2014-03-18 19:02:13 +04:00
|
|
|
|
/**
|
|
|
|
|
* Wrapper for matchMedia
|
|
|
|
|
*
|
|
|
|
|
* This is makes it possible for unit tests to
|
|
|
|
|
* stub matchMedia (which doesn't work in PhantomJS)
|
2014-06-24 01:56:10 +04:00
|
|
|
|
* @private
|
2014-03-18 19:02:13 +04:00
|
|
|
|
*/
|
|
|
|
|
_matchMedia: function(media) {
|
|
|
|
|
if (window.matchMedia) {
|
|
|
|
|
return window.matchMedia(media);
|
|
|
|
|
}
|
|
|
|
|
return false;
|
2014-11-18 14:13:44 +03:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the user's locale
|
|
|
|
|
*
|
|
|
|
|
* @return {String} locale string
|
|
|
|
|
*/
|
|
|
|
|
getLocale: function() {
|
|
|
|
|
return $('html').prop('lang');
|
2012-07-31 14:21:06 +04:00
|
|
|
|
}
|
2012-02-22 01:31:35 +04:00
|
|
|
|
};
|
2014-04-21 15:46:33 +04:00
|
|
|
|
|
2014-12-01 18:17:28 +03:00
|
|
|
|
/**
|
|
|
|
|
* @namespace OC.Plugins
|
|
|
|
|
*/
|
|
|
|
|
OC.Plugins = {
|
|
|
|
|
/**
|
|
|
|
|
* @type Array.<OC.Plugin>
|
|
|
|
|
*/
|
|
|
|
|
_plugins: {},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Register plugin
|
|
|
|
|
*
|
|
|
|
|
* @param {String} targetName app name / class name to hook into
|
|
|
|
|
* @param {OC.Plugin} plugin
|
|
|
|
|
*/
|
|
|
|
|
register: function(targetName, plugin) {
|
|
|
|
|
var plugins = this._plugins[targetName];
|
|
|
|
|
if (!plugins) {
|
|
|
|
|
plugins = this._plugins[targetName] = [];
|
|
|
|
|
}
|
|
|
|
|
plugins.push(plugin);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns all plugin registered to the given target
|
|
|
|
|
* name / app name / class name.
|
|
|
|
|
*
|
|
|
|
|
* @param {String} targetName app name / class name to hook into
|
|
|
|
|
* @return {Array.<OC.Plugin>} array of plugins
|
|
|
|
|
*/
|
|
|
|
|
getPlugins: function(targetName) {
|
|
|
|
|
return this._plugins[targetName] || [];
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Call attach() on all plugins registered to the given target name.
|
|
|
|
|
*
|
|
|
|
|
* @param {String} targetName app name / class name
|
|
|
|
|
* @param {Object} object to be extended
|
|
|
|
|
* @param {Object} [options] options
|
|
|
|
|
*/
|
|
|
|
|
attach: function(targetName, targetObject, options) {
|
|
|
|
|
var plugins = this.getPlugins(targetName);
|
|
|
|
|
for (var i = 0; i < plugins.length; i++) {
|
|
|
|
|
if (plugins[i].attach) {
|
|
|
|
|
plugins[i].attach(targetObject, options);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Call detach() on all plugins registered to the given target name.
|
|
|
|
|
*
|
|
|
|
|
* @param {String} targetName app name / class name
|
|
|
|
|
* @param {Object} object to be extended
|
|
|
|
|
* @param {Object} [options] options
|
|
|
|
|
*/
|
|
|
|
|
detach: function(targetName, targetObject, options) {
|
|
|
|
|
var plugins = this.getPlugins(targetName);
|
|
|
|
|
for (var i = 0; i < plugins.length; i++) {
|
|
|
|
|
if (plugins[i].detach) {
|
|
|
|
|
plugins[i].detach(targetObject, options);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Plugin
|
|
|
|
|
*
|
|
|
|
|
* @todo make this a real class in the future
|
|
|
|
|
* @typedef {Object} OC.Plugin
|
|
|
|
|
*
|
|
|
|
|
* @property {String} name plugin name
|
|
|
|
|
* @property {Function} attach function that will be called when the
|
|
|
|
|
* plugin is attached
|
|
|
|
|
* @property {Function} [detach] function that will be called when the
|
|
|
|
|
* plugin is detached
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
2014-06-24 01:56:10 +04:00
|
|
|
|
/**
|
|
|
|
|
* @namespace OC.search
|
|
|
|
|
*/
|
2014-12-06 02:53:06 +03:00
|
|
|
|
OC.search.customResults = {};
|
|
|
|
|
/**
|
|
|
|
|
* @deprecated use get/setFormatter() instead
|
|
|
|
|
*/
|
|
|
|
|
OC.search.resultTypes = {};
|
|
|
|
|
|
2011-07-30 20:05:20 +04:00
|
|
|
|
OC.addStyle.loaded=[];
|
|
|
|
|
OC.addScript.loaded=[];
|
|
|
|
|
|
2014-04-21 15:46:33 +04:00
|
|
|
|
/**
|
2015-02-13 18:10:13 +03:00
|
|
|
|
* A little class to manage a status field for a "saving" process.
|
|
|
|
|
* It can be used to display a starting message (e.g. "Saving...") and then
|
|
|
|
|
* replace it with a green success message or a red error message.
|
|
|
|
|
*
|
|
|
|
|
* @namespace OC.msg
|
2014-04-21 15:46:33 +04:00
|
|
|
|
*/
|
2015-02-13 18:10:13 +03:00
|
|
|
|
OC.msg = {
|
2014-04-21 15:46:33 +04:00
|
|
|
|
/**
|
2015-02-13 18:10:13 +03:00
|
|
|
|
* Displayes a "Saving..." message in the given message placeholder
|
|
|
|
|
*
|
|
|
|
|
* @param {Object} selector Placeholder to display the message in
|
2014-04-21 15:46:33 +04:00
|
|
|
|
*/
|
2015-02-13 18:10:13 +03:00
|
|
|
|
startSaving: function(selector) {
|
|
|
|
|
this.startAction(selector, t('core', 'Saving...'));
|
2014-02-19 13:20:52 +04:00
|
|
|
|
},
|
2014-10-07 14:02:58 +04:00
|
|
|
|
|
2014-04-21 15:46:33 +04:00
|
|
|
|
/**
|
2015-02-13 18:10:13 +03:00
|
|
|
|
* Displayes a custom message in the given message placeholder
|
|
|
|
|
*
|
|
|
|
|
* @param {Object} selector Placeholder to display the message in
|
|
|
|
|
* @param {string} message Plain text message to display (no HTML allowed)
|
2014-04-21 15:46:33 +04:00
|
|
|
|
*/
|
2015-02-13 18:10:13 +03:00
|
|
|
|
startAction: function(selector, message) {
|
|
|
|
|
$(selector).text(message)
|
|
|
|
|
.removeClass('success')
|
|
|
|
|
.removeClass('error')
|
|
|
|
|
.stop(true, true)
|
|
|
|
|
.show();
|
2014-02-19 13:20:52 +04:00
|
|
|
|
},
|
2014-10-07 14:02:58 +04:00
|
|
|
|
|
2014-04-21 15:46:33 +04:00
|
|
|
|
/**
|
2015-02-13 18:10:13 +03:00
|
|
|
|
* Displayes an success/error message in the given selector
|
|
|
|
|
*
|
|
|
|
|
* @param {Object} selector Placeholder to display the message in
|
|
|
|
|
* @param {Object} response Response of the server
|
|
|
|
|
* @param {Object} response.data Data of the servers response
|
|
|
|
|
* @param {string} response.data.message Plain text message to display (no HTML allowed)
|
|
|
|
|
* @param {string} response.status is being used to decide whether the message
|
|
|
|
|
* is displayed as an error/success
|
|
|
|
|
*/
|
|
|
|
|
finishedSaving: function(selector, response) {
|
|
|
|
|
this.finishedAction(selector, response);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Displayes an success/error message in the given selector
|
|
|
|
|
*
|
|
|
|
|
* @param {Object} selector Placeholder to display the message in
|
|
|
|
|
* @param {Object} response Response of the server
|
|
|
|
|
* @param {Object} response.data Data of the servers response
|
|
|
|
|
* @param {string} response.data.message Plain text message to display (no HTML allowed)
|
|
|
|
|
* @param {string} response.status is being used to decide whether the message
|
|
|
|
|
* is displayed as an error/success
|
|
|
|
|
*/
|
|
|
|
|
finishedAction: function(selector, response) {
|
|
|
|
|
if (response.status === "success") {
|
|
|
|
|
this.finishedSuccess(selector, response.data.message);
|
|
|
|
|
} else {
|
|
|
|
|
this.finishedError(selector, response.data.message);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Displayes an success message in the given selector
|
|
|
|
|
*
|
|
|
|
|
* @param {Object} selector Placeholder to display the message in
|
|
|
|
|
* @param {string} message Plain text success message to display (no HTML allowed)
|
2014-04-21 15:46:33 +04:00
|
|
|
|
*/
|
2015-02-13 18:10:13 +03:00
|
|
|
|
finishedSuccess: function(selector, message) {
|
|
|
|
|
$(selector).text(message)
|
|
|
|
|
.addClass('success')
|
2014-02-19 13:20:52 +04:00
|
|
|
|
.removeClass('error')
|
|
|
|
|
.stop(true, true)
|
2015-02-13 18:10:13 +03:00
|
|
|
|
.delay(3000)
|
|
|
|
|
.fadeOut(900)
|
2014-02-19 13:20:52 +04:00
|
|
|
|
.show();
|
|
|
|
|
},
|
2014-10-07 14:02:58 +04:00
|
|
|
|
|
2014-04-21 15:46:33 +04:00
|
|
|
|
/**
|
2015-02-13 18:10:13 +03:00
|
|
|
|
* Displayes an error message in the given selector
|
|
|
|
|
*
|
|
|
|
|
* @param {Object} selector Placeholder to display the message in
|
|
|
|
|
* @param {string} message Plain text error message to display (no HTML allowed)
|
2014-04-21 15:46:33 +04:00
|
|
|
|
*/
|
2015-02-13 18:10:13 +03:00
|
|
|
|
finishedError: function(selector, message) {
|
|
|
|
|
$(selector).text(message)
|
|
|
|
|
.addClass('error')
|
|
|
|
|
.removeClass('success')
|
|
|
|
|
.show();
|
2014-02-19 13:20:52 +04:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2014-04-21 15:46:33 +04:00
|
|
|
|
/**
|
|
|
|
|
* @todo Write documentation
|
2014-06-24 01:56:10 +04:00
|
|
|
|
* @namespace
|
2014-04-21 15:46:33 +04:00
|
|
|
|
*/
|
2013-01-05 02:34:09 +04:00
|
|
|
|
OC.Notification={
|
2013-03-02 22:24:37 +04:00
|
|
|
|
queuedNotifications: [],
|
2013-02-09 20:20:08 +04:00
|
|
|
|
getDefaultNotificationFunction: null,
|
2015-01-07 16:51:20 +03:00
|
|
|
|
notificationTimer: 0,
|
2014-10-07 14:02:58 +04:00
|
|
|
|
|
2014-04-21 15:46:33 +04:00
|
|
|
|
/**
|
|
|
|
|
* @param callback
|
|
|
|
|
* @todo Write documentation
|
|
|
|
|
*/
|
2013-02-09 20:20:08 +04:00
|
|
|
|
setDefault: function(callback) {
|
|
|
|
|
OC.Notification.getDefaultNotificationFunction = callback;
|
|
|
|
|
},
|
2014-10-07 14:02:58 +04:00
|
|
|
|
|
2014-04-21 15:46:33 +04:00
|
|
|
|
/**
|
|
|
|
|
* Hides a notification
|
|
|
|
|
* @param callback
|
|
|
|
|
* @todo Write documentation
|
|
|
|
|
*/
|
2013-02-09 20:20:08 +04:00
|
|
|
|
hide: function(callback) {
|
|
|
|
|
$('#notification').fadeOut('400', function(){
|
|
|
|
|
if (OC.Notification.isHidden()) {
|
|
|
|
|
if (OC.Notification.getDefaultNotificationFunction) {
|
|
|
|
|
OC.Notification.getDefaultNotificationFunction.call();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (callback) {
|
|
|
|
|
callback.call();
|
|
|
|
|
}
|
|
|
|
|
$('#notification').empty();
|
|
|
|
|
if(OC.Notification.queuedNotifications.length > 0){
|
|
|
|
|
OC.Notification.showHtml(OC.Notification.queuedNotifications[0]);
|
|
|
|
|
OC.Notification.queuedNotifications.shift();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
},
|
2014-10-07 14:02:58 +04:00
|
|
|
|
|
2014-04-21 15:46:33 +04:00
|
|
|
|
/**
|
|
|
|
|
* Shows a notification as HTML without being sanitized before.
|
2014-04-22 11:54:25 +04:00
|
|
|
|
* If you pass unsanitized user input this may lead to a XSS vulnerability.
|
2014-04-21 15:46:33 +04:00
|
|
|
|
* Consider using show() instead of showHTML()
|
|
|
|
|
* @param {string} html Message to display
|
|
|
|
|
*/
|
2013-02-09 20:20:08 +04:00
|
|
|
|
showHtml: function(html) {
|
2014-04-21 16:28:54 +04:00
|
|
|
|
var notification = $('#notification');
|
|
|
|
|
if((notification.filter('span.undo').length == 1) || OC.Notification.isHidden()){
|
|
|
|
|
notification.html(html);
|
2014-07-30 20:02:53 +04:00
|
|
|
|
notification.fadeIn().css('display','inline-block');
|
2013-02-09 20:20:08 +04:00
|
|
|
|
}else{
|
|
|
|
|
OC.Notification.queuedNotifications.push(html);
|
|
|
|
|
}
|
|
|
|
|
},
|
2014-10-07 14:02:58 +04:00
|
|
|
|
|
2014-04-21 15:46:33 +04:00
|
|
|
|
/**
|
|
|
|
|
* Shows a sanitized notification
|
|
|
|
|
* @param {string} text Message to display
|
|
|
|
|
*/
|
2013-02-09 20:20:08 +04:00
|
|
|
|
show: function(text) {
|
2014-04-21 16:28:54 +04:00
|
|
|
|
var notification = $('#notification');
|
|
|
|
|
if((notification.filter('span.undo').length == 1) || OC.Notification.isHidden()){
|
|
|
|
|
notification.text(text);
|
2014-07-30 20:02:53 +04:00
|
|
|
|
notification.fadeIn().css('display','inline-block');
|
2013-02-09 20:20:08 +04:00
|
|
|
|
}else{
|
2013-05-03 02:15:28 +04:00
|
|
|
|
OC.Notification.queuedNotifications.push($('<div/>').text(text).html());
|
2013-02-09 20:20:08 +04:00
|
|
|
|
}
|
|
|
|
|
},
|
2014-10-07 14:02:58 +04:00
|
|
|
|
|
2015-01-07 16:51:20 +03:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Shows a notification that disappears after x seconds, default is
|
|
|
|
|
* 7 seconds
|
|
|
|
|
* @param {string} text Message to show
|
|
|
|
|
* @param {array} [options] options array
|
|
|
|
|
* @param {int} [options.timeout=7] timeout in seconds, if this is 0 it will show the message permanently
|
|
|
|
|
* @param {boolean} [options.isHTML=false] an indicator for HTML notifications (true) or text (false)
|
|
|
|
|
*/
|
|
|
|
|
showTemporary: function(text, options) {
|
|
|
|
|
var defaults = {
|
|
|
|
|
isHTML: false,
|
|
|
|
|
timeout: 7
|
|
|
|
|
},
|
|
|
|
|
options = options || {};
|
|
|
|
|
// merge defaults with passed in options
|
|
|
|
|
_.defaults(options, defaults);
|
|
|
|
|
|
|
|
|
|
// clear previous notifications
|
|
|
|
|
OC.Notification.hide();
|
|
|
|
|
if(OC.Notification.notificationTimer) {
|
|
|
|
|
clearTimeout(OC.Notification.notificationTimer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(options.isHTML) {
|
|
|
|
|
OC.Notification.showHtml(text);
|
|
|
|
|
} else {
|
|
|
|
|
OC.Notification.show(text);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(options.timeout > 0) {
|
|
|
|
|
// register timeout to vanish notification
|
|
|
|
|
OC.Notification.notificationTimer = setTimeout(OC.Notification.hide, (options.timeout * 1000));
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2014-04-21 15:46:33 +04:00
|
|
|
|
/**
|
2014-10-07 14:02:58 +04:00
|
|
|
|
* Returns whether a notification is hidden.
|
2014-04-21 15:46:33 +04:00
|
|
|
|
* @return {boolean}
|
|
|
|
|
*/
|
2013-01-19 03:31:49 +04:00
|
|
|
|
isHidden: function() {
|
|
|
|
|
return ($("#notification").text() === '');
|
|
|
|
|
}
|
2013-01-05 02:34:09 +04:00
|
|
|
|
};
|
|
|
|
|
|
2014-04-21 15:46:33 +04:00
|
|
|
|
/**
|
2014-06-24 01:56:10 +04:00
|
|
|
|
* Breadcrumb class
|
|
|
|
|
*
|
|
|
|
|
* @namespace
|
|
|
|
|
*
|
|
|
|
|
* @deprecated will be replaced by the breadcrumb implementation
|
|
|
|
|
* of the files app in the future
|
2014-04-21 15:46:33 +04:00
|
|
|
|
*/
|
2012-09-09 04:58:16 +04:00
|
|
|
|
OC.Breadcrumb={
|
|
|
|
|
container:null,
|
2014-04-21 15:46:33 +04:00
|
|
|
|
/**
|
|
|
|
|
* @todo Write documentation
|
|
|
|
|
* @param dir
|
2014-04-22 11:54:25 +04:00
|
|
|
|
* @param leafName
|
|
|
|
|
* @param leafLink
|
2014-04-21 15:46:33 +04:00
|
|
|
|
*/
|
2014-04-22 11:54:25 +04:00
|
|
|
|
show:function(dir, leafName, leafLink){
|
2013-08-16 19:20:49 +04:00
|
|
|
|
if(!this.container){//default
|
|
|
|
|
this.container=$('#controls');
|
|
|
|
|
}
|
2014-04-22 11:54:25 +04:00
|
|
|
|
this._show(this.container, dir, leafName, leafLink);
|
2013-08-16 19:20:49 +04:00
|
|
|
|
},
|
|
|
|
|
_show:function(container, dir, leafname, leaflink){
|
|
|
|
|
var self = this;
|
2013-12-13 17:34:26 +04:00
|
|
|
|
|
2013-08-16 19:20:49 +04:00
|
|
|
|
this._clear(container);
|
2013-12-13 17:34:26 +04:00
|
|
|
|
|
2013-08-02 13:44:53 +04:00
|
|
|
|
// show home + path in subdirectories
|
2013-12-13 17:34:26 +04:00
|
|
|
|
if (dir) {
|
2013-08-02 13:44:53 +04:00
|
|
|
|
//add home
|
|
|
|
|
var link = OC.linkTo('files','index.php');
|
2013-08-01 16:38:06 +04:00
|
|
|
|
|
2013-08-02 13:44:53 +04:00
|
|
|
|
var crumb=$('<div/>');
|
|
|
|
|
crumb.addClass('crumb');
|
2013-08-01 16:38:06 +04:00
|
|
|
|
|
2013-08-02 13:44:53 +04:00
|
|
|
|
var crumbLink=$('<a/>');
|
|
|
|
|
crumbLink.attr('href',link);
|
2013-08-01 16:38:06 +04:00
|
|
|
|
|
2013-08-02 13:44:53 +04:00
|
|
|
|
var crumbImg=$('<img/>');
|
|
|
|
|
crumbImg.attr('src',OC.imagePath('core','places/home'));
|
|
|
|
|
crumbLink.append(crumbImg);
|
|
|
|
|
crumb.append(crumbLink);
|
2013-08-16 19:20:49 +04:00
|
|
|
|
container.prepend(crumb);
|
2013-08-02 13:44:53 +04:00
|
|
|
|
|
|
|
|
|
//add path parts
|
|
|
|
|
var segments = dir.split('/');
|
|
|
|
|
var pathurl = '';
|
|
|
|
|
jQuery.each(segments, function(i,name) {
|
|
|
|
|
if (name !== '') {
|
|
|
|
|
pathurl = pathurl+'/'+name;
|
|
|
|
|
var link = OC.linkTo('files','index.php')+'?dir='+encodeURIComponent(pathurl);
|
2013-08-16 19:20:49 +04:00
|
|
|
|
self._push(container, name, link);
|
2013-08-02 13:44:53 +04:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2013-12-13 17:34:26 +04:00
|
|
|
|
|
2013-08-02 13:44:53 +04:00
|
|
|
|
//add leafname
|
|
|
|
|
if (leafname && leaflink) {
|
2013-08-16 19:20:49 +04:00
|
|
|
|
this._push(container, leafname, leaflink);
|
2013-08-02 13:44:53 +04:00
|
|
|
|
}
|
2013-08-01 16:38:06 +04:00
|
|
|
|
},
|
2014-10-07 14:02:58 +04:00
|
|
|
|
|
2014-04-21 15:46:33 +04:00
|
|
|
|
/**
|
|
|
|
|
* @todo Write documentation
|
|
|
|
|
* @param {string} name
|
|
|
|
|
* @param {string} link
|
|
|
|
|
*/
|
2012-09-09 04:58:16 +04:00
|
|
|
|
push:function(name, link){
|
2013-08-16 19:20:49 +04:00
|
|
|
|
if(!this.container){//default
|
|
|
|
|
this.container=$('#controls');
|
2012-09-09 04:58:16 +04:00
|
|
|
|
}
|
2013-08-16 19:20:49 +04:00
|
|
|
|
return this._push(OC.Breadcrumb.container, name, link);
|
|
|
|
|
},
|
|
|
|
|
_push:function(container, name, link){
|
2012-09-09 04:58:16 +04:00
|
|
|
|
var crumb=$('<div/>');
|
|
|
|
|
crumb.addClass('crumb').addClass('last');
|
|
|
|
|
|
|
|
|
|
var crumbLink=$('<a/>');
|
|
|
|
|
crumbLink.attr('href',link);
|
|
|
|
|
crumbLink.text(name);
|
|
|
|
|
crumb.append(crumbLink);
|
|
|
|
|
|
2013-08-16 19:20:49 +04:00
|
|
|
|
var existing=container.find('div.crumb');
|
2012-09-09 04:58:16 +04:00
|
|
|
|
if(existing.length){
|
|
|
|
|
existing.removeClass('last');
|
|
|
|
|
existing.last().after(crumb);
|
|
|
|
|
}else{
|
2013-08-16 19:20:49 +04:00
|
|
|
|
container.prepend(crumb);
|
2012-09-09 04:58:16 +04:00
|
|
|
|
}
|
|
|
|
|
return crumb;
|
|
|
|
|
},
|
2014-10-07 14:02:58 +04:00
|
|
|
|
|
2014-04-21 15:46:33 +04:00
|
|
|
|
/**
|
|
|
|
|
* @todo Write documentation
|
|
|
|
|
*/
|
2012-09-09 04:58:16 +04:00
|
|
|
|
pop:function(){
|
2013-08-16 19:20:49 +04:00
|
|
|
|
if(!this.container){//default
|
|
|
|
|
this.container=$('#controls');
|
2012-09-09 04:58:16 +04:00
|
|
|
|
}
|
2013-08-16 19:20:49 +04:00
|
|
|
|
this.container.find('div.crumb').last().remove();
|
|
|
|
|
this.container.find('div.crumb').last().addClass('last');
|
2012-09-09 04:58:16 +04:00
|
|
|
|
},
|
2014-10-07 14:02:58 +04:00
|
|
|
|
|
2014-04-21 15:46:33 +04:00
|
|
|
|
/**
|
|
|
|
|
* @todo Write documentation
|
|
|
|
|
*/
|
2012-09-09 04:58:16 +04:00
|
|
|
|
clear:function(){
|
2013-08-16 19:20:49 +04:00
|
|
|
|
if(!this.container){//default
|
|
|
|
|
this.container=$('#controls');
|
2012-09-09 04:58:16 +04:00
|
|
|
|
}
|
2013-08-16 19:20:49 +04:00
|
|
|
|
this._clear(this.container);
|
|
|
|
|
},
|
|
|
|
|
_clear:function(container) {
|
|
|
|
|
container.find('div.crumb').remove();
|
2012-09-09 04:58:16 +04:00
|
|
|
|
}
|
2012-09-23 05:16:52 +04:00
|
|
|
|
};
|
2012-09-09 04:58:16 +04:00
|
|
|
|
|
2012-09-23 05:16:52 +04:00
|
|
|
|
if(typeof localStorage !=='undefined' && localStorage !== null){
|
2014-04-21 15:46:33 +04:00
|
|
|
|
/**
|
|
|
|
|
* User and instance aware localstorage
|
2014-06-24 01:56:10 +04:00
|
|
|
|
* @namespace
|
2014-04-21 15:46:33 +04:00
|
|
|
|
*/
|
2012-01-15 22:11:25 +04:00
|
|
|
|
OC.localStorage={
|
|
|
|
|
namespace:'oc_'+OC.currentUser+'_'+OC.webroot+'_',
|
2014-10-07 14:02:58 +04:00
|
|
|
|
|
2014-04-21 15:46:33 +04:00
|
|
|
|
/**
|
|
|
|
|
* Whether the storage contains items
|
|
|
|
|
* @param {string} name
|
|
|
|
|
* @return {boolean}
|
|
|
|
|
*/
|
2012-01-15 22:11:25 +04:00
|
|
|
|
hasItem:function(name){
|
2012-09-23 05:16:52 +04:00
|
|
|
|
return OC.localStorage.getItem(name)!==null;
|
2012-01-15 22:11:25 +04:00
|
|
|
|
},
|
2014-10-07 14:02:58 +04:00
|
|
|
|
|
2014-04-21 15:46:33 +04:00
|
|
|
|
/**
|
|
|
|
|
* Add an item to the storage
|
|
|
|
|
* @param {string} name
|
|
|
|
|
* @param {string} item
|
|
|
|
|
*/
|
2012-01-15 22:11:25 +04:00
|
|
|
|
setItem:function(name,item){
|
|
|
|
|
return localStorage.setItem(OC.localStorage.namespace+name,JSON.stringify(item));
|
|
|
|
|
},
|
2014-10-07 14:02:58 +04:00
|
|
|
|
|
2014-04-21 15:46:33 +04:00
|
|
|
|
/**
|
|
|
|
|
* Removes an item from the storage
|
|
|
|
|
* @param {string} name
|
|
|
|
|
* @param {string} item
|
|
|
|
|
*/
|
2014-03-10 19:22:52 +04:00
|
|
|
|
removeItem:function(name,item){
|
2014-03-10 19:26:07 +04:00
|
|
|
|
return localStorage.removeItem(OC.localStorage.namespace+name);
|
2014-03-10 19:22:52 +04:00
|
|
|
|
},
|
2014-10-07 14:02:58 +04:00
|
|
|
|
|
2014-04-21 15:46:33 +04:00
|
|
|
|
/**
|
|
|
|
|
* Get an item from the storage
|
|
|
|
|
* @param {string} name
|
|
|
|
|
* @return {null|string}
|
|
|
|
|
*/
|
2012-01-15 22:11:25 +04:00
|
|
|
|
getItem:function(name){
|
2013-01-02 20:04:11 +04:00
|
|
|
|
var item = localStorage.getItem(OC.localStorage.namespace+name);
|
2014-04-21 15:46:33 +04:00
|
|
|
|
if(item === null) {
|
2013-01-02 20:04:11 +04:00
|
|
|
|
return null;
|
|
|
|
|
} else if (typeof JSON === 'undefined') {
|
|
|
|
|
//fallback to jquery for IE6/7/8
|
|
|
|
|
return $.parseJSON(item);
|
|
|
|
|
} else {
|
|
|
|
|
return JSON.parse(item);
|
|
|
|
|
}
|
2012-01-15 22:11:25 +04:00
|
|
|
|
}
|
2012-02-22 01:31:35 +04:00
|
|
|
|
};
|
2012-01-15 22:11:25 +04:00
|
|
|
|
}else{
|
|
|
|
|
//dummy localstorage
|
|
|
|
|
OC.localStorage={
|
2012-09-23 05:16:52 +04:00
|
|
|
|
hasItem:function(){
|
2012-01-15 22:11:25 +04:00
|
|
|
|
return false;
|
|
|
|
|
},
|
2012-09-23 05:16:52 +04:00
|
|
|
|
setItem:function(){
|
2012-01-15 22:11:25 +04:00
|
|
|
|
return false;
|
|
|
|
|
},
|
2012-09-23 05:16:52 +04:00
|
|
|
|
getItem:function(){
|
2012-01-15 22:11:25 +04:00
|
|
|
|
return null;
|
|
|
|
|
}
|
2012-02-22 01:31:35 +04:00
|
|
|
|
};
|
2012-01-15 22:11:25 +04:00
|
|
|
|
}
|
|
|
|
|
|
2011-08-07 01:18:49 +04:00
|
|
|
|
/**
|
|
|
|
|
* check if the browser support svg images
|
2014-04-21 15:46:33 +04:00
|
|
|
|
* @return {boolean}
|
2011-08-07 01:18:49 +04:00
|
|
|
|
*/
|
2011-07-28 06:28:04 +04:00
|
|
|
|
function SVGSupport() {
|
2011-08-22 17:20:24 +04:00
|
|
|
|
return SVGSupport.checkMimeType.correct && !!document.createElementNS && !!document.createElementNS('http://www.w3.org/2000/svg', "svg").createSVGRect;
|
2011-07-28 06:28:04 +04:00
|
|
|
|
}
|
2011-08-22 17:20:24 +04:00
|
|
|
|
SVGSupport.checkMimeType=function(){
|
|
|
|
|
$.ajax({
|
|
|
|
|
url: OC.imagePath('core','breadcrumb.svg'),
|
|
|
|
|
success:function(data,text,xhr){
|
|
|
|
|
var headerParts=xhr.getAllResponseHeaders().split("\n");
|
|
|
|
|
var headers={};
|
|
|
|
|
$.each(headerParts,function(i,text){
|
|
|
|
|
if(text){
|
|
|
|
|
var parts=text.split(':',2);
|
2012-09-23 05:16:52 +04:00
|
|
|
|
if(parts.length===2){
|
2012-01-15 02:37:50 +04:00
|
|
|
|
var value=parts[1].trim();
|
2012-09-23 05:16:52 +04:00
|
|
|
|
if(value[0]==='"'){
|
2012-01-15 02:37:50 +04:00
|
|
|
|
value=value.substr(1,value.length-2);
|
|
|
|
|
}
|
2014-03-17 20:11:49 +04:00
|
|
|
|
headers[parts[0].toLowerCase()]=value;
|
2011-08-22 17:20:24 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
2014-03-17 20:11:49 +04:00
|
|
|
|
if(headers["content-type"]!=='image/svg+xml'){
|
2014-04-04 13:32:07 +04:00
|
|
|
|
OC.Util.replaceSVG();
|
2012-02-22 01:31:35 +04:00
|
|
|
|
SVGSupport.checkMimeType.correct=false;
|
2011-08-22 17:20:24 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
2012-02-22 01:31:35 +04:00
|
|
|
|
};
|
2011-08-22 17:20:24 +04:00
|
|
|
|
SVGSupport.checkMimeType.correct=true;
|
2011-07-29 18:52:09 +04:00
|
|
|
|
|
2014-04-21 15:46:33 +04:00
|
|
|
|
/**
|
|
|
|
|
* Replace all svg images with png for browser compatibility
|
|
|
|
|
* @param $el
|
|
|
|
|
* @deprecated use OC.Util.replaceSVG instead
|
|
|
|
|
*/
|
2014-04-04 13:32:07 +04:00
|
|
|
|
function replaceSVG($el){
|
|
|
|
|
return OC.Util.replaceSVG($el);
|
2011-08-22 16:53:52 +04:00
|
|
|
|
}
|
|
|
|
|
|
2011-08-07 01:18:49 +04:00
|
|
|
|
/**
|
2014-04-22 11:54:25 +04:00
|
|
|
|
* prototypical inheritance functions
|
2014-04-21 15:46:33 +04:00
|
|
|
|
* @todo Write documentation
|
2011-08-07 01:18:49 +04:00
|
|
|
|
* usage:
|
|
|
|
|
* MySubObject=object(MyObject)
|
|
|
|
|
*/
|
|
|
|
|
function object(o) {
|
|
|
|
|
function F() {}
|
2013-02-09 20:20:08 +04:00
|
|
|
|
F.prototype = o;
|
2011-08-07 01:18:49 +04:00
|
|
|
|
return new F();
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
|
2015-11-10 16:05:05 +03:00
|
|
|
|
if ($.browser.msie || !!navigator.userAgent.match(/Trident\/7\./)) {
|
|
|
|
|
// for IE10+ that don't have conditional comments
|
|
|
|
|
// and IE11 doesn't identify as MSIE any more...
|
|
|
|
|
$('html').addClass('ie');
|
|
|
|
|
} else if (!!navigator.userAgent.match(/Edge\/12/)) {
|
|
|
|
|
// for edge
|
|
|
|
|
$('html').addClass('edge');
|
|
|
|
|
}
|
2014-10-22 18:38:17 +04:00
|
|
|
|
|
2014-02-04 16:56:10 +04:00
|
|
|
|
/**
|
2014-02-04 23:58:06 +04:00
|
|
|
|
* Calls the server periodically to ensure that session doesn't
|
2014-02-04 16:56:10 +04:00
|
|
|
|
* time out
|
|
|
|
|
*/
|
|
|
|
|
function initSessionHeartBeat(){
|
2014-06-12 20:41:19 +04:00
|
|
|
|
// max interval in seconds set to 24 hours
|
|
|
|
|
var maxInterval = 24 * 3600;
|
2014-02-04 16:56:10 +04:00
|
|
|
|
// interval in seconds
|
|
|
|
|
var interval = 900;
|
|
|
|
|
if (oc_config.session_lifetime) {
|
|
|
|
|
interval = Math.floor(oc_config.session_lifetime / 2);
|
|
|
|
|
}
|
|
|
|
|
// minimum one minute
|
|
|
|
|
if (interval < 60) {
|
|
|
|
|
interval = 60;
|
|
|
|
|
}
|
2014-06-12 20:41:19 +04:00
|
|
|
|
if (interval > maxInterval) {
|
|
|
|
|
interval = maxInterval;
|
|
|
|
|
}
|
2014-03-03 02:15:37 +04:00
|
|
|
|
var url = OC.generateUrl('/heartbeat');
|
2014-03-03 01:30:24 +04:00
|
|
|
|
setInterval(function(){
|
|
|
|
|
$.post(url);
|
|
|
|
|
}, interval * 1000);
|
2014-02-04 16:56:10 +04:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-04 23:58:06 +04:00
|
|
|
|
// session heartbeat (defaults to enabled)
|
2014-02-04 16:56:10 +04:00
|
|
|
|
if (typeof(oc_config.session_keepalive) === 'undefined' ||
|
|
|
|
|
!!oc_config.session_keepalive) {
|
|
|
|
|
|
|
|
|
|
initSessionHeartBeat();
|
|
|
|
|
}
|
2011-10-04 20:54:07 +04:00
|
|
|
|
|
2014-04-09 17:23:09 +04:00
|
|
|
|
if(!OC.Util.hasSVGSupport()){ //replace all svg images with png images for browser that dont support svg
|
2014-04-04 13:32:07 +04:00
|
|
|
|
OC.Util.replaceSVG();
|
2011-08-22 17:20:24 +04:00
|
|
|
|
}else{
|
|
|
|
|
SVGSupport.checkMimeType();
|
|
|
|
|
}
|
2011-08-08 13:45:01 +04:00
|
|
|
|
|
2015-10-21 14:22:49 +03:00
|
|
|
|
OC.registerMenu($('#expand'), $('#expanddiv'));
|
2011-08-14 16:55:43 +04:00
|
|
|
|
|
2014-03-14 13:33:19 +04:00
|
|
|
|
// toggle for menus
|
|
|
|
|
$(document).on('mouseup.closemenus', function(event) {
|
|
|
|
|
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() {
|
2014-05-16 18:04:36 +04:00
|
|
|
|
// toggle the navigation
|
2015-11-02 11:49:03 +03:00
|
|
|
|
var $toggle = $('#header .header-appname-container');
|
2014-03-18 18:52:06 +04:00
|
|
|
|
var $navigation = $('#navigation');
|
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
|
|
|
|
|
|
|
|
|
// show loading feedback
|
|
|
|
|
$navigation.delegate('a', 'click', function(event) {
|
|
|
|
|
var $app = $(event.target);
|
|
|
|
|
if(!$app.is('a')) {
|
|
|
|
|
$app = $app.closest('a');
|
|
|
|
|
}
|
2014-07-07 12:39:48 +04:00
|
|
|
|
if(!event.ctrlKey) {
|
|
|
|
|
$app.addClass('app-loading');
|
|
|
|
|
}
|
2014-06-04 15:18:05 +04:00
|
|
|
|
});
|
2014-03-17 23:40:22 +04:00
|
|
|
|
}
|
2014-03-18 16:09:25 +04:00
|
|
|
|
|
2014-05-17 20:03:00 +04:00
|
|
|
|
setupMainMenu();
|
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) {
|
|
|
|
|
$('#header #owncloud + .menutoggle').one('click', function(){
|
|
|
|
|
var caretPosition = $('.header-appname + .icon-caret').offset().left - 2;
|
|
|
|
|
if(caretPosition > 255) {
|
|
|
|
|
// if the app name is longer than the menu, just put the triangle in the middle
|
|
|
|
|
return;
|
|
|
|
|
} else {
|
|
|
|
|
$('head').append('<style>#navigation:after { left: '+ caretPosition +'px; }</style>');
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-06 03:20:31 +04:00
|
|
|
|
// just add snapper for logged in users
|
2014-06-10 19:14:49 +04:00
|
|
|
|
if($('#app-navigation').length && !$('html').hasClass('lte9')) {
|
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',
|
2015-07-21 18:03:45 +03:00
|
|
|
|
maxPosition: 250,
|
|
|
|
|
minDragDistance: 100
|
2014-06-06 03:20:31 +04:00
|
|
|
|
});
|
|
|
|
|
$('#app-content').prepend('<div id="app-navigation-toggle" class="icon-menu" style="display:none;"></div>');
|
|
|
|
|
$('#app-navigation-toggle').click(function(){
|
|
|
|
|
if(snapper.state().state == 'left'){
|
|
|
|
|
snapper.close();
|
|
|
|
|
} else {
|
|
|
|
|
snapper.open('left');
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
// 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;
|
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var toggleSnapperOnSize = function() {
|
|
|
|
|
if($(window).width() > 768) {
|
|
|
|
|
snapper.close();
|
|
|
|
|
snapper.disable();
|
|
|
|
|
} else {
|
|
|
|
|
snapper.enable();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2014-06-06 11:50:46 +04:00
|
|
|
|
$(window).resize(_.debounce(toggleSnapperOnSize, 250));
|
2014-06-06 03:20:31 +04:00
|
|
|
|
|
|
|
|
|
// initial call
|
|
|
|
|
toggleSnapperOnSize();
|
|
|
|
|
|
2015-03-27 03:34:55 +03:00
|
|
|
|
// adjust controls bar width
|
|
|
|
|
var adjustControlsWidth = function() {
|
|
|
|
|
if($('#controls').length) {
|
2015-03-27 11:37:52 +03:00
|
|
|
|
var controlsWidth;
|
2015-03-27 03:34:55 +03:00
|
|
|
|
// if there is a scrollbar …
|
|
|
|
|
if($('#app-content').get(0).scrollHeight > $('#app-content').height()) {
|
|
|
|
|
if($(window).width() > 768) {
|
2015-08-28 13:23:57 +03:00
|
|
|
|
controlsWidth = $('#content').width() - $('#app-navigation').width() - getScrollBarWidth();
|
|
|
|
|
if (!$('#app-sidebar').hasClass('hidden') && !$('#app-sidebar').hasClass('disappear')) {
|
|
|
|
|
controlsWidth -= $('#app-sidebar').width();
|
|
|
|
|
}
|
2015-03-27 03:34:55 +03:00
|
|
|
|
} else {
|
2015-03-27 11:37:52 +03:00
|
|
|
|
controlsWidth = $('#content').width() - getScrollBarWidth();
|
2015-03-27 03:34:55 +03:00
|
|
|
|
}
|
|
|
|
|
} else { // if there is none
|
|
|
|
|
if($(window).width() > 768) {
|
2015-08-28 13:23:57 +03:00
|
|
|
|
controlsWidth = $('#content').width() - $('#app-navigation').width();
|
|
|
|
|
if (!$('#app-sidebar').hasClass('hidden') && !$('#app-sidebar').hasClass('disappear')) {
|
|
|
|
|
controlsWidth -= $('#app-sidebar').width();
|
|
|
|
|
}
|
2015-03-27 03:34:55 +03:00
|
|
|
|
} else {
|
2015-03-27 11:37:52 +03:00
|
|
|
|
controlsWidth = $('#content').width();
|
2015-03-27 03:34:55 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$('#controls').css('width', controlsWidth);
|
|
|
|
|
$('#controls').css('min-width', controlsWidth);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$(window).resize(_.debounce(adjustControlsWidth, 250));
|
|
|
|
|
|
2015-08-28 13:23:57 +03:00
|
|
|
|
$('body').delegate('#app-content', 'apprendered appresized', adjustControlsWidth);
|
2015-03-27 03:34:55 +03:00
|
|
|
|
|
2014-06-06 03:20:31 +04:00
|
|
|
|
}
|
2014-02-04 16:56:10 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$(document).ready(initCore);
|
2011-08-08 13:07:44 +04:00
|
|
|
|
|
2011-11-02 01:35:13 +04:00
|
|
|
|
/**
|
|
|
|
|
* Filter Jquery selector by attribute value
|
2012-11-14 04:18:26 +04:00
|
|
|
|
*/
|
2012-07-31 14:21:06 +04:00
|
|
|
|
$.fn.filterAttr = function(attr_name, attr_value) {
|
2012-08-25 02:05:07 +04:00
|
|
|
|
return this.filter(function() { return $(this).attr(attr_name) === attr_value; });
|
2011-11-02 01:35:13 +04:00
|
|
|
|
};
|
2012-01-15 22:11:25 +04:00
|
|
|
|
|
2014-04-21 15:46:33 +04:00
|
|
|
|
/**
|
2014-04-22 11:54:25 +04:00
|
|
|
|
* Returns a human readable file size
|
2014-04-21 16:42:50 +04:00
|
|
|
|
* @param {number} size Size in bytes
|
2014-06-02 12:38:46 +04:00
|
|
|
|
* @param {boolean} skipSmallSizes return '< 1 kB' for small files
|
2014-04-21 15:46:33 +04:00
|
|
|
|
* @return {string}
|
|
|
|
|
*/
|
2014-06-02 12:38:46 +04:00
|
|
|
|
function humanFileSize(size, skipSmallSizes) {
|
2016-01-19 12:51:57 +03:00
|
|
|
|
var humanList = ['B', 'KB', 'MB', 'GB', 'TB'];
|
2012-02-26 17:03:53 +04:00
|
|
|
|
// Calculate Log with base 1024: size = 1024 ** order
|
2015-01-29 19:27:28 +03:00
|
|
|
|
var order = size > 0 ? Math.floor(Math.log(size) / Math.log(1024)) : 0;
|
2012-02-26 17:03:53 +04:00
|
|
|
|
// Stay in range of the byte sizes that are defined
|
2012-02-27 01:09:21 +04:00
|
|
|
|
order = Math.min(humanList.length - 1, order);
|
2012-09-23 05:16:52 +04:00
|
|
|
|
var readableFormat = humanList[order];
|
|
|
|
|
var relativeSize = (size / Math.pow(1024, order)).toFixed(1);
|
2014-06-02 12:38:46 +04:00
|
|
|
|
if(skipSmallSizes === true && order === 0) {
|
|
|
|
|
if(relativeSize !== "0.0"){
|
2016-01-19 12:51:57 +03:00
|
|
|
|
return '< 1 KB';
|
2014-06-02 12:38:46 +04:00
|
|
|
|
} else {
|
2016-01-19 12:51:57 +03:00
|
|
|
|
return '0 KB';
|
2014-06-02 12:38:46 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
2013-11-25 15:26:03 +04:00
|
|
|
|
if(order < 2){
|
|
|
|
|
relativeSize = parseFloat(relativeSize).toFixed(0);
|
2013-12-18 18:43:45 +04:00
|
|
|
|
}
|
2013-11-25 15:26:03 +04:00
|
|
|
|
else if(relativeSize.substr(relativeSize.length-2,2)==='.0'){
|
2012-02-26 17:03:53 +04:00
|
|
|
|
relativeSize=relativeSize.substr(0,relativeSize.length-2);
|
2012-02-26 00:19:32 +04:00
|
|
|
|
}
|
2012-02-26 17:03:53 +04:00
|
|
|
|
return relativeSize + ' ' + readableFormat;
|
2012-02-26 00:19:32 +04:00
|
|
|
|
}
|
2012-01-15 22:11:25 +04:00
|
|
|
|
|
2014-04-21 15:46:33 +04:00
|
|
|
|
/**
|
|
|
|
|
* Format an UNIX timestamp to a human understandable format
|
2014-08-26 22:17:33 +04:00
|
|
|
|
* @param {number} timestamp UNIX timestamp
|
2014-04-21 15:46:33 +04:00
|
|
|
|
* @return {string} Human readable format
|
|
|
|
|
*/
|
2014-08-26 22:17:33 +04:00
|
|
|
|
function formatDate(timestamp){
|
|
|
|
|
return OC.Util.formatDate(timestamp);
|
2012-02-26 00:19:32 +04:00
|
|
|
|
}
|
2012-08-29 23:52:42 +04:00
|
|
|
|
|
2014-10-07 14:02:58 +04:00
|
|
|
|
//
|
2014-04-21 15:46:33 +04:00
|
|
|
|
/**
|
|
|
|
|
* Get the value of a URL parameter
|
|
|
|
|
* @link http://stackoverflow.com/questions/1403888/get-url-parameter-with-jquery
|
|
|
|
|
* @param {string} name URL parameter
|
|
|
|
|
* @return {string}
|
|
|
|
|
*/
|
2013-08-01 00:24:52 +04:00
|
|
|
|
function getURLParameter(name) {
|
|
|
|
|
return decodeURI(
|
|
|
|
|
(RegExp(name + '=' + '(.+?)(&|$)').exec(location.search) || [, null])[1]
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2012-11-14 04:18:26 +04:00
|
|
|
|
/**
|
2014-04-21 15:46:33 +04:00
|
|
|
|
* Takes an absolute timestamp and return a string with a human-friendly relative date
|
2014-04-21 16:42:50 +04:00
|
|
|
|
* @param {number} timestamp A Unix timestamp
|
2012-11-06 19:56:42 +04:00
|
|
|
|
*/
|
|
|
|
|
function relative_modified_date(timestamp) {
|
2014-08-26 22:17:33 +04:00
|
|
|
|
/*
|
|
|
|
|
Were multiplying by 1000 to bring the timestamp back to its original value
|
|
|
|
|
per https://github.com/owncloud/core/pull/10647#discussion_r16790315
|
|
|
|
|
*/
|
|
|
|
|
return OC.Util.relativeModifiedDate(timestamp * 1000);
|
2012-11-06 19:56:42 +04:00
|
|
|
|
}
|
|
|
|
|
|
2014-04-21 15:46:33 +04:00
|
|
|
|
/**
|
2014-02-12 17:50:23 +04:00
|
|
|
|
* Utility functions
|
2014-06-24 01:56:10 +04:00
|
|
|
|
* @namespace
|
2014-04-21 15:46:33 +04:00
|
|
|
|
*/
|
2014-04-04 13:32:07 +04:00
|
|
|
|
OC.Util = {
|
2014-02-11 19:52:56 +04:00
|
|
|
|
// TODO: remove original functions from global namespace
|
|
|
|
|
humanFileSize: humanFileSize,
|
2014-08-26 22:17:33 +04:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param timestamp
|
|
|
|
|
* @param format
|
|
|
|
|
* @returns {string} timestamp formatted as requested
|
|
|
|
|
*/
|
|
|
|
|
formatDate: function (timestamp, format) {
|
2015-03-24 15:41:55 +03:00
|
|
|
|
format = format || "LLL";
|
2014-08-26 22:17:33 +04:00
|
|
|
|
return moment(timestamp).format(format);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param timestamp
|
|
|
|
|
* @returns {string} human readable difference from now
|
|
|
|
|
*/
|
|
|
|
|
relativeModifiedDate: function (timestamp) {
|
2015-10-02 11:16:21 +03:00
|
|
|
|
var diff = moment().diff(moment(timestamp));
|
|
|
|
|
if (diff >= 0 && diff < 45000 ) {
|
|
|
|
|
return t('core', 'seconds ago');
|
|
|
|
|
}
|
2014-08-26 22:17:33 +04:00
|
|
|
|
return moment(timestamp).fromNow();
|
|
|
|
|
},
|
2014-04-04 13:32:07 +04:00
|
|
|
|
/**
|
|
|
|
|
* Returns whether the browser supports SVG
|
2014-04-21 15:46:33 +04:00
|
|
|
|
* @return {boolean} true if the browser supports SVG, false otherwise
|
2014-04-04 13:32:07 +04:00
|
|
|
|
*/
|
|
|
|
|
// TODO: replace with original function
|
|
|
|
|
hasSVGSupport: SVGSupport,
|
|
|
|
|
/**
|
|
|
|
|
* If SVG is not supported, replaces the given icon's extension
|
|
|
|
|
* from ".svg" to ".png".
|
|
|
|
|
* If SVG is supported, return the image path as is.
|
2014-04-21 15:46:33 +04:00
|
|
|
|
* @param {string} file image path with svg extension
|
|
|
|
|
* @return {string} fixed image path with png extension if SVG is not supported
|
2014-04-04 13:32:07 +04:00
|
|
|
|
*/
|
|
|
|
|
replaceSVGIcon: function(file) {
|
2014-05-23 18:14:02 +04:00
|
|
|
|
if (file && !OC.Util.hasSVGSupport()) {
|
2014-04-04 13:32:07 +04:00
|
|
|
|
var i = file.lastIndexOf('.svg');
|
|
|
|
|
if (i >= 0) {
|
|
|
|
|
file = file.substr(0, i) + '.png' + file.substr(i+4);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return file;
|
|
|
|
|
},
|
|
|
|
|
/**
|
|
|
|
|
* Replace SVG images in all elements that have the "svg" class set
|
|
|
|
|
* with PNG images.
|
|
|
|
|
*
|
|
|
|
|
* @param $el root element from which to search, defaults to $('body')
|
|
|
|
|
*/
|
|
|
|
|
replaceSVG: function($el) {
|
|
|
|
|
if (!$el) {
|
|
|
|
|
$el = $('body');
|
|
|
|
|
}
|
|
|
|
|
$el.find('img.svg').each(function(index,element){
|
|
|
|
|
element=$(element);
|
|
|
|
|
var src=element.attr('src');
|
|
|
|
|
element.attr('src',src.substr(0, src.length-3) + 'png');
|
|
|
|
|
});
|
|
|
|
|
$el.find('.svg').each(function(index,element){
|
|
|
|
|
element = $(element);
|
|
|
|
|
var background = element.css('background-image');
|
|
|
|
|
if (background){
|
|
|
|
|
var i = background.lastIndexOf('.svg');
|
|
|
|
|
if (i >= 0){
|
|
|
|
|
background = background.substr(0,i) + '.png' + background.substr(i + 4);
|
|
|
|
|
element.css('background-image', background);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
element.find('*').each(function(index, element) {
|
|
|
|
|
element = $(element);
|
|
|
|
|
var background = element.css('background-image');
|
|
|
|
|
if (background) {
|
|
|
|
|
var i = background.lastIndexOf('.svg');
|
|
|
|
|
if(i >= 0){
|
|
|
|
|
background = background.substr(0,i) + '.png' + background.substr(i + 4);
|
|
|
|
|
element.css('background-image', background);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
2014-07-14 18:05:46 +04:00
|
|
|
|
},
|
|
|
|
|
|
2015-09-29 19:15:15 +03:00
|
|
|
|
/**
|
|
|
|
|
* Fix image scaling for IE8, since background-size is not supported.
|
|
|
|
|
*
|
|
|
|
|
* This scales the image to the element's actual size, the URL is
|
|
|
|
|
* taken from the "background-image" CSS attribute.
|
|
|
|
|
*
|
|
|
|
|
* @param {Object} $el image element
|
|
|
|
|
*/
|
|
|
|
|
scaleFixForIE8: function($el) {
|
|
|
|
|
if (!this.isIE8()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var self = this;
|
|
|
|
|
$($el).each(function() {
|
|
|
|
|
var url = $(this).css('background-image');
|
|
|
|
|
var r = url.match(/url\(['"]?([^'")]*)['"]?\)/);
|
|
|
|
|
if (!r) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
url = r[1];
|
|
|
|
|
url = self.replaceSVGIcon(url);
|
|
|
|
|
// TODO: escape
|
|
|
|
|
url = url.replace(/'/g, '%27');
|
|
|
|
|
$(this).css({
|
|
|
|
|
'filter': 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'' + url + '\', sizingMethod=\'scale\')',
|
|
|
|
|
'background-image': ''
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
return $el;
|
|
|
|
|
},
|
|
|
|
|
|
2015-10-21 11:50:06 +03:00
|
|
|
|
/**
|
|
|
|
|
* Returns whether this is IE
|
|
|
|
|
*
|
|
|
|
|
* @return {bool} true if this is IE, false otherwise
|
|
|
|
|
*/
|
|
|
|
|
isIE: function() {
|
|
|
|
|
return $('html').hasClass('ie');
|
|
|
|
|
},
|
|
|
|
|
|
2015-09-29 19:15:15 +03:00
|
|
|
|
/**
|
|
|
|
|
* Returns whether this is IE8
|
|
|
|
|
*
|
|
|
|
|
* @return {bool} true if this is IE8, false otherwise
|
|
|
|
|
*/
|
|
|
|
|
isIE8: function() {
|
|
|
|
|
return $('html').hasClass('ie8');
|
|
|
|
|
},
|
|
|
|
|
|
2015-10-02 19:02:55 +03:00
|
|
|
|
/**
|
|
|
|
|
* Returns the width of a generic browser scrollbar
|
|
|
|
|
*
|
|
|
|
|
* @return {int} width of scrollbar
|
|
|
|
|
*/
|
|
|
|
|
getScrollBarWidth: function() {
|
|
|
|
|
if (this._scrollBarWidth) {
|
|
|
|
|
return this._scrollBarWidth;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var inner = document.createElement('p');
|
|
|
|
|
inner.style.width = "100%";
|
|
|
|
|
inner.style.height = "200px";
|
|
|
|
|
|
|
|
|
|
var outer = document.createElement('div');
|
|
|
|
|
outer.style.position = "absolute";
|
|
|
|
|
outer.style.top = "0px";
|
|
|
|
|
outer.style.left = "0px";
|
|
|
|
|
outer.style.visibility = "hidden";
|
|
|
|
|
outer.style.width = "200px";
|
|
|
|
|
outer.style.height = "150px";
|
|
|
|
|
outer.style.overflow = "hidden";
|
|
|
|
|
outer.appendChild (inner);
|
|
|
|
|
|
|
|
|
|
document.body.appendChild (outer);
|
|
|
|
|
var w1 = inner.offsetWidth;
|
|
|
|
|
outer.style.overflow = 'scroll';
|
|
|
|
|
var w2 = inner.offsetWidth;
|
|
|
|
|
if(w1 === w2) {
|
|
|
|
|
w2 = outer.clientWidth;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
document.body.removeChild (outer);
|
|
|
|
|
|
|
|
|
|
this._scrollBarWidth = (w1 - w2);
|
|
|
|
|
|
|
|
|
|
return this._scrollBarWidth;
|
|
|
|
|
},
|
|
|
|
|
|
2014-07-14 18:05:46 +04:00
|
|
|
|
/**
|
|
|
|
|
* Remove the time component from a given date
|
|
|
|
|
*
|
|
|
|
|
* @param {Date} date date
|
|
|
|
|
* @return {Date} date with stripped time
|
|
|
|
|
*/
|
|
|
|
|
stripTime: function(date) {
|
|
|
|
|
// FIXME: likely to break when crossing DST
|
|
|
|
|
// would be better to use a library like momentJS
|
|
|
|
|
return new Date(date.getFullYear(), date.getMonth(), date.getDate());
|
2014-02-18 15:29:05 +04:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
_chunkify: function(t) {
|
|
|
|
|
// Adapted from http://my.opera.com/GreyWyvern/blog/show.dml/1671288
|
|
|
|
|
var tz = [], x = 0, y = -1, n = 0, code, c;
|
|
|
|
|
|
|
|
|
|
while (x < t.length) {
|
|
|
|
|
c = t.charAt(x);
|
2014-07-23 14:52:13 +04:00
|
|
|
|
// only include the dot in strings
|
|
|
|
|
var m = ((!n && c === '.') || (c >= '0' && c <= '9'));
|
2014-02-18 15:29:05 +04:00
|
|
|
|
if (m !== n) {
|
|
|
|
|
// next chunk
|
|
|
|
|
y++;
|
|
|
|
|
tz[y] = '';
|
|
|
|
|
n = m;
|
|
|
|
|
}
|
|
|
|
|
tz[y] += c;
|
|
|
|
|
x++;
|
|
|
|
|
}
|
|
|
|
|
return tz;
|
|
|
|
|
},
|
|
|
|
|
/**
|
|
|
|
|
* Compare two strings to provide a natural sort
|
|
|
|
|
* @param a first string to compare
|
|
|
|
|
* @param b second string to compare
|
|
|
|
|
* @return -1 if b comes before a, 1 if a comes before b
|
|
|
|
|
* or 0 if the strings are identical
|
|
|
|
|
*/
|
|
|
|
|
naturalSortCompare: function(a, b) {
|
2014-07-23 14:52:13 +04:00
|
|
|
|
var x;
|
2014-02-18 15:29:05 +04:00
|
|
|
|
var aa = OC.Util._chunkify(a);
|
|
|
|
|
var bb = OC.Util._chunkify(b);
|
|
|
|
|
|
|
|
|
|
for (x = 0; aa[x] && bb[x]; x++) {
|
|
|
|
|
if (aa[x] !== bb[x]) {
|
|
|
|
|
var aNum = Number(aa[x]), bNum = Number(bb[x]);
|
|
|
|
|
// note: == is correct here
|
|
|
|
|
if (aNum == aa[x] && bNum == bb[x]) {
|
|
|
|
|
return aNum - bNum;
|
|
|
|
|
} else {
|
|
|
|
|
// Forcing 'en' locale to match the server-side locale which is
|
|
|
|
|
// always 'en'.
|
|
|
|
|
//
|
|
|
|
|
// Note: This setting isn't supported by all browsers but for the ones
|
|
|
|
|
// that do there will be more consistency between client-server sorting
|
|
|
|
|
return aa[x].localeCompare(bb[x], 'en');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return aa.length - bb.length;
|
2015-07-07 16:16:37 +03:00
|
|
|
|
},
|
|
|
|
|
/**
|
|
|
|
|
* Calls the callback in a given interval until it returns true
|
|
|
|
|
* @param {function} callback
|
|
|
|
|
* @param {integer} interval in milliseconds
|
|
|
|
|
*/
|
|
|
|
|
waitFor: function(callback, interval) {
|
|
|
|
|
var internalCallback = function() {
|
|
|
|
|
if(callback() !== true) {
|
|
|
|
|
setTimeout(internalCallback, interval);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
internalCallback();
|
|
|
|
|
},
|
|
|
|
|
/**
|
|
|
|
|
* Checks if a cookie with the given name is present and is set to the provided value.
|
|
|
|
|
* @param {string} name name of the cookie
|
|
|
|
|
* @param {string} value value of the cookie
|
|
|
|
|
* @return {boolean} true if the cookie with the given name has the given value
|
|
|
|
|
*/
|
|
|
|
|
isCookieSetToValue: function(name, value) {
|
|
|
|
|
var cookies = document.cookie.split(';');
|
|
|
|
|
for (var i=0; i < cookies.length; i++) {
|
|
|
|
|
var cookie = cookies[i].split('=');
|
|
|
|
|
if (cookie[0].trim() === name && cookie[1].trim() === value) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
2014-04-04 13:32:07 +04:00
|
|
|
|
}
|
2015-07-07 16:16:37 +03:00
|
|
|
|
};
|
2014-04-04 13:32:07 +04:00
|
|
|
|
|
2014-05-09 00:06:30 +04:00
|
|
|
|
/**
|
|
|
|
|
* Utility class for the history API,
|
|
|
|
|
* includes fallback to using the URL hash when
|
|
|
|
|
* the browser doesn't support the history API.
|
2014-06-24 01:56:10 +04:00
|
|
|
|
*
|
|
|
|
|
* @namespace
|
2014-05-09 00:06:30 +04:00
|
|
|
|
*/
|
|
|
|
|
OC.Util.History = {
|
|
|
|
|
_handlers: [],
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Push the current URL parameters to the history stack
|
|
|
|
|
* and change the visible URL.
|
|
|
|
|
* Note: this includes a workaround for IE8/IE9 that uses
|
|
|
|
|
* the hash part instead of the search part.
|
|
|
|
|
*
|
|
|
|
|
* @param params to append to the URL, can be either a string
|
|
|
|
|
* or a map
|
|
|
|
|
*/
|
|
|
|
|
pushState: function(params) {
|
|
|
|
|
var strParams;
|
|
|
|
|
if (typeof(params) === 'string') {
|
|
|
|
|
strParams = params;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
strParams = OC.buildQueryString(params);
|
|
|
|
|
}
|
|
|
|
|
if (window.history.pushState) {
|
|
|
|
|
var url = location.pathname + '?' + strParams;
|
|
|
|
|
window.history.pushState(params, '', url);
|
|
|
|
|
}
|
|
|
|
|
// use URL hash for IE8
|
|
|
|
|
else {
|
|
|
|
|
window.location.hash = '?' + strParams;
|
|
|
|
|
// inhibit next onhashchange that just added itself
|
|
|
|
|
// to the event queue
|
|
|
|
|
this._cancelPop = true;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add a popstate handler
|
|
|
|
|
*
|
|
|
|
|
* @param handler function
|
|
|
|
|
*/
|
|
|
|
|
addOnPopStateHandler: function(handler) {
|
|
|
|
|
this._handlers.push(handler);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Parse a query string from the hash part of the URL.
|
|
|
|
|
* (workaround for IE8 / IE9)
|
|
|
|
|
*/
|
|
|
|
|
_parseHashQuery: function() {
|
|
|
|
|
var hash = window.location.hash,
|
|
|
|
|
pos = hash.indexOf('?');
|
|
|
|
|
if (pos >= 0) {
|
|
|
|
|
return hash.substr(pos + 1);
|
|
|
|
|
}
|
2014-06-25 14:37:11 +04:00
|
|
|
|
if (hash.length) {
|
|
|
|
|
// remove hash sign
|
|
|
|
|
return hash.substr(1);
|
|
|
|
|
}
|
2014-05-09 00:06:30 +04:00
|
|
|
|
return '';
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
_decodeQuery: function(query) {
|
|
|
|
|
return query.replace(/\+/g, ' ');
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Parse the query/search part of the URL.
|
|
|
|
|
* Also try and parse it from the URL hash (for IE8)
|
|
|
|
|
*
|
|
|
|
|
* @return map of parameters
|
|
|
|
|
*/
|
|
|
|
|
parseUrlQuery: function() {
|
|
|
|
|
var query = this._parseHashQuery(),
|
|
|
|
|
params;
|
|
|
|
|
// try and parse from URL hash first
|
|
|
|
|
if (query) {
|
|
|
|
|
params = OC.parseQueryString(this._decodeQuery(query));
|
|
|
|
|
}
|
|
|
|
|
// else read from query attributes
|
2015-09-28 19:37:40 +03:00
|
|
|
|
params = _.extend(params || {}, OC.parseQueryString(this._decodeQuery(location.search)));
|
2014-05-09 00:06:30 +04:00
|
|
|
|
return params || {};
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
_onPopState: function(e) {
|
|
|
|
|
if (this._cancelPop) {
|
|
|
|
|
this._cancelPop = false;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var params;
|
|
|
|
|
if (!this._handlers.length) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
params = (e && e.state) || this.parseUrlQuery() || {};
|
|
|
|
|
for (var i = 0; i < this._handlers.length; i++) {
|
|
|
|
|
this._handlers[i](params);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 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
|
|
|
|
};
|
2013-02-26 22:34:46 +04:00
|
|
|
|
|
2014-02-20 21:42:59 +04:00
|
|
|
|
// fix device width on windows phone
|
|
|
|
|
(function() {
|
|
|
|
|
if ("-ms-user-select" in document.documentElement.style && navigator.userAgent.match(/IEMobile\/10\.0/)) {
|
|
|
|
|
var msViewportStyle = document.createElement("style");
|
|
|
|
|
msViewportStyle.appendChild(
|
|
|
|
|
document.createTextNode("@-ms-viewport{width:auto!important}")
|
|
|
|
|
);
|
|
|
|
|
document.getElementsByTagName("head")[0].appendChild(msViewportStyle);
|
|
|
|
|
}
|
|
|
|
|
})();
|
|
|
|
|
|
2014-05-08 21:00:42 +04:00
|
|
|
|
/**
|
|
|
|
|
* Namespace for apps
|
2014-06-24 01:56:10 +04:00
|
|
|
|
* @namespace OCA
|
2014-05-08 21:00:42 +04:00
|
|
|
|
*/
|
|
|
|
|
window.OCA = {};
|
|
|
|
|
|
2013-05-13 17:54:45 +04:00
|
|
|
|
/**
|
|
|
|
|
* select a range in an input field
|
|
|
|
|
* @link http://stackoverflow.com/questions/499126/jquery-set-cursor-position-in-text-area
|
|
|
|
|
* @param {type} start
|
|
|
|
|
* @param {type} end
|
|
|
|
|
*/
|
2013-09-16 15:47:37 +04:00
|
|
|
|
jQuery.fn.selectRange = function(start, end) {
|
2013-05-13 17:54:45 +04:00
|
|
|
|
return this.each(function() {
|
|
|
|
|
if (this.setSelectionRange) {
|
|
|
|
|
this.focus();
|
|
|
|
|
this.setSelectionRange(start, end);
|
|
|
|
|
} else if (this.createTextRange) {
|
|
|
|
|
var range = this.createTextRange();
|
|
|
|
|
range.collapse(true);
|
|
|
|
|
range.moveEnd('character', end);
|
|
|
|
|
range.moveStart('character', start);
|
|
|
|
|
range.select();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
2013-02-26 22:34:46 +04:00
|
|
|
|
|
2013-09-16 15:47:37 +04:00
|
|
|
|
/**
|
|
|
|
|
* check if an element exists.
|
|
|
|
|
* allows you to write if ($('#myid').exists()) to increase readability
|
|
|
|
|
* @link http://stackoverflow.com/questions/31044/is-there-an-exists-function-for-jquery
|
|
|
|
|
*/
|
|
|
|
|
jQuery.fn.exists = function(){
|
|
|
|
|
return this.length > 0;
|
2013-10-22 20:11:03 +04:00
|
|
|
|
};
|
2015-03-27 03:34:55 +03:00
|
|
|
|
|
2015-10-02 19:02:55 +03:00
|
|
|
|
/**
|
|
|
|
|
* @deprecated use OC.Util.getScrollBarWidth() instead
|
|
|
|
|
*/
|
2015-03-27 03:34:55 +03:00
|
|
|
|
function getScrollBarWidth() {
|
2015-10-02 19:02:55 +03:00
|
|
|
|
return OC.Util.getScrollBarWidth();
|
2015-03-27 11:37:52 +03:00
|
|
|
|
}
|
2015-06-22 13:48:04 +03:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* jQuery tipsy shim for the bootstrap tooltip
|
|
|
|
|
*/
|
|
|
|
|
jQuery.fn.tipsy = function(argument) {
|
|
|
|
|
console.warn('Deprecation warning: tipsy is deprecated. Use tooltip instead.');
|
|
|
|
|
if(typeof argument === 'object' && argument !== null) {
|
|
|
|
|
|
|
|
|
|
// tipsy defaults
|
|
|
|
|
var options = {
|
|
|
|
|
placement: 'bottom',
|
|
|
|
|
delay: { 'show': 0, 'hide': 0},
|
|
|
|
|
trigger: 'hover',
|
2015-10-27 13:22:41 +03:00
|
|
|
|
html: false,
|
|
|
|
|
container: 'body'
|
2015-06-22 13:48:04 +03:00
|
|
|
|
};
|
|
|
|
|
if(argument.gravity) {
|
|
|
|
|
switch(argument.gravity) {
|
|
|
|
|
case 'n':
|
|
|
|
|
case 'nw':
|
|
|
|
|
case 'ne':
|
|
|
|
|
options.placement='bottom';
|
|
|
|
|
break;
|
|
|
|
|
case 's':
|
|
|
|
|
case 'sw':
|
|
|
|
|
case 'se':
|
|
|
|
|
options.placement='top';
|
|
|
|
|
break;
|
|
|
|
|
case 'w':
|
|
|
|
|
options.placement='right';
|
|
|
|
|
break;
|
|
|
|
|
case 'e':
|
|
|
|
|
options.placement='left';
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(argument.trigger) {
|
|
|
|
|
options.trigger = argument.trigger;
|
|
|
|
|
}
|
|
|
|
|
if(argument.delayIn) {
|
|
|
|
|
options.delay["show"] = argument.delayIn;
|
|
|
|
|
}
|
|
|
|
|
if(argument.delayOut) {
|
|
|
|
|
options.delay["hide"] = argument.delayOut;
|
|
|
|
|
}
|
|
|
|
|
if(argument.html) {
|
|
|
|
|
options.html = true;
|
|
|
|
|
}
|
2015-07-26 18:09:28 +03:00
|
|
|
|
if(argument.fallback) {
|
2015-07-25 23:10:21 +03:00
|
|
|
|
options.title = argument.fallback;
|
2015-06-22 13:48:04 +03:00
|
|
|
|
}
|
2015-07-08 11:53:17 +03:00
|
|
|
|
// destroy old tooltip in case the title has changed
|
|
|
|
|
jQuery.fn.tooltip.call(this, 'destroy');
|
2015-06-22 13:48:04 +03:00
|
|
|
|
jQuery.fn.tooltip.call(this, options);
|
2015-07-08 11:53:17 +03:00
|
|
|
|
} else {
|
|
|
|
|
this.tooltip(argument);
|
|
|
|
|
jQuery.fn.tooltip.call(this, argument);
|
2015-06-22 13:48:04 +03:00
|
|
|
|
}
|
2015-09-23 00:31:50 +03:00
|
|
|
|
return this;
|
2015-06-22 13:48:04 +03:00
|
|
|
|
}
|