Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Styles from attributes to node #71

Open
lifeart opened this issue Sep 2, 2017 · 1 comment
Open

Styles from attributes to node #71

lifeart opened this issue Sep 2, 2017 · 1 comment

Comments

@lifeart
Copy link
Contributor

lifeart commented Sep 2, 2017

After app render, will be good idea to move binded styles to style node

var styleNode = null;

function createStyleNode() {
	var head = document.head || document.getElementsByTagName('head')[0];
	var style = document.createElement('style');
	style.type = 'text/css';
	head.appendChild(style);
	return style;
}

function addStyle(css) {
	if (!styleNode) {
		styleNode = createStyleNode();
	}
	
	if (styleNode.styleSheet){
		styleNode.styleSheet.cssText = css;
	} else {
		styleNode.innerHTML = '';
		styleNode.appendChild(document.createTextNode(css));
	}
}

var styles = Array.prototype.map.call(document.getElementsByTagName('div'), function(node, index) {
	node.dataset.index = index;
	var style = node.getAttribute('style');
	node.removeAttribute('style');
	var prefix = '';
	if (node.className) {
		prefix = '.'+node.className.split(' ').join('.');
	}
	return `${prefix}[data-index="${index}"]{${style};}`;
});

addStyle(styles.join(''));
@whoozle
Copy link
Collaborator

whoozle commented Sep 6, 2017

this needs additional performance investigation, since we already do updates in batches and it will most likely trigger additional layouts

@whoozle whoozle added this to What's on now? in QmlCore Apr 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
QmlCore
  
What's on now?
Development

No branches or pull requests

2 participants