-
-
Save chancancode/5d7f28e83394a1d778ba to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var ViewHandlerMixin = Ember.Mixin.create({ | |
handles: [], | |
concatenatedProperties: ['handles'], | |
views: null, | |
init: function(){ | |
this.set('views', Ember.Object.create()); | |
this._super(); | |
}, | |
hasHandle: function(name){ | |
return this.get('handles').indexOf(name) > -1; | |
}, | |
connectHandle: function(handle, obj){ | |
if(this.hasHandle(handle)){ | |
this.set('views.' + handle, obj); | |
} | |
}, | |
disconnectHandle: function(handle){ | |
if(this.hasHandle(handle)){ | |
this.set('views.' + handle, undefined); | |
} | |
} | |
}); | |
Ember.ControllerMixin.reopen(ViewHandlerMixin); | |
Ember.Component.reopen(ViewHandlerMixin); | |
Ember.View.reopen({ | |
handle: null, | |
didInsertElement: function(){ | |
this._super(); | |
var handle = this.get('handle'), | |
target = this.get('targetObject'); | |
if(handle && ViewHandlerMixin.detect(target)){ | |
target.connectHandle(handle, this); | |
} | |
}, | |
willDestroyElement: function(){ | |
var handle = this.get('handle'), | |
target = this.get('targetObject'); | |
if(handle && ViewHandlerMixin.detect(target)){ | |
target.disconnectHandle(handle); | |
} | |
this._super(); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
App.MyMapComponent = Ember.Component.extend({ | |
/* public API for modifying map state */ | |
panTo: function(lat, lng, zoom, options){ | |
... | |
}, | |
panBy: function(x, y, zoom, options){ | |
... | |
}, | |
... | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
App.UnitsController = Ember.ArrayController.extend({ | |
handles: ['map'], | |
sidebarOpened: false, | |
actions: { | |
openSidebar: function(){ | |
this.set('sidebarOpened', true); | |
this.get('views.map').panBy(-SIDEBAR_WIDTH / 2, 0); | |
}, | |
closeSidebar: function(){ | |
this.set('sidebarOpened', false); | |
this.get('views.map').panBy(SIDEBAR_WIDTH / 2, 0); | |
}, | |
unitSelected: function(unit){ | |
this.get('views.map').panTo(unit.get('lat'), unit.get('lng')); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment