diff options
author | Ondrej Zara <ondrej.zara@firma.seznam.cz> | 2015-06-12 09:30:51 +0200 |
---|---|---|
committer | Ondrej Zara <ondrej.zara@firma.seznam.cz> | 2015-06-12 09:30:51 +0200 |
commit | b3bf2bd8ecc9bd175793f67c46a8319b7d67174c (patch) | |
tree | e74aa005861dbd62381cfce3aac1d1acba3728c0 /js/window.js | |
parent | c5a07ea2b037cc880225defc58ead88c916fa066 (diff) | |
download | wwwsqldesigner-b3bf2bd8ecc9bd175793f67c46a8319b7d67174c.zip wwwsqldesigner-b3bf2bd8ecc9bd175793f67c46a8319b7d67174c.tar.gz wwwsqldesigner-b3bf2bd8ecc9bd175793f67c46a8319b7d67174c.tar.bz2 |
js modularized
Diffstat (limited to 'js/window.js')
-rw-r--r-- | js/window.js | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/js/window.js b/js/window.js new file mode 100644 index 0000000..fd25bd6 --- /dev/null +++ b/js/window.js @@ -0,0 +1,95 @@ +/* --------------------- window ------------ */ + +SQL.Window = OZ.Class(); + +SQL.Window.prototype.init = function(owner) { + this.owner = owner; + this.dom = { + container:OZ.$("window"), + background:OZ.$("background"), + ok:OZ.$("windowok"), + cancel:OZ.$("windowcancel"), + title:OZ.$("windowtitle"), + content:OZ.$("windowcontent"), + throbber:OZ.$("throbber") + } + this.dom.ok.value = _("windowok"); + this.dom.cancel.value = _("windowcancel"); + this.dom.throbber.alt = this.dom.throbber.title = _("throbber"); + OZ.Event.add(this.dom.ok, "click", this.bind(this.ok)); + OZ.Event.add(this.dom.cancel, "click", this.bind(this.close)); + OZ.Event.add(document, "keydown", this.bind(this.key)); + + this.sync = this.bind(this.sync); + + OZ.Event.add(window, "scroll", this.sync); + OZ.Event.add(window, "resize", this.sync); + this.state = 0; + this.hideThrobber(); + + this.sync(); +} + +SQL.Window.prototype.showThrobber = function() { + this.dom.throbber.style.visibility = ""; +} + +SQL.Window.prototype.hideThrobber = function() { + this.dom.throbber.style.visibility = "hidden"; +} + +SQL.Window.prototype.open = function(title, content, callback) { + this.state = 1; + this.callback = callback; + while (this.dom.title.childNodes.length > 1) { this.dom.title.removeChild(this.dom.title.childNodes[1]); } + + var txt = OZ.DOM.text(title); + this.dom.title.appendChild(txt); + this.dom.background.style.visibility = "visible"; + OZ.DOM.clear(this.dom.content); + this.dom.content.appendChild(content); + + var win = OZ.DOM.win(); + var scroll = OZ.DOM.scroll(); + this.dom.container.style.left = Math.round(scroll[0] + (win[0] - this.dom.container.offsetWidth)/2)+"px"; + this.dom.container.style.top = Math.round(scroll[1] + (win[1] - this.dom.container.offsetHeight)/2)+"px"; + + this.dom.cancel.style.visibility = (this.callback ? "" : "hidden"); + this.dom.container.style.visibility = "visible"; + + var formElements = ["input","select","textarea"]; + var all = this.dom.container.getElementsByTagName("*"); + for (var i=0;i<all.length;i++) { + if (formElements.indexOf(all[i].tagName.toLowerCase()) != -1) { + all[i].focus(); + break; + } + } +} + +SQL.Window.prototype.key = function(e) { + if (!this.state) { return; } + if (e.keyCode == 13) { this.ok(e); } + if (e.keyCode == 27) { this.close(); } +} + +SQL.Window.prototype.ok = function(e) { + if (this.callback) { this.callback(); } + this.close(); +} + +SQL.Window.prototype.close = function() { + if (!this.state) { return; } + this.state = 0; + this.dom.background.style.visibility = "hidden"; + this.dom.container.style.visibility = "hidden"; +} + +SQL.Window.prototype.sync = function() { /* adjust background position */ + var dims = OZ.DOM.win(); + var scroll = OZ.DOM.scroll(); + this.dom.background.style.width = dims[0]+"px"; + this.dom.background.style.height = dims[1]+"px"; + this.dom.background.style.left = scroll[0]+"px"; + this.dom.background.style.top = scroll[1]+"px"; +} |