"use strict";

var LivePhotoImagePrototype = Object.create(HTMLImageElement.prototype);

LivePhotoImagePrototype.createdCallback = function() {
  this.addEventListener("mouseenter", function() {
    if (this.src) {
      this.originalSrc = this.src;
      this.src = this.src.replace(/\.[^\.]+$/, ".gif");
    }
  });
  this.addEventListener("mouseleave", function() {
    if (this.originalSrc) {
      this.src = this.originalSrc;
      this.originalSrc = null;
    }
  });
};

var LivePhotoImage = document.registerElement("live-photo", {
  prototype: LivePhotoImagePrototype,
  extends: "img"
});

@@ -110,23 +110,13 @@
 ype.
-createdCallback
+start
  = f
@@ -133,79 +133,45 @@
 %7B%0A  
+if (
 this.
-addEventListener(%22mouseenter%22, function() %7B%0A    if (this.s
+src && !this.originalS
 rc) %7B%0A
-  
     
@@ -195,26 +195,24 @@
 = this.src;%0A
-  
     this.src
@@ -257,57 +257,46 @@
 %22);%0A
-  
   %7D%0A
-  %7D);%0A  this.addEventListener(%22mouseleave%22,
+%7D;%0A%0ALivePhotoImagePrototype.stop =
  fun
@@ -305,18 +305,16 @@
 ion() %7B%0A
-  
   if (th
@@ -331,26 +331,24 @@
 lSrc) %7B%0A    
-  
 this.src = t
@@ -368,18 +368,16 @@
 rc;%0A    
-  
 this.ori
@@ -399,15 +399,317 @@
 ;%0A  
-  %7D%0A  %7D
+%7D%0A%7D;%0A%0ALivePhotoImagePrototype.createdCallback = function() %7B%0A  this.addEventListener(%22mouseenter%22, this.start);%0A  this.addEventListener(%22mouseleave%22, this.stop);%0A  this.addEventListener(%22touchstart%22, this.start);%0A  this.addEventListener(%22touchcancel%22, this.stop);%0A  this.addEventListener(%22touchend%22, this.stop
 );%0A%7D

Add support for touch events.