
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * Owner: mark@famo.us
 * @license MPL 2.0
 * @copyright Famous Industries, Inc. 2014
 */

define(function(require, exports, module) {
    var Surface = require('famous/core/Surface');

    /**
     * A surface containing image content.
     *   This extends the Surface class.
     *
     * @class ImageSurface
     *
     * @extends Surface
     * @constructor
     * @param {Object} [options] overrides of default options
     */
    function ImageSurface(options) {
        this._imageUrl = undefined;
        Surface.apply(this, arguments);
    }

    ImageSurface.prototype = Object.create(Surface.prototype);
    ImageSurface.prototype.constructor = ImageSurface;
    ImageSurface.prototype.elementType = 'img';
    ImageSurface.prototype.elementClass = 'famous-surface';

    /**
     * Set content URL.  This will cause a re-rendering.
     * @method setContent
     * @param {string} imageUrl
     */
    ImageSurface.prototype.setContent = function setContent(imageUrl) {
        this._imageUrl = imageUrl;
        this._contentDirty = true;
    };

    /**
     * Place the document element that this component manages into the document.
     *
     * @private
     * @method deploy
     * @param {Node} target document parent of this container
     */
    ImageSurface.prototype.deploy = function deploy(target) {
        target.src = this._imageUrl || '';
    };

    /**
     * Remove this component and contained content from the document
     *
     * @private
     * @method recall
     *
     * @param {Node} target node to which the component was deployed
     */
    ImageSurface.prototype.recall = function recall(target) {
        target.src = '';
    };

    module.exports = ImageSurface;
});

@@ -385,24 +385,50 @@
 ace');%0A%0A
+    var imageCache = %7B%7D;%0A%0A
     /**%0A
      * A
@@ -415,24 +415,24 @@
 %7D;%0A%0A    /**%0A
-
      * A sur
@@ -1204,24 +1204,422 @@
 imageUrl) %7B%0A
+        if (this._imageUrl && this._imageUrl !== imageUrl) %7B%0A            if (imageCache%5Bthis._imageUrl%5D.count === 1)%0A                imageCache%5Bthis._imageUrl%5D = null;%0A            else%0A                imageCache%5Bthis._imageUrl%5D.count--;%0A        %7D%0A%0A        if (!imageCache%5BimageUrl%5D)%0A            imageCache%5BimageUrl%5D = %7Bcount: 1, node: null%7D;%0A        else%0A            imageCache%5BimageUrl%5D.count++;%0A%0A
         this
@@ -1880,32 +1880,32 @@
 ntainer%0A     */%0A
-
     ImageSurface
@@ -1942,32 +1942,215 @@
 eploy(target) %7B%0A
+        if (!imageCache%5Bthis._imageUrl%5D.node) %7B%0A            var img = new Image();%0A            img.src = this._imageUrl;%0A            imageCache%5Bthis._imageUrl%5D.node = img;%0A        %7D%0A%0A
         target.s

Add functionality for image caching