Hi, just fixed. Changed IUIBase to WrappedHTMLElement so instead using the functions passing "this" you must pass "element" I think is ok.
One more thing is that tI notice you removed "typeName" from removeAllStyles method, so now this will remove all classes included typeNames, I think we want to maintiain typeNames inmutable right ? 2018-03-16 15:14 GMT+01:00 Carlos Rovira <[email protected]>: > Hi Harbs > > I'm building and find the following error, did you compile and try your > change? > > thanks > > [*INFO*] Executing ASDOC in tool group Royale with args: > [-load-config=/Users/carlosrovira/Dev/Royale/ > Source/royale-asjs/frameworks/projects/Core/target/compile-asdoc-swf-config.xml, > -js-output-type=royale_dita] > > /Users/carlosrovira/Dev/Royale/Source/royale-asjs/ > frameworks/projects/Core/src/main/royale/org/apache/royale/ > utils/cssclasslist/addStyles.as(40): col: 21 Access of possibly undefined > property element through a reference with static type IUIBase. > > > wrapper.element.classList.add.apply(wrapper.element.classList, > classes); > > ^ > > > /Users/carlosrovira/Dev/Royale/Source/royale-asjs/ > frameworks/projects/Core/src/main/royale/org/apache/royale/ > utils/cssclasslist/addStyles.as(40): col: 57 Access of possibly undefined > property element through a reference with static type IUIBase. > > > wrapper.element.classList.add.apply(wrapper.element.classList, > classes); > > ^ > > > /Users/carlosrovira/Dev/Royale/Source/royale-asjs/ > frameworks/projects/Core/src/main/royale/org/apache/royale/ > utils/cssclasslist/addStyles.as(43): col: 21 Access of possibly undefined > property element through a reference with static type IUIBase. > > > wrapper.element.classList.add(value); > > ^ > > > /Users/carlosrovira/Dev/Royale/Source/royale-asjs/ > frameworks/projects/Core/src/main/royale/org/apache/royale/ > utils/cssclasslist/removeAllStyles.as(33): col: 46 Access of possibly > undefined property element through a reference with static type IUIBase. > > > var classList:DOMTokenList = wrapper.element.classList; > > ^ > > > /Users/carlosrovira/Dev/Royale/Source/royale-asjs/ > frameworks/projects/Core/src/main/royale/org/apache/royale/ > utils/cssclasslist/removeStyles.as(40): col: 21 Access of possibly > undefined property element through a reference with static type IUIBase. > > > wrapper.element.classList.remove.apply(wrapper.element.classList, > classes); > > ^ > > > /Users/carlosrovira/Dev/Royale/Source/royale-asjs/ > frameworks/projects/Core/src/main/royale/org/apache/royale/ > utils/cssclasslist/removeStyles.as(40): col: 60 Access of possibly > undefined property element through a reference with static type IUIBase. > > > wrapper.element.classList.remove.apply(wrapper.element.classList, > classes); > > ^ > > > /Users/carlosrovira/Dev/Royale/Source/royale-asjs/ > frameworks/projects/Core/src/main/royale/org/apache/royale/ > utils/cssclasslist/removeStyles.as(43): col: 21 Access of possibly > undefined property element through a reference with static type IUIBase. > > > wrapper.element.classList.remove(value); > > ^ > > > /Users/carlosrovira/Dev/Royale/Source/royale-asjs/ > frameworks/projects/Core/src/main/royale/org/apache/royale/ > utils/cssclasslist/toggleStyle.as(37): col: 24 Access of possibly > undefined property element through a reference with static type IUIBase. > > > return wrapper.element.classList.toggle(value, force); > > ^ > > > 2018-03-16 13:15 GMT+01:00 Carlos Rovira <[email protected]>: > >> Ok Harbs, >> >> I like the change >> thanks! >> >> 2018-03-16 12:15 GMT+01:00 Harbs <[email protected]>: >> >>> Carlos, >>> >>> Irrespective of the general discussions on using classList directly, I >>> think using package level functions is better than multifaceted static Util >>> classes. >>> >>> > On Mar 16, 2018, at 1:05 PM, [email protected] wrote: >>> > >>> > This is an automated email from the ASF dual-hosted git repository. >>> > >>> > harbs pushed a commit to branch feature/jewel-ui-set >>> > in repository https://gitbox.apache.org/repos/asf/royale-asjs.git >>> > >>> > >>> > The following commit(s) were added to refs/heads/feature/jewel-ui-set >>> by this push: >>> > new 46d392f Moved util functions to package-level ones >>> > 46d392f is described below >>> > >>> > commit 46d392f30454b9509cc88f883fc7ba0060219acc >>> > Author: Harbs <[email protected]> >>> > AuthorDate: Fri Mar 16 13:05:15 2018 +0200 >>> > >>> > Moved util functions to package-level ones >>> > >>> > (not sure about removeAllStyles — it seemed to have had a bug so it >>> was probably not functional either way) >>> > --- >>> > .../projects/Core/src/main/royale/CoreClasses.as | 5 +++ >>> > .../apache/royale/utils/cssclasslist/addStyles.as | 47 >>> ++++++++++++++++++++++ >>> > .../royale/utils/cssclasslist/removeAllStyles.as | 41 >>> +++++++++++++++++++ >>> > .../royale/utils/cssclasslist/removeStyles.as | 46 >>> +++++++++++++++++++++ >>> > .../royale/utils/cssclasslist/toggleStyle.as | 39 >>> ++++++++++++++++++ >>> > .../main/royale/org/apache/royale/core/UIBase.as | 4 +- >>> > .../main/royale/org/apache/royale/jewel/Button.as | 8 ++-- >>> > 7 files changed, 184 insertions(+), 6 deletions(-) >>> > >>> > diff --git a/frameworks/projects/Core/src/main/royale/CoreClasses.as >>> b/frameworks/projects/Core/src/main/royale/CoreClasses.as >>> > index 8685789..8b0357d 100644 >>> > --- a/frameworks/projects/Core/src/main/royale/CoreClasses.as >>> > +++ b/frameworks/projects/Core/src/main/royale/CoreClasses.as >>> > @@ -224,6 +224,11 @@ internal class CoreClasses >>> > import org.apache.royale.core.IRoyaleElement; >>> IRoyaleElement; >>> > import org.apache.royale.utils.object.defineGetter; >>> defineGetter; >>> > import org.apache.royale.utils.object.defineSimpleGetter; >>> defineSimpleGetter; >>> > + >>> > + import org.apache.royale.utils.cssclasslist.removeAllStyles; >>> removeAllStyles; >>> > + import org.apache.royale.utils.cssclasslist.removeStyles; >>> removeStyles; >>> > + import org.apache.royale.utils.cssclasslist.toggleStyle; >>> toggleStyle; >>> > + import org.apache.royale.utils.cssclasslist.addStyles; >>> addStyles; >>> > } >>> > //Package Level Functions >>> > import org.apache.royale.debugging.assert; assert; >>> > diff --git a/frameworks/projects/Core/src >>> /main/royale/org/apache/royale/utils/cssclasslist/addStyles.as >>> b/frameworks/projects/Core/src/main/royale/org/apache/royale >>> /utils/cssclasslist/addStyles.as >>> > new file mode 100644 >>> > index 0000000..aa995a0 >>> > --- /dev/null >>> > +++ b/frameworks/projects/Core/src/main/royale/org/apache/royale >>> /utils/cssclasslist/addStyles.as >>> > @@ -0,0 +1,47 @@ >>> > +/////////////////////////////////////////////////////////// >>> ///////////////////// >>> > +// >>> > +// 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 "Licens"); 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.cssclasslist >>> > +{ >>> > + import org.apache.royale.core.IUIBase; >>> > + >>> > + /** >>> > + * Add one or more styles to the component. If the specified >>> class already >>> > + * exist, the class will not be added. >>> > + * >>> > + * @param value, a String with the style (or styles separated by >>> an space) to >>> > + * add from the component. If the string is empty doesn't >>> perform any action >>> > + * >>> > + * @langversion 3.0 >>> > + * @productversion Royale 0.9.3 >>> > + */ >>> > + public function addStyles(wrapper:IUIBase, value:String):void >>> > + { >>> > + if (value == "") return; >>> > + >>> > + if (value.indexOf(" ") >= 0) >>> > + { >>> > + var classes:Array = value.split(" "); >>> > + wrapper.element.classList.add. >>> apply(wrapper.element.classList, classes); >>> > + } else >>> > + { >>> > + wrapper.element.classList.add(value); >>> > + } >>> > + } >>> > + >>> > +} >>> > diff --git a/frameworks/projects/Core/src >>> /main/royale/org/apache/royale/utils/cssclasslist/removeAllStyles.as >>> b/frameworks/projects/Core/src/main/royale/org/apache/royale >>> /utils/cssclasslist/removeAllStyles.as >>> > new file mode 100644 >>> > index 0000000..4d19c79 >>> > --- /dev/null >>> > +++ b/frameworks/projects/Core/src/main/royale/org/apache/royale >>> /utils/cssclasslist/removeAllStyles.as >>> > @@ -0,0 +1,41 @@ >>> > +/////////////////////////////////////////////////////////// >>> ///////////////////// >>> > +// >>> > +// 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 "Licens"); 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.cssclasslist >>> > +{ >>> > + import org.apache.royale.core.IUIBase; >>> > + >>> > + /** >>> > + * Removes all styles >>> > + * >>> > + * @langversion 3.0 >>> > + * @playerversion Flash 10.2 >>> > + * @playerversion AIR 2.6 >>> > + * @productversion Royale 0.9.3 >>> > + */ >>> > + public function removeAllStyles(wrapper:IUIBase):void >>> > + { >>> > + var classList:DOMTokenList = wrapper.element.classList; >>> > + var i:int; >>> > + for( i = classList.length -1; i > 0; i-- ) >>> > + { >>> > + classList.remove(classList[i]); >>> > + } >>> > + } >>> > + >>> > +} >>> > diff --git a/frameworks/projects/Core/src >>> /main/royale/org/apache/royale/utils/cssclasslist/removeStyles.as >>> b/frameworks/projects/Core/src/main/royale/org/apache/royale >>> /utils/cssclasslist/removeStyles.as >>> > new file mode 100644 >>> > index 0000000..21f59e0 >>> > --- /dev/null >>> > +++ b/frameworks/projects/Core/src/main/royale/org/apache/royale >>> /utils/cssclasslist/removeStyles.as >>> > @@ -0,0 +1,46 @@ >>> > +/////////////////////////////////////////////////////////// >>> ///////////////////// >>> > +// >>> > +// 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 "Licens"); 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.cssclasslist >>> > +{ >>> > + import org.apache.royale.core.IUIBase; >>> > + >>> > + /** >>> > + * Removes one or more styles from the component. Removing a >>> class that does not >>> > + * exist, does not throw any error >>> > + * >>> > + * @param value, a String with the style (or styles separated by >>> an space) to >>> > + * remove from the component. If the string is empty doesn't >>> perform any action >>> > + * >>> > + * @langversion 3.0 >>> > + * @productversion Royale 0.9.3 >>> > + */ >>> > + public function removeStyles(wrapper:IUIBase, value:String):void >>> > + { >>> > + if (value == "") return; >>> > + >>> > + if (value.indexOf(" ") >= 0) >>> > + { >>> > + var classes:Array = value.split(" "); >>> > + wrapper.element.classList.remo >>> ve.apply(wrapper.element.classList, classes); >>> > + } else >>> > + { >>> > + wrapper.element.classList.remove(value); >>> > + } >>> > + } >>> > +} >>> > diff --git a/frameworks/projects/Core/src >>> /main/royale/org/apache/royale/utils/cssclasslist/toggleStyle.as >>> b/frameworks/projects/Core/src/main/royale/org/apache/royale >>> /utils/cssclasslist/toggleStyle.as >>> > new file mode 100644 >>> > index 0000000..8ef9224 >>> > --- /dev/null >>> > +++ b/frameworks/projects/Core/src/main/royale/org/apache/royale >>> /utils/cssclasslist/toggleStyle.as >>> > @@ -0,0 +1,39 @@ >>> > +/////////////////////////////////////////////////////////// >>> ///////////////////// >>> > +// >>> > +// 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 "Licens"); 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.cssclasslist >>> > +{ >>> > + import org.apache.royale.core.IUIBase; >>> > + >>> > + /** >>> > + * Adds or removes a single style. >>> > + * >>> > + * The first parameter removes the style from an element, and >>> returns false. >>> > + * If the style does not exist, it is added to the element, and >>> the return value is true. >>> > + * >>> > + * The optional second parameter is a Boolean value that forces >>> the class to be added >>> > + * or removed, regardless of whether or not it already existed. >>> > + * >>> > + * @langversion 3.0 >>> > + * @productversion Royale 0.9.3 >>> > + */ >>> > + public function toggleStyle(wrapper:IUIBase, value:String, >>> force:Boolean = false):Boolean >>> > + { >>> > + return wrapper.element.classList.toggle(value, force); >>> > + } >>> > +} >>> > diff --git a/frameworks/projects/Jewel/sr >>> c/main/royale/org/apache/royale/core/UIBase.as >>> b/frameworks/projects/Jewel/src/main/royale/org/apache/royal >>> e/core/UIBase.as >>> > index de5e089..c14e113 100644 >>> > --- a/frameworks/projects/Jewel/src/main/royale/org/apache/royal >>> e/core/UIBase.as >>> > +++ b/frameworks/projects/Jewel/src/main/royale/org/apache/royal >>> e/core/UIBase.as >>> > @@ -37,7 +37,7 @@ package org.apache.royale.core >>> > { >>> > import org.apache.royale.html.util.addElementToWrapper; >>> > import org.apache.royale.utils.CSSUtils; >>> > - import org.apache.royale.util.ClassListUtil; >>> > + import org.apache.royale.utils.cssclasslist.addStyles; >>> > } >>> > >>> > /** >>> > @@ -1085,7 +1085,7 @@ package org.apache.royale.core >>> > COMPILE::JS >>> > protected function setClassName(value:String):void >>> > { >>> > - ClassListUtil.addStyles(this, value); >>> > + addStyles(this, value); >>> > } >>> > >>> > >>> > diff --git a/frameworks/projects/Jewel/sr >>> c/main/royale/org/apache/royale/jewel/Button.as >>> b/frameworks/projects/Jewel/src/main/royale/org/apache/royal >>> e/jewel/Button.as >>> > index 5e4dba9..4059764 100644 >>> > --- a/frameworks/projects/Jewel/src/main/royale/org/apache/royal >>> e/jewel/Button.as >>> > +++ b/frameworks/projects/Jewel/src/main/royale/org/apache/royal >>> e/jewel/Button.as >>> > @@ -23,7 +23,7 @@ package org.apache.royale.jewel >>> > COMPILE::JS >>> > { >>> > import org.apache.royale.core.WrappedHTMLElement; >>> > - import org.apache.royale.util.ClassListUtil; >>> > + import org.apache.royale.utils.cssclasslist.toggleStyle; >>> > } >>> > >>> > /** >>> > @@ -88,7 +88,7 @@ package org.apache.royale.jewel >>> > >>> > COMPILE::JS >>> > { >>> > - ClassListUtil.toggleStyle(this, "primary", >>> value); >>> > + toggleStyle(this, "primary", value); >>> > } >>> > } >>> > } >>> > @@ -118,7 +118,7 @@ package org.apache.royale.jewel >>> > >>> > COMPILE::JS >>> > { >>> > - ClassListUtil.toggleStyle(this, "secondary", >>> value); >>> > + toggleStyle(this, "secondary", value); >>> > } >>> > } >>> > } >>> > @@ -148,7 +148,7 @@ package org.apache.royale.jewel >>> > >>> > COMPILE::JS >>> > { >>> > - ClassListUtil.toggleStyle(this, "emphasized", >>> value); >>> > + toggleStyle(this, "emphasized", value); >>> > } >>> > } >>> > } >>> > >>> > -- >>> > To stop receiving notification emails like this one, please contact >>> > [email protected]. >>> >>> >> >> >> -- >> Carlos Rovira >> http://about.me/carlosrovira >> >> > > > -- > Carlos Rovira > http://about.me/carlosrovira > > -- Carlos Rovira http://about.me/carlosrovira
