1 line
1.8 KiB
JavaScript
1 line
1.8 KiB
JavaScript
if(typeof wp==="undefined"){var wp={}}(function(){wp.shortcode={next:function(b,f,d){var e=wp.shortcode.regexp(b),c,a;e.lastIndex=d||0;c=e.exec(f);if(!c){return}if(c[1]==="["&&c[6]==="]"){return wp.shortcode.next(b,f,e.lastIndex)}a={index:c.index,content:c[0],shortcode:new wp.shortcode.Match(c)};if(c[1]){a.match=a.match.slice(1);a.index++}if(c[6]){a.match=a.match.slice(0,-1)}return a},replace:function(a,b,c){return b.replace(wp.shortcode.regexp(a),function(g,d,l,j,e,h,i,f){if(d==="["&&i==="]"){return g}var k=c(new wp.shortcode.Match(arguments));return k?d+k+i:g})},regexp:_.memoize(function(a){return new RegExp("\\[(\\[?)("+a+")\\b([^\\]\\/]*(?:\\/(?!\\])[^\\]\\/]*)*?)(?:(\\/)\\]|\\](?:([^\\[]*(?:\\[(?!\\/\\2\\])[^\\[]*)*)\\[\\/\\2\\])?)(\\]?)","g")}),attrs:_.memoize(function(e){var a={},c=[],d,b;d=/(\w+)\s*=\s*"([^"]*)"(?:\s|$)|(\w+)\s*=\s*\'([^\']*)\'(?:\s|$)|(\w+)\s*=\s*([^\s\'"]+)(?:\s|$)|"([^"]*)"(?:\s|$)|(\S+)(?:\s|$)/g;e=e.replace(/[\u00a0\u200b]/g," ");while((b=d.exec(e))){if(b[1]){a[b[1].toLowerCase()]=b[2]}else{if(b[3]){a[b[3].toLowerCase()]=b[4]}else{if(b[5]){a[b[5].toLowerCase()]=b[6]}else{if(b[7]){c.push(b[7])}else{if(b[8]){c.push(b[8])}}}}}}return{named:a,numeric:c}})};wp.shortcode.Match=function(a){this.tag=a[2];this.attrs=wp.shortcode.attrs(a[3]);this.single=!!a[4];this.content=a[5]};_.extend(wp.shortcode.Match.prototype,{get:function(a){return this.attrs[_.isNumber(a)?"numeric":"named"][a]},set:function(a,b){this.attrs[_.isNumber(a)?"numeric":"named"][a]=b;return this},text:function(){var a="["+this.tag;_.each(this.attrs.numeric,function(b){if(/\s/.test(b)){a+=' "'+b+'"'}else{a+=" "+b}});_.each(this.attrs.named,function(c,b){a+=" "+b+'="'+c+'"'});if(this.single){return a+" /]"}a+="]";if(this.content){a+=this.content}return a+"[/"+this.tag+"]"}})}()); |