kute.js/dist/kute-attr.min.js

2 lines
1.3 KiB
JavaScript

// Attributes Plugin for KUTE.js | dnp_theme | MIT License
(function(b){if("function"===typeof define&&define.amd)define(["./kute.js"],function(a){b(a);return a});else if("object"==typeof module&&"function"==typeof require){var a=require("./kute.js");module.exports=b(a)}else if("undefined"!==typeof window.KUTE)b(a);else throw Error("Attributes Plugin require KUTE.js.");})(function(b){var a=window.KUTE,h=a.dom;b=a.pp;var m=a.Interpolate.unit,n=a.Interpolate.number,g,p=function(a,d){return a.getAttribute(d)},k=function(a){return/[A-Z]/g.test(a)?a.replace(a.match(/[A-Z]/g)[0],"-"+a.match(/[A-Z]/g)[0].toLowerCase()):a};a.prS.attr=function(a,d,b){d={};for(var c in b){b=k(c).replace(/_+[a-z]+/,"");var e=a.getAttribute(b);d[b]=e||(/opacity/i.test(c)?1:0)}return d};b.attr=function(b,d,q){"attr"in h||(h.attr=function(a,b,c,d,e){for(var f in d)h.attributes[f](a,f,c[f],d[f],e)},g=h.attributes={});b={};for(var c in d){var e=k(c),e=p(q,e.replace(/_+[a-z]+/,""));if(/(%|[a-z]+)$/.test(d[c])||/(%|[a-z]+)$/.test(e)){var e=a.truD(e).u||a.truD(d[c]).u,l=/%/.test(e)?"_percent":"_"+e;c+l in g||(g[c+l]=function(a,b,c,d,e){var f=f||k(b).replace(l,"");a.setAttribute(f,m(c.v,d.v,d.u,e))});b[c+l]=a.truD(d[c])}else c in g||(g[c]=function(a,b,c,d,e){var f=f||k(b);a.setAttribute(f,n(c,d,e))}),b[c]=parseFloat(d[c])}return b}});