मीडियाविकि:Gadget-ShortUrlShare.js

विकिविश्वविद्यालय से

ध्यान दें: प्रकाशित करने के बाद बदलाव देखने के लिए आपको अपने ब्राउज़र के कैश को हटाना पड़ सकता है।

  • Firefox/Safari: Reload क्लिक समय Shift दबाएँ, या फिर Ctrl-F5 या Ctrl-R दबाएँ (Mac पर ⌘-R)
  • Google Chrome: Ctrl-Shift-R दबाएँ (Mac पर ⌘-Shift-R)
  • Internet Explorer/Edge: Refresh पर क्लिक करते समय Ctrl दबाएँ, या Ctrl-F5 दबाएँ
  • Opera: Ctrl-F5 दबाएँ।
// <nowiki>
/*  _____________________________________________________________________________
 * |                                                                             |
 * |                    === चेतावनी: ग्लोबल गैजेट फ़ाइल ===                            |
 * |                  इसमें किए बदलाव कई सदस्यों को प्रभावित करेंगे।                        |
 * | इसमें बदलाव करने से पहले कृपया वार्ता पृष्ठ पे अथवा चौपाल पे बदलावों से सम्बन्धित चर्चा कर लें      |
 * |_____________________________________________________________________________|
 *
 * Author    : [[User:स]]
 * Date      : June 2017
 * Based on  : Gadget ShortURL by [[User:Siddhartha Ghai]] per https://phabricator.wikimedia.org/T40863
 * This Work : Adds some SocialSharing links
 */
( function ( window, document, $, undefined ) { // Wrap with anonymous function
$( document ).ready(function () {
	'use strict';
	//get url from sidebar
	var url = $("li#t-shorturl").children().attr("href");

	//return if short url doesn't exist, or user's not in the view tab
	if ( url === undefined ||
		mw.config.get("wgAction") !== "view" ||
		window.location.href.match("diff=") !== null ) {
		return;
	}

	//create html elements
	var timeoutID = null,
		$icon = $( '<span>' )
					.addClass('title-shortlink')
					.addClass('title-shortlink-icon'),
		$tooltip = $( '<span>' )
						.addClass('title-shortlink')
						.addClass('title-shortlink-tooltip')
						.html( 'छोटा यूआरएल: ' + window.location.protocol + url )
						.append( $( '<a>' )
							.attr( {
								'class': 'title-shortlink title-shortlink-help-link',
								'id': 'title-shortlink-help-link',
								'href': '//hi.wikipedia.org/wiki/सहायता:छोटा_यू॰आर॰एल',
								'target': '_blank'
							} )
						)
	.append( $( '<a>' )
							.attr( {
								'class': 'title-shortlink title-facebook-link',
								'id': 'title-facebook-link',
								'href': '//www.facebook.com/sharer.php?u=http:'+mw.config.get('wgServer')+'/wiki/'+encodeURIComponent(mw.config.get('wgPageName').replace(/ /g,'_'))+'&t='+encodeURIComponent(mw.config.get('wgPageName').replace(/ /g,'_')),
								'target': '_blank'
							} )
						)
	.append( $( '<a>' )
							.attr( {
								'class': 'title-shortlink title-twitter-link',
								'id': 'title-twitter-link',
								'href': '//twitter.com/?status='+encodeURIComponent('हिन्दी विकिपीडिया पर पढ़ें, लेख: ' + mw.config.get('wgTitle') +' '+ window.location.protocol + url +' #hiwikipedia @WikimediaIndia' ),
								'target': '_blank'
							} )
						)
							
	.append( $( '<a>' )
							.attr( {
								'class': 'title-shortlink title-googleplus-link',
								'id': 'title-googleplus-link',
								'href': '//plus.google.com/share?hl=hi&url='+encodeURIComponent(window.location.protocol + url),
								'target': '_blank'
							} )
						);
	//add tooltip to document
	$( '#firstHeading' ).append( $icon );
	$( 'body' ).prepend( $tooltip.hide() );

	// settimeout idea...
	// http://stackoverflow.com/questions/6786322#comment8062858_6786647

	$( '.title-shortlink' ).mouseover( function() {
		var $offset = $icon.offset(),
			left;
		if ( timeoutID !== null ) {
			clearTimeout( timeoutID );
			timeoutID = null;
		}
		$icon.animate( { opacity: 1 }, 400 );
		left = ( $offset.left + $tooltip.width() > window.innerWidth ) ?
				$offset.left - $tooltip.width() :
				$offset.left;
		$tooltip
			.css( {
				'top' : $offset.top + $icon.height() + 'px',
				'left' : left + 'px'
			} )
			.show();
	} );

	$( '.title-shortlink' ).mouseleave( function() {
		timeoutID = setTimeout ( function () {
			$tooltip.fadeOut( 400,
				function () {
					$icon.animate( { opacity: 0.5 }, 400 );
				}
			);
		}, 500);
	} );
} );
} ( window, document, jQuery )); // End wrap with anonymous function

// </nowiki>