You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@royale.apache.org by Harbs <ha...@gmail.com> on 2018/02/26 12:13:36 UTC

Re: [royale-asjs] branch develop updated: Fixed classNames in MDL button

Piotr,

Please look at what I’ve done here. I don’t know if this needs to be fixed elsewhere. I also only tested *adding* of typeNames and not *removal* of them.

> On Feb 26, 2018, at 2:10 PM, harbs@apache.org wrote:
> 
> 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 c01ebc2  Fixed classNames in MDL button
> c01ebc2 is described below
> 
> commit c01ebc2cc946570006d8f5cea607182e16eaf0fe
> Author: Harbs <ha...@in-tools.com>
> AuthorDate: Mon Feb 26 14:10:22 2018 +0200
> 
>    Fixed classNames in MDL button
> 
>    Any MDL Button which set the className on a specific button blew away any settings that were set by the MDL button
> 
>    I don;t know if similar changes need to be made in other MDL components
> ---
> .../main/royale/org/apache/royale/mdl/Button.as    | 73 +++++++++-------------
> 1 file changed, 31 insertions(+), 42 deletions(-)
> 
> diff --git a/frameworks/projects/MaterialDesignLite/src/main/royale/org/apache/royale/mdl/Button.as b/frameworks/projects/MaterialDesignLite/src/main/royale/org/apache/royale/mdl/Button.as
> index 339d4ea..9aed576 100644
> --- a/frameworks/projects/MaterialDesignLite/src/main/royale/org/apache/royale/mdl/Button.as
> +++ b/frameworks/projects/MaterialDesignLite/src/main/royale/org/apache/royale/mdl/Button.as
> @@ -27,7 +27,6 @@ package org.apache.royale.mdl
>     {
>         import org.apache.royale.core.WrappedHTMLElement;
>         import org.apache.royale.html.util.addElementToWrapper;
> -        import org.apache.royale.html.util.addOrReplaceClassName;
>     }
> 
>     /**
> @@ -114,11 +113,7 @@ package org.apache.royale.mdl
> 
>                 COMPILE::JS
>                 {
> -                    element.classList.remove("mdl-button--fab");
> -                    if (value)
> -                    {
> -                        className = addOrReplaceClassName(className, "mdl-button--fab");
> -                    }
> +                    adjustTypeNames("mdl-button--fab", value);
>                 }
>             }
>         }
> @@ -142,17 +137,35 @@ package org.apache.royale.mdl
>             if (_raised != value)
>             {
>                 _raised = value;
> -
>                 COMPILE::JS
>                 {
> -                    element.classList.remove("mdl-button--raised");
> -                    if (value)
> -                    {
> -                        className = addOrReplaceClassName(className, "mdl-button--raised");
> -                    }
> +                    adjustTypeNames("mdl-button--raised", value);
>                 }
>             }
>         }
> +        COMPILE::JS
> +        private function adjustTypeNames(type:String,add:Boolean):void
> +        {
> +            type = " " + type;
> +            var typeLength:int = type.length;
> +            var typeIdx:int = typeNames.indexOf(type);
> +            var adjust:Boolean = false;
> +            if(add && typeIdx == -1)
> +            {
> +                typeNames += type;
> +                adjust = true;
> +            }
> +            else if(!add && typeIdx != -1)
> +            {
> +                typeNames = typeNames.substr(typeIdx,typeLength);
> +                adjust = true;
> +            }
> +            if(adjust)
> +            {
> +                var cl:String = className;
> +                setClassName((cl ? cl + " " : "") + typeNames);                
> +            }
> +        }
> 
>         private var _colored:Boolean = false;
>         /**
> @@ -177,11 +190,7 @@ package org.apache.royale.mdl
> 
>                 COMPILE::JS
>                 {
> -                    element.classList.remove("mdl-button--colored");
> -                    if (value)
> -                    {
> -                        className = addOrReplaceClassName(className, "mdl-button--colored");
> -                    }
> +                    adjustTypeNames("mdl-button--colored", value);
>                 }
>             }
>         }
> @@ -209,11 +218,7 @@ package org.apache.royale.mdl
> 
>                 COMPILE::JS
>                 {
> -                    element.classList.remove("mdl-button--accent");
> -                    if (value)
> -                    {
> -                        className = addOrReplaceClassName(className, "mdl-button--accent");
> -                    }
> +                    adjustTypeNames("mdl-button--accent", value);
>                 }
>             }
>         }
> @@ -241,11 +246,7 @@ package org.apache.royale.mdl
> 
>                 COMPILE::JS
>                 {
> -                    element.classList.remove("mdl-button--primary");
> -                    if (value)
> -                    {
> -                        className = addOrReplaceClassName(className, "mdl-button--primary");
> -                    }
> +                    adjustTypeNames("mdl-button--primary", value);
>                 }
>             }
>         }
> @@ -273,11 +274,7 @@ package org.apache.royale.mdl
> 
>                 COMPILE::JS
>                 {
> -                    element.classList.remove("mdl-button--mini-fab");
> -                    if (value)
> -                    {
> -                        className = addOrReplaceClassName(className, "mdl-button--mini-fab");
> -                    }
> +                    adjustTypeNames("mdl-button--mini-fab", value);
>                 }
>             }
>         }
> @@ -305,11 +302,7 @@ package org.apache.royale.mdl
> 
>                 COMPILE::JS
>                 {
> -                    element.classList.remove("mdl-button--icon");
> -                    if (value)
> -                    {
> -                        className = addOrReplaceClassName(className, "mdl-button--icon");
> -                    }
> +                    adjustTypeNames("mdl-button--icon", value);
>                 }
>             }
>         }
> @@ -336,11 +329,7 @@ package org.apache.royale.mdl
> 
>                 COMPILE::JS
>                 {
> -                    element.classList.remove("mdl-js-ripple-effect");
> -                    if (value)
> -                    {
> -                        className = addOrReplaceClassName(className, "mdl-js-ripple-effect");
> -                    }
> +                    adjustTypeNames("mdl-js-ripple-effect", value);
>                 }
>             }
>         }
> 
> -- 
> To stop receiving notification emails like this one, please contact
> harbs@apache.org.