Skip to content

Instantly share code, notes, and snippets.

@radmike
Created July 9, 2016 00:40
Show Gist options
  • Save radmike/182445657a47d9a99de1d2fce7287c9e to your computer and use it in GitHub Desktop.
Save radmike/182445657a47d9a99de1d2fce7287c9e to your computer and use it in GitHub Desktop.
Sightly Helpers for ACS AEM Commons Touch UI Multifields
"use strict";
/**
* Multifield Helper JS Use-api script (for json-based multifield storage)
*
* @see http://j.mp/29ByR1y [touchui-composite-multifield.js]
*
* @param mfName node name containing the multifield
*/
use(["/libs/wcm/foundation/components/utils/AuthoringUtils.js"], function (AuthoringUtils) {
var parsed = { items: [] }, toParse;
try {
if (this.mfName) {
toParse = properties[this.mfName];
toParse.forEach(function (item) {
var itemParsed = JSON.parse(item);
parsed.items.push(itemParsed);
});
}
}
catch (e) {
console.error("ERROR: " + e);
}
return parsed;
});
"use strict";
/**
* Multifield Helper JS Use-api script (for node-based multifield storage)
*
* @see http://j.mp/29BqSBQ [touchui-composite-multifield-nodestore.js]
*
* @param mfName node name containing the multifield (if empty grabs first child node)
*/
use(["/libs/wcm/foundation/components/utils/AuthoringUtils.js"], function (AuthoringUtils) {
var mf = {};
try {
if (this.mfName) {
var childnode = resource.getChild(this.mfName);
if (childnode) {
mf.items = childnode.getChildren();
}
}
else {
var childnodes = resource.getChildren();
if (childnodes && childnodes.length > 0) {
mf.items = childnodes[0].getChildren();
}
}
}
catch (e) {
console.error("ERROR: " + e);
}
return mf;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment