You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by ca...@apache.org on 2018/03/23 07:57:17 UTC
[royale-asjs] 17/36: Refactor new styles API in UIBase to new
ClassListUtil
This is an automated email from the ASF dual-hosted git repository.
carlosrovira pushed a commit to branch feature/jewel-ui-set
in repository https://gitbox.apache.org/repos/asf/royale-asjs.git
commit 517bf0be4214c874574768db0cfdd1e7516edebd
Author: Carlos Rovira <ca...@apache.org>
AuthorDate: Thu Mar 15 19:22:50 2018 +0100
Refactor new styles API in UIBase to new ClassListUtil
---
.../main/royale/org/apache/royale/core/UIBase.as | 95 +--------------
.../main/royale/org/apache/royale/jewel/Button.as | 8 +-
.../royale/org/apache/royale/util/ClassListUtil.as | 131 +++++++++++++++++++++
3 files changed, 139 insertions(+), 95 deletions(-)
diff --git a/frameworks/projects/Jewel/src/main/royale/org/apache/royale/core/UIBase.as b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/core/UIBase.as
index 1a04fcf..de5e089 100644
--- a/frameworks/projects/Jewel/src/main/royale/org/apache/royale/core/UIBase.as
+++ b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/core/UIBase.as
@@ -37,6 +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;
}
/**
@@ -1074,6 +1075,7 @@ package org.apache.royale.core
return StringUtil.trim((_className ? _className : "") + " " + (typeNames ? typeNames : ""));
}
+
/**
* Sets the component styles in JS
*
@@ -1083,99 +1085,10 @@ package org.apache.royale.core
COMPILE::JS
protected function setClassName(value:String):void
{
- addStyles(value);
- }
-
- /**
- * 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
- */
- COMPILE::JS
- protected function addStyles(value:String):void
- {
- if (value == "") return;
-
- if (value.indexOf(" ") >= 0)
- {
- var classes:Array = value.split(" ");
- element.classList.add.apply(element.classList, classes);
- } else
- {
- element.classList.add(value);
- }
- }
-
- /**
- * 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
- */
- COMPILE::JS
- protected function removeStyles(value:String):void
- {
- if (value == "") return;
-
- if (value.indexOf(" ") >= 0)
- {
- var classes:Array = value.split(" ");
- element.classList.remove.apply(element.classList, classes);
- } else
- {
- element.classList.remove(value);
- }
- }
-
- /**
- * 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
- */
- COMPILE::JS
- protected function toggleStyle(value:String, force:Boolean = false):Boolean
- {
- return element.classList.toggle(value, force);
- }
-
- /**
- * Removes all styles that are not in typeNames
- *
- * @langversion 3.0
- * @playerversion Flash 10.2
- * @playerversion AIR 2.6
- * @productversion Royale 0.0
- */
- COMPILE::JS
- protected function removeAllStyles():void
- {
- var classList:DOMTokenList = element.classList;
- var i:int;
- for( i = classList.length; i > 0; i-- )
- {
- if(typeNames.indexOf(classList[i]) != 0)
- {
- classList.remove(classList[i]);
- }
- }
+ ClassListUtil.addStyles(this, value);
}
+
/**
* @copy org.apache.royale.core.IUIBase#element
*
diff --git a/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/Button.as b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/Button.as
index 1fea4bc..5e4dba9 100644
--- a/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/Button.as
+++ b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/Button.as
@@ -23,7 +23,7 @@ package org.apache.royale.jewel
COMPILE::JS
{
import org.apache.royale.core.WrappedHTMLElement;
- import org.apache.royale.html.util.addElementToWrapper;
+ import org.apache.royale.util.ClassListUtil;
}
/**
@@ -88,7 +88,7 @@ package org.apache.royale.jewel
COMPILE::JS
{
- toggleStyle("primary", value);
+ ClassListUtil.toggleStyle(this, "primary", value);
}
}
}
@@ -118,7 +118,7 @@ package org.apache.royale.jewel
COMPILE::JS
{
- toggleStyle("secondary", value);
+ ClassListUtil.toggleStyle(this, "secondary", value);
}
}
}
@@ -148,7 +148,7 @@ package org.apache.royale.jewel
COMPILE::JS
{
- toggleStyle("emphasized", value);
+ ClassListUtil.toggleStyle(this, "emphasized", value);
}
}
}
diff --git a/frameworks/projects/Jewel/src/main/royale/org/apache/royale/util/ClassListUtil.as b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/util/ClassListUtil.as
new file mode 100644
index 0000000..abbdee0
--- /dev/null
+++ b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/util/ClassListUtil.as
@@ -0,0 +1,131 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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.util
+{
+ /**
+ * The UIBase class is the base class for most composite user interface
+ * components. For the Flash Player, Buttons and Text controls may
+ * have a different base class and therefore may not extend UIBase.
+ * However all user interface components should implement IUIBase.
+ *
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion Royale 0.0
+ */
+ public class ClassListUtil
+ {
+ COMPILE::JS
+ {
+ import org.apache.royale.core.UIBase;
+ import org.apache.royale.core.WrappedHTMLElement;
+ }
+
+ /**
+ * 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
+ */
+ COMPILE::JS
+ public static function addStyles(wrapper:UIBase, 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);
+ }
+ }
+
+ /**
+ * 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
+ */
+ COMPILE::JS
+ public static function removeStyles(wrapper:UIBase, value:String):void
+ {
+ if (value == "") return;
+
+ if (value.indexOf(" ") >= 0)
+ {
+ var classes:Array = value.split(" ");
+ wrapper.element.classList.remove.apply(wrapper.element.classList, classes);
+ } else
+ {
+ wrapper.element.classList.remove(value);
+ }
+ }
+
+ /**
+ * 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
+ */
+ COMPILE::JS
+ public static function toggleStyle(wrapper:UIBase, value:String, force:Boolean = false):Boolean
+ {
+ return wrapper.element.classList.toggle(value, force);
+ }
+
+ /**
+ * Removes all styles that are not in typeNames
+ *
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion Royale 0.0
+ */
+ COMPILE::JS
+ public static function removeAllStyles(wrapper:UIBase):void
+ {
+ var classList:DOMTokenList = wrapper.element.classList;
+ var i:int;
+ for( i = classList.length; i > 0; i-- )
+ {
+ if(wrapper.typeNames.indexOf(classList[i]) != 0)
+ {
+ classList.remove(classList[i]);
+ }
+ }
+ }
+
+ }
+}
\ No newline at end of file
--
To stop receiving notification emails like this one, please contact
carlosrovira@apache.org.