User:Bene*/PopUp.js

From Wikidata
Jump to navigation Jump to search

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
( function ( mw, $ )
{
	var i18nData = {
		'en': {
			'title': 'Improved search',
			'description': 'Search for items by site and title',
			'placeholder': 'Item by title'
		},
		'de': {
			'title': 'Verbesserte Suche',
			'description': 'Suche nach Datenelementen nach Website und Titel',
			'placeholder': 'Datenobjekte nach Titel'
		},
		'fr': {
			'title': 'Recherche améliorée',
			'description': 'Rechercher des éléments par site et par titre',
			'placeholder': 'Article par titre'
		},
		'es': {
			'title': 'Búsqueda mejorada',
			'description': 'Búsqueda de artículos por sitio y título',
			'placeholder': 'Artículo por título'
		},
		'it': {
			'title': 'Ricerca migliorata',
			'description': 'Ricerca elementi per sito e titolo',
			'placeholder': 'Elementi per titolo'
		}
	};
 
	var lang = mw.user.options.get( 'language' );
	if( !inArray( lang, ['de', 'en', 'es', 'fr', 'it'] ) ) {
		lang = 'en';
	}
 
	/**
	 * Return, if the array contains the value.
	 */
	function inArray( value, array ) {
		var contains = false;	
		for (var i = 0; i < array.length; i++) {
			contains = array[i] == value;
			if(contains) {
				break;
			}
		}
		return contains;
	}
 
	/**
	 * Return the localized version of a message.
	 */
	function i18n( key ) {
		if( i18nData[ lang ][ key ] ) {
			return i18nData[ lang ][ key ];
		} else {
			return i18nData[ 'en' ][ key ];
		}
	}

function loadIframeTB(iframeName) {
    //alert( document.getElementById('address').value );
    loadIframe(iframeName, 'http://' + document.getElementById('address').value);
}

function loadIframe(iframeName, url) {
    var $iframe = $('#' + iframeName);
    if ( $iframe.length ) {
        $iframe.attr('src', url);   
        return false;
    }
    return true;
}
	
	function getPageHTML( langCode, title ) {
		alert( 'getPageHTML' );
		var url = 'http://' + langCode + '.wikipedia.org/w/index.php?title=' + title;
		//$( '<div><iframe src="' + url + '" width="700" height="630" /></div>' ).appendTo( '#popup' );
		var $iframe = $( '#popup-frame' );
		if ( $iframe.length ) {
			$iframe.attr('src', url); 
		}
		$( 'div#popup' ).dialog( 'open' );

/******************************
		$.get( url, function(data) {
			$( data ).appendTo( '#popup' );
 			$('.result').html(data);
		});
		//$( '#popup' ).load( url );//.dialog( { modal: true } );
		$( 'div#popup' ).dialog( 'open' );

		$( 'body' ).load( 'http://' + langCode + '.wikipedia.org/w/index.php?title=' + title, function(data) {
			alert( data );
			$( data ).appendTo( '#popup' );
			$( 'div#popup' ).dialog( 'open' );
		});
		$.ajax( {
  			url: '//' + langCode + '.wikipedia.org/w/index.php?title=' + title,
  			data: { },
			dataType: 'jsonp'
		} )
		.done(function( data ) {
			alert( data );
			$( data ).appendTo( '#popup' );
			$( 'div#popup' ).dialog( 'open' );
		})
		.fail(function() { alert( 'fail' ); });
******************************/
	}
	
	function getPageContent( langCode, title ) {
		alert( 'getPageContent' );
		$.ajax( {
  			url: '//' + langCode + '.wikipedia.org/w/api.php',
			data: {
				'format': 'json',
				'action': 'query',
				'prop': 'revisions',
				'rvprop': 'content',
				'rvlimit': '1',
				'titles': title
			},
			dataType: 'jsonp'
		} )
		.done(function( data ) {
			for (var id in data['query']['pages']) {
				alert( data['query']['pages'][id]['revisions'][0]['*'] );
				$( data['query']['pages'][id]['revisions'][0]['*'] ).appendTo( '#popup' );
				$( 'div#popup' ).dialog( 'open' );
			}
		})
		.fail(function() { alert( 'fail' ); });
	}
 
	function init() {
		$('.wb-sitelinks-link').append('<a href="#PopUp">popup</a>')
			.click(function() {
				getPageHTML('de', 'Wikipedia:Hauptseite');
			});
		var formFind = '<div id="popup" title=""><iframe id="popup-frame" src="" width="700" height="630" /></div>';
		if(document.getElementById("content")) {
			var messageFind = $( formFind ).appendTo( '#content' );
		} else {
			var messageFind = $( formFind ).appendTo( '#mw_content' );
		}
		messageFind.dialog({
			title: 'site',
			autoOpen: false,
			modal: true,
			width: 700,
			height: 630,
			show: "blind",
			hide: "blind",
			buttons: [ {
				text: 'close',
				title: 'close',
				id: 'button-close',
				click: function() {
					$( this ).dialog( "close" );
				}
			} ]
		} );
	}
 
	$( document ).ready( init );
} ( mediaWiki, jQuery ) );
//</nowiki>