/*
 * 特别声明：本技术材料受《中华人民共和国著作权法》、《计算机软件保护条例》等法律、法规、行政
 * 规章以及有关国际条约的保护，赞同科技享有知识产权、保留一切权利并视其为技术秘密。未经本公司书
 * 面许可，任何人不得擅自（包括但不限于：以非法的方式复制、传播、展示、镜像、上载、下载）使用，
 * 不得向第三方泄露、透露、披露。否则，本公司将依法追究侵权者的法律责任。特此声明！
 *
 * Special Declaration: These technical material reserved as the technical secrets by AGREE
 * TECHNOLOGY have been protected by the "Copyright Law" "ordinances on Protection of Computer
 * Software" and other relevant administrative regulations and international treaties. Without
 * the written permission of the Company, no person may use (including but not limited to the
 * illegal copy, distribute, display, image, upload, and download) and disclose the above
 * technical documents to any third party. Otherwise, any infringer shall afford the legal
 * liability to the company.
 */
/**
 * Created by huangdeyun on 2015/4/15.
 */
define(["adoreapp/widget/BaseWidget"
    , "adoreapp/widget/constants/ADORE"], function (BaseWidget, ADORE) {
    return BaseWidget.extend(function (base) {
        return {
            _initWidget: function (attrs) {
                var style = attrs.style;

                this.templates = attrs.template.split("<!-- split -->");
                var tmpTemplate = this.templates[0];
                var isFloat = false;
                this.isLayout = false;
                this.isZoom = false;

                if ((style & ADORE.Zoom) === ADORE.Zoom) {
                    tmpTemplate = this.templates[2];
                    this.isZoom = true;
                } else if ((style & ADORE.Float) == ADORE.Float) {
                    tmpTemplate = this.templates[1];
                    isFloat = true;
                }
                this.jqueryNode = $(tmpTemplate).attr({id: this.id});
                if (isFloat) {
                    this.imgNode = this.jqueryNode.find("img");
                } else {
                    this.imgNode = this.jqueryNode;
                }
                this.imgNode.attr({alt: "图片不存在"});
            },

            _setSrc: function (attrs) {
                var src = attrs.src;
                this.imgNode.attr("src", src);
                if (this.isLayout && this.isZoom) {
                    this.imgNode.materialbox();
                }
            },

            _layout: function () {
                base._layout.call(this);
                if (this.isZoom) {
                    this.imgNode.materialbox();
                }
                this.isLayout = true;
            }
        }
    })
})
