মিডিয়াউইকি:Gadget-ShortUrl.js

উইকিপিডিয়া, মুক্ত বিশ্বকোষ থেকে

লক্ষ্য করুন: প্রকাশ করার পর, পরিবর্তনগুলো দেখতে আপনাকে আপনার ব্রাউজারের ক্যাশে পরিষ্কার করার প্রয়োজন হতে পারে।

  • ফায়ারফক্স / সাফারি: পুনরায় লোড-এ ক্লিক করার সময় শিফট টিপে ধরে রাখুন, অথবা হয় Ctrl-F5 বা Ctrl-R টিপুন (ম্যাকে ⌘-R টিপুন)
  • গুগল ক্রোম: Ctrl-Shift-R (ম্যাকে ⌘-Shift-R) টিপুন
  • ইন্টারনেট এক্সপ্লোরার / এজ: Ctrl ধরে রাখা অবস্থায় Refresh-এ ক্লিক করুন, অথবা Ctrl-F5 টিপুন
  • অপেরা: Ctrl-F5 টিপুন।
/*  _____________________________________________________________________________
 * |                                                                             |
 * |                    === সতর্কবার্তা: বৈশ্বিক গ্যাজেট ফাইল ===                            |
 * |                  এই পাতায় কোন পরিবর্তন করলে তা অনেক ব্যবহারকারীকে প্রভাবিত করবে।                          |
 * | যেকোন পরিবর্তন করার পূর্বে দয়া করে আলাপ পাতায় বা উইকিপিডিয়া:আলোচনাসভায় আলোচনা করুন      |
 * |_____________________________________________________________________________|
 *
 */
( 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',
								'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