Files
aritmija/public/admin/plugins/tmce/bootstrap/js/jquery.htmlClean.min.js
2026-05-13 17:11:09 +02:00

1 line
9.4 KiB
JavaScript

!function(t){function e(t,e,n,a){if(t.tag.format&&n.length>0){n.push("\n");for(var r=0;a>r;r++)n.push(" ")}}function n(a,r){var i=[],s=0===a.attributes.length,l=0;if(a.tag.isComment)r.allowComments&&(i.push("<!--"),i.push(a.tag.rawAttributes),i.push(">"),r.format&&e(a,r,i,l-1));else{var h=0===r.removeTagsAndContent.length||-1==t.inArray(a.tag.name,r.removeTagsAndContent),d=h&&a.tag.render&&(0===r.allowedTags.length||t.inArray(a.tag.name,r.allowedTags)>-1)&&(0===r.removeTags.length||-1==t.inArray(a.tag.name,r.removeTags));if(!a.isRoot&&d&&(i.push("<"),i.push(a.tag.name),t.each(a.attributes,function(){if(-1==t.inArray(this.name,r.removeAttrs)){var e=RegExp(/^(['"]?)(.*?)['"]?$/).exec(this.value),n=e[2],s=e[1]||"'";"class"==this.name&&r.allowedClasses.length>0&&(n=t.grep(n.split(" "),function(e){return t.grep(r.allowedClasses,function(n){return n==e||n[0]==e&&(1==n.length||t.inArray(a.tag.name,n[1])>-1)}).length>0}).join(" ")),null!==n&&(n.length>0||t.inArray(this.name,a.tag.requiredAttributes)>-1)&&(i.push(" "),i.push(this.name),i.push("="),i.push(s),i.push(n),i.push(s))}})),a.tag.isSelfClosing)d&&i.push(" />"),s=!1;else if(a.tag.isNonClosing)s=!1;else if(h){!a.isRoot&&d&&i.push(">"),l=r.formatIndent++;var p=[];if(a.tag.toProtect)p=t.htmlClean.trim(a.children.join("")).replace(/<br>/gi,"\n"),i.push(p),s=0===p.length;else{p=[];for(var f=0;f<a.children.length;f++){var b=a.children[f],y=t.htmlClean.trim(g(u(b)?b:b.childrenToString()));m(b)&&f>0&&y.length>0&&(o(b)||c(a.children[f-1]))&&p.push(" "),u(b)?y.length>0&&p.push(y):(f!==a.children.length-1||"br"!==b.tag.name||r.allowBreakAsLastChild&&"br"===b.tag.name)&&(r.format&&e(b,r,p,l),p=p.concat(n(b,r)))}r.formatIndent--,p.length>0&&(r.format&&"\n"!=p[0]&&e(a,r,i,l),i=i.concat(p),s=!1)}!a.isRoot&&d&&(r.format&&e(a,r,i,l-1),i.push("</"),i.push(a.tag.name),i.push(">"))}if(!a.tag.allowEmpty&&s)return[]}return i}function a(e,n){return i(e,function(e){return t.inArray(e.tag.nameOriginal,n)>-1})}function r(t){return i(t,function(t){return t.isRoot||!t.tag.isInline})}function i(t,e,n){n=n||1;var a=t[t.length-n];return e(a)?!0:t.length-n>0&&i(t,e,n+1)?(t.pop(),!0):!1}function s(t){return t?(this.tag=t,this.isRoot=!1):(this.tag=new h("root"),this.isRoot=!0),this.attributes=[],this.children=[],this.hasAttribute=function(t){for(var e=0;e<this.attributes.length;e++)if(this.attributes[e].name==t)return!0;return!1},this.childrenToString=function(){return this.children.join("")},this}function l(t,e){return this.name=t,this.value=e,this}function h(e,n,a,r){return this.name=e.toLowerCase(),this.nameOriginal=this.name,this.render=!0,this.init=function(){if("--"==this.name?(this.isComment=!0,this.isSelfClosing=!0,this.format=!0):(this.isComment=!1,this.isSelfClosing=t.inArray(this.name,w)>-1,this.isNonClosing=t.inArray(this.name,v)>-1,this.isClosing=void 0!==n&&n.length>0,this.isInline=t.inArray(this.name,p)>-1,this.disallowNest=t.inArray(this.name,b)>-1,this.requiredParent=A[t.inArray(this.name,A)+1],this.allowEmpty=r&&t.inArray(this.name,r.allowEmpty)>-1,this.toProtect=t.inArray(this.name,C)>-1,this.format=t.inArray(this.name,f)>-1||!this.isInline),this.rawAttributes=a,this.requiredAttributes=k[t.inArray(this.name,k)+1],r){if(r.tagAttributesCache||(r.tagAttributesCache=[]),-1==t.inArray(this.name,r.tagAttributesCache)){for(var e=x[t.inArray(this.name,x)+1].slice(0),i=0;i<r.allowedAttributes.length;i++){var s=r.allowedAttributes[i][0];(1==r.allowedAttributes[i].length||t.inArray(this.name,r.allowedAttributes[i][1])>-1)&&-1==t.inArray(s,e)&&e.push(s)}r.tagAttributesCache.push(this.name),r.tagAttributesCache.push(e)}this.allowedAttributes=r.tagAttributesCache[t.inArray(this.name,r.tagAttributesCache)+1]}},this.init(),this.rename=function(t){this.name=t,this.init()},this}function o(e){for(;d(e)&&e.children.length>0;)e=e.children[0];if(!u(e))return!1;var n=g(e);return n.length>0&&t.htmlClean.isWhitespace(n.charAt(0))}function c(e){for(;d(e)&&e.children.length>0;)e=e.children[e.children.length-1];if(!u(e))return!1;var n=g(e);return n.length>0&&t.htmlClean.isWhitespace(n.charAt(n.length-1))}function u(t){return t.constructor==String}function m(t){return u(t)||t.tag.isInline}function d(t){return t.constructor==s}function g(t){return t.replace(/&nbsp;|\n/g," ").replace(/\s\s+/g," ")}t.fn.htmlClean=function(e){return this.each(function(){this.value?this.value=t.htmlClean(this.value,e):this.innerHTML=t.htmlClean(this.innerHTML,e)})},t.htmlClean=function(e,i){i=t.extend({},t.htmlClean.defaults,i),i.allowEmpty=y.concat(i.allowEmpty);var o,c=/(<(\/)?(\w+:)?([\w]+)([^>]*)>)|<!--(.*?--)>/gi,m=/([\w\-]+)\s*=\s*(".*?"|'.*?'|[^\s>\/]*)/gi,d=new s,g=[d],p=d;i.bodyOnly&&null!==(o=/<body[^>]*>((\n|.)*)<\/body>/i.exec(e))&&(e=o[1]),e=e.concat("<xxx>");for(var f;null!==(o=c.exec(e));){var b=o[6]?new h("--",null,o[6],i):new h(o[4],o[2],o[5],i),A=e.substring(f,o.index);if(A.length>0){var C=p.children[p.children.length-1];p.children.length>0&&u(C=p.children[p.children.length-1])?p.children[p.children.length-1]=C.concat(A):p.children.push(A)}if(f=c.lastIndex,b.isClosing)a(g,[b.name])&&(g.pop(),p=g[g.length-1]);else{for(var w,v=new s(b);null!==(w=m.exec(b.rawAttributes));){if("style"==w[1].toLowerCase()&&i.replaceStyles)for(var x=!b.isInline,k=0;k<i.replaceStyles.length;k++)i.replaceStyles[k][0].test(w[2])&&(x||(b.render=!1,x=!0),p.children.push(v),g.push(v),p=v,b=new h(i.replaceStyles[k][1],"","",i),v=new s(b));null!==b.allowedAttributes&&(0===b.allowedAttributes.length||t.inArray(w[1],b.allowedAttributes)>-1)&&v.attributes.push(new l(w[1],w[2]))}for(var I=0;I<b.requiredAttributes.length;I++){var S=b.requiredAttributes[I];v.hasAttribute(S)||v.attributes.push(new l(S,""))}for(var T=0;T<i.replace.length;T++)for(var q=0;q<i.replace[T][0].length;q++){var E="string"==typeof i.replace[T][0][q];if(E&&i.replace[T][0][q]==b.name||!E&&i.replace[T][0][q].test(o)){b.rename(i.replace[T][1]),T=i.replace.length;break}}var R=!0;if(p.isRoot||(p.tag.isInline&&!b.isInline?(R=r(g))&&(p=g[g.length-1]):p.tag.disallowNest&&b.disallowNest&&!b.requiredParent?R=!1:b.requiredParent&&(R=a(g,b.requiredParent))&&(p=g[g.length-1])),R)if(p.children.push(v),b.toProtect)for(var j;null!==(j=c.exec(e));){var P=new h(j[4],j[1],j[5],i);if(P.isClosing&&P.name==b.name){v.children.push(RegExp.leftContext.substring(f)),f=c.lastIndex;break}}else b.isSelfClosing||b.isNonClosing||(g.push(v),p=v)}}return t.htmlClean.trim(n(d,i).join(""))},t.htmlClean.defaults={bodyOnly:!0,allowedTags:[],removeTags:["basefont","center","dir","font","frame","frameset","iframe","isindex","menu","noframes","s","strike","u"],removeTagsAndContent:[],allowedAttributes:[],removeAttrs:[],allowedClasses:[],format:!1,formatIndent:0,replace:[[["b","big"],"strong"],[["i"],"em"]],replaceStyles:[[/font-weight:\s*bold/i,"strong"],[/font-style:\s*italic/i,"em"],[/vertical-align:\s*super/i,"sup"],[/vertical-align:\s*sub/i,"sub"]],allowComments:!1,allowEmpty:[],allowBreakAsLastChild:!1},t.htmlClean.trim=function(e){return t.htmlClean.trimStart(t.htmlClean.trimEnd(e))},t.htmlClean.trimStart=function(e){return e.substring(t.htmlClean.trimStartIndex(e))},t.htmlClean.trimStartIndex=function(e){for(var n=0;n<e.length-1&&t.htmlClean.isWhitespace(e.charAt(n));n++);return n},t.htmlClean.trimEnd=function(e){return e.substring(0,t.htmlClean.trimEndIndex(e))},t.htmlClean.trimEndIndex=function(e){for(var n=e.length-1;n>=0&&t.htmlClean.isWhitespace(e.charAt(n));n--);return n+1},t.htmlClean.isWhitespace=function(e){return-1!=t.inArray(e,I)};var p=["a","abbr","acronym","address","b","big","br","button","caption","cite","code","del","em","font","hr","i","input","img","ins","label","legend","map","q","s","samp","select","option","param","small","span","strike","strong","sub","sup","tt","u","var"],f=["address","button","caption","code","input","label","legend","select","option","param"],b=["h1","h2","h3","h4","h5","h6","p","th","td","object"],y=["th","td"],A=[null,"li",["ul","ol"],"dt",["dl"],"dd",["dl"],"td",["tr"],"th",["tr"],"tr",["table","thead","tbody","tfoot"],"thead",["table"],"tbody",["table"],"tfoot",["table"],"param",["object"]],C=["script","style","pre","code"],w=["area","base","br","col","command","embed","hr","img","input","keygen","link","meta","param","source","track","wbr"],v=["!doctype","?xml"],x=[["class"],"?xml",[],"!doctype",[],"a",["accesskey","class","href","name","title","rel","rev","type","tabindex"],"abbr",["class","title"],"acronym",["class","title"],"blockquote",["cite","class"],"button",["class","disabled","name","type","value"],"del",["cite","class","datetime"],"form",["accept","action","class","enctype","method","name"],"iframe",["class","height","name","sandbox","seamless","src","srcdoc","width"],"input",["accept","accesskey","alt","checked","class","disabled","ismap","maxlength","name","size","readonly","src","tabindex","type","usemap","value"],"img",["alt","class","height","src","width"],"ins",["cite","class","datetime"],"label",["accesskey","class","for"],"legend",["accesskey","class"],"link",["href","rel","type"],"meta",["content","http-equiv","name","scheme","charset"],"map",["name"],"optgroup",["class","disabled","label"],"option",["class","disabled","label","selected","value"],"q",["class","cite"],"script",["src","type"],"select",["class","disabled","multiple","name","size","tabindex"],"style",["type"],"table",["class","summary"],"th",["class","colspan","rowspan"],"td",["class","colspan","rowspan"],"textarea",["accesskey","class","cols","disabled","name","readonly","rows","tabindex"],"param",["name","value"],"embed",["height","src","type","width"]],k=[[],"img",["alt"]],I=[" "," "," ","\n","\r","\f"]}(jQuery);