(function(){"use strict";var a=this;a.define(["backbone","communicator","hbs!tmpl/BulletLayer","underscore"],function(a,b,c){var d=a.Marionette.ItemView.extend({events:{click:"onClick"},initialize:function(a){this.listenTo(b.mediator,"selection:activated",this.onSelectionActivated),this.listenTo(b.mediator,"ui:close",this.onDialogClose),this.listenTo(b.mediator,"selection:enabled",this.onSelectionEnabled),this.d=null},onClick:function(a){this.model.get("enabled")&&("selection"==this.model.get("type")?this.model.get("active")?(b.mediator.trigger("selection:activated",{id:this.model.get("id"),active:!1,selectionType:this.model.get("selectionType")}),this.model.set({active:!1})):(b.mediator.trigger("selection:activated",{id:this.model.get("id"),active:!0,selectionType:this.model.get("selectionType")}),this.model.set({active:!0})):this.model.get("active")?(b.mediator.trigger(this.model.get("eventToRaise"),!1),this.model.set({active:!1})):(b.mediator.trigger(this.model.get("eventToRaise"),!0),this.model.set({active:!0})),this.render())},onSelectionActivated:function(a){a.active&&this.model.get("id")!=a.id&&this.model.get("active")&&(this.model.set({active:!1}),this.render())},onDialogClose:function(a){this.model.get("id")==a&&(this.model.set({active:!1}),this.render())},onSelectionEnabled:function(a){this.model.get("id")==a.id&&(this.model.set({enabled:a.enabled}),this.render())},onRender:function(){this.$el.is("div")?this.setElement($(this.$el.children()[0]).unwrap()):this.$el.is("button")&&this.setElement($(this.$el.children()[0]).unwrap());var a=this.model.get("size");if(null==a){var b,c;0!=this.$el.outerHeight()&&(c=this.$el.outerHeight()),0!=this.$el.outerWidth()&&(b=this.$el.outerWidth()),b&&c&&(a={x:b,y:c},this.model.set("size",a))}this.model.get("enabled")?(this.$el.attr("title",this.model.get("description")),this.d&&(this.d.remove(),this.d=null)):!this.d&&a&&(this.d=$("<div>"),this.d.css({height:a.y,width:a.x,position:"relative","margin-top":"-"+a.y+"px"}),this.d.attr("title",this.model.get("disabledDescription")),this.$el.after(this.d))},onClose:function(){this.d&&(this.d.remove(),this.d=null)},onShow:function(){var a=this.model.get("size");if(null==a){var b,c;0!=this.$el.outerHeight()&&(c=this.$el.outerHeight()),0!=this.$el.outerWidth()&&(b=this.$el.outerWidth()),b&&c&&(a={x:b,y:c},this.model.set("size",a))}this.model.get("enabled")?this.$el.attr("title",this.model.get("description")):!this.d&&a&&(this.d=$("<div>"),this.d.css({height:a.y,width:a.x,position:"relative","margin-top":"-"+a.y+"px"}),this.d.attr("title",this.model.get("disabledDescription")),this.$el.after(this.d))}});return{ToolItemView:d}})}).call(this);