-
+ 47CADD6A894FAEB63BDD94BD77BFCB25108E2E172D95A068944E5F9C3D4589F0016398ECD5B669590584E78BF7FA83F6F119C7EB9044AECDDB92558DA71415A6
mp-wp/wp-includes/js/tinymce/plugins/wpeditimage/editor_plugin.js
(0 . 0)(1 . 236)
125570
125571 (function() {
125572 tinymce.create('tinymce.plugins.wpEditImage', {
125573
125574 init : function(ed, url) {
125575 var t = this;
125576
125577 t.url = url;
125578 t._createButtons();
125579
125580 // Register the command so that it can be invoked by using tinyMCE.activeEditor.execCommand('...');
125581 ed.addCommand('WP_EditImage', function() {
125582 var el = ed.selection.getNode(), vp = tinymce.DOM.getViewPort(), H = vp.h, W = ( 720 < vp.w ) ? 720 : vp.w;
125583 var cls = ed.dom.getAttrib(el, 'class');
125584
125585 if ( cls.indexOf('mceItem') != -1 || cls.indexOf('wpGallery') != -1 || el.nodeName != 'IMG' )
125586 return;
125587
125588 tb_show('', url + '/editimage.html?ver=321&TB_iframe=true');
125589 tinymce.DOM.setStyles('TB_window', {
125590 'width':( W - 50 )+'px',
125591 'height':( H - 45 )+'px',
125592 'margin-left':'-'+parseInt((( W - 50 ) / 2),10) + 'px'
125593 });
125594
125595 if ( ! tinymce.isIE6 ) {
125596 tinymce.DOM.setStyles('TB_window', {
125597 'top':'20px',
125598 'marginTop':'0'
125599 });
125600 }
125601
125602 tinymce.DOM.setStyles('TB_iframeContent', {
125603 'width':( W - 50 )+'px',
125604 'height':( H - 75 )+'px'
125605 });
125606 tinymce.DOM.setStyle( ['TB_overlay','TB_window','TB_load'], 'z-index', '999999' );
125607 });
125608
125609 ed.onInit.add(function(ed) {
125610 tinymce.dom.Event.add(ed.getWin(), 'scroll', function(e) {
125611 ed.plugins.wpeditimage.hideButtons();
125612 });
125613 });
125614
125615 ed.onBeforeExecCommand.add(function(ed, cmd, ui, val) {
125616 ed.plugins.wpeditimage.hideButtons();
125617 });
125618
125619 ed.onSaveContent.add(function(ed, o) {
125620 ed.plugins.wpeditimage.hideButtons();
125621 });
125622
125623 ed.onMouseUp.add(function(ed, e) {
125624 if ( tinymce.isOpera ) {
125625 if ( e.target.nodeName == 'IMG' )
125626 ed.plugins.wpeditimage.showButtons(e.target);
125627 } else if ( ! tinymce.isWebKit ) {
125628 var n = ed.selection.getNode(), DL;
125629
125630 if ( n.nodeName == 'IMG' && (DL = ed.dom.getParent(n, 'DL')) ) {
125631 window.setTimeout(function(){
125632 var ed = tinyMCE.activeEditor, n = ed.selection.getNode(), DL = ed.dom.getParent(n, 'DL');
125633
125634 if ( n.width != (parseInt(ed.dom.getStyle(DL, 'width')) - 10) ) {
125635 ed.dom.setStyle(DL, 'width', parseInt(n.width)+10);
125636 ed.execCommand('mceRepaint');
125637 }
125638 }, 100);
125639 }
125640 }
125641 });
125642
125643 ed.onMouseDown.add(function(ed, e) {
125644 if ( tinymce.isOpera || e.target.nodeName != 'IMG' ) {
125645 t.hideButtons();
125646 return;
125647 }
125648 ed.plugins.wpeditimage.showButtons(e.target);
125649 });
125650
125651 ed.onKeyPress.add(function(ed, e) {
125652 var DL, DIV;
125653
125654 if ( e.keyCode == 13 && (DL = ed.dom.getParent(ed.selection.getNode(), 'DL')) ) {
125655 var P = ed.dom.create('p', {}, ' ');
125656 if ( (DIV = DL.parentNode) && DIV.nodeName == 'DIV' )
125657 ed.dom.insertAfter( P, DIV );
125658 else ed.dom.insertAfter( P, DL );
125659
125660 tinymce.dom.Event.cancel(e);
125661 ed.selection.select(P);
125662 return false;
125663 }
125664 });
125665
125666 ed.onBeforeSetContent.add(function(ed, o) {
125667 o.content = t._do_shcode(o.content);
125668 });
125669
125670 ed.onPostProcess.add(function(ed, o) {
125671 if (o.get)
125672 o.content = t._get_shcode(o.content);
125673 });
125674 },
125675
125676 _do_shcode : function(co) {
125677 return co.replace(/\[(?:wp_)?caption([^\]]+)\]([\s\S]+?)\[\/(?:wp_)?caption\][\s\u00a0]*/g, function(a,b,c){
125678 b = b.replace(/\\'|\\'|\\'/g, ''').replace(/\\"|\\"/g, '"');
125679 c = c.replace(/\\'|\\'/g, ''').replace(/\\"/g, '"');
125680 var id = b.match(/id=['"]([^'"]+)/i), cls = b.match(/align=['"]([^'"]+)/i);
125681 var w = b.match(/width=['"]([0-9]+)/), cap = b.match(/caption=['"]([^'"]+)/i);
125682
125683 id = ( id && id[1] ) ? id[1] : '';
125684 cls = ( cls && cls[1] ) ? cls[1] : 'alignnone';
125685 w = ( w && w[1] ) ? w[1] : '';
125686 cap = ( cap && cap[1] ) ? cap[1] : '';
125687 if ( ! w || ! cap ) return c;
125688
125689 var div_cls = (cls == 'aligncenter') ? 'mceTemp mceIEcenter' : 'mceTemp';
125690
125691 return '<div class="'+div_cls+'"><dl id="'+id+'" class="wp-caption '+cls+'" style="width: '+(10+parseInt(w))+
125692 'px"><dt class="wp-caption-dt">'+c+'</dt><dd class="wp-caption-dd">'+cap+'</dd></dl></div>';
125693 });
125694 },
125695
125696 _get_shcode : function(co) {
125697 return co.replace(/<div class="mceTemp[^"]*">\s*<dl([^>]+)>\s*<dt[^>]+>([\s\S]+?)<\/dt>\s*<dd[^>]+>(.+?)<\/dd>\s*<\/dl>\s*<\/div>\s*/gi, function(a,b,c,cap){
125698 var id = b.match(/id=['"]([^'"]+)/i), cls = b.match(/class=['"]([^'"]+)/i);
125699 var w = c.match(/width=['"]([0-9]+)/);
125700
125701 id = ( id && id[1] ) ? id[1] : '';
125702 cls = ( cls && cls[1] ) ? cls[1] : 'alignnone';
125703 w = ( w && w[1] ) ? w[1] : '';
125704
125705 if ( ! w || ! cap ) return c;
125706 cls = cls.match(/align[^ '"]+/) || 'alignnone';
125707 cap = cap.replace(/<\S[^<>]*>/gi, '').replace(/'/g, ''').replace(/"/g, '"');
125708
125709 return '[caption id="'+id+'" align="'+cls+'" width="'+w+'" caption="'+cap+'"]'+c+'[/caption]';
125710 });
125711 },
125712
125713 showButtons : function(n) {
125714 var t = this, ed = tinyMCE.activeEditor, p1, p2, vp, DOM = tinymce.DOM, X, Y;
125715 var cls = ed.dom.getAttrib(n, 'class');
125716
125717 if ( cls.indexOf('mceItem') != -1 || cls.indexOf('wpGallery') != -1 )
125718 return;
125719
125720 vp = ed.dom.getViewPort(ed.getWin());
125721 p1 = DOM.getPos(ed.getContentAreaContainer());
125722 p2 = ed.dom.getPos(n);
125723
125724 X = Math.max(p2.x - vp.x, 0) + p1.x;
125725 Y = Math.max(p2.y - vp.y, 0) + p1.y;
125726
125727 DOM.setStyles('wp_editbtns', {
125728 'top' : Y+5+'px',
125729 'left' : X+5+'px',
125730 'display' : 'block'
125731 });
125732
125733 t.btnsTout = window.setTimeout( function(){ed.plugins.wpeditimage.hideButtons();}, 5000 );
125734 },
125735
125736 hideButtons : function() {
125737 if ( tinymce.DOM.isHidden('wp_editbtns') ) return;
125738
125739 tinymce.DOM.hide('wp_editbtns');
125740 window.clearTimeout(this.btnsTout);
125741 },
125742
125743 _createButtons : function() {
125744 var t = this, ed = tinyMCE.activeEditor, DOM = tinymce.DOM;
125745
125746 DOM.remove('wp_editbtns');
125747
125748 var wp_editbtns = DOM.add(document.body, 'div', {
125749 id : 'wp_editbtns',
125750 style : 'display:none;'
125751 });
125752
125753 var wp_editimgbtn = DOM.add('wp_editbtns', 'img', {
125754 src : t.url+'/img/image.png',
125755 id : 'wp_editimgbtn',
125756 width : '24',
125757 height : '24',
125758 title : ed.getLang('wpeditimage.edit_img')
125759 });
125760
125761 wp_editimgbtn.onmousedown = function(e) {
125762 var ed = tinyMCE.activeEditor;
125763 ed.windowManager.bookmark = ed.selection.getBookmark('simple');
125764 ed.execCommand("WP_EditImage");
125765 this.parentNode.style.display = 'none';
125766 };
125767
125768 var wp_delimgbtn = DOM.add('wp_editbtns', 'img', {
125769 src : t.url+'/img/delete.png',
125770 id : 'wp_delimgbtn',
125771 width : '24',
125772 height : '24',
125773 title : ed.getLang('wpeditimage.del_img')
125774 });
125775
125776 wp_delimgbtn.onmousedown = function(e) {
125777 var ed = tinyMCE.activeEditor, el = ed.selection.getNode(), p;
125778
125779 if ( el.nodeName == 'IMG' && ed.dom.getAttrib(el, 'class').indexOf('mceItem') == -1 ) {
125780 if ( (p = ed.dom.getParent(el, 'div')) && ed.dom.hasClass(p, 'mceTemp') )
125781 ed.dom.remove(p);
125782 else if ( (p = ed.dom.getParent(el, 'A')) && p.childNodes.length == 1 )
125783 ed.dom.remove(p);
125784 else ed.dom.remove(el);
125785
125786 this.parentNode.style.display = 'none';
125787 ed.execCommand('mceRepaint');
125788 return false;
125789 }
125790 };
125791 },
125792
125793 getInfo : function() {
125794 return {
125795 longname : 'Edit Image',
125796 author : 'WordPress',
125797 authorurl : 'http://wordpress.org',
125798 infourl : '',
125799 version : "1.0"
125800 };
125801 }
125802 });
125803
125804 tinymce.PluginManager.add('wpeditimage', tinymce.plugins.wpEditImage);
125805 })();