// JavaScript Document //harry $.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":""}; 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){ $.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){ 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(){ $("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); }); } }); $("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){ if(!target)target = "desktop"; o.currenthtml = target; o.currentface = "home"; var extraspace = 300; var currentElement, elementParent, targetParent, tempElement, widthcheck; widthcheck = false; var bindHandlers = function(){ 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},function(){ }) } } }); $('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){ $("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(){ $.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;'"; $("div#desktop span#section_heading").text(section.name); } $("div#desktop ul#section_list").append($('
  • '+section.name+'
  • ')); }) bindSecondaryHandlers(); }) } var bindSecondaryHandlers = function(){ $("div#desktop ul#section_list li.section_name").click(function(){ $("div#desktop li.section_name").show(); $(this).hide(); $("div#desktop span#section_heading").text($(this).text()); o.sectionId = $(this).find("a").attr("href"); loadTiles(o.sectionId); }) } if(!o.desktopData[o.currentface]){ $(o.contentHolder).empty().load("/desktop/"+target,function(){ loadTiles(o.sectionId); loadSectionList(); }); }else{ $(o.contentHolder).html(o.desktopData[o.currentface]); bindHandlers(); o.initializeWidgets(); bindSecondaryHandlers(); $("div#desktop ul#section_list").empty(); $.each(o.sectionList,function(i,section){ var tempstyle=""; if(i==0){ tempstyle = "style='display:none;'"; $("div#desktop span#section_heading").text(section.name); } $("div#desktop ul#section_list").append($('
  • '+section.name+'
  • ')); }) bindSecondaryHandlers(); } }; this.tempFunc = function(th){ o.confirm("What","","",function(reply){ alert(reply); }) } this.initializeAppSearch = function(target){ o.currenthtml = target; o.currentface = "apps_manager"; var searchArray,allApps; var bindHandlers = function(){ $("div#app_manager #group_wrapper").css("min-width",$(window).width()-100); $("div#app_manager .group_search").css("width",$(window).width()-200); //for textbox search $("div#app_manager #searchbox").focus(function(){$(this).val("");}).keyup(function(e){ if($(this).val()){ $("div#app_manager .search_result").empty(); $("div#app_manager #seperator").hide(); searchArray = $("div#app_manager .element:containsi("+$(this).val()+")"); if(searchArray.length>0){ $("div#app_manager #seperator").show(); searchArray.each(function(){ var $newelement = $(''); $("div#app_manager .search_result").prepend($newelement); }) } }else{$("div#app_manager #seperator").hide();$("div#app_manager .search_result").empty();} }).blur(function(){$(this).val("Search");}); //for Alphabet sorting $("div#app_manager a#alphabet_sort_btn").click(function(){ switch ($(this).attr("href")){ case "ascending": $(this).attr("href","descending").find(".thmtxt").text("Alphabet [Z-A]"); allApps = $("div#app_manager .group_search .element").sort(sortAscending); break; case "descending": $(this).attr("href","ascending").find(".thmtxt").text("Alphabet [A-Z]"); allApps = $("div#app_manager .group_search .element").sort(sortDescending); break; } $("div#app_manager .group_search").html(allApps); return false; }) $('.tinycanvas') .tinyscrollbar({ axis: 'x'}) .find('.scrollbar') .delay(1500) .addClass('op00', 500); } var loadApps = function(){ $.getJSON("/desktop/getapplist",{desktopid:o.desktopId},function(appss){ $.each(appss,function(i,apps){ $.each(apps,function(i,app){ var $div; $div = $('

    '+app.title+'

    '); $("#app_list").append($div); }) }) bindHandlers(); }) } if(!o.desktopData[o.currentface]){ $(o.contentHolder).empty().load("/desktop/"+target,function(){ loadApps(); }); }else{ $(o.contentHolder).html(o.desktopData[o.currentface]); bindHandlers(); } }; this.initializeSectionsManager = function(target){ o.currenthtml = target; o.currentface = "sections"; var elementParent,element; var bindHandlers = function(){ var groupWrapperWidth = 0; $("div#sections .group").width(400); $("div#sections .group").each(function(){groupWrapperWidth+=$(this).width();}) groupWrapperWidth+=200; groupWrapperHeight = $(".group").height() + 20; $("#group_wrapper").width(groupWrapperWidth); $("div#sections #group_wrapper .to_drop").sortable({ start:function(){ var $elementParent = $(this).parent().parent(); elementParent = $elementParent; element = $(this); $elementParent.find("div.section_label ul li").fadeIn(500); }, stop:function(){ elementParent.find("div.section_label ul li:not(:nth-child(1))").fadeOut(500); } }); $("div#sections .section_label ul li:not(:nth-child(1))").droppable({ drop:function(){ if($("#"+$(this).attr("data-category")+" .element").length>=24){ o.notify("Section is full.","alert"); } else{ $("#"+$(this).attr("data-category")).append(element); $.post("/desktop/save_desktop_settings",{"save":"appnewsection","appid":element.attr("id"),"newsectionid":$(this).attr("data-content"),"desktopid":o.desktopId}) if(o.sectionId == $(this).attr("data-content") || o.sectionId == elementParent.attr("id")){ o.desktopData["home"]=""; } } }, over:function(){ $(this).find('span.tile').removeClass('op06'); }, out:function(){ $(this).find('span.tile').addClass('op06'); } }); $('.tinycanvas') .tinyscrollbar({ axis: 'x'}) .find('.scrollbar') .delay(1500) .addClass('op00', 500); var $sdm = $('.sdm'); if( !$sdm.children('.sdm_o') ){ return; } else { $sdm.hover(function(){$(this).addClass('thmc2');}, function(){$(this).removeClass('thmc2');}); } }; var loadApps = function(){ $.getJSON("/desktop/getapplist",{desktopid:o.desktopId},function(appss){ var $group,$lii,$li; var z=0; for(section in o.sectionList){ $group = $('
    '); for(x=0;x<4;x++){ if(x==0){ $li = $('
  • '+o.sectionList[z].name+'
  • '); $group.find("ul.section_grp").append($li); } if(z!=x){ $lii = $(''); $group.find("ul.section_grp").append($lii); } } z++; $("div#group_wrapper").append($group); } var yy=1,y=0; $.each(appss,function(i,apps){ $.each(apps,function(i,app){ $li = $('
  • '+app.title+'

  • '); $("ul#section"+yy).append($li); }) if(y==1){ y=-1; yy++; } y++; }) bindHandlers(); }) } if(!o.desktopData[o.currentface]){ $(o.contentHolder).empty().load("/desktop/"+target,function(){ loadApps(); }); }else{ $(o.contentHolder).html(o.desktopData[o.currentface]); bindHandlers(); } }; this.initializeSettings = function(target){ o.currenthtml = target; o.currentface = "settings"; var bindHandlers = function(){ $("div#settings ul#setting_left_nav li a").on({ click: function(){ if(!$(this).data("clicked")){ var tfunc = $(this).attr("href"); switch(tfunc){ case "themes": themes(); break; case "sections": sections(); break; } $("div#settings ul#setting_left_nav li a").removeClass('thmc1 thmtxt').data('clicked',null); $(this).addClass('thmc1 thmtxt').data('clicked',true); } }, mouseenter: function(){ $(this).removeClass('admtxt').addClass('thmc1 thmtxt'); }, mouseleave: function(){ var t = $(this).data('clicked') ? '' : 'thmc1 thmtxt'; $(this).removeClass(t).addClass('admtxt'); } }); } var sections = function(){ var bindHandlers = function(){ $('.tinycanvas').each(function(){ var h = $(this).parent().height(), sh = $(this).siblings('.s_tab').height(); $(this) .css({'height': h-sh-24}) .tinyscrollbar({ axis: 'y'}) .find('.scrollbar') .delay(1500) .addClass('op00', 500); }); $("a#name_save_btn").click(function(){ var desktopnm = new Array; $("#desktop_names input").each(function(){ desktopnm.push($(this).val()); }) $.post("/desktop/save_desktop_settings",{"save":"desktopnames","desktopid":o.desktopId,"desktopnms":desktopnm},function(result,status){ if(status=="success"){ if(result[0].success=="true") o.notify("Names Saved!!","success",2); else o.notify("Name saving failed!!","imp",2); }else{ o.notify("Connection problem!!","alert",2); } }) $.each(o.sectionList,function(i,sec){ sec.name = desktopnm[i]; }) }) } $("div#settings div#panel_r").load("/desktop/settingsections",function(){ $.getJSON("/desktop/get_desktop_settings",{"get":"sectionnames","desktopid":o.desktopId},function(sectionnames){ $("#desktop_names input").each(function(i){ $(this).val(sectionnames[i]); }) bindHandlers(); }) }) } var themes = function(){ var bindHandlers = function(){ // live change theme $(".theme_list > .ssl_item").click(function(){ o.changeTheme($(this).attr("id")); // $(".theme_list > li").removeClass('thmc1').data('clicked',null).find('.theme_name').removeClass('thmtxt'); // $(this).addClass('thmc1').data('clicked',true).find('.theme_name').addClass('thmtxt'); $.post("/desktop/save_desktop_settings",{"save":"theme","desktopid":o.desktopId,"theme":$(this).attr("id")},function(result,status){ if(status=="success"){ if(result[0].success=="true"){ o.notify("Theme Saved!!","success",2); loadthmc(); } else { o.notify("Theme saving failed!!","imp",2); } }else{ o.notify("Connection problem!!","alert",2); } }); }); // single select $('.ssl .ssl_item').each(function(){ $(this).on({ click: function(){ $(this).switchClass('','thmc1 active',300); $(this).siblings('.thmc1').switchClass('thmc1 active','',100); if( $(this).find('.ssl_des') ){ $(this).parents('.ssl').find('.ssl_des').removeClass('thmtxt'); $(this).find('.ssl_des').addClass('thmtxt'); } } }); }); $('.tinycanvas').each(function(){ var h = $(this).parent().height(), sh = $(this).siblings('.s_tab').height(); $(this) .css({'height': h-sh-24}) .tinyscrollbar({ axis: 'y'}) .find('.scrollbar') .delay(1500) .addClass('op00', 500); }); // tab var $anchor = $('.s_tab a[href*=#]'), $tabcontent = $('.st_c'); $anchor.each(function(){ $(this).click(function(){ var target = $(this).attr('href'); $anchor.removeClass('thmc2 thmtxt admtxt admbg').addClass('admtxt admbg'); $(this).toggleClass('thmc2 thmtxt admtxt admbg'); $tabcontent.hide(); $(target).show(); $('.tinycanvas').tinyscrollbar_update(); return false; }); }); $('.color-picker').miniColors({ change:function(hex){ var changewhat = $(this).attr("for"); var previewarea = $("#theme_preview_area"); switch(changewhat){ case "thmtxt": case "thmtxth": previewarea.find("."+changewhat).css({"color":hex}); break; case "g_sep": previewarea.find("."+changewhat).css({"border-color":hex}); break; case "background": previewarea.css({"background-color":hex}); break; default: previewarea.find("."+changewhat).css({"background-color":hex}); break; } } }); $('.theme_list li:first-child').data('clicked',true); // this line just for demo $('.theme_list li').hover(function(){ $(this).addClass('thmc1').find('.theme_name').addClass('thmtxt'); }, function(){ var c = $(this).data('clicked') ? '' : 'thmc1', t = $(this).data('clicked') ? '' : 'thmtxt'; $(this).removeClass(c).find('.theme_name').removeClass(t); }); $("a#theme_submit").click(function(){ o.confirm("Are you sure that you want to set this custom theme?",["Yes","No"],3,function(reply){ if(reply){ var colors = new Array; $("#color_input input").each(function(){ colors[$(this).attr("for")] = $(this).val(); }) var dhtml =""; $("head").find("#dyn_css").remove(); $("head").append(dhtml); $.post("/desktop/save_desktop_settings",{"save":"customtheme","desktopid":o.desktopId,"theme":dhtml},function(result,status){ if(status=="success"){ if(result[0].success=="true") o.notify("Custom theme saved!!","success",2); else o.notify("Custom theme saving failed!!","imp",2); }else{ o.notify("Connection problem!!","alert",2); } }) } }) }); $(".stock_wallpaper .ssl_item").click(function(){ var wallpapername = $(this).find("img").attr("alt"); o.changeWallpaper(wallpapername); }) } var loadthmc = function(){ $('.color-picker').each(function(){ var cc = $(this).attr('for'), hex, color; switch(cc){ case 'thmtxt': case 'thmtxth': hex = 'color'; break; case 'g_sep': hex = 'border-left-color'; break; default: hex = 'background-color'; break; } if(cc=="background") color = $("#theme_preview_area").css("background-color"); else color = $('#theme_preview_area .'+cc).css(hex); $(this).miniColors("value", o.rgb2hex(color)); }); } $("div#settings div#panel_r").load("/desktop/settingthemes",function(){ $.getJSON("/desktop/get_desktop_settings",{"get":"theme","desktopid":o.desktopId},function(theme){ $("#st1 ul.theme_list li#"+theme).addClass("thmc1").find("span").addClass("thmtxt"); bindHandlers(); loadthmc(); }) }) } $(o.contentHolder).empty().load("/desktop/"+target,function(){ bindHandlers(); themes(); }); }; this.loadWallpaper = function(wallpaper){ if(!wallpaper)wallpapernm = o.themesettings.background;else wallpapernm = wallpaper var ww = $(window).width(); var wh = $(window).height(); if(!wallpaper) $("img#thmbackground").attr({"src":"/"+o.themefolder+"/"+o.theme+"/images/"+wallpapernm,"width":ww}).css({"position":"fixed","top":"0px","left":"0px","z-index":"-1","height":"auto"}); else $("img#thmbackground").attr({"src":o.wallpaperPath+wallpaper,"width":ww}).css({"position":"fixed","top":"0px","left":"0px","z-index":"-1","height":"auto"}); $("div#bgover").css({"position":"fixed","top":"0px","left":"0px","z-index":"-1","width":ww,"height":wh}); }; this.loadIconCache = function(){ var imgs = $("ul.docklist img"); $.each(imgs,function(){ var setting_name = $(this).attr("id").replace("_icon",""); $(this).attr("src","/"+o.themefolder+"/"+o.theme+"/images/"+o.themesettings.icons[setting_name]) }) }; this.initializeWidgets = function(){ var elements = $("#group_wrapper li.element"); $.each(elements,function(){ var widget = $(this); if(widget.attr("data-category")=="widget"){ var widgename = widget.attr("data-content"); $.getScript("/desktop_widgets/"+widgename+"/"+widgename+".js",function(){ widget.find("div.appholder").load("/desktop_widgets/"+widgename+"/index.html.erb"); }); // $(this).find("div.appholder").append( $('').attr('href', "/desktop_widgets/"+widgename+"/css/"+widgename+".css")); } }) }; this.saveWallpaper = function(wallpaper){ $.post("desktop/save_desktop_settings",{"save":"wallpaper","wallpapernm":wallpaper,"desktopid":o.desktopId},function(result,status){ if(status=="success"){ if(result[0].success=="true") o.notify("Wallpaper saved!!","success",2); else o.notify("Wallpaper saving failed!!","imp",2); }else{ o.notify("Connection problem!!","alert",2); } }) } o.initialize(); } orbitDesktop.prototype.themefolder = "themes"; orbitDesktop.prototype.widgetfolder = "desktop_widgets"; orbitDesktop.prototype.desktopId = "1"; orbitDesktop.prototype.notifyImgPath = "temp"; orbitDesktop.prototype.wallpaperPath = "/assets/stockBackground/"; orbitDesktop.prototype.iconPath = "/assets/icons/"; orbitDesktop.prototype.currentLanguage = "en"; var uselessfunction = function(){ $.post("/desktop/temp_func",{sectionid:"4f83e7bbbd98eb041600001d"}); }