This is an automated email from the ASF dual-hosted git repository.

harbs 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 3c5b040  Added HandleImageLoadErrors for global handling of image load 
errors Works for HTML and SVG images
3c5b040 is described below

commit 3c5b040ef38321fa41b064026fcdbbaa6b7ea250
Author: Harbs <ha...@in-tools.com>
AuthorDate: Wed Jan 12 15:47:09 2022 +0200

    Added HandleImageLoadErrors for global handling of image load errors
    Works for HTML and SVG images
---
 .../Basic/src/main/resources/basic-manifest.xml    |  2 +
 .../royale/html/beads/HandleImageLoadErrors.as     | 78 ++++++++++++++++++++++
 2 files changed, 80 insertions(+)

diff --git a/frameworks/projects/Basic/src/main/resources/basic-manifest.xml 
b/frameworks/projects/Basic/src/main/resources/basic-manifest.xml
index e85b84d..3c949f0 100644
--- a/frameworks/projects/Basic/src/main/resources/basic-manifest.xml
+++ b/frameworks/projects/Basic/src/main/resources/basic-manifest.xml
@@ -165,6 +165,8 @@
      <component id="VRuleView" class="org.apache.royale.html.beads.VRuleView" 
/>
      -->
 
+    <component id="HandleImageLoadErrors" 
class="org.apache.royale.html.beads.HandleImageLoadErrors"/>
+
     <component id="GetScrollbarWidth" 
class="org.apache.royale.html.beads.GetScrollbarWidth"/>
     <component id="ThrottleBead" 
class="org.apache.royale.html.beads.ThrottleBead"/>
     <component id="UnselectableElementBead" 
class="org.apache.royale.html.beads.UnselectableElementBead"/>
diff --git 
a/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/beads/HandleImageLoadErrors.as
 
b/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/beads/HandleImageLoadErrors.as
new file mode 100644
index 0000000..0a33787
--- /dev/null
+++ 
b/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/beads/HandleImageLoadErrors.as
@@ -0,0 +1,78 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  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.royale.html.beads
+{
+       import org.apache.royale.core.IStrand;
+       import org.apache.royale.events.Event;
+       import org.apache.royale.core.IRenderedObject;
+       import org.apache.royale.core.DispatcherBead;
+       import org.apache.royale.events.ValueEvent;
+
+       /**
+        *  Dispatched when an image fails to load.
+        *  The ValueEvent contains the caught error event
+        *  https://developer.mozilla.org/en-US/docs/Web/API/Element/error_event
+        *
+        *  @langversion 3.0
+        *  @productversion Royale 0.9.9
+        */
+       [Event(name="error", type="org.apache.royale.events.ValueEvent")]
+
+       /**
+        * Catches errors in loaded images anywhere in the hierarchy below the 
strand.
+        * Caught error can have global handling.
+        * Dispatches a ValueEvent which contains the caught event as its value.
+        */
+       public class HandleImageLoadErrors extends DispatcherBead
+       {
+
+               public static const ERROR:String = "error";
+
+               override public function set strand(value:IStrand):void
+               {
+                       super.strand = value;
+                       attachListener();
+               }
+               COMPILE::JS
+               private function attachListener():void
+               {
+                       (_strand as 
IRenderedObject).element.addEventListener("error",handleError,true);
+               }
+               COMPILE::JS
+               protected function handleError(ev:Event):void
+               {
+                       if(ev.target is HTMLImageElement || ev.target is 
SVGImageElement)
+                       {
+                               dispatchEvent(new ValueEvent(ERROR,ev));
+                       }
+               }
+
+               COMPILE::SWF
+               private function attachListener():void
+               {
+                       //TODO SWF implementation
+               }
+               COMPILE::SWF
+               protected function handleError(ev:Event):void
+               {
+                       //TODO SWF implementation
+               }
+
+       }
+}
\ No newline at end of file

Reply via email to