// JavaScript Document //harry //Inititialize function will initialize desktop //callback-method will be called after desktop controlled ajax call //container=true is the area where the view will be loaded //load = true is used to load the submenu item by default //response-type = "json"|"script"|"xml|html" default is json //autocomplete-list = "listname" an array from which autocomplete will be attached to its respective input or textarea //ajax-remote="get/delete/post/false" this will automatically bind the with remote ajax call. By default if the resposne is html, it ll be inserted in container=true, false option will not make any calls and also stop page refresh // content-holder = "jquery dom", the returned html of server will be put inside the dom mentioned in content-holder of a tag. this can be used in a tags as attributes //confirm-message ="Some message", this will prompt user with a confirm box and show the message before ajax call is made. //"toggle-onclick" = "classes to get toggle" this will toggle classes on toggle when a tags are clicked. //"delete-item" = "true" this will remove its respective item from the list. //for layout tinyscrollbar //content-layout="datalist|column|simple" datalist is for data list from database.. column is usually for forms and some other pages.. simple is without any columns, the page will be displayed as it is.. base width will be considered the default width for tinyscrollbar //base-width="300" this is the basic width of each column and in case of simple layout it ll be the final width //per-column="5" this option is only for datalist layout.. this ll specify number of enteries per column.. default is 4 //column="true" this option is only for column layout... the columns will be formed on this column=true attribute and it should be a div //item=true this attribute should be present in the li tag. li with this attribute are considered as a separate item. $.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.transitionTime = 500; this.currenthtml = "desktop.html"; this.currentface = "home"; this.desktopData = {}; this.tp = ""; this.sectionList; this.data_method; this.gridvar = null; 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(); var custom_load = window.location.hash; if(!custom_load){ $(o.contentHolder).empty().load("/desktop/desktop",function(){ o.desktopData["d_desktop"] = ""; o.initializeDesktop("d_desktop","",false); }) }else{ o.customPage(custom_load); } }); }) } } this.customPage = function(customload){ customload = customload.replace("#",""); if(customload.search("-") != -1){ customload = customload.split("-"); o.menu_item($(".docklist a[custom-load="+customload[0]+"]"),true,customload[1]); }else{ o.menu_item($(".docklist a[custom-load="+customload+"]"),true); } } 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 $(".docklist a").click(function(){ o.menu_item($(this)); return false; }) $('body').on({ click: function(){ if(!$(this).hasClass('active')){ o.sub_menu_item($(this)); } return false; }, mouseenter: function(){ if(!$(this).hasClass('active')){ $(this).switchClass('admtxt','thmc1 thmtxt',0); } }, mouseleave: function(){ var t = $(this).hasClass('active') ? '' : 'thmc1 thmtxt'; $(this).switchClass(t,'admtxt',0); } },'*[content-type=menu] a'); $("body").on("submit","form[form-type=ajax_form]",function(){ var callback_method = $(this).attr("callback-method"); var dt = null; dt = $(this).attr("response-type"); if(dt == null){ dt = "json"; } var options = { dataType : dt, success:function(responseText, statusText, xhr, $form){ if(typeof callback_method != "undefined"){ if(callback_method != ""){ window.o[o.data_method][callback_method](responseText,statusText,xhr,$form); } } }, error:function(){ o.notify("Please try again later!","imp"); } } $(this).ajaxSubmit(options); return false; }) $("body").on("click","*[ajax-remote]",function(){ var $e = $(this); var t = $e.attr("ajax-remote"); var classes_to_toggle = $e.attr("toggle-onclick"); var exe = $e.attr("callback-method"); // (typeof $e.attr("callback-method") == "function"? $e.attr("callback-method") : ""); if(classes_to_toggle){ $e.toggleClass(classes_to_toggle); } if(t == "false"){ if(exe){ window.o[o.data_method][exe](null,$e); } return false; } var ca = $e.attr("content-holder"); var a = function(){ $.ajax({ type : t, url : $e.attr("href"), success : function(data){ if(typeof data == "string"){ if(ca) $(ca).html(data); else{ o.layout_data(data); // $("div[container=true]").html(data); } } if(exe) window.o[o.data_method][exe](data,$e); if(t == "delete"){ if($e.attr("delete-item")=="true"){ var li_to_delete = $e.parentsUntil("li[item=true]").find("li[item=true]"); li_to_delete.slideUp(); } } } }); } if($e.attr("confirm-message")){ o.confirm({ buttons : ["Yes","No"], highlighted : 2, message : $e.attr("confirm-message") },function(value){ if(value){ a(); } }) }else{ a(); } return false; }) $(window).resize(function(){ var ww = $(window).width(); $("img#thmbackground").attr({"width":ww}); if( $('.tinycanvas').length > 0 ){ $('.tinycanvas').tinyscrollbar_update(); } if($(o.contentHolder).find("div.app_frame").length > 0){ $(o.contentHolder).find("div.app_frame").each(function(){ var app_holder_height = $(this).height() - 72; var app_holder_width = $(this).width(); $(this).find("div.app_holder").height(app_holder_height); $(this).find("div.app_holder iframe").attr({"height":app_holder_height,"width":app_holder_width}); }) } }); 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 split = function( val ) { return val.split( /,\s*/ ); } var extractLast = function( term ) { return split( term ).pop(); } var autocompleteListName = null; $("body").on("keydown","*[autocomplete-list]", function( event ) { autocompleteListName = $(this).attr("autocomplete-list"); if ( event.keyCode === $.ui.keyCode.TAB && $( this ).data( "autocomplete" ).menu.active ) { event.preventDefault(); } $(this).autocomplete({ minLength: 0, source: function( request, response ) { // delegate back to autocomplete, but extract the last term response( $.ui.autocomplete.filter( window.o[o.data_method][autocompleteListName], extractLast( request.term ) ) ); }, focus: function() { // prevent value inserted on focus return false; }, select: function( event, ui ) { var terms = split( this.value ); // remove the current input terms.pop(); // add the selected item terms.push( ui.item.value ); // add placeholder to get the comma-and-space at the end terms.push( "" ); this.value = terms.join( ", " ); return false; } }) }) }; this.layout_data = function(h){ var $e = $("
"); $e.html(h); var column_container = $e.find("div.overview"); var layout = column_container.attr("content-layout"), base_width = parseInt(column_container.attr("base-width")), no_of_entries,temp_div = $("
"),total_columns=0; switch (layout){ case "simple": total_columns++; temp_div.append(column_container.html()); break; case "datalist": no_of_entries = (typeof column_container.attr("per-column") != "undefined"? parseInt(column_container.attr("per-column")) : 4); var height_percentage = 100/no_of_entries; var entries = column_container.find("li[item=true]"),x = 0; entries.each(function(i,li){ if(x == 0){ column = $("
'); $("div[container=true]").find("div.tinycanvas").prepend('
'); $("div[container=true] div.overview").html(temp_div.html()); if(isNaN(base_width)){ o.tinyscrollbar_ext({ main : ".tinycanvas", }) }else{ o.tinyscrollbar_ext({ main : ".tinycanvas", fill : base_width * total_columns }) } } this.menu_item = function(dom,customload,submenuitem){ if(!customload)customload=false; var target = dom.attr("id"); var url = dom.attr("href"); o.data_method = dom.attr("callback-method"); if(o.currenthtml!=target){ if(o.desktopData[o.currentface] == "undefined") o.desktopData[o.currentface] = ""; o.desktopData[o.currentface] = $(o.contentHolder).html(); if(customload){ $(o.contentHolder).html("
"); } $("#content").hide("drop",o.transitionTime,function(){ o.currenthtml = target; o.currentface = target; var cache = false; if(!o.desktopData[o.currentface]){ $(o.contentHolder).empty().load(url,function(data){ if(typeof o.data_method != "undefined"){ if(o.data_method != "") window.o[o.data_method](target,url,cache); } try{ if(!customload) o.sub_menu_item($(o.contentHolder).find("*[content-type=menu] a[load=true]"),data); else{ if(submenuitem) o.sub_menu_item($(o.contentHolder).find("*[content-type=menu] a[custom-load="+submenuitem+"]")); else o.sub_menu_item($(o.contentHolder).find("*[content-type=menu] a[load=true]"),data); } }catch(EX){} }) }else{ $(o.contentHolder).html(o.desktopData[o.currentface]); try{ if(!customload) o.sub_menu_item($(o.contentHolder).find("*[content-type=menu] a[load=true]"),data); else{ if(submenuitem) o.sub_menu_item($(o.contentHolder).find("*[content-type=menu] a[custom-load="+submenuitem+"]")); else o.sub_menu_item($(o.contentHolder).find("*[content-type=menu] a[load=true]"),data); } }catch(EX){} cache = true; if(typeof o.data_method != "undefined"){ if(o.data_method != "") window.o[o.data_method](target,url,cache); } } }); } } this.sub_menu_item = function(dom,data){ var sub_data_method = dom.attr('callback-method'); if(sub_data_method){ $.ajax({ url : dom.attr("href"), type : "get", success : function(data){ o.layout_data(data); if(typeof o.data_method != "undefined"){ if(o.data_method != ""){ if(typeof sub_data_method != "undefined"){ if(sub_data_method != ""){ window.o[o.data_method][sub_data_method](); } } } } } }) o.highlight_sub_menu_item(dom); } if(dom.length == 0) o.layout_data(data); // $('*[content-type=menu] a').removeClass('thmc1 thmtxt active'); // dom.addClass('thmc1 thmtxt active'); } this.highlight_sub_menu_item = function(no){ $('*[content-type=menu] a').removeClass('thmc1 thmtxt active'); var dom; if(typeof no == "number"){ dom = $('*[content-type=menu] a').eq(no); dom.addClass('thmc1 thmtxt active'); }else if(typeof no == "object"){ dom = no; dom.addClass('thmc1 thmtxt active'); } return dom; } this.initializeDesktop = function(target,url,cache){ //this is for initializing main desktops that are sections and tiles if(!target)target = "desktop"; var bindHandlers = function(){ // this function will bind all the handlers in the desktop // var groupWrapperWidth = 0; // $("div#desktop .group").each(function(){groupWrapperWidth+=$(this).outerWidth(true);}); // var grps = new Array; // $("div#desktop #group_wrapper").css("width",groupWrapperWidth); // var first = true; // $("div#desktop .g_col").sortable({ // connectWith: ".g_col", // tolerance: 'pointer' , // revert: 300, // containment: '#group_wrapper', // helper: 'clone', // stop:function(){ // first = true; // var grpwidth = 0; // for(i in grps){ // var grp = grps[i]; // if(grp.find(".element").length == 0){ // grp.animate({"width":"0px"},500,function(){$(this).remove();}); // grpwidth+=225; // } // } // grps = []; // $("#group_wrapper").width($("#group_wrapper").width()-grpwidth); // }, // start:function(){ // $("#group_wrapper").find("div.group").each(function(i,par){ // var nextnumber = $(this).find("ul").length; // $newcol = $('