Skip to content

Instantly share code, notes, and snippets.

@ericf
Created October 2, 2009 17:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ericf/199914 to your computer and use it in GitHub Desktop.
Save ericf/199914 to your computer and use it in GitHub Desktop.
/**
* Overlay Modal Extension
*
* Oddnut Software
* Copyright (c) 2009 Eric Ferraiuolo - http://eric.ferraiuolo.name
* MIT License - http://www.opensource.org/licenses/mit-license.php
*/
var Modal,
OVERLAY = 'overlay',
BOUNDING_BOX = 'boundingBox',
MODAL = 'modal',
MASK = 'mask',
MASKED = 'masked',
isBoolean = Y.Lang.isBoolean,
getClassName = Y.ClassNameManager.getClassName;
// *** Constructor *** //
Modal = function (config) {
Y.after(this._renderUIModal, this, 'renderUI');
Y.after(this._bindUIModal, this, 'bindUI');
Y.after(this._syncUIModal, this, 'syncUI');
};
// *** Static *** //
Modal.MODAL_CLASS_NAME = getClassName(OVERLAY, MODAL);
Modal.MASK_CLASS_NAME = getClassName(OVERLAY, MASK);
Modal.MASKED_CLASS_NAME = getClassName(OVERLAY, MASKED);
Modal.ATTRS = {
modal : {
value : true,
validator : isBoolean
},
mask : {
value : false,
validator : isBoolean
}
};
// *** Prototype *** //
Modal.prototype = {
// *** Instance Members *** //
_modalNode : null,
// *** Public Methods *** //
modal : function (v) {
this.set(MODAL, v);
},
mask : function (v) {
this.set(MASK, v);
},
// *** Private Methods *** //
_renderUIModal : function () {
this._modalNode = Y.Node.create('<div></div>');
this._modalNode.addClass(Modal.MASK_CLASS_NAME);
this._modalNode.setStyles({
position : 'fixed',
width : '100%',
height : '100%',
top : '0',
left : '0',
zIndex : '-1'
});
},
_bindUIModal : function () {
this.after('modalChange', Y.bind(this._afterModalChange, this));
this.after('maskChange', Y.bind(this._afterMaskChange, this));
},
_syncUIModal : function () {
this._uiSetModal(this.get(MODAL));
this._uiSetMask(this.get(MASK));
},
_afterModalChange : function (e) {
this._uiSetModal(e.newVal);
},
_afterMaskChange : function (e) {
this._uiSetMask(e.newVal);
},
_uiSetModal : function (isModal) {
var boundingBox = this.get(BOUNDING_BOX),
modalNode = this._modalNode,
modalClass = Modal.MODAL_CLASS_NAME;
if (isModal) {
boundingBox.addClass(modalClass).prepend(modalNode);
} else {
boundingBox.removeClass(modalClass).removeChild(modalNode);
}
},
_uiSetMask : function (hasMask) {
var modalNode = this._modalNode,
maskedClass = Modal.MASKED_CLASS_NAME;
if (hasMask) {
modalNode.addClass(maskedClass);
} else {
modalNode.removeClass(maskedClass);
}
}
};
Y.OverlayModal = Modal;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment