]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-includes/js/tinymce/plugins/wpfullscreen/editor_plugin_src.js
Wordpress 3.5
[autoinstalls/wordpress.git] / wp-includes / js / tinymce / plugins / wpfullscreen / editor_plugin_src.js
index 9d33795f4991f97ad8dde1ae1434773e51a460de..c1a30759b5567b59a565f60c51039704339b5d13 100644 (file)
@@ -6,6 +6,7 @@
 
 (function() {
        tinymce.create('tinymce.plugins.wpFullscreenPlugin', {
+               resize_timeout: false,
 
                init : function(ed, url) {
                        var t = this, oldHeight = 0, s = {}, DOM = tinymce.DOM;
                                }
                        });
 
+                       ed.addCommand('wpFullScreen', function() {
+                               if ( typeof(fullscreen) == 'undefined' )
+                                       return;
+
+                               if ( 'wp_mce_fullscreen' == ed.id )
+                                       fullscreen.off();
+                               else
+                                       fullscreen.on();
+                       });
+
                        // Register buttons
-                       if ( 'undefined' != fullscreen ) {
-                               ed.addButton('wp_fullscreen', {
-                                       title : 'fullscreen.desc',
-                                       onclick : function(){ fullscreen.on(); }
-                               });
-                       }
+                       ed.addButton('wp_fullscreen', {
+                               title : 'wordpress.wp_fullscreen_desc',
+                               cmd : 'wpFullScreen'
+                       });
 
                        // END fullscreen
 //----------------------------------------------------------------
                        /**
                         * This method gets executed each time the editor needs to resize.
                         */
-                       function resize() {
-                               var d = ed.getDoc(), DOM = tinymce.DOM, resizeHeight, myHeight;
+                       function resize(editor, e) {
+                               var DOM = tinymce.DOM, body = ed.getBody(), ifr = DOM.get(ed.id + '_ifr'), height, y = ed.dom.win.scrollY;
 
-                               // Get height differently depending on the browser used
-                               if ( tinymce.isWebKit )
-                                       myHeight = d.body.offsetHeight;
-                               else
-                                       myHeight = d.body.scrollHeight;
+                               if ( t.resize_timeout )
+                                       return;
+
+                               // sometimes several events are fired few ms apart, trottle down resizing a little
+                               t.resize_timeout = true;
+                               setTimeout(function(){
+                                       t.resize_timeout = false;
+                               }, 500);
 
-                               // Don't make it smaller than 300px
-                               resizeHeight = (myHeight > 300) ? myHeight : 300;
+                               height = body.scrollHeight > 300 ? body.scrollHeight : 300;
+
+                               if ( height != ifr.scrollHeight ) {
+                                       DOM.setStyle(ifr, 'height', height + 'px');
+                                       ed.getWin().scrollTo(0, 0); // iframe window object, make sure there's no scrolling
+                               }
 
-                               // Resize content element
-                               if ( oldHeight != resizeHeight ) {
-                                       DOM.setStyle(DOM.get(ed.id + '_ifr'), 'height', resizeHeight + 'px');
-                                       oldHeight = resizeHeight;
-                                       ed.getWin().scrollTo(0,0);
+                               // WebKit scrolls to top on paste...
+                               if ( e && e.type == 'paste' && tinymce.isWebKit ) {
+                                       setTimeout(function(){
+                                               ed.dom.win.scrollTo(0, y);
+                                       }, 40);
                                }
                        };
 
                                ed.getBody().style.overflowY = "hidden";
                        });
 
-                       if (ed.getParam('autoresize_on_init', true)) {
+                       if ( ed.getParam('autoresize_on_init', true) ) {
                                ed.onLoadContent.add(function(ed, l) {
                                        // Because the content area resizes when its content CSS loads,
                                        // and we can't easily add a listener to its onload event,