Browse Source

+ clone & rootTag option

master
RubaXa 10 years ago
parent
commit
fd2cfe9b00
  1. 1
      Gruntfile.js
  2. 4
      Ply.min.js
  3. 1
      README.md
  4. 2
      package.json
  5. 10
      src/Ply.es6
  6. 7
      src/defaults.es6
  7. 8
      src/effects.preset.es6
  8. 24
      src/ui.es6
  9. 2
      tests/Ply.effects.tests.js
  10. 11
      tests/Ply.ui.tests.js
  11. 4
      tests/index.html

1
Gruntfile.js

@ -100,5 +100,6 @@ module.exports = function (grunt){
grunt.registerTask('es', ['export', 'es6transpiler']); grunt.registerTask('es', ['export', 'es6transpiler']);
grunt.registerTask('build', ['es', 'qunit']); grunt.registerTask('build', ['es', 'qunit']);
grunt.registerTask('min', ['uglify']); grunt.registerTask('min', ['uglify']);
grunt.registerTask('quick', ['es', 'min']);
grunt.registerTask('default', ['version', 'build', 'min']); grunt.registerTask('default', ['version', 'build', 'min']);
}; };

4
Ply.min.js vendored

File diff suppressed because one or more lines are too long

1
README.md

@ -394,6 +394,7 @@ Ply.dialog("subscribe", {
## Changelog ## Changelog
##### 0.5.0
* Added `ply-loading` * Added `ply-loading`
* `ui.layer` -> `ui.widget` * `ui.layer` -> `ui.widget`
* Added a `on` prefix to all callbacks * Added a `on` prefix to all callbacks

2
package.json

@ -1,7 +1,7 @@
{ {
"name": "ply", "name": "ply",
"exportName": "Ply", "exportName": "Ply",
"version": "0.5.0", "version": "0.6.0",
"devDependencies": { "devDependencies": {
"grunt": "*", "grunt": "*",
"grunt-contrib-watch": "*", "grunt-contrib-watch": "*",

10
src/Ply.es6

@ -167,8 +167,10 @@
function _createPly(target, options, onlyLayer) { function _createPly(target, options, onlyLayer) {
// Корневой слой // Корневой слой
target.wrapEl = _buildDOM({ target.wrapEl = _buildDOM({
tag: 'form', tag: options.rootTag,
css: { whiteSpace: 'nowrap', zIndex: options.zIndex } css: { whiteSpace: 'nowrap', zIndex: options.zIndex },
method: 'post',
action: '/'
}); });
@ -192,7 +194,7 @@
// Контент // Контент
var el = options.el; var el = options.el;
target.el = (el && el.cloneNode) ? el.cloneNode(true) : _buildDOM({ html: el || '' }); target.el = (el && el.cloneNode) ? (options.clone ? el.cloneNode(true) : el) : _buildDOM({ html: el || '' });
// Содержит контент // Содержит контент
@ -786,7 +788,7 @@
}; };
Ply.version = '0.5.0'; Ply.version = '0.6.0';
return Ply; return Ply;
}); });

7
src/defaults.es6

@ -3,7 +3,10 @@
*/ */
module.exports = { module.exports = {
clone: true,
zIndex: 10000, zIndex: 10000,
rootTag: 'form',
baseHtml: true,
layer: {}, // css layer: {}, // css
@ -21,9 +24,7 @@ module.exports = {
visibleOverlayInStack: false visibleOverlayInStack: false
}, },
baseHtml: true, // Callbacks
// Callback's
oninit: noop, oninit: noop,
onopen: noop, onopen: noop,
onclose: noop, onclose: noop,

8
src/effects.preset.es6

@ -112,8 +112,8 @@ module.exports = {
}, },
'3d-flip-in': { '3d-flip-in': {
'from': (el, args) => { 'from': (el, deg) => {
Ply.effects.rotate3d(el, 0, 'Y', args || -70); Ply.effects.rotate3d(el, 0, 'Y', deg || -70);
}, },
'to': (el) => { 'to': (el) => {
_css(el.firstChild, { opacity: 1, transform: 'rotateY(0)' }); _css(el.firstChild, { opacity: 1, transform: 'rotateY(0)' });
@ -124,8 +124,8 @@ module.exports = {
'from': (el) => { 'from': (el) => {
Ply.effects.rotate3d(el, 1, 'Y', 0); Ply.effects.rotate3d(el, 1, 'Y', 0);
}, },
'to': (el, args) => { 'to': (el, deg) => {
_css(el.firstChild, { opacity: 0, transform: 'rotateY(' + (args || 70) + 'deg)' }); _css(el.firstChild, { opacity: 0, transform: 'rotateY(' + (deg || 70) + 'deg)' });
} }
}, },

24
src/ui.es6

@ -6,6 +6,9 @@
;;;(Ply => { ;;;(Ply => {
'use strict'; 'use strict';
function _isNode(el) {
return el && el.appendChild;
}
function _toBlock(block, name) { function _toBlock(block, name) {
if (block == null) { if (block == null) {
@ -63,14 +66,15 @@
*/ */
ui.factory = function (name, renderer, simpleMode) { ui.factory = function (name, renderer, simpleMode) {
ui[name.replace(/^\s+|\s+$/g, '').replace(/\s+/g, ' ')] = function (data, path) { ui[name.replace(/^\s+|\s+$/g, '').replace(/\s+/g, ' ')] = function (data, path) {
var fragment = document.createDocumentFragment(); var fragment = document.createDocumentFragment(), result;
if ((data != null) || name === ':root') { if ((data != null) || name === ':root') {
data = simpleMode ? data : _toBlock(data); data = simpleMode ? data : _toBlock(data);
_each(simpleMode ? data : data.children, function (block, key) { _each(simpleMode ? data : data.children, function (block, key) {
var abs = ((path || name) + ' ' + key).replace(/^:\w+\s+/, ''); var abs = ((path || name) + ' ' + key).replace(/^:\w+\s+/, ''),
var el = ui(abs, _toBlock(block, key), abs); el = _isNode(block) ? block : ui(abs, _toBlock(block, key), abs)
;
_appendChild(fragment, el); _appendChild(fragment, el);
}); });
@ -79,10 +83,10 @@
delete data.children; delete data.children;
} }
var result = renderer(data, fragment); result = renderer(data, fragment);
/* istanbul ignore else */ /* istanbul ignore else */
if (!result.appendChild) { if (!_isNode(result)) {
_extend(result, data); _extend(result, data);
} }
@ -164,7 +168,7 @@
renderer(options, data, resolve, reject); renderer(options, data, resolve, reject);
}).then((el) => { }).then((el) => {
/* istanbul ignore else */ /* istanbul ignore else */
if (!el.appendChild) { if (!_isNode(el)) {
el = ui(':root', el); el = ui(':root', el);
} }
@ -271,6 +275,10 @@
* @returns {Promise} * @returns {Promise}
*/ */
Ply.create = (name, options, data) => { Ply.create = (name, options, data) => {
if (_isNode(name)) {
return _resolvePromise(new Ply(_extend(options || {}, { el: name })));
}
if (!data) { if (!data) {
data = options; data = options;
options = {}; options = {};
@ -305,7 +313,7 @@
* @returns {Promise} * @returns {Promise}
*/ */
Ply.dialog = (name, options, data) => { Ply.dialog = (name, options, data) => {
if (name instanceof Object) { if ((name instanceof Object) && !_isNode(name)) {
options = options || /* istanbul ignore next */ {}; options = options || /* istanbul ignore next */ {};
return _promise((resolve, reject) => { return _promise((resolve, reject) => {
@ -396,7 +404,7 @@
}); });
} }
else { else {
if (!data) { if (!data && !_isNode(name)) {
data = options || {}; data = options || {};
options = {}; options = {};
} }

2
tests/Ply.effects.tests.js

@ -130,7 +130,7 @@
}); });
test('effects:args', function () { test('effects[args]:duration', function () {
Ply.effects.defaults = { duration: 300, open: {}, close: {} }; Ply.effects.defaults = { duration: 300, open: {}, close: {} };
deepEqual(Ply.effects.get('scale[0.5,0.3]'), { deepEqual(Ply.effects.get('scale[0.5,0.3]'), {

11
tests/Ply.ui.tests.js

@ -1,6 +1,17 @@
(function (Ply) { (function (Ply) {
module('Ply.ui'); module('Ply.ui');
asyncTest('dialog(el)', function () {
setTimeout(function () {
var el = Ply.stack.last.wrapEl;
el.getElementsByTagName('button')[0].click();
}, 50);
Ply.dialog(document.getElementById('dialog-el'), { clone: false, rootTag: 'div' }).always(function (ui) {
equal(ui.state, true);
start();
});
});
asyncTest('dialog("unknown")', function () { asyncTest('dialog("unknown")', function () {
setTimeout(function () { setTimeout(function () {

4
tests/index.html

@ -119,6 +119,10 @@
<h2 id="qunit-userAgent"></h2> <h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol> <ol id="qunit-tests"></ol>
<div id="playground"></div> <div id="playground"></div>
<form id="dialog-el">
<input name="foo"/>
<button data-ply=":ok">bar</button>
</form>
<!-- lib:css --> <!-- lib:css -->

Loading…
Cancel
Save