remove css class handling from util.js

This commit is contained in:
Fabian Jakobs 2010-12-16 18:23:18 +01:00
commit 74408f30ac
3 changed files with 30 additions and 61 deletions

View file

@ -37,16 +37,14 @@
define(function(require, exports, module) {
var util = require('pilot/util');
var requestViewCss = require("text!cockpit/ui/requestView.css");
var dom = require("pilot/dom");
dom.importCssString(requestViewCss);
var event = require("pilot/event");
var requestViewHtml = require("text!cockpit/ui/requestView.html");
var Templater = require("pilot/domtemplate").Templater;
var requestViewCss = require("text!cockpit/ui/requestView.css");
dom.importCssString(requestViewCss);
/**
* Pull the HTML into the DOM, but don't add it to the document
*/
@ -102,24 +100,24 @@ RequestView.prototype = {
hideOutput: function(ev) {
this.output.style.display = 'none';
util.addClass(this.hide, 'cmd_hidden');
util.removeClass(this.show, 'cmd_hidden');
dom.addCssClass(this.hide, 'cmd_hidden');
dom.removeCssClass(this.show, 'cmd_hidden');
ev.stopPropagation();
event.stopPropagation(ev);
},
showOutput: function(ev) {
this.output.style.display = 'block';
util.removeClass(this.hide, 'cmd_hidden');
util.addClass(this.show, 'cmd_hidden');
dom.removeCssClass(this.hide, 'cmd_hidden');
dom.addCssClass(this.show, 'cmd_hidden');
ev.stopPropagation();
event.stopPropagation(ev);
},
remove: function(ev) {
this.cliView.output.removeChild(this.rowin);
this.cliView.output.removeChild(this.rowout);
ev.stopPropagation();
event.stopPropagation(ev);
},
onRequestChange: function(ev) {
@ -140,7 +138,7 @@ RequestView.prototype = {
}, this);
this.cliView.scrollOutputToBottom();
util.setClass(this.output, 'cmd_error', this.request.error);
dom.setCssClass(this.output, 'cmd_error', this.request.error);
this.throb.style.display = this.request.completed ? 'none' : 'block';
}

View file

@ -51,12 +51,30 @@ exports.hasCssClass = function(el, name) {
return classes.indexOf(name) !== -1;
};
/**
* Add a CSS class to the list of classes on the given node
*/
exports.addCssClass = function(el, name) {
if (!exports.hasCssClass(el, name)) {
el.className += " " + name;
}
};
/**
* Add or remove a CSS class from the list of classes on the given node
* depending on the value of <tt>include</tt>
*/
exports.setCssClass = function(node, className, include) {
if (include) {
exports.addCssClass(node, className);
} else {
exports.removeCssClass(node, className);
}
};
/**
* Remove a CSS class from the list of classes on the given node
*/
exports.removeCssClass = function(el, name) {
var classes = el.className.split(/\s+/g);
while (true) {

View file

@ -480,53 +480,6 @@ exports.formatDate = function (date) {
*/
exports.formatDate.shortMonths = [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ];
/**
* Add a CSS class to the list of classes on the given node
*/
exports.addClass = function(node, className) {
var parts = className.split(/\s+/);
var cls = " " + node.className + " ";
for (var i = 0, len = parts.length, c; i < len; ++i) {
c = parts[i];
if (c && cls.indexOf(" " + c + " ") < 0) {
cls += c + " ";
}
}
node.className = cls.trim();
};
/**
* Remove a CSS class from the list of classes on the given node
*/
exports.removeClass = function(node, className) {
var cls;
if (className !== undefined) {
var parts = className.split(/\s+/);
cls = " " + node.className + " ";
for (var i = 0, len = parts.length; i < len; ++i) {
cls = cls.replace(" " + parts[i] + " ", " ");
}
cls = cls.trim();
} else {
cls = "";
}
if (node.className != cls) {
node.className = cls;
}
};
/**
* Add or remove a CSS class from the list of classes on the given node
* depending on the value of <tt>include</tt>
*/
exports.setClass = function(node, className, include) {
if (include) {
exports.addClass(node, className);
} else {
exports.removeClass(node, className);
}
};
/**
* Is the passed object either null or undefined (using ===)
*/