Merge pull request +15846 from c9/fix-apf-dynamic-styles

fix tab and content color mismatch for output tabs
pull/468/merge
Harutyun Amirjanyan 2017-12-07 16:12:29 +04:00 zatwierdzone przez GitHub
commit 1d5c3f6750
5 zmienionych plików z 42 dodań i 93 usunięć

Wyświetl plik

@ -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

Wyświetl plik

@ -89,6 +89,9 @@
left: @menu-item-check-left; left: @menu-item-check-left;
margin-top : -1px; margin-top : -1px;
} }
.c9menu>div.menu_item>a{
float: left;
}
.c9menu>div.menu_item.selected>u{ .c9menu>div.menu_item.selected>u{
background: @menu-item-radio-background; background: @menu-item-radio-background;

Wyświetl plik

@ -219,59 +219,6 @@
</a:main> </a:main>
</a:presentation> </a:presentation>
</a:checkbox> </a:checkbox>
<a:datagrid name="datagrid">
<a:presentation>
<a:main head="div[1]" container="div[3]" pointer="div[2]" widthdiff="1" iframe2="true">
<div class="datagrid">
<div class="headings">
</div>
<div class="pointer"> </div>
<div class="records"> </div>
</div>
</a:main>
<a:headitem class="." caption="u/text()">
<div><u>-<span/></u></div>
</a:headitem>
<a:rowheaditem class="." caption="text()">
<span>-</span>
</a:rowheaditem>
<a:item class="." container="following-sibling::blockquote">
<div class="row"/>
<blockquote> </blockquote>
</a:item>
<a:dragindicator>
<div class="dragdg"> </div>
</a:dragindicator>
<a:cell caption="u"><span><u>-</u></span></a:cell>
<a:treecell caption="u" openclose="strong" editoroffset="0"><span class="treecell"><strong> </strong><u>-</u></span></a:treecell>
<a:container container=".">
<div class="dginfo">-</div>
</a:container>
<a:loading>
<div class="message"/>
</a:loading>
<a:empty caption=".">
<div class="empty"> </div>
</a:empty>
</a:presentation>
</a:datagrid>
<a:divider name="divider"> <a:divider name="divider">
@ -420,8 +367,8 @@
</blockquote> </blockquote>
</a:main> </a:main>
<a:item caption="text()" icon="u" hotkey="span" inherit="true"> <a:item caption="a/text()" icon="u" hotkey="span" inherit="true">
<div class="menu_item"><span> </span><u> </u>-</div> <div class="menu_item"><u> </u><a>-</a><span class="shortcut"> </span></div>
</a:item> </a:item>
<a:divider inherit="true"> <a:divider inherit="true">
<div class="menu_divider"> </div> <div class="menu_divider"> </div>

Wyświetl plik

@ -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");
style.appendChild(doc.createTextNode(cssString)); if (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 elem.sheet;
return doc.createStyleSheet();
else {
var elem = doc.createElement("style");
elem.type = "text/css";
doc.getElementsByTagName("head")[0].appendChild(elem);
return elem.sheet;
}
}; };
/** /**

Wyświetl plik

@ -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() {