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

164 lines
6.4 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-05-25 07:41:07 +00:00
this.windowcounter = 0;
2012-03-29 11:50:23 +00:00
this.notify = function(msg,type,time){
2012-05-25 07:41:07 +00:00
//takes 3 arguments
//msg (string) : message to display
//type (string : success, imp, alert
//time (int) : duration for notification in seconds
2012-03-29 11:50:23 +00:00
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){
2012-05-25 07:41:07 +00:00
//takes 2 arguments
//func (object Function) : the function which has to be executed
//callbackFn (object function) : the function for callback
2012-04-11 07:31:10 +00:00
func.call(this);
if(callbackFn){
callbackFn.call(this,func);
}
};
this.sortJSON = function(field, reverse, primer){
2012-05-25 07:41:07 +00:00
//takes 3 arguments
//field (string): it is the field on which sorting has to be done
//reverse (boolean): this is for asc or desc
//primer (method): for example pass parseInt for converting the field attribute in integer
2012-04-11 07:31:10 +00:00
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) {
2012-05-25 07:41:07 +00:00
// takes 1 parameter
// rgb (string) : pass rgb string to convert
2012-04-18 10:15:02 +00:00
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){
2012-05-25 07:41:07 +00:00
//takes 1 parameter
//wallpaper (string): takes wallpaper and sets the wallpaper
$("img#thmbackground").attr("src",o.wallpaperPath+wallpaper);
o.saveWallpaper(wallpaper);
};
2012-04-19 07:36:03 +00:00
this.confirm = function(settings,callbackfn){
2012-05-25 07:41:07 +00:00
//takes set of arguments in array
//settings.buttons (array string) : name of buttons to be displayed
//settings.highlighted (integer) : takes either 1 or 2.. will highlight the button which is passed
//settings.message (string) : takes a string and message to be displayed on the confirmbox
//callbackfn (object function) : function to callback
2012-04-19 07:36:03 +00:00
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){
2012-05-25 07:41:07 +00:00
// returns array and takes json object and key
//json (json object) : json object from which the key has to be extracted
// key (string) : key which has to be extracted
var tempArray = new Array;
$.each(tjson,function(i,val){
tempArray.push(val[key]);
})
return tempArray;
2012-05-25 07:41:07 +00:00
};
this.appWindow = function(settings,callbackfn){
//takes set of arguments as array and gives callback
//settings.method (string) : like open and close
//settings.title (string) : the window title
//settings.appid (string) : appid.. user can use this appid to open or close or refresh the window
//settings.url (string) : it is the url if you want to force external url to open in appwindow... you have to pass extURL in appid if you want to open externalurl
if(typeof settings == "undefined")settings = {};
if(!settings.appid){
o.notify("Invalid AppID.","imp",3);
return;
}
if(!settings.method)settings.method = "open";
if(settings.method == 'open'){
var appurl = "http://www.rulingcom.com";
o.windowcounter++;
if(!settings.title)settings.title = "New Window "+o.windowcounter;
if(settings.appid=="extURL"){
if(settings.url){
if(settings.url.substr(0,3)!="http")settings.url = "http://"+settings.url;
var urlregex = new RegExp("^(http:\/\/www.|https:\/\/www.|ftp:\/\/www.|www.){1}([0-9A-Za-z]+\.)");
if(urlregex.test(settings.url))
appurl = settings.url;
else{
o.notify("Invalid URL","alert",3);
return;
}
}
else{
o.notify("Invalid URL","alert",3);
return;
}
}
var whtml =$('<div id="app_frame_'+o.windowcounter+'" class="thmc2 app_frame" data-content="'+settings.appid+'"><div id="content"><div id="header" class="hh3"><div class="dtitle w2 hh3 hp" style="text-transform:capitalize;"><span class="thmtxth">'+settings.title+'</span></div><span class="icon-remove hh3 hp thmtxt"></span></div><div id="holder_'+o.windowcounter+'" class="app_holder"><iframe src="'+appurl+'" frameborder="0" scrolling="auto"></iframe><div class="clear"></div></div></div></div>');
$(o.contentHolder).append(whtml);
var parentwindow = $(o.contentHolder).find("div#app_frame_"+o.windowcounter);
var app_holder_height = parentwindow.height() - 72;
var app_holder_width = parentwindow.width();
parentwindow.find("iframe").attr({"height":app_holder_height,"width":app_holder_width});
parentwindow.find("div.app_holder").height(app_holder_height);
parentwindow.find("span.icon-remove").click(function(){
parentwindow.remove();
})
}
if(typeof callbackfn=="function"){
callbackfn.call(this);
}
};
2012-03-29 11:50:23 +00:00
};
orbitDesktopAPI.prototype.notifyImgPath = "temp";
orbitDesktopAPI.prototype.wallpaperPath = "temp";