मीडियाविकि:Gadget-ShortUrl.js
सूचना: सम्पादनहरू प्रकाशित गरेपछि, परिवर्तनहरू हेर्नको लागि तपाईंले आफ्नो ब्राउजरको क्यासलाई बाइपास गर्नुपर्छ। गुगल क्रोम, फायरफक्स, माइक्रोसफ्ट एज र सफारी: ⇧ Shift कुञ्जी थिचिराखेर रिलोड उपकरणपट्टी बटनमा थिच्नुहोस्।
/* _____________________________________________________________________________
* | |
* | === चेतावनी: विश्वव्यापी उपकरण फाइल === |
* | यसमा कुनै पनि सानो परिवर्तनले धेरै प्रयोगकर्तालाई प्रभावित गर्न सक्नेछ । |
* | यसमा परिवर्तन गर्नु पूर्व पहिले वार्ता पृष्ठमा अथवा चौतारीमा परिवर्तनसँग सम्बन्धित छलफल गर्नुहोला |
* |_____________________________________________________________________________|
*
*/
( 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'
} )
);
//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