Skip to content

Commit

Permalink
Adds KT javascript global object for all other modules to attach to.
Browse files Browse the repository at this point in the history
Moves helptip and common to be attached to KT.

This change is aimed at reducing the global object footprint custom
javascript files leave behind and make debugging easier by being able to
find custom modules attached to the single global object in debug
consoles.
  • Loading branch information
ehelms committed Aug 31, 2011
1 parent 6ce1886 commit 4c72dac
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 37 deletions.
4 changes: 2 additions & 2 deletions src/public/javascripts/content.js
Expand Up @@ -103,7 +103,7 @@ var content = (function(){
return {
statusChecker : function(repo, sync, product_id){
fadeUpdate("#prod_sync_start_" + product_id, ' ');
var updateField = $('#' + common.escapeId("repo_bar_" + repo));
var updateField = $('#' + KT.common.escapeId("repo_bar_" + repo));
updateField.fadeOut('fast');
updateField.html('');
cancelButton = $('<a/>')
Expand Down Expand Up @@ -177,7 +177,7 @@ var content = (function(){
});
},
cancelSync : function(repoid, syncid, updateField, pu){
var btn = $('#' + common.escapeId("cancel_" + repoid));
var btn = $('#' + KT.common.escapeId("cancel_" + repoid));
var prod_id = getProductId(updateField);
btn.addClass("disabled");
pu.stop();
Expand Down
61 changes: 34 additions & 27 deletions src/public/javascripts/katello.js
Expand Up @@ -18,6 +18,9 @@
* Date: 09/01/2010
*/

//Katello global object namespace that all others should be attached to
var KT = {};

//i18n global variable
var i18n = {};

Expand Down Expand Up @@ -54,38 +57,41 @@ function log(msg) {
}, 0);
}

var helptip = (function() {
return {
handle_close: function(){
var key = this.id.split("helptip-opened_")[1];
$("#helptip-opened_" + key).hide();
$("#helptip-closed_" + key).show();
helptip.disable(key);
},
handle_open: function(){
var key = this.id.split("helptip-closed_")[1];
$("#helptip-opened_" + key).show();
$("#helptip-closed_" + key).hide();
helptip.enable(key);
},
enable: function(key) {
KT.helptip = (function($) {
var enable = function(key) {
$.ajax({
type: "POST",
url: "/users/enable_helptip",
data: { "key":key},
cache: false
});
},
disable: function(key) {
disable = function(key) {
$.ajax({
type: "POST",
url: "/users/disable_helptip",
data: { "key":key},
cache: false
});
}
},
handle_close = function(){
var key = this.id.split("helptip-opened_")[1];
$("#helptip-opened_" + key).hide();
$("#helptip-closed_" + key).show();
disable(key);
},
handle_open = function(){
var key = this.id.split("helptip-closed_")[1];
$("#helptip-opened_" + key).show();
$("#helptip-closed_" + key).hide();
enable(key);
};

return {
handle_close : handle_close,
handle_open : handle_open
};
})();
})(jQuery);

//override the jQuery UJS $.rails.allowAction
$.rails.allowAction = function(element) {
Expand All @@ -94,7 +100,7 @@ $.rails.allowAction = function(element) {
if (!message) { return true; }

if ($.rails.fire(element, 'confirm')) {
common.customConfirm(message, function() {
KT.common.customConfirm(message, function() {
callback = $.rails.fire(element,
'confirm:complete', [answer]);
if(callback) {
Expand All @@ -119,7 +125,7 @@ $.expr[':'].contains = function(a, i, m) {
};

//requires jQuery
var common = (function() {
KT.common = (function() {
return {
height: function() {
return $(window).height();
Expand All @@ -144,6 +150,7 @@ var common = (function() {
var html = "<div style='margin:20px;'><span class='status_confirm_icon'/><div style='margin-left: 24px; display:table;height:1%;'>" + message + "</div></div>";
var confirmTrue = new Boolean(true);
var confirmFalse = new Boolean(false);

$(html).dialog({
closeOnEscape: false,
open: function (event, ui) {
Expand Down Expand Up @@ -297,12 +304,12 @@ $(document).ready(function (){
});

//Add a handler for helptips
$(".helptip-open").live('click', helptip.handle_close);
$(".helptip-close").live('click', helptip.handle_open);
$(".helptip-open").live('click', KT.helptip.handle_close);
$(".helptip-close").live('click', KT.helptip.handle_open);

common.orgSwitcherSetup();
common.orgFilterSetup();
common.thirdLevelNavSetup();
KT.common.orgSwitcherSetup();
KT.common.orgFilterSetup();
KT.common.thirdLevelNavSetup();
});

/**
Expand All @@ -328,6 +335,6 @@ $(window).ready(function(){
}
});

window.alert = function(message){common.customAlert(message);return false;};
$.rails.confirm = function(message) { common.customConfirm(message); return false;};
window.alert = function(message){KT.common.customAlert(message);return false;};
$.rails.confirm = function(message) { KT.common.customConfirm(message); return false;};
});
2 changes: 1 addition & 1 deletion src/public/javascripts/notices.js
Expand Up @@ -93,7 +93,7 @@ var notices = (function() {
},
checkNoticesInResponse : function(xhr) {
if (xhr !== undefined) {
var message = common.decode(xhr.getResponseHeader('X-Message'));
var message = KT.common.decode(xhr.getResponseHeader('X-Message'));
if (message === "null") {message = null;}
var messageType = xhr.getResponseHeader('X-Message-Type');
if (message) {
Expand Down
6 changes: 3 additions & 3 deletions src/public/javascripts/panel.js
Expand Up @@ -272,7 +272,7 @@ var panel = (function(){

//if there is a lot in the list, make the panel a bit larger
if ($('#content').height() > 642){
var extraHeight = common.height() - 192;
var extraHeight = KT.common.height() - 192;
if (isSubpanel) {
extraHeight -= subpanelSpacing;
}
Expand Down Expand Up @@ -381,8 +381,8 @@ var panel = (function(){
}
},
handleScroll : function(jQPanel, container, top, bodyY, spacing, offset) {
var scrollY = common.scrollTop(),
scrollX = common.scrollLeft(),
var scrollY = KT.common.scrollTop(),
scrollX = KT.common.scrollLeft(),
isfixed = jQPanel.css('position') === 'fixed';

offset = offset ? offset : 10;
Expand Down
4 changes: 2 additions & 2 deletions src/public/javascripts/promotion.js
Expand Up @@ -46,7 +46,7 @@ var promotion_page = (function($){
},
//Finds the add/remove buttons in the left pane
find_button = function(id, type) {
return $("a[class~=content_add_remove][data-id=" + common.escapeId(id) + "][data-type=" + type + "]");
return $("a[class~=content_add_remove][data-id=" + KT.common.escapeId(id) + "][data-type=" + type + "]");
},
conflict = function(){
//conflict object that stores conflict information
Expand Down Expand Up @@ -791,7 +791,7 @@ var registerEvents = function(){
return false;
}
var id = promotion_page.get_changeset().id;
common.customConfirm(button.attr('data-confirm-text'), function(){
KT.common.customConfirm(button.attr('data-confirm-text'), function(){
button.addClass('disabled');
$.ajax({
type: "DELETE",
Expand Down
2 changes: 1 addition & 1 deletion src/public/javascripts/role_sliding_tree.js
Expand Up @@ -900,7 +900,7 @@ var pageActions = (function($){

$('#remove_role').live('click', function(){
var button = $(this);
common.customConfirm(button.attr('data-confirm-text'), function(){
KT.common.customConfirm(button.attr('data-confirm-text'), function(){
roleActions.removeRole(button);
});
});
Expand Down
2 changes: 1 addition & 1 deletion src/public/javascripts/test/js/katelloTests.js
Expand Up @@ -12,6 +12,6 @@ test('localize_i18n', function() {
})

test('escapeSelector', function() {
var val = common.escapeId("#my.val");
var val = KT.common.escapeId("#my.val");
ok(val.indexOf("\\") != -1, "properly escape Jquery selectors");
})

0 comments on commit 4c72dac

Please sign in to comment.