(function(){"use strict";u8.Base.Widgets.WaypointManager=function(e,t){this.Widget(e,$.extend({},u8.Base.Widgets.WaypointManager.defaults,t));this._isCreated=false;this._create();u8.tools.created(this)};u8.Base.Widgets.WaypointManager.defaults={allowRemove:false,showMarkersWithoutLocation:false};$.extend(u8.Base.Widgets.WaypointManager.prototype,{_create:function(){var e=this,t=this.$(this.element);if(!this._$waypoints){this._$waypoints=t.append('<div class="u8-waypointmanager"><ul class="u8-waypointmanager-waypoints" /></div>').find(".u8-waypointmanager-waypoints")}this._addInsertionMarker(0);(this.markers||[]).forEach(function(t,a){if(e.showMarkersWithoutLocation||t.location){e._addMarker(t,a);e._addInsertionMarker(a+1)}})},_addInsertionMarker:function(e){this.$("<li />").addClass("u8-waypointmanager-marker u8-clickable insertion").data("index",e).append("<span />").on("click",this._onMarkerClick.bind(this)).appendTo(this._$waypoints)},_addMarker:function(e,t){var a=this._$waypoints,i=(e.height-e.tipOffset.y)/2,s=this.$("<li />").addClass("u8-waypointmanager-marker u8-clickable").data("index",t).css({width:e.width,height:e.height}).on("click",this._onMarkerClick.bind(this));this.$("<img />").image(e.image).css("margin-top",i).appendTo(s);if(this.allowRemove){this.$("<button type='button'></button>").addClass("delete").append(u8.images.html("u8-img-delete-xs",{classNames:"delete"})).appendTo(s)}if(e.innerImage){this.$("<span />").image(e.innerImage).css({top:e.innerImageOffset.y+i,left:e.innerImageOffset.x}).appendTo(s)}if(e.text){this.$('<div class="text" />').text((e.text+"").format(function(t){return e[t]||""})).css({top:e.textOffset.y+i,left:e.textOffset.x}).appendTo(s)}s.appendTo(a)},_onMarkerClick:function(e){var t=this.$(e.target),a=t.closest(".u8-waypointmanager-marker"),i=a.is(".insertion"),s=i?false:t.is(".delete"),n={targetType:i?null:s?"delete":"marker",target:i?a.data("index"):this.markers[a.data("index")]};this.raise("Click",n)}});u8.Base.Widgets.WaypointManager.makeClass({name:"WaypointManager",deriveFrom:u8.Base.Widgets.Widget,events:["Create","Click"]})})();