mirror of
https://github.com/WordPress/WordPress.git
synced 2024-11-18 00:25:37 +01:00
06d16327f5
git-svn-id: http://core.svn.wordpress.org/trunk@22128 1a063a9b-81f0-0310-95a4-ce76da25c4cd
1 line
2.2 KiB
JavaScript
1 line
2.2 KiB
JavaScript
window.wp=window.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[7]==="]"){return wp.shortcode.next(b,f,e.lastIndex)}a={index:c.index,content:c[0],shortcode:wp.shortcode.fromMatch(c)};if(c[1]){a.match=a.match.slice(1);a.index++}if(c[7]){a.match=a.match.slice(0,-1)}return a},replace:function(a,b,c){return b.replace(wp.shortcode.regexp(a),function(h,d,m,k,g,i,e,j,f){if(d==="["&&j==="]"){return h}var l=c(wp.shortcode.fromMatch(arguments));return l?d+l+j:h})},string:function(a){return new wp.shortcode(a).string()},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}}),fromMatch:function(a){var b;if(a[4]){b="self-closing"}else{if(a[6]){b="closed"}else{b="single"}}return new wp.shortcode({tag:a[2],attrs:a[3],type:b,content:a[5]})}};wp.shortcode=_.extend(function(b){_.extend(this,_.pick(b||{},"tag","attrs","type","content"));var a=this.attrs;this.attrs={named:{},numeric:[]};if(!a){return}if(_.isString(a)){this.attrs=wp.shortcode.attrs(a)}else{if(_.isEqual(_.keys(a),["named","numeric"])){this.attrs=a}else{_.each(b.attrs,function(d,c){this.set(c,d)},this)}}},wp.shortcode);_.extend(wp.shortcode.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},string: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("single"===this.type){return a+"]"}else{if("self-closing"===this.type){return a+" /]"}}a+="]";if(this.content){a+=this.content}return a+"[/"+this.tag+"]"}})}()); |