2011-08-07 01:18:49 +04:00
|
|
|
/**
|
|
|
|
* translate a string
|
|
|
|
* @param app the id of the app for which to translate the string
|
|
|
|
* @param text the string to translate
|
|
|
|
* @return string
|
|
|
|
*/
|
2012-09-04 23:27:04 +04:00
|
|
|
|
2012-10-05 05:33:46 +04:00
|
|
|
function t(app,text, vars){
|
2012-09-23 05:16:52 +04:00
|
|
|
if( !( t.cache[app] )){
|
2012-01-16 03:09:43 +04:00
|
|
|
$.ajax(OC.filePath('core','ajax','translations.php'),{
|
|
|
|
async:false,//todo a proper sollution for this without sync ajax calls
|
|
|
|
data:{'app': app},
|
|
|
|
type:'POST',
|
|
|
|
success:function(jsondata){
|
|
|
|
t.cache[app] = jsondata.data;
|
2012-09-23 05:16:52 +04:00
|
|
|
}
|
2012-02-22 01:31:35 +04:00
|
|
|
});
|
2011-06-20 01:33:34 +04:00
|
|
|
|
|
|
|
// Bad answer ...
|
2012-09-23 05:16:52 +04:00
|
|
|
if( !( t.cache[app] )){
|
2011-07-27 18:39:44 +04:00
|
|
|
t.cache[app] = [];
|
2011-06-20 01:33:34 +04:00
|
|
|
}
|
2011-05-18 00:34:31 +04:00
|
|
|
}
|
2012-10-05 05:33:46 +04:00
|
|
|
var _build = function(text, vars) {
|
|
|
|
return text.replace(/{([^{}]*)}/g,
|
|
|
|
function (a, b) {
|
|
|
|
var r = vars[b];
|
|
|
|
return typeof r === 'string' || typeof r === 'number' ? r : a;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2011-07-27 18:39:44 +04:00
|
|
|
if( typeof( t.cache[app][text] ) !== 'undefined' ){
|
2012-10-05 05:33:46 +04:00
|
|
|
if(typeof vars === 'object') {
|
|
|
|
return _build(t.cache[app][text], vars);
|
|
|
|
} else {
|
|
|
|
return t.cache[app][text];
|
|
|
|
}
|
2011-05-19 23:19:37 +04:00
|
|
|
}
|
2011-06-20 01:33:34 +04:00
|
|
|
else{
|
2012-10-05 05:33:46 +04:00
|
|
|
if(typeof vars === 'object') {
|
|
|
|
return _build(text, vars);
|
|
|
|
} else {
|
|
|
|
return text;
|
|
|
|
}
|
2011-06-20 01:33:34 +04:00
|
|
|
}
|
|
|
|
}
|
2011-07-27 18:39:44 +04:00
|
|
|
t.cache={};
|
2011-06-20 01:33:34 +04:00
|
|
|
|
2012-10-12 16:01:47 +04:00
|
|
|
/*
|
|
|
|
* Sanitizes a HTML string
|
|
|
|
* @param string
|
|
|
|
* @return Sanitized string
|
|
|
|
*/
|
|
|
|
function escapeHTML(s) {
|
|
|
|
return s.toString().split('&').join('&').split('<').join('<').split('"').join('"');
|
|
|
|
}
|
|
|
|
|
2012-08-27 23:46:05 +04:00
|
|
|
/**
|
|
|
|
* Get the path to download a file
|
|
|
|
* @param file The filename
|
|
|
|
* @param dir The directory the file is in - e.g. $('#dir').val()
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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,
|
2011-07-26 00:30:55 +04:00
|
|
|
webroot:oc_webroot,
|
2012-06-06 23:54:57 +04:00
|
|
|
appswebroots:oc_appswebroots,
|
2011-08-11 18:53:00 +04:00
|
|
|
currentUser:(typeof oc_current_user!=='undefined')?oc_current_user:false,
|
2012-05-07 17:39:17 +04:00
|
|
|
coreApps:['', 'admin','log','search','settings','core','3rdparty'],
|
2011-08-07 01:18:49 +04:00
|
|
|
/**
|
|
|
|
* get an absolute url to a file in an appen
|
|
|
|
* @param app the id of the app the file belongs to
|
|
|
|
* @param file the file path relative to the app folder
|
|
|
|
* @return string
|
|
|
|
*/
|
2011-07-26 00:30:55 +04:00
|
|
|
linkTo:function(app,file){
|
|
|
|
return OC.filePath(app,'',file);
|
|
|
|
},
|
2011-08-07 01:18:49 +04:00
|
|
|
/**
|
|
|
|
* get the absolute url for a file in an app
|
|
|
|
* @param app the id of the app
|
|
|
|
* @param type the type of the file to link to (e.g. css,img,ajax.template)
|
|
|
|
* @param file the filename
|
|
|
|
* @return string
|
|
|
|
*/
|
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;
|
|
|
|
if((file.substring(file.length-3) === 'php' || file.substring(file.length-3) === 'css') && !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-02 23:57:51 +04:00
|
|
|
if ((app == 'settings' || app == 'core') && 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;
|
|
|
|
},
|
2011-08-07 01:18:49 +04:00
|
|
|
/**
|
|
|
|
* get the absolute path to an image file
|
|
|
|
* @param app the app id to which the image belongs
|
|
|
|
* @param file the name of the image file
|
|
|
|
* @return string
|
2012-07-31 14:21:06 +04:00
|
|
|
*
|
2012-04-15 15:32:45 +04:00
|
|
|
* if no extension is given for the image, it will automatically decide between .png and .svg based on what the browser supports
|
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
|
2012-02-22 01:31:35 +04:00
|
|
|
file+=(SVGSupport())?'.svg':'.png';
|
2011-07-28 06:28:04 +04:00
|
|
|
}
|
2011-07-26 00:30:55 +04:00
|
|
|
return OC.filePath(app,'img',file);
|
|
|
|
},
|
2011-08-07 01:18:49 +04:00
|
|
|
/**
|
|
|
|
* load a script for the server and load it
|
|
|
|
* @param app the app id to which the script belongs
|
|
|
|
* @param script the filename of the script
|
|
|
|
* @param ready event handeler to be called when the script is loaded
|
2012-07-31 14:21:06 +04:00
|
|
|
*
|
2011-08-07 01:18:49 +04:00
|
|
|
* if the script is already loaded, the event handeler will be called directly
|
|
|
|
*/
|
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
|
|
|
/**
|
|
|
|
* load a css file and load it
|
|
|
|
* @param app the app id to which the css style belongs
|
|
|
|
* @param style the filename of the css file
|
|
|
|
*/
|
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);
|
2012-09-23 05:16:52 +04:00
|
|
|
style=$('<link rel="stylesheet" type="text/css" href="'+path+'"/>');
|
2011-07-30 20:05:20 +04:00
|
|
|
$('head').append(style);
|
|
|
|
}
|
|
|
|
},
|
2012-09-09 01:56:37 +04:00
|
|
|
basename: function(path) {
|
|
|
|
return path.replace(/\\/g,'/').replace( /.*\//, '' );
|
|
|
|
},
|
|
|
|
dirname: function(path) {
|
2012-09-23 05:16:52 +04:00
|
|
|
return path.replace(/\\/g,'/').replace(/\/[^\/]*$/, '');
|
2012-09-09 02:35:02 +04:00
|
|
|
},
|
2011-08-07 01:18:49 +04:00
|
|
|
/**
|
|
|
|
* do a search query and display the results
|
|
|
|
* @param query the search query
|
|
|
|
*/
|
2011-07-30 20:05:20 +04:00
|
|
|
search:function(query){
|
|
|
|
if(query){
|
2011-07-31 06:03:48 +04:00
|
|
|
OC.addStyle('search','results');
|
|
|
|
$.getJSON(OC.filePath('search','ajax','search.php')+'?query='+encodeURIComponent(query), function(results){
|
|
|
|
OC.search.lastResults=results;
|
|
|
|
OC.search.showResults(results);
|
2011-07-30 23:18:54 +04:00
|
|
|
});
|
2011-07-30 20:05:20 +04:00
|
|
|
}
|
2012-02-29 02:02:02 +04:00
|
|
|
},
|
2012-04-02 21:39:24 +04:00
|
|
|
dialogs:OCdialogs,
|
2012-07-31 16:06:44 +04:00
|
|
|
mtime2date:function(mtime) {
|
2012-09-23 05:16:52 +04:00
|
|
|
mtime = parseInt(mtime,10);
|
2012-07-31 16:06:44 +04:00
|
|
|
var date = new Date(1000*mtime);
|
2012-09-23 05:16:52 +04:00
|
|
|
return date.getDate()+'.'+(date.getMonth()+1)+'.'+date.getFullYear()+', '+date.getHours()+':'+date.getMinutes();
|
2012-07-31 16:06:44 +04:00
|
|
|
},
|
2012-07-31 18:03:08 +04:00
|
|
|
/**
|
|
|
|
* Opens a popup with the setting for an app.
|
|
|
|
* @param appid String. The ID of the app e.g. 'calendar', 'contacts' or 'files'.
|
|
|
|
* @param loadJS boolean or String. If true 'js/settings.js' is loaded. If it's a string
|
|
|
|
* it will attempt to load a script by that name in the 'js' directory.
|
|
|
|
* @param cache boolean. If true the javascript file won't be forced refreshed. Defaults to true.
|
|
|
|
* @param scriptName String. The name of the PHP file to load. Defaults to 'settings.php' in
|
|
|
|
* 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');
|
2012-07-31 18:03:08 +04:00
|
|
|
if(settings.length == 0) {
|
|
|
|
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');
|
|
|
|
if(popup.length == 0) {
|
|
|
|
$('body').prepend('<div class="popup hidden" id="appsettings_popup"></div>');
|
|
|
|
popup = $('#appsettings_popup');
|
|
|
|
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;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}).show();
|
|
|
|
}, 'html');
|
2012-07-31 14:21:06 +04:00
|
|
|
}
|
|
|
|
}
|
2012-02-22 01:31:35 +04:00
|
|
|
};
|
2011-07-31 02:50:04 +04:00
|
|
|
OC.search.customResults={};
|
2011-07-31 06:03:48 +04:00
|
|
|
OC.search.currentResult=-1;
|
|
|
|
OC.search.lastQuery='';
|
|
|
|
OC.search.lastResults={};
|
2011-07-30 20:05:20 +04:00
|
|
|
OC.addStyle.loaded=[];
|
|
|
|
OC.addScript.loaded=[];
|
|
|
|
|
2012-09-09 04:58:16 +04:00
|
|
|
OC.Breadcrumb={
|
|
|
|
container:null,
|
|
|
|
crumbs:[],
|
|
|
|
push:function(name, link){
|
|
|
|
if(!OC.Breadcrumb.container){//default
|
|
|
|
OC.Breadcrumb.container=$('#controls');
|
|
|
|
}
|
|
|
|
var crumb=$('<div/>');
|
|
|
|
crumb.addClass('crumb').addClass('last');
|
|
|
|
crumb.attr('style','background-image:url("'+OC.imagePath('core','breadcrumb')+'")');
|
|
|
|
|
|
|
|
var crumbLink=$('<a/>');
|
|
|
|
crumbLink.attr('href',link);
|
|
|
|
crumbLink.text(name);
|
|
|
|
crumb.append(crumbLink);
|
|
|
|
|
|
|
|
var existing=OC.Breadcrumb.container.find('div.crumb');
|
|
|
|
if(existing.length){
|
|
|
|
existing.removeClass('last');
|
|
|
|
existing.last().after(crumb);
|
|
|
|
}else{
|
|
|
|
OC.Breadcrumb.container.append(crumb);
|
|
|
|
}
|
|
|
|
OC.Breadcrumb.crumbs.push(crumb);
|
|
|
|
return crumb;
|
|
|
|
},
|
|
|
|
pop:function(){
|
|
|
|
if(!OC.Breadcrumb.container){//default
|
|
|
|
OC.Breadcrumb.container=$('#controls');
|
|
|
|
}
|
|
|
|
OC.Breadcrumb.container.find('div.crumb').last().remove();
|
|
|
|
OC.Breadcrumb.container.find('div.crumb').last().addClass('last');
|
|
|
|
OC.Breadcrumb.crumbs.pop();
|
|
|
|
},
|
|
|
|
clear:function(){
|
|
|
|
if(!OC.Breadcrumb.container){//default
|
|
|
|
OC.Breadcrumb.container=$('#controls');
|
|
|
|
}
|
|
|
|
OC.Breadcrumb.container.find('div.crumb').remove();
|
|
|
|
OC.Breadcrumb.crumbs=[];
|
|
|
|
}
|
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){
|
|
|
|
//user and instance aware localstorage
|
2012-01-15 22:11:25 +04:00
|
|
|
OC.localStorage={
|
|
|
|
namespace:'oc_'+OC.currentUser+'_'+OC.webroot+'_',
|
|
|
|
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
|
|
|
},
|
|
|
|
setItem:function(name,item){
|
|
|
|
return localStorage.setItem(OC.localStorage.namespace+name,JSON.stringify(item));
|
|
|
|
},
|
|
|
|
getItem:function(name){
|
2012-09-23 05:16:52 +04:00
|
|
|
if(localStorage.getItem(OC.localStorage.namespace+name)===null){return null;}
|
2012-01-15 22:11:25 +04:00
|
|
|
return JSON.parse(localStorage.getItem(OC.localStorage.namespace+name));
|
|
|
|
}
|
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
|
|
|
/**
|
|
|
|
* implement Array.filter for browsers without native support
|
|
|
|
*/
|
2011-07-26 18:43:12 +04:00
|
|
|
if (!Array.prototype.filter) {
|
|
|
|
Array.prototype.filter = function(fun /*, thisp*/) {
|
|
|
|
var len = this.length >>> 0;
|
2012-09-23 05:16:52 +04:00
|
|
|
if (typeof fun !== "function"){
|
2011-07-26 18:43:12 +04:00
|
|
|
throw new TypeError();
|
2012-09-23 05:16:52 +04:00
|
|
|
}
|
2012-07-31 14:21:06 +04:00
|
|
|
|
2011-07-26 18:43:12 +04:00
|
|
|
var res = [];
|
|
|
|
var thisp = arguments[1];
|
|
|
|
for (var i = 0; i < len; i++) {
|
|
|
|
if (i in this) {
|
|
|
|
var val = this[i]; // in case fun mutates this
|
|
|
|
if (fun.call(thisp, val, i, this))
|
|
|
|
res.push(val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return res;
|
2012-02-22 01:31:35 +04:00
|
|
|
};
|
2011-07-27 18:57:49 +04:00
|
|
|
}
|
2011-08-07 01:18:49 +04:00
|
|
|
/**
|
|
|
|
* implement Array.indexOf for browsers without native support
|
|
|
|
*/
|
2011-07-27 18:39:44 +04:00
|
|
|
if (!Array.prototype.indexOf){
|
|
|
|
Array.prototype.indexOf = function(elt /*, from*/)
|
|
|
|
{
|
|
|
|
var len = this.length;
|
2012-07-31 14:21:06 +04:00
|
|
|
|
2011-07-27 18:39:44 +04:00
|
|
|
var from = Number(arguments[1]) || 0;
|
2012-09-23 05:16:52 +04:00
|
|
|
from = (from < 0) ? Math.ceil(from) : Math.floor(from);
|
|
|
|
if (from < 0){
|
2011-07-27 18:39:44 +04:00
|
|
|
from += len;
|
2012-09-23 05:16:52 +04:00
|
|
|
}
|
2012-07-31 14:21:06 +04:00
|
|
|
|
2011-07-27 18:39:44 +04:00
|
|
|
for (; from < len; from++)
|
|
|
|
{
|
2012-09-23 05:16:52 +04:00
|
|
|
if (from in this && this[from] === elt){
|
2011-07-27 18:39:44 +04:00
|
|
|
return from;
|
2012-09-23 05:16:52 +04:00
|
|
|
}
|
2011-07-27 18:39:44 +04:00
|
|
|
}
|
|
|
|
return -1;
|
2011-07-26 18:43:12 +04:00
|
|
|
};
|
2011-07-28 06:28:04 +04:00
|
|
|
}
|
|
|
|
|
2011-08-07 01:18:49 +04:00
|
|
|
/**
|
|
|
|
* check if the browser support svg images
|
|
|
|
*/
|
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);
|
|
|
|
}
|
|
|
|
headers[parts[0]]=value;
|
2011-08-22 17:20:24 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2012-09-23 05:16:52 +04:00
|
|
|
if(headers["Content-Type"]!=='image/svg+xml'){
|
2011-08-22 17:20:24 +04:00
|
|
|
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
|
|
|
|
2011-08-22 16:53:52 +04:00
|
|
|
//replace all svg images with png for browser compatibility
|
|
|
|
function replaceSVG(){
|
|
|
|
$('img.svg').each(function(index,element){
|
|
|
|
element=$(element);
|
|
|
|
var src=element.attr('src');
|
|
|
|
element.attr('src',src.substr(0,src.length-3)+'png');
|
|
|
|
});
|
|
|
|
$('.svg').each(function(index,element){
|
|
|
|
element=$(element);
|
|
|
|
var background=element.css('background-image');
|
2012-02-26 06:10:01 +04:00
|
|
|
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);
|
|
|
|
}
|
2011-08-22 16:53:52 +04:00
|
|
|
}
|
|
|
|
element.find('*').each(function(index,element) {
|
|
|
|
element=$(element);
|
|
|
|
var background=element.css('background-image');
|
2012-02-26 06:10:01 +04:00
|
|
|
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);
|
|
|
|
}
|
2011-08-22 16:53:52 +04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2011-08-07 01:18:49 +04:00
|
|
|
/**
|
|
|
|
* prototypal inharitence functions
|
2012-07-31 14:21:06 +04:00
|
|
|
*
|
2011-08-07 01:18:49 +04:00
|
|
|
* usage:
|
|
|
|
* MySubObject=object(MyObject)
|
|
|
|
*/
|
|
|
|
function object(o) {
|
|
|
|
function F() {}
|
|
|
|
F.prototype = o;
|
|
|
|
return new F();
|
|
|
|
}
|
|
|
|
|
2011-10-04 20:54:07 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Fills height of window. (more precise than height: 100%;)
|
|
|
|
*/
|
|
|
|
function fillHeight(selector) {
|
2012-09-23 05:16:52 +04:00
|
|
|
if (selector.length === 0) {
|
2012-04-14 20:15:21 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
var height = parseFloat($(window).height())-selector.offset().top;
|
2011-10-04 20:54:07 +04:00
|
|
|
selector.css('height', height + 'px');
|
2012-09-23 05:16:52 +04:00
|
|
|
if(selector.outerHeight() > selector.height()){
|
2011-10-04 20:54:07 +04:00
|
|
|
selector.css('height', height-(selector.outerHeight()-selector.height()) + 'px');
|
2012-09-23 05:16:52 +04:00
|
|
|
}
|
2011-10-04 20:54:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fills height and width of window. (more precise than height: 100%; or width: 100%;)
|
|
|
|
*/
|
|
|
|
function fillWindow(selector) {
|
2012-09-23 05:16:52 +04:00
|
|
|
if (selector.length === 0) {
|
2012-04-14 20:15:21 +04:00
|
|
|
return;
|
|
|
|
}
|
2011-10-04 20:54:07 +04:00
|
|
|
fillHeight(selector);
|
2012-04-14 20:15:21 +04:00
|
|
|
var width = parseFloat($(window).width())-selector.offset().left;
|
2011-10-04 20:54:07 +04:00
|
|
|
selector.css('width', width + 'px');
|
2012-09-23 05:16:52 +04:00
|
|
|
if(selector.outerWidth() > selector.width()){
|
2011-10-04 20:54:07 +04:00
|
|
|
selector.css('width', width-(selector.outerWidth()-selector.width()) + 'px');
|
2012-09-23 05:16:52 +04:00
|
|
|
}
|
2011-10-04 20:54:07 +04:00
|
|
|
}
|
|
|
|
|
2011-07-29 18:52:09 +04:00
|
|
|
$(document).ready(function(){
|
2011-10-04 20:54:07 +04:00
|
|
|
|
|
|
|
$(window).resize(function () {
|
|
|
|
fillHeight($('#leftcontent'));
|
2012-02-22 01:31:35 +04:00
|
|
|
fillWindow($('#content'));
|
2011-10-04 20:54:07 +04:00
|
|
|
fillWindow($('#rightcontent'));
|
|
|
|
});
|
|
|
|
$(window).trigger('resize');
|
2012-07-31 14:21:06 +04:00
|
|
|
|
2012-02-22 01:31:35 +04:00
|
|
|
if(!SVGSupport()){ //replace all svg images with png images for browser that dont support svg
|
2011-08-22 16:53:52 +04:00
|
|
|
replaceSVG();
|
2011-08-22 17:20:24 +04:00
|
|
|
}else{
|
|
|
|
SVGSupport.checkMimeType();
|
|
|
|
}
|
2011-07-31 06:03:48 +04:00
|
|
|
$('form.searchbox').submit(function(event){
|
|
|
|
event.preventDefault();
|
2011-10-03 16:41:55 +04:00
|
|
|
});
|
2011-07-31 06:03:48 +04:00
|
|
|
$('#searchbox').keyup(function(event){
|
2012-09-23 05:16:52 +04:00
|
|
|
if(event.keyCode===13){//enter
|
2011-07-31 06:03:48 +04:00
|
|
|
if(OC.search.currentResult>-1){
|
|
|
|
var result=$('#searchresults tr.result a')[OC.search.currentResult];
|
2011-08-28 00:36:15 +04:00
|
|
|
window.location = $(result).attr('href');
|
2011-07-31 06:03:48 +04:00
|
|
|
}
|
2012-09-23 05:16:52 +04:00
|
|
|
}else if(event.keyCode===38){//up
|
2011-07-31 06:03:48 +04:00
|
|
|
if(OC.search.currentResult>0){
|
|
|
|
OC.search.currentResult--;
|
|
|
|
OC.search.renderCurrent();
|
|
|
|
}
|
2012-09-23 05:16:52 +04:00
|
|
|
}else if(event.keyCode===40){//down
|
2011-07-31 06:03:48 +04:00
|
|
|
if(OC.search.lastResults.length>OC.search.currentResult+1){
|
|
|
|
OC.search.currentResult++;
|
|
|
|
OC.search.renderCurrent();
|
|
|
|
}
|
2012-09-23 05:16:52 +04:00
|
|
|
}else if(event.keyCode===27){//esc
|
2011-07-31 06:03:48 +04:00
|
|
|
OC.search.hide();
|
2011-07-30 20:05:20 +04:00
|
|
|
}else{
|
2011-07-31 06:03:48 +04:00
|
|
|
var query=$('#searchbox').val();
|
2012-09-23 05:16:52 +04:00
|
|
|
if(OC.search.lastQuery!==query){
|
2011-07-31 06:03:48 +04:00
|
|
|
OC.search.lastQuery=query;
|
|
|
|
OC.search.currentResult=-1;
|
|
|
|
if(query.length>2){
|
|
|
|
OC.search(query);
|
|
|
|
}else{
|
|
|
|
if(OC.search.hide){
|
|
|
|
OC.search.hide();
|
|
|
|
}
|
|
|
|
}
|
2011-07-30 23:18:54 +04:00
|
|
|
}
|
2011-07-30 20:05:20 +04:00
|
|
|
}
|
|
|
|
});
|
2011-08-08 13:45:01 +04:00
|
|
|
|
2012-07-31 14:21:06 +04:00
|
|
|
// 'show password' checkbox
|
2011-08-08 13:07:44 +04:00
|
|
|
$('#pass2').showPassword();
|
2011-08-08 13:45:01 +04:00
|
|
|
|
2011-10-03 16:41:55 +04:00
|
|
|
//use infield labels
|
|
|
|
$("label.infield").inFieldLabels();
|
|
|
|
|
2012-09-23 05:16:52 +04:00
|
|
|
var checkShowCredentials = function() {
|
2011-08-08 13:45:01 +04:00
|
|
|
var empty = false;
|
2012-05-17 03:17:44 +04:00
|
|
|
$('input#user, input#password').each(function() {
|
2012-09-23 05:16:52 +04:00
|
|
|
if ($(this).val() === '') {
|
2011-08-08 13:45:01 +04:00
|
|
|
empty = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if(empty) {
|
|
|
|
$('#submit').fadeOut();
|
2011-10-03 16:41:55 +04:00
|
|
|
$('#remember_login').hide();
|
2011-08-08 13:45:01 +04:00
|
|
|
$('#remember_login+label').fadeOut();
|
|
|
|
} else {
|
|
|
|
$('#submit').fadeIn();
|
2011-10-03 16:41:55 +04:00
|
|
|
$('#remember_login').show();
|
2011-08-08 13:45:01 +04:00
|
|
|
$('#remember_login+label').fadeIn();
|
|
|
|
}
|
2012-09-23 05:16:52 +04:00
|
|
|
};
|
2012-08-03 15:15:15 +04:00
|
|
|
// hide log in button etc. when form fields not filled
|
2012-08-25 02:05:07 +04:00
|
|
|
// commented out due to some browsers having issues with it
|
2012-08-17 00:42:51 +04:00
|
|
|
// checkShowCredentials();
|
|
|
|
// $('input#user, input#password').keyup(checkShowCredentials);
|
2011-08-09 01:31:58 +04:00
|
|
|
|
2012-05-04 11:53:36 +04:00
|
|
|
$('#settings #expand').keydown(function(event) {
|
2012-09-23 05:16:52 +04:00
|
|
|
if (event.which === 13 || event.which === 32) {
|
2012-05-04 11:53:36 +04:00
|
|
|
$('#expand').click()
|
|
|
|
}
|
|
|
|
});
|
2011-08-13 00:18:38 +04:00
|
|
|
$('#settings #expand').click(function(event) {
|
2011-08-10 19:29:26 +04:00
|
|
|
$('#settings #expanddiv').slideToggle();
|
2011-08-13 00:18:38 +04:00
|
|
|
event.stopPropagation();
|
2011-08-09 01:31:58 +04:00
|
|
|
});
|
2011-08-13 00:18:38 +04:00
|
|
|
$('#settings #expanddiv').click(function(event){
|
|
|
|
event.stopPropagation();
|
2011-10-03 16:41:55 +04:00
|
|
|
});
|
2012-09-23 05:16:52 +04:00
|
|
|
$(window).click(function(){//hide the settings menu when clicking outside it
|
|
|
|
if($('body').attr("id")==="body-user"){
|
2011-08-13 00:18:38 +04:00
|
|
|
$('#settings #expanddiv').slideUp();
|
|
|
|
}
|
|
|
|
});
|
2011-08-14 16:55:43 +04:00
|
|
|
|
2011-08-14 18:12:27 +04:00
|
|
|
// all the tipsy stuff needs to be here (in reverse order) to work
|
|
|
|
$('.jp-controls .jp-previous').tipsy({gravity:'nw', fade:true, live:true});
|
|
|
|
$('.jp-controls .jp-next').tipsy({gravity:'n', fade:true, live:true});
|
2011-08-16 01:45:25 +04:00
|
|
|
$('.password .action').tipsy({gravity:'se', fade:true, live:true});
|
2012-04-13 19:22:23 +04:00
|
|
|
$('.file_upload_button_wrapper').tipsy({gravity:'w', fade:true});
|
2011-08-28 10:46:38 +04:00
|
|
|
$('.selectedActions a').tipsy({gravity:'s', fade:true, live:true});
|
2012-04-15 19:40:58 +04:00
|
|
|
$('a.delete').tipsy({gravity: 'e', fade:true, live:true});
|
2012-04-13 20:28:17 +04:00
|
|
|
$('a.action').tipsy({gravity:'s', fade:true, live:true});
|
2011-08-28 10:46:38 +04:00
|
|
|
$('#headerSize').tipsy({gravity:'s', fade:true, live:true});
|
2011-08-14 18:12:27 +04:00
|
|
|
$('td.filesize').tipsy({gravity:'s', fade:true, live:true});
|
|
|
|
$('td .modified').tipsy({gravity:'s', fade:true, live:true});
|
|
|
|
|
|
|
|
$('input').tipsy({gravity:'w', fade:true});
|
|
|
|
$('input[type=text]').focus(function(){
|
|
|
|
this.select();
|
2011-08-14 16:55:43 +04:00
|
|
|
});
|
2011-07-29 18:52:09 +04:00
|
|
|
});
|
2011-08-08 13:07:44 +04:00
|
|
|
|
2011-08-10 22:51:35 +04:00
|
|
|
if (!Array.prototype.map){
|
|
|
|
Array.prototype.map = function(fun /*, thisp */){
|
|
|
|
"use strict";
|
2012-07-31 14:21:06 +04:00
|
|
|
|
2012-09-23 05:16:52 +04:00
|
|
|
if (this === void 0 || this === null){
|
2011-08-10 22:51:35 +04:00
|
|
|
throw new TypeError();
|
2012-09-23 05:16:52 +04:00
|
|
|
}
|
2012-07-31 14:21:06 +04:00
|
|
|
|
2011-08-10 22:51:35 +04:00
|
|
|
var t = Object(this);
|
|
|
|
var len = t.length >>> 0;
|
2012-09-23 05:16:52 +04:00
|
|
|
if (typeof fun !== "function"){
|
2011-08-10 22:51:35 +04:00
|
|
|
throw new TypeError();
|
2012-09-23 05:16:52 +04:00
|
|
|
}
|
2012-07-31 14:21:06 +04:00
|
|
|
|
2011-08-10 22:51:35 +04:00
|
|
|
var res = new Array(len);
|
|
|
|
var thisp = arguments[1];
|
|
|
|
for (var i = 0; i < len; i++){
|
|
|
|
if (i in t){
|
|
|
|
res[i] = fun.call(thisp, t[i], i, t);
|
|
|
|
}
|
|
|
|
}
|
2012-07-31 14:21:06 +04:00
|
|
|
|
2012-08-25 02:05:07 +04:00
|
|
|
return res;
|
2011-08-10 22:51:35 +04:00
|
|
|
};
|
|
|
|
}
|
2011-11-02 01:35:13 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Filter Jquery selector by attribute value
|
|
|
|
**/
|
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
|
|
|
|
2012-02-26 17:03:53 +04:00
|
|
|
function humanFileSize(size) {
|
2012-09-23 05:16:52 +04:00
|
|
|
var humanList = ['B', 'kB', 'MB', 'GB', 'TB'];
|
2012-02-26 17:03:53 +04:00
|
|
|
// Calculate Log with base 1024: size = 1024 ** order
|
2012-09-23 05:16:52 +04:00
|
|
|
var order = Math.floor(Math.log(size) / Math.log(1024));
|
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);
|
2012-02-26 17:03:53 +04:00
|
|
|
if(relativeSize.substr(relativeSize.length-2,2)=='.0'){
|
|
|
|
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
|
|
|
|
2012-02-26 00:19:32 +04:00
|
|
|
function simpleFileSize(bytes) {
|
2012-09-23 05:16:52 +04:00
|
|
|
var mbytes = Math.round(bytes/(1024*1024/10))/10;
|
2012-02-26 00:19:32 +04:00
|
|
|
if(bytes == 0) { return '0'; }
|
|
|
|
else if(mbytes < 0.1) { return '< 0.1'; }
|
|
|
|
else if(mbytes > 1000) { return '> 1000'; }
|
|
|
|
else { return mbytes.toFixed(1); }
|
|
|
|
}
|
|
|
|
|
|
|
|
function formatDate(date){
|
|
|
|
if(typeof date=='number'){
|
|
|
|
date=new Date(date);
|
|
|
|
}
|
2012-09-21 10:33:26 +04:00
|
|
|
return $.datepicker.formatDate(datepickerFormatDate, date)+' '+date.getHours()+':'+((date.getMinutes()<10)?'0':'')+date.getMinutes();
|
2012-02-26 00:19:32 +04:00
|
|
|
}
|
2012-08-29 23:52:42 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* get a variable by name
|
|
|
|
* @param string name
|
|
|
|
*/
|
|
|
|
OC.get=function(name) {
|
|
|
|
var namespaces = name.split(".");
|
|
|
|
var tail = namespaces.pop();
|
|
|
|
var context=window;
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
/**
|
|
|
|
* set a variable by name
|
|
|
|
* @param string name
|
|
|
|
* @param mixed value
|
|
|
|
*/
|
|
|
|
OC.set=function(name, value) {
|
|
|
|
var namespaces = name.split(".");
|
|
|
|
var tail = namespaces.pop();
|
|
|
|
var context=window;
|
|
|
|
|
|
|
|
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
|
|
|
};
|