X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/412e60ded1457ec0f408e2234c9dd60122929bac..efe36f4f1b5df351eeb4d40a54c3900cf9a7079b:/src/fnpjs/layout.js diff --git a/src/fnpjs/layout.js b/src/fnpjs/layout.js new file mode 100644 index 0000000..c1d110e --- /dev/null +++ b/src/fnpjs/layout.js @@ -0,0 +1,37 @@ +define(['libs/jquery', 'libs/underscore'], function($ ,_) { + 'use strict'; + + var Layout = function(template) { + var layout = this; + this.dom = $(_.template(template)()); + this.views = {}; + + this.dom.onShow = function() { + _.values(layout.views).forEach(function(view) { + if(view.onShow) + view.onShow(); + }); + }; + this.dom.onHide = function() { + _.values(layout.views).forEach(function(view) { + if(view.onHide) + view.onHide(); + }); + }; + + }; + + Layout.prototype.setView = function(place, view) { + this.dom.find('[fnpjs-place=' + place + ']').append(view); + this.views[place] = view; + if(this.dom.is(':visible') && view.onShow) { + view.onShow(); + } + }; + + Layout.prototype.getAsView = function() { + return this.dom; + }; + + return {Layout: Layout}; +}); \ No newline at end of file