Return-Path: X-Original-To: apmail-flex-commits-archive@www.apache.org Delivered-To: apmail-flex-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id AD9B310F8F for ; Wed, 21 Jan 2015 22:53:43 +0000 (UTC) Received: (qmail 96599 invoked by uid 500); 21 Jan 2015 22:53:43 -0000 Delivered-To: apmail-flex-commits-archive@flex.apache.org Received: (qmail 96573 invoked by uid 500); 21 Jan 2015 22:53:43 -0000 Mailing-List: contact commits-help@flex.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@flex.apache.org Delivered-To: mailing list commits@flex.apache.org Received: (qmail 96565 invoked by uid 99); 21 Jan 2015 22:53:43 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 21 Jan 2015 22:53:43 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 36B52E0838; Wed, 21 Jan 2015 22:53:43 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: pent@apache.org To: commits@flex.apache.org Date: Wed, 21 Jan 2015 22:53:45 -0000 Message-Id: <7ad0cd17d2c941e5a30645d2965d1c7a@git.apache.org> In-Reply-To: <72fdcc9af671449d8468e6cde4e3f579@git.apache.org> References: <72fdcc9af671449d8468e6cde4e3f579@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [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 Authored: Wed Jan 21 17:53:31 2015 -0500 Committer: Peter Ent 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; + } + } +};