2011-08-06 21:18:49 +00: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-19 21:33:34 +00:00
|
|
|
function t(app,text){
|
2011-07-27 14:39:44 +00:00
|
|
|
if( !( app in t.cache )){
|
|
|
|
|
|
|
|
$.post( OC.filePath('core','ajax','translations.php'), {'app': app}, function(jsondata){
|
|
|
|
t.cache[app] = jsondata.data;
|
2011-06-19 21:33:34 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// Bad answer ...
|
2011-07-27 14:39:44 +00:00
|
|
|
if( !( app in t.cache )){
|
|
|
|
t.cache[app] = [];
|
2011-06-19 21:33:34 +00:00
|
|
|
}
|
2011-05-17 20:34:31 +00:00
|
|
|
}
|
2011-07-27 14:39:44 +00:00
|
|
|
if( typeof( t.cache[app][text] ) !== 'undefined' ){
|
|
|
|
return t.cache[app][text];
|
2011-05-19 19:19:37 +00:00
|
|
|
}
|
2011-06-19 21:33:34 +00:00
|
|
|
else{
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
}
|
2011-07-27 14:39:44 +00:00
|
|
|
t.cache={};
|
2011-06-19 21:33:34 +00:00
|
|
|
|
2011-07-25 20:30:55 +00:00
|
|
|
OC={
|
|
|
|
webroot:oc_webroot,
|
2011-07-27 14:39:44 +00:00
|
|
|
coreApps:['files','admin','log','search','settings','core'],
|
2011-08-06 21:18:49 +00: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-25 20:30:55 +00:00
|
|
|
linkTo:function(app,file){
|
|
|
|
return OC.filePath(app,'',file);
|
|
|
|
},
|
2011-08-06 21:18:49 +00: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-25 20:30:55 +00: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-06 21:18:49 +00: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-25 20:30:55 +00:00
|
|
|
imagePath:function(app,file){
|
2011-07-28 02:28:04 +00:00
|
|
|
if(file.indexOf('.')==-1){//if no extention is given, use png or svg depending on browser support
|
|
|
|
file+=(SVGSupport())?'.svg':'.png'
|
|
|
|
}
|
2011-07-25 20:30:55 +00:00
|
|
|
return OC.filePath(app,'img',file);
|
|
|
|
},
|
2011-08-06 21:18:49 +00: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-25 20:30:55 +00:00
|
|
|
addScript:function(app,script,ready){
|
|
|
|
var path=OC.filePath(app,'js',script+'.js');
|
2011-07-30 16:05:20 +00:00
|
|
|
if(OC.addStyle.loaded.indexOf(path)==-1){
|
|
|
|
OC.addStyle.loaded.push(path);
|
|
|
|
if(ready){
|
|
|
|
$.getScript(path,ready);
|
|
|
|
}else{
|
|
|
|
$.getScript(path);
|
|
|
|
}
|
2011-07-30 19:18:54 +00:00
|
|
|
}else{
|
|
|
|
if(ready){
|
|
|
|
ready();
|
|
|
|
}
|
2011-07-25 20:30:55 +00:00
|
|
|
}
|
|
|
|
},
|
2011-08-06 21:18:49 +00: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-25 20:30:55 +00:00
|
|
|
addStyle:function(app,style){
|
|
|
|
var path=OC.filePath(app,'css',style+'.css');
|
2011-07-30 16:05:20 +00:00
|
|
|
if(OC.addScript.loaded.indexOf(path)==-1){
|
|
|
|
OC.addScript.loaded.push(path);
|
|
|
|
var style=$('<link rel="stylesheet" type="text/css" href="'+path+'"/>');
|
|
|
|
$('head').append(style);
|
|
|
|
}
|
|
|
|
},
|
2011-08-06 21:18:49 +00:00
|
|
|
/**
|
|
|
|
* do a search query and display the results
|
|
|
|
* @param query the search query
|
|
|
|
*/
|
2011-07-30 16:05:20 +00:00
|
|
|
search:function(query){
|
|
|
|
if(query){
|
2011-07-31 02:03:48 +00: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 19:18:54 +00:00
|
|
|
});
|
2011-07-30 16:05:20 +00:00
|
|
|
}
|
2011-07-25 20:30:55 +00:00
|
|
|
}
|
|
|
|
}
|
2011-07-30 22:50:04 +00:00
|
|
|
OC.search.customResults={};
|
2011-07-31 02:03:48 +00:00
|
|
|
OC.search.currentResult=-1;
|
|
|
|
OC.search.lastQuery='';
|
|
|
|
OC.search.lastResults={};
|
2011-07-30 16:05:20 +00:00
|
|
|
OC.addStyle.loaded=[];
|
|
|
|
OC.addScript.loaded=[];
|
|
|
|
|
2011-08-06 21:18:49 +00:00
|
|
|
/**
|
|
|
|
* implement Array.filter for browsers without native support
|
|
|
|
*/
|
2011-07-26 14:43:12 +00: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 14:57:49 +00:00
|
|
|
}
|
|
|
|
}
|
2011-08-06 21:18:49 +00:00
|
|
|
/**
|
|
|
|
* implement Array.indexOf for browsers without native support
|
|
|
|
*/
|
2011-07-27 14:39:44 +00: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 14:43:12 +00:00
|
|
|
};
|
2011-07-28 02:28:04 +00:00
|
|
|
}
|
|
|
|
|
2011-08-06 21:18:49 +00:00
|
|
|
/**
|
|
|
|
* check if the browser support svg images
|
|
|
|
*/
|
2011-07-28 02:28:04 +00:00
|
|
|
function SVGSupport() {
|
|
|
|
return document.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#BasicStructure", "1.1") || document.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#Shape", "1.0");
|
|
|
|
}
|
2011-07-29 14:52:09 +00:00
|
|
|
|
2011-08-06 21:18:49 +00:00
|
|
|
/**
|
|
|
|
* prototypal inharitence functions
|
|
|
|
*
|
|
|
|
* usage:
|
|
|
|
* MySubObject=object(MyObject)
|
|
|
|
*/
|
|
|
|
function object(o) {
|
|
|
|
function F() {}
|
|
|
|
F.prototype = o;
|
|
|
|
return new F();
|
|
|
|
}
|
|
|
|
|
2011-07-29 14:52:09 +00:00
|
|
|
$(document).ready(function(){
|
|
|
|
if(!SVGSupport()){//replace all svg images with png images for browser that dont support svg
|
|
|
|
$('img.svg').each(function(index,element){
|
|
|
|
element=$(element);
|
|
|
|
var src=element.attr('src');
|
|
|
|
element.attr('src',src.substr(0,src.length-3)+'png');
|
|
|
|
});
|
|
|
|
};
|
2011-07-31 02:03:48 +00:00
|
|
|
$('form.searchbox').submit(function(event){
|
|
|
|
event.preventDefault();
|
|
|
|
})
|
|
|
|
$('#searchbox').keyup(function(event){
|
|
|
|
if(event.keyCode==13){//enter
|
|
|
|
if(OC.search.currentResult>-1){
|
|
|
|
var result=$('#searchresults tr.result a')[OC.search.currentResult];
|
|
|
|
$(result).click();
|
|
|
|
}
|
|
|
|
}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 16:05:20 +00:00
|
|
|
}else{
|
2011-07-31 02:03:48 +00: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 19:18:54 +00:00
|
|
|
}
|
2011-07-30 16:05:20 +00:00
|
|
|
}
|
|
|
|
});
|
2011-08-08 09:45:01 +00:00
|
|
|
|
|
|
|
// 'show password' checkbox
|
2011-08-08 09:07:44 +00:00
|
|
|
$('#pass2').showPassword();
|
2011-08-08 09:45:01 +00: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();
|
|
|
|
$('#remember_login').fadeOut();
|
|
|
|
$('#remember_login+label').fadeOut();
|
|
|
|
} else {
|
|
|
|
$('#submit').fadeIn();
|
|
|
|
$('#remember_login').fadeIn();
|
|
|
|
$('#remember_login+label').fadeIn();
|
|
|
|
}
|
|
|
|
});
|
2011-07-29 14:52:09 +00:00
|
|
|
});
|
2011-08-08 09:07:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @name Show Password
|
|
|
|
* @descripton
|
|
|
|
* @version 1.3
|
|
|
|
* @requires Jquery 1.5
|
|
|
|
*
|
|
|
|
* @author Jan Jarfalk
|
|
|
|
* @author-email jan.jarfalk@unwrongest.com
|
|
|
|
* @author-website http://www.unwrongest.com
|
|
|
|
*
|
|
|
|
* @special-thanks Michel Gratton
|
|
|
|
*
|
|
|
|
* @licens MIT License - http://www.opensource.org/licenses/mit-license.php
|
|
|
|
*/
|
|
|
|
(function($){
|
|
|
|
$.fn.extend({
|
|
|
|
showPassword: function(c) {
|
|
|
|
|
|
|
|
// Setup callback object
|
|
|
|
var callback = {'fn':null,'args':{}}
|
|
|
|
callback.fn = c;
|
|
|
|
|
|
|
|
// Clones passwords and turn the clones into text inputs
|
|
|
|
var cloneElement = function( element ) {
|
|
|
|
|
|
|
|
var $element = $(element);
|
|
|
|
|
|
|
|
$clone = $("<input />");
|
|
|
|
|
|
|
|
// Name added for JQuery Validation compatibility
|
|
|
|
// Element name is required to avoid script warning.
|
|
|
|
$clone.attr({
|
|
|
|
'type' : 'text',
|
|
|
|
'class' : $element.attr('class'),
|
|
|
|
'style' : $element.attr('style'),
|
|
|
|
'size' : $element.attr('size'),
|
|
|
|
'name' : $element.attr('name')+'-clone',
|
|
|
|
'tabindex' : $element.attr('tabindex')
|
|
|
|
});
|
|
|
|
|
|
|
|
return $clone;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
// Transfers values between two elements
|
|
|
|
var update = function(a,b){
|
|
|
|
b.val(a.val());
|
|
|
|
};
|
|
|
|
|
|
|
|
// Shows a or b depending on checkbox
|
|
|
|
var setState = function( checkbox, a, b ){
|
|
|
|
|
|
|
|
if(checkbox.is(':checked')){
|
|
|
|
update(a,b);
|
|
|
|
b.show();
|
|
|
|
a.hide();
|
|
|
|
} else {
|
|
|
|
update(b,a);
|
|
|
|
b.hide();
|
|
|
|
a.show();
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
return this.each(function() {
|
|
|
|
|
|
|
|
var $input = $(this),
|
|
|
|
$checkbox = $($input.data('typetoggle'));
|
|
|
|
|
|
|
|
// Create clone
|
|
|
|
var $clone = cloneElement($input);
|
|
|
|
$clone.insertAfter($input);
|
|
|
|
|
|
|
|
// Set callback arguments
|
|
|
|
if(callback.fn){
|
|
|
|
callback.args.input = $input;
|
|
|
|
callback.args.checkbox = $checkbox;
|
|
|
|
callback.args.clone = $clone;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$checkbox.bind('click', function() {
|
|
|
|
setState( $checkbox, $input, $clone );
|
|
|
|
});
|
|
|
|
|
|
|
|
$input.bind('keyup', function() {
|
|
|
|
update( $input, $clone )
|
|
|
|
});
|
|
|
|
|
|
|
|
$clone.bind('keyup', function(){
|
|
|
|
update( $clone, $input );
|
|
|
|
|
|
|
|
// Added for JQuery Validation compatibility
|
|
|
|
// This will trigger validation if it's ON for keyup event
|
|
|
|
$input.trigger('keyup');
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
// Added for JQuery Validation compatibility
|
|
|
|
// This will trigger validation if it's ON for blur event
|
|
|
|
$clone.bind('blur', function() { $input.trigger('focusout'); });
|
|
|
|
|
|
|
|
setState( $checkbox, $input, $clone );
|
|
|
|
|
|
|
|
if( callback.fn ){
|
|
|
|
callback.fn( callback.args );
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
})(jQuery);
|