You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by ah...@apache.org on 2020/05/29 07:56:54 UTC
[royale-asjs] branch develop updated: DownloadButton replacement
for FileReference.save. Might fix #838
This is an automated email from the ASF dual-hosted git repository.
aharui 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 e5d57b6 DownloadButton replacement for FileReference.save. Might fix #838
e5d57b6 is described below
commit e5d57b6afbd7a70f722d130b5150cc11f7210676
Author: Alex Harui <ah...@apache.org>
AuthorDate: Fri May 29 00:56:29 2020 -0700
DownloadButton replacement for FileReference.save. Might fix #838
---
.../MXRoyale/src/main/resources/defaults.css | 6 ++
.../src/main/resources/mx-royale-manifest.xml | 1 +
.../src/main/royale/mx/controls/DownloadButton.as | 110 +++++++++++++++++++++
.../src/main/royale/mx/net/FileReference.as | 18 +++-
4 files changed, 132 insertions(+), 3 deletions(-)
diff --git a/frameworks/projects/MXRoyale/src/main/resources/defaults.css b/frameworks/projects/MXRoyale/src/main/resources/defaults.css
index 2a2ad19..61d70b3 100644
--- a/frameworks/projects/MXRoyale/src/main/resources/defaults.css
+++ b/frameworks/projects/MXRoyale/src/main/resources/defaults.css
@@ -287,6 +287,12 @@ DateField {
IPopUp: ClassReference("mx.controls.dateFieldClasses.DateFieldDateChooser");
}
+DownloadButton
+{
+ border: solid 1px #000;
+ text-decoration: none;
+}
+
FormItem
{
IBeadView: ClassReference("mx.containers.beads.FormItemView");
diff --git a/frameworks/projects/MXRoyale/src/main/resources/mx-royale-manifest.xml b/frameworks/projects/MXRoyale/src/main/resources/mx-royale-manifest.xml
index a19a31e..77b8d88 100644
--- a/frameworks/projects/MXRoyale/src/main/resources/mx-royale-manifest.xml
+++ b/frameworks/projects/MXRoyale/src/main/resources/mx-royale-manifest.xml
@@ -215,4 +215,5 @@
<component id="GroupingCollection" class="mx.collections.GroupingCollection"/>
<component id="GroupingCollection2" class="mx.collections.GroupingCollection2"/>
+ <component id="DownloadButton" class="mx.controls.DownloadButton"/>
</componentPackage>
diff --git a/frameworks/projects/MXRoyale/src/main/royale/mx/controls/DownloadButton.as b/frameworks/projects/MXRoyale/src/main/royale/mx/controls/DownloadButton.as
new file mode 100644
index 0000000..6a706f8
--- /dev/null
+++ b/frameworks/projects/MXRoyale/src/main/royale/mx/controls/DownloadButton.as
@@ -0,0 +1,110 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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 mx.controls
+{
+COMPILE::JS
+{
+ import org.apache.royale.core.WrappedHTMLElement;
+ import org.apache.royale.html.util.addElementToWrapper;
+}
+
+/**
+ * The DownloadButton control is a Button control
+ * that initiates the downloading of some data
+ * when the user clicks the button. The user can
+ * also right click to choose the location of the download.
+ * It only works on JS. The data must be set before
+ * the user clicks or right-clicks.
+ *
+ * @langversion 3.0
+ * @playerversion Flash 9
+ * @playerversion AIR 1.1
+ * @productversion Flex 3
+ */
+public class DownloadButton extends Button
+{
+
+ //--------------------------------------------------------------------------
+ //
+ // Constructor
+ //
+ //--------------------------------------------------------------------------
+
+ /**
+ * Constructor.
+ *
+ * @langversion 3.0
+ * @playerversion Flash 9
+ * @playerversion AIR 1.1
+ * @productversion Flex 3
+ */
+ public function DownloadButton()
+ {
+ super();
+ typeNames = "DownloadButton";
+ }
+
+ COMPILE::JS
+ override protected function createElement():WrappedHTMLElement
+ {
+ addElementToWrapper(this, "a");
+ return element;
+ }
+
+ //--------------------------------------------------------------------------
+ //
+ // Overridden properties
+ //
+ //--------------------------------------------------------------------------
+
+ override public function set data(value:Object):void
+ {
+ super.data = value;
+ COMPILE::JS
+ {
+ (element as HTMLAnchorElement).href = URL.createObjectURL(new Blob([data]));
+ }
+ }
+
+ private var _defaultFileName:String;
+
+ public function get defaultFileName():String
+ {
+ return _defaultFileName;
+ }
+
+ public function set defaultFileName(value:String):void
+ {
+ _defaultFileName = value;
+ COMPILE::JS
+ {
+ (element as HTMLAnchorElement).setAttribute("download", _defaultFileName);
+ }
+ }
+
+ //--------------------------------------------------------------------------
+ //
+ // Overridden methods: UIComponent
+ //
+ //--------------------------------------------------------------------------
+
+}
+
+}
diff --git a/frameworks/projects/MXRoyale/src/main/royale/mx/net/FileReference.as b/frameworks/projects/MXRoyale/src/main/royale/mx/net/FileReference.as
index 5e07293..636581a 100644
--- a/frameworks/projects/MXRoyale/src/main/royale/mx/net/FileReference.as
+++ b/frameworks/projects/MXRoyale/src/main/royale/mx/net/FileReference.as
@@ -108,10 +108,22 @@ package mx.net
dispatchEvent(new Event(Event.SELECT));
}
+ /**
+ * @royaleignorecoercion HTMLAnchorElement
+ */
public function save(data:*, defaultFileName:String = null):void
- {
-
- }
+ {
+ COMPILE::JS
+ {
+ var a:HTMLAnchorElement = document.createElement("a") as HTMLAnchorElement;
+ a.href = URL.createObjectURL(new Blob([data]));
+ a.setAttribute("download", defaultFileName);
+ a.text = defaultFileName;
+ document.body.appendChild(a);
+// a.click();
+// document.body.removeChild(a);
+ }
+ }