diff options
author | Pierre Schmitz <pierre@archlinux.de> | 2013-12-08 09:55:49 +0100 |
---|---|---|
committer | Pierre Schmitz <pierre@archlinux.de> | 2013-12-08 09:55:49 +0100 |
commit | 4ac9fa081a7c045f6a9f1cfc529d82423f485b2e (patch) | |
tree | af68743f2f4a47d13f2b0eb05f5c4aaf86d8ea37 /extensions/WikiEditor/modules/jquery.wikiEditor.dialogs.config.js | |
parent | af4da56f1ad4d3ef7b06557bae365da2ea27a897 (diff) |
Update to MediaWiki 1.22.0
Diffstat (limited to 'extensions/WikiEditor/modules/jquery.wikiEditor.dialogs.config.js')
-rw-r--r-- | extensions/WikiEditor/modules/jquery.wikiEditor.dialogs.config.js | 124 |
1 files changed, 68 insertions, 56 deletions
diff --git a/extensions/WikiEditor/modules/jquery.wikiEditor.dialogs.config.js b/extensions/WikiEditor/modules/jquery.wikiEditor.dialogs.config.js index 146de0f9..f37d004e 100644 --- a/extensions/WikiEditor/modules/jquery.wikiEditor.dialogs.config.js +++ b/extensions/WikiEditor/modules/jquery.wikiEditor.dialogs.config.js @@ -1,6 +1,8 @@ /** * Configuration of Dialog module for wikiEditor */ +/*jshint curly:false, noarg:false, quotmark:false, onevar:false */ +/*global alert */ ( function ( $, mw ) { $.wikiEditor.modules.dialogs.config = { @@ -188,45 +190,45 @@ $.wikiEditor.modules.dialogs.config = { // Show loading spinner while waiting for the API to respond updateWidget( 'loading' ); // Call the API to check page status, saving the request object so it can be aborted if - // necessary + // necessary. + // This used to request a page that would show whether or not the target exists, but we can + // also check whether it has the disambiguation property and still get existence information. + // If the Disambiguator extension is not installed then such a property won't be set. $( '#wikieditor-toolbar-link-int-target-status' ).data( 'request', - $.ajax( { - url: mw.util.wikiScript( 'api' ), - dataType: 'json', - data: { - action: 'query', - indexpageids: '', - titles: target, - converttitles: '', - format: 'json' - }, - success: function ( data ) { - var status; - if ( !data || !data.query ) { - // This happens in some weird cases - status = false; - } else { - var page = data.query.pages[data.query.pageids[0]]; - status = 'exists'; - if ( page.missing !== undefined ) { - status = 'notexists'; - } else if ( page.invalid !== undefined ) { - status = 'invalid'; - } - } - // Cache the status of the link target if the force internal - // parameter was not passed - if ( !internal ) { - cache[target] = status; + ( new mw.Api() ).get( { + action: 'query', + prop: 'pageprops', + titles: target, + ppprop: 'disambiguation', + indexpageids: true + } ).done( function ( data ) { + var status; + if ( !data.query ) { + // This happens in some weird cases + status = false; + } else { + var page = data.query.pages[data.query.pageids[0]]; + status = 'exists'; + if ( page.missing !== undefined ) { + status = 'notexists'; + } else if ( page.invalid !== undefined ) { + status = 'invalid'; + } else if ( page.pageprops !== undefined ) { + status = 'disambig'; } - updateWidget( status ); } + // Cache the status of the link target if the force internal + // parameter was not passed + if ( !internal ) { + cache[target] = status; + } + updateWidget( status ); } ) ); } $( '#wikieditor-toolbar-link-type-int, #wikieditor-toolbar-link-type-ext' ).click( function () { - if ( $( '#wikieditor-toolbar-link-type-ext' ).is( ':checked' ) ) { + if ( $( '#wikieditor-toolbar-link-type-ext' ).prop( 'checked' ) ) { // Abort previous request var request = $( '#wikieditor-toolbar-link-int-target-status' ).data( 'request' ); if ( request ) { @@ -234,8 +236,9 @@ $.wikiEditor.modules.dialogs.config = { } updateWidget( 'external' ); } - if ( $( '#wikieditor-toolbar-link-type-int' ).is( ':checked' ) ) + if ( $( '#wikieditor-toolbar-link-type-int' ).prop( 'checked' ) ) { updateExistence( true ); + } }); // Set labels of tabs based on rel values $(this).find( '[rel]' ).each( function () { @@ -250,12 +253,12 @@ $.wikiEditor.modules.dialogs.config = { .data( 'tooltip', mw.msg( 'wikieditor-toolbar-tool-link-int-text-tooltip' ) ); $( '#wikieditor-toolbar-link-int-target, #wikieditor-toolbar-link-int-text' ) .each( function () { - var tooltip = mw.msg( $( this ).attr( 'id' ) + '-tooltip' ); - if ( $( this ).val() === '' ) + if ( $( this ).val() === '' ) { $( this ) .addClass( 'wikieditor-toolbar-dialog-hint' ) .val( $( this ).data( 'tooltip' ) ) .data( 'tooltip-mode', true ); + } } ) .focus( function () { if ( $( this ).val() === $( this ).data( 'tooltip' ) ) { @@ -295,26 +298,30 @@ $.wikiEditor.modules.dialogs.config = { $( '#wikieditor-toolbar-link-type-int' ).prop( 'checked', true ); updateExistence(); } - if ( $( '#wikieditor-toolbar-link-int-text' ).data( 'untouched' ) ) + /*jshint eqeqeq:false */ + if ( $( '#wikieditor-toolbar-link-int-text' ).data( 'untouched' ) ) { if ( $( '#wikieditor-toolbar-link-int-target' ).val() == - $( '#wikieditor-toolbar-link-int-target' ).data( 'tooltip' ) ) { - $( '#wikieditor-toolbar-link-int-text' ) - .addClass( 'wikieditor-toolbar-dialog-hint' ) - .val( $( '#wikieditor-toolbar-link-int-text' ).data( 'tooltip' ) ) - .change(); - } else { - $( '#wikieditor-toolbar-link-int-text' ) - .val( $( '#wikieditor-toolbar-link-int-target' ).val() ) - .change(); - } + $( '#wikieditor-toolbar-link-int-target' ).data( 'tooltip' ) + ) { + $( '#wikieditor-toolbar-link-int-text' ) + .addClass( 'wikieditor-toolbar-dialog-hint' ) + .val( $( '#wikieditor-toolbar-link-int-text' ).data( 'tooltip' ) ) + .change(); + } else { + $( '#wikieditor-toolbar-link-int-text' ) + .val( $( '#wikieditor-toolbar-link-int-target' ).val() ) + .change(); + } + } }, 0 ); }); $( '#wikieditor-toolbar-link-int-text' ).bind( 'change keydown paste cut', function () { var oldVal = $(this).val(); var that = this; setTimeout( function () { - if ( $(that).val() !== oldVal ) + if ( $(that).val() !== oldVal ) { $(that).data( 'untouched', false ); + } }, 0 ); }); // Add images to the page existence widget, which will be shown mutually exclusively to communicate if @@ -324,6 +331,7 @@ $.wikiEditor.modules.dialogs.config = { var invalidMsg = mw.msg( 'wikieditor-toolbar-tool-link-int-target-status-invalid' ); var externalMsg = mw.msg( 'wikieditor-toolbar-tool-link-int-target-status-external' ); var loadingMsg = mw.msg( 'wikieditor-toolbar-tool-link-int-target-status-loading' ); + var disambigMsg = mw.msg( 'wikieditor-toolbar-tool-link-int-target-status-disambig' ); $( '#wikieditor-toolbar-link-int-target-status' ) .append( $( '<div>' ) .attr( 'id', 'wikieditor-toolbar-link-int-target-status-exists' ) @@ -349,6 +357,10 @@ $.wikiEditor.modules.dialogs.config = { 'title': loadingMsg } ) ) ) + .append( $( '<div>' ) + .attr( 'id', 'wikieditor-toolbar-link-int-target-status-disambig' ) + .append( disambigMsg ) + ) .data( 'existencecache', {} ) .children().hide(); @@ -374,7 +386,7 @@ $.wikiEditor.modules.dialogs.config = { // Title suggestions $( '#wikieditor-toolbar-link-int-target' ).data( 'suggcache', {} ).suggestions( { - fetch: function ( query ) { + fetch: function () { var that = this; var title = $(this).val(); @@ -603,7 +615,7 @@ $.wikiEditor.modules.dialogs.config = { // Execute the action associated with the first button // when the user presses Enter $(this).closest( '.ui-dialog' ).keypress( function ( e ) { - if ( ( e.keyCode || e.which ) == 13 ) { + if ( ( e.keyCode || e.which ) === 13 ) { var button = $(this).data( 'dialogaction' ) || $(this).find( 'button:first' ); button.click(); e.preventDefault(); @@ -701,7 +713,7 @@ $.wikiEditor.modules.dialogs.config = { // Execute the action associated with the first button // when the user presses Enter $( this ).closest( '.ui-dialog' ).keypress( function ( e ) { - if ( ( e.keyCode || e.which ) == 13 ) { + if ( ( e.keyCode || e.which ) === 13 ) { var button = $( this ).data( 'dialogaction' ) || $( this ).find( 'button:first' ); button.click(); e.preventDefault(); @@ -973,7 +985,7 @@ $.wikiEditor.modules.dialogs.config = { var hiddenHTML = $( '.wikieditor-toolbar-table-preview-hidden' ).html(); $( '.wikieditor-toolbar-table-preview-header' ).html( hiddenHTML ); $( '.wikieditor-toolbar-table-preview-hidden' ).html( headerHTML ); - if ( typeof jQuery.fn.tablesorter == 'function' ) { + if ( typeof jQuery.fn.tablesorter === 'function' ) { $( '#wikieditor-toolbar-table-preview, #wikieditor-toolbar-table-preview2' ) .filter( '.sortable' ) .tablesorter(); @@ -1065,7 +1077,7 @@ $.wikiEditor.modules.dialogs.config = { // Execute the action associated with the first button // when the user presses Enter $(this).closest( '.ui-dialog' ).keypress( function ( e ) { - if ( ( e.keyCode || e.which ) == 13 ) { + if ( ( e.keyCode || e.which ) === 13 ) { var button = $(this).data( 'dialogaction' ) || $(this).find( 'button:first' ); button.click(); e.preventDefault(); @@ -1197,7 +1209,7 @@ $.wikiEditor.modules.dialogs.config = { if ( !match ) { $( '#wikieditor-toolbar-replace-nomatch' ).show(); - } else if ( mode == 'replaceAll' ) { + } else if ( mode === 'replaceAll' ) { // Instead of using repetitive .match() calls, we use one .match() call with /g // and indexOf() followed by substr() to find the offsets. This is actually // faster because our indexOf+substr loop is faster than a match loop, and the @@ -1232,7 +1244,7 @@ $.wikiEditor.modules.dialogs.config = { $(this).data( 'offset', 0 ); } else { - if ( mode == 'replace' ) { + if ( mode === 'replace' ) { var actualReplacement; if (isRegex) { @@ -1325,7 +1337,7 @@ $.wikiEditor.modules.dialogs.config = { // Execute the action associated with the first button // when the user presses Enter $(this).closest( '.ui-dialog' ).keypress( function ( e ) { - if ( ( e.keyCode || e.which ) == 13 ) { + if ( ( e.keyCode || e.which ) === 13 ) { var button = $(this).data( 'dialogaction' ) || $(this).find( 'button:first' ); button.click(); e.preventDefault(); @@ -1345,12 +1357,12 @@ $.wikiEditor.modules.dialogs.config = { $( textbox ) .bind( 'keypress.srdialog', function ( e ) { - if ( e.which == 13 ) { + if ( e.which === 13 ) { // Enter var button = dialog.data( 'dialogaction' ) || dialog.find( 'button:first' ); button.click(); e.preventDefault(); - } else if ( e.which == 27 ) { + } else if ( e.which === 27 ) { // Escape $(that).dialog( 'close' ); } |