kopia lustrzana https://github.com/c9/core
fix tab and content color mismatch for output tabs
rodzic
ce4864646d
commit
3c63dd06fd
|
@ -1,3 +1,4 @@
|
||||||
|
/*global apf*/
|
||||||
define(function(require, module, exports) {
|
define(function(require, module, exports) {
|
||||||
main.consumes = ["Plugin", "ui", "Document", "dialog.alert"];
|
main.consumes = ["Plugin", "ui", "Document", "dialog.alert"];
|
||||||
main.provides = ["Tab"];
|
main.provides = ["Tab"];
|
||||||
|
@ -9,8 +10,6 @@ define(function(require, module, exports) {
|
||||||
var ui = imports.ui;
|
var ui = imports.ui;
|
||||||
var alert = imports["dialog.alert"].show;
|
var alert = imports["dialog.alert"].show;
|
||||||
|
|
||||||
var stylesheet = ui.createStylesheet();
|
|
||||||
|
|
||||||
function Tab(options) {
|
function Tab(options) {
|
||||||
var editorType, doc, path, amlPane, init, active, fg, bg,
|
var editorType, doc, path, amlPane, init, active, fg, bg,
|
||||||
title, tooltip, amlTab, closed, rule, docInited;
|
title, tooltip, amlTab, closed, rule, docInited;
|
||||||
|
@ -53,12 +52,8 @@ define(function(require, module, exports) {
|
||||||
if (!bg) bg = "inherit";
|
if (!bg) bg = "inherit";
|
||||||
if (!fg) fg = "inherit";
|
if (!fg) fg = "inherit";
|
||||||
|
|
||||||
(
|
ui.setStyleRule(rule, "background-color", bg);
|
||||||
ui.setStyleRule(rule, "background-color", bg, stylesheet) &&
|
ui.setStyleRule(rule, "color", fg);
|
||||||
ui.setStyleRule(rule, "foreground-color", fg, stylesheet)
|
|
||||||
) || ui.importStylesheet([
|
|
||||||
[rule, "background-color:" + bg + ";" + "color:" + fg + ";"]
|
|
||||||
], window, stylesheet);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/***** Initialization *****/
|
/***** Initialization *****/
|
||||||
|
@ -301,7 +296,7 @@ define(function(require, module, exports) {
|
||||||
closed = true;
|
closed = true;
|
||||||
|
|
||||||
if (rule)
|
if (rule)
|
||||||
ui.removeStyleRule(rule, stylesheet);
|
ui.removeStyleRule(rule);
|
||||||
// If there are no more pages left, reset location
|
// If there are no more pages left, reset location
|
||||||
var last = e && e.last || amlPane.getPages().length === 0;
|
var last = e && e.last || amlPane.getPages().length === 0;
|
||||||
if (last)
|
if (last)
|
||||||
|
@ -432,7 +427,7 @@ define(function(require, module, exports) {
|
||||||
bg = v || "";
|
bg = v || "";
|
||||||
if (!rule)
|
if (!rule)
|
||||||
return initStyleSheet(fg, bg);
|
return initStyleSheet(fg, bg);
|
||||||
ui.setStyleRule(rule, "background-color", bg, stylesheet);
|
ui.setStyleRule(rule, "background-color", bg);
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* The foreground color of the tab button and it's body. It is
|
* The foreground color of the tab button and it's body. It is
|
||||||
|
@ -447,7 +442,7 @@ define(function(require, module, exports) {
|
||||||
fg = v;
|
fg = v;
|
||||||
if (!rule)
|
if (!rule)
|
||||||
return initStyleSheet(fg, bg);
|
return initStyleSheet(fg, bg);
|
||||||
ui.setStyleRule(rule, "color", fg, stylesheet);
|
ui.setStyleRule(rule, "color", fg);
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* @property {Object} classList Object that
|
* @property {Object} classList Object that
|
||||||
|
|
|
@ -2406,6 +2406,14 @@ function findCssRule(name, stylesheet, win) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function toCssPropertyName(name) {
|
||||||
|
return name.replace(/[A-Z]/g, function(a) {return "-" + a.toLowerCase()});
|
||||||
|
}
|
||||||
|
function toCamelCase(name) {
|
||||||
|
return name.replace(/-(\w)/g, function(_, a) {return a.toUpperCase()});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method sets a single CSS rule.
|
* This method sets a single CSS rule.
|
||||||
* @param {String} name The CSS name of the rule (i.e. `.cls` or `#id`).
|
* @param {String} name The CSS name of the rule (i.e. `.cls` or `#id`).
|
||||||
|
@ -2415,14 +2423,22 @@ function findCssRule(name, stylesheet, win) {
|
||||||
* @param {Object} [win] A reference to a window
|
* @param {Object} [win] A reference to a window
|
||||||
*/
|
*/
|
||||||
apf.setStyleRule = function(name, type, value, stylesheet, win) {
|
apf.setStyleRule = function(name, type, value, stylesheet, win) {
|
||||||
|
if (!stylesheet)
|
||||||
|
stylesheet = apf.$dynamicStyles || (apf.$dynamicStyles = apf.createStylesheet("", "dynamicStyles.css"));
|
||||||
var rule = findCssRule(name, stylesheet, win);
|
var rule = findCssRule(name, stylesheet, win);
|
||||||
if (rule) {
|
if (rule) {
|
||||||
if (value.indexOf("!important") > -1) {
|
if (value.indexOf("!important") > -1) {
|
||||||
|
type = toCssPropertyName(type);
|
||||||
rule.style.cssText = type + ":" + value;
|
rule.style.cssText = type + ":" + value;
|
||||||
} else {
|
} else {
|
||||||
type = type.replace(/-(\w)/g, function(_, a) {return a.toUpperCase()});
|
type = toCamelCase(type);
|
||||||
rule.style[type] = value;
|
rule.style[type] = value;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
type = toCssPropertyName(type);
|
||||||
|
apf.importStylesheet([
|
||||||
|
[name, type + ":" + value]
|
||||||
|
], win, stylesheet);
|
||||||
}
|
}
|
||||||
return !!rule;
|
return !!rule;
|
||||||
};
|
};
|
||||||
|
@ -2492,12 +2508,15 @@ apf.setStyleClass = function(oHtml, className, exclusion, userAction) {
|
||||||
*/
|
*/
|
||||||
apf.importCssString = function(cssString, doc, media) {
|
apf.importCssString = function(cssString, doc, media) {
|
||||||
doc = doc || document;
|
doc = doc || document;
|
||||||
var htmlNode = doc.getElementsByTagName("head")[0];
|
var htmlNode = doc.head;
|
||||||
var style = doc.createElement("style");
|
var style = doc.createElement("style");
|
||||||
|
if (cssString)
|
||||||
style.appendChild(doc.createTextNode(cssString));
|
style.appendChild(doc.createTextNode(cssString));
|
||||||
if (media)
|
if (media)
|
||||||
style.setAttribute('media', media);
|
style.setAttribute('media', media);
|
||||||
htmlNode.appendChild(style);
|
var before = apf.$dynamicStyles && apf.$dynamicStyles.ownerNode;
|
||||||
|
htmlNode.insertBefore(style, before);
|
||||||
|
return style;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2553,11 +2572,10 @@ apf.importStylesheet = function (def, win, stylesheet) {
|
||||||
|
|
||||||
var rule = def[i][0] + " {" + def[i][1] + "}";
|
var rule = def[i][0] + " {" + def[i][1] + "}";
|
||||||
try {
|
try {
|
||||||
stylesheet.insertRule(rule, 0);
|
stylesheet.insertRule(rule, stylesheet.cssRules.length);
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
stylesheet = new StyleSheet();
|
console.error(e);
|
||||||
stylesheet.insertRule(rule, 0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -2567,17 +2585,10 @@ apf.importStylesheet = function (def, win, stylesheet) {
|
||||||
* @param {Object} [win] A reference to a window
|
* @param {Object} [win] A reference to a window
|
||||||
* @returns {String} The created CSS stylesheet
|
* @returns {String} The created CSS stylesheet
|
||||||
*/
|
*/
|
||||||
apf.createStylesheet = function(win) {
|
apf.createStylesheet = function(win, id) {
|
||||||
var doc = (win || window).document;
|
var elem = apf.importCssString(null, (win || window).document)
|
||||||
|
if (id) elem.id = id;
|
||||||
if (doc.createStyleSheet)
|
|
||||||
return doc.createStyleSheet();
|
|
||||||
else {
|
|
||||||
var elem = doc.createElement("style");
|
|
||||||
elem.type = "text/css";
|
|
||||||
doc.getElementsByTagName("head")[0].appendChild(elem);
|
|
||||||
return elem.sheet;
|
return elem.sheet;
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -126,13 +126,6 @@ define(function(require, module, exports) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function createStyleSheet(css) {
|
|
||||||
var style = document.createElement("style");
|
|
||||||
style.appendChild(document.createTextNode(css));
|
|
||||||
document.getElementsByTagName("head")[0].appendChild(style);
|
|
||||||
return style;
|
|
||||||
}
|
|
||||||
|
|
||||||
function insertLess(css, filename, staticPrefix, _callback, force) {
|
function insertLess(css, filename, staticPrefix, _callback, force) {
|
||||||
var callback = _callback || function(err) {
|
var callback = _callback || function(err) {
|
||||||
if (err) console.error(err);
|
if (err) console.error(err);
|
||||||
|
@ -166,7 +159,7 @@ define(function(require, module, exports) {
|
||||||
return callback(e);
|
return callback(e);
|
||||||
|
|
||||||
// Add css to the DOM
|
// Add css to the DOM
|
||||||
var style = createStyleSheet(tree.toCSS({
|
var style = apf.importCssString(tree.toCSS({
|
||||||
relativeUrls: true,
|
relativeUrls: true,
|
||||||
rootpath: staticPrefix || ""
|
rootpath: staticPrefix || ""
|
||||||
}));
|
}));
|
||||||
|
@ -202,7 +195,7 @@ define(function(require, module, exports) {
|
||||||
if (!packed && packedThemes && staticPrefix !== false) {
|
if (!packed && packedThemes && staticPrefix !== false) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var style = createStyleSheet(css);
|
var style = apf.importCssString(css);
|
||||||
|
|
||||||
// Cleanup
|
// Cleanup
|
||||||
plugin.addOther(function() {
|
plugin.addOther(function() {
|
||||||
|
|
Ładowanie…
Reference in New Issue