Make WordPress Core

Ticket #21812: 21812-4.patch

File 21812-4.patch, 10.6 KB (added by azaozz, 13 years ago)
  • wp-includes/js/tinymce/plugins/wordpress/editor_plugin_src.js

     
    77
    88        tinymce.create('tinymce.plugins.WordPress', {
    99                mceTout : 0,
     10                previews : {i: 0},
     11                reg_previews : [],
    1012
    1113                init : function(ed, url) {
    1214                        var t = this, tbId = ed.getParam('wordpress_adv_toolbar', 'toolbar2'), last = 0, moreHTML, nextpageHTML, closeOnClick, mod_key;
     15
    1316                        moreHTML = '<img src="' + url + '/img/trans.gif" class="mceWPmore mceItemNoResize" title="'+ed.getLang('wordpress.wp_more_alt')+'" />';
    1417                        nextpageHTML = '<img src="' + url + '/img/trans.gif" class="mceWPnextpage mceItemNoResize" title="'+ed.getLang('wordpress.wp_page_alt')+'" />';
    1518
    16                         if ( getUserSetting('hidetb', '0') == '1' )
     19                        t.ed = ed;
     20
     21                        if ( typeof(getUserSetting) == 'function' && getUserSetting('hidetb', '0') == '1' )
    1722                                ed.settings.wordpress_adv_hidden = 0;
    1823
    1924                        // Hides the specified toolbar and resizes the iframe
     
    251256                        // Add custom shortcuts
    252257                        mod_key = 'alt+shift';
    253258
    254                 //      if ( tinymce.isGecko ) // disable for mow, too many shortcuts conflicts
    255                 //              mod_key = 'ctrl+alt';
    256 
    257259                        ed.addShortcut(mod_key + '+c', 'justifycenter_desc', 'JustifyCenter');
    258260                        ed.addShortcut(mod_key + '+r', 'justifyright_desc', 'JustifyRight');
    259261                        ed.addShortcut(mod_key + '+l', 'justifyleft_desc', 'JustifyLeft');
     
    313315                        // close popups when clicking on the background
    314316                        tinymce.dom.Event.remove(document.body, 'click', closeOnClick);
    315317                        tinymce.dom.Event.add(document.body, 'click', closeOnClick);
     318
     319
     320                        // previews
     321                        ed.onPreInit.add( function(ed){
     322                                ed.schema.addValidElements('div[*],span[*]'); // so we can set contenteditable=false
     323
     324                                // add custom jQuery event so plugins can do:
     325                                // jQuery(document).on( 'wp_add_mce_previews', function(e, ed){ ed.wpPreviewRegister(args) } );
     326                                if ( typeof(jQuery) != 'undefined' )
     327                                        jQuery(document).trigger( 'wp_add_mce_previews', ed );
     328                        });
     329
     330                        // scan on paste and on inserting nodes/html (on send_to_editor)
     331                        ed.onInit.add(function(ed) {
     332                                ed.selection.onSetContent.add(function(sel, o) {
     333                                        var node;
     334
     335                                        if ( o.context && t.reg_previews.length ) {
     336                                                node = sel.getNode();
     337
     338                                                if ( node.innerHTML ) {
     339                                                        node.innerHTML = t.previews_step_1(node.innerHTML);
     340                                                        t.previews_step_2( ed.dom.select('.wp-preview-wrap', node) );
     341                                                }
     342                                        }
     343                                });
     344                        });
     345
     346                        // scan the last paragraph on enter
     347                        ed.onKeyDown.add(function(ed, e){
     348                                var node, html;
     349
     350                                if ( e.keyCode == 13 ) {
     351                                        node = ed.selection.getNode();
     352
     353                                        if ( node.innerHTML ) {
     354                                                html = t.previews_step_1(node.innerHTML);
     355
     356                                                setTimeout(function(){ // delay so all other keydown events run
     357                                                        node.innerHTML = html;
     358
     359                                                        if ( ed.dom.is(node.lastChild, 'br') )
     360                                                                ed.dom.remove(node.lastChild);
     361
     362                                                        t.previews_step_2( ed.dom.select('.wp-preview-wrap', node) );
     363                                                }, 50);
     364                                        }
     365                                }
     366                        });
     367
     368                        // runs every time content (html string) is loaded in the editor
     369                        ed.onBeforeSetContent.add(function(ed, o) {
     370                                t.previews = {i: 0};
     371
     372                                if ( o.content )
     373                                        o.content = t.previews_step_1(o.content);
     374                        });
     375
     376                        // runs when the DOM is ready every time content is loaded in the editor
     377                        ed.onLoadContent.add(function(ed, o){
     378                                t.previews_step_2( ed.dom.select('.wp-preview-wrap') );
     379                        });
     380
     381                        ed.onPostProcess.add(function(ed, o) {
     382                                if ( ( o.get || o.save ) && o.content.indexOf('data-wp-preview="') > -1 ) {
     383                                        o.content = o.content.replace(/(<(div|span)[^>]+data-wp-preview="([^"]+)"[^>]*>)[\s\S]+?<\2 data-wp-preview-blocker="1">.*?<\/\2><\/\2>/g, function(a, b, c, d){
     384                                                var previews = t.previews, str = decodeURIComponent(d), div_id = c.replace(/.+id="([^"]+)".+/, '$1');
     385
     386                                                if ( b == 'div' )
     387                                                        str = '<p>'+ str +'</p>';
     388
     389                                                if ( previews[div_id] && previews[div_id].cleanup_callback )
     390                                                        str = previews[div_id].cleanup_callback.call( t, { ed: ed, original: str } );
     391
     392                                                return str;
     393                                        });
     394                                }
     395                        });
     396
     397                        /*
     398                        store all preview args
     399                        args = {
     400                                ref_name: 'my_preview',
     401                                tag: 'span', // html tag for the wrapper elements div|span, default = div
     402                                preview_regexp: /\[gallery[^\]]*\]/,
     403                                str_callback: function(obj){ console.log('str_callback'); console.log(obj); return obj.original+' 123 ' },
     404                                node_callback: function(obj){ console.log('node_callback'); console.log(obj) },
     405                                cleanup_callback: function(obj){ console.log('cleanup_callback'); console.log(obj); return obj.original }
     406                        }
     407                        */
     408                        ed.wpPreviewRegister = function(args) {
     409                                t.reg_previews.push(args);
     410                        };
    316411                },
    317412
    318413                getInfo : function() {
     
    418513
    419514                        // Replace images with morebreak
    420515                        ed.onPostProcess.add(function(ed, o) {
    421                                 if (o.get)
     516                                if ( o.get ) {
    422517                                        o.content = o.content.replace(/<img[^>]+>/g, function(im) {
    423                                                 if (im.indexOf('class="mceWPmore') !== -1) {
    424                                                         var m, moretext = (m = im.match(/alt="(.*?)"/)) ? m[1] : '';
     518                                                if ( im.indexOf('class="mceWPmore') !== -1 ) {
     519                                                        var m, moretext = ( m = im.match(/alt="(.*?)"/) ) ? m[1] : '';
    425520                                                        im = '<!--more'+moretext+'-->';
    426521                                                }
    427                                                 if (im.indexOf('class="mceWPnextpage') !== -1)
     522                                                if ( im.indexOf('class="mceWPnextpage') !== -1 )
    428523                                                        im = '<!--nextpage-->';
    429524
    430525                                                return im;
    431526                                        });
     527                                }
    432528                        });
    433529
    434530                        // Set active buttons if user selected pagebreak or more break
     
    436532                                cm.setActive('wp_page', n.nodeName === 'IMG' && ed.dom.hasClass(n, 'mceWPnextpage'));
    437533                                cm.setActive('wp_more', n.nodeName === 'IMG' && ed.dom.hasClass(n, 'mceWPmore'));
    438534                        });
     535                },
     536
     537                previews_step_1: function(content) {
     538                        var self = this, previews = self.previews;
     539
     540                        if ( self.reg_previews.length ) {
     541                                tinymce.each( self.reg_previews, function(args){
     542                                        if ( !args.preview_regexp )
     543                                                return;
     544
     545                                        var regex = new RegExp( '(?:<p>\\s*)?(' + args.preview_regexp.source + ')(?:\\s*</p>)?', 'g' ),
     546                                                tag = 'div';
     547
     548                                        if ( args.tag && args.tag == 'span' )
     549                                                tag = 'span';
     550
     551                                        content = content.replace(regex, function(a, orig_str){
     552                                                var html, div_id, new_str;
     553
     554                                                previews.i++;
     555                                                div_id = 'wp_mce_preview_' + previews.i;
     556
     557                                                new_str = args.str_callback.call( self, { ed: self.ed, original: orig_str, div_id: div_id } );
     558                                                previews[div_id] = args;
     559
     560                                                html = '<'+tag+' id="'+ div_id +'" data-wp-preview="'+ encodeURIComponent(orig_str) +'" class="wp-preview-wrap" contenteditable="false">' +
     561                                                        '<'+tag+' class="wp-preview">'+ new_str +'</'+tag+'>' + // add inner wrapper so the preview node(s) can be appended there without disturbing the blocker and end divs?
     562                                                        '<'+tag+' data-wp-preview-blocker="1">\uFEFF</'+tag+'></'+tag+'>';
     563
     564                                                return html;
     565                                        });
     566                                });
     567                        }
     568
     569                        return content;
     570                },
     571
     572                // go through the previews added in step_1 and fire node callback
     573                previews_step_2: function(nodes) {
     574                        var self = this, events = self.ed.dom.events;
     575
     576                        tinymce.each( nodes, function(node){
     577                                var div_id = node.id, args;
     578
     579                                if ( !div_id || !self.previews.hasOwnProperty(div_id) ) // no reference for this preview? Remove it?
     580                                        return;
     581
     582                                args = self.previews[div_id];
     583                                events.add( node, ['mousedown'], function(e){ events.prevent(e); } ); // prevent FF from highlighting the non-editable element
     584
     585                                if ( args.node_callback ) { // use the inner wrapper as node in the callback
     586                                        args.node_callback.call( self, { ed: self.ed, node: node.firstChild, div_id: div_id } );
     587                                }
     588                        });
    439589                }
    440590        });
    441591
  • wp-includes/js/tinymce/plugins/wpgallery/editor_plugin_src.js

     
    2626                                if ( e.target.nodeName == 'IMG' && ed.dom.hasClass(e.target, 'wpGallery') )
    2727                                        ed.plugins.wordpress._showButtons(e.target, 'wp_gallerybtns');
    2828                        });
    29 
     29/*
    3030                        ed.onBeforeSetContent.add(function(ed, o) {
    3131                                o.content = t._do_gallery(o.content);
    3232                        });
     
    3535                                if (o.get)
    3636                                        o.content = t._get_gallery(o.content);
    3737                        });
     38*/
    3839                },
    3940
    4041                _do_gallery : function(co) {
  • wp-includes/js/tinymce/themes/advanced/skins/wp_theme/content.css

     
    141141        height: 250px;
    142142}
    143143
     144/* Previews */
     145div[data-wp-preview-blocker],
     146span[data-wp-preview-blocker] {
     147        height: 100%;
     148        width: 100%;
     149        position: absolute;
     150        background: #fff;
     151        opacity: 0.01;
     152        filter: alpha(opacity=1);
     153        top: 0;
     154        left: 0;
     155        bottom: 0;
     156        right: 0;
     157        z-index: 5;
     158}
     159
     160div.wp-preview-wrap,
     161span.wp-preview-wrap {
     162        margin: 10px auto;
     163        position: relative;
     164}
     165
     166span.wp-preview-wrap,
     167span[data-wp-preview-blocker] {
     168        display: inline-block;
     169}
     170
     171div.wp-preview-wrap,
     172span.wp-preview-wrap,
     173div[data-wp-preview-blocker],
     174span[data-wp-preview-blocker] {
     175        -ms-user-select: none;
     176        -moz-user-select: none; /* doesn't work */
     177        -webkit-user-select: none;
     178        user-select: none;
     179}
     180
     181div.wp-preview-wrap .gallery-icon {
     182        margin: 0;
     183}
     184
     185div.wp-preview-wrap .gallery-icon img {
     186        display: block;
     187        margin: 0 auto;
     188        padding: 0;
     189        max-width: 90%;
     190        height: auto;
     191        border: 0;
     192}
     193
     194div.wp-preview-wrap dd.gallery-caption {
     195        margin: 0 6%;
     196        font-size: 12px;
     197}
     198
     199div.wp-preview-wrap div.gallery {
     200        clear: both;
     201}
     202
     203div.wp-preview-wrap div.gallery dl.gallery-item {
     204        float: left;
     205        margin: 10px 0;
     206        padding: 0;
     207}
     208
     209div.wp-preview-wrap div.gallery-columns-1 dl.gallery-item {
     210        width: 99%;
     211}
     212
     213div.wp-preview-wrap div.gallery-columns-2 dl.gallery-item {
     214        width: 49.5%;
     215}
     216
     217div.wp-preview-wrap div.gallery-columns-3 dl.gallery-item {
     218        width: 33%;
     219}
     220
     221div.wp-preview-wrap div.gallery-columns-4 dl.gallery-item {
     222        width: 24.75%;
     223}
     224
     225div.wp-preview-wrap div.gallery-columns-5 dl.gallery-item {
     226        width: 19.8%;
     227}
     228
     229div.wp-preview-wrap div.gallery-columns-6 dl.gallery-item {
     230        width: 16.5%;
     231}
     232
     233div.wp-preview-wrap div.gallery-columns-7 dl.gallery-item {
     234        width: 14.2%;
     235}
     236
     237div.wp-preview-wrap div.gallery-columns-8 dl.gallery-item {
     238        width: 12.45%;
     239}
     240
     241div.wp-preview-wrap div.gallery-columns-9 dl.gallery-item {
     242        width: 11.1%;
     243}
     244
     245div.wp-preview-wrap div.gallery-columns-10 dl.gallery-item {
     246        width: 9.99%;
     247}
     248
     249
     250