//requires jQuery KT.common = (function() { var root_url; return { height: function() { return $(window).height(); }, width: function() { return $(window).width(); }, scrollTop: function() { return $(window).scrollTop(); }, scrollLeft: function() { return $(window).scrollLeft(); }, decode: function(value){ var decoded = decodeURIComponent(value); return decoded.replace(/\+/g, " "); }, escapeId: function(myid) { return myid.replace(/([ #;&,.%+*~\':"!\^$\[\]()=>|\/])/g,'\\$1'); }, customConfirm : function (params) { var settings = { message: undefined, warning_message: undefined, yes_text: katelloI18n.yes, no_text: katelloI18n.no, yes_callback: function(){}, no_callback: function(){}, include_cancel: false }, confirmTrue = true, confirmFalse = false; $.extend(settings, params); var message = "
" + settings.message + "
", warning_message = (settings.warning_message === undefined) ? undefined : "
" + settings.warning_message + "
", html = (warning_message === undefined) ? message : "
"+message+warning_message+"
", buttons = { "Yes": { click : function () { $(this).dialog("close"); $(this).dialog("destroy"); settings.yes_callback(); return confirmTrue; }, 'class' : 'button', 'text' : settings.yes_text }, "No": { click:function () { $(this).dialog("close"); $(this).dialog("destroy"); settings.no_callback(); return confirmFalse; }, 'class' : 'button', 'text' : settings.no_text } }; if(settings.include_cancel === true) { buttons["Cancel"] = { click:function () { $(this).dialog("close"); $(this).dialog("destroy"); return confirmFalse; }, 'class' : 'button', 'text' : katelloI18n.cancel }; } $(html).dialog({ closeOnEscape: true, open: function (event, ui) { $('.ui-dialog-titlebar-close').hide(); $('.confirmation').find('.ui-button')[1].focus(); }, modal: true, resizable: false, width: 450, title: katelloI18n.confirmation, dialogClass: "confirmation", buttons: buttons }); }, customAlert : function(message) { var html = "
" + message + "
"; $(html).dialog({ closeOnEscape: true, open: function (event, ui) { $('.ui-dialog-titlebar-close').hide(); }, modal: true, resizable: false, width: 300, title: katelloI18n.alert, dialogClass: "alert", stack: false, buttons: { "Ok": { click : function () { $(this).dialog("close"); $(this).dialog("destroy"); return false; }, 'class' : 'button', 'text' : katelloI18n.ok } } }); }, orgSwitcherSetup : function() { $('.favorite').live('click', function(e) { KT.orgswitcher.checkboxChanged($(this).parent().find('.default_org')); }); }, rootURL : function() { if (root_url === undefined) { root_url = KT.routes.options.prefix; } return root_url; }, getSearchParams : function(val) { var search_string; if ($.bbq) { search_string = $.bbq.getState('list_search'); } if( search_string ){ return { 'search' : search_string }; } else { return false; } }, spinner_path : function() { return "/assets/spinner.gif"; }, to_human_readable_bytes : function(bytes) { var sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB'], i; if (bytes === 0) { return '0'; } else { i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)), 10); return ((i === 0) ? (bytes / Math.pow(1024, i)) : (bytes / Math.pow(1024, i)).toFixed(1)) + ' ' + sizes[i]; } }, icon_hover_change : function(element, shade){ var background_position, icon = element.find('i[data-change_on_hover="' + shade + '"]'), shade_position; if( icon.length > 0 ){ background_position = icon.css('background-position'); if( background_position !== undefined ){ background_position = background_position.split(" "); shade_position = (background_position[1] === "0" || background_position[1] === "0px") ? ' -16px' : ' 0'; background_position = background_position[0] + shade_position; icon.css({ 'background-position' : background_position }); } } }, link_hover_setup : function(shade){ $('a').live('mouseenter', function(){ KT.common.icon_hover_change($(this), shade); } ).live('mouseleave', function(){ KT.common.icon_hover_change($(this), shade); } ); } }; })(jQuery);