Fetching desktop from db

This commit is contained in:
Harry Bomrah committed 2012-04-11 15:31:10 +08:00
1 parent eb219c14b7
commit 4875b339f8
24 files changed
+470 -41

No files matched your search

+76 -32
View File
@@ -82,34 +82,27 @@ var orbitDesktop = function(dom){
var ww = $(window).width();
$("img#thmbackground").attr({"width":ww});
});
$(o.contentHolder).mousemove(function(event){
/*if(($(window).width()-50)<=event.pageX){
$("#holder").animate({scrollLeft:$("#holder").scrollLeft()+500},1000);
}
if(event.pageX<300){
$("#holder").animate({scrollLeft:0},1000);
}*/
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();
});
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){
if(!target)target = "desktop";
o.currenthtml = target;
o.currentface = "home";
var groupWrapperWidth = 0;
var groupWrapperHeight = 0;
var extraspace = 300;
var currentElement, elementParent, targetParent, tempElement, widthcheck;
widthcheck = false;
var bindHandlers = function(){
var groupWrapperWidth = 0;
var groupWrapperHeight = 0;
$(".element").mousedown(function(){
currentElement = $(this);
elementParent = $(this).parent();
@@ -163,16 +156,65 @@ var orbitDesktop = function(dom){
$(this).removeClass('thmc2');
});
}
}
var loadTiles = function(id){
$("div#group_wrapper").empty();
$.getJSON("/desktop/getgroups",{sectionid:id},function(groups){
var tilecolors = o.themesettings.tilecolor;
var opacity = ["op05","op06","op07","op08"];
$.each(groups,function(i,group){
group.sort(o.sortJSON("position",true,parseInt));
var $group = $('<div class="group"><ul class="grp ui-sortable"></ul></div>');
$.each(group,function(j,tile){
var tilecolor = tilecolors[Math.floor(Math.random()*tilecolors.length)];
var op = opacity[Math.floor(Math.random()*opacity.length)];
if(tile.data_category == "app")
$li = $('<li class="element '+tile.shape+' hp vp" data-category="'+tile.data_category+'" data-content="'+tile.data_content+'"><span class="tile '+tilecolor+' '+op+'"></span><a href="" class="appicon"><img src="" alt=""></a><h1 class="appname thmtxt">'+tile.title+'</h1></li>');
else
$li = $('<li class="element '+tile.shape+' hp vp" data-category="'+tile.data_category+'" data-content="'+tile.data_content+'"><span class="tile '+tilecolor+' '+op+'"></span><h1 class="appname thmtxt">'+tile.title+'</h1><div class="appholder holder_f">test content</div></li>');
$group.find("ul").append($li);
})
$("div#group_wrapper").append($group);
})
bindHandlers();
o.initializeWidgets();
})
}
var loadSectionList = function(){
$.getJSON("/desktop/getsectionlist",{desktopid:o.desktopId},function(sectionlist){
$.each(sectionlist,function(i,section){
var tempstyle="";
if(i==0){
tempstyle = "style='display:none;'";
$("span#section_heading").text(section.name);
}
$("ul#section_list").append($('<li class="section_name" '+tempstyle+'><a class="admtxt hp w2 hh2" onclick="return false;" href="'+section._id+'" >'+section.name+'</a></li>'));
})
bindSecondaryHandlers();
})
}
var bindSecondaryHandlers = function(){
$("ul#section_list li.section_name").click(function(){
$("li.section_name").show();
$(this).hide();
$("span#section_heading").text($(this).text());
loadTiles($(this).find("a").attr("href"));
})
}
if(!o.desktopData[o.currentface]){
$(o.contentHolder).empty().load("/desktop/"+target,function(){
bindHandlers();
o.initializeWidgets();
loadTiles(o.sectionId);
loadSectionList();
});
}else{
$(o.contentHolder).html(o.desktopData[o.currentface]);
bindHandlers();
o.initializeWidgets();
bindHandlers();
o.initializeWidgets();
bindSecondaryHandlers();
}
};
this.tempFunc = function(){
@@ -206,7 +248,7 @@ var orbitDesktop = function(dom){
//for Alphabet sorting
$("a#alphabet_sort_btn").click(function(){
switch ($(this).attr("href")) {
switch ($(this).attr("href")){
case "ascending":
$(this).attr("href","descending").find(".thmtxt").text("Alphabet [Z-A]");
allApps = $(".group_search .element").sort(sortAscending);
@@ -225,7 +267,6 @@ var orbitDesktop = function(dom){
if(!o.desktopData[o.currentface]){
$(o.contentHolder).empty().load("/desktop/"+target,function(){
bindHandlers();
});
}else{
$(o.contentHolder).html(o.desktopData[o.currentface]);
@@ -276,9 +317,10 @@ var orbitDesktop = function(dom){
});
}
};
if(!o.desktopData[o.currentface]){
$(o.contentHolder).empty().load("/desktop/"+target,function(){
bindHandlers();
bindHandlers();
});
}else{
$(o.contentHolder).html(o.desktopData[o.currentface]);
@@ -294,14 +336,14 @@ var orbitDesktop = function(dom){
o.changeTheme($(this).val());
})
}
if(!o.desktopData[o.currentface]){
// if(!o.desktopData[o.currentface]){
$(o.contentHolder).empty().load("/desktop/"+target,function(){
bindHandlers();
});
}else{
$(o.contentHolder).html(o.desktopData[o.currentface]);
bindHandlers();
}
// }else{
// $(o.contentHolder).html(o.desktopData[o.currentface]);
// bindHandlers();
// }
};
this.loadWallpaper = function(wallpaper){
if(!wallpaper)wallpaper = o.themesettings.background;
@@ -326,7 +368,7 @@ var orbitDesktop = function(dom){
$.each(elements,function(){
var widget = $(this);
if(widget.attr("data-category")=="widget"){
var widgename =widget.attr("data-content");
var widgename = widget.attr("data-content");
$.getScript("/desktop_widgets/"+widgename+"/"+widgename+".js",function(){
widget.find("div.appholder").load("/desktop_widgets/"+widgename+"/index.html.erb");
});
@@ -343,4 +385,6 @@ orbitDesktop.prototype.widgetfolder = "desktop_widgets";
orbitDesktop.prototype.desktopId = "1";
orbitDesktop.prototype.notifyImgPath = "temp";
// devin
var uselessfunction = function(){
$.post("/desktop/temp_func",{sectionid:"4f83e7bbbd98eb041600001d"});
}
+13
View File
@@ -38,4 +38,17 @@ var orbitDesktopAPI = function(){
if(!time)time=5000; else time=time*1000;
$notify.slideDown().delay(time).slideUp();
};
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];
}
}
};