orbit-basic/app/assets/javascripts/orbitdesktopAPI.js

92 lines
2.9 KiB
JavaScript
Raw Normal View History

2012-03-28 10:53:30 +00:00
// JavaScript Document
//Harry Bomrah
2012-03-28 10:53:30 +00:00
var orbitDesktopAPI = function(){
o = this;
2012-03-29 11:50:23 +00:00
this.notify = function(msg,type,time){
var $notify = $("#orbitnote");
var img, n_height;
2012-03-29 11:50:23 +00:00
if(!type)type="";
switch(type){
case "alert":
img = "note_alert.png";
break;
case "imp":
img = "note_imp.png";
break;
case "success":
img = "note_success.png";
break;
default:
img = "note_alert.png";
break;
}
2012-04-05 12:32:56 +00:00
$notify.find("img#note_img").attr("src",o.notifyImgPath+img);
2012-03-29 11:50:23 +00:00
$notify.find(".note_message").text(msg);
n_height = $notify.outerHeight();
2012-03-29 11:50:23 +00:00
if(!time)time=5000; else time=time*1000;
$notify
.css({'top':-n_height, 'display':'block', 'opacity':0})
.animate({top:0,opacity:1},200)
.delay(time)
.animate({top:-n_height,opacity:0},200);
2012-03-28 10:53:30 +00:00
};
2012-04-11 07:31:10 +00:00
this.executeFunc = function(func,callbackFn){
func.call(this);
if(callbackFn){
callbackFn.call(this,func);
}
};
this.sortJSON = function(field, reverse, primer){
var key = function (x) {return primer ? primer(x[field]) : x[field]};
return function (a,b) {
var A = key(a), B = key(b);
return ((A < B) ? -1 : (A > B) ? +1 : 0) * [-1,1][+!!reverse];
}
2012-04-18 10:15:02 +00:00
};
this.rgb2hex = function(rgb) {
rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
var hex = function(x) {
return ("0" + parseInt(x).toString(16)).slice(-2);
}
return "#" + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]);
};
this.changeWallpaper = function(wallpaper){
$("img#thmbackground").attr("src",o.wallpaperPath+wallpaper);
o.saveWallpaper(wallpaper);
};
2012-04-19 07:36:03 +00:00
this.confirm = function(settings,callbackfn){
if(!settings.buttons)settings.buttons=["Ok","Cancel"];
2012-04-24 08:45:26 +00:00
if(settings.highlighted!=1 && settings.highlighted!=2)settings.highlighted=2;
2012-04-19 07:36:03 +00:00
if(!settings.message)settings.message = "Are you sure?"
var $confirm = $("#orbitdiag");
2012-04-24 08:45:26 +00:00
$confirm.find(".diag_action a").removeClass("thmc1 thmtxt").addClass("admbg admtxt");
2012-04-19 07:36:03 +00:00
$confirm.find(".diag_message").text(settings.message);
if(settings.highlighted == 1)
$confirm.find("#diag_confirm").removeClass("admbg admtxt").addClass("thmc1 thmtxt");
2012-04-19 07:36:03 +00:00
if(settings.highlighted == 2)
$confirm.find("#diag_cancel").removeClass("admbg admtxt").addClass("thmc1 thmtxt");
2012-04-19 07:36:03 +00:00
$confirm.find("#diag_confirm").text(settings.buttons[0]).one("click",function(){
2012-04-26 15:18:35 +00:00
$confirm.stop(1,1).fadeOut();
$confirm.find(".diag_action a").unbind();
if(typeof callbackfn=="function")
callbackfn.call(this,true);
});
2012-04-19 07:36:03 +00:00
$confirm.find("#diag_cancel").text(settings.buttons[1]).one("click",function(){
2012-04-26 15:18:35 +00:00
$confirm.stop(1,1).fadeOut();
$confirm.find(".diag_action a").unbind();
if(typeof callbackfn=="function")
callbackfn.call(this,false);
});
2012-04-26 15:18:35 +00:00
$confirm.stop(1,1).fadeIn();
2012-04-24 08:45:26 +00:00
};
this.getArrayfromJson = function(tjson,key){
var tempArray = new Array;
$.each(tjson,function(i,val){
tempArray.push(val[key]);
})
return tempArray;
}
2012-03-29 11:50:23 +00:00
};
orbitDesktopAPI.prototype.notifyImgPath = "temp";
orbitDesktopAPI.prototype.wallpaperPath = "temp";