|
|
@ -7,12 +7,12 @@ |
|
|
|
/*global define, window */ |
|
|
|
/*global define, window */ |
|
|
|
((factory) => { |
|
|
|
((factory) => { |
|
|
|
window['Ply'] = factory(window); |
|
|
|
window['Ply'] = factory(window); |
|
|
|
})((window) => { |
|
|
|
})((window, Deferred) => { |
|
|
|
'use strict'; |
|
|
|
'use strict'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var gid = 1, |
|
|
|
var gid = 1, |
|
|
|
noop = (() => {}), |
|
|
|
noop = () => {}, |
|
|
|
|
|
|
|
|
|
|
|
document = window.document, |
|
|
|
document = window.document, |
|
|
|
setTimeout = window.setTimeout, |
|
|
|
setTimeout = window.setTimeout, |
|
|
@ -22,7 +22,7 @@ |
|
|
|
|| /* istanbul ignore next */ window.ender |
|
|
|
|| /* istanbul ignore next */ window.ender |
|
|
|
|| /* istanbul ignore next */ window.$, |
|
|
|
|| /* istanbul ignore next */ window.$, |
|
|
|
|
|
|
|
|
|
|
|
Promise = window.Promise, |
|
|
|
Promise = Deferred || window.Promise, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -82,9 +82,7 @@ |
|
|
|
array_push = array_core.push, |
|
|
|
array_push = array_core.push, |
|
|
|
array_splice = array_core.splice, |
|
|
|
array_splice = array_core.splice, |
|
|
|
|
|
|
|
|
|
|
|
_plyAttr = 'data-ply', |
|
|
|
_plyAttr = 'data-ply' |
|
|
|
|
|
|
|
|
|
|
|
_resolvedPromise = _promise((resolve) => resolve()) |
|
|
|
|
|
|
|
; |
|
|
|
; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -139,7 +137,6 @@ |
|
|
|
* @private |
|
|
|
* @private |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
function _promiseAll(iterable) { |
|
|
|
function _promiseAll(iterable) { |
|
|
|
// @todo: Поткрыть тестами `Promise.all` |
|
|
|
|
|
|
|
return Promise |
|
|
|
return Promise |
|
|
|
? /* istanbul ignore next */ Promise.all(iterable) |
|
|
|
? /* istanbul ignore next */ Promise.all(iterable) |
|
|
|
: $.when.apply($, iterable); |
|
|
|
: $.when.apply($, iterable); |
|
|
@ -147,18 +144,28 @@ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Выполнить действие в следующем тике |
|
|
|
* Вернуть разрешенное «Обещание» |
|
|
|
* @param {Function} fn |
|
|
|
* @param {*} [value] |
|
|
|
* @returns {Function} |
|
|
|
* @returns {Promise} |
|
|
|
* @private |
|
|
|
* @private |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
function _nextTick(fn) { |
|
|
|
function _resolvePromise(value) { |
|
|
|
return () => { |
|
|
|
return _promise((resolve) => resolve(value)); |
|
|
|
setTimeout(fn, 1); |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Привести значение к «Обещанию» |
|
|
|
|
|
|
|
* @param {*} value |
|
|
|
|
|
|
|
* @returns {Promise} |
|
|
|
|
|
|
|
* @private |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
function _cast(value) { |
|
|
|
|
|
|
|
return value && value.then ? value : _resolvePromise(value); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Object iterator |
|
|
|
* Object iterator |
|
|
|
* @param {Object|Array} obj |
|
|
|
* @param {Object|Array} obj |
|
|
@ -808,7 +815,7 @@ |
|
|
|
return _this; |
|
|
|
return _this; |
|
|
|
})); |
|
|
|
})); |
|
|
|
}; |
|
|
|
}; |
|
|
|
_this.fx.queue = _resolvedPromise; |
|
|
|
_this.fx.queue = _resolvePromise(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Клик по затемнению |
|
|
|
// Клик по затемнению |
|
|
@ -839,8 +846,8 @@ |
|
|
|
if (!this.hasFlag('bodyScroll')) { |
|
|
|
if (!this.hasFlag('bodyScroll')) { |
|
|
|
var bodyEl = this.bodyEl, |
|
|
|
var bodyEl = this.bodyEl, |
|
|
|
dummyEl = _buildDOM({ |
|
|
|
dummyEl = _buildDOM({ |
|
|
|
css: { overflow: 'scroll', visibility: 'hidden' }, |
|
|
|
css: { overflow: 'auto', visibility: 'hidden', height: '5px' }, |
|
|
|
children: [{ tag: 'div' }] |
|
|
|
children: [{ tag: 'div', css: { height: '100px' } }] |
|
|
|
}) |
|
|
|
}) |
|
|
|
; |
|
|
|
; |
|
|
|
|
|
|
|
|
|
|
@ -933,16 +940,22 @@ |
|
|
|
* @param {String} name прчина закрытия |
|
|
|
* @param {String} name прчина закрытия |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
closeBy: function (name) { |
|
|
|
closeBy: function (name) { |
|
|
|
var result = this.options.callback({ |
|
|
|
var ui = { |
|
|
|
by: name, |
|
|
|
by: name, |
|
|
|
state: name === 'submit', |
|
|
|
state: name === 'submit', |
|
|
|
layer: this, |
|
|
|
layer: this, |
|
|
|
context: this.context |
|
|
|
data: this.context.toJSON(), |
|
|
|
}); |
|
|
|
context: this.context |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
result = this.options.callback(ui) |
|
|
|
|
|
|
|
; |
|
|
|
|
|
|
|
|
|
|
|
if (result !== false) { |
|
|
|
_cast(result).then((result) => { |
|
|
|
this.close(); |
|
|
|
if (result !== false) { |
|
|
|
} |
|
|
|
this.result = ui; |
|
|
|
|
|
|
|
this.close(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -1062,7 +1075,9 @@ |
|
|
|
} else if (prevLayer = Ply.stack.last) { |
|
|
|
} else if (prevLayer = Ply.stack.last) { |
|
|
|
// Слой мог быть скрыт, нужно вернуть его |
|
|
|
// Слой мог быть скрыт, нужно вернуть его |
|
|
|
_appendChild(prevLayer.wrapEl, prevLayer.layerEl); |
|
|
|
_appendChild(prevLayer.wrapEl, prevLayer.layerEl); |
|
|
|
prevLayer.hasFlag('hideLayerInStack') && prevLayer.applyEffect('open.layer', effect); |
|
|
|
prevLayer.hasFlag('hideLayerInStack') && prevLayer.applyEffect('open.layer', effect).then(() => { |
|
|
|
|
|
|
|
_autoFocus(prevLayer.el); // todo: нужен метод layer.autoFocus(); |
|
|
|
|
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Применяем основные эффекты |
|
|
|
// Применяем основные эффекты |
|
|
@ -1074,6 +1089,7 @@ |
|
|
|
_removeElement(_this.wrapEl); |
|
|
|
_removeElement(_this.wrapEl); |
|
|
|
_appendChild(_this.overlayEl, _this.overlayBoxEl); |
|
|
|
_appendChild(_this.overlayEl, _this.overlayBoxEl); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// «Событие» open или close |
|
|
|
_this.options[mode](_this); |
|
|
|
_this.options[mode](_this); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
@ -1090,6 +1106,7 @@ |
|
|
|
* @returns {Promise} |
|
|
|
* @returns {Promise} |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
open: function (effect) { |
|
|
|
open: function (effect) { |
|
|
|
|
|
|
|
this.result = null; |
|
|
|
return this._toggleState(true, effect); |
|
|
|
return this._toggleState(true, effect); |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
@ -1423,7 +1440,7 @@ |
|
|
|
; |
|
|
|
; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (effects && (effect = effects[name[1]]) && (fx = Ply.effects[effect.name])) { // layer/overlay |
|
|
|
if (support.transition && effects && (effect = effects[name[1]]) && (fx = Ply.effects[effect.name])) { |
|
|
|
if (fx['to'] || fx['from']) { |
|
|
|
if (fx['to'] || fx['from']) { |
|
|
|
// Клонируем |
|
|
|
// Клонируем |
|
|
|
fx = _deepClone(fx); |
|
|
|
fx = _deepClone(fx); |
|
|
@ -1463,17 +1480,15 @@ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Ждем завершения анимации |
|
|
|
// Ждем завершения анимации |
|
|
|
setTimeout(resolve, support.transition && effect.duration); |
|
|
|
setTimeout(resolve, effect.duration); |
|
|
|
}).then(_nextTick(() => { |
|
|
|
}).then(() => { |
|
|
|
// Возвращаем стили, именно на "then" с разрывом, т.к. «Обещания» могу быть ассинхронными |
|
|
|
|
|
|
|
el.setAttribute('style', oldStyle[0]); |
|
|
|
el.setAttribute('style', oldStyle[0]); |
|
|
|
firstEl && firstEl.setAttribute('style', oldStyle[1]); |
|
|
|
firstEl && firstEl.setAttribute('style', oldStyle[1]); |
|
|
|
return el; |
|
|
|
}); |
|
|
|
})); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return _resolvedPromise; |
|
|
|
return _resolvePromise(); |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -1625,6 +1640,10 @@ |
|
|
|
* @param {HTMLElement} el |
|
|
|
* @param {HTMLElement} el |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
function Context(el) { |
|
|
|
function Context(el) { |
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Корневой элемент |
|
|
|
|
|
|
|
* @type {HTMLElement} |
|
|
|
|
|
|
|
*/ |
|
|
|
this.el = el; |
|
|
|
this.el = el; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -1639,12 +1658,7 @@ |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
getEl: function (name) { |
|
|
|
getEl: function (name) { |
|
|
|
if (this.el) { |
|
|
|
if (this.el) { |
|
|
|
var items = _getElementsByTagName(this.el, '*'), i = items.length; |
|
|
|
return _querySelector('[' + _plyAttr + '-name="' + name + '"]', this.el); |
|
|
|
while (i--) { |
|
|
|
|
|
|
|
if (items[i].getAttribute(_plyAttr + '-name') === name) { |
|
|
|
|
|
|
|
return items[i]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
@ -1656,7 +1670,7 @@ |
|
|
|
* @returns {String} |
|
|
|
* @returns {String} |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
val: function (name, value) { |
|
|
|
val: function (name, value) { |
|
|
|
var el = this.getEl(name); |
|
|
|
var el = typeof name === 'string' ? this.getEl(name) : name; |
|
|
|
|
|
|
|
|
|
|
|
if (el && (el.value == null)) { |
|
|
|
if (el && (el.value == null)) { |
|
|
|
el = _getElementsByTagName(el, 'input')[0] |
|
|
|
el = _getElementsByTagName(el, 'input')[0] |
|
|
@ -1670,6 +1684,24 @@ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return el && el.value || ""; |
|
|
|
return el && el.value || ""; |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Получить JSON |
|
|
|
|
|
|
|
* @returns {Object} |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
toJSON: function () { |
|
|
|
|
|
|
|
var items = this.el.querySelectorAll('[' + _plyAttr + '-name]'), |
|
|
|
|
|
|
|
json = {}, |
|
|
|
|
|
|
|
el, |
|
|
|
|
|
|
|
i = items.length |
|
|
|
|
|
|
|
; |
|
|
|
|
|
|
|
while (i--) { |
|
|
|
|
|
|
|
el = items[i]; |
|
|
|
|
|
|
|
json[el.getAttribute(_plyAttr + '-name')] = this.val(el); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return json; |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|