Great! This seems to be very useful! thanks! :)
2018-06-04 10:22 GMT+02:00 <[email protected]>: > This is an automated email from the ASF dual-hosted git repository. > > harbs pushed a commit to branch develop > in repository https://gitbox.apache.org/repos/asf/royale-asjs.git > > > The following commit(s) were added to refs/heads/develop by this push: > new 50ca711 Added utility function to dynamically add CSS selectors > 50ca711 is described below > > commit 50ca711de856475536ea26934023ccb2ebdfc360 > Author: Harbs <[email protected]> > AuthorDate: Mon Jun 4 11:22:53 2018 +0300 > > Added utility function to dynamically add CSS selectors > > I’m not sure if there’s a good way to do this for swf. > --- > .../projects/Core/src/main/royale/CoreClasses.as | 2 + > .../apache/royale/utils/css/addDynamicSelector.as | 57 > ++++++++++++++++++++++ > 2 files changed, 59 insertions(+) > > diff --git a/frameworks/projects/Core/src/main/royale/CoreClasses.as > b/frameworks/projects/Core/src/main/royale/CoreClasses.as > index a0a0b58..ee14d3a 100644 > --- a/frameworks/projects/Core/src/main/royale/CoreClasses.as > +++ b/frameworks/projects/Core/src/main/royale/CoreClasses.as > @@ -303,6 +303,8 @@ internal class CoreClasses > import org.apache.royale.utils.date.addSeconds; addSeconds; > import org.apache.royale.utils.date.addYears; addYears; > > + import org.apache.royale.utils.css.addDynamicSelector; > addDynamicSelector; > + > import org.apache.royale.core.TextLineMetrics; TextLineMetrics; > import org.apache.royale.utils.ClassSelectorList; ClassSelectorList; > } > diff --git a/frameworks/projects/Core/src/main/royale/org/apache/ > royale/utils/css/addDynamicSelector.as b/frameworks/projects/Core/ > src/main/royale/org/apache/royale/utils/css/addDynamicSelector.as > new file mode 100644 > index 0000000..b7e495a > --- /dev/null > +++ b/frameworks/projects/Core/src/main/royale/org/apache/ > royale/utils/css/addDynamicSelector.as > @@ -0,0 +1,57 @@ > +/////////////////////////////////////////////////////////// > ///////////////////// > +// > +// Licensed to the Apache Software Foundation (ASF) under one or more > +// contributor license agreements. See the NOTICE file distributed with > +// this work for additional information regarding copyright ownership. > +// The ASF licenses this file to You under the Apache License, Version > 2.0 > +// (the "License"); you may not use this file except in compliance with > +// the License. You may obtain a copy of the License at > +// > +// http://www.apache.org/licenses/LICENSE-2.0 > +// > +// Unless required by applicable law or agreed to in writing, software > +// distributed under the License is distributed on an "AS IS" BASIS, > +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or > implied. > +// See the License for the specific language governing permissions and > +// limitations under the License. > +// > +/////////////////////////////////////////////////////////// > ///////////////////// > +package org.apache.royale.utils.css > +{ > + import org.apache.royale.core.IUIBase; > + > + /** > + * Adds a CSS selector dynamically at runtime. > + * > + * @param selector The CSS selector. > + * > + * @param rule The CSS rule to apply. > + * > + * @langversion 3.0 > + * @productversion Royale 0.9.3 > + * @royaleignorecoercion CSSStyleSheet > + * @royaleignorecoercion HTMLStyleElement > + */ > + public function addDynamicSelector(selector:String, rule:String):void > + { > + COMPILE::JS > + { > + var selectorString:String = selector + ' { ' + rule + ' }' > + var element:HTMLStyleElement = > document.getElementById("royale_dynamic_css") > as HTMLStyleElement; > + if(element) > + { > + var sheet:CSSStyleSheet = element.sheet as CSSStyleSheet; > + sheet.insertRule(selectorString); > + } > + else > + { > + var style:HTMLStyleElement = > document.createElement('style') as HTMLStyleElement; > + style.type = 'text/css'; > + style.id = "royale_dynamic_css"; > + style.innerHTML = selectorString; > + document.getElementsByTagName( > 'head')[0].appendChild(style); > + } > + } > + } > + > +} > > -- > To stop receiving notification emails like this one, please contact > [email protected]. > -- Carlos Rovira http://about.me/carlosrovira
