You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by ah...@apache.org on 2013/03/21 23:24:33 UTC
[11/14] git commit: Add JS DropDownList
Add JS DropDownList
Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/c8686da8
Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/c8686da8
Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/c8686da8
Branch: refs/heads/develop
Commit: c8686da8bfb452e49cb4535cb451264c4910dd0f
Parents: 1eeca03
Author: Alex Harui <ah...@apache.org>
Authored: Tue Mar 19 12:35:51 2013 -0700
Committer: Alex Harui <ah...@apache.org>
Committed: Tue Mar 19 12:35:51 2013 -0700
----------------------------------------------------------------------
.../flex/html/staticControls/DropDownList.js | 145 +++++++++++++++
1 files changed, 145 insertions(+), 0 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/c8686da8/frameworks/js/FlexJS/src/org/apache/flex/html/staticControls/DropDownList.js
----------------------------------------------------------------------
diff --git a/frameworks/js/FlexJS/src/org/apache/flex/html/staticControls/DropDownList.js b/frameworks/js/FlexJS/src/org/apache/flex/html/staticControls/DropDownList.js
new file mode 100644
index 0000000..f888f19
--- /dev/null
+++ b/frameworks/js/FlexJS/src/org/apache/flex/html/staticControls/DropDownList.js
@@ -0,0 +1,145 @@
+/**
+ * Licensed 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.
+ */
+
+goog.provide('org.apache.flex.html.staticControls.DropDownList');
+
+goog.require('org.apache.flex.core.UIBase');
+
+/**
+ * @constructor
+ * @extends {org.apache.flex.core.UIBase}
+ */
+org.apache.flex.html.staticControls.DropDownList = function() {
+ org.apache.flex.core.UIBase.call(this);
+
+ /**
+ * @private
+ * @type {Array.<Object>}
+ */
+ this._dataProvider;
+
+};
+goog.inherits(
+ org.apache.flex.html.staticControls.DropDownList, org.apache.flex.core.UIBase
+);
+
+/**
+ * @override
+ * @this {org.apache.flex.html.staticControls.DropDownList}
+ * @param {Object} p The parent element.
+ */
+org.apache.flex.html.staticControls.DropDownList.prototype.addToParent = function(p) {
+ this.element = document.createElement('select');
+ this.element.onChange = org.apache.flex.FlexGlobal.createProxy(
+ this, this.changeHandler);
+
+ p.appendChild(this.element);
+
+ this.positioner = this.element;
+};
+
+/**
+ * @expose
+ * @this {org.apache.flex.html.staticControls.DropDownList}
+ * @return {Array.<Object>} The collection of data.
+ */
+org.apache.flex.html.staticControls.DropDownList.prototype.get_dataProvider =
+function() {
+ return this._dataProvider;
+};
+
+/**
+ * @expose
+ * @this {org.apache.flex.html.staticControls.DropDownList}
+ * @param {Array.<Object>} value The text setter.
+ */
+org.apache.flex.html.staticControls.DropDownList.prototype.set_dataProvider =
+function(value) {
+ this._dataProvider = value;
+
+ var dp = this.element.options;
+ var n = dp.length;
+ for (var i = 0; i < n; i++)
+ dp.remove(0);
+
+ n = value.length;
+ for (i = 0; i < n; i++)
+ {
+ var opt = document.createElement('option');
+ opt.text = value[i];
+ dp.add(opt);
+ }
+};
+
+/**
+ * @expose
+ * @this {org.apache.flex.html.staticControls.DropDownList}
+ * @return {int} The selected index.
+ */
+org.apache.flex.html.staticControls.DropDownList.prototype.get_selectedIndex =
+function() {
+ return this.element.selectedIndex;
+};
+
+/**
+ * @expose
+ * @this {org.apache.flex.html.staticControls.DropDownList}
+ * @param {int} value The selected index.
+ */
+org.apache.flex.html.staticControls.DropDownList.prototype.set_selectedIndex =
+function(value) {
+ this.element.selectedIndex = value;
+};
+
+/**
+ * @expose
+ * @this {org.apache.flex.html.staticControls.DropDownList}
+ * @return {Object} The selected item.
+ */
+org.apache.flex.html.staticControls.DropDownList.prototype.get_selectedItem =
+function() {
+ return this._dataProvider[this.element.selectedIndex];
+};
+
+/**
+ * @expose
+ * @this {org.apache.flex.html.staticControls.DropDownList}
+ * @param {Object} value The selected item.
+ */
+org.apache.flex.html.staticControls.DropDownList.prototype.set_selectedItem =
+function(value) {
+
+ var dp = this._dataProvider;
+ var n = dp.length;
+ for (var i = 0; i < n; i++)
+ {
+ if (dp[i] == value)
+ break;
+ }
+ if (i < n)
+ this.element.selectedIndex = i;
+};
+
+/**
+ * @protected
+ * @this {org.apache.flex.html.staticControls.DropDownList}
+ * @return {Object} The selected item.
+ */
+org.apache.flex.html.staticControls.DropDownList.prototype.changeHandler =
+function() {
+ evt = document.createEvent('Event');
+ evt.initEvent('change', false, false);
+ this.element.dispatchEvent(evt);
+};
+