pre d: setattr, settext, split as ContextTransformations; detach in old format; pre...
[fnpeditor.git] / src / fnpjs / layout.js
1 define(['libs/jquery', 'libs/underscore'], function($ ,_) {
2     'use strict';
3       
4     var Layout = function(template) {
5         var layout = this;
6         this.dom = $(_.template(template)());
7         this.views = {};
8         
9         this.dom.onShow = function() {
10             _.values(layout.views).forEach(function(view) {
11                 if(view.onShow) {
12                     view.onShow();
13                 }
14             });
15         };
16         this.dom.onHide = function() {
17             _.values(layout.views).forEach(function(view) {
18                 if(view.onHide) {
19                     view.onHide();
20                 }
21             });
22         };
23         
24     };
25     
26     Layout.prototype.setView = function(place, view) {
27         this.dom.find('[fnpjs-place=' + place + ']').append(view);
28         this.views[place] = view;
29         if(this.dom.is(':visible') && view.onShow) {
30             view.onShow();
31         }
32     };
33     
34     Layout.prototype.getAsView = function() {
35         return this.dom;
36     };
37     
38     return {Layout: Layout};
39 });