// JavaScript Document
//harry
//Inititialize function will initialize desktop
$.extend($.expr[':'], {
'containsi': function (elem, i, match, array) {
return (elem.textContent || elem.innerText || '').toLowerCase().indexOf((match[3] || "").toLowerCase()) >= 0;
}
});
$.fn.sort = function(c) {
return this.pushStack([].sort.apply(this, arguments), []);
};
var sortAscending = function(a, b) {
return $(a).find("h1").text() > $(b).find("h1").text() ? 1 : -1;
};
var sortDescending = function(a, b) {
return $(a).find("h1").text() < $(b).find("h1").text() ? 1 : -1;
};
var orbitDesktop = function(dom){
orbitDesktopAPI.apply(this);
o = this;
this.contentHolder = dom;
this.themesettings = "";
this.theme = "4f8d3f493b67fcd05f086359";
// this.themefolder = "themes";
this.transitionTime = 500;
this.currenthtml = "desktop.html";
this.currentface = "home";
this.desktopData = {"home":"","settings":"","work":"","favorite":"","apps_manager":"","sections":"","journal_p":""};
this.tp = "";
this.sectionList;
this.initialize = function(){
var theme = o.theme;
var custom = false;
$.getJSON("/desktop/get_desktop_settings",{"get":"desktop","desktopid":o.desktopId},function(desktopSettings){
if(desktopSettings){
if(desktopSettings.theme!="custom"){
theme = desktopSettings.theme;
}else{
theme = "4f8d3f493b67fcd05f086359";
custom = true;
}
o.theme = theme;
loadTheme(desktopSettings.customtheme,desktopSettings.wallpaper);
}else{loadTheme();}
})
var loadTheme = function(customtheme,customwallpaper){ //This function will load the theme from database
$.getJSON("/"+o.themefolder+"/"+theme+"/settings/"+theme+".json",function(ts){
o.themesettings = eval(ts);
$('head').append( $('').attr('href', "/"+o.themefolder+"/"+theme+"/css/"+ts.css));
if(custom){
$("head").find("#dyn_css").remove();
$("head").append(customtheme);
}
$(document).ready(function(){o.loadWallpaper(customwallpaper);o.bindDesktopEvents();o.loadIconCache();o.initializeDesktop();});
})
}
};
this.changeTheme = function(theme){ // this function is used for changing theme
o.theme = theme;
$.getJSON("/"+o.themefolder+"/"+theme+"/settings/"+theme+".json",function(ts){
o.themesettings = eval(ts);
$('head').find("#dyn_css").remove();
$('head').append( $('').attr('href', "/"+o.themefolder+"/"+theme+"/css/"+ts.css));
o.loadWallpaper();
o.loadIconCache();
})
};
this.bindDesktopEvents = function(){ //this function will bind the global handlers to thd desktop, for example doc
$("a#d_app_manager").click(function(){
var target = $(this).attr("href");
if(o.currenthtml!=target){
o.desktopData[o.currentface] = $(o.contentHolder).html();
$("#content").hide("drop",o.transitionTime,function(){
o.initializeAppSearch(target);
});
}
});
$("a#d_desktop").click(function(){
var target = $(this).attr("href");
if(o.currenthtml!=target){
o.desktopData[o.currentface] = $(o.contentHolder).html();
$("#content").hide("drop",o.transitionTime,function(){
o.initializeDesktop(target);
});
}
});
$("a#d_sections").click(function(){
var target = $(this).attr("href");
if(o.currenthtml!=target){
o.desktopData[o.currentface] = $(o.contentHolder).html();
$("#content").hide("drop",o.transitionTime,function(){
o.initializeSectionsManager(target);
});
}
});
$("#d_journal_p").click(function(){
var target = $(this).attr("href");
if(o.currenthtml!=target){
o.desktopData[o.currentface] = $(o.contentHolder).html();
$("#content").hide("drop",o.transitionTime,function(){
o.initializeJournalPapers(target);
});
}
});
$("a#d_settings").click(function(){
var target = $(this).attr("href");
if(o.currenthtml!=target){
o.desktopData[o.currentface] = $(o.contentHolder).html();
$("#content").hide("drop",o.transitionTime,function(){
o.initializeSettings(target);
});
}
});
$(window).resize(function(){
var ww = $(window).width();
$("img#thmbackground").attr({"width":ww});
});
var $widget_fn = $('.widget_fn'),$fn_des = $('.fn_des');
$widget_fn.hover(function(){
var fn_name = $(this).find('img').attr('alt'),nth = $(this).parents('.d_cate').index(),des_left = $('.dock_child').eq(nth).width();
$(this).addClass('thmc1');
$fn_des.text(fn_name).css({'top':nth * 60,'left': des_left + 60}).stop(true, true).fadeIn();
},function(){
$(this).removeClass('thmc1');
$fn_des.stop(true, true).fadeOut();
});
};
this.initializeDesktop = function(target){ //this is for initializing main desktops that are sections and tiles
if(!target)target = "desktop";
o.currenthtml = target;
o.currentface = "home";
var extraspace = 300;
var currentElement, elementParent, targetParent, tempElement, widthcheck;
widthcheck = false;
var bindHandlers = function(){ // this function will bind all the handlers in the desktop
var groupWrapperWidth = 0;
var groupWrapperHeight = 0;
$('div#desktop div.group').width(528);
$("div#desktop .element").mousedown(function(){
currentElement = $(this);
elementParent = $(this).parent();
})
$("div#desktop .group").mouseenter(function(){
targetParent = $(this);
})
$("div#desktop .group").each(function(){groupWrapperWidth+=$(this).width();})
groupWrapperWidth+=200;
groupWrapperHeight = $(".group").height() + 20;
// groupWrapperHeight = (groupWrapperHeight > ($(window).height()-extraspace))? $(window).height()-extraspace:groupWrapperHeight;
$("div#desktop #group_wrapper").css("width",groupWrapperWidth);
var first = true;
$("div#desktop .grp").sortable({
connectWith: ".grp",
tolerance: 'pointer' ,
revert:true,
stop:function(){
o.tp = targetParent.height();
var currentElementWidth = currentElement.width();
var targetElementWidth = targetParent.width();
if(targetParent.height()>540){
//targetParent.width(currentElement.width());
var newWidth = targetElementWidth+currentElementWidth;
targetParent.css("max-width",newWidth);
var newParentWidth = $("div#desktop #group_wrapper").width()+currentElementWidth;
$("div#desktop #group_wrapper").css("width",newParentWidth);
}else if(targetParent.height()<540){
var newWidth = targetElementWidth - (540-targetElementWidth);
targetParent.css("max-width",newWidth);
var newParentWidth = $("div#desktop #group_wrapper").width()+currentElementWidth;
$("div#desktop #group_wrapper").css("width",newParentWidth);
}
first = true;
},
update:function(){
if(first){
first = false;
var newpostitions = new Array;
var groupids = new Array;
$.each($("div#desktop .group"),function(i,grp){
var groupone = new Array;
groupids.push($(grp).attr("id"));
$ul = $(grp).find("ul.grp li");
$.each($ul,function(){
groupone.push($(this).attr("id"));
})
newpostitions.push(groupone);
});
$.post("/desktop/newpositions",{"sectionid":o.sectionId,"newpos":newpostitions,"groupids":groupids})
}
}
});
$('div#desktop .tinycanvas')
.tinyscrollbar({ axis: 'x' })
.find('.scrollbar')
.delay(1500)
.addClass('op00', 500);
// simple dropdown menu
var $sdm = $('.sdm');
if( !$sdm.children('.sdm_o') ){
return;
} else {
$sdm.hover(function(){
$(this).addClass('thmc2');
}, function(){
$(this).removeClass('thmc2');
});
}
}
var loadTiles = function(id){ //This will load tiles for a specific desktop .. id of section has to be passed here to load tiles
$("div#desktop div#group_wrapper").empty();
$.getJSON("/desktop/getgroups",{sectionid:id},function(groups){
var tilecolors = o.themesettings.tilecolor;
var opacity = ["op05","op06","op07","op08","op09"];
$.each(groups,function(i,group){
group.sort(o.sortJSON("position",true,parseInt));
var $group = $('
');
$.each(group,function(j,tile){
var tilecolor = tilecolors[Math.floor(Math.random()*tilecolors.length)];
var op = opacity[Math.floor(Math.random()*opacity.length)];
if(j==0)$group.attr("id",tile.group_id);
if(tile.data_category == "app")
$li = $('
'+tile.title+'
');
else
$li = $('
'+tile.title+'
Loading...
');
$group.find("ul").append($li);
})
$("div#desktop div#group_wrapper").append($group);
})
bindHandlers();
o.initializeWidgets();
})
}
var loadSectionList = function(){ //This will load the section list from the db
$.getJSON("/desktop/getsectionlist",{desktopid:o.desktopId},function(sectionlist){
o.sectionList = eval(sectionlist);
$.each(sectionlist,function(i,section){
var tempstyle="";
if(i==0){
tempstyle = "style='display:none;'";
$("#desktop #section_heading").text(section.name);
}
$("div#desktop ul#section_list").append($('