[ Index ] |
PHP Cross Reference of MediaWiki-1.24.0 |
[Summary view] [Print] [Text view]
1 /* Publish module for wikiEditor */ 2 /*jshint onevar:false */ 3 ( function ( $, mw ) { $.wikiEditor.modules.previewDialog = { 4 5 /** 6 * Compatability map 7 */ 8 'browsers': { 9 // Left-to-right languages 10 'ltr': { 11 'msie': [['>=', 7]], 12 'firefox': [['>=', 3]], 13 'opera': [['>=', 9.6]], 14 'safari': [['>=', 4]] 15 }, 16 // Right-to-left languages 17 'rtl': { 18 'msie': [['>=', 8]], 19 'firefox': [['>=', 3]], 20 'opera': [['>=', 9.6]], 21 'safari': [['>=', 4]] 22 } 23 }, 24 /** 25 * Internally used functions 26 */ 27 fn: { 28 /** 29 * Creates a publish module within a wikiEditor 30 * @param context Context object of editor to create module in 31 * @param config Configuration object to create module from 32 */ 33 create: function ( context ) { 34 // Build the dialog behind the Publish button 35 var dialogID = 'wikiEditor-' + context.instance + '-preview-dialog'; 36 $.wikiEditor.modules.dialogs.fn.create( 37 context, 38 { 39 preview: { 40 id: dialogID, 41 titleMsg: 'wikieditor-preview-tab', 42 html: '\ 43 <div class="wikiEditor-ui-loading"><span></span></div>\ 44 <div class="wikiEditor-preview-dialog-contents"></div>\ 45 ', 46 init: function () { 47 }, 48 dialog: { 49 buttons: { 50 'wikieditor-publish-dialog-publish': function () { 51 var minorChecked = $( '#wikiEditor-' + context.instance + 52 '-dialog-minor' ).is( ':checked' ) ? 53 'checked' : ''; 54 var watchChecked = $( '#wikiEditor-' + context.instance + 55 '-dialog-watch' ).is( ':checked' ) ? 56 'checked' : ''; 57 $( '#wpMinoredit' ).attr( 'checked', minorChecked ); 58 $( '#wpWatchthis' ).attr( 'checked', watchChecked ); 59 $( '#wpSummary' ).val( $( '#wikiEditor-' + context.instance + 60 '-dialog-summary' ).val() ); 61 $( '#editform' ).submit(); 62 }, 63 'wikieditor-publish-dialog-goback': function () { 64 $( this ).dialog( 'close' ); 65 } 66 }, 67 resizable: false, 68 height: $( 'body' ).height() - 100, 69 width: $( 'body' ).width() - 300, 70 position: ['center', 'top'], 71 open: function () { 72 // Gets the latest copy of the wikitext 73 var wikitext = context.fn.getContents(); 74 var $dialog = $( '#' + dialogID ); 75 $dialog 76 .css( 'position', 'relative' ) 77 .css( 'height', $( 'body' ).height() - 200 ) 78 .parent() 79 .css( 'top', '25px' ); 80 // $dialog.dialog( 'option', 'width', $( 'body' ).width() - 300 ); 81 // Aborts when nothing has changed since the last preview 82 if ( context.modules.preview.previewText === wikitext ) { 83 return; 84 } 85 86 $dialog.find( '.wikiEditor-preview-dialog-contents' ).empty(); 87 $dialog.find( '.wikiEditor-ui-loading' ).show(); 88 $.post( 89 mw.util.wikiScript( 'api' ), 90 { 91 'action': 'parse', 92 'title': mw.config.get( 'wgPageName' ), 93 'text': wikitext, 94 'prop': 'text', 95 'pst': '', 96 'format': 'json' 97 }, 98 function ( data ) { 99 if ( 100 typeof data.parse === 'undefined' || 101 typeof data.parse.text === 'undefined' || 102 typeof data.parse.text['*'] === 'undefined' 103 ) { 104 return; 105 } 106 context.modules.preview.previewText = wikitext; 107 $dialog.find( '.wikiEditor-ui-loading' ).hide(); 108 $dialog.find( '.wikiEditor-preview-dialog-contents' ) 109 .html( '<h1 class="firstHeading" id="firstHeading">' + 110 mw.config.get( 'wgTitle' ) + '</h1>' + 111 data.parse.text['*'] ) 112 .find( 'a:not([href^=#])' ).click( function () { return false; } ); 113 }, 114 'json' 115 ); 116 } 117 }, 118 resizeme: false 119 } 120 } 121 ); 122 context.fn.addButton( { 123 'captionMsg': 'wikieditor-preview-tab', 124 'action': function () { 125 context.$textarea.wikiEditor( 'openDialog', 'preview' ); 126 return false; 127 } 128 } ); 129 } 130 } 131 132 }; } )( jQuery, mediaWiki );
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 14:03:12 2014 | Cross-referenced by PHPXref 0.7.1 |