diff options
author | Luke Shumaker <lukeshu@sbcglobal.net> | 2016-05-01 15:12:12 -0400 |
---|---|---|
committer | Luke Shumaker <lukeshu@sbcglobal.net> | 2016-05-01 15:12:12 -0400 |
commit | c9aa36da061816dee256a979c2ff8d2ee41824d9 (patch) | |
tree | 29f7002b80ee984b488bd047dbbd80b36bf892e9 /extensions/WikiEditor/modules/jquery.wikiEditor.preview.js | |
parent | b4274e0e33eafb5e9ead9d949ebf031a9fb8363b (diff) | |
parent | d1ba966140d7a60cd5ae4e8667ceb27c1a138592 (diff) |
Merge branch 'archwiki'
# Conflicts:
# skins/ArchLinux.php
# skins/ArchLinux/archlogo.gif
Diffstat (limited to 'extensions/WikiEditor/modules/jquery.wikiEditor.preview.js')
-rw-r--r-- | extensions/WikiEditor/modules/jquery.wikiEditor.preview.js | 115 |
1 files changed, 66 insertions, 49 deletions
diff --git a/extensions/WikiEditor/modules/jquery.wikiEditor.preview.js b/extensions/WikiEditor/modules/jquery.wikiEditor.preview.js index 39907364..f0665220 100644 --- a/extensions/WikiEditor/modules/jquery.wikiEditor.preview.js +++ b/extensions/WikiEditor/modules/jquery.wikiEditor.preview.js @@ -1,6 +1,6 @@ /* Preview module for wikiEditor */ ( function ( $, mw ) { - +/*jshint onevar:false */ $.wikiEditor.modules.preview = { /** @@ -32,7 +32,7 @@ fn: { * @param context Context object of editor to create module in * @param config Configuration object to create module from */ - create: function ( context, config ) { + create: function ( context ) { if ( 'initialized' in context.modules.preview ) { return; } @@ -53,32 +53,37 @@ fn: { } context.modules.preview.$preview.find( '.wikiEditor-preview-contents' ).empty(); context.modules.preview.$preview.find( '.wikiEditor-preview-loading' ).show(); - $.post( - mw.util.wikiScript( 'api' ), - { + $.ajax( { + url: mw.util.wikiScript( 'api' ), + type: 'POST', + dataType: 'json', + data: { format: 'json', action: 'parse', title: mw.config.get( 'wgPageName' ), text: wikitext, - prop: 'text', + prop: 'text|modules', pst: '' - }, - function ( data ) { - if ( - typeof data.parse == 'undefined' || - typeof data.parse.text == 'undefined' || - typeof data.parse.text['*'] == 'undefined' - ) { - return; - } - context.modules.preview.previewText = wikitext; - context.modules.preview.$preview.find( '.wikiEditor-preview-loading' ).hide(); - context.modules.preview.$preview.find( '.wikiEditor-preview-contents' ) - .html( data.parse.text['*'] ) - .find( 'a:not([href^=#])' ).click( false ); - }, - 'json' - ); + } + } ).done( function ( data ) { + if ( !data.parse || !data.parse.text || data.parse.text['*'] === undefined ) { + return; + } + + context.modules.preview.previewText = wikitext; + context.modules.preview.$preview.find( '.wikiEditor-preview-loading' ).hide(); + context.modules.preview.$preview.find( '.wikiEditor-preview-contents' ) + .html( data.parse.text['*'] ) + .find( 'a:not([href^=#])' ) + .click( false ); + + var loadmodules = data.parse.modules.concat( + data.parse.modulescripts, + data.parse.modulestyles, + data.parse.modulemessages + ); + mw.loader.load( loadmodules ); + } ); } } ); @@ -89,21 +94,25 @@ fn: { // Gets the latest copy of the wikitext var wikitext = context.$textarea.textSelection( 'getContents' ); // Aborts when nothing has changed since the last time - if ( context.modules.preview.changesText == wikitext ) { + if ( context.modules.preview.changesText === wikitext ) { return; } context.$changesTab.find( 'table.diff tbody' ).empty(); context.$changesTab.find( '.wikiEditor-preview-loading' ).show(); // Call the API. First PST the input, then diff it - var postdata = { - format: 'json', - action: 'parse', - onlypst: '', - text: wikitext - }; - - $.post( mw.util.wikiScript( 'api' ), postdata, function ( data ) { + $.ajax( { + url: mw.util.wikiScript( 'api' ), + type: 'POST', + dataType: 'json', + data: { + format: 'json', + action: 'parse', + title: mw.config.get( 'wgPageName' ), + onlypst: '', + text: wikitext + } + } ).done( function ( data ) { try { var postdata2 = { format: 'json', @@ -115,25 +124,33 @@ fn: { rvprop: '' }; var section = $( '[name="wpSection"]' ).val(); - if ( section !== '' ) + if ( section !== '' ) { postdata2.rvsection = section; + } + + $.ajax( { + url: mw.util.wikiScript( 'api' ), + type: 'POST', + dataType: 'json', + data: postdata2 + } ).done( function ( data ) { + // Add diff CSS + mw.loader.load( 'mediawiki.action.history.diff' ); + try { + var diff = data.query.pages[data.query.pageids[0]] + .revisions[0].diff['*']; - $.post( mw.util.wikiScript( 'api' ), postdata2, function ( data ) { - // Add diff CSS - mw.loader.load( 'mediawiki.action.history.diff' ); - try { - var diff = data.query.pages[data.query.pageids[0]] - .revisions[0].diff['*']; - context.$changesTab.find( 'table.diff tbody' ) - .html( diff ); - context.$changesTab - .find( '.wikiEditor-preview-loading' ).hide(); - context.modules.preview.changesText = wikitext; - } catch ( e ) { } // "blah is undefined" error, ignore - }, 'json' - ); - } catch ( e ) { } // "blah is undefined" error, ignore - }, 'json' ); + context.$changesTab.find( 'table.diff tbody' ).html( diff ); + context.modules.preview.changesText = wikitext; + } catch ( e ) { + // "data.blah is undefined" error, ignore + } + context.$changesTab.find( '.wikiEditor-preview-loading' ).hide(); + } ); + } catch ( e ) { + // "data.blah is undefined" error, ignore + } + } ); } } ); |