X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/1fee1a1755e0b9ce88e1f9df5016f44b9982f368..1f2f8117ae10eaebde925989e1b3710c8cc47323:/modules/documentCanvas/classAttributes.js?ds=sidebyside diff --git a/modules/documentCanvas/classAttributes.js b/modules/documentCanvas/classAttributes.js new file mode 100644 index 0000000..fe7409a --- /dev/null +++ b/modules/documentCanvas/classAttributes.js @@ -0,0 +1,64 @@ +define([], function() { + +'use strict'; + +var wlxmlDict = { + 'uri': { + 'uri': 'string' + } +}; + +var hasMetaAttr = function(klass, attrName, dict) { + dict = dict || wlxmlDict; + if(!klass) + return false; + + var parts = klass.split('-'); + var partialClass = ''; + for(var i = 0; i < parts.length; i++) { + partialClass += (partialClass === '' ? '' : '-') + parts[i]; + if(dict[partialClass] && dict[partialClass][attrName]) + return true; + } + return false; +}; + +var getMetaAttrsList = function(klass, dict) { + dict = dict || wlxmlDict; + klass = klass || ''; + + var toret = {own: [], inheritedFrom: {}, all: []}; + var parts = klass.split('-'); + var partialClass = ''; + + var generate = function(klass) { + var toret = [], + desc = dict[klass]; + + if(!desc) + return toret; + + _.keys(desc).forEach(function(key) { + toret.push({name: key, type: desc[key]}); + }); + return toret; + }; + + toret.own = generate(klass); + for(var i = 0; i < parts.length; i++) { + partialClass += (partialClass === '' ? '' : '-') + parts[i]; + var list = generate(partialClass); + if(list.length > 0) { + toret.inheritedFrom[partialClass] = generate(partialClass); + toret.all = toret.all.concat(toret.inheritedFrom[partialClass]); + } + } + return toret; +}; + +return { + hasMetaAttr: hasMetaAttr, + getMetaAttrsList: getMetaAttrsList +}; + +}); \ No newline at end of file