@ampify/aquery
Advanced tools
Comparing version 1.2.2 to 1.2.4
{ | ||
"name": "@ampify/aquery", | ||
"version": "1.2.2", | ||
"version": "1.2.4", | ||
"main": "./dist/aquery.js", | ||
@@ -37,3 +37,3 @@ "module": "./src", | ||
}, | ||
"gitHead": "9501ae5e9a2ab73216d003368c4e210e96694f14" | ||
"gitHead": "c7bf8c99371eaad4eddb3eca16f64298b1fd9362" | ||
} |
@@ -360,4 +360,4 @@ import jQuery from 'jquery'; | ||
class aQueryActions { | ||
constructor(nodes, parent) { | ||
this.parent = parent; | ||
constructor(nodes, aQueryEventParent) { | ||
this.aQueryEventParent = aQueryEventParent; | ||
this.nodes = nodes; | ||
@@ -371,3 +371,27 @@ | ||
return this; | ||
this.proxy = new Proxy(this, { | ||
get(target, prop) { | ||
if (target[prop]) { | ||
return target[prop]; | ||
} else if (jQuery.fn[prop]) { | ||
return (...args) => { | ||
args = args.map((arg) => | ||
arg.__proto__.constructor.name == 'aQueryActions' | ||
? arg.nodes | ||
: arg, | ||
); | ||
const ret = jQuery(target.nodes)[prop](...args); | ||
if (ret instanceof jQuery) { | ||
return new aQueryActions(ret.toArray()); | ||
} | ||
return ret; | ||
}; | ||
} | ||
}, | ||
}); | ||
return this.proxy; | ||
} | ||
@@ -391,2 +415,5 @@ | ||
for (const node of this.nodes) { | ||
//if node is hidden we need to show and and hide it again using hidden attribute | ||
if (!node.offsetParent) { jQuery(node).show().attr('hidden', ''); } | ||
arrActions.push(`${genId(node)}.show()`); | ||
@@ -516,3 +543,3 @@ } | ||
open(url, target = '_top') { | ||
const eventSource = this.parent.nodes[0].matches('select') | ||
const eventSource = this.aQueryEventParent.nodes[0].matches('select') | ||
? 'select' | ||
@@ -522,3 +549,3 @@ : 'node'; | ||
if (eventSource === 'select') { | ||
for (const { options } of this.parent.nodes) { | ||
for (const { options } of this.aQueryEventParent.nodes) { | ||
for (const opt of options) { | ||
@@ -540,32 +567,7 @@ if (opt.getAttribute('value')) { | ||
} | ||
//DOM | ||
next() { | ||
for (const [i, node] of this.nodes.entries()) { | ||
this.nodes[i] = node.nextElementSibling; | ||
} | ||
return this; | ||
} | ||
parentNode() { | ||
for (const [i, node] of this.nodes.entries()) { | ||
this.nodes[i] = node.parentNode; | ||
} | ||
return this; | ||
} | ||
first() { | ||
for (const [i, node] of this.nodes.entries()) { | ||
this.nodes[i] = node.firstElementChild; | ||
} | ||
return this; | ||
} | ||
} | ||
class aQueryScrollActions { | ||
constructor(nodes, parent) { | ||
this.parent = parent; | ||
constructor(nodes, aQueryEventParent) { | ||
this.aQueryEventParent = aQueryEventParent; | ||
this.nodes = nodes; | ||
@@ -724,5 +726,4 @@ | ||
aQuery.cssIgnore = (...ignoreList) => { | ||
//#TODO - support ids (make class default) | ||
if (ignoreList.length) { | ||
return ignoreList.forEach((ignore) => cssIgnore.add(`.${ignore}`)); | ||
return ignoreList.forEach((ignore) => cssIgnore.add(`${ignore}`)); | ||
} | ||
@@ -729,0 +730,0 @@ |
const defaults = { | ||
'submit-error': {color: '#F44336'}, | ||
'submit-success': {color: '#009688'}, | ||
'submitting': {color: '#607D8B'} | ||
'submit-error': { color: '#F44336' }, | ||
'submit-success': { color: '#009688' }, | ||
'submitting': { color: '#607D8B' }, | ||
}; | ||
@@ -12,8 +12,16 @@ | ||
div.setAttribute(messageId, ''); | ||
div.innerHTML = `<template type="amp-mustache"><p style="padding: 1.5rem; direction: ltr; color: ${color}; clear: both;">${message}</p></template>`; | ||
div.innerHTML = ` | ||
<template type="amp-mustache"> | ||
${/^\</.test(message) ? message : `<span style="color: ${color}; clear: both;">${message}</span>`} | ||
</template> | ||
`; | ||
form.appendChild(div); | ||
} | ||
}; | ||
const createForm = ({ form, url, success, error, submit }, $) => { | ||
const createForm = ({ form, url, success, error, submit, fields = [] }, $) => { | ||
for (const { name, value } of fields) { | ||
$(`<input type="hidden" name="${name}" value="${value}" />`).appendTo(form); | ||
} | ||
if (url) { | ||
@@ -28,3 +36,3 @@ form.setAttribute('action', url); | ||
if (error) { | ||
addMessage(form, 'submit-success', error); | ||
addMessage(form, 'submit-error', error); | ||
} | ||
@@ -37,2 +45,2 @@ | ||
export default createForm; | ||
export default createForm; |
44133
1355