You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by pe...@apache.org on 2015/01/21 23:53:45 UTC

[3/3] git commit: [flex-asjs] [refs/heads/develop] - Updated the JS RadioButton to work better with jQuery and to have a more natural layout.

Updated the JS RadioButton to work better with jQuery and to have a more natural layout.


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

Branch: refs/heads/develop
Commit: 406ace6f8f77d0c77cfbf90c5920647e260ea70a
Parents: c005141
Author: Peter Ent <pe...@apache.org>
Authored: Wed Jan 21 17:53:31 2015 -0500
Committer: Peter Ent <pe...@apache.org>
Committed: Wed Jan 21 17:53:31 2015 -0500

----------------------------------------------------------------------
 .../src/org/apache/flex/html/RadioButton.js     | 54 +++++++----
 .../src/org/apache/flex/jquery/RadioButton.js   | 97 ++++++++++++++++++--
 2 files changed, 127 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/406ace6f/frameworks/js/FlexJS/src/org/apache/flex/html/RadioButton.js
----------------------------------------------------------------------
diff --git a/frameworks/js/FlexJS/src/org/apache/flex/html/RadioButton.js b/frameworks/js/FlexJS/src/org/apache/flex/html/RadioButton.js
index 98616a1..46e9114 100644
--- a/frameworks/js/FlexJS/src/org/apache/flex/html/RadioButton.js
+++ b/frameworks/js/FlexJS/src/org/apache/flex/html/RadioButton.js
@@ -40,22 +40,32 @@ org.apache.flex.html.RadioButton.prototype.FLEXJS_CLASS_INFO =
 
 
 /**
+ * Provides unique name
+ */
+org.apache.flex.html.RadioButton.radioCounter = 0;
+
+
+/**
  * @override
  */
 org.apache.flex.html.RadioButton.prototype.createElement =
     function() {
-  var rb;
 
-  this.element = document.createElement('label');
+  this.input = document.createElement('input');
+  this.input.type = 'radio';
+  this.input.id = '_radio_' + org.apache.flex.html.RadioButton.radioCounter++;
+
+  this.textNode = document.createTextNode('radio button');
 
-  rb = document.createElement('input');
-  rb.type = 'radio';
-  this.element.appendChild(rb);
-  this.element.appendChild(document.createTextNode('radio button'));
+  this.labelFor = document.createElement('label');
+  this.labelFor.appendChild(this.input);
+  this.labelFor.appendChild(this.textNode);
 
+  this.element = this.labelFor;
   this.positioner = this.element;
-  rb.flexjs_wrapper = this;
+  this.input.flexjs_wrapper = this;
   this.element.flexjs_wrapper = this;
+  this.textNode.flexjs_wrapper = this;
 
   return this.element;
 };
@@ -78,12 +88,22 @@ org.apache.flex.html.RadioButton.prototype.initSkin =
 
 
 /**
+ * @override
+ */
+org.apache.flex.html.RadioButton.prototype.set_id = function(value) {
+  org.apache.flex.html.RadioButton.base(this, 'set_id', value);
+  this.labelFor.id = value;
+  this.input.id = value;
+};
+
+
+/**
  * @expose
  * @return {string} The groupName getter.
  */
 org.apache.flex.html.RadioButton.prototype.get_groupName =
     function() {
-  return this.element.childNodes.item(0).name;
+  return this.input.name;
 };
 
 
@@ -93,7 +113,7 @@ org.apache.flex.html.RadioButton.prototype.get_groupName =
  */
 org.apache.flex.html.RadioButton.prototype.set_groupName =
     function(value) {
-  this.element.childNodes.item(0).name = value;
+  this.input.name = value;
 };
 
 
@@ -103,7 +123,7 @@ org.apache.flex.html.RadioButton.prototype.set_groupName =
  */
 org.apache.flex.html.RadioButton.prototype.get_text =
     function() {
-  return this.element.childNodes.item(1).nodeValue;
+  return this.textNode.nodeValue;
 };
 
 
@@ -113,7 +133,7 @@ org.apache.flex.html.RadioButton.prototype.get_text =
  */
 org.apache.flex.html.RadioButton.prototype.set_text =
     function(value) {
-  this.element.childNodes.item(1).nodeValue = value;
+  this.textNode.nodeValue = value;
 };
 
 
@@ -123,7 +143,7 @@ org.apache.flex.html.RadioButton.prototype.set_text =
  */
 org.apache.flex.html.RadioButton.prototype.get_selected =
     function() {
-  return this.element.childNodes.item(0).checked;
+  return this.input.checked;
 };
 
 
@@ -133,7 +153,7 @@ org.apache.flex.html.RadioButton.prototype.get_selected =
  */
 org.apache.flex.html.RadioButton.prototype.set_selected =
     function(value) {
-  this.element.childNodes.item(0).checked = value;
+  this.input.checked = value;
 };
 
 
@@ -143,7 +163,7 @@ org.apache.flex.html.RadioButton.prototype.set_selected =
  */
 org.apache.flex.html.RadioButton.prototype.get_value =
     function() {
-  return this.element.childNodes.item(0).value;
+  return this.input.value;
 };
 
 
@@ -153,7 +173,7 @@ org.apache.flex.html.RadioButton.prototype.get_value =
  */
 org.apache.flex.html.RadioButton.prototype.set_value =
     function(value) {
-  this.element.childNodes.item(0).value = value;
+  this.input.value = value;
 };
 
 
@@ -165,7 +185,7 @@ org.apache.flex.html.RadioButton.prototype.get_selectedValue =
     function() {
   var buttons, groupName, i, n;
 
-  groupName = this.element.childNodes.item(0).name;
+  groupName = this.input.name;
   buttons = document.getElementsByName(groupName);
   n = buttons.length;
 
@@ -186,7 +206,7 @@ org.apache.flex.html.RadioButton.prototype.set_selectedValue =
     function(value) {
   var buttons, groupName, i, n;
 
-  groupName = this.element.childNodes.item(0).name;
+  groupName = this.input.name;
   buttons = document.getElementsByName(groupName);
   n = buttons.length;
   for (i = 0; i < n; i++) {

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/406ace6f/frameworks/js/FlexJS/src/org/apache/flex/jquery/RadioButton.js
----------------------------------------------------------------------
diff --git a/frameworks/js/FlexJS/src/org/apache/flex/jquery/RadioButton.js b/frameworks/js/FlexJS/src/org/apache/flex/jquery/RadioButton.js
index b4ca75e..762f902 100644
--- a/frameworks/js/FlexJS/src/org/apache/flex/jquery/RadioButton.js
+++ b/frameworks/js/FlexJS/src/org/apache/flex/jquery/RadioButton.js
@@ -67,27 +67,49 @@ org.apache.flex.jquery.RadioButton.groupHandlerSet = false;
 org.apache.flex.jquery.RadioButton.prototype.createElement =
     function() {
 
+  // the radio itself
   this.input = document.createElement('input');
   this.input.type = 'radio';
   this.input.name = 'radio';
-  this.input.id = 'radio' + org.apache.flex.jquery.RadioButton.radioCounter;
+  this.input.id = '_radio_' + org.apache.flex.jquery.RadioButton.radioCounter++;
 
   this.labelFor = document.createElement('label');
   this.labelFor.htmlFor = this.input.id;
 
-  this.element = document.createElement('div');
-  this.element.appendChild(this.input);
-  this.element.appendChild(this.labelFor);
-  this.positioner = this.element;
-  this.flexjs_wrapper = this;
+  this.positioner = document.createElement('div');
+  this.positioner.appendChild(this.input);
+  this.positioner.appendChild(this.labelFor);
+  this.element = this.input;
+
   this.input.flexjs_wrapper = this;
-  this.labelFor.fljs_wrapper = this;
+  this.labelFor.flexjs_wrapper = this;
+  this.positioner.flexjs_wrapper = this;
 
   return this.element;
 };
 
 
 /**
+ * @override
+ */
+org.apache.flex.jquery.RadioButton.prototype.addedToParent =
+    function() {
+  org.apache.flex.jquery.RadioButton.base(this, 'addedToParent');
+  $(this.input).button();
+};
+
+
+/**
+ * @override
+ */
+org.apache.flex.jquery.RadioButton.prototype.set_id = function(value) {
+  org.apache.flex.jquery.RadioButton.base(this, 'set_id', value);
+  this.labelFor.id = value;
+  this.labelFor.htmlFor = value;
+};
+
+
+/**
  * @expose
  * @return {?string} The groupName getter.
  */
@@ -147,3 +169,64 @@ org.apache.flex.jquery.RadioButton.prototype.set_selected =
     function(value) {
   this.input.checked = value;
 };
+
+
+/**
+ * @expose
+ * @return {Object} The value getter.
+ */
+org.apache.flex.jquery.RadioButton.prototype.get_value =
+    function() {
+  return this.input.value;
+};
+
+
+/**
+ * @expose
+ * @param {Object} value The value setter.
+ */
+org.apache.flex.jquery.RadioButton.prototype.set_value =
+    function(value) {
+  this.input.value = value;
+};
+
+
+/**
+ * @expose
+ * @return {Object} The value of the selected RadioButton.
+ */
+org.apache.flex.jquery.RadioButton.prototype.get_selectedValue =
+    function() {
+  var buttons, groupName, i, n;
+
+  groupName = this.input.name;
+  buttons = document.getElementsByName(groupName);
+  n = buttons.length;
+
+  for (i = 0; i < n; i++) {
+    if (buttons[i].checked) {
+      return buttons[i].value;
+    }
+  }
+  return null;
+};
+
+
+/**
+ * @expose
+ * @param {Object} value The value of the selected RadioButton.
+ */
+org.apache.flex.jquery.RadioButton.prototype.set_selectedValue =
+    function(value) {
+  var buttons, groupName, i, n;
+
+  groupName = this.input.name;
+  buttons = document.getElementsByName(groupName);
+  n = buttons.length;
+  for (i = 0; i < n; i++) {
+    if (buttons[i].value === value) {
+      buttons[i].checked = true;
+      break;
+    }
+  }
+};