This is an automated email from the ASF dual-hosted git repository. aharui pushed a commit to branch feature/uibase-classname in repository https://gitbox.apache.org/repos/asf/royale-asjs.git
The following commit(s) were added to refs/heads/feature/uibase-classname by this push: new 919e9e7 first cut at another version of class selector management" 919e9e7 is described below commit 919e9e73510011c037b89806b37a886ccbd17803 Author: Alex Harui <aha...@apache.org> AuthorDate: Mon Apr 16 00:24:59 2018 -0700 first cut at another version of class selector management" --- .../org/apache/royale/utils/ClassSelectorList.as | 111 +++++++++++++++++++++ 1 file changed, 111 insertions(+) diff --git a/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/ClassSelectorList.as b/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/ClassSelectorList.as new file mode 100644 index 0000000..941d183 --- /dev/null +++ b/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/ClassSelectorList.as @@ -0,0 +1,111 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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 +{ + import org.apache.royale.core.IUIBase; + import org.osmf.elements.HTMLElement; + + /** + * The ClassSelectorList class is used to manage the list of class selectors + * applied to a component. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion Royale 1.0.0 + * @productversion Royale 0.0 + */ + public class ClassSelectorList + { + public function ClassSelectorList(component:IUIBase) + { + this.component = component; + } + + private var component:IUIBase; + + private var startIndex:int = 0; + private var count:int; + + /** + * Add a class selector to the list. + * @param name Name of selector to add. + */ + COMPILE::JS + public function add(name:String):void + { + component.positioner.classList.add(name); + if (!component.parent) + startIndex++; + } + + /** + * Add a class selector to the list. + * @param name Name of selector to remove. + */ + COMPILE::JS + public function remove(name:String):void + { + var classList:DOMTokenList = positioner.classList; + for (var i:int = 0; i < startIndex; i++) + { + if (classList.item(i) == name) + startIndex--; + } + positioner.classList.remove(name); + } + + /** + * Add or remove a class selector to/from the list. + * @param name Name of selector to add or remove. + * @param value True to add, False to remove. + */ + COMPILE::JS + public function toggle(name:String, value:Boolean):void + { + component.positioner.classList.toggle(name, value); + if (!component.parent && value) + startIndex++; + } + + + /** + * Add a space-separated list of names. + * @param names Space-separated list of names to add. + * @royaleignorecoercion HTMLElement + */ + COMPILE::JS + public function addNames(names:String):void + { + var positioner:HTMLElement = component.positioner as HTMLElement; + var classList:DOMTokenList = positioner.classList; + if (component.parent) + { + // remove names that were set last time + while (count > 0) + { + var name:String = classList.item(startIndex); + classList.remove(name); + } + } + positioner.className += names; + count = classList.length - startIndex; + } + } +} -- To stop receiving notification emails like this one, please contact aha...@apache.org.