From ca3ad6305ec0655ad8475a12ac2228b61cdd9ba0 Mon Sep 17 00:00:00 2001 From: Lionel LASKE Date: Sat, 25 Aug 2012 20:23:36 +0000 Subject: Init commit --- (limited to 'html/lib/onyx/source/Popup.js') diff --git a/html/lib/onyx/source/Popup.js b/html/lib/onyx/source/Popup.js new file mode 100644 index 0000000..105431a --- /dev/null +++ b/html/lib/onyx/source/Popup.js @@ -0,0 +1,87 @@ +/** + An enhanced popup with built-in scrim and z-index handling. To avoid + obscuring popup contents, scrims require the dialog to be floating; + otherwise, they won't render. Modal popups get a transparent scrim by + default, unless the modal popup isn't floating. To get a translucent scrim + when modal, specify _scrim: true, scrimWhenModal: false_. +*/ +enyo.kind({ + name: "onyx.Popup", + kind: "Popup", + classes: "onyx-popup", + published: { + /** + Determines whether a scrim will appear when the dialog is modal. + Note that modal scrims are transparent, so you won't see them. + */ + scrimWhenModal: true, + //* Determines whether or not to display a scrim. Only displays scrims + //* when floating. + scrim: false, + /** + Optional class name to apply to the scrim. Be aware that the scrim + is a singleton and you will be modifying the scrim instance used for + other popups. + */ + scrimClassName: "" + }, + //* @protected + statics: { count: 0 }, + defaultZ: 120, + showingChanged: function() { + if(this.showing) { + onyx.Popup.count++; + this.applyZIndex(); + } + else { + if(onyx.Popup.count > 0) { + onyx.Popup.count--; + } + } + this.showHideScrim(this.showing); + this.inherited(arguments); + }, + showHideScrim: function(inShow) { + if (this.floating && (this.scrim || (this.modal && this.scrimWhenModal))) { + var scrim = this.getScrim(); + if (inShow) { + // move scrim to just under the popup to obscure rest of screen + var i = this.getScrimZIndex(); + this._scrimZ = i; + scrim.showAtZIndex(i); + } else { + scrim.hideAtZIndex(this._scrimZ); + } + enyo.call(scrim, "addRemoveClass", [this.scrimClassName, scrim.showing]); + } + }, + getScrimZIndex: function() { + // Position scrim directly below popup + return this.findZIndex()-1; + }, + getScrim: function() { + // show a transparent scrim for modal popups if scrimWhenModal is true + // if scrim is true, then show a regular scrim. + if (this.modal && this.scrimWhenModal && !this.scrim) { + return onyx.scrimTransparent.make(); + } + return onyx.scrim.make(); + }, + applyZIndex: function() { + // Adjust the zIndex so that popups will properly stack on each other. + this._zIndex = onyx.Popup.count * 2 + this.findZIndex() + 1; + // leave room for scrim + this.applyStyle("z-index", this._zIndex); + }, + findZIndex: function() { + // a default z value + var z = this.defaultZ; + if (this._zIndex) { + z = this._zIndex; + } else if (this.hasNode()) { + // Re-use existing zIndex if it has one + z = Number(enyo.dom.getComputedStyleValue(this.node, "z-index")) || z; + } + return (this._zIndex = z); + } +}); \ No newline at end of file -- cgit v0.9.1