MDL TextPromptBead in place

Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/8390928a
Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/8390928a
Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/8390928a

Branch: refs/heads/feature/mdl
Commit: 8390928a15cc161512931c0eaa17677505b17d61
Parents: 911901b
Author: Carlos Rovira <carlosrov...@apache.org>
Authored: Wed Oct 26 12:29:26 2016 +0200
Committer: Carlos Rovira <carlosrov...@apache.org>
Committed: Sun Nov 6 13:15:38 2016 +0100

----------------------------------------------------------------------
 .../flexjs/MDLExample/src/main/flex/App.mxml    |  12 +-
 .../src/main/flex/MDLClasses.as                 |   2 +-
 .../main/flex/org/apache/flex/mdl/TextInput.as  |  16 +-
 .../org/apache/flex/mdl/beads/TextPromptBead.as | 151 +++++++++++++++++++
 .../src/main/resources/mdl-manifest.xml         |   1 +
 5 files changed, 178 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/8390928a/examples/flexjs/MDLExample/src/main/flex/App.mxml
----------------------------------------------------------------------
diff --git a/examples/flexjs/MDLExample/src/main/flex/App.mxml 
b/examples/flexjs/MDLExample/src/main/flex/App.mxml
index 3924dba..9f1be78 100644
--- a/examples/flexjs/MDLExample/src/main/flex/App.mxml
+++ b/examples/flexjs/MDLExample/src/main/flex/App.mxml
@@ -55,8 +55,16 @@ limitations under the License.
                 </js:HContainer>
 
                 <!-- Text Fields :: 
https://getmdl.io/components/index.html#textfields-section -->
-                <mdl:TextInput id="mdlti" text="Normal Text Field..." 
change="mdlchk.text = mdlti.text"/>
-                <mdl:TextInput text="Floating Label" 
mdlEffect="mdl-textfield--floating-label" />
+                <mdl:TextInput id="mdlti" change="mdlchk.text = mdlti.text">
+                    <js:beads>
+                        <mdl:TextPromptBead prompt="Normal Text Field..."/>
+                    </js:beads>
+                </mdl:TextInput>
+                <mdl:TextInput mdlEffect="mdl-textfield--floating-label">
+                    <js:beads>
+                        <mdl:TextPromptBead prompt="Floating Label"/>
+                    </js:beads>
+                </mdl:TextInput>
 
                 <!-- Toggles :: 
https://getmdl.io/components/index.html#toggles-section -->
                 <mdl:CheckBox id="mdlchk" text="Disabled at start" />

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/8390928a/frameworks/projects/MaterialDesignLite/src/main/flex/MDLClasses.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/MaterialDesignLite/src/main/flex/MDLClasses.as 
b/frameworks/projects/MaterialDesignLite/src/main/flex/MDLClasses.as
index 733728e..c0ea571 100644
--- a/frameworks/projects/MaterialDesignLite/src/main/flex/MDLClasses.as
+++ b/frameworks/projects/MaterialDesignLite/src/main/flex/MDLClasses.as
@@ -29,7 +29,7 @@ internal class MDLClasses
 {      
        COMPILE::SWF
        {
-               //import org.apache.flex.flat.beads.CSSScrollBarView; 
CSSScrollBarView;
+               //import org.apache.flex.mdl.beads.TextPromptBead; 
TextPromptBead;
        }
 }
 

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/8390928a/frameworks/projects/MaterialDesignLite/src/main/flex/org/apache/flex/mdl/TextInput.as
----------------------------------------------------------------------
diff --git 
a/frameworks/projects/MaterialDesignLite/src/main/flex/org/apache/flex/mdl/TextInput.as
 
b/frameworks/projects/MaterialDesignLite/src/main/flex/org/apache/flex/mdl/TextInput.as
index 87f9c5a..c8244a4 100644
--- 
a/frameworks/projects/MaterialDesignLite/src/main/flex/org/apache/flex/mdl/TextInput.as
+++ 
b/frameworks/projects/MaterialDesignLite/src/main/flex/org/apache/flex/mdl/TextInput.as
@@ -17,6 +17,8 @@
 
////////////////////////////////////////////////////////////////////////////////
 package org.apache.flex.mdl
 {
+    import org.apache.flex.core.ITextModel;
+       import org.apache.flex.events.Event;
        import org.apache.flex.html.TextInput;
 
     COMPILE::JS
@@ -52,6 +54,16 @@ package org.apache.flex.mdl
         COMPILE::JS
         {
             private var _textNode:Text;
+
+            public function get textNode():Text
+            {
+                return _textNode;
+            }
+
+            public function set textNode(value:Text):void
+            {
+                _textNode = value;
+            }
         }
         
         /**
@@ -78,7 +90,7 @@ package org.apache.flex.mdl
             var label:HTMLLabelElement = document.createElement('label') as 
HTMLLabelElement;
             label.className = "mdl-textfield__label";
 
-            var textNode:Text = document.createTextNode('') as Text;
+            textNode = document.createTextNode('') as Text;
             label.appendChild(textNode);
             
             div.appendChild(input);
@@ -110,5 +122,7 @@ package org.apache.flex.mdl
                 positioner.className = positioner.className + " " + _mdlEffect;
             }
         }
+
+        
        }
 }

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/8390928a/frameworks/projects/MaterialDesignLite/src/main/flex/org/apache/flex/mdl/beads/TextPromptBead.as
----------------------------------------------------------------------
diff --git 
a/frameworks/projects/MaterialDesignLite/src/main/flex/org/apache/flex/mdl/beads/TextPromptBead.as
 
b/frameworks/projects/MaterialDesignLite/src/main/flex/org/apache/flex/mdl/beads/TextPromptBead.as
new file mode 100644
index 0000000..1c1e8fb
--- /dev/null
+++ 
b/frameworks/projects/MaterialDesignLite/src/main/flex/org/apache/flex/mdl/beads/TextPromptBead.as
@@ -0,0 +1,151 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  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.flex.mdl.beads
+{
+       COMPILE::SWF
+       {
+               import flash.text.TextFieldType;                        
+               
+               import org.apache.flex.core.CSSTextField;
+       }
+       
+       import org.apache.flex.core.IBead;
+       import org.apache.flex.core.IStrand;
+       import org.apache.flex.core.UIBase;
+       import org.apache.flex.events.Event;
+       import org.apache.flex.events.IEventDispatcher;
+
+    import org.apache.flex.mdl.TextInput;
+       
+       /**
+        *  The TextPromptBead class is a specialty bead that can be used with
+        *  any TextInput control. The bead places a string into the input field
+        *  when there is no value associated with the text property.
+        *  
+        *  @langversion 3.0
+        *  @playerversion Flash 10.2
+        *  @playerversion AIR 2.6
+        *  @productversion FlexJS 0.0
+        */
+       public class TextPromptBead implements IBead
+       {
+               /**
+                *  constructor.
+                *
+                *  @langversion 3.0
+                *  @playerversion Flash 10.2
+                *  @playerversion AIR 2.6
+                *  @productversion FlexJS 0.0
+                */
+               public function TextPromptBead()
+               {
+               }
+               
+               private var _prompt:String;
+               
+               /**
+                *  The string to use as the placeholder prompt.
+                *
+                *  @langversion 3.0
+                *  @playerversion Flash 10.2
+                *  @playerversion AIR 2.6
+                *  @productversion FlexJS 0.0
+                */
+               public function get prompt():String
+               {
+                       return _prompt;
+               }
+               public function set prompt(value:String):void
+               {
+                       _prompt = value;
+               }
+               
+               private var _strand:IStrand;
+               
+               /**
+                *  @copy org.apache.flex.core.IBead#strand
+                *  
+                *  @langversion 3.0
+                *  @playerversion Flash 10.2
+                *  @playerversion AIR 2.6
+                *  @productversion FlexJS 0.0
+                *  @flexjsignorecoercion HTMLInputElement
+                *  @flexjsignorecoercion org.apache.flex.core.UIBase;
+                */
+               public function set strand(value:IStrand):void
+               {
+                       _strand = value;
+                       
+                       COMPILE::SWF
+                       {
+                               // listen for changes in text to hide or show 
the prompt
+                               var model:Object = UIBase(_strand).model;
+                               if (!model.hasOwnProperty("text")) {
+                                       throw new Error("Model requires a text 
property when used with TextPromptBead");
+                               }
+                               
IEventDispatcher(model).addEventListener("textChange", handleTextChange);
+                               
+                               // create a TextField that displays the prompt 
- it shows
+                               // and hides based on the model's content
+                               promptField = new CSSTextField();
+                               promptField.selectable = false;
+                               promptField.type = TextFieldType.DYNAMIC;
+                               promptField.mouseEnabled = false;
+                               promptField.multiline = false;
+                               promptField.wordWrap = false;
+                               promptField.textColor = 0xBBBBBB;
+                               
+                               // trigger the event handler to display if 
needed
+                               handleTextChange(null);                         
        
+                       }
+                       COMPILE::JS
+                       {
+                               var mdlTi:TextInput = value as TextInput;
+                mdlTi.textNode.nodeValue = prompt;
+                               //var e:HTMLInputElement = host.element as 
HTMLInputElement;
+                               //e.placeholder = prompt;
+                       }
+               }
+               
+               COMPILE::SWF
+               private var promptField:CSSTextField;
+               private var promptAdded:Boolean;
+               
+               /**
+                * @private
+                */
+               COMPILE::SWF
+               private function handleTextChange( event:Event ):void
+               {       
+                       // see what the model currently has to determine if the 
prompt should be
+                       // displayed or not.
+                       var model:Object = UIBase(_strand).model;
+                       
+                       if (model.text != null && model.text.length > 0 ) {
+                               if (promptAdded) 
UIBase(_strand).removeChild(promptField);
+                               promptAdded = false;
+                       }
+                       else {
+                               if (!promptAdded) 
UIBase(_strand).addChild(promptField);
+                               promptField.text = prompt;
+                               promptAdded = true;
+                       }
+               }
+       }
+}

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/8390928a/frameworks/projects/MaterialDesignLite/src/main/resources/mdl-manifest.xml
----------------------------------------------------------------------
diff --git 
a/frameworks/projects/MaterialDesignLite/src/main/resources/mdl-manifest.xml 
b/frameworks/projects/MaterialDesignLite/src/main/resources/mdl-manifest.xml
index 6dcb073..9f47fea 100644
--- a/frameworks/projects/MaterialDesignLite/src/main/resources/mdl-manifest.xml
+++ b/frameworks/projects/MaterialDesignLite/src/main/resources/mdl-manifest.xml
@@ -25,5 +25,6 @@
     <component id="TextInput" class="org.apache.flex.mdl.TextInput"/>
     <component id="CheckBox" class="org.apache.flex.mdl.CheckBox"/>
     <component id="RadioButton" class="org.apache.flex.mdl.RadioButton"/>
+    <component id="TextPromptBead" 
class="org.apache.flex.mdl.beads.TextPromptBead"/>
 
 </componentPackage>

Reply via email to