-
+ 5A009E860A521D0FCBC87E11CDAF5577446F69F25EACEA842A09E9C97C6519E11016BDB04D61358FF1FB0A4D6FA47946336613044133FA9F0FD48D7C2CD2DEE9
mp-wp/wp-includes/js/tinymce/plugins/wordpress/editor_plugin.js
(0 . 0)(1 . 298)
124438 /**
124439 * WordPress plugin.
124440 */
124441
124442 (function() {
124443 var DOM = tinymce.DOM;
124444
124445 // Load plugin specific language pack
124446 tinymce.PluginManager.requireLangPack('wordpress');
124447
124448 tinymce.create('tinymce.plugins.WordPress', {
124449 init : function(ed, url) {
124450 var t = this, tbId = ed.getParam('wordpress_adv_toolbar', 'toolbar2');
124451 var moreHTML = '<img src="' + url + '/img/trans.gif" class="mceWPmore mceItemNoResize" title="'+ed.getLang('wordpress.wp_more_alt')+'" />';
124452 var nextpageHTML = '<img src="' + url + '/img/trans.gif" class="mceWPnextpage mceItemNoResize" title="'+ed.getLang('wordpress.wp_page_alt')+'" />';
124453
124454 if ( getUserSetting('hidetb', '0') == '1' )
124455 ed.settings.wordpress_adv_hidden = 0;
124456
124457 // Hides the specified toolbar and resizes the iframe
124458 ed.onPostRender.add(function() {
124459 if ( ed.getParam('wordpress_adv_hidden', 1) ) {
124460 DOM.hide(ed.controlManager.get(tbId).id);
124461 t._resizeIframe(ed, tbId, 28);
124462 }
124463 });
124464
124465 // Register commands
124466 ed.addCommand('WP_More', function() {
124467 ed.execCommand('mceInsertContent', 0, moreHTML);
124468 });
124469
124470 ed.addCommand('WP_Page', function() {
124471 ed.execCommand('mceInsertContent', 0, nextpageHTML);
124472 });
124473
124474 ed.addCommand('WP_Help', function() {
124475 ed.windowManager.open({
124476 url : tinymce.baseURL + '/wp-mce-help.php',
124477 width : 450,
124478 height : 420,
124479 inline : 1
124480 });
124481 });
124482
124483 ed.addCommand('WP_Adv', function() {
124484 var id = ed.controlManager.get(tbId).id, cm = ed.controlManager;
124485
124486 if (DOM.isHidden(id)) {
124487 cm.setActive('wp_adv', 1);
124488 DOM.show(id);
124489 t._resizeIframe(ed, tbId, -28);
124490 ed.settings.wordpress_adv_hidden = 0;
124491 setUserSetting('hidetb', '1');
124492 } else {
124493 cm.setActive('wp_adv', 0);
124494 DOM.hide(id);
124495 t._resizeIframe(ed, tbId, 28);
124496 ed.settings.wordpress_adv_hidden = 1;
124497 setUserSetting('hidetb', '0');
124498 }
124499 });
124500
124501 // Register buttons
124502 ed.addButton('wp_more', {
124503 title : 'wordpress.wp_more_desc',
124504 image : url + '/img/more.gif',
124505 cmd : 'WP_More'
124506 });
124507
124508 ed.addButton('wp_page', {
124509 title : 'wordpress.wp_page_desc',
124510 image : url + '/img/page.gif',
124511 cmd : 'WP_Page'
124512 });
124513
124514 ed.addButton('wp_help', {
124515 title : 'wordpress.wp_help_desc',
124516 image : url + '/img/help.gif',
124517 cmd : 'WP_Help'
124518 });
124519
124520 ed.addButton('wp_adv', {
124521 title : 'wordpress.wp_adv_desc',
124522 image : url + '/img/toolbars.gif',
124523 cmd : 'WP_Adv'
124524 });
124525
124526 // Add Media buttons
124527 ed.addButton('add_media', {
124528 title : 'wordpress.add_media',
124529 image : url + '/img/media.gif',
124530 onclick : function() {
124531 tb_show('', tinymce.DOM.get('add_media').href);
124532 tinymce.DOM.setStyle( ['TB_overlay','TB_window','TB_load'], 'z-index', '999999' );
124533 }
124534 });
124535
124536 ed.addButton('add_image', {
124537 title : 'wordpress.add_image',
124538 image : url + '/img/image.gif',
124539 onclick : function() {
124540 tb_show('', tinymce.DOM.get('add_image').href);
124541 tinymce.DOM.setStyle( ['TB_overlay','TB_window','TB_load'], 'z-index', '999999' );
124542 }
124543 });
124544
124545 ed.addButton('add_video', {
124546 title : 'wordpress.add_video',
124547 image : url + '/img/video.gif',
124548 onclick : function() {
124549 tb_show('', tinymce.DOM.get('add_video').href);
124550 tinymce.DOM.setStyle( ['TB_overlay','TB_window','TB_load'], 'z-index', '999999' );
124551 }
124552 });
124553
124554 ed.addButton('add_audio', {
124555 title : 'wordpress.add_audio',
124556 image : url + '/img/audio.gif',
124557 onclick : function() {
124558 tb_show('', tinymce.DOM.get('add_audio').href);
124559 tinymce.DOM.setStyle( ['TB_overlay','TB_window','TB_load'], 'z-index', '999999' );
124560 }
124561 });
124562
124563 // Add Media buttons to fullscreen
124564 ed.onBeforeExecCommand.add(function(ed, cmd, ui, val) {
124565 if ( 'mceFullScreen' != cmd ) return;
124566 if ( 'mce_fullscreen' != ed.id )
124567 ed.settings.theme_advanced_buttons1 += ',|,add_image,add_video,add_audio,add_media';
124568 });
124569
124570 // Add class "alignleft", "alignright" and "aligncenter" when selecting align for images.
124571 ed.addCommand('JustifyLeft', function() {
124572 var n = ed.selection.getNode();
124573
124574 if ( n.nodeName != 'IMG' )
124575 ed.editorCommands.mceJustify('JustifyLeft', 'left');
124576 else ed.plugins.wordpress.do_align(n, 'alignleft');
124577 });
124578
124579 ed.addCommand('JustifyRight', function() {
124580 var n = ed.selection.getNode();
124581
124582 if ( n.nodeName != 'IMG' )
124583 ed.editorCommands.mceJustify('JustifyRight', 'right');
124584 else ed.plugins.wordpress.do_align(n, 'alignright');
124585 });
124586
124587 ed.addCommand('JustifyCenter', function() {
124588 var n = ed.selection.getNode(), P = ed.dom.getParent(n, 'p'), DL = ed.dom.getParent(n, 'dl');
124589
124590 if ( n.nodeName == 'IMG' && ( P || DL ) )
124591 ed.plugins.wordpress.do_align(n, 'aligncenter');
124592 else ed.editorCommands.mceJustify('JustifyCenter', 'center');
124593 });
124594
124595 // Word count if script is loaded
124596 if ( 'undefined' != typeof wpWordCount ) {
124597 var last = 0;
124598 ed.onKeyUp.add(function(ed, e) {
124599 if ( e.keyCode == last ) return;
124600 if ( 13 == e.keyCode || 8 == last || 46 == last ) wpWordCount.wc( ed.getContent({format : 'raw'}) );
124601 last = e.keyCode;
124602 });
124603 };
124604
124605 // Add listeners to handle more break
124606 t._handleMoreBreak(ed, url);
124607
124608 // Add custom shortcuts
124609 ed.addShortcut('alt+shift+c', ed.getLang('justifycenter_desc'), 'JustifyCenter');
124610 ed.addShortcut('alt+shift+r', ed.getLang('justifyright_desc'), 'JustifyRight');
124611 ed.addShortcut('alt+shift+l', ed.getLang('justifyleft_desc'), 'JustifyLeft');
124612 ed.addShortcut('alt+shift+j', ed.getLang('justifyfull_desc'), 'JustifyFull');
124613 ed.addShortcut('alt+shift+q', ed.getLang('blockquote_desc'), 'mceBlockQuote');
124614 ed.addShortcut('alt+shift+u', ed.getLang('bullist_desc'), 'InsertUnorderedList');
124615 ed.addShortcut('alt+shift+o', ed.getLang('numlist_desc'), 'InsertOrderedList');
124616 ed.addShortcut('alt+shift+d', ed.getLang('striketrough_desc'), 'Strikethrough');
124617 ed.addShortcut('alt+shift+n', ed.getLang('spellchecker.desc'), 'mceSpellCheck');
124618 ed.addShortcut('alt+shift+a', ed.getLang('link_desc'), 'mceLink');
124619 ed.addShortcut('alt+shift+s', ed.getLang('unlink_desc'), 'unlink');
124620 ed.addShortcut('alt+shift+m', ed.getLang('image_desc'), 'mceImage');
124621 ed.addShortcut('alt+shift+g', ed.getLang('fullscreen.desc'), 'mceFullScreen');
124622 ed.addShortcut('alt+shift+z', ed.getLang('wp_adv_desc'), 'WP_Adv');
124623 ed.addShortcut('alt+shift+h', ed.getLang('help_desc'), 'WP_Help');
124624 ed.addShortcut('alt+shift+t', ed.getLang('wp_more_desc'), 'WP_More');
124625 ed.addShortcut('alt+shift+p', ed.getLang('wp_page_desc'), 'WP_Page');
124626
124627 if ( tinymce.isWebKit ) {
124628 ed.addShortcut('alt+shift+b', ed.getLang('bold_desc'), 'Bold');
124629 ed.addShortcut('alt+shift+i', ed.getLang('italic_desc'), 'Italic');
124630 }
124631 },
124632
124633 getInfo : function() {
124634 return {
124635 longname : 'WordPress Plugin',
124636 author : 'WordPress', // add Moxiecode?
124637 authorurl : 'http://wordpress.org',
124638 infourl : 'http://wordpress.org',
124639 version : '3.0'
124640 };
124641 },
124642
124643 // Internal functions
124644 do_align : function(n, a) {
124645 var P, DL, DIV, cls, c, ed = tinyMCE.activeEditor;
124646
124647 if ( /^(mceItemFlash|mceItemShockWave|mceItemWindowsMedia|mceItemQuickTime|mceItemRealMedia)$/.test(n.className) )
124648 return;
124649
124650 P = ed.dom.getParent(n, 'p');
124651 DL = ed.dom.getParent(n, 'dl');
124652 DIV = ed.dom.getParent(n, 'div');
124653
124654 if ( DL && DIV ) {
124655 cls = ed.dom.hasClass(DL, a) ? 'alignnone' : a;
124656 DL.className = DL.className.replace(/align[^ '"]+\s?/g, '');
124657 ed.dom.addClass(DL, cls);
124658 c = (cls == 'aligncenter') ? ed.dom.addClass(DIV, 'mceIEcenter') : ed.dom.removeClass(DIV, 'mceIEcenter');
124659 } else if ( P ) {
124660 cls = ed.dom.hasClass(n, a) ? 'alignnone' : a;
124661 n.className = n.className.replace(/align[^ '"]+\s?/g, '');
124662 ed.dom.addClass(n, cls);
124663 if ( cls == 'aligncenter' )
124664 ed.dom.setStyle(P, 'textAlign', 'center');
124665 else if (P.style && P.style.textAlign == 'center')
124666 ed.dom.setStyle(P, 'textAlign', '');
124667 }
124668
124669 ed.execCommand('mceRepaint');
124670 },
124671
124672 // Resizes the iframe by a relative height value
124673 _resizeIframe : function(ed, tb_id, dy) {
124674 var ifr = ed.getContentAreaContainer().firstChild;
124675
124676 DOM.setStyle(ifr, 'height', ifr.clientHeight + dy); // Resize iframe
124677 ed.theme.deltaHeight += dy; // For resize cookie
124678 },
124679
124680 _handleMoreBreak : function(ed, url) {
124681 var moreHTML = '<img src="' + url + '/img/trans.gif" alt="$1" class="mceWPmore mceItemNoResize" title="'+ed.getLang('wordpress.wp_more_alt')+'" />';
124682 var nextpageHTML = '<img src="' + url + '/img/trans.gif" class="mceWPnextpage mceItemNoResize" title="'+ed.getLang('wordpress.wp_page_alt')+'" />';
124683
124684 // Load plugin specific CSS into editor
124685 ed.onInit.add(function() {
124686 ed.dom.loadCSS(url + '/css/content.css');
124687 });
124688
124689 // Display morebreak instead if img in element path
124690 ed.onPostRender.add(function() {
124691 if (ed.theme.onResolveName) {
124692 ed.theme.onResolveName.add(function(th, o) {
124693 if (o.node.nodeName == 'IMG') {
124694 if ( ed.dom.hasClass(o.node, 'mceWPmore') )
124695 o.name = 'wpmore';
124696 if ( ed.dom.hasClass(o.node, 'mceWPnextpage') )
124697 o.name = 'wppage';
124698 }
124699
124700 });
124701 }
124702 });
124703
124704 // Replace morebreak with images
124705 ed.onBeforeSetContent.add(function(ed, o) {
124706 o.content = o.content.replace(/<!--more(.*?)-->/g, moreHTML);
124707 o.content = o.content.replace(/<!--nextpage-->/g, nextpageHTML);
124708 });
124709
124710 // Replace images with morebreak
124711 ed.onPostProcess.add(function(ed, o) {
124712 if (o.get)
124713 o.content = o.content.replace(/<img[^>]+>/g, function(im) {
124714 if (im.indexOf('class="mceWPmore') !== -1) {
124715 var m, moretext = (m = im.match(/alt="(.*?)"/)) ? m[1] : '';
124716 im = '<!--more'+moretext+'-->';
124717 }
124718 if (im.indexOf('class="mceWPnextpage') !== -1)
124719 im = '<!--nextpage-->';
124720
124721 return im;
124722 });
124723 });
124724
124725 // Set active buttons if user selected pagebreak or more break
124726 ed.onNodeChange.add(function(ed, cm, n) {
124727 cm.setActive('wp_page', n.nodeName === 'IMG' && ed.dom.hasClass(n, 'mceWPnextpage'));
124728 cm.setActive('wp_more', n.nodeName === 'IMG' && ed.dom.hasClass(n, 'mceWPmore'));
124729 });
124730 }
124731 });
124732
124733 // Register plugin
124734 tinymce.PluginManager.add('wordpress', tinymce.plugins.WordPress);
124735 })();