1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618 |
- goog.provide('goog.ui.Dialog');
- goog.provide('goog.ui.Dialog.ButtonSet');
- goog.provide('goog.ui.Dialog.ButtonSet.DefaultButtons');
- goog.provide('goog.ui.Dialog.DefaultButtonCaptions');
- goog.provide('goog.ui.Dialog.DefaultButtonKeys');
- goog.provide('goog.ui.Dialog.Event');
- goog.provide('goog.ui.Dialog.EventType');
- goog.require('goog.a11y.aria');
- goog.require('goog.a11y.aria.Role');
- goog.require('goog.a11y.aria.State');
- goog.require('goog.asserts');
- goog.require('goog.dom');
- goog.require('goog.dom.NodeType');
- goog.require('goog.dom.TagName');
- goog.require('goog.dom.classlist');
- goog.require('goog.dom.safe');
- goog.require('goog.events');
- goog.require('goog.events.Event');
- goog.require('goog.events.EventType');
- goog.require('goog.events.KeyCodes');
- goog.require('goog.fx.Dragger');
- goog.require('goog.html.SafeHtml');
- goog.require('goog.math.Rect');
- goog.require('goog.string');
- goog.require('goog.structs.Map');
- goog.require('goog.style');
- goog.require('goog.ui.ModalPopup');
- goog.ui.Dialog = function(opt_class, opt_useIframeMask, opt_domHelper) {
- goog.ui.Dialog.base(this, 'constructor', opt_useIframeMask, opt_domHelper);
-
- this.class_ = opt_class || goog.getCssName('modal-dialog');
- this.buttons_ = goog.ui.Dialog.ButtonSet.createOkCancel();
- };
- goog.inherits(goog.ui.Dialog, goog.ui.ModalPopup);
- goog.tagUnsealableClass(goog.ui.Dialog);
- goog.ui.Dialog.prototype.buttons_;
- goog.ui.Dialog.prototype.escapeToCancel_ = true;
- goog.ui.Dialog.prototype.hasTitleCloseButton_ = true;
- goog.ui.Dialog.prototype.modal_ = true;
- goog.ui.Dialog.prototype.draggable_ = true;
- goog.ui.Dialog.prototype.backgroundElementOpacity_ = 0.50;
- goog.ui.Dialog.prototype.title_ = '';
- goog.ui.Dialog.prototype.content_ = null;
- goog.ui.Dialog.prototype.dragger_ = null;
- goog.ui.Dialog.prototype.disposeOnHide_ = false;
- goog.ui.Dialog.prototype.titleEl_ = null;
- goog.ui.Dialog.prototype.titleTextEl_ = null;
- goog.ui.Dialog.prototype.titleTextId_ = null;
- goog.ui.Dialog.prototype.titleCloseEl_ = null;
- goog.ui.Dialog.prototype.contentEl_ = null;
- goog.ui.Dialog.prototype.buttonEl_ = null;
- goog.ui.Dialog.prototype.preferredAriaRole_ = goog.a11y.aria.Role.DIALOG;
- goog.ui.Dialog.prototype.getCssClass = function() {
- return this.class_;
- };
- goog.ui.Dialog.prototype.setTitle = function(title) {
- this.title_ = title;
- if (this.titleTextEl_) {
- goog.dom.setTextContent(this.titleTextEl_, title);
- }
- };
- goog.ui.Dialog.prototype.getTitle = function() {
- return this.title_;
- };
- goog.ui.Dialog.prototype.setTextContent = function(text) {
- this.setSafeHtmlContent(
- goog.html.SafeHtml.htmlEscapePreservingNewlines(text));
- };
- goog.ui.Dialog.prototype.setSafeHtmlContent = function(html) {
- this.content_ = html;
- if (this.contentEl_) {
- goog.dom.safe.setInnerHtml(this.contentEl_, html);
- }
- };
- goog.ui.Dialog.prototype.getContent = function() {
- return this.content_ != null ? goog.html.SafeHtml.unwrap(this.content_) : '';
- };
- goog.ui.Dialog.prototype.getSafeHtmlContent = function() {
- return this.content_;
- };
- goog.ui.Dialog.prototype.getPreferredAriaRole = function() {
- return this.preferredAriaRole_;
- };
- goog.ui.Dialog.prototype.setPreferredAriaRole = function(role) {
- this.preferredAriaRole_ = role;
- };
- goog.ui.Dialog.prototype.renderIfNoDom_ = function() {
- if (!this.getElement()) {
-
-
-
-
- this.render();
- }
- };
- goog.ui.Dialog.prototype.getContentElement = function() {
- this.renderIfNoDom_();
- return this.contentEl_;
- };
- goog.ui.Dialog.prototype.getTitleElement = function() {
- this.renderIfNoDom_();
- return this.titleEl_;
- };
- goog.ui.Dialog.prototype.getTitleTextElement = function() {
- this.renderIfNoDom_();
- return this.titleTextEl_;
- };
- goog.ui.Dialog.prototype.getTitleCloseElement = function() {
- this.renderIfNoDom_();
- return this.titleCloseEl_;
- };
- goog.ui.Dialog.prototype.getButtonElement = function() {
- this.renderIfNoDom_();
- return this.buttonEl_;
- };
- goog.ui.Dialog.prototype.getDialogElement = function() {
- this.renderIfNoDom_();
- return this.getElement();
- };
- goog.ui.Dialog.prototype.getBackgroundElement = function() {
- this.renderIfNoDom_();
- return goog.ui.Dialog.base(this, 'getBackgroundElement');
- };
- goog.ui.Dialog.prototype.getBackgroundElementOpacity = function() {
- return this.backgroundElementOpacity_;
- };
- goog.ui.Dialog.prototype.setBackgroundElementOpacity = function(opacity) {
- this.backgroundElementOpacity_ = opacity;
- if (this.getElement()) {
- var bgEl = this.getBackgroundElement();
- if (bgEl) {
- goog.style.setOpacity(bgEl, this.backgroundElementOpacity_);
- }
- }
- };
- goog.ui.Dialog.prototype.setModal = function(modal) {
- if (modal != this.modal_) {
- this.setModalInternal_(modal);
- }
- };
- goog.ui.Dialog.prototype.setModalInternal_ = function(modal) {
- this.modal_ = modal;
- if (this.isInDocument()) {
- var dom = this.getDomHelper();
- var bg = this.getBackgroundElement();
- var bgIframe = this.getBackgroundIframe();
- if (modal) {
- if (bgIframe) {
- dom.insertSiblingBefore(bgIframe, this.getElement());
- }
- dom.insertSiblingBefore(bg, this.getElement());
- } else {
- dom.removeNode(bgIframe);
- dom.removeNode(bg);
- }
- }
- if (this.isVisible()) {
- this.setA11YDetectBackground(modal);
- }
- };
- goog.ui.Dialog.prototype.getModal = function() {
- return this.modal_;
- };
- goog.ui.Dialog.prototype.getClass = function() {
- return this.getCssClass();
- };
- goog.ui.Dialog.prototype.setDraggable = function(draggable) {
- this.draggable_ = draggable;
- this.setDraggingEnabled_(draggable && this.isInDocument());
- };
- goog.ui.Dialog.prototype.createDragger = function() {
- return new goog.fx.Dragger(this.getElement(), this.titleEl_);
- };
- goog.ui.Dialog.prototype.getDraggable = function() {
- return this.draggable_;
- };
- goog.ui.Dialog.prototype.setDraggingEnabled_ = function(enabled) {
-
-
-
-
- var classNames =
- goog.string.trim(goog.getCssName(this.class_, 'title-draggable'))
- .split(' ');
- if (this.getElement()) {
- if (enabled) {
- goog.dom.classlist.addAll(goog.asserts.assert(this.titleEl_), classNames);
- } else {
- goog.dom.classlist.removeAll(
- goog.asserts.assert(this.titleEl_), classNames);
- }
- }
- if (enabled && !this.dragger_) {
- this.dragger_ = this.createDragger();
- goog.dom.classlist.addAll(goog.asserts.assert(this.titleEl_), classNames);
- goog.events.listen(
- this.dragger_, goog.fx.Dragger.EventType.START, this.setDraggerLimits_,
- false, this);
- } else if (!enabled && this.dragger_) {
- this.dragger_.dispose();
- this.dragger_ = null;
- }
- };
- goog.ui.Dialog.prototype.createDom = function() {
- goog.ui.Dialog.base(this, 'createDom');
- var element = this.getElement();
- goog.asserts.assert(element, 'getElement() returns null');
- var dom = this.getDomHelper();
- this.titleEl_ = dom.createDom(
- goog.dom.TagName.DIV, goog.getCssName(this.class_, 'title'),
- this.titleTextEl_ = dom.createDom(
- goog.dom.TagName.SPAN, {
- 'className': goog.getCssName(this.class_, 'title-text'),
- 'id': this.getId()
- },
- this.title_),
- this.titleCloseEl_ = dom.createDom(
- goog.dom.TagName.SPAN, goog.getCssName(this.class_, 'title-close'))),
- goog.dom.append(
- element, this.titleEl_,
- this.contentEl_ = dom.createDom(
- goog.dom.TagName.DIV, goog.getCssName(this.class_, 'content')),
- this.buttonEl_ = dom.createDom(
- goog.dom.TagName.DIV, goog.getCssName(this.class_, 'buttons')));
-
-
-
- goog.a11y.aria.setRole(this.titleTextEl_, goog.a11y.aria.Role.HEADING);
- goog.a11y.aria.setRole(this.titleCloseEl_, goog.a11y.aria.Role.BUTTON);
- goog.dom.setFocusableTabIndex(this.titleCloseEl_, true);
- goog.a11y.aria.setLabel(
- this.titleCloseEl_, goog.ui.Dialog.MSG_GOOG_UI_DIALOG_CLOSE_);
- this.titleTextId_ = this.titleTextEl_.id;
- goog.a11y.aria.setRole(element, this.getPreferredAriaRole());
- goog.a11y.aria.setState(
- element, goog.a11y.aria.State.LABELLEDBY, this.titleTextId_ || '');
-
-
- if (this.content_) {
- goog.dom.safe.setInnerHtml(this.contentEl_, this.content_);
- }
- goog.style.setElementShown(this.titleCloseEl_, this.hasTitleCloseButton_);
-
- if (this.buttons_) {
- this.buttons_.attachToElement(this.buttonEl_);
- }
- goog.style.setElementShown(this.buttonEl_, !!this.buttons_);
- this.setBackgroundElementOpacity(this.backgroundElementOpacity_);
- };
- goog.ui.Dialog.prototype.decorateInternal = function(element) {
- goog.ui.Dialog.base(this, 'decorateInternal', element);
- var dialogElement = this.getElement();
- goog.asserts.assert(
- dialogElement, 'The DOM element for dialog cannot be null.');
-
- var contentClass = goog.getCssName(this.class_, 'content');
- this.contentEl_ = goog.dom.getElementsByTagNameAndClass(
- null, contentClass, dialogElement)[0];
- if (!this.contentEl_) {
- this.contentEl_ =
- this.getDomHelper().createDom(goog.dom.TagName.DIV, contentClass);
- if (this.content_) {
- goog.dom.safe.setInnerHtml(this.contentEl_, this.content_);
- }
- dialogElement.appendChild(this.contentEl_);
- }
-
- var titleClass = goog.getCssName(this.class_, 'title');
- var titleTextClass = goog.getCssName(this.class_, 'title-text');
- var titleCloseClass = goog.getCssName(this.class_, 'title-close');
- this.titleEl_ =
- goog.dom.getElementsByTagNameAndClass(null, titleClass, dialogElement)[0];
- if (this.titleEl_) {
-
-
-
- this.titleTextEl_ = goog.dom.getElementsByTagNameAndClass(
- null, titleTextClass, this.titleEl_)[0];
- this.titleCloseEl_ = goog.dom.getElementsByTagNameAndClass(
- null, titleCloseClass, this.titleEl_)[0];
- } else {
-
-
- this.titleEl_ =
- this.getDomHelper().createDom(goog.dom.TagName.DIV, titleClass);
- dialogElement.insertBefore(this.titleEl_, this.contentEl_);
- }
-
- if (this.titleTextEl_) {
- this.title_ = goog.dom.getTextContent(this.titleTextEl_);
-
- if (!this.titleTextEl_.id) {
- this.titleTextEl_.id = this.getId();
- }
- } else {
- this.titleTextEl_ = goog.dom.createDom(
- goog.dom.TagName.SPAN,
- {'className': titleTextClass, 'id': this.getId()});
- this.titleEl_.appendChild(this.titleTextEl_);
- }
- this.titleTextId_ = this.titleTextEl_.id;
- goog.a11y.aria.setState(
- dialogElement, goog.a11y.aria.State.LABELLEDBY, this.titleTextId_ || '');
-
- if (!this.titleCloseEl_) {
- this.titleCloseEl_ =
- this.getDomHelper().createDom(goog.dom.TagName.SPAN, titleCloseClass);
- this.titleEl_.appendChild(this.titleCloseEl_);
- }
- goog.style.setElementShown(this.titleCloseEl_, this.hasTitleCloseButton_);
-
- var buttonsClass = goog.getCssName(this.class_, 'buttons');
- this.buttonEl_ = goog.dom.getElementsByTagNameAndClass(
- null, buttonsClass, dialogElement)[0];
- if (this.buttonEl_) {
-
-
- this.buttons_ = new goog.ui.Dialog.ButtonSet(this.getDomHelper());
- this.buttons_.decorate(this.buttonEl_);
- } else {
-
- this.buttonEl_ =
- this.getDomHelper().createDom(goog.dom.TagName.DIV, buttonsClass);
- dialogElement.appendChild(this.buttonEl_);
- if (this.buttons_) {
- this.buttons_.attachToElement(this.buttonEl_);
- }
- goog.style.setElementShown(this.buttonEl_, !!this.buttons_);
- }
- this.setBackgroundElementOpacity(this.backgroundElementOpacity_);
- };
- goog.ui.Dialog.prototype.enterDocument = function() {
- goog.ui.Dialog.base(this, 'enterDocument');
-
- this.getHandler()
- .listen(this.getElement(), goog.events.EventType.KEYDOWN, this.onKey_)
- .listen(this.getElement(), goog.events.EventType.KEYPRESS, this.onKey_);
-
-
-
-
-
-
-
-
- this.getHandler().listen(
- this.buttonEl_, goog.events.EventType.CLICK, this.onButtonClick_);
-
- this.setDraggingEnabled_(this.draggable_);
-
- this.getHandler().listen(
- this.titleCloseEl_, goog.events.EventType.CLICK, this.onTitleCloseClick_);
- var element = this.getElement();
- goog.asserts.assert(element, 'The DOM element for dialog cannot be null');
- goog.a11y.aria.setRole(element, this.getPreferredAriaRole());
- if (this.titleTextEl_.id !== '') {
- goog.a11y.aria.setState(
- element, goog.a11y.aria.State.LABELLEDBY, this.titleTextEl_.id);
- }
- if (!this.modal_) {
- this.setModalInternal_(false);
- }
- };
- goog.ui.Dialog.prototype.exitDocument = function() {
- if (this.isVisible()) {
- this.setVisible(false);
- }
-
- this.setDraggingEnabled_(false);
- goog.ui.Dialog.base(this, 'exitDocument');
- };
- goog.ui.Dialog.prototype.setVisible = function(visible) {
- if (visible == this.isVisible()) {
- return;
- }
-
- if (!this.isInDocument()) {
- this.render();
- }
- goog.ui.Dialog.base(this, 'setVisible', visible);
- };
- goog.ui.Dialog.prototype.onShow = function() {
- goog.ui.Dialog.base(this, 'onShow');
- this.dispatchEvent(goog.ui.Dialog.EventType.AFTER_SHOW);
- };
- goog.ui.Dialog.prototype.onHide = function() {
- goog.ui.Dialog.base(this, 'onHide');
- this.dispatchEvent(goog.ui.Dialog.EventType.AFTER_HIDE);
- if (this.disposeOnHide_) {
- this.dispose();
- }
- };
- goog.ui.Dialog.prototype.setDraggerLimits_ = function(e) {
- var doc = this.getDomHelper().getDocument();
- var win = goog.dom.getWindow(doc) || window;
-
-
- var viewSize = goog.dom.getViewportSize(win);
- var w = Math.max(doc.body.scrollWidth, viewSize.width);
- var h = Math.max(doc.body.scrollHeight, viewSize.height);
- var dialogSize = goog.style.getSize(this.getElement());
- if (goog.style.getComputedPosition(this.getElement()) == 'fixed') {
-
- this.dragger_.setLimits(
- new goog.math.Rect(
- 0, 0, Math.max(0, viewSize.width - dialogSize.width),
- Math.max(0, viewSize.height - dialogSize.height)));
- } else {
- this.dragger_.setLimits(
- new goog.math.Rect(0, 0, w - dialogSize.width, h - dialogSize.height));
- }
- };
- goog.ui.Dialog.prototype.onTitleCloseClick_ = function(e) {
- this.handleTitleClose_();
- };
- goog.ui.Dialog.prototype.handleTitleClose_ = function() {
- if (!this.hasTitleCloseButton_) {
- return;
- }
- var bs = this.getButtonSet();
- var key = bs && bs.getCancel();
-
- if (key) {
- var caption = (bs.get(key));
- if (this.dispatchEvent(new goog.ui.Dialog.Event(key, caption))) {
- this.setVisible(false);
- }
- } else {
- this.setVisible(false);
- }
- };
- goog.ui.Dialog.prototype.getHasTitleCloseButton = function() {
- return this.hasTitleCloseButton_;
- };
- goog.ui.Dialog.prototype.setHasTitleCloseButton = function(b) {
- this.hasTitleCloseButton_ = b;
- if (this.titleCloseEl_) {
- goog.style.setElementShown(this.titleCloseEl_, this.hasTitleCloseButton_);
- }
- };
- goog.ui.Dialog.prototype.isEscapeToCancel = function() {
- return this.escapeToCancel_;
- };
- goog.ui.Dialog.prototype.setEscapeToCancel = function(b) {
- this.escapeToCancel_ = b;
- };
- goog.ui.Dialog.prototype.setDisposeOnHide = function(b) {
- this.disposeOnHide_ = b;
- };
- goog.ui.Dialog.prototype.getDisposeOnHide = function() {
- return this.disposeOnHide_;
- };
- goog.ui.Dialog.prototype.disposeInternal = function() {
- this.titleCloseEl_ = null;
- this.buttonEl_ = null;
- goog.ui.Dialog.base(this, 'disposeInternal');
- };
- goog.ui.Dialog.prototype.setButtonSet = function(buttons) {
- this.buttons_ = buttons;
- if (this.buttonEl_) {
- if (this.buttons_) {
- this.buttons_.attachToElement(this.buttonEl_);
- } else {
- goog.dom.safe.setInnerHtml(this.buttonEl_, goog.html.SafeHtml.EMPTY);
- }
- goog.style.setElementShown(this.buttonEl_, !!this.buttons_);
- }
- };
- goog.ui.Dialog.prototype.getButtonSet = function() {
- return this.buttons_;
- };
- goog.ui.Dialog.prototype.onButtonClick_ = function(e) {
- var button = this.findParentButton_( (e.target));
- if (button && !button.disabled) {
- var key = button.name;
- var caption = (this.getButtonSet().get(key));
- if (this.dispatchEvent(new goog.ui.Dialog.Event(key, caption))) {
- this.setVisible(false);
- }
- }
- };
- goog.ui.Dialog.prototype.findParentButton_ = function(element) {
- var el = element;
- while (el != null && el != this.buttonEl_) {
- if (el.tagName == goog.dom.TagName.BUTTON) {
- return (el);
- }
- el = el.parentNode;
- }
- return null;
- };
- goog.ui.Dialog.prototype.onKey_ = function(e) {
- var close = false;
- var hasHandler = false;
- var buttonSet = this.getButtonSet();
- var target = e.target;
- if (e.type == goog.events.EventType.KEYDOWN) {
-
- if (this.escapeToCancel_ && e.keyCode == goog.events.KeyCodes.ESC) {
-
- var cancel = buttonSet && buttonSet.getCancel();
-
- var isSpecialFormElement =
- target.tagName == goog.dom.TagName.SELECT && !target.disabled;
- if (cancel && !isSpecialFormElement) {
- hasHandler = true;
- var caption = buttonSet.get(cancel);
- close = this.dispatchEvent(
- new goog.ui.Dialog.Event(
- cancel,
- (caption)));
- } else if (!isSpecialFormElement) {
- close = true;
- }
- } else if (
- e.keyCode == goog.events.KeyCodes.TAB && e.shiftKey &&
- target == this.getElement()) {
-
-
- this.setupBackwardTabWrap();
- }
- } else if (e.keyCode == goog.events.KeyCodes.ENTER) {
-
-
- var key;
- if (target.tagName == goog.dom.TagName.BUTTON && !target.disabled) {
-
-
- key = target.name;
- } else if (target == this.titleCloseEl_) {
-
- this.handleTitleClose_();
- } else if (buttonSet) {
-
-
- var defaultKey = buttonSet.getDefault();
- var defaultButton = defaultKey && buttonSet.getButton(defaultKey);
-
- var isSpecialFormElement = (target.tagName == goog.dom.TagName.TEXTAREA ||
- target.tagName == goog.dom.TagName.SELECT ||
- target.tagName == goog.dom.TagName.A) &&
- !target.disabled;
- if (defaultButton && !defaultButton.disabled && !isSpecialFormElement) {
- key = defaultKey;
- }
- }
- if (key && buttonSet) {
- hasHandler = true;
- close = this.dispatchEvent(
- new goog.ui.Dialog.Event(key, String(buttonSet.get(key))));
- }
- } else if (
- target == this.titleCloseEl_ && e.keyCode == goog.events.KeyCodes.SPACE) {
-
- this.handleTitleClose_();
- }
- if (close || hasHandler) {
- e.stopPropagation();
- e.preventDefault();
- }
- if (close) {
- this.setVisible(false);
- }
- };
- goog.ui.Dialog.Event = function(key, caption) {
- this.type = goog.ui.Dialog.EventType.SELECT;
- this.key = key;
- this.caption = caption;
- };
- goog.inherits(goog.ui.Dialog.Event, goog.events.Event);
- goog.ui.Dialog.SELECT_EVENT = 'dialogselect';
- goog.ui.Dialog.EventType = {
-
- SELECT: 'dialogselect',
-
- AFTER_HIDE: 'afterhide',
-
- AFTER_SHOW: 'aftershow'
- };
- goog.ui.Dialog.ButtonSet = function(opt_domHelper) {
-
- this.dom_ = opt_domHelper || goog.dom.getDomHelper();
- goog.structs.Map.call(this);
- };
- goog.inherits(goog.ui.Dialog.ButtonSet, goog.structs.Map);
- goog.tagUnsealableClass(goog.ui.Dialog.ButtonSet);
- goog.ui.Dialog.ButtonSet.prototype.class_ = goog.getCssName('goog-buttonset');
- goog.ui.Dialog.ButtonSet.prototype.defaultButton_ = null;
- goog.ui.Dialog.ButtonSet.prototype.element_ = null;
- goog.ui.Dialog.ButtonSet.prototype.cancelButton_ = null;
- goog.ui.Dialog.ButtonSet.prototype.clear = function() {
- goog.structs.Map.prototype.clear.call(this);
- this.defaultButton_ = this.cancelButton_ = null;
- };
- goog.ui.Dialog.ButtonSet.prototype.set = function(
- key, caption, opt_isDefault, opt_isCancel) {
- goog.structs.Map.prototype.set.call(this, key, caption);
- if (opt_isDefault) {
- this.defaultButton_ = (key);
- }
- if (opt_isCancel) {
- this.cancelButton_ = (key);
- }
- return this;
- };
- goog.ui.Dialog.ButtonSet.prototype.addButton = function(
- button, opt_isDefault, opt_isCancel) {
- return this.set(button.key, button.caption, opt_isDefault, opt_isCancel);
- };
- goog.ui.Dialog.ButtonSet.prototype.attachToElement = function(el) {
- this.element_ = el;
- this.render();
- };
- goog.ui.Dialog.ButtonSet.prototype.render = function() {
- if (this.element_) {
- goog.dom.safe.setInnerHtml(this.element_, goog.html.SafeHtml.EMPTY);
- var domHelper = goog.dom.getDomHelper(this.element_);
- this.forEach(function(caption, key) {
- var button =
- domHelper.createDom(goog.dom.TagName.BUTTON, {'name': key}, caption);
- if (key == this.defaultButton_) {
- button.className = goog.getCssName(this.class_, 'default');
- }
- this.element_.appendChild(button);
- }, this);
- }
- };
- goog.ui.Dialog.ButtonSet.prototype.decorate = function(element) {
- if (!element || element.nodeType != goog.dom.NodeType.ELEMENT) {
- return;
- }
- this.element_ = element;
- var buttons =
- goog.dom.getElementsByTagName(goog.dom.TagName.BUTTON, this.element_);
- for (var i = 0, button, key, caption; button = buttons[i]; i++) {
-
-
- key = button.name || button.id;
- caption = goog.dom.getTextContent(button) || button.value;
- if (key) {
- var isDefault = i == 0;
- var isCancel = button.name == goog.ui.Dialog.DefaultButtonKeys.CANCEL;
- this.set(key, caption, isDefault, isCancel);
- if (isDefault) {
- goog.dom.classlist.add(button, goog.getCssName(this.class_, 'default'));
- }
- }
- }
- };
- goog.ui.Dialog.ButtonSet.prototype.getElement = function() {
- return this.element_;
- };
- goog.ui.Dialog.ButtonSet.prototype.getDomHelper = function() {
- return this.dom_;
- };
- goog.ui.Dialog.ButtonSet.prototype.setDefault = function(key) {
- this.defaultButton_ = key;
- };
- goog.ui.Dialog.ButtonSet.prototype.getDefault = function() {
- return this.defaultButton_;
- };
- goog.ui.Dialog.ButtonSet.prototype.setCancel = function(key) {
- this.cancelButton_ = key;
- };
- goog.ui.Dialog.ButtonSet.prototype.getCancel = function() {
- return this.cancelButton_;
- };
- goog.ui.Dialog.ButtonSet.prototype.getButton = function(key) {
- var buttons = this.getAllButtons();
- for (var i = 0, nextButton; nextButton = buttons[i]; i++) {
- if (nextButton.name == key || nextButton.id == key) {
- return nextButton;
- }
- }
- return null;
- };
- goog.ui.Dialog.ButtonSet.prototype.getAllButtons = function() {
- return goog.dom.getElementsByTagName(
- goog.dom.TagName.BUTTON, goog.asserts.assert(this.element_));
- };
- goog.ui.Dialog.ButtonSet.prototype.setButtonEnabled = function(key, enabled) {
- var button = this.getButton(key);
- if (button) {
- button.disabled = !enabled;
- }
- };
- goog.ui.Dialog.ButtonSet.prototype.setAllButtonsEnabled = function(enabled) {
- var allButtons = this.getAllButtons();
- for (var i = 0, button; button = allButtons[i]; i++) {
- button.disabled = !enabled;
- }
- };
- goog.ui.Dialog.DefaultButtonKeys = {
- OK: 'ok',
- CANCEL: 'cancel',
- YES: 'yes',
- NO: 'no',
- SAVE: 'save',
- CONTINUE: 'continue'
- };
- goog.ui.Dialog.MSG_DIALOG_OK_ = goog.getMsg('OK');
- goog.ui.Dialog.MSG_DIALOG_CANCEL_ = goog.getMsg('Cancel');
- goog.ui.Dialog.MSG_DIALOG_YES_ = goog.getMsg('Yes');
- goog.ui.Dialog.MSG_DIALOG_NO_ = goog.getMsg('No');
- goog.ui.Dialog.MSG_DIALOG_SAVE_ = goog.getMsg('Save');
- goog.ui.Dialog.MSG_DIALOG_CONTINUE_ = goog.getMsg('Continue');
- goog.ui.Dialog.MSG_GOOG_UI_DIALOG_CLOSE_ = goog.getMsg('Close');
- goog.ui.Dialog.DefaultButtonCaptions = {
- OK: goog.ui.Dialog.MSG_DIALOG_OK_,
- CANCEL: goog.ui.Dialog.MSG_DIALOG_CANCEL_,
- YES: goog.ui.Dialog.MSG_DIALOG_YES_,
- NO: goog.ui.Dialog.MSG_DIALOG_NO_,
- SAVE: goog.ui.Dialog.MSG_DIALOG_SAVE_,
- CONTINUE: goog.ui.Dialog.MSG_DIALOG_CONTINUE_
- };
- goog.ui.Dialog.ButtonSet.DefaultButtons = {
- OK: {
- key: goog.ui.Dialog.DefaultButtonKeys.OK,
- caption: goog.ui.Dialog.DefaultButtonCaptions.OK
- },
- CANCEL: {
- key: goog.ui.Dialog.DefaultButtonKeys.CANCEL,
- caption: goog.ui.Dialog.DefaultButtonCaptions.CANCEL
- },
- YES: {
- key: goog.ui.Dialog.DefaultButtonKeys.YES,
- caption: goog.ui.Dialog.DefaultButtonCaptions.YES
- },
- NO: {
- key: goog.ui.Dialog.DefaultButtonKeys.NO,
- caption: goog.ui.Dialog.DefaultButtonCaptions.NO
- },
- SAVE: {
- key: goog.ui.Dialog.DefaultButtonKeys.SAVE,
- caption: goog.ui.Dialog.DefaultButtonCaptions.SAVE
- },
- CONTINUE: {
- key: goog.ui.Dialog.DefaultButtonKeys.CONTINUE,
- caption: goog.ui.Dialog.DefaultButtonCaptions.CONTINUE
- }
- };
- goog.ui.Dialog.ButtonSet.createOk = function() {
- return new goog.ui.Dialog.ButtonSet().addButton(
- goog.ui.Dialog.ButtonSet.DefaultButtons.OK, true, true);
- };
- goog.ui.Dialog.ButtonSet.createOkCancel = function() {
- return new goog.ui.Dialog.ButtonSet()
- .addButton(goog.ui.Dialog.ButtonSet.DefaultButtons.OK, true)
- .addButton(goog.ui.Dialog.ButtonSet.DefaultButtons.CANCEL, false, true);
- };
- goog.ui.Dialog.ButtonSet.createYesNo = function() {
- return new goog.ui.Dialog.ButtonSet()
- .addButton(goog.ui.Dialog.ButtonSet.DefaultButtons.YES, true)
- .addButton(goog.ui.Dialog.ButtonSet.DefaultButtons.NO, false, true);
- };
- goog.ui.Dialog.ButtonSet.createYesNoCancel = function() {
- return new goog.ui.Dialog.ButtonSet()
- .addButton(goog.ui.Dialog.ButtonSet.DefaultButtons.YES)
- .addButton(goog.ui.Dialog.ButtonSet.DefaultButtons.NO, true)
- .addButton(goog.ui.Dialog.ButtonSet.DefaultButtons.CANCEL, false, true);
- };
- goog.ui.Dialog.ButtonSet.createContinueSaveCancel = function() {
- return new goog.ui.Dialog.ButtonSet()
- .addButton(goog.ui.Dialog.ButtonSet.DefaultButtons.CONTINUE)
- .addButton(goog.ui.Dialog.ButtonSet.DefaultButtons.SAVE)
- .addButton(goog.ui.Dialog.ButtonSet.DefaultButtons.CANCEL, true, true);
- };
- (function() {
- if (typeof document != 'undefined') {
-
- goog.ui.Dialog.ButtonSet.OK = goog.ui.Dialog.ButtonSet.createOk();
-
- goog.ui.Dialog.ButtonSet.OK_CANCEL =
- goog.ui.Dialog.ButtonSet.createOkCancel();
-
- goog.ui.Dialog.ButtonSet.YES_NO = goog.ui.Dialog.ButtonSet.createYesNo();
-
- goog.ui.Dialog.ButtonSet.YES_NO_CANCEL =
- goog.ui.Dialog.ButtonSet.createYesNoCancel();
-
- goog.ui.Dialog.ButtonSet.CONTINUE_SAVE_CANCEL =
- goog.ui.Dialog.ButtonSet.createContinueSaveCancel();
- }
- })();
|