summaryrefslogtreecommitdiffstats
path: root/core/js/js.js
blob: 2dac6907d961337545698f29f1ca870b2e79d088 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
var _l10ncache = {};
function t(app,text){
	if( !( app in _l10ncache )){
		$.post( oc_webroot+'/core/ajax/translations.php', {'app': app}, function(jsondata){
			_l10ncache[app] = jsondata.data;
		});

		// Bad answer ...
		if( !( app in _l10ncache )){
			_l10ncache[app] = [];
		}
	}
	if( typeof( _l10ncache[app][text] ) !== 'undefined' ){
		return _l10ncache[app][text];
	}
	else{
		return text;
	}
}

OC={
	webroot:oc_webroot,
	coreApps:['files','admin','log','search','settings'],
	linkTo:function(app,file){
		return OC.filePath(app,'',file);
	},
	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;
	},
	imagePath:function(app,file){
		return OC.filePath(app,'img',file);
	},
	addScript:function(app,script,ready){
		var path=OC.filePath(app,'js',script+'.js');
		if(ready){
			$.getScript(path,ready);
		}else{
			$.getScript(path);
		}
	},
	addStyle:function(app,style){
		var path=OC.filePath(app,'css',style+'.css');
		var style=$('<link rel="stylesheet" type="text/css" href="'+path+'"/>');
		$('head').append(style);
	}
}

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;
	};
}