(function(){"use strict";u8.Base.Widgets.Image=function(e,t){this.Widget(e,$.extend({},u8.Base.Widgets.Image.defaults,t));this._isCreated=false;this._create();u8.tools.created(this)};u8.Base.Widgets.Image.defaults={isSprite:true,source:null,title:null,clickable:false,decorator:"",forceDisabledClick:false};u8.Base.Widgets.Image.states={disabled:{is:function(){return!!this.disabled},update:function(){this._updateDisabledState()}},readonly:{is:function(){return!!this.readonly},update:function(){this._updateReadonlyState()}}};$.extend(u8.Base.Widgets.Image.prototype,{update:function(e){if(typeof e=="string"){e={reason:e}}if(!e.reason){e.reason="all"}if(e.reason=="all"||e.reason.all){this._create()}if(e.reason=="title"||e.reason.title||e.reason=="attr"&&e.properties.title){this._updateTitle()}if(e.reason=="source"||e.reason.source||e.reason=="attr"&&e.properties.source){this._updateSource()}if(e.reason=="disabled"||e.reason.disabled||e.reason=="attr"&&e.properties.disabled){this["States.update"]("disabled")}if(e.reason=="readonly"||e.reason.readonly||e.reason=="attr"&&e.properties.readonly){this["States.update"]("readonly")}if(e.reason=="visible"||e.reason.visible||e.reason=="attr"&&e.properties.visible){this._updateVisibility()}},getSource:function(){return this.source},setSource:function(e){this.source=e;if(!this._isCreated){return}this.update("source")},getValue:function(){return this.getSource()},setValue:function(e){this.setSource(e)},getTitle:function(){return this.title},setTitle:function(e){this.title=e;if(!this._isCreated){return}this.update("title")},getIsLink:function(){return this.isLink},setIsLink:function(e){this.isLink=e;if(!this._isCreated){return}this.update("all")},dispose:function(){if(this._isDisposed){return}this.$(this.element).off(".image").removeClass("u8-image u8-clickable disabled readonly");this.Widget_dispose();this._$image=null},setVisible:function(e){this._visible=!!e;this.update("visible")},_create:function(){var e=this.$(this.element).addClass("u8-image").off(".image").empty();if(this.designer&&!this.source){this._$image=this.$("<span>Image</span>").appendTo(e);return}else{var t=e;if(this.isLink){this._$link=this.$('<a href="javascript:void(0);" tabindex="-1"/>').appendTo(t);t=this._$link}else{delete this._$link}this._$image=this.$(this.isSprite?"<span/>":"<img/>").appendTo(t);if(!this._isCreated){this["States.create"]()}else{this._updateClickability()}}this.update({reason:{title:true,source:true,disabled:true,readonly:true}})},_updateSource:function(){var e=this._determineSource();if(e){if(e&&typeof e=="object"){e=e.style||e.filename}if(e.indexOf("data:image")==0){this._$image.attr("src",e)}else{this._$image.image(e,this.decorator)}this.update("visible")}else{this.$(this.element).hide()}},_updateTitle:function(){var e=this._$image;this._determineTitle().then(function(t){if(t){e.attr("title",t)}else{e.removeAttr("title")}})},_determineSource:function(){var e=this.source;if(u8.session&&typeof e=="string"){e=u8.session.images[e]||e}else if(typeof e!="object"){return null}return e},_determineTitle:function(){var e=$.Deferred(),t=this.title;if(t===true){var i=this._determineSource();if(typeof i=="object"&&"label"in i){e.resolve(i.label)}else{e.resolve(null)}}else if(t&&typeof t=="string"){if(u8.services.texts.isTextId(t)){u8.services.texts.loadText([t],function(){e.resolve($t(t))})}else{e.resolve(t)}}else{e.resolve(null)}return e.promise()},_updateDisabledState:function(){this.$(this.element).toggleClass("disabled",this["States.is"]("disabled"));this._updateClickability()},_updateReadonlyState:function(){this.$(this.element).toggleClass("readonly",this["States.is"]("readonly"));this._updateClickability()},_updateClickability:function(){var e=this.$(this.element),t=this["States.is"]("disabled"),i=this["States.is"]("readonly"),s=this.isLink||this.clickable,a=this.forceDisabledClick;e.off("click.image");if(s&&t&&!a){e.toggleClass("u8-clickable",true)}else if(!s||s&&i){e.toggleClass("u8-clickable",false)}else{e.on("click.image",this._onClick.bind(this)).toggleClass("u8-clickable",true)}},_updateVisibility:function(){var e=this.$(this.element);if(this._visible===undefined?true:this._visible){e.css("display","")}else{e.hide()}},_onClick:function(e){e.stopPropagation();e.preventDefault();this.raise("Click",{elEvent:e})}});u8.Base.Widgets.Image.makeClass({name:"Image",deriveFrom:u8.Base.Widgets.Widget,events:["Create","Click"],mixins:[u8.Base.StatesMixIn]})})();