This is an automated email from the ASF dual-hosted git repository. hiedra pushed a commit to branch develop in repository https://gitbox.apache.org/repos/asf/royale-asjs.git
commit 2865e5b772097f191d3bca09acf6db0b466a59fc Author: mjesteve <[email protected]> AuthorDate: Mon Jul 29 11:18:01 2024 +0200 New bead removeDynamicSelector: Removes a CSS selector dynamically at runtime. --- .../projects/Core/src/main/royale/CoreClasses.as | 1 + .../royale/utils/css/removeDynamicSelector.as | 55 ++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/frameworks/projects/Core/src/main/royale/CoreClasses.as b/frameworks/projects/Core/src/main/royale/CoreClasses.as index 086a456697..38be706720 100644 --- a/frameworks/projects/Core/src/main/royale/CoreClasses.as +++ b/frameworks/projects/Core/src/main/royale/CoreClasses.as @@ -380,6 +380,7 @@ internal class CoreClasses import org.apache.royale.utils.async.promiseToTask; promiseToTask; import org.apache.royale.utils.css.addDynamicSelector; addDynamicSelector; + import org.apache.royale.utils.css.removeDynamicSelector; removeDynamicSelector; COMPILE::JS { diff --git a/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/css/removeDynamicSelector.as b/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/css/removeDynamicSelector.as new file mode 100644 index 0000000000..a73854d5ae --- /dev/null +++ b/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/css/removeDynamicSelector.as @@ -0,0 +1,55 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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; + + /** + * Removes a CSS selector dynamically at runtime. + * + * @param selector The CSS selector. + * + * @langversion 3.0 + * @productversion Royale 0.9.3 + * @royalesuppressexport + * @royaleignorecoercion CSSStyleSheet + * @royaleignorecoercion HTMLStyleElement + */ + public function removeDynamicSelector(selector:String):void + { + COMPILE::JS + { + var element:HTMLStyleElement = document.getElementById("royale_dynamic_css") as HTMLStyleElement; + if(element) + { + var sheet:CSSStyleSheet = element.sheet as CSSStyleSheet; + + for(var idxrule:int = 0; idxrule<sheet.cssRules.length; idxrule++) + { + if(sheet.cssRules[idxrule].selectorText == selector) + { + sheet.deleteRule(idxrule); + break; + } + } + } + } + } + +}
