Browse Source

* closeByOverlay

modules
RubaXa 11 years ago
parent
commit
e4578d3405
  1. 41
      src/Ply.es6

41
src/Ply.es6

@ -577,7 +577,7 @@
transform: 'translate3d(0, 0, 0)' transform: 'translate3d(0, 0, 0)'
}, },
children: options.baseHtml ? [{ children: options.baseHtml ? [{
ply: 'layer', ply: ':layer',
tag: '.ply-layer', tag: '.ply-layer',
className: options.mod, className: options.mod,
css: _extend({ css: _extend({
@ -605,21 +605,16 @@
* @private * @private
*/ */
function _createOverlay(style) { function _createOverlay(style) {
var el = _buildDOM(); return _buildDOM({
ply: ':overlay',
if (style) { css: _extend({
_css(el, style);
_css(el, {
top: 0, top: 0,
left: 0, left: 0,
right: 0, right: 0,
bottom: 0, bottom: 0,
position: 'fixed' position: 'fixed'
}); }, style)
el.setAttribute(_plyAttr, 'overlay'); });
}
return el;
} }
@ -811,10 +806,6 @@
_removeElement(dummyEl); _removeElement(dummyEl);
} }
if (this.hasFlag('closeByOverlay')) {
_addEvent(this.overlayEl, 'click', this._getHandleEvent('overlay'));
}
_addEvent(this.wrapEl, 'submit', this._getHandleEvent('submit')); _addEvent(this.wrapEl, 'submit', this._getHandleEvent('submit'));
}, },
@ -829,7 +820,6 @@
} }
_removeEvent(this.layerEl, 'submit', this._getHandleEvent('submit')); _removeEvent(this.layerEl, 'submit', this._getHandleEvent('submit'));
_removeEvent(this.overlayEl, 'click', this._getHandleEvent('overlay'));
}, },
@ -840,7 +830,9 @@
* @private * @private
*/ */
_getHandleEvent: function (name) { _getHandleEvent: function (name) {
var _this = this, handleEvent = _this.__handleEvent || (_this.__handleEvent = {}); var _this = this,
handleEvent = _this.__handleEvent || (_this.__handleEvent = {})
;
if (!handleEvent[name]) { if (!handleEvent[name]) {
handleEvent[name] = (evt) => { handleEvent[name] = (evt) => {
@ -908,10 +900,10 @@
if (!handle) { if (!handle) {
handle = target; handle = target;
target = 'layer'; target = ':layer';
} }
handle['_' + target] = ((evt) => { handle['_' + target] = (evt) => {
var el = evt.target; var el = evt.target;
do { do {
if (el.nodeType === 1) { if (el.nodeType === 1) {
@ -921,7 +913,7 @@
} }
} }
while ((el !== _this.wrapEl) && (el = el.parentNode)); while ((el !== _this.wrapEl) && (el = el.parentNode));
}); };
_addEvent(_this.wrapEl, event, handle['_' + target]); _addEvent(_this.wrapEl, event, handle['_' + target]);
return _this; return _this;
@ -1170,6 +1162,9 @@
if (evt.keyCode === keys.esc && layer.hasFlag('closeByEsc')) { if (evt.keyCode === keys.esc && layer.hasFlag('closeByEsc')) {
layer.closeBy('esc'); layer.closeBy('esc');
} }
else if (layer.hasFlag('closeByOverlay') && evt.target.getAttribute(_plyAttr) === ':overlay') {
layer.closeBy('overlay');
}
}, },
@ -1181,7 +1176,7 @@
var idx = array_push.call(this, layer); var idx = array_push.call(this, layer);
if (this.last) { if (this.last) {
_css(layer.overlayEl, 'visibility', 'hidden'); // _css(layer.overlayEl, 'visibility', 'hidden');
_css(this.last.layerEl, 'display', 'none'); _css(this.last.layerEl, 'display', 'none');
} }
@ -1189,6 +1184,7 @@
this._idx[layer.cid] = idx - 1; this._idx[layer.cid] = idx - 1;
if (idx === 1) { if (idx === 1) {
_addEvent(document, 'click', this._pop);
_addEvent(document, 'keyup', this._pop); _addEvent(document, 'keyup', this._pop);
} }
}, },
@ -1208,9 +1204,10 @@
this.last = this[this.length-1]; this.last = this[this.length-1];
if (this.last) { if (this.last) {
_css(layer.overlayEl, 'visibility', ''); // _css(layer.overlayEl, 'visibility', '');
_css(this.last.layerEl, 'display', 'inline-block'); _css(this.last.layerEl, 'display', 'inline-block');
} else { } else {
_removeEvent(document, 'click', this._pop);
_removeEvent(document, 'keyup', this._pop); _removeEvent(document, 'keyup', this._pop);
} }
} }

Loading…
Cancel
Save