Improvements to the name-editable path control.
[armadillo.git] / web_frontend / modal_dialog.js
1 //
2 // Armadillo File Manager
3 // Copyright (c) 2010, Robert Sesek <http://www.bluestatic.org>
4 //
5 // This program is free software: you can redistribute it and/or modify it under
6 // the terms of the GNU General Public License as published by the Free Software
7 // Foundation, either version 3 of the License, or any later version.
8 //
9
10 goog.provide('armadillo.ModalDialog');
11
12 goog.require('goog.dom.classes');
13 goog.require('goog.events.EventHandler');
14 goog.require('goog.ui.Container');
15 goog.require('goog.ui.Control');
16
17 /**
18 * A modal dialog that does not use iframe masks, but instead installs a global
19 * event listener to prevent events.
20 * @param {goog.ui.DomHelper} opt_domHelper
21 * @constructor
22 */
23 armadillo.ModalDialog = function(opt_domHelper) {
24 goog.ui.Container.call(this, null, null, opt_domHelper);
25
26 /**
27 * Master EventHandler
28 */
29 this.eh_ = new goog.events.EventHandler();
30 };
31 goog.inherits(armadillo.ModalDialog, goog.ui.Container);
32
33 /**
34 * Disposer
35 * @private
36 */
37 armadillo.ModalDialog.prototype.disposeInternal = function() {
38 armadillo.ModalDialog.superClass_.disposeInternal.call(this);
39 this.eh_.dispose();
40 this.eh_ = null;
41 };
42
43 /**
44 * @inheritsDoc
45 */
46 armadillo.ModalDialog.prototype.createDom = function() {
47 this.decorateInternal(this.dom_.createElement('div'));
48 };
49
50 /**
51 * @inheritsDoc
52 */
53 armadillo.ModalDialog.prototype.decorateInternal = function(element) {
54 this.element_ = element;
55 goog.dom.classes.set(this.element_, 'modalDialog');
56
57 var close = new goog.ui.Control('Close Modal Dialog');
58 var dialog = this;
59 close.handleMouseDown = function(e) {
60 e.stopPropagation();
61 dialog.dispose();
62 };
63 this.addChild(close, true);
64 };
65
66 /**
67 * @inheritsDoc
68 */
69 armadillo.ModalDialog.prototype.enterDocument = function() {
70 armadillo.ModalDialog.superClass_.enterDocument.call(this);
71 // Create an event sink that captures all browser event types.
72 var types = new Array();
73 for (type in goog.events.EventType) {
74 types.push(goog.events.EventType[type]);
75 }
76 this.eventSinkKey_ = this.eh_.listen(this.dom_.getWindow(),
77 types, this.eventSink_, true, this);
78 };
79
80 /**
81 * @inheritsDoc
82 */
83 armadillo.ModalDialog.prototype.exitDocument = function() {
84 goog.events.unlistenByKey(this.eventSinkKey_);
85 this.eventSinkKey_ = null;
86 };
87
88 /**
89 * Every event that gets dispatched to the Window will first be evaluated by
90 * this memeber. If the event's target is not a child of the dialog, the event
91 * is cancelled.
92 * @param {Event} event
93 */
94 armadillo.ModalDialog.prototype.eventSink_ = function(event) {
95 var target = event.target;
96 while (target) {
97 if (target == this.element_) {
98 return;
99 }
100 target = target.parentNode;
101 }
102 event.stopPropagation();
103 };