diff --git a/app/assets/images/desktop/chrome.png b/app/assets/images/desktop/chrome.png new file mode 100755 index 00000000..5661a687 Binary files /dev/null and b/app/assets/images/desktop/chrome.png differ diff --git a/app/assets/images/desktop/compatibility_bg.jpg b/app/assets/images/desktop/compatibility_bg.jpg new file mode 100755 index 00000000..7d52cd0e Binary files /dev/null and b/app/assets/images/desktop/compatibility_bg.jpg differ diff --git a/app/assets/images/desktop/firefox.png b/app/assets/images/desktop/firefox.png new file mode 100755 index 00000000..c7f06487 Binary files /dev/null and b/app/assets/images/desktop/firefox.png differ diff --git a/app/assets/images/desktop/ie.png b/app/assets/images/desktop/ie.png new file mode 100755 index 00000000..ef5f454d Binary files /dev/null and b/app/assets/images/desktop/ie.png differ diff --git a/app/assets/images/desktop/opera.png b/app/assets/images/desktop/opera.png new file mode 100755 index 00000000..484b56af Binary files /dev/null and b/app/assets/images/desktop/opera.png differ diff --git a/app/assets/images/desktop/safari.png b/app/assets/images/desktop/safari.png new file mode 100755 index 00000000..163e4c8a Binary files /dev/null and b/app/assets/images/desktop/safari.png differ diff --git a/app/assets/images/desktop/select2/select2.png b/app/assets/images/desktop/select2/select2.png new file mode 100755 index 00000000..7f378627 Binary files /dev/null and b/app/assets/images/desktop/select2/select2.png differ diff --git a/app/assets/images/desktop/select2/select2x2.png b/app/assets/images/desktop/select2/select2x2.png new file mode 100755 index 00000000..4bdd5c96 Binary files /dev/null and b/app/assets/images/desktop/select2/select2x2.png differ diff --git a/app/assets/images/desktop/select2/spinner.gif b/app/assets/images/desktop/select2/spinner.gif new file mode 100755 index 00000000..5b33f7e5 Binary files /dev/null and b/app/assets/images/desktop/select2/spinner.gif differ diff --git a/app/assets/javascripts/desktop/orbitdesktop.js b/app/assets/javascripts/desktop/orbitdesktop.js index e241c2b2..fc945390 100755 --- a/app/assets/javascripts/desktop/orbitdesktop.js +++ b/app/assets/javascripts/desktop/orbitdesktop.js @@ -6,7 +6,8 @@ //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 +//autocomplete = "url" this will automatically convert textarea or input to autocomplete. +//autocomplete-format = "--:[text,email]" first one is seperator which will be put on between every field. //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. @@ -37,6 +38,15 @@ var sortAscending = function(a, b) { var sortDescending = function(a, b) { return $(a).find("h1").text() < $(b).find("h1").text() ? 1 : -1; }; + +Array.prototype.indexOfObject = function(object){ + for(i = 0;i < this.length; i++){ + if(this[i] === object) + break; + } + return i; +} + jQuery.ajax = (function(_ajax){ var protocol = location.protocol, @@ -107,9 +117,9 @@ var orbitDesktop = function(dom){ // o = this; this.contentHolder = dom; this.themesettings = ""; - this.theme = "4f8d3f493b67fcd05f086359"; + this.theme = null; this.transitionTime = 1000; - this.currenthtml = "desktop.html"; + this.currenthtml = "home"; this.currentface = "home"; this.desktopData = {}; this.tp = ""; @@ -124,22 +134,21 @@ var orbitDesktop = function(dom){ var theme = o.theme; var custom = false; o.getlocation(); + o.minimizeBarManager(); $.getJSON("/desktop/get_desktop_settings",{"get":"desktop","desktopid":o.desktopId},function(desktopSettings){ if(desktopSettings){ - if(desktopSettings.theme!="custom"){ - theme = desktopSettings.theme; - }else{ - theme = "4f8d3f493b67fcd05f086359"; + if(desktopSettings.theme=="custom"){ custom = true; } + theme = desktopSettings.theme; 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)); + $.getJSON("/desktop_themes/settings",{"id":theme},function(ts){ + o.themesettings = ts; + $('head').append( $('').attr('href', o.themesettings.css)); if(custom){ $("head").find("#dyn_css").remove(); $("head").append(customtheme); @@ -148,7 +157,6 @@ var orbitDesktop = function(dom){ o.loadWallpaper(customwallpaper); o.bindDesktopEvents(); o.loadIconCache(); - o.getlocation(); var custom_load = window.location.hash; if(!custom_load){ $(o.contentHolder).empty().load("/desktop/desktop",function(){ @@ -173,10 +181,10 @@ var orbitDesktop = function(dom){ }; 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); + $.getJSON("/desktop_themes/settings",{"id":theme},function(ts){ + o.themesettings = ts; $('head').find("#dyn_css").remove(); - $('head').append( $('').attr('href', "/"+o.themefolder+"/"+theme+"/css/"+ts.css)); + $('head').append( $('').attr('href', o.themesettings.css)); o.loadWallpaper(); o.loadIconCache(); }) @@ -315,7 +323,9 @@ var orbitDesktop = function(dom){ $(window).resize(function(){ // var ww = $(window).width(); // $("img#thmbackground").attr({"width":ww}); - if( $('.tinycanvas').length > 0 ){ $('.tinycanvas').tinyscrollbar_update('relative'); } + // if( $('.tinycanvas').length > 0 ){ + $('.tinycanvas').tinyscrollbar_update('relative'); + // } if($(o.contentHolder).find("div.app_frame").length > 0){ $(o.contentHolder).find("div.app_frame").each(function(){ var app_holder_height = $(this).height() - 72; @@ -343,56 +353,36 @@ var orbitDesktop = function(dom){ 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; - } - }); - }); + // $("body").on("keydown","*[autocomplete]", function( event ) { + // var autocompleteList = $(this).attr("autocomplete-list"); + // console.log($(this)); + + // }); + // }; this.layout_data = function(h){ - var $e; - var column_container,layout, base_width, total_width, gutter, no_of_entries = 0, pagination_link, pagination_variable; + var $e; + var column_container,layout, base_width , no_of_entries = 0, pagination_link , pagination_variable, gutter, total_width; o.paging = true; gutter = (!isNaN(gutter)) ? gutter : 12; this.layout_data.generate_layout_html = function(l){ $e = $("
"); $e.html(l); - column_container = $e.find("div.overview"); - layout = column_container.attr("content-layout"), base_width = parseInt(column_container.attr("base-width")), no_of_entries,total_columns=0, pagination_link = column_container.attr("pagination-link"), pagination_variable = column_container.attr("pagination-var"); + column_container = $e.find("div.overview"), + layout = column_container.attr("content-layout"), + base_width = parseInt(column_container.attr("base-width")), + no_of_entries,total_columns = 0, + pagination_link = column_container.attr("pagination-link"), + pagination_variable = column_container.attr("pagination-var"); var temp_div = $("
"); var entries = []; switch (layout){ - case "simple": + case "simple": total_columns++; temp_div.append(column_container.html()); + total_width = "auto"; break; case "datalist": no_of_entries = (typeof column_container.attr("per-column") != "undefined"? parseInt(column_container.attr("per-column")) : 4); @@ -411,7 +401,10 @@ var orbitDesktop = function(dom){ x = 0; temp_div.append(column); } - }); + }) + if(x != 0){ + temp_div.append(column); + } } total_width = (!isNaN(base_width)) ? (base_width + gutter*2 +1) * total_columns : null; break; @@ -419,24 +412,40 @@ var orbitDesktop = function(dom){ entries = column_container.find("div[column=true]"),x = 0,column; if(entries.length!=0){ entries.each(function(i,ul){ - column = $("
'); - $("div[container=true]").find("div.tinycanvas").prepend('
'); + var check_container = $("
").html(h).find("div[container=true]"); + if(check_container.length > 0){ + $("div[container=true]") + .html(check_container.html()) + .find("div.overview") + .wrap('
'); + }else{ + $("div[container=true]") + .html(h) + .find("div.overview") + .wrap('
'); + } + $("div[container=true]") + .find("div.tinycanvas") + .prepend('
'); var f = o.layout_data.generate_layout_html(h) $("div[container=true] div.overview").html(f.markup); var settings = {main : ".tinycanvas"}; @@ -458,7 +467,12 @@ var orbitDesktop = function(dom){ } } } + // call other functions here o.tinyscrollbar_ext(settings,tsettings); + o.simple_drop_down(); + o.autocomplete(); + o.use_select2(); + o.check_simple_layout(); } this.paging = true; this.pagination = function(link,variable,page_no){ @@ -538,7 +552,7 @@ var orbitDesktop = function(dom){ var target = dom.attr("id"); var url = dom.attr("href"); if(!url)return false; - o.lastlink = url; + o.data_method = dom.attr("callback-method"); if(o.currenthtml!=target){ if(o.desktopData[o.currentface] == "undefined"){ @@ -576,20 +590,22 @@ var orbitDesktop = function(dom){ $(o.contentHolder).html(o.desktopData[o.currentface]); try{ if(!customload){ - o.sub_menu_item($(o.contentHolder).find("*[content-type=menu] a[load=true]")); + o.sub_menu_item($(o.contentHolder).find("*[content-type=menu] a[load=true]"),o.desktopData[o.currentface]); }else{ if(submenuitem) - o.sub_menu_item($(o.contentHolder).find("*[content-type=menu] a[custom-load="+submenuitem+"]")); + o.sub_menu_item($(o.contentHolder).find("*[content-type=menu] a[custom-load="+submenuitem+"]"),o.desktopData[o.currentface]); else - o.sub_menu_item($(o.contentHolder).find("*[content-type=menu] a[load=true]")); + o.sub_menu_item($(o.contentHolder).find("*[content-type=menu] a[load=true]"),o.desktopData[o.currentface]); } }catch(EX){} - cache = true; + + cache = (o.lastlink == "/desktop/app_manager" ? false : true); if(typeof o.data_method != "undefined"){ if(o.data_method != ""){ window.o[o.data_method](target,url,cache); } } + header_ani(); } }); $('#header') @@ -606,6 +622,7 @@ var orbitDesktop = function(dom){ $(this).hide().delay(i*100).fadeIn(600,'easeInOutQuint'); }); } + o.lastlink = url; } this.sub_menu_item = function(dom,data){ var sub_data_method = dom.attr('callback-method'); @@ -634,23 +651,15 @@ var orbitDesktop = function(dom){ // $('*[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 target = (!target) ? 'desktop' : target; var bindHandlers = function(){ // this function will bind all the handlers in the desktop var dragged = null,draggable,lastpos = []; + /* Hotfix - Part 1 */ + // var items = $(".gridster ul li"); + // items.detach(); + o.gridvar = $(".grid ul").find("> li ") .mousedown(function(e){ !draggable; @@ -662,26 +671,43 @@ var orbitDesktop = function(dom){ }) .end() .gridster({ + max_rows: 4, + shift_larger_widgets_down: false, widget_margins: [6, 6], widget_base_dimensions: [120, 120], + serialize_params: function($w, wgd) { return { col: wgd.col, row: wgd.row, id: $w.data("id") } }, draggable : { start: function(event, ui){ dragged.addClass("noClick"); }, stop: function(event, ui){ - for (var i = 1; i <= 30; i++) { - // var celement = $(".grid ul .widget[data-col="+i+"]:last"); - $(".grid ul .widget[data-col="+i+"]").each(function(){ - var pos = $(this).position(); - if(pos && (pos.top + $(this).height() + 6) > 550){ - revertbacktiles(); - } - }); - } + // for (var i = 1; i <= 30; i++) { + // // var celement = $(".grid ul .widget[data-col="+i+"]:last"); + // $(".grid ul .widget[data-col="+i+"]").each(function(){ + // var pos = $(this).position(); + // if(pos && (pos.top + $(this).height() + 6) > 550){ + // revertbacktiles(); + // } + // }); + // } + $('.tinycanvas').tinyscrollbar_update('relative'); + var newpos = o.gridvar.serialize(); + $.post("/desktop/newpositions",{"newpositions":newpos}); } } }) .data('gridster'); + + /* Hotfix - Part 2 */ + // $.each(items , function (i, e) { + // var item = $(this); + // var columns = parseInt(item.attr("data-sizex")); + // var rows = parseInt(item.attr("data-sizey")); + // var col = parseInt(item.attr("data-col")); + // var row = parseInt(item.attr("data-row")); + // o.gridvar.add_widget(item, columns, rows, col, row); + // }); + var revertbacktiles = function(){ lastpos.push({"col":"","row":""}); $(".grid ul li").each(function(i){ @@ -710,19 +736,7 @@ var orbitDesktop = function(dom){ dragged.removeClass("noClick"); }); - var element = $('.gridster li'); - $.each(element, function(i){ - if($(this).attr("data-category")=="app" && $(this).find('.text_wrapper').length < 1){ - $(this).find('.appname').wrapInner(''); - var w = $(this).find('.text_wrapper').width(); - if (w > 96){ - var text = $(this).find('.text_wrapper').text(); - slice = text.substr(0,12); - $(this).find('.text_wrapper').attr('title',text).text(slice+'...'); - } - } - }); - + o.appname_substr('.gridster li'); o.simple_drop_down(); o.tinyscrollbar_ext({ main: '.tinycanvas' @@ -731,33 +745,54 @@ var orbitDesktop = function(dom){ var loadTiles = function(id){ //This will load tiles for a specific desktop .. id of section has to be passed here to load tiles $("#desktop #group_wrapper").empty(); $.getJSON("/desktop/getgroups",{sectionid:id},function(tiles){ - tiles.sort(o.sortJSON("position",true,parseInt)); - var tilecolors = o.themesettings.tilecolor; + // tiles.sort(o.sortJSON("position",true,parseInt)); + var tilecolors = (o.themesettings.tilecolor ? o.themesettings.tilecolor : ["thmc1","thmc2","thmc3","thmc4"]) ; var totaltiles_in_a_row = 4; var opacity = ["op07","op08","op09",""]; - var row = 1, col = 1, x = 1, y = 1; + var row = 0, col = 1, x = 1, y = 1, total_x = 0, prev_y = 0; var $group = $('
'); var $ul = $(''); $.each(tiles,function(i,tile){ - if(row >= 4){ - row = 1; - col++; - } var shape = tile.shape.split(" "); - x = parseInt(shape[0].substr(1,1)); - y = parseInt(shape[1].substr(1,1)); + // if(tile.title == "Weather")console.log("Big - row : " + tile.row + ", col : "+ tile.column); + // if(tile.title == "Google Scholar")console.log("Scholar - row : " + tile.row + ", col : "+ tile.column); + + // if(total_x % 2 != 0) + // row = row - y; + // if(i == 7)tile.row = null; + if(tile.row){ + row = tile.row; + col = tile.column; + x = parseInt(shape[0].substr(1,1)); + y = parseInt(shape[1].substr(1,1)); + }else{ + x = parseInt(shape[0].substr(1,1)); + if(total_x % 2 == 0){ + row = row + y; + }else if(x == 1){ + col++; + } + y = parseInt(shape[1].substr(1,1)); + total_x = total_x + ( x * y ); + prev_y = y; + if(total_x > 8){ + row = 1; + total_x = 0; + col++; + } + } var tilecolor = tilecolors[Math.floor(Math.random()*tilecolors.length)]; var op = opacity[Math.floor(Math.random()*opacity.length)]; var f = (tile.fullsize?"fullsize":null); if(tile.data_category == "app"){ - $li = $('
  • '+tile.title+'

  • '); + $li = $('
  • '+tile.title+'

  • '); } else { $li = $('
  • '+tile.title+'

  • '); } - row = row + y; + $ul.append($li); }); @@ -770,7 +805,7 @@ var orbitDesktop = function(dom){ } var loadSectionList = function(){ //This will load the section list from the db $.getJSON("/desktop/getsectionlist",{desktopid:o.desktopId},function(sectionlist){ - o.sectionList = eval(sectionlist); + o.sectionList = sectionlist; $.each(sectionlist,function(i,section){ var tempstyle=""; if(i==0){ @@ -805,6 +840,7 @@ var orbitDesktop = function(dom){ $("#desktop #section_list").append($('
  • '+section.name+'
  • ')); }); bindSecondaryHandlers(); + o.simple_drop_down(); }else{ loadSectionList(); loadTiles(o.sectionId); @@ -815,52 +851,116 @@ var orbitDesktop = function(dom){ $.post("desktop/twitter",function(){}); }; - this.initializeAppSearch = function(target,url,cache){ //this is application search ie is app manager initialization - var searchArray,allApps; + this.initializeAppManager = function(target,url,cache){ //this is application search ie is app manager initialization + var searchArray, allApps; + var bindHandlers = function(){ // bind handler for app manager page - var gn = $('.g_col').length, - gw = $('.g_col').outerWidth(true); - $("#app_manager #group_wrapper").css("width",gn*gw); + // var gn = $('.g_col').length, + // gw = $('.g_col').outerWidth(true); + // $("#app_manager #group_wrapper").css("width",gn*gw); // $("div#app_manager .group_search").css("width",$(window).width()-200); - //for textbox search - $("#app_manager #searchbox").focus(function(){$(this).val("");}).keyup(function(e){ - if($(this).val()){ - $("#app_manager .search_result").empty(); - $("#app_manager #seperator").hide(); - searchArray = $("#app_manager .element:containsi("+$(this).val()+")"); - if(searchArray.length>0){ - $("#app_manager #seperator").show(); - var i = 0; - var $column; - searchArray.each(function(){ - i++; - if(i == 1){ - $column = $("
    "); + //for textbox search + var $elements = $("#app_manager .element"), + $result = $("#app_manager .search_result"), + $appinfo = $("#app_info"), + $applist = $("#app_list"), + $apptitle = $appinfo.find(".app_info_name"), + $appicon = $appinfo.find(".app_info_icon"), + $appinfolist = $appinfo.find(".app_info_list"), + $canvas = $result.parents('.overview'), + current_width = $canvas.css('width'); + + $("#app_manager #searchbox") + .focus(function(){ + $(this).val(""); + }) + .keyup(function(e){ + var query = $(this).val(); + if(query){ + $appinfo.hide().attr('style',''); + $result.empty().show(); + $applist.hide(); + + // searchArray = $elements.filter(":containsi("+$(this).val()+")").clone(1,1); + // searchArray = $('#app_list').find('[data-title*="'+query+'"]').clone(1,1); + searchArray = $elements.filter(function(){ + var matcher = new RegExp(query, "i"); + return matcher.test( $(this).attr('data-title') ); + }).clone(1,1); + + if(searchArray.length > 0){ + // searchArray.each(function(){ + // $(this).hide("fold","fast"); + // }) + // $("#app_manager #seperator").show(); + var i = 0, c = 1; // c for numbers of columns + var $column; + searchArray.each(function(){ + i++; + if(i == 1){ + $column = $('
    '); + } + $column.append($(this)); + $(this).show(); + if(i == 4){ + $result.append($column); + i = 0; + c++; + } + }); + if(i != 0){ + $result.append($column); + c*=132; + searchArray + .eq(0) + .parents('.overview') + .animate({ + 'width': c + },0, function(){ + $(this) + .parents('.tinycanvas') + .tinyscrollbar_update(); + }); } - var $newelement = $(''); - $column.append($newelement); - if(i == 4){ - $("#app_manager .search_result").append($column); - i = 0; - } - }) - if(i != 0){ - $("#app_manager .search_result").append($column); + } else { + var $no_result = $('
    No result for
    '); + $no_result + .find('b') + .text('"'+$(this).val()+'"') + .end() + .show() + .appendTo($result); + $canvas.animate({ + 'width':252 + }, 0, function(){ + $(this) + .parents('.tinycanvas') + .tinyscrollbar_update(); + }); } + } else if( query == "" ) { + info_close(); + $result.empty(); + $applist.show(); + $canvas.css('width',current_width); } - }else{$("#app_manager #seperator").hide();$("#app_manager .search_result").empty();} - }).blur(function(){$(this).val("Search");}); + }) + .blur(function(){ + if($(this).val()==""){ + $(this).val("Search"); + } + }); //for Alphabet sorting $("#app_manager #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); + allApps = $("div#app_manager .element").sort(sortAscending); break; case "descending": $(this).attr("href","ascending").find(".thmtxt").text("Alphabet [A-Z]"); - allApps = $("#app_manager .group_search .element").sort(sortDescending); + allApps = $("#app_manager .element").sort(sortDescending); break; } $("#app_manager #app_list").empty(); @@ -876,173 +976,166 @@ var orbitDesktop = function(dom){ $('.g_col.col'+ colindex).append(app); } }); + elementSetting(); return false; }); - } - var loadApps = function(){ //this load apps for sorting and searching - $.getJSON("/desktop/getapplist",{desktopid:o.desktopId},function(appss){ - var count = 0, colindex = 0; - $('#app_list').append('
    '); - $.each(appss,function(i,apps){ - $.each(apps,function(i,app){ - var $app; - count++; - $app = $('

    '+app.title+'

    '); - if( count > 4 ){ - count = 1, colindex+=1; - $('#app_list').append('
    '); - $('.g_col.col'+ colindex).append($app); - } else { - $('.g_col.col'+ colindex).append($app); - } - }); - }); + var elementSetting = function(){// for element setting load + $elements.click(function(){ + var $e = $(this); + $apptitle.text($e.data("title")); + $appicon.attr("src",$e.find("img").attr("src")); + $appinfolist.find("[info=app_version]").text($e.data("version")); + var dt = new Date($e.data("update")); + $appinfolist.find("[info=app_last_update]").text(dt.toUTCString()); + $appinfolist.find("[info=app_author]").text($e.data("author")); + $appinfo + .find(".app_info_header") + .attr('style','') + .css({ + "background-color": $e.data("background"), + "color": $e.data("text-color") + }); + var sections = elementSettingsData[$e.data("id")].sections; + + var sectionids = new Array(); + $.each(sections,function(i,sec){ + sectionids.push(sec.id); + }) + + $appinfolist.find("[info=app_section_activation]").empty(); + $.each(o.sectionList,function(i,sec){ + + var present = $.inArray(sec._id,sectionids); + if(present == -1){ + $sectionswitch = $('
    Off
    '); + }else{ + $sectionswitch = $('
    On
    '); + } + $appinfolist.find("[info=app_section_activation]").append($sectionswitch); + }); + info_open(); + o.simple_switch(function(dom){ + var options = { + "status" : dom.is(":checked"), + "id" : dom.data("widget"), + "section_id" : dom.data("section"), + "type" : dom.data("type") + } + var sectionDetails = o.sectionList.filter(function(o){return(o._id == dom.data("section"))})[0]; + $.ajax({ + url : "/desktop/appactivation", + type : "post", + datatype : "json", + data : options, + success : function(data){ + if(data.success == "true"){ + if(dom.is(":checked")){ console.log("true"); + elementSettingsData[$e.data("id")].sections.push({"id" : dom.data("section"),"name":sectionDetails.name}); + o.notify("Added to " + sectionDetails.name,"success"); + }else{ + var index = elementSettingsData[$e.data("id")].sections.indexOfObject(elementSettingsData[$e.data("id")].sections.filter(function(a){return a.id == dom.data("section")})[0]); + elementSettingsData[$e.data("id")].sections.splice(index,1); + o.notify("Removed from " + sectionDetails.name,"success"); + } + } + } + }); + }); + return false; + }); + } + + $appinfo.find("a.panel_close").click(function(){ + info_close(); + return false; + }); + + var info_open = function(){ + if($appinfo.is(":hidden")){ + $('.overview').stop().animate({'width': '+=480'},0 , function(){ + $('.tinycanvas').tinyscrollbar_update(); + }); + $appinfo + .css({ + 'display': 'block', + 'margin-left': -480 + }) + .delay(300) + .animate({ + 'margin-left': 0 + }, 500, 'easeInOutQuint'); + } else { + $('.tinycanvas').tinyscrollbar_update(); + } + } + + var info_close = function(){ + if( $appinfo.is(":visible") ){ + $appinfo + .stop() + .animate({ + 'margin-left': -480 + },500 , 'easeInOutQuint', function(){ + $('.overview').animate({'width': '-=480'}, 0, function(){ + $('.tinycanvas').tinyscrollbar_update(); + }); + $(this).attr("style",""); + }); + } else { + $('.tinycanvas').tinyscrollbar_update(); + } + } + $(window).on('keydown', function(){ + if($('#searchbox').val() == 'Search'){ + $('#searchbox').focus(); + } + }); + elementSetting(); + o.appname_substr('#group_wrapper .element'); + o.check_simple_layout(); + } + var elementSettingsData = {}; + var loadApps = function(){ //this load apps for sorting and searching + $('#app_info').attr('style',''); + $('.search_result').hide().text(""); + $('#app_list').empty().show(); + $.getJSON("/desktop/getapplistforManager",{desktopid:o.desktopId},function(apps){ + var count = 0, + colindex = 0, + apps_sum = apps.length, + col_sum; + + col_sum = (apps_sum - (apps_sum % 4)) / 4 + 1; + + $('#app_list') + .css('width',col_sum * 132) + .append('
    '); + + $.each(apps,function(i,app){ + var $app; + count++; + elementSettingsData[app.id] = {"sections" : app.sections}; + $app = $('

    '+app.title+'

    '); + if( count > 4 ){ + count = 1, colindex+=1; + $('#app_list').append('
    '); + $('.g_col.col'+ colindex).append($app); + } else { + $('.g_col.col'+ colindex).append($app); + } + }); bindHandlers(); }); } - if(cache){ - bindHandlers(); - } else { + // if(cache){ + // bindHandlers(); + // } else { loadApps(); - } + // } }; - this.initializeSectionsManager = function(target,url,cache){ // this is init function for section manager - var elementParent,element,slabel; - var bindHandlers = function(){ // this is bind handler for section manager page - var groupWrapperWidth = 0; - $("#sections .group").each(function(){groupWrapperWidth+=$(this).width();}) - groupWrapperWidth+=200; - groupWrapperHeight = $(".group").height() + 20; - $("#group_wrapper").width(groupWrapperWidth); + - var sortingoptions = { - start:function(){ - slabel = $(this).parent().siblings('.section_label'); - slabel.find('li:hidden').stop(1,1).fadeIn(500); - }, - stop:function(){ - slabel.find('li:not(:nth-child(1))').stop(1,1).fadeOut(500); - } - } - $("#sections #group_wrapper .appgroup").sortable(sortingoptions); - - $("#sections .section_label li:not(:nth-child(1))").droppable({ - drop:function(event, ui){ - elementParent = ui.draggable.parents('.group'); - elementParentUl = ui.draggable.parents(".appgroup"); - var $item = $( this ), - $list = $( '#'+$item.data("category") ); - if($list.children('.element').length>=24){ - o.notify("Section is full.","alert"); - }else{ - ui.draggable.hide('fast',function(){ - var newul = false; - if($list.find("ul").length == 0){ - $list.append(('
      ')); - newul = true; - }else if($list.find("ul:eq(0) li").length == 7){ - $list.append(('
        ')); - newul = true; - } - $(this).appendTo($list.find("ul:last")).fadeIn(); - var next_group = elementParent.find(".grp ul").eq(elementParentUl.index() + 1); - if(elementParentUl.index() == 0){ - if(elementParentUl.find("li").length < 7){ - - var element_to_shift = next_group.find("li").eq(0); - if(element_to_shift.length != 0){ - elementParentUl.append(element_to_shift); - } - } - } - - if(next_group.find("li").length == 0){ - next_group.remove(); - } - if(elementParentUl.find("li").length == 0){ - elementParentUl.remove(); - } - - if(elementParent.find(".grp ul").length == 0){ - elementParent.find(".grp").addClass("no_app"); - }else{ - elementParent.find(".grp").removeClass("no_app"); - } - - if(newul){ - $("#sections #group_wrapper .appgroup").sortable(sortingoptions); - $list.removeClass("no_app"); - } - }); - - $.post("/desktop/save_desktop_settings",{"save":"appnewsection","appid":ui.draggable.attr("id"),"newsectionid":$(this).data("content"),"desktopid":o.desktopId}); - if(o.sectionId == $(this).data("content") || o.sectionId == elementParent.attr("id")){ - o.desktopData["home"]=""; - } - } - $(this).find('span.tile').addClass('op06',400); - }, - over:function(){ - $(this).find('span.tile').removeClass('op06'); - }, - out:function(){ - $(this).find('span.tile').addClass('op06'); - }, - accept: '.to_drop' - }); - }; - var loadApps = function(){ // this loads apps from db to in each sections - $.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(".section_grp").append($lii); - } - } - z++; - - $("#group_wrapper").append($group); - } - - var x = 0; - $.each(appss,function(i,apps){ - x = 0; - $.each(apps,function(y,app){ - x++; - if(x == 1){ - $ul = $('
          '); - } - $li = $('
        • '+app.title+'

        • '); - $ul.append($li); - if(x == 7){ - $("#group_wrapper #section"+(i+1)).append($ul); - $("#group_wrapper #section"+(i+1)).removeClass("no_app") - x = 0; - } - }) - if(x != 0){ - $("#group_wrapper #section"+(i+1)).append($ul); - $("#group_wrapper #section"+(i+1)).removeClass("no_app") - } - }) - bindHandlers(); - }) - } - if(cache) - bindHandlers(); - else - loadApps(); - - }; this.initializeSettings = function(target,url,cache){ //this is to initialize setting page this.initializeSettings.account = function(data){} @@ -1261,17 +1354,17 @@ var orbitDesktop = function(dom){ }) } - $.getJSON("/otheraccounts/getaccounts",function(accounts){ - $.each(accounts,function(i,account){ - $ul = $("#"+account.type+"_connection"); - $ul.find("input[type=text]").replaceWith("
          "+account.email+"
          ") - $ul.find("input[type=password]").replaceWith("
          ••••••
          "); - $ul.find("a[for=new]").text("Edit").attr("for","edit"); - $ul.find("a[for=delete]").show(); - $ul.find(".c_status").text("Connected").addClass("c_status_on"); - }) - bindHandlers(); - }) + // $.getJSON("/otheraccounts/getaccounts",function(accounts){ + // $.each(accounts,function(i,account){ + // $ul = $("#"+account.type+"_connection"); + // $ul.find("input[type=text]").replaceWith("
          "+account.email+"
          ") + // $ul.find("input[type=password]").replaceWith("
          ••••••
          "); + // $ul.find("a[for=new]").text("Edit").attr("for","edit"); + // $ul.find("a[for=delete]").show(); + // $ul.find(".c_status").text("Connected").addClass("c_status_on"); + // }) + // bindHandlers(); + // }) } @@ -1420,9 +1513,8 @@ var orbitDesktop = function(dom){ } this.loadWallpaper = function(wallpaper){ // this is to load new wallpaper - wallpapernm = (!wallpaper) ? o.themesettings.background : wallpaper; if(!wallpaper){ - $("#thmbackground").attr("src","/"+o.themefolder+"/"+o.theme+"/images/"+wallpapernm); + $("#thmbackground").attr("src",o.themesettings.background); } else { $("#thmbackground").attr("src",o.wallpaperPath+wallpaper); } @@ -1432,7 +1524,7 @@ var orbitDesktop = function(dom){ var imgs = $(".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).attr("src","/assets/desktop/icons/"+o.themesettings.icons[setting_name]) }) }; this.initializeWidgets = function(){ // this function will initialize all the widgets in the desktop @@ -1440,11 +1532,11 @@ var orbitDesktop = function(dom){ loading = '
          Loading
          '; $.each(elements,function(){ var widget = $(this), - widget_holder = $(this).find('.appholder'), - widget_style = (widget.find('.widget_style').length > 0) ? '' : ''; + widget_holder = $(this).find('.appholder') + // widget_style = (widget.find('.widget_style').length > 0) ? '' : ''; if(widget.attr("data-category")=="widget"){ var widgetname = widget.attr("data-content"); - widget_holder.before(widget_style).empty(); + // widget_holder.before(widget_style).empty(); $.getScript(widget.attr("js-link")).done(function(){ // widget.find(".appholder").load(widget.attr("data-content")); $.ajax({ @@ -1513,6 +1605,25 @@ var orbitDesktop = function(dom){ o.tinyscrollbar = target.main.tinyscrollbar( settings ); }; + this.check_simple_layout = function(){ + // use for various width of columns inside canvas(.overview) + // only count width for visible element which has "s_column" class + // then set width to canvas + // ** not sure to update canvas here ( $.tinyscrollbar_update() ) + var sw = 0, + $simple_layout = $('#content .overview[content-layout=simple]'); + if($simple_layout.find(".s_column").length > 0){ + $simple_layout.each(function(){ + $(this).find(".s_column").filter(":visible").each(function(){ + sw += $(this).outerWidth(); + }); + $simple_layout.css('width',sw); + }); + } + // if($simple_layout.find(".s_column").length > 0){ + // $simple_layout.css('width',sw); + // } + }; this.simple_drop_down = function(){ // simple dropdown menu var $sdm = $('.sdm'); @@ -1547,6 +1658,38 @@ var orbitDesktop = function(dom){ }); }); }; + + this.simple_switch = function(func){ + $('.s_switch').each(function(){ + var $switcher = $(this).find('.s_switch_switcher'), + $checkbox = $(this).find('input[type=checkbox]'), + $status = $(this).find('.s_switch_status'), + toggle = '', + status_on = $status.attr('status-on'), + status_off = $status.attr('status-off'), + ini, set; + ini = ($switcher.hasClass('admbg2')) ? null : $switcher.addClass('admbg2'); + ini = ($switcher.find('.s_switch_toggle').length < 1) ? $checkbox.after(toggle) : null; + set = ($checkbox.is(':checked')) ? $status.text(status_on) : $status.text(status_off); + $checkbox.unbind().change(function(){ + var v = $(this).attr('checked'); + switch (v) { + case 'checked': + $switcher.switchClass('admbg2','thmc2'); + $status.text(status_on); + break; + case undefined: + $switcher.switchClass('thmc2','admbg2'); + $status.text(status_off); + break; + } + if(typeof func == "function"){ + func.call(this,$(this)); + } + }); + }); + }; + this.single_select = function(){ // single select $('.ssl .ssl_item').each(function(){ @@ -1583,6 +1726,143 @@ var orbitDesktop = function(dom){ }); }); } + + 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.use_select2 = function(){ + $('select:not(.select2-offscreen)').select2({ + minimumResultsForSearch: -1 + // minimumInputLength: -1 + }); + } + + this.autocomplete = function(){ + $("*[autocomplete]").each(function(){ + $e = $(this); + var options = { + multiple:true, + minimumInputLength: -1, + width: "off", + ajax: { + url: $e.attr("autocomplete"), + dataType: 'json', + quietMillis: 100, + tokenSeparators: [","], + data: function (search, page) { + return {q: search}; + }, + results: function (data, page) { + return {results: data.results}; + } + } + } + var format = $e.attr("autocomplete-format"); + if(format){ + format = format.split(":"); + var seperator = format[0]; + var fields = format[1]; + fields = fields.replace("]",""); + fields = fields.replace("[",""); + fields = fields.split(","); + + options.formatResult = function(data){ + var markup = ""; + var x = 0; + for(i = 0;i < fields.length; i++){ + + if(i > 0)markup += " " + seperator + " "; + if(data[fields[i]]) + markup += data[fields[i]]; + else + markup += fields[i] + " not available"; + } + + return markup; + } + } + $e.select2(options); + }) + } + + this.appname_substr = function(target,length){ + var $target = $(target), + length = (length && typeof length == 'number') ? length : 12, + wrapper = '', + w1, w2; + if(!$target && $target.find('.text_wrapper').length > 0){ + return; + } else { + for(i = 0; i < $target.length; i++){ + var $this = $target.eq(i); + if($this.find('.appname').text().length > length + 1){ + $this.find('.appname').wrapInner(wrapper); + w1 = $this.find('.appname').width() - 24 + w2 = $this.find('.text_wrapper').width(); + if(w2 > w1){ + var text = $this.find('.text_wrapper').text(); + slice = text.substr(0,length); + $this.find('.text_wrapper').attr('title',text).text(slice+'...'); + } + } + } + } + } + this.minimizeBarManager = function(){ + var minimizedApps = [], + minimizeBar = $("#minimizebar"); + this.minimizeBarManager.minimize = function(win){ + minimizedApps.push(win.attr("id")); + var $e = generateMiniBar(win.attr("id")); + $e.find("span[for=title]").text(win.data('title')); + $e.one("click",function(){ + o.minimizeBarManager.maximize(win); + }); + $e.find("span.icon-remove").one("click",function(e){ + o.appWindow.close(win); + e.stopPropagation(); + }); + minimizeBar.append($e); + win.hide(); + // var minimizeOffset = minimizeBar.offset(); + // win.animate({"left":minimizeOffset.left + "px","top":minimizeOffset.top + "px","height":"25px","width":"200px"},function(){ + + // }); + + } + this.minimizeBarManager.maximize = function(win){ + var position = minimizedApps.indexOf(win.attr("id")); + minimizedApps.splice(position,1); + getMiniBar(position).remove(); + win.show(); + updatePositions(); + } + var getMiniBar = function(position){ + return minimizeBar.find("div[data-position="+position+"]"); + } + var generateMiniBar = function(id){ + var position = minimizedApps.indexOf(id), + template = '
          ', + $e = $(template); + return $e; + } + + var updatePositions = function(){ + minimizeBar.find("div.minimize").each(function(){ + $(this).attr("data-position",minimizedApps.indexOf($(this).data("app-id"))); + }) + } + } o.initialize(); } diff --git a/app/assets/javascripts/desktop/orbitdesktopAPI.js b/app/assets/javascripts/desktop/orbitdesktopAPI.js index 9e4700ea..4480555b 100644 --- a/app/assets/javascripts/desktop/orbitdesktopAPI.js +++ b/app/assets/javascripts/desktop/orbitdesktopAPI.js @@ -8,32 +8,37 @@ var orbitDesktopAPI = function(){ //msg (string) : message to display //type (string : success, imp, alert //time (int) : duration for notification in seconds - var $notify = $("#orbitnote"); - var img, n_height; + var $notify = $('#orbitnote'), + ani_method = { direction: 'up',easing: 'easeInOutQuint' }, + img, n_height; if(!type)type=""; switch(type){ case "alert": - img = "note_alert.png"; + img = "exclamation-sign"; break; case "imp": - img = "note_imp.png"; + img = "warning-sign"; break; case "success": - img = "note_success.png"; + img = "ok"; break; default: - img = "note_alert.png"; + img = "exclamation-sign"; break; } - $notify.find("img#note_img").attr("src",o.notifyImgPath+img); - $notify.find(".note_message").html(msg); - n_height = $notify.outerHeight(); - if(!time)time=5000; else time=time*1000; - $notify - .css({'top':-n_height, 'display':'block', 'opacity':0}) - .animate({top:0,opacity:1},200) + if( !time || time > 20) time = 5000; else time = time*1000; + + var sign = '
          ', + message = '
          '+ msg +'
          ', + item = '
          '+ sign + message +'
          '; + + $(item) + .prependTo($notify) + .stop(1,1) + .toggle('slide', ani_method, 300) .delay(time) - .animate({top:-n_height,opacity:0},200); + .toggle('slide', ani_method, 800); + $notify.find('.note_holder:hidden').remove(); }; this.executeFunc = function(func,callbackFn){ //takes 2 arguments @@ -67,7 +72,7 @@ var orbitDesktopAPI = function(){ this.changeWallpaper = function(wallpaper){ //takes 1 parameter //wallpaper (string): takes wallpaper and sets the wallpaper - $("img#thmbackground").attr("src",o.wallpaperPath+wallpaper); + $("#thmbackground").attr("src",o.wallpaperPath+wallpaper); o.saveWallpaper(wallpaper); }; this.confirm = function(settings,callbackfn){ @@ -111,29 +116,35 @@ var orbitDesktopAPI = function(){ }) return tempArray; }; - this.appWindow = function(settings,callbackfn){ + this.appWindow = function(options,callbackfn){ //takes set of arguments as array and gives callback //settings.method (string) : like open and close //settings.title (string) : the window title //settings.extUrl (boolean) : true for opening external url else false //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 = {}; + var settings = { + method : "open", + extUrl : true, + title : "New Window" + } + $.extend(settings,options); if(!settings.appid){ o.notify("Invalid AppID.","imp",3); return; } - if(!settings.method)settings.method = "open"; - if(!settings.extUrl)settings.extUrl = true; + var isWindow = ($("div.app_frame[data-app="+settings.appid+"]").length > 0 ? $("div.app_frame[data-app="+settings.appid+"]") : null); + if(isWindow){ + o.minimizeBarManager.maximize(isWindow); + return; + } if(settings.method == 'open'){ var appurl = "http://www.rulingcom.com"; o.windowcounter++; - if(!settings.title)settings.title = "New Window "+o.windowcounter; if(settings.extUrl){ if(settings.url){ if(settings.url.substr(0,4)!="http")settings.url = "http://"+settings.url; - console.log(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; @@ -147,20 +158,34 @@ var orbitDesktopAPI = function(){ return; } } - var whtml =$('
          '); + var whtml =$('
          '+settings.title+'
          '); $(o.contentHolder).append(whtml); - var parentwindow = $(o.contentHolder).find("div#app_frame_"+o.windowcounter); + var parentwindow = $(o.contentHolder).find("#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(); + parentwindow.find(".app_holder").height(app_holder_height); + parentwindow.find(".icon-remove").click(function(){ + o.appWindow.close(parentwindow); + }); + parentwindow.find(".icon-minus").click(function(){ + o.appWindow.minimize(parentwindow); }) + } + + this.appWindow.close = function(win){ + win.remove(); + } + + this.appWindow.minimize = function(win){ + o.minimizeBarManager.minimize(win) + } + if(typeof callbackfn=="function"){ - callbackfn.call(this); + callbackfn.call(this,parentwindow); } + return parentwindow; }; this.toolPopup = function(settings){ if(settings == "destroy"){ diff --git a/app/assets/javascripts/orbitdesktop.js b/app/assets/javascripts/orbitdesktop.js new file mode 100755 index 00000000..fc945390 --- /dev/null +++ b/app/assets/javascripts/orbitdesktop.js @@ -0,0 +1,1880 @@ +// 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 = "url" this will automatically convert textarea or input to autocomplete. +//autocomplete-format = "--:[text,email]" first one is seperator which will be put on between every field. +//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. +//"pagination-link" = "url" this url will be used for pagination.. this will override last link url. +//"pagination-var" = "variable to send paramater with url for pagination" this will enable pagination with this attribute for that view. + +//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; +}; + +Array.prototype.indexOfObject = function(object){ + for(i = 0;i < this.length; i++){ + if(this[i] === object) + break; + } + return i; +} + +jQuery.ajax = (function(_ajax){ + + var protocol = location.protocol, + hostname = location.hostname, + exRegex = RegExp(protocol + '//' + hostname), + YQL = 'http' + (/^https/.test(protocol)?'s':'') + '://query.yahooapis.com/v1/public/yql?callback=?', + query = 'select * from html where url="{URL}" and xpath="*"'; + + function isExternal(url) { + return !exRegex.test(url) && /:\/\//.test(url); + } + + return function(o) { + + var url = o.url; + + if ( /get/i.test(o.type) && !/json/i.test(o.dataType) && isExternal(url) ) { + + // Manipulate options so that JSONP-x request is made to YQL + + o.url = YQL; + o.dataType = 'json'; + + o.data = { + q: query.replace( + '{URL}', + url + (o.data ? + (/\?/.test(url) ? '&' : '?') + jQuery.param(o.data) + : '') + ), + format: 'xml' + }; + + // Since it's a JSONP request + // complete === success + if (!o.success && o.complete) { + o.success = o.complete; + delete o.complete; + } + + o.success = (function(_success){ + return function(data) { + + if (_success) { + // Fake XHR callback. + _success.call(this, { + responseText: (data.results[0] || '') + // YQL screws with