javascript - Is it possible for CSS to escape the shadow dom (Polymer)? -
i have drop-down element in polymer. because of z-indexing issues, need pull drop-down part out , make direct child of <body>. unfortunately, can't figure out how , still able style element. solution can come make drop-down portion own polymer tag, seems really... backwards.
in short, have element:
<my-element> <template> <style>...</style> <input> <div id="dropdown">...</div> </template> </my-element> and js in element document.body.appendchild( this.$.dropdown )
i'm trying figure out how stylize drop-down once been moved, polymer/web components' css isolation preventing me doing that.
[edit] note polymer can't handle on-* event handlers attached via dom method due fact can't walk dom tree polymer-element. events need manually attached using this.
i created custom element can inserted element , pull out rules start body , promote them new stylesheet inserted head. there bit of work done, around browsers need polyfilled ::shadow selector won't work. i'll shortly.
<link rel="import" href="../polymer/polymer.html" /> <polymer-element name="promote-body-css"> <script> 'use strict'; ~function(){ var promoted = {}; function promote( node ){ var nodename = node.nodename; if( promoted[ nodename ] ){ return; } var promoterules = []; [].foreach.call( node.queryselectorall( '::shadow style' ), function( stylesheet ){ [].foreach.call( stylesheet.sheet.cssrules, function( rule ){ if( rule.csstext.indexof( 'body ' ) === 0 ){ promoterules.push( rule.csstext ); } } ); } ); if( promoterules.length ){ var stylesheet = document.createelement( 'style' ); stylesheet.innerhtml = promoterules.join( '' ) + '/* inserted polymer element ' + nodename + ' */'; document.getelementsbytagname( 'head' )[0].appendchild( stylesheet ); } } promoted[ nodename ] = 1; polymer( 'promote-body-css', { attached : function( parent ){ promote( ( parent = this.parentnode ).host || parent ); } } ); }(); </script> </polymer-element>
Comments
Post a Comment