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
|
|
|
|
*/
|
2011-06-20 01:33:34 +04:00
|
|
|
function t(app,text){
|
2011-07-27 18:39:44 +04:00
|
|
|
if( !( app in t.cache )){
|
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;
|
|
|
|
},
|
|
|
|
})
|
2011-06-20 01:33:34 +04:00
|
|
|
|
|
|
|
// Bad answer ...
|
2011-07-27 18:39:44 +04:00
|
|
|
if( !( app in t.cache )){
|
|
|
|
t.cache[app] = [];
|
2011-06-20 01:33:34 +04:00
|
|
|
}
|
2011-05-18 00:34:31 +04:00
|
|
|
}
|
2011-07-27 18:39:44 +04:00
|
|
|
if( typeof( t.cache[app][text] ) !== 'undefined' ){
|
|
|
|
return t.cache[app][text];
|
2011-05-19 23:19:37 +04:00
|
|
|
}
|
2011-06-20 01:33:34 +04:00
|
|
|
else{
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
}
|
2011-07-27 18:39:44 +04:00
|
|
|
t.cache={};
|
2011-06-20 01:33:34 +04:00
|
|
|
|
2011-07-26 00:30:55 +04:00
|
|
|
OC={
|
|
|
|
webroot:oc_webroot,
|
2011-08-11 18:53:00 +04:00
|
|
|
currentUser:(typeof oc_current_user!=='undefined')?oc_current_user:false,
|
2011-08-09 17:25:18 +04:00
|
|
|
coreApps:['files','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){
|
|
|
|
var isCore=OC.coreApps.indexOf(app)!=-1;
|
|
|
|
app+='/';
|
|
|
|
var link=OC.webroot+'/';
|
|
|
|
if(!isCore){
|
|
|
|
link+='apps/';
|
|
|
|
}
|
|
|
|
link+=app;
|
|
|
|
if(type){
|
|
|
|
link+=type+'/'
|
|
|
|
}
|
|
|
|
link+=file;
|
|
|
|
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
|
|
|
|
*
|
|
|
|
* if no extention is given for the image, it will automatically decide between .png and .svg based on what the browser supports
|
|
|
|
*/
|
2011-07-26 00:30:55 +04:00
|
|
|
imagePath:function(app,file){
|
2011-07-28 06:28:04 +04:00
|
|
|
if(file.indexOf('.')==-1){//if no extention is given, use png or svg depending on browser support
|
|
|
|
file+=(SVGSupport())?'.svg':'.png'
|
|
|
|
}
|
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
|
|
|
|
*
|
|
|
|
* 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){
|
|
|
|
var path=OC.filePath(app,'js',script+'.js');
|
2011-09-26 23:18:56 +04:00
|
|
|
if(OC.addScript.loaded.indexOf(path)==-1){
|
|
|
|
OC.addScript.loaded.push(path);
|
2011-07-30 20:05:20 +04:00
|
|
|
if(ready){
|
|
|
|
$.getScript(path,ready);
|
|
|
|
}else{
|
|
|
|
$.getScript(path);
|
|
|
|
}
|
2011-07-30 23:18:54 +04:00
|
|
|
}else{
|
|
|
|
if(ready){
|
|
|
|
ready();
|
|
|
|
}
|
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');
|
2011-09-26 23:18:56 +04:00
|
|
|
if(OC.addStyle.loaded.indexOf(path)==-1){
|
|
|
|
OC.addStyle.loaded.push(path);
|
2011-07-30 20:05:20 +04:00
|
|
|
var style=$('<link rel="stylesheet" type="text/css" href="'+path+'"/>');
|
|
|
|
$('head').append(style);
|
|
|
|
}
|
|
|
|
},
|
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
|
|
|
}
|
2011-07-26 00:30:55 +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-01-15 22:11:25 +04:00
|
|
|
if(typeof localStorage !='undefined'){
|
|
|
|
//user and instance awere localstorage
|
|
|
|
OC.localStorage={
|
|
|
|
namespace:'oc_'+OC.currentUser+'_'+OC.webroot+'_',
|
|
|
|
hasItem:function(name){
|
|
|
|
return OC.localStorage.getItem(name)!=null;
|
|
|
|
},
|
|
|
|
setItem:function(name,item){
|
|
|
|
return localStorage.setItem(OC.localStorage.namespace+name,JSON.stringify(item));
|
|
|
|
},
|
|
|
|
getItem:function(name){
|
|
|
|
return JSON.parse(localStorage.getItem(OC.localStorage.namespace+name));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
//dummy localstorage
|
|
|
|
OC.localStorage={
|
|
|
|
hasItem:function(name){
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
setItem:function(name,item){
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
getItem:function(name){
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
if (typeof fun != "function")
|
|
|
|
throw new TypeError();
|
|
|
|
|
|
|
|
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;
|
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;
|
|
|
|
|
|
|
|
var from = Number(arguments[1]) || 0;
|
|
|
|
from = (from < 0)
|
|
|
|
? Math.ceil(from)
|
|
|
|
: Math.floor(from);
|
|
|
|
if (from < 0)
|
|
|
|
from += len;
|
|
|
|
|
|
|
|
for (; from < len; from++)
|
|
|
|
{
|
|
|
|
if (from in this &&
|
|
|
|
this[from] === elt)
|
|
|
|
return from;
|
|
|
|
}
|
|
|
|
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-01-15 02:37:50 +04:00
|
|
|
if(parts.length==2){
|
|
|
|
var value=parts[1].trim();
|
|
|
|
if(value[0]=='"'){
|
|
|
|
value=value.substr(1,value.length-2);
|
|
|
|
}
|
|
|
|
headers[parts[0]]=value;
|
2011-08-22 17:20:24 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if(headers["Content-Type"]!='image/svg+xml'){
|
|
|
|
replaceSVG();
|
|
|
|
SVGSupport.checkMimeType.correct=false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
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');
|
|
|
|
if(background && background!='none'){
|
|
|
|
background=background.substr(0,background.length-4)+'png)';
|
|
|
|
element.css('background-image',background);
|
|
|
|
}
|
|
|
|
element.find('*').each(function(index,element) {
|
|
|
|
element=$(element);
|
|
|
|
var background=element.css('background-image');
|
|
|
|
if(background && background!='none'){
|
|
|
|
background=background.substr(0,background.length-4)+'png)';
|
|
|
|
element.css('background-image',background);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2011-08-07 01:18:49 +04:00
|
|
|
/**
|
|
|
|
* prototypal inharitence functions
|
|
|
|
*
|
|
|
|
* 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) {
|
|
|
|
var height = parseFloat($(window).height())-parseFloat(selector.css('top'));
|
|
|
|
selector.css('height', height + 'px');
|
|
|
|
if(selector.outerHeight() > selector.height())
|
|
|
|
selector.css('height', height-(selector.outerHeight()-selector.height()) + 'px');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fills height and width of window. (more precise than height: 100%; or width: 100%;)
|
|
|
|
*/
|
|
|
|
function fillWindow(selector) {
|
|
|
|
fillHeight(selector);
|
|
|
|
var width = parseFloat($(window).width())-parseFloat(selector.css('left'));
|
|
|
|
selector.css('width', width + 'px');
|
|
|
|
if(selector.outerWidth() > selector.width())
|
|
|
|
selector.css('width', width-(selector.outerWidth()-selector.width()) + 'px');
|
|
|
|
}
|
|
|
|
|
2011-07-29 18:52:09 +04:00
|
|
|
$(document).ready(function(){
|
2011-10-04 20:54:07 +04:00
|
|
|
|
|
|
|
$(window).resize(function () {
|
|
|
|
fillHeight($('#leftcontent'));
|
|
|
|
fillWindow($('#rightcontent'));
|
|
|
|
});
|
|
|
|
$(window).trigger('resize');
|
|
|
|
|
2011-07-29 18:52:09 +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){
|
|
|
|
if(event.keyCode==13){//enter
|
|
|
|
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
|
|
|
}
|
|
|
|
}else if(event.keyCode==38){//up
|
|
|
|
if(OC.search.currentResult>0){
|
|
|
|
OC.search.currentResult--;
|
|
|
|
OC.search.renderCurrent();
|
|
|
|
}
|
|
|
|
}else if(event.keyCode==40){//down
|
|
|
|
if(OC.search.lastResults.length>OC.search.currentResult+1){
|
|
|
|
OC.search.currentResult++;
|
|
|
|
OC.search.renderCurrent();
|
|
|
|
}
|
|
|
|
}else if(event.keyCode==27){//esc
|
|
|
|
OC.search.hide();
|
2011-07-30 20:05:20 +04:00
|
|
|
}else{
|
2011-07-31 06:03:48 +04:00
|
|
|
var query=$('#searchbox').val();
|
|
|
|
if(OC.search.lastQuery!=query){
|
|
|
|
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
|
|
|
|
|
|
|
// '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();
|
|
|
|
|
2011-08-08 13:45:01 +04:00
|
|
|
// hide log in button etc. when form fields not filled
|
|
|
|
$('#submit').hide();
|
|
|
|
$('#remember_login').hide();
|
|
|
|
$('#remember_login+label').hide();
|
|
|
|
$('#body-login input').keyup(function() {
|
|
|
|
var empty = false;
|
|
|
|
$('#body-login input').each(function() {
|
|
|
|
if ($(this).val() == '') {
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
});
|
2011-08-09 01:31:58 +04:00
|
|
|
|
2011-08-10 19:29:26 +04:00
|
|
|
if($('body').attr("id")=="body-user") { $('#settings #expanddiv').hide(); }
|
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
|
|
|
});
|
2011-08-10 19:29:26 +04:00
|
|
|
$('#settings #expand').hover(function(){
|
|
|
|
$('#settings #expand+span').fadeToggle();
|
2011-08-12 13:26:13 +04:00
|
|
|
});
|
2011-08-13 00:18:38 +04:00
|
|
|
$(window).click(function(){//hide the settings menu when clicking oustide it
|
|
|
|
if($('body').attr("id")=="body-user"){
|
|
|
|
$('#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});
|
2011-10-23 13:40:40 +04:00
|
|
|
$('.file_upload_button_wrapper').tipsy({gravity:'w', fade:true});
|
2011-08-28 10:46:38 +04:00
|
|
|
$('.selectedActions a.delete').tipsy({gravity: 'se', fade:true, live:true});
|
|
|
|
$('.selectedActions a').tipsy({gravity:'s', fade:true, live:true});
|
|
|
|
$('#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";
|
|
|
|
|
|
|
|
if (this === void 0 || this === null)
|
|
|
|
throw new TypeError();
|
|
|
|
|
|
|
|
var t = Object(this);
|
|
|
|
var len = t.length >>> 0;
|
|
|
|
if (typeof fun !== "function")
|
|
|
|
throw new TypeError();
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
};
|
|
|
|
}
|
2011-11-02 01:35:13 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Filter Jquery selector by attribute value
|
|
|
|
**/
|
|
|
|
$.fn.filterAttr = function(attr_name, attr_value) {
|
|
|
|
return this.filter(function() { return $(this).attr(attr_name) === attr_value; });
|
|
|
|
};
|
2012-01-15 22:11:25 +04:00
|
|
|
|
|
|
|
|