X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/e823ad27e90d5cba05fb2ea8ac2a0d258be2f707..bbe3a85e8006750d52bd591086c8b196714ef759:/project/static/js/views/view.js diff --git a/project/static/js/views/view.js b/project/static/js/views/view.js index 498341e7..bc8266c1 100644 --- a/project/static/js/views/view.js +++ b/project/static/js/views/view.js @@ -1,28 +1,29 @@ -/*globals Class render_template*/ -var View = Class.extend({ +/*globals Editor render_template*/ +var View = Editor.Object.extend({ + _className: 'View', element: null, model: null, template: null, overlayClass: 'view-overlay', overlay: null, - id: null, - init: function(element, model, template) { + init: function(element, model, template) + { + console.log("init for view"); this.element = $(element); this.model = model; this.template = template || this.template; - if (this.template) { - this.element.html(render_template(this.template, {})); - } + if (this.template) this.render(); - View.lastId = View.lastId + 1; - this.id = 'view-' + View.lastId; + this._resizeHandler = this.resized.bind(this); + $(window).bind('resize', this._resizeHandler); + $(this.element).bind('resize', this._resizeHandler); }, - - // Identyczność - hash: function() { - + + render: function() { + console.log('rendering:', this._className); + this.element.html(render_template(this.template, this)); }, frozen: function() { @@ -30,6 +31,9 @@ var View = Class.extend({ }, freeze: function(message) { + if (this.frozen()) { + this.unfreeze(); + } this.overlay = this.overlay || $('
' + message + '
') .addClass(this.overlayClass) @@ -38,8 +42,14 @@ var View = Class.extend({ width: this.element.width(), height: this.element.height(), top: this.element.position().top, - left: this.element.position().left + left: this.element.position().left, + 'user-select': 'none', + '-webkit-user-select': 'none', + '-khtml-user-select': 'none', + '-moz-user-select': 'none', + overflow: 'hidden' }) + .attr('unselectable', 'on') .appendTo(this.element.parent()); this.overlay.children('div').css({ @@ -55,11 +65,25 @@ var View = Class.extend({ } }, + resized: function(event) { + if (this.frozen()) { + this.overlay.css({ + position: 'absolute', + width: this.element.width(), + height: this.element.height(), + top: this.element.position().top, + left: this.element.position().left + }).children('div').css({ + position: 'relative', + top: this.overlay.height() / 2 - 20 + }); + } + }, + dispose: function() { + $(window).unbind('resize', this._resizeHandler); + $(this.element).unbind('resize', this._resizeHandler); this.unfreeze(); this.element.contents().remove(); } }); - - -View.lastId = 0;