forked from mike1104/mapstick
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackbone.mapstick.min.js
More file actions
4 lines (3 loc) · 24.1 KB
/
Copy pathbackbone.mapstick.min.js
File metadata and controls
4 lines (3 loc) · 24.1 KB
1
2
3
4
/*! MapStick (backbone.mapstick) - v0.2.4 - 2018-06-12
* Copyright (c) 2018 William Ross; Distributed under MIT license */
(function(){var a,b=function(a,b){return function(){return a.apply(b,arguments)}},c=[].indexOf||function(a){for(var b=0,c=this.length;c>b;b++)if(b in this&&this[b]===a)return b;return-1},d=function(a,b){function c(){this.constructor=a}for(var d in b)e.call(b,d)&&(a[d]=b[d]);return c.prototype=b.prototype,a.prototype=new c,a.__super__=b.prototype,a},e={}.hasOwnProperty;a=window.MapStick=function(){return{extend:Backbone.Model.extend}},a.ChildViewContainer=function(){function a(a){this._updateLength=b(this._updateLength,this),this.apply=b(this.apply,this),this.call=b(this.call,this),this.remove=b(this.remove,this),this.findByCid=b(this.findByCid,this),this.findByIndex=b(this.findByIndex,this),this.findByCustom=b(this.findByCustom,this),this.findByModelCid=b(this.findByModelCid,this),this.findByModel=b(this.findByModel,this),this.add=b(this.add,this),this._views={},this._indexByModel={},this._indexByCustom={},this._methods=["forEach","each","map","find","detect","filter","select","reject","every","all","some","any","include","contains","invoke","toArray","first","initial","rest","last","without","isEmpty","pluck"],_.each(this._methods,function(b){return function(c){return b[c]=function(){var d;return a=_.values(b._views),d=[a].concat(_.toArray(arguments)),_[c].apply(_,d)}}}(this)),this._updateLength(),_.each(a,this.add)}return a.prototype.add=function(a,b){var c,d;return d=a.cid,this._views[d]=a,(c=a.model)&&(this._indexByModel[c.cid]=d),b&&(this._indexByCustom[b]=d),this._updateLength(),this},a.prototype.findByModel=function(a){return this.findByModelCid(a.cid)},a.prototype.findByModelCid=function(a){var b;return b=this._indexByModel[a],this.findByCid(b)},a.prototype.findByCustom=function(a){var b;return b=this._indexByCustom[a],this.findByCid(b)},a.prototype.findByIndex=function(a){return _.values(this._views)[a]},a.prototype.findByCid=function(a){return this._views[a]},a.prototype.remove=function(a){var b;return b=a.cid,a.model&&delete this._indexByModel[a.model.cid],_.any(this._indexByCustom,function(a){return function(c,d){return c===b?(delete a._indexByCustom[d],!0):void 0}}(this),this),delete this._views[b],this._updateLength(),this},a.prototype.call=function(a){return this.apply(a,_.tail(arguments))},a.prototype.apply=function(a,b){return _.each(this._views,function(c){return _.isFunction(c[a])?c[a].apply(c,b||[]):void 0})},a.prototype._updateLength=function(){return this.length=_.size(this._views)},a}(),a.getOption=function(a,b){return a&&b?a.options&&c.call(a.options,b)>=0&&void 0!==a.options[b]?a.options[b]:a[b]:null},a.triggerMethod=function(){var a,b,c;return b=/(^|:)(\w)/gi,a=function(a,b,c){return c.toUpperCase()},c=function(c){return function(d){var e,f;return f="on"+d.replace(b,a),e=c[f],_.isFunction(c.trigger)&&c.trigger.apply(c,arguments),_.isFunction(e)?e.apply(c,_.tail(arguments)):void 0}}(this)},a.actAsCollection=function(a,b){var c;return c=["forEach","each","map","find","detect","filter","select","reject","every","all","some","any","include","contains","invoke","toArray","first","initial","rest","last","without","isEmpty","pluck"],_.each(c,function(c){return function(d){return a[d]=function(){var a,e;return e=_.values(_.result(c,b)),a=[e].concat(_.toArray(arguments)),_[d].apply(_,a)}}}(this))},a.decodePathString=function(a){return google.maps.geometry?a&&_.isString(a)&&""!==a?google.maps.geometry.encoding.decodePath(a):[]:console.error("please include google.maps.geometry library")},a.encodePathString=function(a){return google.maps.geometry?a?google.maps.geometry.encoding.encodePath(a):void 0:console.error("please include google.maps.geometry library")},a.isClockwise=function(a){var b,c,d,e;return _.isArray(a)||(a=a.getArray()),a.push(a[0]),b=0,e=0,c=null,d=null,_.each(a,function(a){var f,g;return g=a.lng(),f=a.lat(),d&&c&&(b+=g*c,e+=f*d),d=g,c=f}),b-e>0},a.Overlay=function(e){function f(a){var c;null==a&&(a={}),this.getDrawnOptions=b(this.getDrawnOptions,this),this.abandonOverlay=b(this.abandonOverlay,this),this.saveOverlay=b(this.saveOverlay,this),this.stopDrawing=b(this.stopDrawing,this),this.completeDraw=b(this.completeDraw,this),this.cancelDraw=b(this.cancelDraw,this),this.handleKey=b(this.handleKey,this),this.draw=b(this.draw,this),this.render=b(this.render,this),this.clearModelListeners=b(this.clearModelListeners,this),this.clearListeners=b(this.clearListeners,this),this.remove=b(this.remove,this),this.hide=b(this.hide,this),this.show=b(this.show,this),this.set=b(this.set,this),this.get=b(this.get,this),this.triggerOverlayEvent=b(this.triggerOverlayEvent,this),this.setBoundOverlayAttributes=b(this.setBoundOverlayAttributes,this),this.setBoundModelAttributes=b(this.setBoundModelAttributes,this),this.listenToBoundOverlayEvents=b(this.listenToBoundOverlayEvents,this),this.listenToBoundModelChanges=b(this.listenToBoundModelChanges,this),this.bindPosition=b(this.bindPosition,this),this.setBindings=b(this.setBindings,this),this.listenToModel=b(this.listenToModel,this),this.attachOverlayEvents=b(this.attachOverlayEvents,this),this.buildOverlay=b(this.buildOverlay,this),this.googleDrawingOverlayType=b(this.googleDrawingOverlayType,this),this.googleOverlayType=b(this.googleOverlayType,this),this.cid=_.uniqueId(this.cidPrefix),this.options=_.extend({},_.result(this,"options"),_.isFunction(a)?a.call(this):a),this.overlayOptions=_.pick(a,this.properties),_.defaults(this.overlayOptions,this.defaultOptions),this[this.overlayType]=this.overlay=this.buildOverlay(this.overlayOptions),_.extend(this,_.pick(a,this.viewOptions)),this.attachOverlayEvents(),this.listenToModel(),this.setBindings(),_.isFunction(this.initialize)&&this.initialize(this.options),this.model.on("destroy",this.remove),"info_window"===this.overlayType?(c=this.options.content_view)&&this.setContentView(c):this.model.on("draw",this.draw)}return d(f,e),f.prototype.googleOverlayType=function(){return this.overlayType.split("_").map(function(a){return a.charAt(0).toUpperCase()+a.slice(1)}).join("")},f.prototype.googleDrawingOverlayType=function(){return google.maps.drawing.OverlayType[""+this.overlayType.split("_").map(function(a){return a.toUpperCase()}).join("")]},f.prototype.defaultOptions={},f.prototype.properties=[],f.prototype.overlayEvents={},f.prototype.viewOptions=["model","events","map"],f.prototype.bindings={},f.prototype.defaultOverlayEvents=[],f.prototype.modelEvents={},f.prototype.triggerMethod=a.triggerMethod,f.prototype.showing=!1,f.prototype.cidPrefid="o",f.prototype.buildOverlay=function(a){return new(google.maps[this.googleOverlayType()])(a)},f.prototype.attachOverlayEvents=function(){return _.each(this.overlayEventNames,function(a){return function(b){return google.maps.event.addListener(a.overlay,b,function(c){return _.isFunction(a.trigger)&&a.trigger(b,c),a.triggerOverlayEvent(b,c)})}}(this))},f.prototype.listenToModel=function(){return this.model?_.each(this.modelEvents,function(a){return function(b,c){var d;return _.isFunction(d=a[b])?a.model.on(c,d):void 0}}(this)):void 0},f.prototype.setBindings=function(){return _.each(this.bindings,function(a){return function(b,d){var e;if(_.isString(b)&&(b={attribute:b,overlayChanged:!0}),_.isObject(b)){if(b.overlay_attribute=d,"position"===d&&_.isString(b.lat)&&_.isString(b.lng))return a.bindPosition(b);if((e=b.attributes||b.attribute)&&(_.isString(e)&&(b.attributes=e=[e]),a.setBoundOverlayAttributes(b),a.listenToBoundModelChanges(b),c.call(a.twoWayProperties,d)>=0))return a.listenToBoundOverlayEvents(b)}}}(this))},f.prototype.bindPosition=function(a){var b,c,d,e;return null==a&&(a={}),b=a.lat,c=a.lng,e=function(a){return function(){return a.model.has(b)&&a.model.has(c)?a.set({position:new google.maps.LatLng(a.model.get(b),a.model.get(c))}):void 0}}(this),e(),this.model.on("change:"+b+" change:"+c,function(a,b,c){var d;return d=(null!=c?c:{}).mapstickChange,d?void 0:e()}),d=a.overlayEvents||this.defaultOverlayEvents,_.each(d,function(a){return function(d){return google.maps.event.addListener(a.overlay,d,function(){var d,e;return(e=a.get("position"))?(d={},d[b]=e.lat(),d[c]=e.lng(),a.model.set(d,{mapstickChange:!0})):void 0})}}(this))},f.prototype.listenToBoundModelChanges=function(a){var b,c;return null==a&&(a={}),b=a.attributes,c=b.map(function(a){return"change:"+a}).join(" "),this.model.on(c,function(b){return function(c,d,e){var f;return f=(null!=e?e:{}).mapstickChange,f?void 0:b.setBoundOverlayAttributes(a)}}(this))},f.prototype.listenToBoundOverlayEvents=function(a){var b,c;return null==a&&(a={}),c=a.overlay_attribute,(b=a.overlayEvents)&&_.isString(b)&&(b=[b]),null==b&&(b=this.defaultOverlayEvents),_.each(b,function(b){return function(d){return google.maps.event.addListener(b.overlay,d,function(e){return"drawn"===d&&("paths"===c?b._listenToPaths(a):"path"===c&&b._listenToPath(a)),b.setBoundModelAttributes(a,e)})}}(this))},f.prototype.setBoundModelAttributes=function(a,b){var c,d,e,f,g;return null==a&&(a={}),a.overlayChanged?(f=a.overlay_attribute,d=a.attributes,c="paths"===f?this.overlay.getPaths():"path"===f?this.overlay.getPath():this.get(f),g={},e=a.overlayChanged,_.isFunction(e)?g=e(c,b):_.isString(e)&&_.isFunction(this[e])?g=this[e](c,b):e===!0&&1===d.length&&(g[d[0]]=c),this.model.set(g,{mapstickChange:!0})):void 0},f.prototype.setBoundOverlayAttributes=function(a){var b,c,d,e,f,g;return null==a&&(a={}),b=a.attributes,e=a.overlay_attribute,c={},_.each(b,function(a){return function(b){return c[b]=a.model.get(b)}}(this)),f={},(d=a.modelChanged)?(g=null,_.isFunction(d)?g=d(c):_.isFunction(this[d])&&(g=this[d](c)),f[e]=g):1===b.length&&(f[e]=this.model.get(b[0])),this.set(f),"paths"===e?this._listenToPaths(a):"path"===e?this._listenToPath(a):void 0},f.prototype.triggerOverlayEvent=function(a,b){var c,d;return(c=this.overlayEvents[a])&&(d=this[c],_.isFunction(d)?d(b):console.error("no such handler for event: '"+a+"'")),d=this["on"+a.split("_").map(function(a){return a.charAt(0).toUpperCase()+a.slice(1)}).join("")],_.isFunction(d)?d(b):void 0},f.prototype.get=function(a){return this.overlay.get(a)},f.prototype.set=function(a,b){return _.isObject(a)?this.overlay.setOptions(a):_.isString(a)?this.overlay.set(a,b):console.error("can't set that")},f.prototype.show=function(a){return this.showing=!0,a&&(this.map=a),this.set("map",this.map)},f.prototype.hide=function(){return this.showing=!1,this.set("map",null)},f.prototype.remove=function(){return this.clearListeners(),this.clearModelListeners(),this.set("map",null)},f.prototype.clearListeners=function(){return this.overlay?google.maps.event.clearListeners(this.overlay):void 0},f.prototype.clearModelListeners=function(){return this.model?_.each(this.modelEvents,function(a){return function(b,c){var d;return _.isFunction(d=a[b])?a.model.off(c,d):void 0}}(this)):void 0},f.prototype.render=function(){return this.showing?this.overlay.setMap(this.map):void 0},f.prototype.draw=function(b){return null==b&&(b=this.map),google.maps.drawing?(this._cancelled=!1,null==a.drawingManager&&(a.drawingManager=new google.maps.drawing.DrawingManager({map:b,drawingControl:!1})),a.drawingManager.setMap(b),a.drawingManager.setDrawingMode(this.overlayType),google.maps.event.clearInstanceListeners(a.drawingManager),google.maps.event.addListener(a.drawingManager,"overlaycomplete",function(b){return function(c){return a.drawingManager.getDrawingMode()&&b.stopDrawing(),b._cancelled?b.abandonOverlay(c.overlay):b.saveOverlay(c.overlay)}}(this)),this._key_listener=google.maps.event.addDomListener(document,"keyup",this.handleKey)):console.error("please include google.maps.drawing library")},f.prototype.handleKey=function(a){return 27===a.keyCode&&this.cancelDraw(),13===a.keyCode?this.completeDraw():void 0},f.prototype.cancelDraw=function(){return this._cancelled=!0,this.stopDrawing()},f.prototype.completeDraw=function(){return this._cancelled=!1,this.stopDrawing()},f.prototype.stopDrawing=function(){return this._key_listener&&google.maps.event.removeListener(this._key_listener),a.drawingManager.setDrawingMode(null),a.drawingManager.setMap(null)},f.prototype.saveOverlay=function(a){return this.overlay.setOptions(this.getDrawnOptions(a)),this.model.trigger("overlay:drawn"),google.maps.event.trigger(this.overlay,"drawn"),a.setMap(null),this.show()},f.prototype.abandonOverlay=function(a){return this.model.trigger("overlay:cancelled"),google.maps.event.trigger(this.overlay,"cancelled"),a.setMap(null)},f.prototype.getDrawnOptions=function(){return{}},f}(Backbone.View),a.Marker=function(a){function c(){return this.getDrawnOptions=b(this.getDrawnOptions,this),c.__super__.constructor.apply(this,arguments)}return d(c,a),c.prototype.overlayType="marker",c.prototype.overlayEventNames=["animation_changed","click","clickable_changed","cursor_changed","dblclick","drag","dragend","draggable_changed","dragstart","flat_changed","icon_changed","mousedown","mouseout","mouseover","mouseup","position_changed","rightclick","shape_changed","title_changed","visible_changed","zindex_changed"],c.prototype.defaultOverlayEvents=["drag","dragend","dragstart","drawn"],c.prototype.twoWayProperties=["position"],c.prototype.properties=["anchorPoint","animation","clickable","crossOnDrag","cursor","draggable","icon","map","opacity","optimized","position","shape","title","visible","zIndex"],c.prototype.getDrawnOptions=function(a){return{position:a.getPosition()}},c}(a.Overlay),a.OverlayWithPath=function(c){function e(){return this._listenToPath=b(this._listenToPath,this),this.getDrawnOptions=b(this.getDrawnOptions,this),this.setOverlayPathFromEncodedString=b(this.setOverlayPathFromEncodedString,this),this.getEncodedPathFromOverlay=b(this.getEncodedPathFromOverlay,this),e.__super__.constructor.apply(this,arguments)}return d(e,c),e.prototype.defaultOptions={path:new google.maps.MVCArray},e.prototype.getEncodedPathFromOverlay=function(){return a.encodePathString(this.overlay.getPath())},e.prototype.setOverlayPathFromEncodedString=function(b){return this.overlay.setPath(a.decodePathString(b))},e.prototype.getDrawnOptions=function(a){return{path:a.getPath()}},e.prototype._listenToPath=function(a){var b;return null==a&&(a={}),b=this.overlay.getPath(),_.each(["insert_at","remove_at","set_at"],function(c){return function(d){return google.maps.event.addListener(b,d,function(b){return c.setBoundModelAttributes(a,b)})}}(this))},e}(a.Overlay),a.Polyline=function(a){function c(){return this.getBounds=b(this.getBounds,this),c.__super__.constructor.apply(this,arguments)}return d(c,a),c.prototype.overlayType="polyline",c.prototype.overlayEventNames=["click","dblclick","drag","dragend","dragstart","mousedown","mousemove","mouseout","mouseover","mouseup","rightclick"],c.prototype.defaultOverlayEvents=["drag","dragend","drawn"],c.prototype.twoWayProperties=["path"],c.prototype.properties=["clickable","draggable","editable","geodesic","icons","map","path","strokeColor","strokeOpacity","strokeWeight","visible","zIndex"],c.prototype.getBounds=function(){var a;return a=new google.maps.LatLngBounds,this.overlay.getPath().forEach(function(b){return a.extend(b)}),a},c}(a.OverlayWithPath),a.Polygon=function(c){function e(){return this.getBounds=b(this.getBounds,this),this._listenToPaths=b(this._listenToPaths,this),this.setOverlayPathsFromEncodedStrings=b(this.setOverlayPathsFromEncodedStrings,this),this.getEncodedPathsFromOverlay=b(this.getEncodedPathsFromOverlay,this),this.finishExclusion=b(this.finishExclusion,this),this.drawExclusion=b(this.drawExclusion,this),e.__super__.constructor.apply(this,arguments)}return d(e,c),e.prototype.overlayType="polygon",e.prototype.overlayEventNames=["click","dblclick","drag","dragend","dragstart","mousedown","mousemove","mouseout","mouseover","mouseup","rightclick"],e.prototype.defaultOverlayEvents=["drag","dragend","drawn"],e.prototype.twoWayProperties=["paths"],e.prototype.properties=["zIndex","visible","strokeWeight","strokePosition","strokeOpacity","strokeColor","paths","map","geodesic","fillOpacity","fillColor","editable","draggable","clickable"],e.prototype.drawExclusion=function(){return google.maps.drawing?(a.drawingManager&&a.drawingManager.getMap()===this.map||(a.drawingManager=new google.maps.drawing.DrawingManager({map:this.map,drawingControl:!1})),a.drawingManager.setDrawingMode("polygon"),google.maps.event.clearInstanceListeners(a.drawingManager),google.maps.event.addListener(a.drawingManager,"polygoncomplete",function(a){return function(b){return a.finishExclusion(b)}}(this))):console.error("please include google.maps.drawing library")},e.prototype.finishExclusion=function(b){var c,d;return c=b.getPath(),a.isClockwise(c)===a.isClockwise(this.overlay.getPath())&&(c=new google.maps.MVCArray(c.getArray().reverse())),d=this.overlay.getPaths(),d.push(c),this.overlay.setPaths(d),b.setMap(null),a.drawingManager.setDrawingMode(null),google.maps.event.trigger(this.overlay,"drawn")},e.prototype.getEncodedPathsFromOverlay=function(){return _.collect(this.overlay.getPaths().getArray(),function(b){return a.encodePathString(b)})},e.prototype.setOverlayPathsFromEncodedStrings=function(b){return _.isString(b)&&(b=b.split(",")),b=_.collect(b,function(b){return a.decodePathString(b)}),this.overlay.setPaths(b)},e.prototype._listenToPaths=function(a){var b;return null==a&&(a={}),b=this.overlay.getPaths(),_.each(["insert_at","remove_at","set_at"],function(c){return function(d){return b.forEach(function(b){return google.maps.event.addListener(b,d,function(){return c.setBoundModelAttributes(a)})})}}(this))},e.prototype.getBounds=function(){var a;return a=new google.maps.LatLngBounds,this.overlay.getPaths().forEach(function(b){return b.forEach(function(b){return a.extend(b)})}),a},e}(a.OverlayWithPath),a.Rectangle=function(a){function c(){return this.getDrawnOptions=b(this.getDrawnOptions,this),c.__super__.constructor.apply(this,arguments)}return d(c,a),c.prototype.overlayType="rectangle",c.prototype.overlayEventNames=["bounds_changed","click","dblclick","drag","dragend","dragstart","mousedown","mousemove","mouseout","mouseover","mouseup","rightclick"],c.prototype.defaultOverlayEvents=["drag","dragend","dragstart","drawn"],c.prototype.twoWayProperties=["bounds"],c.prototype.properties=["bounds","clickable","draggable","editable","fillColor","fillOpacity","map","strokeColor","strokeOpacity","strokePosition","strokeWeight","visible","zIndex"],c.prototype.getDrawnOptions=function(a){return{bounds:a.getBounds()}},c}(a.Overlay),a.Circle=function(a){function c(){return this.getDrawnOptions=b(this.getDrawnOptions,this),c.__super__.constructor.apply(this,arguments)}return d(c,a),c.prototype.overlayType="circle",c.prototype.overlayEventNames=["center_changed","click","dblclick","drag","dragend","dragstart","mousedown","mousemove","mouseout","mouseup","mouseover","radius_changed","rightclick"],c.prototype.defaultOverlayEvents=["drag","dragend","dragstart","drawn"],c.prototype.twoWayProperties=["center","radius"],c.prototype.properties=["center","clickable","draggable","editable","fillColor","fillOpacity","map","radius","strokeColor","strokeOpacity","strokePosition","strokeWeight","visible","zIndex"],c.prototype.getDrawnOptions=function(a){return{center:a.getCenter(),radius:a.getRadius()}},c}(a.Overlay),a.InfoWindow=function(a){function c(){return this.setContentView=b(this.setContentView,this),this.remove=b(this.remove,this),this.close=b(this.close,this),this.open=b(this.open,this),this.isOpen=b(this.isOpen,this),c.__super__.constructor.apply(this,arguments)}return d(c,a),c.prototype.overlayType="info_window",c.prototype.overlayEventNames=["closeclick","content_changed","domready","position_changed","zindex_changed"],c.prototype.twoWayProperties=["content"],c.prototype.properties=["content","disableAutoPan","maxWidth","pixelOffset","position","zIndex"],c.prototype.isOpen=function(){var a;return a=this.get("map"),null!==a&&"undefined"!=typeof a},c.prototype.open=function(a){var b,c,d,e;return e=null!=a?a:{},c=e.map,b=e.anchor,d=e.position,b?this.overlay.open(c||(c=b.getMap()),b):d&&(this.overlay.setPosition(d),c||(c=this.map))?this.overlay.open(c):void 0},c.prototype.close=function(){return this.overlay.close()},c.prototype.remove=function(){return this.close(),c.__super__.remove.apply(this,arguments)},c.prototype.setContentView=function(a){return null==a&&(a=this.content_view),a.render(),this.overlay.setContent(a.$el[0])},c}(a.Overlay),a.OverlayCollection=function(c){function e(a){this.closeChildren=b(this.closeChildren,this),this.close=b(this.close,this),this.triggerRendered=b(this.triggerRendered,this),this.triggerBeforeRender=b(this.triggerBeforeRender,this),this._initChildViewStorage=b(this._initChildViewStorage,this),this.removeChildView=b(this.removeChildView,this),this.removeItemView=b(this.removeItemView,this),this.buildItemView=b(this.buildItemView,this),this.addItemView=b(this.addItemView,this),this.getItemView=b(this.getItemView,this),this.showCollection=b(this.showCollection,this),this._renderChildren=b(this._renderChildren,this),this.render=b(this.render,this),this.hide=b(this.hide,this),this.show=b(this.show,this),this.addChildView=b(this.addChildView,this),this.removeListeners=b(this.removeListeners,this),this.listenToCollection=b(this.listenToCollection,this),this._initialEvents=b(this._initialEvents,this),this.cid=_.uniqueId(this.cidPrefix),this.options=_.extend({},_.result(this,"options"),_.isFunction(a)?a.call(this):a),_.extend(this,_.pick(a,this.viewOptions)),this._initChildViewStorage(),this._initialEvents(),this.listenToCollection(),_.isFunction(this.initialize)&&this.initialize(this.options)}return d(e,c),e.prototype.itemType="model",e.prototype.triggerMethod=a.triggerMethod,e.prototype.viewOptions=["collection","model","map"],e.prototype.showing=!1,e.prototype.collectionEvents={},e.prototype.cidPrefix="oc",e.prototype._initialEvents=function(){return this.collection?(this.listenTo(this.collection,"add",this.addChildView),this.listenTo(this.collection,"remove",this.removeItemView),this.listenTo(this.collection,"reset",this.render)):void 0},e.prototype.listenToCollection=function(){return this.collection?_.each(this.collectionEvents,function(a){return function(b,c){var d;return _.isFunction(d=a[b])?a.collection.on(c,d):void 0}}(this)):void 0},e.prototype.removeListeners=function(){return this.collection?(this.stopListening(this.collection,"add"),this.stopListening(this.collection,"remove"),this.stopListening(this.collection,"reset")):void 0},e.prototype.addChildView=function(a){var b;return(b=this.getItemView(a))?this.addItemView(a,b):void 0},e.prototype.show=function(a){return this.showing=!0,a&&(this.map=a),this.children.apply("show")},e.prototype.hide=function(){return this.showing=!1,this.children.apply("hide")},e.prototype.render=function(){return this.isClosed=!1,this.triggerBeforeRender(),this._renderChildren(),this.triggerRendered(),this},e.prototype._renderChildren=function(){return this.closeChildren(),this.showCollection()},e.prototype.showCollection=function(){return this.collection.each(function(a){return function(b){var c;return(c=a.getItemView(b))?a.addItemView(b,c):void 0}}(this))},e.prototype.getItemView=function(){var b;return b=a.getOption(this,"itemView"),b||console.error("An 'itemView' must be specified for class: "+this.constructor.name),b},e.prototype.addItemView=function(b,c,d){var e,f;return e=a.getOption(this,"itemViewOptions"),_.isFunction(e)&&(e=e.call(this,b,d)),f=this.buildItemView(b,c,e),this.triggerMethod("before:item:added",f),this.children.add(f),this.showing?f.show():f.hide(),this.triggerMethod("after:item:added",f),f},e.prototype.buildItemView=function(a,b,c){var d,e;return d=_.extend({model:a,map:this.map},c),e=new b(d)},e.prototype.removeItemView=function(a){var b;return b=this.children.findByModel(a),this.removeChildView(b)},e.prototype.removeChildView=function(a){return a&&(a.close?a.close():a.remove&&a.remove(),this.stopListening(a),this.children.remove(a)),this.triggerMethod("item:removed",a)},e.prototype._initChildViewStorage=function(){return this.children=new a.ChildViewContainer},e.prototype.triggerBeforeRender=function(){return this.triggerMethod("before:render",this),this.triggerMethod("collection:before:render",this)},e.prototype.triggerRendered=function(){return this.triggerMethod("render",this),this.triggerMethod("collection:rendered",this)},e.prototype.close=function(){return this.isClosed?void 0:(this.triggerMethod("collection:before:close"),this.closeChildren(),this.removeListeners(),this.triggerMethod("collection:closed"))},e.prototype.closeChildren=function(){return this.children.each(this.removeChildView)},e}(Backbone.View)}).call(this);