support for interwikis in experimental JS preview
authorMatmaRex <matma.rex@gmail.com>
Thu, 9 Aug 2012 12:27:46 +0000 (14:27 +0200)
committerMatmaRex <matma.rex@gmail.com>
Thu, 9 Aug 2012 20:13:19 +0000 (22:13 +0200)
Add support for previewing interwikis in "experimental" JavaScript live
preview.

The #p-lang container is not shown when action=edit by default; it is,
however, shown when action=submit. We check for its existence and if
missing, we add it after #p-tb. (As print/export links are not shown
during either editing or previewing.)

If #p-tb is missing (as the case is in some skins), nothing happens
(and interwikis stay unpreviewable). jQuery is very permissive
and keeps chugging along at all costs.

If #p-lang is missing in the preview page, nothing bad happens as well.
The content of #p-lang is properly cleared and not filled with anything.
(See above comment about jQuery being permissive.)

Change-Id: Idda2e6f7514ba8b1021c719a08855ee9601fa90e

skins/common/preview.js

index 9e76ca0..de4bcff 100644 (file)
@@ -12,7 +12,7 @@
 
                // Hide active diff, used templates, old preview if shown
                var copyElements = ['#wikiPreview', '.templatesUsed', '.hiddencats',
-                                                       '#catlinks'];
+                                                       '#catlinks', '#p-lang'];
                var copySelector = copyElements.join(',');
 
                $.each( copyElements, function(k,v) { $(v).fadeOut('fast'); } );
        };
 
        $(document).ready( function() {
-               $('#wpPreview').click( doLivePreview );
+               // construct space for interwiki links if missing
+               // (it is usually not shown when action=edit, but shown if action=submit)
+               if ( !document.getElementById( 'p-lang' ) && document.getElementById( 'p-tb' ) ) {
+                       // we need not hide this, because it's empty anyway
+                       $( '#p-tb' ).after( $( '<div>' ).attr( 'id', 'p-lang' ) );
+               }
+
+               $( '#wpPreview' ).click( doLivePreview );
        } );
 }) ( jQuery );