mirror of
https://github.com/WordPress/WordPress.git
synced 2024-11-09 04:11:10 +01:00
852d90b3d6
git-svn-id: http://core.svn.wordpress.org/trunk@22763 1a063a9b-81f0-0310-95a4-ce76da25c4cd
1 line
6.1 KiB
JavaScript
1 line
6.1 KiB
JavaScript
var wpActiveEditor;function send_to_editor(c){var b,a=typeof(tinymce)!="undefined",f=typeof(QTags)!="undefined";if(!wpActiveEditor){if(a&&tinymce.activeEditor){b=tinymce.activeEditor;wpActiveEditor=b.id}else{if(!f){return false}}}else{if(a){if(tinymce.activeEditor&&(tinymce.activeEditor.id=="mce_fullscreen"||tinymce.activeEditor.id=="wp_mce_fullscreen")){b=tinymce.activeEditor}else{b=tinymce.get(wpActiveEditor)}}}if(b&&!b.isHidden()){if(tinymce.isIE&&b.windowManager.insertimagebookmark){b.selection.moveToBookmark(b.windowManager.insertimagebookmark)}if(c.indexOf("[caption")===0){if(b.wpSetImgCaption){c=b.wpSetImgCaption(c)}}else{if(c.indexOf("[gallery")===0){if(b.plugins.wpgallery){c=b.plugins.wpgallery._do_gallery(c)}}else{if(c.indexOf("[embed")===0){if(b.plugins.wordpress){c=b.plugins.wordpress._setEmbed(c)}}}}b.execCommand("mceInsertContent",false,c)}else{if(f){QTags.insertContent(c)}else{document.getElementById(wpActiveEditor).value+=c}}try{tb_remove()}catch(d){}}var tb_position;(function(a){tb_position=function(){var f=a("#TB_window"),e=a(window).width(),d=a(window).height(),c=(720<e)?720:e,b=0;if(a("body.admin-bar").length){b=28}if(f.size()){f.width(c-50).height(d-45-b);a("#TB_iframeContent").width(c-50).height(d-75-b);f.css({"margin-left":"-"+parseInt(((c-50)/2),10)+"px"});if(typeof document.body.style.maxWidth!="undefined"){f.css({top:20+b+"px","margin-top":"0"})}}return a("a.thickbox").each(function(){var g=a(this).attr("href");if(!g){return}g=g.replace(/&width=[0-9]+/g,"");g=g.replace(/&height=[0-9]+/g,"");a(this).attr("href",g+"&width="+(c-80)+"&height="+(d-85-b))})};a(window).resize(function(){tb_position()});a(document).ready(function(b){b("a.thickbox").click(function(){var c;if(typeof(tinymce)!="undefined"&&tinymce.isIE&&(c=tinymce.get(wpActiveEditor))&&!c.isHidden()){c.focus();c.windowManager.insertimagebookmark=c.selection.getBookmark()}})})})(jQuery);(function(b){var a={},c;c=function(e,g){var f=e.link||getUserSetting("urlbutton","post"),d;if("file"===f){d=g.url}else{if("post"===f){d=g.link}else{if("custom"===f){d=e.linkUrl}}}return d||""};wp.media.string={link:function(e,f){var d;e=_.defaults(e||{},{title:"",linkUrl:""});if(f){_.extend(e,{title:f.title||f.filename,linkUrl:c(e,f),rel:"attachment wp-att-"+f.id})}d={tag:"a",content:e.title,attrs:{href:e.linkUrl}};if(e.rel){d.attrs.rel=e.rel}return wp.html.string(d)},image:function(i,h){var d=[],f={},l,j,k,e,g;i=_.defaults(i||{},{align:getUserSetting("align","none"),size:getUserSetting("imgsize","medium"),url:""});if(h){d.push("wp-image-"+h.id);j=h.sizes;k=j&&j[i.size]?j[i.size]:h;_.extend(i,_.pick(h,"align","caption"),{width:k.width,height:k.height,src:k.url,linkUrl:c(i,h),captionId:"attachment_"+h.id})}f.src=i.url;_.extend(f,_.pick(i,"width","height","alt"));if(i.align&&!i.caption){d.push("align"+i.align)}if(i.size){d.push("size-"+i.size)}f["class"]=_.compact(d).join(" ");l={tag:"img",attrs:f,single:true};if(i.linkUrl){l={tag:"a",attrs:{href:i.linkUrl},content:l}}g=wp.html.string(l);if(i.caption){e={};if(f.width){e.width=f.width}if(i.captionId){e.id=i.captionId}if(i.align){e.align="align"+i.align}g=wp.shortcode.string({tag:"caption",attrs:e,content:g+" "+i.caption})}return g}};wp.media.gallery=(function(){var d={};return{defaults:{order:"ASC",id:wp.media.view.settings.postId,itemtag:"dl",icontag:"dt",captiontag:"dd",columns:3,size:"thumbnail"},attachments:function(i){var k=i.string(),e=d[k],g,f,j,h;delete d[k];if(e){return e}g=i.attrs.named;f=_.pick(g,"orderby","order");f.type="image";f.perPage=-1;if(g.ids){f.post__in=g.ids.split(",");f.orderby="post__in"}else{if(g.include){f.post__in=g.include.split(",")}}if(g.exclude){f.post__not_in=g.exclude.split(",")}if(!f.post__in){f.parent=g.id}h={};_.filter(g,function(m,l){if(_.isUndefined(f[l])){h[l]=m}});j=media.query(f);j.gallery=new Backbone.Model(h);return j},shortcode:function(e){var g=e.props.toJSON(),f=_.pick(g,"include","exclude","orderby","order"),h,i;if(e.gallery){_.extend(f,e.gallery.toJSON())}f.ids=e.pluck("id");if(f.ids&&"post__in"===f.orderby){delete f.orderby}_.each(wp.media.gallery.defaults,function(k,j){if(k===f[j]){delete f[j]}});h=new wp.shortcode({tag:"gallery",attrs:f,type:"single"});i=new wp.media.model.Attachments(e.models,{props:g});i.gallery=e.gallery;d[h.string()]=i;return h},edit:function(h){var g=wp.shortcode.next("gallery",h),i=wp.media.gallery.defaults.id,e,f;if(!g||g.content!==h){return}g=g.shortcode;if(_.isUndefined(g.get("id"))&&!_.isUndefined(i)){g.set("id",i)}e=wp.media.gallery.attachments(g);f=new wp.media.model.Selection(e.models,{props:e.props.toJSON(),multiple:true});f.gallery=e.gallery;f.more().done(function(){f.props.set({query:false});f.unmirror();f.props.unset("orderby")});return wp.media({frame:"post",state:"gallery-edit",title:wp.media.view.l10n.editGalleryTitle,editing:true,multiple:true,selection:f})}}}());wp.media.editor={insert:send_to_editor,add:function(f,d){var e=this.get(f);if(e){return e}e=a[f]=wp.media(_.defaults(d||{},{frame:"post",title:wp.media.view.l10n.insertMedia,multiple:true}));e.on("insert",function(h){var i=e.state(),g=i.get("details");h=h||i.get("selection");if(!h||!g){return}h.each(function(k){var j=g[k.cid];if(j){j=j.toJSON()}delete g[k.cid];k=k.toJSON();if(!wp.media.view.settings.captions){delete k.caption}if("image"===k.type){this.insert(wp.media.string.image(j,k)+" ")}else{this.insert(wp.media.string.link(j,k)+" ")}},this)},this);e.get("gallery-edit").on("update",function(g){this.insert(wp.media.gallery.shortcode(g).string())},this);e.get("embed").on("select",function(){var g=e.state().toJSON();g.url=g.url||"";if("link"===g.type){_.defaults(g,{title:g.url,linkUrl:g.url});this.insert(wp.media.string.link(g))}else{if("image"===g.type){_.defaults(g,{title:g.url,linkUrl:"",align:"none",link:"none"});if("none"===g.link){g.linkUrl=""}else{if("file"===g.link){g.linkUrl=g.url}}this.insert(wp.media.string.image(g))}}},this);return e},get:function(d){return a[d]},remove:function(d){delete a[d]},init:function(){b(document.body).on("click",".insert-media",function(e){var f=b(this),d=f.data("editor"),g;e.preventDefault();f.blur();if(!_.isString(d)){return}g=wp.media.editor.get(d);if(g){g.open();return}wp.media.editor.add(d)})}};b(wp.media.editor.init)}(jQuery)); |